/* PrepBank design system
   Color: Highland Park "Scots" royal blue for brand + actions, gold reserved for PrepBank+,
          neutrals tinted slightly blue so greys read as intentional.
   Type:  Bricolage Grotesque (display, headings only), Hanken Grotesk (body/UI),
          JetBrains Mono (numbers, counts, timer).
   Motion: short (150-450ms), eased, only on real state changes; off for reduced-motion users.
*/

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --surface-3: #e5eaf2;
  --ink: #0e1a33;
  --ink-soft: #55617a;
  --ink-faint: #8792a7;
  --line: #dde3ec;
  --line-strong: #c8d1de;
  --brand: #1b3fa6;
  --brand-hover: #16358e;
  --brand-ink: #ffffff;
  --brand-soft: #e8eefc;
  --gold: #b9820f;
  --gold-hover: #a57309;
  --gold-ink: #ffffff;
  --gold-soft: #fbf2de;
  --good: #16784c;
  --good-bg: #e5f4ec;
  --bad: #b3321f;
  --bad-bg: #fbeae6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(14, 26, 51, 0.06);
  --shadow-md: 0 1px 2px rgba(14, 26, 51, 0.05), 0 8px 24px -12px rgba(14, 26, 51, 0.18);
  --shadow-lg: 0 24px 60px -20px rgba(14, 26, 51, 0.35);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --display: "Bricolage Grotesque", "Hanken Grotesk", system-ui, sans-serif;
  --body: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  /* legacy aliases used by older markup */
  --accent: var(--gold);
  --accent2: var(--brand);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1c;
    --surface: #111829;
    --surface-2: #172036;
    --surface-3: #1e2944;
    --ink: #e8edf6;
    --ink-soft: #9ba7be;
    --ink-faint: #6c7892;
    --line: #222d46;
    --line-strong: #2f3c5a;
    --brand: #7f9dff;
    --brand-hover: #9bb3ff;
    --brand-ink: #0a0f1c;
    --brand-soft: #1a2750;
    --gold: #e8b64a;
    --gold-hover: #f1c567;
    --gold-ink: #1c1405;
    --gold-soft: #33280f;
    --good: #5ccb92;
    --good-bg: #0f2a1e;
    --bad: #f08a76;
    --bad-bg: #33160f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0a0f1c;
    --surface: #111829;
    --surface-2: #172036;
    --surface-3: #1e2944;
    --ink: #e8edf6;
    --ink-soft: #9ba7be;
    --ink-faint: #6c7892;
    --line: #222d46;
    --line-strong: #2f3c5a;
    --brand: #7f9dff;
    --brand-hover: #9bb3ff;
    --brand-ink: #0a0f1c;
    --brand-soft: #1a2750;
    --gold: #e8b64a;
    --gold-hover: #f1c567;
    --gold-ink: #1c1405;
    --gold-soft: #33280f;
    --good: #5ccb92;
    --good-bg: #0f2a1e;
    --bad: #f08a76;
    --bad-bg: #33160f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--display); font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.75rem, 3.2vw, 2.25rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--brand); }
