/* ============================================================
   Hall Pass Go — base.css
   Theme system: every visual choice flows from CSS variables.
   `body[data-grade-band="k2|35|68"]` selects which palette / type
   scale / radius scale is in effect. assets/theme.js sets the
   attribute on every page based on the current user's grade.

   Default (no attribute) = '35' band — Khayir's band, matches the
   legacy GitHub Pages design Dr. Cato approved.
   ============================================================ */

/* ---- font load (one declaration, three bands use different weights) ---- */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Nunito:wght@400;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

/* ============================================================
   THEME TOKENS
   ============================================================ */

/* ---- band: 35 (default — Grades 3-5) ---- */
:root,
body[data-grade-band="35"] {
  --bg-1: #f5f1ff;
  --bg-2: #ffe8f3;
  --bg: linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 100%);

  --ink: #1e1140;
  --muted: #6b6288;
  --surface: #ffffff;
  --surface-soft: #f8f5ff;
  --line: #ebe5fa;

  --primary: #6c5ce7;
  --primary-dark: #5542cf;
  --primary-soft: #eeeaff;
  --accent: #ff6b8b;          /* coral */
  --accent-soft: #ffe1e9;
  --gold: #fcd34d;
  --gold-dark: #e5a81a;
  --success: #10b981;
  --success-soft: #d1fae5;
  --wrong: #ef4444;
  --wrong-soft: #fee2e2;

  --shadow-sm: 0 4px 12px -2px rgba(108, 92, 231, 0.12);
  --shadow:    0 12px 28px -8px rgba(108, 92, 231, 0.22);
  --shadow-lg: 0 24px 48px -12px rgba(108, 92, 231, 0.30);

  --radius:    20px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  --font-display: 'Fredoka', system-ui, sans-serif;
  --font-display-weight: 600;
  --font-body: 'Nunito', system-ui, sans-serif;
  --font-body-weight: 400;
  --font-bold: 700;
  --font-extrabold: 800;
  --font-size-body: 16px;
  --font-size-lg: 18px;
  --line-height: 1.45;
  --letter-tight: -0.01em;
}

/* ---- band: k2 (Grades K-2) — playful, big targets, warmer ---- */
body[data-grade-band="k2"] {
  --bg-1: #fff5e6;
  --bg-2: #ffe1ec;
  --bg: linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 100%);

  --ink: #2a1248;
  --muted: #7d6b8f;
  --surface: #ffffff;
  --surface-soft: #fff8f1;
  --line: #ffe5d6;

  --primary: #ff6b8b;          /* coral PROMOTED to primary in k2 */
  --primary-dark: #e6516f;
  --primary-soft: #ffe1e9;
  --accent: #fcd34d;           /* gold accent */
  --accent-soft: #fff4cc;
  --gold: #fcd34d;
  --gold-dark: #e5a81a;

  --shadow-sm: 0 5px 14px -2px rgba(255, 107, 139, 0.16);
  --shadow:    0 16px 32px -8px rgba(255, 107, 139, 0.25);
  --shadow-lg: 0 28px 56px -12px rgba(255, 107, 139, 0.32);

  --radius:    24px;            /* chunkier corners */
  --radius-sm: 16px;

  --font-display-weight: 700;   /* bolder display */
  --font-body-weight: 600;      /* medium body so it feels solid */
  --font-size-body: 18px;       /* larger body text */
  --font-size-lg: 21px;
  --line-height: 1.55;
}

/* ---- band: 68 (Grades 6-8) — grown-up study tool ---- */
body[data-grade-band="68"] {
  --bg-1: #f5f7fa;
  --bg-2: #eef2f7;
  --bg: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);

  --ink: #0f172a;
  --muted: #64748b;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e2e8f0;

  --primary: #475569;          /* slate primary, less candy */
  --primary-dark: #334155;
  --primary-soft: #e2e8f0;
  --accent: #6366f1;           /* indigo accent */
  --accent-soft: #e0e7ff;
  --gold: #f59e0b;
  --gold-dark: #b45309;

  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04), 0 1px 3px 0 rgba(15, 23, 42, 0.06);
  --shadow:    0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px -8px rgba(15, 23, 42, 0.12);

  --radius:    12px;
  --radius-sm: 8px;

  --font-display: 'Inter', system-ui, sans-serif;
  --font-display-weight: 600;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-body-weight: 400;
  --font-size-body: 15px;
  --font-size-lg: 17px;
  --line-height: 1.55;
  --letter-tight: -0.015em;
}

