/* ============================================================
   ExamPrep — Midnight / Iris
   Light by default, Midnight dark via prefers-color-scheme or
   [data-theme="dark"] (set by the header toggle, see app.js).
   Geist type, iris accent, green = correct, red-orange = wrong.
   ============================================================ */

/* ---------- Theme tokens ---------- */
:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --line: #e4e6eb;
  --line-strong: #d3d6dd;
  --header-bg: rgba(244, 245, 247, 0.82);
  --nav-bg: rgba(255, 255, 255, 0.94);

  /* Inks */
  --ink: #0b0c10;
  --solid: #2a2d35; /* filled pills, toasts, selected states */
  --body: #3a3f4a;
  --muted: #5b616e;
  --faint: #8a909c;

  /* Accent: Iris */
  --accent: #6c55f5;
  --accent-hover: #5a43e0;
  --on-accent: #ffffff;
  --accent-text: #5a43e0;
  --accent-soft: #ece8ff;
  --accent-border: #cfc6ff;
  --accent-glow: rgba(108, 85, 245, 0.22);
  --accent-field: #ffffff;

  /* Semantics */
  --ok: #15803d;
  --ok-solid: #22a55b;
  --ok-soft: #e7f7ec;
  --ok-border: #9bd8ae;
  --bad: #b3261e;
  --bad-solid: #e5533f;
  --bad-soft: #fff0ed;
  --bad-border: #f6c1b8;
  --warm: #b4500f;
  --warm-soft: #fff1e6;
  --warm-border: #fbd3b4;

  /* Inverse (one dark card per screen) */
  --inverse-bg: var(--solid);
  --inverse-ink: #f2f3f5;
  --inverse-muted: #b0b5c0;
  --inverse-line: #3a3e48;


  /* Heatmap ramp (empty → most active) */
  --heat-0: #eceef1;
  --heat-1: #ddd6ff;
  --heat-2: #b4a6ff;
  --heat-3: #8a74fb;
  --heat-4: #5a43e0;

  /* Subject tiles (hue from --h) */
  --tile-s: 70%;
  --tile-bg-l: 95%;
  --tile-fg-l: 32%;
  --tile-border-l: 88%;

  /* Geometry */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 22px;
  --r-pill: 9999px;

  --shadow-sm: 0 1px 2px rgba(11, 12, 16, 0.05);
  --shadow-md: 0 6px 18px rgba(11, 12, 16, 0.07);
  --shadow-xl: 0 20px 40px rgba(11, 12, 16, 0.16);

  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --max-w: 1200px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0c10;
    --surface: #14161c;
    --surface-2: #1b1e26;
    --line: #23262f;
    --line-strong: #2e323c;
    --header-bg: rgba(11, 12, 16, 0.82);
    --nav-bg: rgba(28, 31, 39, 0.94);
    --ink: #f2f3f5;
    --solid: #f2f3f5;
    --body: #c9ccd3;
    --muted: #9aa0ac;
    --faint: #6b7180;
    --accent: #9d8cff;
    --accent-hover: #b3a6ff;
    --on-accent: #0b0c10;
    --accent-text: #b3a6ff;
    --accent-soft: #221d3d;
    --accent-border: #3c3470;
    --accent-glow: rgba(157, 140, 255, 0.25);
    --accent-field: rgba(11, 12, 16, 0.88);
    --ok: #4ade80;
    --ok-solid: #4ade80;
    --ok-soft: #12261a;
    --ok-border: #1f5133;
    --bad: #ff8a7a;
    --bad-solid: #ff7a6b;
    --bad-soft: #2a1512;
    --bad-border: #5c2a22;
    --warm: #ffa45c;
    --warm-soft: #2a1c10;
    --warm-border: #4d3218;
    --inverse-bg: #1b1e26;
    --inverse-ink: #f2f3f5;
    --inverse-muted: #9aa0ac;
    --inverse-line: #2e323c;
    --heat-0: #1d2028;
    --heat-1: #2c2552;
    --heat-2: #4a3d99;
    --heat-3: #7865e6;
    --heat-4: #9d8cff;
    --tile-s: 45%;
    --tile-bg-l: 18%;
    --tile-fg-l: 80%;
    --tile-border-l: 26%;
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c10;
  --surface: #14161c;
  --surface-2: #1b1e26;
  --line: #23262f;
  --line-strong: #2e323c;
  --header-bg: rgba(11, 12, 16, 0.82);
  --nav-bg: rgba(28, 31, 39, 0.94);
  --ink: #f2f3f5;
  --solid: #f2f3f5;
  --body: #c9ccd3;
  --muted: #9aa0ac;
  --faint: #6b7180;
  --accent: #9d8cff;
  --accent-hover: #b3a6ff;
  --on-accent: #0b0c10;
  --accent-text: #b3a6ff;
  --accent-soft: #221d3d;
  --accent-border: #3c3470;
  --accent-glow: rgba(157, 140, 255, 0.25);
  --accent-field: rgba(11, 12, 16, 0.88);
  --ok: #4ade80;
  --ok-solid: #4ade80;
  --ok-soft: #12261a;
  --ok-border: #1f5133;
  --bad: #ff8a7a;
  --bad-solid: #ff7a6b;
  --bad-soft: #2a1512;
  --bad-border: #5c2a22;
  --warm: #ffa45c;
  --warm-soft: #2a1c10;
  --warm-border: #4d3218;
  --inverse-bg: #1b1e26;
  --inverse-ink: #f2f3f5;
  --inverse-muted: #9aa0ac;
  --inverse-line: #2e323c;
  --heat-0: #1d2028;
  --heat-1: #2c2552;
  --heat-2: #4a3d99;
  --heat-3: #7865e6;
  --heat-4: #9d8cff;
  --tile-s: 45%;
  --tile-bg-l: 18%;
  --tile-fg-l: 80%;
  --tile-border-l: 26%;
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.5);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  color: var(--ink);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 0 0 0.5rem;
}
h1 { font-size: 2.25rem; letter-spacing: -0.04em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.75rem; color: var(--body); }
a { color: var(--accent-text); text-decoration: none; font-weight: 500; transition: color 0.15s ease; }
a:hover { color: var(--accent-hover); }
code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 0.05rem 0.35rem; }
::selection { background: var(--accent-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 200;
  background: var(--solid); color: var(--bg); padding: 0.6rem 1.2rem;
  border-radius: var(--r); font-weight: 600; transition: top 0.15s;
}
.skip-link:focus { top: 1rem; }

/* ---------- App Shell ---------- */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.screen {
  flex: 1;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 1.25rem 1rem calc(110px + env(safe-area-inset-bottom));
}
@media (min-width: 768px) {
  .screen { padding: 2rem 2rem 4rem; }
}

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 60;
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
@media (min-width: 768px) {
  .header-inner { padding: 0.9rem 2rem; }
}

.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; font-size: 1.3rem; letter-spacing: -0.04em; color: var(--ink); }
.brand-accent { color: var(--accent-text); transition: color 0.2s ease; }
.brand:hover .brand-accent { color: var(--accent); }
.brand-tier {
  font-family: var(--mono); font-size: 0.6rem; font-weight: 500; letter-spacing: 0.08em;
  color: var(--muted); text-transform: uppercase;
}
@media (max-width: 767px) {
  .brand-tier { display: none; }
}

