/* ---------------------------------------------------------------------
   Design tokens. Palette: a clinical chart-paper ground with a deep
   surgical-teal accent, a warm amber for "locked/in progress", and a
   restrained clinical green/red reserved for correct/incorrect state.
   Type: Spectral (serif, textbook/pharmacopeia character) for headings,
   IBM Plex Sans for interface text, IBM Plex Mono for scores and counts
   (tabular figures -- reads like a vitals readout).
   --------------------------------------------------------------------- */

:root {
  --bg: #f8f7f5;
  --surface: #ffffff;
  --surface-2: #eaf1ee;
  --ink: #172420;
  --ink-muted: #5d6d67;
  --border: #d9e4df;

  --accent: #0f6e6a;
  --accent-ink: #0a4f4c;
  --accent-tint: #e2f1ef;

  --locked: #96774a;
  --locked-tint: #f4ead9;

  --good: #2f7d4f;
  --good-tint: #e5f3ea;
  --good-ink: #1b4a2f;

  --bad: #b23b32;
  --bad-tint: #fbe9e7;
  --bad-ink: #7a2921;

  --shadow: 0 1px 2px rgba(15, 30, 26, 0.05), 0 6px 20px rgba(15, 30, 26, 0.06);
  --radius: 16px;
  --radius-sm: 10px;

  --font-display: "Spectral", Georgia, "Iowan Old Style", serif;
  --font-body: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101815;
    --surface: #172420;
    --surface-2: #1e2e28;
    --ink: #e9f2ee;
    --ink-muted: #91a29b;
    --border: #2b3d36;

    --accent: #4fb3ac;
    --accent-ink: #b7e6e1;
    --accent-tint: #1c3733;

    --locked: #d3ac6c;
    --locked-tint: #33291a;

    --good: #6cc78f;
    --good-tint: #1a3324;
    --good-ink: #bfe9cf;

    --bad: #e58077;
    --bad-tint: #3a1f1c;
    --bad-ink: #f3bab3;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #101815;
  --surface: #172420;
  --surface-2: #1e2e28;
  --ink: #e9f2ee;
  --ink-muted: #91a29b;
  --border: #2b3d36;

  --accent: #4fb3ac;
  --accent-ink: #b7e6e1;
  --accent-tint: #1c3733;

  --locked: #d3ac6c;
  --locked-tint: #33291a;

  --good: #6cc78f;
  --good-tint: #1a3324;
  --good-ink: #bfe9cf;

  --bad: #e58077;
  --bad-tint: #3a1f1c;
  --bad-ink: #f3bab3;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 18px 72px;
  min-height: 100vh;
}

/* Home screen only: widen on desktop so the category card grid gets
   reference-sized cards instead of being squeezed into the narrow,
   reading-optimized width every other (text-heavy) screen uses. Capped
   at 960px (not scaled further on very wide screens) to match the Skool
   classroom reference, whose content column stays a fixed ~910px
   regardless of viewport width -- letting it keep growing past that
   made the cards oversized. */
@media (min-width: 900px) {
  #app.app-wide { max-width: 960px; }
}

/* ---------- Header / nav ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.topbar h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 23px;
  margin: 0;
  flex: 1;
  letter-spacing: 0.01em;
}

.back-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}
.back-btn:hover { background: var(--surface-2); }
.back-btn.icon-btn {
  padding: 9px 11px;
  font-size: 16px;
  line-height: 1;
}
.back-btn:focus-visible, .card:focus-visible, .btn:focus-visible,
.option:focus-visible, .mode-card:focus-visible, .level-row.clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.eyebrow {
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}

.subtitle {
  color: var(--ink-muted);
  font-size: 14.5px;
  line-height: 1.5;
  margin: 0 0 22px;
  max-width: 72ch;
}

.quote {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--ink-muted);
  font-size: 15px;
  line-height: 1.5;
  margin: -8px 0 22px;
  max-width: 52ch;
}

.quote-prompt {
  color: var(--ink-muted);
  font-size: 13.5px;
  line-height: 1.5;
  margin: -10px 0 22px;
}

/* ---------- Category grid (home) ---------- */

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