/* ============================================================
   RESET + GLOBALS
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  font-family: var(--font-body);
  font-weight: var(--font-body-weight);
  font-size: var(--font-size-body);
  color: var(--ink);
  background: var(--bg);
  background-attachment: fixed;
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: var(--font-display-weight);
  letter-spacing: var(--letter-tight);
  margin: 0 0 .4em;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; border: 0; }
input, select, textarea { font-family: inherit; font-size: inherit; }

.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ============================================================
   LAYOUT PRIMITIVES
   ============================================================ */

.screen { max-width: 1100px; margin: 0 auto; padding: 24px 28px 56px; }
@media (max-width: 640px) { .screen { padding: 16px 16px 40px; } }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; gap: 12px; flex-wrap: wrap;
}
.topbar .right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ============================================================
   LOGO
   ============================================================ */

.logo { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; }
.logo-mark {
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 22px; font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.logo-text { font-size: 22px; color: var(--ink); }
.logo-text .tag { color: var(--primary); }

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  background: var(--primary); color: white;
  padding: 14px 24px; border-radius: var(--radius-sm);
  font-weight: var(--font-bold); font-size: 16px; letter-spacing: 0.01em;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
  box-shadow: 0 4px 0 var(--primary-dark), var(--shadow-sm);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; color: white; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn.big { padding: 18px 32px; font-size: 18px; border-radius: var(--radius); }
.btn.secondary {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 4px 0 var(--line), var(--shadow-sm);
}
.btn.secondary:hover { background: var(--surface-soft); color: var(--ink); }
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 var(--gold-dark), var(--shadow-sm); }
.btn.ghost { background: transparent; color: var(--primary); box-shadow: none; padding: 8px 12px; }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.full { width: 100%; }

/* ============================================================
   CARDS / SURFACES
   ============================================================ */

.card {
  background: var(--surface); padding: 24px;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card.tight { padding: 16px; }
.card-soft {
  background: var(--surface-soft); padding: 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
}

/* ============================================================
   FORMS
   ============================================================ */

.field { display: block; margin-bottom: 14px; }
.field label {
  display: block; margin-bottom: 6px;
  font-weight: var(--font-bold); font-size: 14px; color: var(--ink);
}
.input, select.input {
  width: 100%; padding: 13px 14px;
  border: 2px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, select.input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.input.error { border-color: var(--wrong); }
.field .help { font-size: 13px; color: var(--muted); margin-top: 4px; }
.form-error {
  background: var(--wrong-soft); color: var(--wrong);
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px;
  font-weight: var(--font-bold); font-size: 14px;
}
.form-success {
  background: var(--success-soft); color: var(--success);
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px;
  font-weight: var(--font-bold); font-size: 14px;
}

/* ============================================================
   CHIPS + BADGES
   ============================================================ */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius-pill);
  background: var(--surface); box-shadow: var(--shadow-sm);
  font-weight: var(--font-bold); font-size: 13px;
}
.chip.streak { color: #ea580c; }
.chip.xp { color: var(--gold-dark); }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: var(--radius-pill);
  font-weight: var(--font-bold); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase;
}
.badge.free    { background: var(--surface-soft); color: var(--muted); }
.badge.plus    { background: var(--primary-soft); color: var(--primary); }
.badge.premium { background: var(--accent-soft); color: var(--accent); }
.badge.family  { background: var(--success-soft); color: var(--success); }
.badge.institution { background: var(--gold); color: var(--ink); }
.badge.trial   { background: var(--gold); color: var(--ink); }

/* ============================================================
   STAT CARDS / DASHBOARD
   ============================================================ */

.stat-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 640px) { .stat-grid { grid-template-columns: 1fr 1fr; } }