.desktop-nav {
  display: none; align-items: center; gap: 2px;
  padding: 4px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
}
@media (min-width: 900px) {
  .desktop-nav { display: flex; }
}
.desktop-nav a {
  padding: 0.4rem 0.85rem; border-radius: var(--r-sm);
  font-size: 0.875rem; font-weight: 500; color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.desktop-nav a:hover { color: var(--ink); background: var(--surface-2); }
.desktop-nav a[aria-current="page"] { color: var(--bg); background: var(--solid); }

.header-right { display: flex; align-items: center; gap: 0.5rem; }

.streak-pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  height: 36px; padding: 0 0.75rem; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink); font-family: var(--mono); font-weight: 500; font-size: 0.8rem;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.streak-flame { color: var(--warm); display: inline-flex; }

.btn-header-cta { display: none; }
@media (min-width: 1100px) {
  .btn-header-cta { display: inline-flex; }
}

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r); cursor: pointer; flex: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.theme-btn .icon-sun { display: none; }
.theme-btn .icon-moon { display: block; }
:root[data-theme="dark"] .theme-btn .icon-sun { display: block; }
:root[data-theme="dark"] .theme-btn .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-btn .icon-moon { display: none; }
}

.avatar-btn {
  width: 36px; height: 36px; border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.avatar-btn:hover { color: var(--ink); border-color: var(--line-strong); }

.auth-area { display: inline-flex; }
.user-chip {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 0.2rem 0.5rem 0.2rem 0.2rem;
  max-width: 220px;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: var(--r-sm); flex: none;
  background: var(--accent); color: var(--on-accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.8rem;
}
.user-name { font-weight: 500; font-size: 0.82rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-signout {
  border: 0; background: none; padding: 0.2rem 0.3rem; cursor: pointer; flex: none;
  font: inherit; font-size: 0.75rem; font-weight: 500; color: var(--muted);
}
.user-signout:hover { color: var(--ink); }

/* Mobile menu */
.menu-btn {
  display: none;
  width: 40px; height: 40px; border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  align-items: center; justify-content: center; flex: none;
}
.menu-panel { display: none; }
@media (max-width: 767px) {
  .header-inner { position: relative; }
  .header-right .streak-pill,
  .header-right .btn-header-cta,
  .header-right .auth-area { display: none; }
  .menu-btn { display: inline-flex; }
  .menu-panel.open {
    display: flex; flex-direction: column; gap: 0.75rem;
    position: absolute; top: calc(100% + 8px); right: 1rem;
    width: min(19rem, calc(100vw - 2rem));
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); box-shadow: var(--shadow-xl);
    padding: 1rem; z-index: 70;
  }
}
.menu-streak {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink); border-radius: var(--r);
  padding: 0.6rem 0.85rem; font-family: var(--mono); font-weight: 500; font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.menu-streak .streak-flame { color: var(--warm); }
.menu-streak-sub { font-family: var(--font); font-weight: 400; font-size: 0.78rem; color: var(--muted); }
.menu-link {
  display: block; text-align: center; font-weight: 500; font-size: 0.9rem;
  color: var(--accent-text); padding: 0.35rem 0;
}
.menu-auth { display: flex; }
.menu-auth .user-chip { max-width: none; flex: 1; }
.menu-auth .user-name { flex: 1; }
.menu-auth .btn { flex: 1; }

/* ---------- Floating Tab Bar (mobile) ---------- */
.tabbar {
  position: fixed; z-index: 60;
  left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  height: 64px; padding: 8px;
  background: var(--nav-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  box-shadow: var(--shadow-xl);
}
@media (min-width: 768px) {
  .tabbar { display: none; }
}
.tabbar a {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--muted); font-size: 0.78rem; font-weight: 500;
  border-radius: 16px; text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.tabbar a span { display: none; }
.tabbar a:hover { color: var(--ink); }
.tabbar a[aria-current="page"] { background: var(--solid); color: var(--bg); font-weight: 600; }
.tabbar a[aria-current="page"] span { display: inline; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  font: inherit; font-weight: 600; font-size: 0.9rem;
  height: 42px; padding: 0 1.1rem; border-radius: var(--r); cursor: pointer; white-space: nowrap;
  border: 1px solid transparent; text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: var(--on-accent) !important; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--line-strong); background: var(--surface-2); color: var(--ink); }

.btn-cream { background: var(--solid); color: var(--bg) !important; }
.btn-cream:hover { opacity: 0.9; }

.btn-danger { background: var(--bad-solid); color: #ffffff !important; }
.btn-danger:hover { filter: brightness(0.92); }

.btn-sm { height: 34px; padding: 0 0.8rem; font-size: 0.82rem; border-radius: 10px; }
.btn-lg { height: 50px; padding: 0 1.5rem; font-size: 0.98rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 1.4rem;
}

.x-btn {
  width: 36px; height: 36px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 1.25rem; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.x-btn:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 1.15rem; }
.field-label {
  display: block; font-weight: 500; font-size: 0.85rem; color: var(--muted);
  margin-bottom: 0.45rem;
}
fieldset.field { border: 0; padding: 0; margin: 0 0 1.15rem; }
fieldset.field legend { padding: 0; margin-bottom: 0.45rem; }

input[type="email"], input[type="text"], input[type="search"], select, textarea {
  font: inherit; font-weight: 500; width: 100%; padding: 0.7rem 0.9rem;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
select option, select optgroup { background: var(--surface); color: var(--ink); }
textarea { resize: vertical; min-height: 4.5rem; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 4px var(--accent-glow);
}
select[disabled] { opacity: 0.55; cursor: not-allowed; }

.link-btn {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--accent-text); font: inherit; font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--accent-hover); }

/* Count pills */
.count-pills {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  padding: 4px; border-radius: var(--r); background: var(--surface-2);
}
.count-pills label { position: relative; cursor: pointer; display: block; }
.count-pills input { position: absolute; opacity: 0; inset: 0; }
.count-pills span {
  display: block; text-align: center; font-family: var(--mono); font-weight: 500; font-size: 0.95rem;
  padding: 0.55rem 0.25rem; border-radius: var(--r-sm);
  color: var(--muted); transition: background 0.15s ease, color 0.15s ease;
  font-variant-numeric: tabular-nums;
}
.count-pills small { display: block; font-family: var(--font); font-size: 0.68rem; color: var(--faint); }
.count-pills input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); outline: 1px solid var(--line); }
.count-pills input:focus-visible + span { outline: 2px solid var(--accent); }

