:root {
  --bg: #fff;
  --bg-secondary: #f5f5f7;
  --text: #1d1d1f;
  --text-muted: #86868b;
  --border: #d2d2d7;
  --border-light: #e8e8ed;
  --accent: #1d1d1f;
  --accent-hover: #424245;
  --danger: #ff3b30;
  --danger-hover: #d63028;
  --success: #34c759;
  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
  --warn-text: #92400e;
  --error-bg: #fef2f2;
  --error-border: #ef4444;
  --error-text: #991b1b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
  --transition: 0.2s ease;
}

html.dark {
  --bg: #000;
  --bg-secondary: #1c1c1e;
  --text: #f5f5f7;
  --text-muted: #86868b;
  --border: #424245;
  --border-light: #2c2c2e;
  --accent: #f5f5f7;
  --accent-hover: #d2d2d7;
  --danger: #ff453a;
  --danger-hover: #ff6961;
  --success: #30d158;
  --warn-bg: #1c1a0e;
  --warn-border: #f59e0b;
  --warn-text: #fbbf24;
  --error-bg: #1c0e0e;
  --error-border: #ef4444;
  --error-text: #fca5a5;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.4);
}

*,*::before,*::after { margin: 0; padding: 0; box-sizing: border-box; }

html.transitioning,
html.transitioning *,
html.transitioning *::before,
html.transitioning *::after {
  transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease, fill 0.4s ease, stroke 0.4s ease !important;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--text); text-decoration: none; }
a:hover { opacity: 0.7; }

main { flex: 1; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.site-header nav {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.nav-right { display: flex; align-items: center; gap: 1.25rem; }

.nav-link {
  font-size: 0.8125rem;
  color: var(--text-muted);
  transition: color var(--transition);
}
.nav-link:hover { color: var(--text); opacity: 1; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: 4px;
  transition: color var(--transition);
}
.btn-icon:hover { color: var(--text); }

.icon-moon { display: none; }
html.dark .icon-sun { display: none; }
html.dark .icon-moon { display: block; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border-light);
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ---------- Hero ---------- */
.hero {
  max-width: 680px;
  margin: 0 auto;
  padding: 6rem 1.5rem 4rem;
  text-align: center;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.1;
  margin-bottom: 0.75rem;
}

.hero-sub {
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.hero-desc {
  font-size: 1.0625rem;
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto 2rem;
  line-height: 1.6;
}

.hero-actions { display: flex; gap: 0.75rem; justify-content: center; }

/* ---------- Sections ---------- */
.section {
  max-width: 980px;
  margin: 0 auto;
  padding: 4rem 1.5rem;
}

.section h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 2rem;
  text-align: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 980px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  font-family: var(--font);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); opacity: 1; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-secondary); opacity: 1; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; opacity: 1; }

.btn-full { width: 100%; }
.btn-sm { padding: 0.375rem 0.875rem; font-size: 0.8125rem; }

/* ---------- Grid ---------- */
.grid-2, .grid-3 {
  display: grid;
  gap: 1.25rem;
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2.5rem; }
  .hero-sub { font-size: 1.25rem; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-lg); }

.card-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.card p { color: var(--text-muted); font-size: 0.875rem; }

.card-wide {
  max-width: 680px;
  margin: 0 auto;
  text-align: center;
}

.card-wide p { margin-bottom: 1rem; }

.code-block {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  margin: 0.75rem 0;
}

.code-block code {
  font-family: "SF Mono", Menlo, Monaco, monospace;
  font-size: 0.8125rem;
  color: var(--text);
}

code {
  font-family: "SF Mono", Menlo, Monaco, monospace;
  font-size: 0.8125rem;
  background: var(--bg-secondary);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
}

/* ---------- Auth pages ---------- */
.auth-section {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 120px);
  padding: 2rem 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.25rem;
}

.auth-sub { color: var(--text-muted); margin-bottom: 2rem; font-size: 0.9375rem; }

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.auth-footer a { color: var(--text); font-weight: 500; }

/* ---------- Form ---------- */
.field { margin-bottom: 1.25rem; }

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--text);
}

.field input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  transition: border-color var(--transition);
  outline: none;
}