code { font-family: var(--mono); font-size: 0.85em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 0.92em; letter-spacing: -0.02em; }
.icon { width: 18px; height: 18px; flex: none; }
.help { color: var(--ink-soft); font-size: 0.875rem; }
.help.pad { padding: 1rem 1.25rem; }
.meta { color: var(--ink-soft); font-size: 0.85rem; }
.center { text-align: center; display: flex; justify-content: center; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1160px; margin: 0 auto; padding: 0.7rem 1.25rem; display: flex; align-items: center; gap: 1.25rem; }
.brand { display: inline-flex; align-items: center; gap: 0.55rem; font-family: var(--display); font-weight: 700; font-size: 1.15rem; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.logo { display: inline-flex; width: 28px; height: 28px; }
.logo svg { width: 100%; height: 100%; }
.logo rect { fill: var(--brand); }
.logo path { fill: none; stroke: var(--brand-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.topnav { display: flex; gap: 0.2rem; flex: 1; }
.topnav button {
  border: 0; background: transparent; color: var(--ink-soft); font-weight: 600; font-size: 0.92rem;
  padding: 0.45rem 0.8rem; border-radius: 8px; position: relative; transition: color 0.15s, background 0.15s;
}
.topnav button:hover { color: var(--ink); background: var(--surface-2); }
.topnav button.active { color: var(--ink); }
.topnav button.active::after {
  content: ""; position: absolute; left: 0.8rem; right: 0.8rem; bottom: -0.72rem; height: 2px; background: var(--brand); border-radius: 2px;
}
.top-right { display: flex; align-items: center; gap: 0.6rem; }
.plan-pill {
  display: inline-flex; align-items: center; gap: 0.35rem; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font-size: 0.8rem; font-weight: 700; padding: 0.3rem 0.75rem; border-radius: 999px; transition: transform 0.15s var(--ease), border-color 0.15s;
}
.plan-pill .icon { width: 14px; height: 14px; }
.plan-pill:hover { border-color: var(--gold); transform: translateY(-1px); }
.plan-pill.plus { background: var(--gold-soft); border-color: color-mix(in srgb, var(--gold) 45%, transparent); color: var(--gold); }
.user-chip { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; font-weight: 600; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 0.72rem; font-weight: 700;
  background: var(--brand-soft); color: var(--brand); letter-spacing: 0.02em;
}

main { flex: 1; width: 100%; max-width: 880px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
main.wide { max-width: 1160px; }

.site-footer { border-top: 1px solid var(--line); padding: 1.5rem 1.25rem 2rem; max-width: 1160px; width: 100%; margin: 0 auto; display: flex; gap: 1.5rem; align-items: flex-start; color: var(--ink-faint); font-size: 0.82rem; }
.site-footer > div { display: inline-flex; align-items: center; gap: 0.45rem; font-family: var(--display); font-weight: 700; color: var(--ink-soft); white-space: nowrap; }
.site-footer .logo { width: 20px; height: 20px; }
.site-footer p { max-width: 70ch; }
.footer-links { display: flex; gap: 1rem; margin-left: auto; white-space: nowrap; }
.footer-links a { color: var(--ink-soft); font-weight: 600; text-decoration: none; }
.footer-links a:hover { color: var(--brand); text-decoration: underline; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 0.58rem 1rem; border-radius: 9px; font-weight: 650; font-size: 0.92rem; line-height: 1.2;
  transition: transform 0.12s var(--ease), background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn .icon { width: 16px; height: 16px; }
.btn:hover { border-color: var(--ink-faint); background: var(--surface-2); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset, var(--shadow-sm); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--brand) 60%, transparent); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.gold:hover { background: var(--gold-hover); border-color: var(--gold-hover); box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--gold) 60%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: transparent; border-color: color-mix(in srgb, var(--bad) 40%, transparent); color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn.small { padding: 0.36rem 0.7rem; font-size: 0.82rem; border-radius: 7px; }
.btn.lg { padding: 0.75rem 1.25rem; font-size: 0.98rem; }
.btn.block { width: 100%; }
.btn.icon-btn { width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.card.flush { padding: 0; overflow: hidden; }
.section-label {
  display: flex; align-items: center; gap: 0.5rem; margin: 1.75rem 0 0.7rem;
  font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint);
}
.section-label .num { background: var(--surface-2); color: var(--ink-soft); padding: 0.05rem 0.45rem; border-radius: 999px; font-size: 0.75rem; letter-spacing: 0; }
.eyebrow { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--brand); margin-bottom: 0.55rem; }
.page-head { margin-bottom: 1.5rem; }
.page-head .sub { color: var(--ink-soft); margin-top: 0.45rem; max-width: 64ch; }
.page-head.row { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 650; font-size: 0.86rem; margin-bottom: 0.35rem; }
.field { margin-bottom: 1rem; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; padding: 0.62rem 0.75rem; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
textarea { min-height: 170px; resize: vertical; line-height: 1.5; }
.error-box { background: var(--bad-bg); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); border-radius: 10px; padding: 0.7rem 0.9rem; margin-bottom: 1rem; font-size: 0.9rem; animation: shake 0.35s var(--ease); }

.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.seg button { border: 0; background: transparent; color: var(--ink-soft); font-weight: 650; font-size: 0.84rem; padding: 0.42rem 0.8rem; border-radius: 7px; display: inline-flex; align-items: center; gap: 0.35rem; transition: background 0.18s var(--ease), color 0.18s, box-shadow 0.18s; }
.seg button .icon { width: 14px; height: 14px; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.seg-full { display: flex; width: 100%; }
.seg-full button { flex: 1; justify-content: center; }

.searchbox { display: flex; align-items: center; gap: 0.6rem; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 11px; padding: 0 0.8rem; margin: 0; transition: border-color 0.15s, box-shadow 0.15s; font-weight: 400; }
.searchbox:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.searchbox .icon { color: var(--ink-faint); }
.searchbox input { border: 0 !important; box-shadow: none !important; padding: 0.72rem 0; background: transparent; font-size: 0.98rem; }
.searchbox kbd { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-faint); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0.05rem 0.4rem; }
.searchbox.compact { margin: 1rem 0 0.6rem; }
.searchbox.compact input { padding: 0.55rem 0; font-size: 0.9rem; }

/* ---------- Badges ---------- */
.level { display: inline-flex; align-items: center; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; padding: 0.16rem 0.5rem; border-radius: 5px; white-space: nowrap; }
.level-ap { background: var(--gold-soft); color: var(--gold); }
.level-honors { background: var(--brand-soft); color: var(--brand); }
.level-elective { background: var(--surface-2); color: var(--ink-soft); }
.level-on { background: transparent; color: var(--ink-faint); box-shadow: inset 0 0 0 1px var(--line); }
.test-badges { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.badge-official, .badge-student, .badge-free, .badge-plus {
  display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.72rem; font-weight: 700; padding: 0.14rem 0.5rem; border-radius: 999px; letter-spacing: 0.01em; text-transform: none;
}
.badge-official { background: var(--brand); color: var(--brand-ink); }
.badge-official .icon, .badge-plus .icon { width: 12px; height: 12px; stroke-width: 3; }
.badge-student { color: var(--ink-soft); box-shadow: inset 0 0 0 1px var(--line-strong); }
.badge-free { background: var(--good-bg); color: var(--good); }
.badge-plus { background: var(--gold-soft); color: var(--gold); }

/* ---------- Auth ---------- */
.auth-main { max-width: 1080px; display: grid; grid-template-columns: 1.15fr 1fr; gap: 3rem; align-items: center; padding-top: 3.5rem; }
.auth-hero h1 { font-size: clamp(2rem, 4.2vw, 3.1rem); line-height: 1.05; letter-spacing: -0.03em; }
.auth-hero .lede { font-size: 1.08rem; color: var(--ink-soft); margin-top: 1rem; max-width: 50ch; }
.auth-points { list-style: none; padding: 0; margin: 1.75rem 0 0; display: grid; gap: 0.8rem; }
.auth-points li { display: flex; gap: 0.75rem; align-items: center; color: var(--ink-soft); }
.auth-points .icon { width: 34px; height: 34px; padding: 8px; border-radius: 9px; background: var(--brand-soft); color: var(--brand); }
.auth-points strong { color: var(--ink); }
.auth-card { padding: 1.75rem; box-shadow: var(--shadow-md); }
.auth-card h2 { margin: 1.4rem 0 1rem; }

/* ---------- Catalog (browse) ---------- */
.popular { margin-bottom: 0.5rem; }
.popular .section-label { margin-top: 0; }
.popular-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem; }
.popular-card {
  text-align: left; display: flex; flex-direction: column; gap: 0.2rem; padding: 0.95rem 1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform 0.18s var(--ease), box-shadow 0.18s, border-color 0.18s;
}
.popular-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.pc-dept { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-faint); }
.pc-name { font-family: var(--display); font-weight: 650; font-size: 1.02rem; letter-spacing: -0.01em; }
.pc-count { font-size: 0.82rem; color: var(--brand); font-weight: 600; }

.catalog { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 2rem; margin-top: 1.5rem; align-items: start; }
.dept-rail { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 2px; }
.dept-item {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; text-align: left;
  border: 0; background: transparent; color: var(--ink-soft); font-weight: 600; font-size: 0.9rem;
  padding: 0.5rem 0.7rem; border-radius: 8px; position: relative; transition: background 0.15s, color 0.15s;
}
.dept-item .num { font-size: 0.78rem; color: var(--ink-faint); }
.dept-item:hover { background: var(--surface-2); color: var(--ink); }
.dept-item.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.dept-item.on::before { content: ""; position: absolute; left: -0.6rem; top: 25%; bottom: 25%; width: 3px; border-radius: 3px; background: var(--brand); animation: grow 0.25s var(--ease); }
.dept-item.on .num { color: var(--brand); }

.catalog-tools { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 0.5rem; }
.level-seg { align-self: flex-start; }
.catalog-group { margin-top: 1.5rem; }
.catalog-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 0.25rem 0.5rem; }
.catalog-head h3 { font-size: 1.1rem; }
.catalog-head .count { font-size: 0.8rem; color: var(--ink-faint); }
.catalog-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.class-row {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 7.5rem 5.5rem 18px; align-items: center; gap: 1rem;
  text-align: left; border: 0; background: transparent; padding: 0.78rem 1rem; border-top: 1px solid var(--line);
  transition: background 0.15s;
}
.class-row:first-child { border-top: 0; }
.class-row:hover { background: var(--surface-2); }
.class-row:active { background: var(--surface-3); }
.class-name { font-weight: 600; transition: color 0.15s; }
.class-row:hover .class-name { color: var(--brand); }
.class-level { display: flex; }
.class-tests { display: inline-flex; align-items: center; justify-content: flex-end; gap: 0.3rem; font-size: 0.82rem; color: var(--ink-faint); }
.class-tests.has { color: var(--ink); font-weight: 600; }
.dot-official { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); }
.dot-official .icon { width: 10px; height: 10px; stroke-width: 3.5; }
.row-chevron { color: var(--ink-faint); transition: transform 0.18s var(--ease), color 0.15s; width: 16px; height: 16px; }
.class-row:hover .row-chevron { transform: translateX(3px); color: var(--brand); }