.crumbs {
  font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 1rem; display: flex; align-items: center; gap: 0.45rem;
}
.crumbs a { color: var(--muted); font-weight: 400; }
.crumbs a:hover { color: var(--ink); }
.crumbs [aria-current="page"] { color: var(--ink); }

.empty {
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--r-xl);
  padding: 2.5rem 1.5rem; text-align: center; color: var(--muted);
  margin: 1.5rem 0;
}
.spinner {
  width: 36px; height: 36px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- HOME ---------- */
.home-top {
  display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr);
  margin-bottom: 1rem;
}
@media (min-width: 960px) {
  .home-top { grid-template-columns: minmax(0, 1fr) 380px; }
}
.hero-copy {
  display: flex; flex-direction: column; justify-content: flex-end; gap: 0.85rem;
  padding: 0.5rem 0.25rem 0.75rem;
}
.hero-kicker {
  font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin: 0;
}
.hero-kicker strong { color: var(--accent-text); font-weight: 600; }
.hero-title {
  font-size: 2.5rem; line-height: 0.98; letter-spacing: -0.045em; font-weight: 600; margin: 0;
}
.hero-title .dim { color: var(--faint); display: block; }
@media (min-width: 768px) {
  .hero-title { font-size: 4rem; }
}
.hero-subtitle { color: var(--muted); font-size: 0.98rem; max-width: 34rem; margin: 0; }
/* Greeting name: prepend a comma only when signed in (name present). */
#greet-name:not(:empty)::before { content: ", "; }