.field input:focus { border-color: var(--accent); }

.field input::placeholder { color: var(--text-muted); opacity: 0.6; }

/* ---------- Alerts ---------- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
  border: 1px solid;
}

.alert-error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }
.alert-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }

/* ---------- Authorize ---------- */
.authorize-card { max-width: 440px; }

.authorize-header { text-align: center; margin-bottom: 1.5rem; }

.authorize-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  object-fit: cover;
  margin-bottom: 0.75rem;
}

.authorize-logo-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.authorize-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.authorize-origin {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.authorize-info { margin-bottom: 1.5rem; font-size: 0.9375rem; }

.scope-list { margin-top: 1rem; }
.scope-label { font-size: 0.8125rem; font-weight: 500; margin-bottom: 0.5rem; }
.scope-list ul { list-style: none; }
.scope-list li {
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.875rem;
}
.scope-list li::before { content: "•"; margin-right: 0.5rem; color: var(--text-muted); }

.authorize-actions { display: flex; gap: 0.75rem; }
.authorize-actions .btn { flex: 1; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: 980px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge-verified { background: var(--success); color: #fff; }
.badge-test { background: var(--warn-border); color: #fff; }
.badge-pending { background: var(--text-muted); color: #fff; }
.badge-sm { font-size: 0.625rem; padding: 0.125rem 0.5rem; }

/* ---------- Dashboard ---------- */
.dashboard {
  max-width: 800px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

.dashboard-header {
  margin-bottom: 2.5rem;
}

.dashboard-header h1 {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.dashboard-grid { display: flex; flex-direction: column; gap: 1.5rem; }

.panel {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.count {
  background: var(--bg-secondary);
  padding: 0.125rem 0.5rem;
  border-radius: 980px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.panel-body { padding: 1.5rem; }

.profile-field {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: 0.9375rem;
}
.profile-field + .profile-field { border-top: 1px solid var(--border-light); }
.profile-field .label { color: var(--text-muted); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 1rem 0;
}

/* ---------- Grants ---------- */
.grant-list { display: flex; flex-direction: column; }

.grant-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  gap: 1rem;
}
.grant-item + .grant-item { border-top: 1px solid var(--border-light); }

.grant-name { font-weight: 600; font-size: 0.9375rem; display: flex; align-items: center; gap: 0.5rem; }
.grant-origin { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.125rem; }
.grant-scope { margin-top: 0.375rem; display: flex; gap: 0.375rem; flex-wrap: wrap; }
.grant-scope code { font-size: 0.6875rem; }
.grant-date { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ---------- Domains ---------- */
.domain-form {
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
}

.domain-list { display: flex; flex-direction: column; }

.domain-item { padding: 1rem 0; }
.domain-item + .domain-item { border-top: 1px solid var(--border-light); }

.domain-name { font-weight: 600; font-size: 0.9375rem; display: flex; align-items: center; gap: 0.5rem; }
.domain-app { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.125rem; }
.domain-txt { margin-top: 0.75rem; font-size: 0.8125rem; }
.domain-txt p { margin-bottom: 0.25rem; color: var(--text-muted); }

/* ---------- Username Check ---------- */
.username-status {
  margin-top: 0.375rem;
  min-height: 1.25rem;
  font-size: 0.8125rem;
  line-height: 1.4;
}
.status-ok {
  color: var(--success);
  font-family: "SF Mono", Menlo, Monaco, monospace;
  font-size: 0.8125rem;
}
.status-taken { color: var(--danger); font-weight: 500; }
.status-checking { color: var(--text-muted); }
.status-error { color: var(--danger); }

.suggestions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.suggestion-btn { cursor: pointer; }

.optional-section {
  margin-bottom: 1.25rem;
}
.optional-section summary {
  cursor: pointer;
  font-size: 0.8125rem;
  padding: 0.5rem 0;
  user-select: none;
}
.optional-section summary:hover { color: var(--text); }
.optional-fields {
  padding-top: 0.75rem;
}

.alert-success {
  background: #f0fdf4;
  border-color: var(--success);
  color: #166534;
}
html.dark .alert-success {
  background: #0e1c0e;
  color: #86efac;
}

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