.empty-state { text-align: center; padding: 2.5rem 1.5rem; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); display: flex; flex-direction: column; align-items: center; gap: 0.6rem; margin-top: 1rem; }
.empty-state > .icon { width: 40px; height: 40px; padding: 9px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); }
.empty-state p { color: var(--ink-soft); max-width: 46ch; }
.empty-state .btn { margin-top: 0.4rem; }
.empty-state.small { border: 0; margin: 0; padding: 2rem 1rem; }

/* ---------- Breadcrumbs ---------- */
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 0.35rem; font-size: 0.85rem; margin-bottom: 1.25rem; color: var(--ink-faint); }
.crumbs button { display: inline-flex; align-items: center; gap: 0.2rem; border: 0; background: transparent; padding: 0.15rem 0.3rem; border-radius: 5px; color: var(--ink-soft); font-weight: 600; }
.crumbs button .icon { width: 15px; height: 15px; }
.crumbs button:hover { color: var(--brand); background: var(--brand-soft); }
.crumbs .current { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }

/* ---------- Class page: test rows ---------- */
.test-group .stagger { display: flex; flex-direction: column; gap: 0.6rem; }
.test-row {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 1rem; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow-sm);
  transition: transform 0.18s var(--ease), box-shadow 0.18s, border-color 0.18s;
}
.test-row:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.test-row.official { box-shadow: inset 3px 0 0 var(--brand), var(--shadow-sm); }
.test-row.official:hover { box-shadow: inset 3px 0 0 var(--brand), var(--shadow-md); }
.tr-main { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.tr-title { font-weight: 700; font-size: 1rem; }
.tr-open { display: inline-flex; align-items: center; gap: 0.2rem; font-weight: 650; font-size: 0.86rem; color: var(--brand); white-space: nowrap; }
.tr-open .icon { width: 16px; height: 16px; transition: transform 0.18s var(--ease); }
.test-row:hover .tr-open .icon { transform: translateX(3px); }
.lock { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; font-weight: 650; color: var(--gold); white-space: nowrap; }
.lock .icon { width: 15px; height: 15px; }

/* ---------- Test page: modes ---------- */
.stat-row { display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; margin-top: 0.7rem; color: var(--ink-soft); font-size: 0.9rem; }
.stat-row .num { color: var(--ink); font-weight: 600; }
.page-head .help { margin-top: 0.6rem; }
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.85rem; }
.mode-card {
  display: flex; flex-direction: column; gap: 0.4rem; text-align: left; padding: 1.2rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform 0.18s var(--ease), box-shadow 0.18s, border-color 0.18s;
}
.mode-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.mode-card:active { transform: translateY(-1px) scale(0.99); }
.mode-card.primary { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.mode-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); margin-bottom: 0.35rem; }
.mode-icon.gold { background: var(--gold-soft); color: var(--gold); }
.mode-title { font-family: var(--display); font-weight: 650; font-size: 1.1rem; letter-spacing: -0.01em; }
.mode-desc { color: var(--ink-soft); font-size: 0.88rem; flex: 1; }
.mode-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 0.5rem; padding-top: 0.7rem; border-top: 1px solid var(--line); font-size: 0.82rem; font-weight: 650; color: var(--brand); }
.mode-meta .icon { width: 16px; height: 16px; transition: transform 0.18s var(--ease); }
.mode-card:hover .mode-meta .icon { transform: translateX(3px); }
.locked-card { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.locked-card > div { flex: 1; min-width: 200px; }
.locked-card .mode-icon { margin: 0; }

/* ---------- Quiz ---------- */
.quiz-top { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem; }
.quiz-top .meta { text-align: center; }
.timer { font-family: var(--mono); font-weight: 600; font-size: 1rem; padding: 0.25rem 0.6rem; border-radius: 7px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); background: var(--bad-bg); animation: pulse 1s ease-in-out infinite; }
.progressbar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin: 0.9rem 0 1.4rem; }
.progressbar.thin { height: 4px; margin: 0.6rem 0 0.5rem; }
.progressbar > div { height: 100%; background: var(--brand); border-radius: inherit; transition: width 0.45s var(--ease); }
.question-card { padding: 1.6rem; }
.q-type { font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); margin-bottom: 0.5rem; }
.q-prompt { font-size: 1.3rem; line-height: 1.35; margin-bottom: 1.2rem; }
.choices { display: flex; flex-direction: column; gap: 0.55rem; }
.choice {
  display: flex; align-items: center; gap: 0.8rem; width: 100%; text-align: left;
  border: 1px solid var(--line-strong); border-radius: 11px; padding: 0.75rem 0.9rem; background: var(--surface);
  transition: border-color 0.15s, background 0.15s, transform 0.12s var(--ease), box-shadow 0.15s;
}
.choice:hover:not(:disabled) { border-color: var(--brand); background: color-mix(in srgb, var(--brand-soft) 45%, var(--surface)); }
.choice:active:not(:disabled) { transform: scale(0.99); }
.choice:disabled { cursor: default; }
.choice-letter {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  font-family: var(--mono); font-size: 0.8rem; font-weight: 600; background: var(--surface-2); color: var(--ink-soft);
  transition: background 0.15s, color 0.15s;
}
.choice-text { flex: 1; }
.choice-mark { color: var(--good); stroke-width: 3; }
.choice.selected { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand); }
.choice.selected .choice-letter { background: var(--brand); color: var(--brand-ink); animation: pick 0.25s var(--ease); }
.choice.correct { border-color: var(--good); background: var(--good-bg); box-shadow: 0 0 0 1px var(--good); animation: pop 0.4s var(--ease); }
.choice.correct .choice-letter { background: var(--good); color: var(--surface); }
.choice.incorrect { border-color: var(--bad); background: var(--bad-bg); box-shadow: 0 0 0 1px var(--bad); animation: shake 0.38s var(--ease); }
.choice.incorrect .choice-letter { background: var(--bad); color: var(--surface); }
.answer-box { min-height: 120px; font-size: 1rem; }
.feedback { margin-top: 1rem; padding: 0.85rem 1rem; border-radius: 10px; font-size: 0.92rem; animation: rise 0.3s var(--ease) both; }
.feedback.good { background: var(--good-bg); color: var(--ink); box-shadow: inset 3px 0 0 var(--good); }
.feedback.good strong { color: var(--good); }
.feedback.bad { background: var(--bad-bg); color: var(--ink); box-shadow: inset 3px 0 0 var(--bad); }
.feedback.bad strong { color: var(--bad); }
.feedback.neutral { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--brand); }
.quiz-nav { display: flex; gap: 0.6rem; justify-content: space-between; margin-top: 1rem; }