/* Quick drill: the accent card */
.drill-card {
  background: var(--accent); color: var(--on-accent);
  border-radius: var(--r-xl); padding: 1.4rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.drill-card-head { display: flex; align-items: center; justify-content: space-between; }
.drill-card-kicker { font-family: var(--mono); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; }
.drill-card-title { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; margin: 0; color: inherit; }
.drill-card-icon {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--on-accent); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
}
.launcher-form { display: grid; gap: 0.75rem; }
.launcher-field { display: flex; flex-direction: column; gap: 0.35rem; }
.launcher-label { font-size: 0.78rem; font-weight: 500; color: var(--muted); }
.drill-card .launcher-label { color: inherit; opacity: 0.8; }
.drill-card select { background: var(--accent-field); border-color: transparent; }
.drill-card .launcher-row { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 0.75rem; align-items: end; }
.btn-on-accent { background: var(--on-accent); color: var(--accent) !important; height: 46px; border-radius: var(--r); }
.btn-on-accent:hover { opacity: 0.9; }

/* Bento */
.bento {
  display: grid; gap: 1rem;
  grid-template-columns: minmax(0, 1fr);
  margin-bottom: 1rem;
}
@media (min-width: 640px) {
  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .bento { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .bento .span-2 { grid-column: span 2; }
}
.bento-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: 1.35rem;
  display: flex; flex-direction: column; gap: 0.6rem; min-width: 0;
}
.bento-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
.bento-title { font-size: 0.95rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.stat-label { font-size: 0.85rem; color: var(--muted); margin: 0; }
.stat-num {
  font-size: 2.5rem; font-weight: 600; letter-spacing: -0.04em; line-height: 1.05;
  font-variant-numeric: tabular-nums; color: var(--ink); margin: 0;
}
.stat-sub { font-size: 0.82rem; color: var(--muted); margin: 0; }
.stat-sub.up { color: var(--ok); }
.mono-tag {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}

.heatmap {
  display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 5px;
  margin-top: 0.25rem;
}
.heatmap span { aspect-ratio: 1; border-radius: 5px; background: var(--heat-0); }
.heatmap span[data-l="1"] { background: var(--heat-1); }
.heatmap span[data-l="2"] { background: var(--heat-2); }
.heatmap span[data-l="3"] { background: var(--heat-3); }
.heatmap span[data-l="4"] { background: var(--heat-4); }
.heatmap-legend { display: flex; justify-content: space-between; }

.spark { width: 100%; height: 40px; display: block; margin-top: auto; }
.spark .spark-area { fill: var(--accent-soft); }
.spark .spark-line { fill: none; stroke: var(--accent-text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }

/* Inverse feature card (spotlight) */
.inverse-card {
  background: var(--inverse-bg); color: var(--inverse-ink);
  border: 1px solid var(--inverse-line);
  border-radius: var(--r-xl); padding: 1.5rem;
  display: flex; flex-direction: column; gap: 0.6rem; min-width: 0;
}
.inverse-card h2 { color: var(--inverse-ink); font-size: 1.5rem; margin: 0; }
.inverse-card p { color: var(--inverse-muted); margin: 0; }
.inverse-card .mono-tag { color: var(--inverse-muted); }
.inverse-card .actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.5rem; }
.inverse-card .btn-ghost { background: transparent; color: var(--inverse-ink); border-color: var(--inverse-line); }
.inverse-card .btn-ghost:hover { background: rgba(255, 255, 255, 0.06); }

.link-card { text-decoration: none; color: var(--ink); transition: border-color 0.15s ease; }
.link-card:hover { color: var(--ink); border-color: var(--line-strong); }
.link-card .arrow {
  margin-top: auto; align-self: flex-end;
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--ink);
}

/* Legacy stat tiles (history page) */
.tiles {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.85rem;
  margin-bottom: 1.75rem;
}
@media (min-width: 768px) {
  .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1rem; }
}
.tile {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 1rem 1.15rem;
}
.tile-top {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.82rem; color: var(--muted); margin-bottom: 0.3rem;
}
.tile-top .ico { color: var(--faint); }
.tile-val {
  font-size: 1.75rem; font-weight: 600; letter-spacing: -0.04em; line-height: 1.2;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.tile-val.orange { color: var(--warm); }
.tile-val.green { color: var(--accent-text); }
.tile-sub { font-size: 0.76rem; color: var(--muted); margin-top: 0.1rem; }

/* ---------- Sections & directory ---------- */
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin: 2.25rem 0 1rem;
}
.section-head h2 { margin: 0; font-size: 1.35rem; }
.section-link { font-size: 0.85rem; font-weight: 500; color: var(--accent-text); }

.searchbar {
  display: flex; align-items: center; gap: 0.65rem;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r);
  padding: 0 1rem; height: 48px; color: var(--muted); margin-bottom: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow); }
.searchbar input[type="search"] {
  border: 0; background: transparent; outline: none; flex: 1; box-shadow: none;
  font: inherit; font-weight: 500; color: var(--ink); padding: 0; min-width: 0;
}