@media (min-width: 560px) {
  .card-grid.categories { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 860px) {
  .card-grid.categories { grid-template-columns: 1fr 1fr 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  text-align: left;
  font-family: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(15,30,26,0.1), 0 14px 28px rgba(15,30,26,0.12); }
.card:active { transform: translateY(0); }

.card-banner {
  aspect-ratio: 16 / 9;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-banner-icon {
  font-size: 64px;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.28));
}

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  font-size: 16px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-title-icon { font-size: 17px; line-height: 1; flex-shrink: 0; }
.card-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.card p { margin: 0 0 10px; font-size: 14px; font-weight: 400; color: var(--ink-muted); }

.card-progress-track {
  height: 20px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.card-progress-fill {
  height: 100%;
  min-width: 40px;
  border-radius: 999px;
  background: #22c55e;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 10px;
  transition: width 0.3s ease;
}
.card-progress-label {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
}

.card.is-locked {
  cursor: not-allowed;
  box-shadow: none;
}
.card.is-locked:hover { transform: none; box-shadow: none; }
.card.is-locked .card-banner { filter: grayscale(0.7) brightness(0.8); }
.card.is-locked h3 { color: var(--locked); }
.card.is-locked p { margin-bottom: 0; color: var(--ink-muted); }

/* ---------- Level list (chart-flowsheet style rows) ---------- */

.level-row {
  display: flex;
  align-items: center;
  gap: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
}
.level-row.locked { border-left-color: var(--locked); }
.level-row.locked .level-info h4,
.level-row.locked .level-info span { opacity: 0.65; }
.level-row.current { border-left-color: var(--accent); }
.level-row.cleared-row { border-left-color: var(--good); }
.level-row.clickable { cursor: pointer; }
.level-row.clickable:hover { background: var(--surface-2); }

.level-badge {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  font-family: var(--font-mono);
  flex-shrink: 0;
  background: var(--surface-2);
  color: var(--ink-muted);
}
.level-badge.cleared { background: var(--good-tint); color: var(--good-ink); }
.level-badge.current { background: var(--accent-tint); color: var(--accent-ink); }
.level-badge.locked-badge { background: var(--locked-tint); color: var(--locked); font-size: 13px; }

.level-info { flex: 1; min-width: 0; }
.level-info h4 { margin: 0 0 2px; font-size: 15px; font-weight: 600; }
.level-info span { font-size: 12.5px; color: var(--ink-muted); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.pill {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-muted);
  white-space: nowrap;
}
.pill.cleared { background: var(--good-tint); color: var(--good-ink); }

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-ink);
}

/* ---------- Home tabs (Topics / Crash Course / Progress) ---------- */

.home-tabs {
  display: flex;
  gap: 22px;
  border-bottom: 1px solid var(--border);
  margin: 4px 0 22px;
}
.home-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 4px 2px 12px;
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
}
.home-tab:hover { color: var(--ink); }
.home-tab.active { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- Progress tab (avatar card + tier list) ---------- */

.progress-tab-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 700px) {
  .progress-tab-layout { grid-template-columns: 280px 1fr; align-items: start; }
}

.progress-avatar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
}

.progress-avatar-wrap {
  position: relative;
  margin-bottom: 10px;
}
.progress-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.progress-avatar-emoji { font-size: 38px; filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.25)); }
.progress-avatar-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--surface);
}

.progress-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  margin: 4px 0 0;
  color: var(--ink);
}
.progress-current-line { margin: 0 0 14px; font-size: 13.5px; color: var(--ink-muted); }
.progress-current-line strong { color: var(--ink); }

.progress-stats-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
}
.progress-stats-row .stat-pill { justify-content: center; margin: 0; }

.progress-tier-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: #026CAA;
  color: #f4fbfa;
  width: 100%;
}
.btn:hover { filter: brightness(0.93); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn.secondary:hover { background: var(--surface-2); }

/* ---------- Mode picker ---------- */

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}
@media (max-width: 480px) { .mode-grid { grid-template-columns: 1fr; } }

.mode-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 16px;
  box-shadow: var(--shadow);
  text-align: center;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}
.mode-card:hover { background: var(--surface-2); }
.mode-card .icon { font-size: 26px; margin-bottom: 10px; }
.mode-card h3 { font-family: var(--font-display); font-weight: 600; margin: 0 0 4px; font-size: 16.5px; }
.mode-card p { margin: 0; font-size: 12.5px; color: var(--ink-muted); line-height: 1.4; }

/* ---------- Progress header (study/quiz) ---------- */

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 9px;
}
.progress-header span:last-child {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- Flashcard (study mode) ---------- */

.flashcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 320px;
  padding: 30px 26px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
  margin-bottom: 16px;
}
.flashcard .label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
}
.flashcard .stem {
  font-family: var(--font-display);
  font-size: 19px;
  line-height: 1.5;
}
.flashcard .answer-block { margin-top: 20px; }
.flashcard .answer-line {
  font-size: 16px;
  font-weight: 600;
  color: var(--good-ink);
  margin-bottom: 8px;
}
.flashcard .rationale {
  font-size: 16px;
  color: var(--ink-muted);
  line-height: 1.6;
}
.flashcard .tap-hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--ink-muted);
  text-align: center;
}

.nav-row {
  display: flex;
  gap: 10px;
}

/* ---------- Quiz ---------- */

.question-stem {
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1.5;
  margin-bottom: 18px;
}
.question-stem em { color: var(--accent-ink); font-style: normal; font-family: var(--font-body); font-size: 13px; font-weight: 600; }