.stat-card {
  background: var(--surface); padding: 18px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  text-align: center;
}
.stat-card .n {
  font-family: var(--font-display); font-weight: var(--font-display-weight);
  font-size: 32px; color: var(--ink);
}
.stat-card .label {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.08em; font-weight: var(--font-bold);
}

/* ---- usage bar (e.g. "12 / 20 questions today") ---- */
.usage-bar {
  height: 8px; background: var(--surface-soft);
  border-radius: var(--radius-pill); overflow: hidden;
  border: 1px solid var(--line);
}
.usage-bar > .fill {
  height: 100%; background: var(--primary); border-radius: var(--radius-pill);
  transition: width 0.3s ease-out;
}
.usage-bar.warn > .fill { background: var(--gold-dark); }
.usage-bar.full > .fill { background: var(--wrong); }

/* ============================================================
   FRACTIONS (used in question stems via <span class="frac">)
   ============================================================ */

.frac {
  display: inline-flex; flex-direction: column; vertical-align: middle;
  text-align: center; font-size: 0.9em; margin: 0 2px; line-height: 1;
  font-weight: var(--font-bold);
}
.frac .top { border-bottom: 1.5px solid currentColor; padding: 0 4px 1px; }
.frac .bot { padding: 1px 4px 0; }
.mixed { margin-right: 2px; font-weight: var(--font-bold); }

/* ============================================================
   PRACTICE RUNNER (universal question UI)
   ============================================================ */

.q-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 28px 32px; box-shadow: var(--shadow);
}
.q-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.q-badge {
  background: var(--primary-soft); color: var(--primary);
  padding: 6px 14px; border-radius: var(--radius-pill);
  font-weight: var(--font-extrabold); font-size: 12px; letter-spacing: 0.08em;
}
.q-topic {
  background: var(--surface-soft); color: var(--muted);
  padding: 6px 12px; border-radius: var(--radius-pill);
  font-weight: var(--font-bold); font-size: 12px; letter-spacing: 0.04em;
}
.q-stem {
  font-size: var(--font-size-lg); line-height: 1.55;
  margin: 12px 0 18px;
}
.q-stem img {
  display: block; margin: 14px auto;
  max-width: 100%; height: auto;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.choices { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.choice {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; border-radius: var(--radius-sm);
  background: var(--surface); border: 2px solid var(--line);
  font-size: 16px; cursor: pointer; transition: all 0.15s; text-align: left;
}
.choice:hover { border-color: var(--primary); background: var(--primary-soft); }
.choice.selected { border-color: var(--primary); background: var(--primary-soft); }
.choice .letter {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface-soft); color: var(--muted);
  font-weight: var(--font-extrabold); font-size: 14px; flex-shrink: 0;
}
.choice.selected .letter { background: var(--primary); color: white; }
.choice.correct {
  border-color: var(--success); background: var(--success-soft);
}
.choice.correct .letter { background: var(--success); color: white; }
.choice.wrong {
  border-color: var(--wrong); background: var(--wrong-soft);
}
.choice.wrong .letter { background: var(--wrong); color: white; }
.choice.disabled { cursor: default; opacity: 0.7; }
.choice .body { flex: 1; }

.fill-input { margin-top: 12px; display: flex; gap: 8px; align-items: center; }
.fill-input .input { flex: 1; }
.fill-input .unit {
  font-weight: var(--font-bold); color: var(--muted); white-space: nowrap;
}

.q-feedback {
  margin-top: 18px; padding: 14px 18px; border-radius: var(--radius-sm);
  font-weight: var(--font-bold);
}
.q-feedback.right { background: var(--success-soft); color: var(--success); }
.q-feedback.wrong { background: var(--wrong-soft); color: var(--wrong); }
.q-feedback .explanation {
  display: block; margin-top: 6px; font-weight: var(--font-body-weight); color: var(--ink);
}

.q-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* Cap-reached notice (free tier hits 20/day) */
.cap-notice {
  margin: 32px 0; padding: 28px;
  background: var(--gold); border-radius: var(--radius);
  text-align: center; box-shadow: var(--shadow);
}
.cap-notice h2 { margin: 0 0 8px; }
.cap-notice p { margin: 0 0 16px; }

/* ============================================================
   TUTOR CHAT
   ============================================================ */

.chat-shell {
  display: grid; grid-template-columns: 280px 1fr; gap: 16px;
  height: calc(100vh - 140px); min-height: 500px;
}
@media (max-width: 820px) {
  .chat-shell { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .chat-sidebar { display: none; }
  .chat-sidebar.open { display: block; height: 50vh; }
}
.chat-sidebar {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
  overflow-y: auto;
}
.chat-sidebar h3 {
  font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 0 0 12px;
}
.chat-thread-row {
  padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px; line-height: 1.35;
  margin-bottom: 4px;
}
.chat-thread-row:hover { background: var(--surface-soft); }
.chat-thread-row.active { background: var(--primary-soft); color: var(--primary); font-weight: var(--font-bold); }
.chat-thread-row .meta {
  font-size: 11px; color: var(--muted); display: block; margin-top: 2px;
  text-transform: uppercase; letter-spacing: 0.05em;
}

.chat-main {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  overflow: hidden;
}
.chat-header {
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  font-weight: var(--font-bold); font-size: 15px;
  display: flex; align-items: center; gap: 10px;
}
.chat-header .hoot {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: var(--font-extrabold); font-size: 14px;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 18px 22px;
  display: flex; flex-direction: column; gap: 14px;
}
.chat-bubble {
  max-width: 75%; padding: 12px 16px; border-radius: var(--radius);
  font-size: 15px; line-height: 1.5;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary); color: white;
  border-bottom-right-radius: 6px;
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--surface-soft); color: var(--ink);
  border-bottom-left-radius: 6px;
}
.chat-bubble.thinking {
  align-self: flex-start; background: var(--surface-soft); color: var(--muted);
  font-style: italic;
}
.chat-input {
  padding: 14px 18px; border-top: 1px solid var(--line);
  display: flex; gap: 10px; align-items: flex-end;
}
.chat-input textarea {
  flex: 1; min-height: 44px; max-height: 140px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 2px solid var(--line); font-size: 15px; resize: vertical;
  font-family: inherit;
}
.chat-input textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.chat-empty {
  padding: 32px; text-align: center; color: var(--muted);
}
.chat-cap-warning {
  background: var(--gold); color: var(--ink); padding: 10px 14px;
  border-radius: var(--radius-sm); margin: 12px 22px 0;
  font-weight: var(--font-bold); font-size: 13px; text-align: center;
}