.tiers {
  display: flex; gap: 2px; overflow-x: auto; margin-bottom: 1.25rem;
  padding: 4px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line);
  width: max-content; max-width: 100%;
  scrollbar-width: none;
}
.tiers::-webkit-scrollbar { display: none; }
.tier {
  display: inline-flex; align-items: center; gap: 0.45rem; flex: none; cursor: pointer;
  font: inherit; font-weight: 500; font-size: 0.875rem;
  border-radius: var(--r-sm); padding: 0.4rem 0.85rem;
  background: transparent; border: 0; color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.tier:hover { color: var(--ink); background: var(--surface-2); }
.tier .tier-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.tier.active { background: var(--solid); color: var(--bg); }
.tier.active .tier-dot { background: var(--accent); }

.tier-select { display: none; margin-bottom: 1.25rem; }
@media (max-width: 767px) {
  #tier-row { display: none; }
  .tier-select { display: block; }
}

.subj-grid {
  list-style: none; margin: 0 0 1.5rem; padding: 0;
  display: grid; gap: 1rem;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 640px) {
  .subj-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .subj-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.subj-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: 1.2rem;
  display: flex; flex-direction: column; justify-content: space-between; gap: 1rem;
  transition: border-color 0.15s ease;
}
.subj-card:hover { border-color: var(--line-strong); }
.subj-card-top { display: flex; align-items: flex-start; gap: 0.85rem; }
.subj-icon {
  --h: 250;
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 1.1rem;
  background: hsl(var(--h) var(--tile-s) var(--tile-bg-l));
  color: hsl(var(--h) var(--tile-s) var(--tile-fg-l));
  border: 1px solid hsl(var(--h) var(--tile-s) var(--tile-border-l));
}
.subj-icon.exam-mark { width: auto; min-width: 44px; padding: 0 0.5rem; font-family: var(--mono); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; }
.sub-hero .subj-icon.exam-mark { font-size: 0.9rem; }
.subj-info { flex: 1; min-width: 0; }
.subj-name {
  font-weight: 600; font-size: 1.02rem; color: var(--ink); letter-spacing: -0.01em;
  margin-bottom: 0.2rem;
  display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
}
.subj-name a { color: var(--ink); font-weight: 600; }
.subj-name a:hover { color: var(--accent-text); }
.subj-meta { font-size: 0.82rem; color: var(--muted); }
.tag {
  display: inline-block; font-family: var(--mono); font-size: 0.66rem; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--muted); border-radius: 6px; padding: 0.1rem 0.45rem;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.tag-hot { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-text); }
.subj-card-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding-top: 0.85rem; border-top: 1px solid var(--line);
}
.mastery-pill { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }

/* ---------- QUIZ PLAYER ---------- */
.quiz-container { max-width: 780px; margin: 0 auto; width: 100%; }
.quiz-wrap { max-width: 100%; }

.quiz-loading { text-align: center; padding: 3.5rem 1.5rem; }
.quiz-loading h2 { margin: 1.25rem 0 0.5rem; font-size: 1.4rem; }
.quiz-loading p { color: var(--muted); font-size: 0.95rem; }

.q-run { display: grid; gap: 1rem; }