/* ---------- Results ---------- */
.score-card { display: flex; align-items: center; gap: 2rem; padding: 1.75rem; flex-wrap: wrap; }
.score-card > div:last-child { flex: 1; min-width: 220px; }
.score-card h1 { margin-bottom: 0.3rem; }
.score-line { color: var(--ink-soft); font-size: 1.05rem; }
.score-line .num { color: var(--ink); font-weight: 700; font-size: 1.15rem; }
.score-card .builder-actions { margin-top: 1.1rem; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--surface-3); }
.ring-fg { stroke: var(--brand); stroke-linecap: round; stroke-dasharray: var(--dash); stroke-dashoffset: var(--off); animation: ring 1s var(--ease) both; }
.ring-fg.good { stroke: var(--good); }
.ring-fg.mid { stroke: var(--gold); }
.ring-fg.low { stroke: var(--bad); }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.6rem; font-weight: 700; }
.review-item { display: grid; grid-template-columns: 26px 1fr; gap: 0.8rem; padding: 1rem 1.2rem; border-top: 1px solid var(--line); }
.review-item:first-child { border-top: 0; }
.verdict-dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; }
.verdict-dot .icon { width: 14px; height: 14px; stroke-width: 3; }
.is-correct .verdict-dot { background: var(--good-bg); color: var(--good); }
.is-wrong .verdict-dot { background: var(--bad-bg); color: var(--bad); }
.ri-prompt { font-weight: 650; margin-bottom: 0.35rem; }
.ri-line { font-size: 0.9rem; display: flex; gap: 0.6rem; }
.ri-line span { flex: none; width: 6.5rem; color: var(--ink-faint); font-size: 0.8rem; font-weight: 600; padding-top: 0.1rem; }
.ri-line.good { color: var(--good); }
.review-item .help { margin-top: 0.35rem; }