/* ============================================================
   AUTH PAGES
   ============================================================ */

.auth-shell {
  max-width: 460px; margin: 6vh auto;
  padding: 24px;
}
.auth-shell h1 {
  font-size: 32px; text-align: center; margin: 0 0 8px;
}
.auth-shell .subtitle {
  text-align: center; color: var(--muted);
  margin: 0 0 28px; font-size: 15px;
}

/* ============================================================
   LANDING PAGE
   ============================================================ */

.hero {
  text-align: center; padding: 6vh 16px 4vh;
}
.hero h1 {
  font-size: 56px; margin: 0 0 16px;
}
@media (max-width: 640px) { .hero h1 { font-size: 38px; } }
.hero .lead {
  font-size: 19px; color: var(--muted); max-width: 640px; margin: 0 auto 28px;
}
.hero .cta-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

/* ============================================================
   PRICING
   ============================================================ */

.pricing-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px;
  margin-top: 28px;
}
@media (max-width: 1080px) { .pricing-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 540px)  { .pricing-grid { grid-template-columns: 1fr; } }
.pricing-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.pricing-card.highlight {
  outline: 3px solid var(--primary); transform: translateY(-4px);
}
.pricing-card .price {
  font-family: var(--font-display); font-weight: var(--font-display-weight);
  font-size: 32px; color: var(--ink);
}
.pricing-card .price small { font-size: 14px; color: var(--muted); font-weight: 400; }
.pricing-card .bullets {
  list-style: none; padding: 0; margin: 8px 0 16px; flex: 1;
}
.pricing-card .bullets li {
  padding: 6px 0 6px 22px; position: relative; font-size: 14px;
}
.pricing-card .bullets li::before {
  content: '✓'; color: var(--success);
  position: absolute; left: 0; font-weight: var(--font-extrabold);
}