.option {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  margin-bottom: 10px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1.45;
}
.option:hover { border-color: #026CAA; }
.option.selected { border-color: #026CAA; background: rgba(2, 108, 170, 0.16); }
.option.correct { border-color: var(--good); background: var(--good-tint); }
.option.incorrect { border-color: var(--bad); background: var(--bad-tint); }
.option .key {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink-muted);
  flex-shrink: 0;
}
.option.correct .key { color: var(--good-ink); }
.option.incorrect .key { color: var(--bad-ink); }
.option input { margin-top: 3px; flex-shrink: 0; accent-color: var(--accent); }

.feedback-box {
  border-radius: 12px;
  padding: 15px 17px;
  margin: 6px 0 16px;
  font-size: 16px;
  line-height: 1.6;
}
.feedback-box.good { background: var(--good-tint); color: var(--good-ink); }
.feedback-box.bad { background: var(--bad-tint); color: var(--bad-ink); }
.feedback-box .verdict { font-family: var(--font-display); font-weight: 600; font-size: 17px; margin-bottom: 5px; }
.feedback-box .correct-ans-line { font-weight: 600; margin-bottom: 8px; }

/* ---------- Results ---------- */

.results-hero {
  text-align: center;
  padding: 30px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.results-hero .score {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 44px;
  font-weight: 600;
  margin: 8px 0;
}
.results-hero.pass .score { color: var(--good-ink); }
.results-hero.fail .score { color: var(--bad-ink); }
.results-hero .msg { font-size: 15px; color: var(--ink-muted); max-width: 42ch; margin: 0 auto; }

.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  font-size: 14px;
}
.review-item .q { font-weight: 600; margin-bottom: 7px; font-family: var(--font-display); font-size: 15px; }
.review-item .your-ans { color: var(--bad-ink); margin-bottom: 3px; }
.review-item .correct-ans { color: var(--good-ink); }

.footer-note {
  text-align: center;
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 30px;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: inherit;
  color: #026CAA;
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: #01547f; }
.link-btn.sign-out {
  margin-left: 6px;
}

/* ---------- Profile form ---------- */

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 420px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-muted);
}

.form-field input,
.form-field select,
.form-field textarea {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 400;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: #026CAA;
}

.profile-form .btn { width: auto; padding: 12px 28px; align-self: flex-start; }

/* ---------- Google Sign-In gate (Vercel deployment only) ---------- */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-gate[hidden] { display: none; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 21px;
  margin: 0 0 8px;
}

.auth-card .subtitle {
  margin: 0 0 22px;
  max-width: none;
}

.google-signin-btn {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.auth-error {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--bad-ink);
  background: var(--bad-tint);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ---------- Paywall (Vercel deployment only) ---------- */

#paywall-card { max-width: 480px; }

.tier-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 4px 0 0;
}
@media (max-width: 480px) { .tier-grid { grid-template-columns: 1fr; } }

.tier-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 10px;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}
.tier-card:hover { border-color: #026CAA; }
.tier-card:disabled { opacity: 0.5; cursor: not-allowed; }

.tier-price {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
}
.tier-label { font-size: 12.5px; color: var(--ink-muted); }
.tier-save {
  margin-top: 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--good-ink);
  background: var(--good-tint);
  border-radius: 999px;
  padding: 3px 8px;
}

.access-note {
  font-size: 13px;
  color: var(--ink-muted);
  margin: -6px 0 18px;
}

/* ---------- Mobile: bump reading/interactive text sizes up a notch ---------- */

@media (max-width: 600px) {
  .topbar h1 { font-size: 25px; }
  .eyebrow { font-size: 12.5px; }
  .subtitle { font-size: 16px; }
  .quote { font-size: 16.5px; }
  .quote-prompt { font-size: 15px; }

  .card h3 { font-size: 18.5px; }
  .card p { font-size: 14.5px; }

  .level-info h4 { font-size: 16.5px; }
  .level-info span { font-size: 13.5px; }
  .pill { font-size: 12px; }

  .stat-pill { font-size: 14.5px; }
  .home-tab { font-size: 15.5px; }
  .progress-name { font-size: 19px; }

  .mode-card h3 { font-size: 18px; }
  .mode-card p { font-size: 14px; }

  .question-stem { font-size: 20px; }
  .option { font-size: 16.5px; }
  .feedback-box { font-size: 17px; }
  .feedback-box .verdict { font-size: 18.5px; }

  .flashcard .stem { font-size: 21px; }
  .flashcard .answer-line { font-size: 17.5px; }
  .flashcard .rationale { font-size: 17px; }

  .results-hero .msg { font-size: 16.5px; }
  .review-item { font-size: 15.5px; }
  .review-item .q { font-size: 16.5px; }

  .back-btn { font-size: 15px; }
  .btn { font-size: 16.5px; }

  .form-field { font-size: 15px; }
  .form-field input,
  .form-field select,
  .form-field textarea { font-size: 16.5px; }
}