/* ---------- Flashcards ---------- */
.flash-stats { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: 0.88rem; color: var(--ink-soft); }
.flash-stats .num { color: var(--ink); font-weight: 600; }
.fs-know { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--good); }
.fs-know .icon { width: 14px; height: 14px; stroke-width: 3; }
.fs-learn { color: var(--gold); }
.flashcard-wrap { display: flex; justify-content: center; padding: 1.5rem 0 1.25rem; perspective: 1400px; }
.flashcard { width: min(560px, 100%); height: 300px; border: 0; padding: 0; background: transparent; border-radius: 18px; }
.flashcard.fc-enter { animation: rise 0.35s var(--ease) both; }
.fc-inner { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.55s var(--ease); }
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem;
  padding: 2rem; border-radius: 18px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-md); text-align: center;
}
.fc-back { transform: rotateY(180deg); background: color-mix(in srgb, var(--brand-soft) 55%, var(--surface)); border-color: color-mix(in srgb, var(--brand) 25%, var(--line)); }
.flashcard:hover .fc-face { border-color: var(--line-strong); }
.side-label { position: absolute; top: 1rem; left: 1.25rem; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); }
.fc-text { font-family: var(--display); font-size: 1.6rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.fc-text.small { font-family: var(--body); font-size: 1.08rem; font-weight: 500; line-height: 1.5; max-width: 44ch; }
.fc-hint { position: absolute; bottom: 1rem; font-size: 0.78rem; color: var(--ink-faint); }
.flashcard-controls { display: flex; justify-content: center; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.btn.know { background: var(--good); border-color: var(--good); color: var(--surface); }
.btn.know:hover { filter: brightness(1.08); background: var(--good); }
.btn.learn { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, transparent); }
.btn.learn:hover { background: var(--gold-soft); border-color: var(--gold); }
.flashcard-controls + .center { margin-top: 0.75rem; }

/* ---------- Builder ---------- */
.notice { display: flex; gap: 0.8rem; align-items: flex-start; padding: 0.9rem 1rem; border-radius: var(--radius); background: var(--gold-soft); border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent); font-size: 0.9rem; margin-bottom: 1.25rem; }
.notice > .icon { color: var(--gold); margin-top: 2px; }
.option-card { margin-bottom: 1rem; padding: 0.4rem 1.25rem; }
.switch-row, .option-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.85rem 0; margin: 0; cursor: pointer; flex-wrap: wrap; }
.switch-row > span, .option-row > span { display: flex; flex-direction: column; gap: 0.1rem; font-weight: 400; }
.switch-row .help { font-weight: 400; }
.option-divider { height: 1px; background: var(--line); }
.switch { appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 999px; background: var(--surface-3); position: relative; cursor: pointer; transition: background 0.2s var(--ease); flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform 0.22s var(--ease); }
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(18px); }
.builder-card { position: relative; overflow: hidden; }
.admin-card { box-shadow: inset 0 3px 0 var(--brand), var(--shadow-sm); }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem; text-align: center; cursor: pointer; font-weight: 400;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1.1rem; background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--brand); background: var(--brand-soft); }
.dropzone > .icon { color: var(--brand); width: 22px; height: 22px; }
.dropzone input[type="file"] { font-size: 0.8rem; color: var(--ink-soft); margin-top: 0.4rem; max-width: 100%; }
.count-inputs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
.count-inputs .field { margin-bottom: 0.4rem; }
.count-inputs input { font-family: var(--mono); }
.builder-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.8rem; }
.busy-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; overflow: hidden; background: var(--surface-3); }
.busy-bar div { width: 35%; height: 100%; background: var(--brand); border-radius: 3px; animation: indeterminate 1.3s var(--ease) infinite; }
.tip { margin-top: 0.8rem; }
.save-card { margin-bottom: 0.5rem; }
.preview-item { padding: 1rem 1.2rem; border-top: 1px solid var(--line); }
.preview-item:first-child { border-top: 0; }
.pi-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.pi-title { font-weight: 650; }
.pi-choices { list-style: none; padding: 0; margin: 0.6rem 0 0; display: grid; gap: 0.3rem; }
.pi-choices li { display: flex; align-items: center; gap: 0.55rem; font-size: 0.9rem; color: var(--ink-soft); }
.pi-choices .choice-letter { width: 22px; height: 22px; font-size: 0.7rem; border-radius: 6px; }
.pi-choices li.correct { color: var(--good); font-weight: 600; }
.pi-choices li.correct .choice-letter { background: var(--good); color: var(--surface); }

/* ---------- Modal + toast ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1.25rem; background: rgba(8, 14, 30, 0.55); backdrop-filter: blur(3px); }
.modal-backdrop.animate { animation: fade 0.2s ease both; }
.modal-backdrop.animate .modal { animation: modal-in 0.3s var(--ease) both; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 1.75rem; max-width: 420px; width: 100%; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 0.6rem; }
.modal-badge { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold); }
.modal-badge .icon { width: 22px; height: 22px; }
.price-line { display: flex; align-items: baseline; gap: 0.5rem; }
.price { font-family: var(--display); font-size: 2.6rem; font-weight: 700; letter-spacing: -0.03em; }
.perks { list-style: none; padding: 0; margin: 0.2rem 0 0.6rem; display: grid; gap: 0.5rem; }
.perks li { display: flex; gap: 0.55rem; align-items: flex-start; font-size: 0.93rem; }
.perks .icon { color: var(--good); width: 16px; height: 16px; margin-top: 3px; stroke-width: 3; }
.modal .help.center { display: block; text-align: center; }
#toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); z-index: 60; max-width: min(440px, calc(100vw - 2rem));
  background: var(--ink); color: var(--bg); padding: 0.75rem 1.1rem; border-radius: 12px; font-size: 0.9rem; font-weight: 550; box-shadow: var(--shadow-lg);
  transform: translate(-50%, 140%); opacity: 0; pointer-events: none; transition: transform 0.35s var(--ease), opacity 0.25s;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.15rem; box-shadow: var(--shadow-sm); }
.stat-num { font-size: 1.7rem; font-weight: 600; letter-spacing: -0.03em; }
.stat-label { font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 1.75rem; align-items: start; }
.admin-test { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: 0.95rem 1.15rem; border-top: 1px solid var(--line); flex-wrap: wrap; }
.admin-test:first-child { border-top: 0; }
.admin-test.official { box-shadow: inset 3px 0 0 var(--brand); }
.at-main { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.at-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.admin-class-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 0.6rem; }
.admin-class-form input { grid-column: 1 / -1; }
.admin-class-form .btn { grid-column: 1 / -1; }
.admin-class-list { max-height: 460px; overflow-y: auto; }
.admin-class-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.6rem 1rem; border-top: 1px solid var(--line); }
.admin-class-row:first-child { border-top: 0; }
.acr-name { font-weight: 600; font-size: 0.92rem; }
.acr-right { display: flex; align-items: center; gap: 0.5rem; }

/* ---------- Loading ---------- */
.skeleton-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.skeleton { height: 52px; border-radius: 10px; background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }

