/* ── Design Tokens ─────────────────────────────────────────────────────── */

:root {
  /* Type Scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* Fonts */
  --font-display: 'General Sans', 'Inter', sans-serif;
  --font-body: 'Satoshi', 'Inter', sans-serif;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Content widths */
  --content-narrow: 640px;
  --content-default: 800px;
  --content-wide: 1000px;
}

/* ── Color: Education / Knowledge — Deep Navy + Teal Accent ───────────── */

:root, [data-theme="light"] {
  --color-bg:             #f8f9fa;
  --color-surface:        #ffffff;
  --color-surface-2:      #f1f3f5;
  --color-surface-offset: #e9ecef;
  --color-divider:        #dee2e6;
  --color-border:         #ced4da;

  --color-text:           #1a1d23;
  --color-text-muted:     #5c6370;
  --color-text-faint:     #adb5bd;

  --color-primary:        #1B3A6B;
  --color-primary-hover:  #15305a;
  --color-primary-active: #0f2444;
  --color-primary-light:  #e8eef6;

  --color-accent:         #0891b2;
  --color-accent-light:   #ecfeff;

  --color-success:        #10b981;
  --color-success-light:  #d1fae5;
  --color-error:          #ef4444;
  --color-error-light:    #fee2e2;
  --color-warning:        #f59e0b;
  --color-warning-light:  #fef3c7;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
}

[data-theme="dark"] {
  --color-bg:             #0f1117;
  --color-surface:        #161920;
  --color-surface-2:      #1c1f28;
  --color-surface-offset: #22252e;
  --color-divider:        #2a2d36;
  --color-border:         #353840;

  --color-text:           #e1e4ea;
  --color-text-muted:     #8b92a0;
  --color-text-faint:     #4a5060;

  --color-primary:        #5b8dd9;
  --color-primary-hover:  #7ba3e4;
  --color-primary-active: #4a7bc8;
  --color-primary-light:  #1c2640;

  --color-accent:         #22d3ee;
  --color-accent-light:   #0c2d33;

  --color-success:        #34d399;
  --color-success-light:  #0d2e22;
  --color-error:          #f87171;
  --color-error-light:    #2d1515;
  --color-warning:        #fbbf24;
  --color-warning-light:  #2d2210;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:             #0f1117;
    --color-surface:        #161920;
    --color-surface-2:      #1c1f28;
    --color-surface-offset: #22252e;
    --color-divider:        #2a2d36;
    --color-border:         #353840;
    --color-text:           #e1e4ea;
    --color-text-muted:     #8b92a0;
    --color-text-faint:     #4a5060;
    --color-primary:        #5b8dd9;
    --color-primary-hover:  #7ba3e4;
    --color-primary-active: #4a7bc8;
    --color-primary-light:  #1c2640;
    --color-accent:         #22d3ee;
    --color-accent-light:   #0c2d33;
    --color-success:        #34d399;
    --color-success-light:  #0d2e22;
    --color-error:          #f87171;
    --color-error-light:    #2d1515;
    --color-warning:        #fbbf24;
    --color-warning-light:  #2d2210;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
  }
}

/* ── Global Layout ────────────────────────────────────────────────────── */

.app-wrap {
  max-width: var(--content-default);
  margin: 0 auto;
  padding: var(--space-8) var(--space-4);
  min-height: 100dvh;
}

@media (max-width: 640px) {
  .app-wrap {
    padding: var(--space-4) var(--space-3);
  }
}

/* ── Cards ────────────────────────────────────────────────────────────── */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.card-flush {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-body);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  min-height: 44px;
  transition: all var(--transition-interactive);
}

.btn:hover {
  background: var(--color-surface-2);
  border-color: var(--color-text-faint);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* ── Tags ─────────────────────────────────────────────────────────────── */

.tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  letter-spacing: 0.03em;
}

/* ── Labels ───────────────────────────────────────────────────────────── */

.label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── Progress Bar ─────────────────────────────────────────────────────── */

.progress-track {
  height: 4px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* ── Options ──────────────────────────────────────────────────────────── */

.option-btn {
  text-align: left;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-divider);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: 1.6;
  transition: all var(--transition-interactive);
  min-height: 44px;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.option-btn.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.option-btn.correct {
  border-color: var(--color-success);
  background: var(--color-success-light);
  color: var(--color-text);
}

.option-btn.incorrect {
  border-color: var(--color-error);
  background: var(--color-error-light);
  color: var(--color-text);
}

.option-btn:disabled {
  cursor: default;
}

/* ── Textarea ─────────────────────────────────────────────────────────── */

.response-textarea {
  width: 100%;
  min-height: 140px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  line-height: 1.7;
  resize: vertical;
}

.response-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.response-textarea:disabled {
  opacity: 0.7;
  cursor: default;
}

/* ── Feedback Boxes ───────────────────────────────────────────────────── */

.feedback {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.6;
  margin-top: var(--space-4);
}

.feedback-correct {
  background: var(--color-success-light);
  border: 1px solid var(--color-success);
}

.feedback-incorrect {
  background: var(--color-error-light);
  border: 1px solid var(--color-error);
}

.feedback-info {
  background: var(--color-accent-light);
  border: 1px solid var(--color-accent);
}

/* ── Tier Select Grid ─────────────────────────────────────────────────── */

.tier-grid {
  display: grid;
  gap: var(--space-3);
}

.tier-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  text-align: left;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-divider);
  background: var(--color-surface);
  cursor: pointer;
  transition: all var(--transition-interactive);
  min-height: 44px;
}

.tier-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.tier-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.tier-info {
  flex: 1;
  min-width: 0;
}

.tier-label {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  font-family: var(--font-display);
}

.tier-sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.tier-meta {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  flex-shrink: 0;
}

/* ── Results ──────────────────────────────────────────────────────────── */

.score-ring {
  margin: 0 auto var(--space-6);
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

@media (max-width: 640px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}

.results-full {
  grid-column: 1 / -1;
}

.cat-bar-track {
  height: 6px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  margin-top: 4px;
}

.cat-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.8s ease;
}

/* ── Email Form ───────────────────────────────────────────────────────── */

.email-input {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  width: 100%;
  min-height: 44px;
}

.email-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

/* ── Loading Animation ────────────────────────────────────────────────── */

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.spinner {
  display: inline-block;
  animation: spin 1s linear infinite;
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* ── Header ───────────────────────────────────────────────────────────── */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: var(--space-6);
  margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--color-divider);
}

.site-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.site-brand-text {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
  line-height: 1.4;
}

/* ── Theme Toggle ─────────────────────────────────────────────────────── */

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  border: 1px solid var(--color-divider);
  background: var(--color-surface);
}

.theme-toggle:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* ── Utilities ────────────────────────────────────────────────────────── */

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-faint { color: var(--color-text-faint); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