.q-top { padding: 1.1rem 1.25rem; display: grid; gap: 0.85rem; }
.q-top-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.q-kicker {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin: 0;
}
.q-count { margin: 0.1rem 0 0; font-size: 0.95rem; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.q-side { display: flex; align-items: center; gap: 0.5rem; }
.q-timer {
  margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 500; font-size: 0.85rem;
  background: var(--surface-2); border-radius: var(--r);
  height: 36px; padding: 0 0.75rem; color: var(--ink);
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.q-timer.live svg { color: var(--accent-text); }

.track { height: 6px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.track > div { height: 100%; width: 0; background: var(--accent); border-radius: var(--r-pill); transition: width 0.35s ease; }

.q-dots { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.q-dot {
  min-width: 34px; height: 34px; padding: 0 0.35rem;
  border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-family: var(--mono);
  font-size: 0.78rem; font-weight: 500; cursor: pointer;
  font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.q-dot:hover { border-color: var(--line-strong); color: var(--ink); }
.q-dot.done { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-text); }
.q-dot.ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.q-dot.miss { background: var(--bad-soft); border-color: var(--bad-border); color: var(--bad); }
.q-dot.now { background: var(--solid); border-color: var(--solid); color: var(--bg); }

.q-card { padding: 1.75rem 1.5rem; }
.q-topic {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 0.75rem;
}
.q-title {
  font-size: 1.5rem; font-weight: 600; line-height: 1.25; letter-spacing: -0.025em;
  margin: 0 0 1.5rem; color: var(--ink);
}
@media (min-width: 768px) {
  .q-title { font-size: 1.75rem; }
}

.opts { display: grid; gap: 0.65rem; }
.opt {
  display: flex; align-items: center; gap: 0.9rem; width: 100%; text-align: left;
  font: inherit; font-size: 1rem; font-weight: 500; line-height: 1.4;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px;
  min-height: 60px; padding: 0.75rem 1rem; cursor: pointer; color: var(--ink);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.opt:hover { border-color: var(--line-strong); background: var(--surface-2); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.opt-key {
  flex: none; width: 30px; height: 30px; border-radius: 9px;
  background: var(--surface-2); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 0.8rem; font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.opt[aria-checked="true"] .opt-key { background: var(--accent); color: var(--on-accent); }
.opt-mark { font-size: 0.82rem; font-weight: 600; flex: none; }
.opt.is-correct { border-color: var(--ok-border); background: var(--ok-soft); }
.opt.is-correct .opt-key { background: var(--ok-solid); color: var(--surface); }
.opt.is-correct .opt-mark { color: var(--ok); }
.opt.is-wrong { border-color: var(--bad-border); background: var(--bad-soft); }
.opt.is-wrong .opt-key { background: var(--bad-solid); color: var(--surface); }
.opt.is-wrong .opt-mark { color: var(--bad); }

.q-tip { margin: 1.25rem 0 0; font-size: 0.8rem; color: var(--muted); }
.kbd {
  font-family: var(--mono); font-size: 0.7rem; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-bottom-width: 2px; border-radius: 6px; padding: 0.05rem 0.4rem;
  color: var(--ink);
}

.q-nav { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-top: 0.25rem; }
.q-nav-right { display: flex; gap: 0.6rem; }

/* Narrow-screen overflow guards: wrap rows instead of forcing horizontal
   scroll; minmax(0,1fr) keeps long unbroken strings inside the viewport. */
.quiz-container { overflow-wrap: break-word; }
.crumbs { flex-wrap: wrap; }
.crumbs > *, .q-top-row > *, .opt > *, .review-item summary > * { min-width: 0; }
.q-top-row, .q-side, .q-nav, .q-nav-right { flex-wrap: wrap; }
.opts, .q-run, .q-top, .review, .review-detail { grid-template-columns: minmax(0, 1fr); }
.screen, .quiz-container, .opt { min-width: 0; }

/* ---------- Results ---------- */
.verdict-hero {
  text-align: center;
  padding: 2.25rem 1.5rem;
  background: var(--inverse-bg);
  border: 1px solid var(--inverse-line);
  border-radius: var(--r-xl);
  color: var(--inverse-ink);
}
.verdict-eyebrow {
  font-family: var(--mono); color: var(--inverse-muted); font-size: 0.72rem; letter-spacing: 0.1em;
  text-transform: uppercase; margin: 0 0 1rem;
}
.verdict-hero h2 { color: var(--inverse-ink); font-size: 1.6rem; margin-bottom: 0.3rem; }
.verdict-grade {
  display: inline-block; font-size: 0.82rem; font-weight: 600;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--inverse-line);
  border-radius: var(--r-pill); padding: 0.3rem 0.9rem; margin-bottom: 0.75rem; color: var(--inverse-ink);
}
.verdict-sub { color: var(--inverse-muted); font-size: 0.95rem; }

.verdict-ring {
  --ring-track: rgba(255, 255, 255, 0.1);
  width: 148px; height: 148px; border-radius: 50%; margin: 0 auto 1.25rem;
  display: flex; align-items: center; justify-content: center; position: relative;
  background: var(--ring-track);
}
.verdict-ring::before {
  content: ""; position: absolute; inset: 12px; border-radius: 50%;
  background: var(--inverse-bg);
}
.verdict-ring span {
  position: relative; font-size: 2.25rem; font-weight: 600; letter-spacing: -0.04em; color: var(--inverse-ink);
  font-variant-numeric: tabular-nums;
}

.verdict-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center; margin-top: 1.5rem; }
.verdict-hero .btn-cream { background: var(--accent); color: var(--on-accent) !important; }
.verdict-hero .btn-ghost { background: transparent; border-color: var(--inverse-line); color: var(--inverse-ink); }
.verdict-hero .btn-ghost:hover { background: rgba(255, 255, 255, 0.06); }

.saved-note { color: var(--inverse-muted); font-size: 0.9rem; margin: 1rem 0 0; }
.saved-note a { color: var(--inverse-ink); text-decoration: underline; }

.review-section { margin-top: 2rem; }
.review-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.review-head h3 { margin: 0; font-size: 1.2rem; }
.review-head p { color: var(--muted); font-size: 0.88rem; margin: 0; }

.review { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.review-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.review-item summary {
  cursor: pointer; padding: 1rem 1.15rem; display: flex; gap: 0.85rem;
  align-items: flex-start; list-style: none;
}
.review-item summary::-webkit-details-marker { display: none; }
.badge {
  flex: none; font-size: 0.72rem; font-weight: 600; border-radius: var(--r-pill);
  padding: 0.2rem 0.65rem; margin-top: 0.1rem; border: 1px solid transparent;
}
.badge.ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.badge.miss { background: var(--bad-soft); border-color: var(--bad-border); color: var(--bad); }
.review-q { font-weight: 500; font-size: 0.95rem; color: var(--ink); line-height: 1.45; }
.review-detail {
  border-top: 1px solid var(--line); padding: 1rem 1.15rem;
  display: grid; gap: 0.5rem; font-size: 0.9rem; background: var(--surface-2);
}
.review-opt { padding: 0.6rem 0.9rem; border-radius: var(--r); border: 1px solid var(--line); color: var(--body); background: var(--surface); }
.review-opt.is-correct { border-color: var(--ok-border); background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.review-opt.is-picked:not(.is-correct) { border-color: var(--bad-border); background: var(--bad-soft); color: var(--bad); font-weight: 600; }

#confetti-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 150; }

/* ---------- Subject / exam detail ---------- */
.sub-hero { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1rem; }
.sub-hero .subj-icon { width: 60px; height: 60px; font-size: 1.5rem; border-radius: 16px; }
.sub-hero h1 { font-size: 1.85rem; margin-bottom: 0.2rem; }
.sub-hero p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.meta-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.6rem; }

.builder { margin-bottom: 1.5rem; }
.builder-note { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 0.75rem 0 0; }

.topics { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.trow {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 0.95rem 1.15rem;
  transition: border-color 0.15s ease;
}
.trow:hover { border-color: var(--line-strong); }
.trow-hero { background: var(--accent-soft); border-color: var(--accent-border); }
.trow-main { min-width: 0; }
.trow-name { font-weight: 600; font-size: 0.98rem; color: var(--ink); }
.trow-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.1rem; }

/* ---------- Leaderboard ---------- */
.board-row .trow-main { flex: 1; }
.board-rank { font-family: var(--mono); font-weight: 600; font-size: 0.9rem; min-width: 2.6rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.board-points { font-family: var(--mono); font-weight: 600; font-size: 1rem; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Pinned subject filter (leaderboard) */
.filter-fab-wrap {
  position: fixed; z-index: 55; left: 16px; right: 16px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; justify-content: center; pointer-events: none;
}
@media (max-width: 767px) {
  /* Sits above the floating tab bar (64px tall, 12px off the bottom). */
  .filter-fab-wrap { bottom: calc(88px + env(safe-area-inset-bottom)); }
}
.filter-fab {
  pointer-events: auto; max-width: 100%;
  display: inline-flex; align-items: center; gap: 0.6rem;
  padding: 0.8rem 0.95rem 0.8rem 1.1rem;
  background: var(--solid); color: var(--bg);
  border: 0; border-radius: var(--r-pill);
  font: 600 0.9rem/1.2 var(--font); cursor: pointer;
  box-shadow: 0 8px 24px rgba(11, 12, 16, 0.2);
  transition: transform 0.15s ease;
}
.filter-fab:hover { transform: translateY(-1px); }
.filter-fab:active { transform: scale(0.98); }
.filter-fab svg { flex: none; }
.filter-fab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Room so the last row clears the button. */
.board-list { margin-bottom: 5rem; }

/* Subject sheet: bottom sheet on phones, centered dialog on wider screens */
.sheet {
  border: 0; padding: 0; background: transparent; color: var(--ink);
  width: 100%; max-width: 100%; max-height: 100%;
  margin: auto 0 0; height: 82vh; height: 82dvh;
}
.sheet::backdrop {
  background: rgba(11, 12, 16, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.sheet-card {
  height: 100%; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 24px 24px 0 0; box-shadow: var(--shadow-xl);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet[open] .sheet-card { animation: sheet-up 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes sheet-up { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 768px) {
  .sheet { margin: auto; width: calc(100vw - 2rem); max-width: 520px; height: min(680px, 82vh); }
  .sheet-card { border-radius: var(--r-xl); border-bottom: 1px solid var(--line); }
  .sheet-handle { display: none !important; }
  .sheet[open] .sheet-card { animation-name: sheet-in; }
  @keyframes sheet-in { from { transform: translateY(12px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
}
@media (prefers-reduced-motion: reduce) {
  .sheet[open] .sheet-card { animation: none; }
}
.sheet-handle {
  display: block; width: 36px; height: 4px; border-radius: 2px;
  background: var(--line-strong); margin: 10px auto 2px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.25rem 0.75rem; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.sheet-search {
  display: flex; align-items: center; gap: 0.6rem; margin: 0 1rem 0.5rem;
  padding: 0 0.9rem; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface); color: var(--muted);
}
.sheet-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sheet-search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  padding: 0.8rem 0; font: inherit; font-size: 1rem; color: var(--ink);
}
#sheet-browse, #sheet-results { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#sheet-browse[hidden], #sheet-results[hidden] { display: none; }
.sheet-tabs {
  display: flex; border-bottom: 1px solid var(--line); padding: 0 0.5rem;
  overflow-x: auto; scrollbar-width: none;
}
.sheet-tabs::-webkit-scrollbar { display: none; }
.sheet-tab {
  flex: 1; min-width: max-content; padding: 0.8rem 1rem; border: 0; background: none;
  font: 600 0.9rem var(--font); color: var(--muted); cursor: pointer;
  box-shadow: inset 0 -2px 0 transparent; transition: color 0.15s ease;
}
.sheet-tab:hover { color: var(--ink); }
.sheet-tab[aria-selected="true"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.sheet-list { list-style: none; margin: 0; padding: 0.25rem 0 1rem; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.sheet-item {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.6rem 1.25rem; color: var(--ink); text-decoration: none;
}
.sheet-item:hover { background: var(--surface-2); color: var(--ink); }
.sheet-item .subj-icon { width: 36px; height: 36px; border-radius: 10px; font-size: 0.95rem; }
.sheet-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sheet-item-name { font-weight: 500; }
.sheet-item-meta { font-size: 0.82rem; color: var(--muted); }
.sheet-check { flex: none; color: var(--accent-text); visibility: hidden; }
.sheet-item[aria-current] { color: var(--accent-text); }
.sheet-item[aria-current] .sheet-item-name { font-weight: 600; }
.sheet-item[aria-current] .sheet-check { visibility: visible; }
.sheet-all { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.sheet-all-icon { width: 36px; display: inline-flex; justify-content: center; color: var(--muted); }
.sheet-all[aria-current] .sheet-all-icon { color: var(--accent-text); }
.sheet-empty { text-align: center; color: var(--muted); padding: 2rem; margin: 0; }
.you-pill { display: inline-block; font-size: 0.65rem; font-weight: 600; background: var(--accent); color: var(--on-accent); border-radius: var(--r-pill); padding: 0.1rem 0.5rem; margin-left: 0.4rem; vertical-align: 0.1rem; }
.launcher-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: 1.15rem 1.25rem;
}

/* ---------- Auth modal ---------- */
.modal {
  border: 0; padding: 0; background: transparent; color: var(--ink);
  max-width: 440px; width: calc(100vw - 2rem);
  border-radius: var(--r-xl);
}
.modal::backdrop {
  background: rgba(11, 12, 16, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-card {
  border-radius: var(--r-xl); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-xl);
}
.modal-head { display: flex; gap: 0.9rem; align-items: flex-start; padding: 1.4rem 1.4rem 0.5rem; }
.modal-badge {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center;
}
.modal-head h2 { margin: 0 0 0.15rem; font-size: 1.3rem; }
.modal-sub { color: var(--muted); font-size: 0.9rem; margin: 0; }
.modal-head .x-btn { margin-left: auto; }
.modal-body { padding: 1rem 1.4rem 1.4rem; }
.alert-err {
  background: var(--bad-soft); border: 1px solid var(--bad-border);
  color: var(--bad); border-radius: var(--r); padding: 0.75rem 1rem;
  font-size: 0.88rem; font-weight: 500; margin-bottom: 1.25rem;
}
.auth-fineprint { text-align: center; color: var(--muted); font-size: 0.82rem; margin: 0.85rem 0 0; }
.auth-sent-to { font-size: 0.9rem; color: var(--muted); margin: 0 0 1rem; }
.auth-sent-to strong { color: var(--ink); font-weight: 600; }
.otp-group { display: flex; gap: 0.5rem; justify-content: space-between; margin-bottom: 1.25rem; }
.otp-box {
  width: 3.2rem; height: 3.6rem; text-align: center; flex: 1; min-width: 0;
  font-family: var(--mono); font-size: 1.5rem; font-weight: 500; font-variant-numeric: tabular-nums;
  border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--ink); caret-color: var(--accent);
  padding: 0; transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.otp-box:focus { border-color: var(--accent); outline: none; background: var(--surface); box-shadow: 0 0 0 4px var(--accent-glow); }
.otp-box.filled { border-color: var(--accent-border); background: var(--accent-soft); color: var(--ink); }
.auth-resend-row { text-align: center; font-size: 0.88rem; color: var(--muted); margin: 0.85rem 0 0; }
.auth-dev-hint {
  margin: 1rem 0 0; font-size: 0.82rem;
  color: var(--warm); background: var(--warm-soft);
  border: 1px solid var(--warm-border); border-radius: var(--r); padding: 0.65rem 0.85rem;
}

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed; bottom: 2rem; right: 2rem; z-index: 120;
  display: grid; gap: 0.6rem; pointer-events: none;
}
@media (max-width: 767px) {
  .toast-root { bottom: calc(92px + env(safe-area-inset-bottom)); left: 1rem; right: 1rem; }
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 0.6rem;
  background: var(--solid); color: var(--bg); border-radius: var(--r);
  padding: 0.8rem 1.1rem; font-size: 0.9rem; font-weight: 500;
  box-shadow: var(--shadow-xl);
  animation: toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--accent); }
.toast.success::before { background: var(--ok-solid); }
.toast.error::before { background: var(--bad-solid); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } }

/* ---------- Admin ---------- */
.admin-tools { display: flex; gap: 0.6rem; margin-bottom: 0.75rem; }
.admin-tools input { flex: 1; min-width: 0; }
.admin-tools .btn { flex: none; height: auto; }
.admin-list {
  list-style: none; margin: 0; padding: 0.6rem; display: grid; gap: 0.4rem;
  max-height: 22rem; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface-2);
}
.admin-row {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 0.6rem 0.9rem; cursor: pointer;
}
.admin-row.off { opacity: 0.6; cursor: default; }
.admin-row input[type="checkbox"] { width: 1.1rem; height: 1.1rem; flex: none; accent-color: var(--accent); }
.admin-row-main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.admin-row-name { font-weight: 600; font-size: 0.95rem; color: var(--ink); }
.admin-row-meta { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-empty { color: var(--muted); font-size: 0.88rem; margin: 0.5rem 0 0; }
.admin-result { margin: 1rem 0 0; font-weight: 500; font-size: 0.9rem; color: var(--ok); }

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