/* ---------- Motion ---------- */
main.view-enter > * { animation: rise 0.42s var(--ease) both; }
main.view-enter > *:nth-child(2) { animation-delay: 0.04s; }
main.view-enter > *:nth-child(3) { animation-delay: 0.08s; }
main.view-enter > *:nth-child(4) { animation-delay: 0.12s; }
main.view-enter > *:nth-child(n+5) { animation-delay: 0.16s; }
main.view-enter .stagger > * { animation: rise 0.4s var(--ease) both; }
main.view-enter .stagger > *:nth-child(1) { animation-delay: 0.1s; }
main.view-enter .stagger > *:nth-child(2) { animation-delay: 0.15s; }
main.view-enter .stagger > *:nth-child(3) { animation-delay: 0.2s; }
main.view-enter .stagger > *:nth-child(4) { animation-delay: 0.25s; }
main.view-enter .stagger > *:nth-child(n+5) { animation-delay: 0.3s; }
main.view-enter .catalog-group { animation: rise 0.45s var(--ease) both; }
main.view-enter .catalog-group:nth-child(2) { animation-delay: 0.06s; }
main.view-enter .catalog-group:nth-child(3) { animation-delay: 0.12s; }
main.view-enter .catalog-group:nth-child(n+4) { animation-delay: 0.18s; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes pick { 0% { transform: scale(0.8); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.015); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes ring { from { stroke-dashoffset: var(--dash); } to { stroke-dashoffset: var(--off); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes indeterminate { 0% { transform: translateX(-100%); } 100% { transform: translateX(290%); } }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .auth-main { grid-template-columns: 1fr; gap: 2rem; padding-top: 2rem; }
  .admin-grid { grid-template-columns: 1fr; }
  .catalog { grid-template-columns: 1fr; gap: 0.75rem; }
  .dept-rail { position: static; flex-direction: row; overflow-x: auto; gap: 0.35rem; padding: 2px 2px 6px; margin: 0 -2px; scrollbar-width: none; }
  .dept-rail::-webkit-scrollbar { display: none; }
  .dept-item { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 0.38rem 0.8rem; font-size: 0.84rem; }
  .dept-item.on { background: var(--ink); color: var(--bg); box-shadow: none; border-color: var(--ink); }
  .dept-item.on .num { color: inherit; opacity: 0.7; }
  .dept-item.on::before { display: none; }
}
@media (max-width: 640px) {
  main { padding: 1.25rem 1rem 3rem; }
  .topbar-inner { padding: 0.6rem 1rem; gap: 0.6rem; }
  .user-name { display: none; }
  .top-right .btn.ghost { padding: 0.36rem 0.5rem; }
  .topnav button { padding: 0.4rem 0.55rem; }
  .topnav button.active::after { bottom: -0.62rem; }
  .class-row { grid-template-columns: minmax(0, 1fr) auto 16px; gap: 0.6rem; padding: 0.75rem 0.85rem; }
  .class-level { display: none; }
  .class-tests { font-size: 0.78rem; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .count-inputs { grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem; }
  .count-inputs label { font-size: 0.76rem; }
  .q-prompt { font-size: 1.12rem; }
  .question-card { padding: 1.2rem; }
  .flashcard { height: 260px; }
  .fc-text { font-size: 1.3rem; }
  .score-card { gap: 1.25rem; }
  .ring { width: 104px; height: 104px; }
  .site-footer { flex-direction: column; gap: 0.5rem; }
  .footer-links { margin-left: 0; }
  .level-seg, .unit-chips { align-self: stretch; overflow-x: auto; flex-wrap: nowrap; }
  .unit-chips button { flex: none; }
  .level-seg button { flex: none; }
  .ri-line { flex-direction: column; gap: 0; }
}
@media (max-width: 380px) {
  .plan-pill { display: none; }
}

/* ---------- Fixes: flexible inputs, compact mobile header ---------- */
.searchbox input { flex: 1; min-width: 0; }
.signout .icon { display: none; }
@media (max-width: 640px) {
  .signout span { display: none; }
  .signout .icon { display: block; }
  .brand span:last-child { font-size: 1.05rem; }
  .popular-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .popular-card { padding: 0.75rem 0.8rem; }
  .pc-name { font-size: 0.92rem; }
  .searchbox kbd { display: none; }
}
@media (max-width: 360px) {
  .brand span:last-child { display: none; }
}
@media (max-width: 640px) {
  .user-chip { display: none; }
  .topnav { min-width: 0; }
  .top-right { gap: 0.35rem; }
}

/* ---------- Accent colors (Settings > Appearance) ---------- */
:root[data-accent="crimson"] { --brand: #b42335; --brand-hover: #971c2c; --brand-soft: #fbe8eb; }
:root[data-accent="emerald"] { --brand: #157a52; --brand-hover: #106443; --brand-soft: #e2f4eb; }
:root[data-accent="violet"] { --brand: #6b3fc4; --brand-hover: #5a33a8; --brand-soft: #efe8fb; }
:root[data-accent="teal"] { --brand: #0e7c86; --brand-hover: #0b6770; --brand-soft: #e0f3f5; }
:root[data-accent="gold"] { --brand: #a86c00; --brand-hover: #8e5b00; --brand-soft: #fbf0da; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="crimson"] { --brand: #ff8a98; --brand-hover: #ffa6b1; --brand-soft: #3a1820; } }
:root[data-theme="dark"][data-accent="crimson"] { --brand: #ff8a98; --brand-hover: #ffa6b1; --brand-soft: #3a1820; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="emerald"] { --brand: #5fd3a1; --brand-hover: #7fe0b6; --brand-soft: #12301f; } }
:root[data-theme="dark"][data-accent="emerald"] { --brand: #5fd3a1; --brand-hover: #7fe0b6; --brand-soft: #12301f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="violet"] { --brand: #b69bff; --brand-hover: #c9b5ff; --brand-soft: #261c44; } }
:root[data-theme="dark"][data-accent="violet"] { --brand: #b69bff; --brand-hover: #c9b5ff; --brand-soft: #261c44; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="teal"] { --brand: #5ed0da; --brand-hover: #80dde5; --brand-soft: #10303a; } }
:root[data-theme="dark"][data-accent="teal"] { --brand: #5ed0da; --brand-hover: #80dde5; --brand-soft: #10303a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="gold"] { --brand: #f0bf4c; --brand-hover: #f6cf72; --brand-soft: #33280f; } }
:root[data-theme="dark"][data-accent="gold"] { --brand: #f0bf4c; --brand-hover: #f6cf72; --brand-soft: #33280f; }

/* ---------- Pins ---------- */
.pin-btn { display: inline-flex; align-items: center; gap: 0.35rem; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); border-radius: 9px; padding: 0.5rem 0.8rem; font-weight: 650; font-size: 0.86rem; transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.12s var(--ease); }
.pin-btn .icon { width: 16px; height: 16px; transition: transform 0.25s var(--ease); }
.pin-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.pin-btn:active { transform: scale(0.95); }
.pin-btn.on { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 45%, transparent); background: var(--brand-soft); }
.pin-btn.on .icon { transform: rotate(-20deg); fill: currentColor; }
.pin-btn.compact { padding: 0.35rem; border-color: transparent; background: transparent; border-radius: 8px; }
.pin-btn.compact:hover { background: var(--surface-2); }
.pin-btn.compact.on { background: var(--brand-soft); }
.tr-side { display: inline-flex; align-items: center; gap: 0.6rem; flex: none; }
.test-row { cursor: pointer; }
.head-actions, .title-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.title-row { justify-content: space-between; }
.pinned { margin-bottom: 1.25rem; }
.pinned .section-label .icon { width: 14px; height: 14px; }
.pinned-card { border-color: color-mix(in srgb, var(--brand) 25%, var(--line)); }
.pinned-card.test .pc-name { font-size: 0.98rem; }

/* ---------- Units on class pages ---------- */
.unit-chips { margin: 0 0 0.75rem; max-width: 100%; }
.unit-group { margin-top: 1.5rem; }
.unit-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: 0 0.1rem 0.6rem; border-bottom: 1px solid var(--line); margin-bottom: 0.75rem; }
.unit-head h2 { font-size: 1.2rem; }
.unit-head .count { font-size: 0.8rem; color: var(--ink-faint); }
.unit-field select { max-width: 360px; }
.unit-mini { width: auto; padding: 0.3rem 0.5rem; font-size: 0.8rem; border-radius: 7px; }

/* ---------- Top bar user button ---------- */
button.user-chip { border: 1px solid transparent; background: transparent; border-radius: 999px; padding: 0.2rem 0.55rem 0.2rem 0.2rem; color: var(--ink); transition: background 0.15s, border-color 0.15s; }
button.user-chip:hover, button.user-chip.active { background: var(--surface-2); border-color: var(--line); }
.user-chip .gear { width: 15px; height: 15px; color: var(--ink-faint); transition: transform 0.4s var(--ease); }
.user-chip:hover .gear { transform: rotate(60deg); }
.avatar { flex: none; }
.avatar.img { border-radius: 50%; object-fit: cover; background: var(--surface-2); display: block; }
.topnav { overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav button { white-space: nowrap; }

/* ---------- Settings ---------- */
.settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.settings-card { display: flex; flex-direction: column; gap: 0.9rem; padding: 1.4rem; }
.settings-card h2 { font-size: 1.15rem; }
.settings-card .field { margin-bottom: 0; }
.settings-card p { margin: 0; }
.avatar-row { display: flex; align-items: center; gap: 1rem; }
.avatar-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.avatar-actions .help { flex-basis: 100%; }
.avatar-actions label.btn { margin: 0; cursor: pointer; font-weight: 650; }
.inline-form { display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 180px; }
.swatches { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.45rem; }
.swatch { display: flex; align-items: center; gap: 0.5rem; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 9px; padding: 0.45rem 0.6rem; font-size: 0.84rem; font-weight: 600; color: var(--ink); transition: border-color 0.15s, transform 0.12s var(--ease); }
.swatch span { width: 18px; height: 18px; border-radius: 50%; background: var(--sw); flex: none; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35); transition: transform 0.2s var(--ease); }
.swatch:hover span { transform: scale(1.12); }
.swatch.on { border-color: var(--sw); box-shadow: 0 0 0 1px var(--sw); }
.swatch:active { transform: scale(0.97); }

/* ---------- My tests + leaderboard ---------- */
.play-line { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--ink-soft); margin-top: 0.15rem; }
.play-line .num { color: var(--ink); font-weight: 600; }
.play-line .pts, .play-line .pts .num { color: var(--brand); font-weight: 700; }
.me-card { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1rem; flex-wrap: wrap; }
.me-card > div { flex: 1; min-width: 180px; }
.lb-row { display: grid; grid-template-columns: 2.4rem 36px minmax(0, 1fr) auto; align-items: center; gap: 0.85rem; padding: 0.75rem 1.1rem; border-top: 1px solid var(--line); }
.lb-row:first-child { border-top: 0; }
.lb-row.me { background: var(--brand-soft); }
.lb-rank { font-family: var(--mono); font-weight: 700; text-align: center; color: var(--ink-soft); }
.lb-rank.gold, .lb-rank.silver, .lb-rank.bronze { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; justify-self: center; font-size: 0.85rem; }
.lb-rank.gold { background: linear-gradient(135deg, #e6b43a, #b8860b); }
.lb-rank.silver { background: linear-gradient(135deg, #b9c2cf, #7d8898); }
.lb-rank.bronze { background: linear-gradient(135deg, #d59363, #9c5a2c); }
.lb-name { display: flex; flex-direction: column; align-items: flex-start; font-weight: 650; min-width: 0; }
.lb-name .meta { font-weight: 400; }
.lb-top { display: flex; align-items: center; gap: 0.45rem; min-width: 0; max-width: 100%; }
.lb-dn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.you { display: inline-block; font-size: 0.68rem; font-weight: 700; background: var(--brand); color: var(--brand-ink); padding: 0.05rem 0.4rem; border-radius: 999px; vertical-align: middle; }
.lb-points { font-weight: 700; color: var(--brand); white-space: nowrap; }
.lb-points .num { font-size: 1.05rem; }
main.view-enter .lb-row { animation: rise 0.4s var(--ease) both; }
main.view-enter .lb-row:nth-child(2) { animation-delay: 0.04s; }
main.view-enter .lb-row:nth-child(3) { animation-delay: 0.08s; }
main.view-enter .lb-row:nth-child(n+4) { animation-delay: 0.12s; }

@media (max-width: 760px) {
  .settings { grid-template-columns: 1fr; }
  .swatches { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; }
  .topnav { order: 3; flex-basis: 100%; }
  .topnav button.active::after { bottom: -0.35rem; }
  .test-row { flex-direction: row; align-items: center; }
  .lb-row { padding: 0.7rem 0.8rem; gap: 0.6rem; }
}

/* ---- Upload guide, material meter, file chips ---- */
.guide { padding: 0; margin-bottom: 1rem; }
.guide summary { list-style: none; cursor: pointer; display: flex; gap: 0.8rem; align-items: center; padding: 1rem 1.25rem; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary > span:last-child { display: flex; flex-direction: column; gap: 0.1rem; }
.guide summary::after { content: "Show"; margin-left: auto; font-size: 0.8rem; font-weight: 600; color: var(--brand); }
.guide[open] summary::after { content: "Hide"; }
.guide-icon { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); flex: none; }
.guide-icon .icon { width: 18px; height: 18px; }
.guide-steps { margin: 0; padding: 0 1.25rem 0 3.4rem; display: grid; gap: 0.55rem; line-height: 1.5; }
.guide-steps li::marker { color: var(--brand); font-weight: 700; }
.guide-steps em { font-style: normal; font-weight: 600; background: var(--surface-2); padding: 0.05rem 0.35rem; border-radius: 5px; }
.guide-foot { padding: 0.8rem 1.25rem 1.1rem 3.4rem; margin: 0; }
.material-meter { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; }
.mm-bar { flex: 0 0 140px; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.mm-bar span { display: block; height: 100%; border-radius: 99px; background: var(--ink-faint); transition: width 0.35s var(--ease), background 0.2s; }
.material-meter.low .mm-bar span { background: var(--bad); }
.material-meter.ok .mm-bar span { background: var(--gold); }
.material-meter.good .mm-bar span, .material-meter.great .mm-bar span { background: var(--good); }
.file-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: -0.25rem 0 0.9rem; }
.file-chip { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; font-weight: 600; padding: 0.3rem 0.6rem; border-radius: 99px; background: var(--good-bg); color: var(--good); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .icon { width: 13px; height: 13px; flex: none; }

/* ---- Class page tabs + quality badges ---- */
.class-tabs { margin: 0 0 0.75rem; }
.class-tabs button .num { font-size: 0.75rem; opacity: 0.7; margin-left: 0.15rem; }
.badge-best, .badge-top { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.7rem; font-weight: 700; padding: 0.12rem 0.5rem; border-radius: 99px; }
.badge-best { background: var(--gold-soft); color: var(--gold); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 35%, transparent); }
.badge-top { background: var(--good-bg); color: var(--good); }
.badge-best .icon, .badge-top .icon { width: 12px; height: 12px; }
.empty-state.small { padding: 2rem 1rem; }
.quality-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.6rem; margin-top: 0.35rem; }
.q-score { font-size: 0.78rem; font-weight: 700; padding: 0.12rem 0.5rem; border-radius: 6px; }
.q-score.high { background: var(--good-bg); color: var(--good); }
.q-score.mid { background: var(--gold-soft); color: var(--gold); }
.q-score.low { background: var(--bad-bg); color: var(--bad); }
.points-rules { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; margin-top: 0.9rem; }
.points-rules > div { display: flex; gap: 0.6rem; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.7rem 0.8rem; font-size: 0.85rem; color: var(--ink-soft); line-height: 1.4; }
.points-rules .num { font-weight: 700; color: var(--brand); font-size: 1rem; flex: none; }
@media (max-width: 720px) {
  .points-rules { grid-template-columns: 1fr; }
  .class-tabs { align-self: stretch; overflow-x: auto; flex-wrap: nowrap; }
  .class-tabs button { flex: none; }
  .guide-steps { padding-left: 2.6rem; }
  .guide-foot { padding-left: 1.25rem; }
  .mm-bar { flex-basis: 90px; }
}
.class-tabs { display: flex; width: max-content; max-width: 100%; }
.unit-field select { width: 100%; max-width: 560px; }
