/* ==========================================================================
   Nerdlyy — Design System
   Brand theme: warm paper, ink navy, coral accent (official Nerdlyy palette).
   Ink #172747 · Coral #FF6B50 · Paper #FAF8F3 · Blue #8DB5F4 · Yellow #FFD166 · Mint #9DD9C7
   Zero external dependencies (offline-safe).
   ========================================================================== */

:root {
  /* brand tokens (see assets/web/nerdlyy-theme.css) */
  --nerdlyy-ink: #172747;
  --nerdlyy-coral: #FF6B50;
  --nerdlyy-paper: #FAF8F3;
  --nerdlyy-blue: #8DB5F4;
  --nerdlyy-yellow: #FFD166;
  --nerdlyy-mint: #9DD9C7;

  /* design-system aliases */
  --bg: var(--nerdlyy-paper);
  --bg-2: #F2F5FA;            /* soft blue-tinted surface */
  --panel: #FFFFFF;
  --panel-2: #F2F5FA;
  --panel-3: #C9D4E6;
  --line: #B4C2D4;
  --line-soft: #CBD5E4;
  --text: var(--nerdlyy-ink);
  --text-2: #43536E;
  --text-3: #5C6B85;
  --accent: var(--nerdlyy-coral);
  --accent-dim: #E4573F;
  --accent-deep: #D94F38;     /* readable coral for small text / links */
  --accent-soft: rgba(255, 107, 80, .10);
  --blue: var(--nerdlyy-blue);
  --blue-deep: #5B8DEF;
  --ok: #1E9E7B;
  --ok-soft: rgba(157, 217, 199, .25);
  --warn: #A87B00;
  --warn-soft: rgba(255, 209, 102, .30);
  --err: #D63A3A;
  --err-soft: rgba(214, 58, 58, .10);
  --gold: var(--nerdlyy-yellow);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --shadow: 0 10px 30px rgba(23, 39, 71, .10);
  --shadow-sm: 0 4px 14px rgba(23, 39, 71, .06);
  --max: 1180px;
}

* { box-sizing: border-box; }
/* The HTML hidden attribute must always win — author display rules
   (e.g. .user-menu-panel{display:flex}) otherwise force panels/avatars
   to stay visible. This single rule keeps every hidden toggle honest. */
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1100px 500px at 85% -100px, rgba(141, 181, 244, .16), transparent 60%),
    radial-gradient(900px 420px at -10% 0px, rgba(255, 107, 80, .06), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

main { flex: 1 0 auto; width: 100%; }
footer { margin-top: auto; }

img, svg, canvas { max-width: 100%; }
a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 1em; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .55em; font-weight: 700; letter-spacing: .01em; color: var(--text); }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
code, .mono { font-family: var(--mono); }
code { background: var(--panel-2); border: 1px solid var(--line-soft); padding: .1em .4em; border-radius: 5px; font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--line-soft); margin: 1.6em 0; }

.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 22px; }
.section { padding: 34px 0; }
.section + .section { padding-top: 6px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.muted { color: var(--text-2); }
.small { font-size: .86rem; }
.tiny { font-size: .78rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--blue-deep, #5B8DEF); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------- Header -------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 60;
  background: rgba(250, 248, 243, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
/* v5 — header fits on ONE row at desktop widths: the header may use a
   wider container than the page body (menus used to wrap under the brand),
   the menu hugs the brand on the LEFT (it used to start near the centre,
   leaving dead space and forcing a horizontal page drag on laptops), the
   auth block pins to the right edge, and the nav wraps instead of ever
   overflowing. */
.site-header .container { max-width: 1280px; }
.header-inner { display: flex; align-items: center; gap: 14px; min-height: 64px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); font-weight: 800; font-size: 1.14rem; letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
.brand img { width: 34px; height: 34px; object-fit: contain; flex: none; }
/* v5.5 — the logo stays optically centred against the two-line brand copy
   (name + sub-label) on every page, never stuck to the header's top edge */
.brand img { display: block; align-self: center; margin-top: 1px; }
.brand .brand-sub { color: var(--text-3); font-weight: 600; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; display: block; margin-top: -4px; }
/* v5 — the menu hugs the brand on the LEFT (it used to be pushed to the
   right edge, starting near the centre and leaving dead space on the left,
   which forced a horizontal page drag on laptop widths). The auth block is
   pushed to the right edge, and the nav wraps instead of overflowing. */
.main-nav { margin-left: 0; display: flex; align-items: center; gap: 3px; flex-wrap: wrap; min-width: 0; row-gap: 4px; }
.main-nav a {
  color: var(--text-2); padding: 8px 8px; border-radius: 10px; font-size: .89rem; font-weight: 600;
}
.main-nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.main-nav a.active { color: var(--accent-deep); background: var(--accent-soft); }
.progress-chip {
  display: inline-flex; align-items: center; gap: 7px; margin-left: 8px;
  font-size: .78rem; color: var(--text-2); background: var(--panel);
  border: 1px solid var(--line-soft); padding: 5px 11px; border-radius: 999px; white-space: nowrap;
}
.progress-chip .bar { width: 54px; height: 5px; background: var(--panel-3); border-radius: 3px; overflow: hidden; }
.progress-chip .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--nerdlyy-blue), var(--nerdlyy-coral)); border-radius: 3px; }
.nav-toggle { display: none; margin-left: auto; background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 8px 11px; cursor: pointer; font: inherit; font-weight: 600; }

/* v5 — the progress chip was the widest item in the menu row (~250px with
   its long label): cap the label, tighten the chip, and below 1240px show
   only the progress bar so the menu row never wraps awkwardly. */
.progress-chip { padding: 6px 10px; }
.progress-chip .pc-label { max-width: 132px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1560px) {
  .progress-chip { display: none; }
}
@media (max-width: 1240px) {
  .streak-chip span { display: none; }
  .streak-chip { padding: 8px 9px; }
}
@media (max-width: 1150px) {
  .streak-chip { display: none; }
}

@media (max-width: 840px) {
  .nav-toggle { display: inline-flex; align-items: center; gap: 8px; }
  .main-nav {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--nerdlyy-paper); border-bottom: 1px solid var(--line);
    flex-direction: column; align-items: stretch; padding: 10px 18px 16px; gap: 4px;
    box-shadow: var(--shadow);
  }
  .main-nav.open { display: flex; }
  .progress-chip { margin: 6px 0 0; }
}

/* -------------------------------- Hero --------------------------------- */
.hero { padding: 64px 0 40px; position: relative; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: url("../assets/brand/dot-grid.svg"); background-size: 340px;
  opacity: .5; mask-image: radial-gradient(720px 420px at 78% 18%, #000 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(720px 420px at 78% 18%, #000 30%, transparent 75%);
}
.hero > .container { position: relative; }
.hero .kicker {
  display: inline-flex; align-items: center; gap: 8px; font-size: .75rem; font-weight: 800;
  letter-spacing: .14em; text-transform: uppercase; color: var(--accent-deep);
  background: var(--accent-soft); border: 1px solid rgba(255, 107, 80, .28);
  padding: 6px 13px; border-radius: 999px; margin-bottom: 18px;
}
.hero h1 { font-size: clamp(1.9rem, 4.4vw, 3rem); max-width: 21ch; }
.hero .lede { font-size: 1.12rem; color: var(--text-2); max-width: 62ch; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }
.hero-grid { display: grid; grid-template-columns: 1.25fr .9fr; gap: 40px; align-items: center; }
.hero-art { position: relative; }
.hero-art .illus { width: 100%; max-width: 380px; margin: 0 auto; display: block; filter: drop-shadow(0 14px 28px rgba(23, 39, 71, .10)); }
.hero-art .blob { position: absolute; z-index: -1; width: 78%; left: 50%; top: 52%; transform: translate(-50%, -50%); opacity: .16; }
@media (max-width: 900px) { .hero-grid { grid-template-columns: 1fr; } .hero { padding: 44px 0 30px; } .hero-art { max-width: 330px; margin: 0 auto; } }

/* ------------------------------- Buttons -------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  font-family: var(--font); font-size: .93rem; font-weight: 700;
  padding: 10px 18px; border-radius: 12px; cursor: pointer;
  border: 1px solid transparent; transition: background .15s, border-color .15s, transform .18s, box-shadow .18s;
  text-decoration: none !important; line-height: 1.2;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--nerdlyy-coral); color: #fff; box-shadow: 0 6px 16px rgba(255, 107, 80, .32); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); transform: translateY(-2px); box-shadow: 0 10px 22px rgba(255, 107, 80, .38); }
.btn-ink { background: var(--nerdlyy-ink); color: #fff; }
.btn-ink:hover:not(:disabled) { background: #22345C; transform: translateY(-2px); box-shadow: 0 8px 18px rgba(23, 39, 71, .22); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--panel); border-color: var(--accent); color: var(--accent-deep); }
.btn-ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(30, 158, 123, .4); }
.btn-ok:hover:not(:disabled) { background: rgba(157, 217, 199, .45); }
.btn-danger { background: var(--err-soft); color: var(--err); border-color: rgba(214, 58, 58, .35); }
.btn-danger:hover:not(:disabled) { background: rgba(214, 58, 58, .16); }
.btn-sm { padding: 6px 12px; font-size: .82rem; border-radius: 9px; }
.btn-lg { padding: 13px 24px; font-size: 1rem; border-radius: 14px; }
/* base size for every inline icon — unconstrained SVGs used to blow up to
   full panel width inside flex headings (the "giant question mark" bug) */
.ic { width: 18px; height: 18px; flex: none; }
.btn .ic { width: 16px; height: 16px; flex: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* -------------------------------- Cards --------------------------------- */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(272px, 1fr)); gap: 16px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  padding: 20px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 9px; position: relative;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.card:hover { border-color: rgba(255, 107, 80, .45); transform: translateY(-3px); box-shadow: var(--shadow); }
.card h3 { margin: 0; font-size: 1.02rem; }
.card p { margin: 0; color: var(--text-2); font-size: .89rem; }
.card .card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card .go { margin-top: auto; padding-top: 10px; font-size: .86rem; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.card .go .ic { width: 14px; height: 14px; transition: transform .15s; }
.card:hover .go .ic { transform: translateX(3px); }
.card-icon {
  width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); flex: none; overflow: hidden;
}
.card-icon svg { width: 22px; height: 22px; }
.card-icon img { width: 30px; height: 30px; object-fit: contain; }
.card-icon.tint-blue { background: rgba(141, 181, 244, .18); }
.card-icon.tint-mint { background: var(--ok-soft); }
.card-icon.tint-gold { background: var(--warn-soft); }
.card-flagship { border-color: rgba(255, 107, 80, .4); background: linear-gradient(180deg, rgba(255, 107, 80, .05), var(--panel) 55%); }

/* ------------------------------- Badges --------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: .72rem; font-weight: 700;
  letter-spacing: .03em; padding: 3.5px 10px; border-radius: 999px; white-space: nowrap;
  border: 1px solid transparent;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { color: var(--ok); background: var(--ok-soft); border-color: rgba(30, 158, 123, .35); }
.badge-plan { color: var(--warn); background: var(--warn-soft); border-color: rgba(168, 123, 0, .3); }
.badge-info { color: var(--accent-deep); background: var(--accent-soft); border-color: rgba(255, 107, 80, .32); }
.badge-dim { color: var(--text-2); background: var(--panel-2); border-color: var(--line-soft); }
.badge-flag { color: #fff; background: linear-gradient(135deg, #FF8A70, var(--nerdlyy-coral)); font-weight: 800; }

/* ------------------------------- Panels --------------------------------- */
.panel { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.panel + .panel { margin-top: 16px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 13px 18px; border-bottom: 1px solid var(--line-soft); background: rgba(242, 245, 250, .6);
}
.panel-head h3 { margin: 0; font-size: .95rem; display: flex; align-items: center; gap: 9px; }
.panel-head .ic { width: 16px; height: 16px; color: var(--accent-deep); }
.panel-body { padding: 18px; }
.panel-body > :last-child { margin-bottom: 0; }

/* ------------------------------ Lab layout ------------------------------ */
.lab-layout { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 18px; align-items: start; }
@media (max-width: 1020px) { .lab-layout { grid-template-columns: 1fr; } }
.sim-wrap {
  position: relative; background: linear-gradient(180deg, #EAF1FA, #F0F5FC); border: 1px solid var(--line);
  border-radius: var(--r-md); overflow: hidden; min-height: 420px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.5);
}
.sim-wrap canvas { display: block; width: 100%; height: 100%; }
.sim-wrap.tall { height: 560px; }
.sim-wrap.medium { height: 430px; }
.sim-hint {
  position: absolute; left: 12px; bottom: 12px; font-size: .74rem; font-weight: 600; color: var(--text);
  background: rgba(255, 255, 255, .96); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 8px; pointer-events: none; backdrop-filter: blur(4px); box-shadow: var(--shadow-sm);
}
.sim-badge {
  position: absolute; top: 12px; left: 12px; font-family: var(--mono); font-size: .74rem; font-weight: 700;
  color: var(--accent-deep); background: rgba(255, 255, 255, .96); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 8px; pointer-events: none; box-shadow: var(--shadow-sm);
}
.sim-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: #EDF3FB;
  color: var(--text-2); font-size: .85rem; font-weight: 600;
}
.sim-loading img { width: 64px; height: 64px; }

/* ------------------------------ Controls -------------------------------- */
.field { display: block; padding: 7px 0; }
.field-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.field-label .name { font-size: .84rem; font-weight: 700; color: var(--text); }
.field-label .val { font-family: var(--mono); font-size: .84rem; color: var(--accent-deep); font-weight: 700; }
.field-input { display: flex; gap: 8px; align-items: center; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--panel-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 17px; height: 17px; margin-top: -5.5px; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--nerdlyy-coral); box-shadow: 0 1px 5px rgba(23, 39, 71, .25);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--panel-3); }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: #fff; border: 2.5px solid var(--nerdlyy-coral); }
input[type="range"]:focus-visible { outline: 3px solid rgba(91, 141, 239, .45); border-radius: 8px; }
input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }

.num-input, .select-input {
  width: 100%; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 8px 10px; font-family: var(--mono); font-size: .88rem;
}
.num-input:focus, .select-input:focus { border-color: var(--nerdlyy-blue); outline: 3px solid rgba(141, 181, 244, .35); outline-offset: 0; }
.num-input.err { border-color: var(--err); }
.select-input { font-family: var(--font); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: .86rem; color: var(--text-2); }
.switch { position: relative; width: 38px; height: 21px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--panel-3); border-radius: 999px; transition: background .15s; }
.switch .knob { position: absolute; top: 2.5px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(23,39,71,.3); transition: transform .15s; }
.switch input:checked + .track { background: var(--nerdlyy-coral); }
.switch input:checked + .track .knob { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 3px solid var(--nerdlyy-blue); outline-offset: 2px; }

.control-group { border-top: 1px solid var(--line-soft); margin-top: 10px; padding-top: 10px; }
.control-group:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.control-group-title {
  font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-2); margin-bottom: 4px; display: flex; align-items: center; gap: 7px;
}

/* ---------------------------- Measurements ------------------------------ */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 9px; }
.kv { background: var(--panel-2); border: 1px solid #C4D0E2; border-radius: var(--r-sm); padding: 9px 11px; min-width: 0; }
.kv .k { font-size: .7rem; color: #3E4E6B; letter-spacing: .05em; text-transform: uppercase; font-weight: 700; }
.kv .v { font-family: var(--mono); font-size: 1.02rem; color: var(--text); margin-top: 2px; word-break: break-all; }
.kv .v .unit { color: #3E4E6B; font-size: .76rem; margin-left: 3px; }
.kv.hl .v { color: var(--accent-deep); }
.kv.ok .v { color: var(--ok); }
.kv.warn .v { color: var(--warn); }

/* -------------------------------- Table --------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--r-md); }
table.data { width: 100%; border-collapse: collapse; font-size: .86rem; background: var(--panel); }
table.data th {
  text-align: left; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2);
  padding: 9px 12px; background: #E7EDF6; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
table.data td { padding: 8px 12px; border-bottom: 1px solid #DCE4EF; font-family: var(--mono); font-size: .83rem; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.txt { font-family: var(--font); }
table.data tr.diff td { color: var(--warn); font-weight: 600; }

/* -------------------------------- Quiz ---------------------------------- */
.quiz-q { margin-bottom: 4px; font-weight: 600; }
.quiz-meta { font-size: .76rem; color: var(--text-3); margin-bottom: 10px; letter-spacing: .04em; }
.quiz-opt {
  display: flex; gap: 11px; align-items: flex-start; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--r-md); padding: 11px 14px; margin: 8px 0; cursor: pointer; font-family: var(--font);
  font-size: .92rem; line-height: 1.45; transition: border-color .12s, background .12s, box-shadow .12s;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); background: #FFF9F7; box-shadow: var(--shadow-sm); }
.quiz-opt .key {
  font-family: var(--mono); font-size: .76rem; font-weight: 700; color: var(--accent-deep);
  border: 1px solid rgba(255, 107, 80, .4); border-radius: 6px; padding: 1px 7px; flex: none; margin-top: 1px;
  background: var(--panel);
}
.quiz-opt.correct { border-color: var(--ok); background: #F0FAF6; }
.quiz-opt.correct .key { color: var(--ok); border-color: rgba(30, 158, 123, .5); }
.quiz-opt.wrong { border-color: var(--err); background: #FDF3F3; }
.quiz-opt.wrong .key { color: var(--err); border-color: rgba(214, 58, 58, .5); }
.quiz-opt:disabled { cursor: default; }
.quiz-explain {
  border-left: 3px solid var(--nerdlyy-blue); background: rgba(141, 181, 244, .14); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 11px 14px; font-size: .88rem; color: var(--text-2); margin: 12px 0;
}
.quiz-explain.good { border-left-color: var(--ok); background: #F0FAF6; }
.quiz-explain.bad { border-left-color: var(--err); background: #FDF3F3; }
.quiz-score { font-weight: 700; font-size: 1.05rem; }

/* ------------------------------- Notices --------------------------------- */
.note {
  border: 1px solid; border-radius: var(--r-md); padding: 12px 15px; font-size: .88rem;
  display: flex; gap: 11px; align-items: flex-start; margin: 14px 0;
}
.note .ic { width: 17px; height: 17px; flex: none; margin-top: 2px; }
.note-info { border-color: rgba(141, 181, 244, .55); background: rgba(141, 181, 244, .14); color: var(--text-2); }
.note-info .ic { color: var(--blue-deep); }
.note-warn { border-color: rgba(255, 209, 102, .65); background: var(--warn-soft); color: var(--text-2); }
.note-warn .ic { color: var(--warn); }
.note p { margin: 0; }

/* ------------------------------- Equations ------------------------------- */
.eq-list { display: grid; gap: 9px; }
.eq {
  background: var(--panel-2); border: 1px solid #C4D0E2; border-radius: var(--r-sm);
  padding: 10px 13px; font-family: var(--mono); font-size: .95rem; overflow-x: auto; white-space: nowrap;
}
.eq .what { display: block; font-family: var(--font); font-size: .74rem; color: var(--text-2); margin-bottom: 3px; letter-spacing: .03em; }
sup, sub { font-size: .72em; }

/* ------------------------------ Structure ------------------------------- */
.crumbs { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--text-3); padding: 18px 0 4px; flex-wrap: wrap; }
.crumbs a { color: var(--text-2); }
.crumbs .sep { opacity: .5; }
.page-head { padding: 10px 0 22px; border-bottom: 1px solid var(--line-soft); margin-bottom: 28px; }
.page-head .badges { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin-bottom: 8px; }
.page-head .desc { color: var(--text-2); max-width: 72ch; font-size: 1.02rem; }
.page-head .meta-row { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 14px; font-size: .84rem; color: var(--text-3); }
.page-head .meta-row a { color: var(--text-2); font-weight: 600; }

.subnav { display: flex; gap: 7px; flex-wrap: wrap; margin: 0 0 22px; position: sticky; top: 76px; z-index: 40; padding: 8px 0; background: linear-gradient(180deg, var(--bg) 75%, transparent); }
.subnav a {
  font-size: .8rem; font-weight: 600; color: var(--text-2); padding: 6px 13px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
}
.subnav a:hover { text-decoration: none; color: var(--accent-deep); border-color: rgba(255, 107, 80, .45); }

.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 26px; align-items: start; }
@media (max-width: 940px) { .two-col { grid-template-columns: 1fr; } }

/* ------------------------------ Stat blocks ----------------------------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 15px 17px; box-shadow: var(--shadow-sm); }
.stat .n { font-family: var(--mono); font-size: 1.55rem; font-weight: 700; color: var(--accent-deep); }
.stat .l { font-size: .78rem; color: var(--text-2); margin-top: 2px; }

/* -------------------------------- Search -------------------------------- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.filter-bar .search { flex: 1; min-width: 220px; position: relative; }
.filter-bar .search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); }
.filter-bar input[type="search"] {
  width: 100%; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 11px; padding: 10px 12px 10px 35px; font-family: var(--font); font-size: .92rem;
}
.filter-bar input[type="search"]:focus { border-color: var(--nerdlyy-blue); outline: 3px solid rgba(141, 181, 244, .35); outline-offset: 0; }
.filter-bar select { border-radius: 11px; }

/* -------------------------------- Module -------------------------------- */
.module-block { margin-bottom: 34px; }
.module-head { display: flex; align-items: center; gap: 13px; margin-bottom: 14px; }
.module-code {
  font-family: var(--mono); font-weight: 700; color: var(--accent-deep); background: var(--accent-soft);
  border: 1px solid rgba(255, 107, 80, .3); width: 36px; height: 36px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center; flex: none; font-size: .9rem;
}
.module-head h2 { margin: 0; font-size: 1.15rem; }
.module-head .muted { font-size: .82rem; }
.module-icon { width: 42px; height: 42px; object-fit: contain; flex: none; }

/* --------------------------------- Ask ---------------------------------- */
.ask-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 15px; }
.ask-box .ask-row { display: flex; gap: 9px; }
.ask-box input { flex: 1; background: var(--panel-2); }
.ask-result { margin-top: 12px; display: grid; gap: 8px; }
.ask-hit { background: var(--panel-2); border: 1px solid #C4D0E2; border-radius: var(--r-sm); padding: 10px 13px; font-size: .88rem; }
.ask-hit .score { color: var(--text-3); font-size: .72rem; }

/* --------------------------------- Toast -------------------------------- */
.toast-zone { position: fixed; bottom: 18px; right: 18px; z-index: 100; display: grid; gap: 9px; max-width: 340px; }
.toast {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-soft); border-radius: var(--r-md);
  padding: 11px 15px; font-size: .88rem; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in .22s ease;
}
.toast .ic { width: 16px; height: 16px; flex: none; margin-top: 2px; color: var(--blue-deep); }
.toast.ok .ic { color: var(--ok); } .toast.warn .ic { color: var(--warn); } .toast.err .ic { color: var(--err); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --------------------------------- Modal -------------------------------- */
.modal-back { position: fixed; inset: 0; background: rgba(23, 39, 71, .5); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r-lg); max-width: 620px; width: 100%; max-height: 82vh; overflow-y: auto; padding: 24px; box-shadow: var(--shadow); }
.modal h3 { margin-top: 0; }
.modal-close { float: right; background: none; border: 0; color: var(--text-3); font-size: 1.25rem; cursor: pointer; padding: 2px 8px; border-radius: 6px; }
.modal-close:hover { color: var(--text); background: var(--panel-2); }

/* -------------------------------- Footer -------------------------------- */
.site-footer { border-top: 1px solid var(--line-soft); background: var(--nerdlyy-ink); margin-top: 56px; padding: 34px 0; font-size: .85rem; color: #B9C4D9; }
.footer-grid { display: flex; justify-content: space-between; gap: 26px; flex-wrap: wrap; }
.footer-grid h4 { font-size: .74rem; letter-spacing: .13em; text-transform: uppercase; color: #8DB5F4; margin-bottom: 10px; }
.footer-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.footer-grid a { color: #DCE4F2; }
.footer-grid a:hover { color: var(--nerdlyy-coral); }
.footer-note { margin-top: 22px; padding-top: 16px; border-top: 1px solid rgba(255, 255, 255, .12); color: #C3CEE0; font-size: .78rem; }

/* ------------------------------ Progress -------------------------------- */
.pbar { height: 7px; background: var(--panel-3); border-radius: 4px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--nerdlyy-blue), var(--nerdlyy-coral)); border-radius: 4px; transition: width .3s; }
.checklist { display: grid; gap: 7px; font-size: .88rem; }
.checklist .done { color: var(--ok); }
.checklist .ic { width: 15px; height: 15px; vertical-align: -2px; margin-right: 7px; }

/* ---------------------------- Illustrations ----------------------------- */
.illus { display: block; max-width: 100%; height: auto; }
.illus-frame {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  padding: 18px; box-shadow: var(--shadow-sm); display: flex; align-items: center; justify-content: center;
}
.illus-frame .illus { width: 100%; max-width: 300px; }
.empty-state { text-align: center; padding: 44px 18px; color: var(--text-2); }
.empty-state .illus { width: 190px; margin: 0 auto 16px; opacity: .95; }
.empty-state h3 { margin-bottom: 4px; }
.avatar-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.avatar-row .av { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--line-soft); background: var(--panel-2); overflow: hidden; }
.avatar-row .av img { width: 100%; height: 100%; object-fit: cover; }
.about-illus { width: 100%; max-width: 340px; }

/* -------------------------------- Misc ---------------------------------- */
.legend-row { display: flex; gap: 15px; flex-wrap: wrap; font-size: .78rem; color: var(--text-2); margin-top: 9px; }
.legend-row .sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(23, 39, 71, .18); }
.fdb-arrow { stroke-width: 2.5; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}

@media print {
  .site-header, .site-footer, .subnav, .toast-zone, .btn { display: none !important; }
  body { background: #fff; color: #000; }
}

/* ========================= Accounts & admin (Supabase) ========================= */

/* --- header auth area --- */
.nav-auth { display: inline-flex; align-items: center; margin-left: auto; }
.nav-auth-loading { width: 74px; height: 30px; border-radius: 10px; background: linear-gradient(90deg, #EEF1F7 25%, #E3E8F1 50%, #EEF1F7 75%); background-size: 200% 100%; animation: nav-skel 1.1s infinite linear; display: inline-block; }
@keyframes nav-skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.nav-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 1.5px solid var(--line-soft); background: var(--panel); display: inline-block; }
.nav-avatar-fallback { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: var(--accent-deep); background: #FFE3DB; border: 1.5px solid #FFC9B8; }
.user-menu { position: relative; min-width: 0; max-width: 100%; }
.user-menu-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line-soft); border-radius: 999px; padding: 4px 12px 4px 5px; cursor: pointer; font: inherit; font-size: .86rem; font-weight: 600; color: var(--text); box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s, transform .15s; min-width: 0; max-width: 100%; }
/* The display name must be shrinkable so a long name on a crowded header
   ellipsises inside the pill instead of pushing the chip out of the box. */
.user-menu-name { min-width: 0; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-avatar { flex: none; }
.user-menu-btn:hover { border-color: var(--line); box-shadow: 0 4px 18px rgba(23,39,71,.12); }
.user-menu-btn:active { transform: scale(.97); }
.user-menu-btn[aria-expanded="true"] { border-color: var(--nerdlyy-blue); background: #F4F8FF; }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + 8px); background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r-md); box-shadow: var(--shadow-md, 0 10px 30px rgba(23,39,71,.12)); min-width: 190px; padding: 6px; z-index: 60; display: flex; flex-direction: column; transform-origin: top right; }
.user-menu-panel:not([hidden]) { animation: menu-pop .16s cubic-bezier(.2,.8,.3,1.2); }
@keyframes menu-pop { from { opacity: 0; transform: translateY(-4px) scale(.97); } to { opacity: 1; transform: none; } }
.user-menu-panel a, .user-menu-panel button { text-align: left; background: none; border: 0; font: inherit; font-size: .88rem; color: var(--text); padding: 9px 12px; border-radius: 9px; text-decoration: none; cursor: pointer; }
.user-menu-panel a:hover, .user-menu-panel button:hover { background: #F2F5FB; }
.user-menu-panel button { color: #B3402A; border-top: 1px solid var(--line-soft); border-radius: 0 0 9px 9px; margin-top: 3px; }

/* --- full Python syllabus (cs-curriculum) --- */
.syllabus-list { list-style: none; margin: 0; padding: 0; }
.syllabus-unit { padding: 18px 4px; border-bottom: 1px solid var(--line-soft); }
.syllabus-unit:last-child { border-bottom: 0; }
.syllabus-unit .su-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.syllabus-unit .su-num { flex: none; background: var(--nerdlyy-blue); color: #fff; border-radius: 8px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; padding: 3px 9px; }
.syllabus-unit .su-title { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.02rem; }
.syllabus-unit .su-title:hover { color: var(--nerdlyy-blue); text-decoration: underline; }
.syllabus-unit .su-topics { margin: 9px 0 6px; color: var(--text-2); font-size: .9rem; line-height: 1.62; }
.syllabus-unit .su-outcome { margin: 0; font-size: .86rem; color: var(--text-2); }
.syllabus-unit .su-outcome strong { color: var(--text); }

/* --- bookmark button (topic pages) --- */
.bookmark-btn { display: inline-flex; align-items: center; gap: 7px; background: var(--panel); color: var(--text); border: 1px solid var(--line-soft); border-radius: 999px; padding: 7px 15px; font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer; margin-top: 12px; box-shadow: var(--shadow-sm); transition: border-color .15s, background .15s; }
.bookmark-btn .ic { width: 15px; height: 15px; }
.bookmark-btn:hover { border-color: var(--nerdlyy-blue); }
.bookmark-btn.is-saved { background: #FFF4E0; border-color: #FFD166; color: #8A6400; }

/* --- personal notes (topic pages) --- */
.notes-input { width: 100%; min-height: 120px; resize: vertical; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 13px 15px; font-family: var(--font); font-size: .93rem; color: var(--text); line-height: 1.55; }
.notes-input:focus { outline: 3px solid rgba(141, 181, 244, .35); border-color: var(--nerdlyy-blue); }

/* --- auth callback --- */
.auth-callback-panel h1 { font-size: 1.4rem; }
@media (prefers-reduced-motion: reduce) { .nav-auth-loading { animation: none; } }

/* --- admin dashboard --- */
.admin-tab .panel { margin-bottom: 18px; }
table.data th { text-align: left; }
.pub-toggle { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 4px; cursor: pointer; font: inherit; font-size: .78rem; font-weight: 600; color: var(--text-2); }
.pub-toggle .pub-knob { width: 26px; height: 16px; border-radius: 999px; background: #D7DEEA; position: relative; transition: background .15s; flex: none; }
.pub-toggle .pub-knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(23,39,71,.25); transition: transform .15s; }
.pub-toggle.is-on { color: #1F7A4D; }
.pub-toggle.is-on .pub-knob { background: var(--ok, #9DD9C7); }
.pub-toggle.is-on .pub-knob::after { transform: translateX(10px); }
.role-chip { background: var(--panel); border: 1px dashed var(--line); border-radius: 999px; padding: 4px 11px; font: inherit; font-size: .78rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.role-chip:hover { border-color: var(--nerdlyy-blue); color: var(--text); }
.role-chip.is-set { border-style: solid; border-color: #FFB39E; background: #FFE3DB; color: #B3402A; }
.role-chip:disabled { opacity: .55; cursor: wait; }

/* --- profile page --- */
#profile-content .card h3 { margin-bottom: 10px; }
.kv .v.small { word-break: break-word; }

/* ============================ AI Teacher chat ============================ */
/* Matches the Nerdlyy design system: paper, ink navy, coral accent, Inter. */

.ai-launcher {
  position: fixed; right: 20px; bottom: 20px; z-index: 95;
  display: inline-flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, var(--nerdlyy-coral), #E4573F);
  border: 0; border-radius: 999px; cursor: pointer; padding: 6px;
  box-shadow: 0 10px 26px rgba(255, 107, 80, .40), 0 2px 8px rgba(23, 39, 71, .18);
  color: #fff; font: inherit;
  transition: transform .18s ease, box-shadow .18s ease;
}
.ai-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(255, 107, 80, .48), 0 3px 10px rgba(23, 39, 71, .2); }
.ai-launcher:active { transform: translateY(0) scale(.98); }
.ai-launcher[aria-expanded="true"] { opacity: 0; pointer-events: none; transform: translateY(8px); }
.ai-launcher-ic { width: 42px; height: 42px; border-radius: 50%; background: rgba(255, 255, 255, .16); display: flex; align-items: center; justify-content: center; }
.ai-launcher-ic svg { width: 22px; height: 22px; }
.ai-launcher-label { padding-right: 8px; font-weight: 700; font-size: .86rem; letter-spacing: .01em; }
@media (max-width: 640px) { .ai-launcher-label, .ai-launcher-copy, .ai-launcher-arrow { display: none; } .ai-launcher { right: 14px; bottom: 14px; padding: 8px; } }
.ai-launcher::after { content: ""; position: absolute; inset: -4px; border-radius: 999px; border: 2px solid rgba(255, 107, 80, .45); opacity: 0; animation: ai-ping 2.6s ease-out 1.6s 3; pointer-events: none; }
@keyframes ai-ping { 0% { transform: scale(.9); opacity: .8; } 70% { transform: scale(1.25); opacity: 0; } 100% { opacity: 0; } }

.ai-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 96;
  width: 396px; max-width: calc(100vw - 28px); max-height: min(72vh, 620px);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: 0 24px 60px rgba(23, 39, 71, .28), 0 4px 14px rgba(23, 39, 71, .14);
  display: flex; flex-direction: column; overflow: hidden;
  animation: ai-panel-in .22s cubic-bezier(.2, .8, .3, 1.1);
}
@keyframes ai-panel-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) { .ai-panel { right: 8px; left: 8px; bottom: 8px; width: auto; max-height: 78vh; } }

.ai-head { display: flex; align-items: center; gap: 11px; padding: 13px 14px; background: linear-gradient(135deg, #1B2E56, var(--nerdlyy-ink)); color: #fff; }
.ai-head-av { width: 38px; height: 38px; border-radius: 50%; background: #fff; border: 2px solid rgba(255, 107, 80, .6); overflow: hidden; flex: none; }
.ai-head-av img { width: 100%; height: 100%; object-fit: cover; }
.ai-head-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ai-head-txt strong { font-size: .95rem; line-height: 1.2; }
.ai-head-sub { font-size: .68rem; color: #B9C4D9; letter-spacing: .02em; }
.ai-icon-btn { background: none; border: 0; color: #B9C4D9; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex: none; transition: background .15s, color .15s; }
.ai-icon-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.ai-icon-btn svg { width: 16px; height: 16px; }

.ai-messages { flex: 1; overflow-y: auto; padding: 14px; background: var(--bg-2); display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.ai-msg { display: flex; align-items: flex-end; gap: 8px; animation: ai-msg-in .18s ease; }
@keyframes ai-msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.ai-msg-av { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 1.5px solid var(--line-soft); overflow: hidden; flex: none; }
.ai-msg-av img { width: 100%; height: 100%; object-fit: cover; }
.ai-bubble { max-width: 84%; border-radius: 14px; padding: 10px 13px; font-size: .88rem; line-height: 1.55; }
.ai-bubble p { margin: 0 0 .5em; } .ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble code { font-family: var(--mono); font-size: .82rem; background: rgba(141, 181, 244, .18); border: 1px solid rgba(141, 181, 244, .30); border-radius: 6px; padding: 0 5px; }
.ai-md-list { margin: .35em 0; padding-left: 1.1em; } .ai-md-list li { margin: .15em 0; }
/* ---------- AI markdown blocks (v3.8): code, tables, quotes, rules ---------- */
.ai-bubble h3, .ai-bubble h4, .ai-bubble h5, .ai-bubble h6 { margin: .55em 0 .3em; line-height: 1.3; }
.ai-bubble h3:first-child, .ai-bubble h4:first-child, .ai-bubble h5:first-child, .ai-bubble h6:first-child { margin-top: .1em; }
.ai-bubble .ai-md-pre { margin: .5em 0; padding: 10px 12px; background: #0B1220; color: #EAF1FF; border: 1px solid rgba(141,181,244,.28); border-radius: 10px; overflow-x: auto; }
.ai-bubble .ai-md-pre code { display: block; background: none; border: 0; padding: 0; font-size: .78rem; line-height: 1.55; color: inherit; white-space: pre; }
.ai-msg-user .ai-bubble .ai-md-pre { background: rgba(0,0,0,.28); border-color: rgba(255,255,255,.3); }
.ai-bubble .ai-md-table-wrap { overflow-x: auto; margin: .5em 0; }
.ai-bubble .ai-md-table { border-collapse: collapse; font-size: .82rem; min-width: 40%; }
.ai-bubble .ai-md-table th, .ai-bubble .ai-md-table td { border: 1px solid var(--line-soft); padding: 5px 9px; text-align: left; }
.ai-bubble .ai-md-table th { background: rgba(141,181,244,.12); font-weight: 650; }
.ai-msg-user .ai-bubble .ai-md-table th, .ai-msg-user .ai-bubble .ai-md-table td { border-color: rgba(255,255,255,.35); }
.ai-bubble .ai-md-quote { margin: .5em 0; padding: .35em .8em; border-left: 3px solid var(--accent); background: rgba(141,181,244,.08); border-radius: 0 8px 8px 0; }
.ai-bubble .ai-md-quote p { margin: 0; }
.ai-bubble .ai-md-hr { border: 0; border-top: 1px solid var(--line-soft); margin: .7em 0; }
.ai-bubble a { color: var(--accent); text-decoration: underline; }
.ai-msg-user .ai-bubble a { color: #fff; }
/* ---------- AI math rendering (KaTeX-lite, fully offline) ----------
   Stacked fractions, radicals, boxes, overlines, sup/sub + unicode
   operators so the tutor's LaTeX renders like real math, not raw text. */
.ai-bubble .mm-inline, .ai-bubble .mm-display { display: inline; }
.ai-bubble .mm-display { display: block; margin: .45em 0; padding: .3em .2em; overflow-x: auto; text-align: center; }
.ai-bubble .mm-display:first-child { margin-top: 0; } .ai-bubble .mm-display:last-child { margin-bottom: 0; }
.ai-bubble .mm-line { display: block; line-height: 1.7; }
.ai-bubble .mm-inline .mm-line { display: inline; }
.ai-bubble .mm-frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: -0.55em; margin: 0 .14em; font-size: .95em; line-height: 1.25; }
.ai-bubble .mm-frac .mm-num { padding: 0 .3em .06em; border-bottom: 1.2px solid currentColor; }
.ai-bubble .mm-frac .mm-den { padding: .06em .3em 0; }
.ai-bubble .mm-sqrt { display: inline-block; margin: 0 .1em; }
.ai-bubble .mm-sqrt::before { content: '√'; }
.ai-bubble .mm-sqrt .mm-rad { border-top: 1.2px solid currentColor; padding: 0 .18em; margin-left: -0.05em; }
.ai-bubble .mm-box { display: inline-block; border: 1.4px solid currentColor; border-radius: 5px; padding: .1em .45em; margin: .05em .1em; background: rgba(141,181,244,.10); }
.ai-bubble .mm-ovl { text-decoration: overline; }
.ai-bubble .mm-hat::before { content: '\0302'; }   /* combining circumflex */
.ai-bubble .mm-vec { position: relative; display: inline-block; padding-right: .05em; }
.ai-bubble .mm-vec-arrow { position: absolute; top: -0.72em; left: 12%; font-size: .7em; line-height: 1; opacity: .85; }
.ai-bubble .mm-text { font-style: normal; }
.ai-bubble sup, .ai-bubble sub { line-height: 0; }
.ai-bubble .mm-gap { display: inline-block; width: 1.1em; }
/* larger, clearer display math inside the AI bubble */
.ai-bubble .mm-display .mm-frac { vertical-align: -0.6em; }
.ai-msg-user { justify-content: flex-end; }
.ai-msg-user .ai-bubble { background: linear-gradient(135deg, var(--nerdlyy-coral), #E4573F); color: #fff; border-bottom-right-radius: 4px; box-shadow: 0 3px 10px rgba(255, 107, 80, .30); }
.ai-msg-user .ai-bubble code { background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .28); color: #fff; }
.ai-msg-ai .ai-bubble { background: var(--panel); border: 1px solid var(--line-soft); border-bottom-left-radius: 4px; color: var(--text); box-shadow: var(--shadow-sm); }
.ai-typing .ai-bubble { display: flex; gap: 5px; align-items: center; padding: 13px 15px; }
.ai-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .35; animation: ai-dot-b 1.1s infinite; }
.ai-dot:nth-child(2) { animation-delay: .18s; } .ai-dot:nth-child(3) { animation-delay: .36s; }
@keyframes ai-dot-b { 0%, 70%, 100% { transform: translateY(0); opacity: .35; } 35% { transform: translateY(-4px); opacity: 1; } }
.ai-notice { background: var(--warn-soft); border: 1px solid rgba(255, 209, 102, .6); color: var(--text-2); border-radius: 10px; padding: 8px 12px; font-size: .8rem; }

.ai-empty { text-align: center; padding: 18px 10px 6px; color: var(--text-2); font-size: .88rem; }
.ai-empty-av { width: 62px; height: 62px; margin: 0 auto 10px; border-radius: 50%; background: #fff; border: 2px solid var(--line-soft); overflow: hidden; box-shadow: var(--shadow-sm); }
.ai-empty-av img { width: 100%; height: 100%; object-fit: cover; }
.ai-empty p { margin: 0; }

.ai-suggest { display: flex; gap: 7px; flex-wrap: wrap; padding: 0 14px 10px; background: var(--bg-2); align-items: center; }
.ai-suggest-label { font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.ai-chip { background: var(--panel); border: 1px solid var(--line); color: var(--text-2); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .76rem; font-weight: 600; cursor: pointer; transition: border-color .15s, color .15s, transform .15s; }
.ai-chip:hover { border-color: var(--accent); color: var(--accent-deep); transform: translateY(-1px); }

.ai-inputrow { display: flex; gap: 8px; padding: 11px 12px; border-top: 1px solid var(--line-soft); background: var(--panel); align-items: flex-end; }
.ai-inputrow textarea { flex: 1; resize: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; font-family: var(--font); font-size: .88rem; color: var(--text); line-height: 1.45; max-height: 120px; outline: none; }
.ai-inputrow textarea:focus { border-color: var(--blue-deep); box-shadow: 0 0 0 3px rgba(91, 141, 239, .22); background: #fff; }
.ai-send { width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0; background: linear-gradient(135deg, var(--nerdlyy-coral), #E4573F); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(255, 107, 80, .35); transition: transform .15s, box-shadow .15s; }
.ai-send:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(255, 107, 80, .45); }
.ai-send:active:not(:disabled) { transform: scale(.94); }
.ai-send:disabled { opacity: .45; cursor: default; }
.ai-send svg { width: 17px; height: 17px; margin-left: 2px; }
.ai-foot { margin: 0; padding: 8px 14px 10px; font-size: .68rem; color: var(--text-3); background: var(--panel); border-top: 1px solid #EDF1F7; }

@media (prefers-reduced-motion: reduce) { .ai-launcher::after { animation: none; } }

/* ===================== UI polish & lightweight motion ==================== */

/* Header gains a soft shadow once the page scrolls (class set from utils.js) */
.site-header { transition: box-shadow .25s ease; }
.site-header.is-scrolled { box-shadow: 0 8px 26px rgba(23, 39, 71, .10); }

/* Hero: subtle brand dot-grid wash behind the content, fading out downward */
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: url("../assets/brand/dot-grid.svg") repeat;
  background-size: 26px 26px; opacity: .5;
  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,.9), transparent 78%);
  mask-image: linear-gradient(180deg, rgba(0,0,0,.9), transparent 78%);
}
@media (max-width: 900px) { .hero::before { opacity: .3; } }

/* Gentle float for the hero illustration + coral blob orbit */
.hero-art { position: relative; }
.hero-art .illus { animation: hero-float 6s ease-in-out infinite; }
@keyframes hero-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.hero-art .blob { position: absolute; inset: -8% -6% auto auto; width: 58%; z-index: -1; animation: hero-blob 9s ease-in-out infinite; }
@keyframes hero-blob { 0%, 100% { transform: rotate(-2deg) scale(1); } 50% { transform: rotate(2.5deg) scale(1.06); } }

/* Coral accent bar before section titles */
.section-head h2 { position: relative; padding-left: 14px; }
.section-head h2::before {
  content: ""; position: absolute; left: 0; top: .34em; height: .78em; width: 5px;
  border-radius: 999px; background: linear-gradient(180deg, var(--nerdlyy-coral), #E4573F);
}
.section .panel-head h3, .section-head h2 { /* keep rhythm stable */ }

/* Scroll-reveal (armed only from JS, so no-JS users keep full visibility) */
.reveal-armed { opacity: 0; transform: translateY(12px); }
.reveal-armed.reveal-in { opacity: 1; transform: none; transition: opacity .5s ease, transform .5s cubic-bezier(.2,.8,.3,1); }

/* Card icon pop on hover */
.card { will-change: transform; }
.card:hover .card-icon { transform: scale(1.08) rotate(-3deg); }
.card-icon { transition: transform .25s cubic-bezier(.2,.8,.3,1.4); }

/* Buttons: press feedback */
.btn:active:not(:disabled) { transform: translateY(-1px) scale(.98); }
.btn-primary { transition: background .18s, transform .18s, box-shadow .18s; }
.btn-ghost { transition: border-color .18s, background .18s, transform .18s; }

/* Live badge dot: soft pulse to signal interactivity */
.badge .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 6px; background: var(--ok); }
.badge-ok .dot { animation: dot-pulse 2.2s ease infinite; }
@keyframes dot-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(30, 158, 123, .30); } 50% { box-shadow: 0 0 0 5px rgba(30, 158, 123, 0); } }

/* Footer links: slide underline */
.site-footer a { position: relative; }
.site-footer a::after {
  content: ""; position: absolute; left: 0; right: 100%; bottom: -2px; height: 2px;
  border-radius: 2px; background: var(--nerdlyy-coral); transition: right .2s ease;
}
.site-footer a:hover::after { right: 0; }

/* Quiz option keys: subtle lift on hover */
.quiz-opt:hover:not(:disabled) .key { background: #FFF4F1; }

/* Progress bar: smoother + gradient shine on the filled part */
.pbar i { background: linear-gradient(90deg, var(--nerdlyy-blue), var(--nerdlyy-coral)) , linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent); background-blend-mode: normal; }

/* Panels: soften entrance without hiding content */
.panel { transition: box-shadow .2s ease; }
.panel:hover { box-shadow: var(--shadow-sm); }

/* Home AI-teacher feature strip: real capabilities, not a fake chat transcript */
.ai-capability-list { display: grid; gap: 10px; max-width: 320px; width: 100%; margin: 0 auto; }
.ai-capability-list > div { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel-2); color: var(--text); }
.ai-capability-list img { flex: none; object-fit: contain; }
@media (max-width: 940px) { .ai-capability-list { max-width: 100%; } }

/* ==================== AI Teacher refreshed chat surface ==================== */
.ai-launcher {
  right: 24px; bottom: 24px; gap: 12px; padding: 9px 15px 9px 9px;
  border: 1px solid rgba(255,255,255,.3); border-radius: 18px;
  background: linear-gradient(135deg, #ff745b 0%, #ed4f3b 100%);
  box-shadow: 0 15px 34px rgba(212, 74, 55, .27), 0 4px 12px rgba(18, 33, 60, .15);
}
.ai-launcher-ic { width: 43px; height: 43px; border-radius: 14px; background: rgba(255,255,255,.17); }
.ai-launcher-ic svg { width: 22px; height: 22px; }
.ai-launcher-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding-right: 2px; }
.ai-launcher-copy strong { font-size: .88rem; letter-spacing: -.01em; }
.ai-launcher-copy small { font-size: .7rem; color: rgba(255,255,255,.8); }
.ai-launcher-arrow { display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; border-radius: 50%; background: rgba(255,255,255,.13); }
.ai-launcher-arrow svg { width: 16px; height: 16px; }
.ai-launcher-label { display: none; }
.ai-launcher[aria-expanded="true"] { opacity: 0; pointer-events: none; transform: translateY(8px); }
/* Conflict state: footer links/buttons scrolled under the launcher corner —
   it steps aside (transparent + click-through) until the zone is clear. */
.ai-launcher.ai-launcher--ghost { opacity: 0; pointer-events: none; transform: translateY(10px) scale(.94); }
.ai-panel[hidden] { display: none !important; }
.ai-panel {
  right: 22px; bottom: 22px; width: min(456px, calc(100vw - 28px));
  height: min(720px, calc(100dvh - 44px)); max-height: 780px; min-height: 440px;
  border: 1px solid rgba(205,215,229,.92); border-radius: 25px;
  background: #f9fbfe; box-shadow: 0 28px 90px rgba(16,31,57,.28), 0 4px 14px rgba(16,31,57,.09);
  animation: ai-panel-in .24s cubic-bezier(.2,.8,.2,1);
}
.ai-head {
  position: relative; min-height: 82px; gap: 11px; padding: 16px 15px;
  background: radial-gradient(circle at 0 0, rgba(255,116,91,.24), transparent 40%), linear-gradient(135deg,#172746 0%,#20375f 100%);
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.ai-head-av { width: 44px; height: 44px; border-radius: 15px; border: 1px solid rgba(255,255,255,.45); box-shadow: 0 3px 12px rgba(0,0,0,.13); }
.ai-head-txt { gap: 5px; }
.ai-head-txt strong { font-size: .96rem; letter-spacing: -.015em; color: #fff; }
.ai-head-txt > span { font-size: .72rem; color: #bac8dd; }
.ai-status { display: inline-flex; align-items: center; gap: 6px; flex: none; border: 1px solid rgba(255,255,255,.13); border-radius: 999px; padding: 5px 8px; font-size: .64rem; font-weight: 700; color: #ced8e7; white-space: nowrap; }
.ai-status i { display: block; width: 6px; height: 6px; border-radius: 50%; background: #f1c56b; box-shadow: 0 0 0 3px rgba(241,197,107,.12); }
.ai-status[data-state="online"] { color: #d8ffeb; }
.ai-status[data-state="online"] i { background: #58d99a; box-shadow: 0 0 0 3px rgba(88,217,154,.15); }
.ai-status[data-state="offline"], .ai-status[data-state="degraded"] { color: #ffe1d8; }
.ai-status[data-state="offline"] i, .ai-status[data-state="degraded"] i { background: #ff927d; box-shadow: 0 0 0 3px rgba(255,146,125,.15); }
.ai-icon-btn { width: 30px; height: 30px; border-radius: 10px; color: #b7c5dc; }
.ai-icon-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.ai-icon-btn svg { width: 17px; height: 17px; }
.ai-connection { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border-bottom: 1px solid #f0d6ab; background: #fff8ec; color: #674619; }
.ai-connection[hidden] { display: none; }
.ai-connection-icon { width: 28px; height: 28px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; background: #ffedcf; color: #9b6517; }
.ai-connection-icon svg { width: 17px; height: 17px; }
.ai-connection-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.ai-connection-copy strong { font-size: .76rem; line-height: 1.3; }
.ai-connection-copy span { font-size: .69rem; line-height: 1.45; color: #82643c; }
.ai-retry { flex: none; border: 1px solid #e5bd7c; border-radius: 9px; background: #fff; color: #79511a; font: inherit; font-size: .69rem; font-weight: 750; padding: 7px 9px; cursor: pointer; }
.ai-retry:hover { background: #fff0d6; }
.ai-messages { flex: 1; min-height: 0; padding: 19px 17px; gap: 17px; background: linear-gradient(180deg,#f7f9fc 0%,#f3f6fb 100%); overscroll-behavior: contain; }
.ai-welcome { margin: auto 0; text-align: center; padding: 8px 4px 16px; color: var(--text-2); }
.ai-welcome-kicker { display: flex; align-items: center; justify-content: center; gap: 7px; color: #8491a6; font-size: .62rem; font-weight: 800; letter-spacing: .13em; margin-bottom: 17px; }
.ai-welcome-kicker span { display: block; width: 6px; height: 6px; border-radius: 50%; background: #fa745b; box-shadow: 0 0 0 4px rgba(250,116,91,.12); }
.ai-welcome-avatar { width: 66px; height: 66px; margin: 0 auto 12px; padding: 4px; border-radius: 22px; background: linear-gradient(135deg,#fff,#ffe4dc); border: 1px solid #ffccbd; box-shadow: 0 8px 20px rgba(231,91,68,.12); }
.ai-welcome-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ai-welcome h3 { margin: 0 0 8px; color: #1a2b49; font-size: 1.48rem; line-height: 1.2; letter-spacing: -.045em; }
.ai-welcome > p { max-width: 310px; margin: 0 auto; font-size: .83rem; line-height: 1.65; color: #6e7b90; }
.ai-welcome-note { display: inline-flex; align-items: center; gap: 7px; margin-top: 17px; padding: 8px 11px; border: 1px solid #e6ebf3; border-radius: 10px; background: rgba(255,255,255,.75); color: #64738a; font-size: .7rem; }
.ai-welcome-note svg { width: 15px; height: 15px; color: #e86650; }
.ai-msg { gap: 9px; align-items: flex-start; }
.ai-msg-av { width: 29px; height: 29px; margin-top: 19px; border-radius: 10px; border: 1px solid #dfe5ef; box-shadow: 0 2px 5px rgba(20,40,70,.05); }
.ai-msg-content { display: flex; flex-direction: column; gap: 5px; min-width: 0; max-width: calc(100% - 39px); }
.ai-msg-label { color: #8591a4; font-size: .59rem; font-weight: 800; letter-spacing: .09em; padding-left: 2px; }
.ai-msg-user .ai-msg-content { align-items: flex-end; max-width: 88%; }
.ai-msg-user .ai-msg-label { text-align: right; }
.ai-bubble { max-width: 100%; border-radius: 16px; padding: 12px 14px; font-size: .84rem; line-height: 1.68; overflow-wrap: anywhere; }
.ai-bubble p { margin: 0 0 .65em; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble h3, .ai-bubble h4, .ai-bubble h5 { color: inherit; margin: .75em 0 .35em; line-height: 1.3; font-size: .93rem; }
.ai-bubble h3:first-child, .ai-bubble h4:first-child { margin-top: 0; }
.ai-bubble strong { font-weight: 750; }
.ai-bubble code { word-break: break-word; }
.ai-md-list { margin: .4em 0 .6em; padding-left: 1.25em; }
.ai-md-list li { margin: .3em 0; padding-left: 2px; }
.ai-msg-user .ai-bubble { background: linear-gradient(135deg,#ff795f,#ec543f); border: 1px solid rgba(202,69,47,.24); box-shadow: 0 6px 13px rgba(232,84,60,.15); border-bottom-right-radius: 5px; }
.ai-msg-ai .ai-bubble { background: #fff; border: 1px solid #e4e9f1; border-bottom-left-radius: 5px; color: #34425a; box-shadow: 0 3px 8px rgba(24,43,73,.035); }
.ai-msg-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 2px 0 5px 2px; }
.ai-msg-action { appearance: none; border: 1px solid #dbe3ef; background: #fff; color: #52617a; padding: 4px 9px; border-radius: 7px; font-family: inherit; font-size: .68rem; font-weight: 650; line-height: 1.2; cursor: pointer; transition: background .14s, border-color .14s, color .14s; }
.ai-msg-action:hover { border-color: #ff9b88; color: #b73e2c; background: #fff6f3; }
.ai-msg-action:focus-visible { outline: 2px solid #5b8def; outline-offset: 2px; }
.ai-msg-action-primary { background: #fff0ec; border-color: #ffb7a8; color: #a93525; }
.ai-msg-action-primary:hover { background: #ffe5de; border-color: #ff8c75; }
.ai-msg-actions button:disabled { opacity: .55; cursor: wait; }

.ai-typing .ai-bubble { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; padding: 12px 14px; }
.ai-thinking-copy { font-size: .75rem; color: #7a879b; margin-right: 4px; }
.ai-notice { border-radius: 12px; padding: 10px 12px; font-size: .78rem; line-height: 1.5; }
.ai-suggest { display: block; padding: 0 15px 13px; background: #f3f6fb; }
.ai-suggest[hidden] { display: none; }
.ai-suggest-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; color: #52617a; font-size: .72rem; font-weight: 700; }
.ai-suggest-heading small { color: #9ba6b7; font-size: .56rem; font-weight: 800; letter-spacing: .1em; }
.ai-suggest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.ai-chip { display: flex; min-width: 0; align-items: center; gap: 8px; text-align: left; padding: 10px; border-radius: 13px; background: rgba(255,255,255,.88); border: 1px solid #e3e9f2; color: #42516a; font: inherit; cursor: pointer; transition: border-color .16s, transform .16s, box-shadow .16s, background .16s; }
.ai-chip > svg { width: 14px; height: 14px; flex: none; color: #9aa6b8; }
.ai-chip:hover { border-color: #f5a18f; background: #fff; transform: translateY(-1px); box-shadow: 0 4px 10px rgba(23,39,71,.05); }
.ai-chip-icon { display: inline-flex; width: 31px; height: 31px; flex: none; align-items: center; justify-content: center; border-radius: 10px; background: #fff0ec; color: #df624d; }
.ai-chip-icon svg { width: 16px; height: 16px; }
.ai-chip-copy { display: flex; flex-direction: column; min-width: 0; gap: 3px; flex: 1; }
.ai-chip-copy strong { font-size: .7rem; font-weight: 750; color: #293a57; }
.ai-chip-copy small { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; color: #7e8ba0; font-size: .63rem; line-height: 1.4; overflow-wrap: anywhere; }
.ai-composer-wrap { background: #fff; border-top: 1px solid #e7ecf4; padding: 11px 13px 10px; }
.ai-inputrow { border: 1px solid #dfe6f0; background: #f9fbfe; border-radius: 15px; padding: 7px 7px 7px 12px; gap: 8px; align-items: flex-end; box-shadow: inset 0 1px 2px rgba(25,44,74,.025); }
.ai-inputrow:focus-within { border-color: #9cb4e6; background: #fff; box-shadow: 0 0 0 3px rgba(91,141,239,.11); }
.ai-inputrow textarea { min-width: 0; min-height: 39px; max-height: 124px; padding: 10px 2px; border: 0; background: transparent; box-shadow: none; font-size: .83rem; line-height: 1.45; }
.ai-inputrow textarea:focus { border: 0; outline: none; box-shadow: none; background: transparent; }
.ai-inputrow textarea:disabled { opacity: .7; }
.ai-send { width: 39px; height: 39px; border-radius: 12px; box-shadow: 0 5px 11px rgba(232,84,60,.2); }
.ai-send svg { width: 17px; height: 17px; margin: 0; }
.ai-send:disabled { opacity: .38; box-shadow: none; }
.ai-composer-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 3px 0; color: #9aa5b5; font-size: .61rem; }
.ai-composer-meta b { font-weight: 400; padding: 0 3px; color: #c1c8d3; }
.ai-foot { display: none; }
@media (max-width: 640px) {
  .ai-launcher { right: 14px; bottom: 14px; padding: 7px 11px 7px 7px; gap: 9px; border-radius: 16px; }
  .ai-launcher-ic { width: 39px; height: 39px; border-radius: 12px; }
  .ai-launcher-copy strong { font-size: .81rem; }
  .ai-launcher-copy small { font-size: .65rem; }
  .ai-launcher-arrow { display: none; }
  .ai-panel { inset: 8px; width: auto; height: calc(100dvh - 16px); min-height: 0; max-height: none; border-radius: 22px; }
  .ai-head { min-height: 75px; padding: 13px 11px; gap: 8px; }
  .ai-head-av { width: 39px; height: 39px; border-radius: 13px; }
  .ai-head-txt strong { font-size: .84rem; }
  .ai-head-txt > span { font-size: .65rem; }
  .ai-status { padding: 5px 6px; font-size: .58rem; gap: 5px; }
  .ai-icon-btn { width: 27px; height: 29px; }
  .ai-messages { padding: 15px 12px; }
  .ai-suggest { padding: 0 10px 10px; }
  .ai-chip { padding: 8px; gap: 6px; }
  .ai-chip-icon { width: 27px; height: 27px; }
  .ai-chip-copy strong { font-size: .66rem; }
  .ai-chip-copy small { font-size: .6rem; }
  .ai-composer-wrap { padding: 9px 10px 8px; }
  .ai-composer-meta { font-size: .57rem; }
  .ai-connection { padding: 9px 10px; gap: 7px; }
  .ai-connection-copy span { font-size: .65rem; }
  .ai-retry { padding: 7px; }
}
@media (max-width: 370px) {
  .ai-status { display: none; }
  .ai-suggest-grid { grid-template-columns: 1fr; }
  .ai-chip-copy small { -webkit-line-clamp: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .ai-panel, .ai-msg, .ai-dot, .ai-launcher::after { animation: none !important; }
  .ai-launcher, .ai-chip { transition: none !important; }
}

/* ==========================================================================
   Nerdlyy — Premium polish layer (Apple-OS-style, Subtle Premium)
   Same warm-paper/ink/coral identity; refined glass, depth and motion.
   ========================================================================== */

:root {
  --glass: rgba(255, 255, 255, .78);
  --glass-border: rgba(23, 39, 71, .08);
  --ease: cubic-bezier(.25, .1, .25, 1);
  --spring: cubic-bezier(.34, 1.3, .5, 1);
}

/* ---------- refined type ---------- */
h1 { letter-spacing: -0.018em; font-weight: 800; }
h2 { letter-spacing: -0.012em; font-weight: 750; }
h3 { letter-spacing: -0.008em; }
p { text-wrap: pretty; }
::selection { background: rgba(255, 107, 80, .22); }

/* ---------- glass header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 90;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(1.7) blur(16px);
  backdrop-filter: saturate(1.7) blur(16px);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 1px 2px rgba(23, 39, 71, .04), 0 8px 28px -18px rgba(23, 39, 71, .18);
}
.site-header .header-inner { transition: padding .2s var(--ease); }
.main-nav a {
  border-radius: 10px;
  font-weight: 600;
  transition: color .18s var(--ease), background .18s var(--ease), transform .18s var(--ease);
}
.main-nav a:hover { background: rgba(23, 39, 71, .05); text-decoration: none; transform: translateY(-1px); }
.main-nav a.active { color: var(--accent-deep); background: var(--accent-soft); }
.main-nav a.active::after { border-radius: 3px; }

/* ---------- buttons: quieter borders, deeper press, gentle lift ---------- */
.btn {
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), background .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease);
  will-change: transform;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(180deg, #FF7A5F, #F45B3E);
  border-color: rgba(214, 79, 56, .5);
  box-shadow: 0 1px 2px rgba(214, 79, 56, .35), 0 6px 16px -6px rgba(255, 107, 80, .55), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(214, 79, 56, .3), 0 12px 24px -8px rgba(255, 107, 80, .6), inset 0 1px 0 rgba(255, 255, 255, .25); }
.btn-ghost:hover { transform: translateY(-1px); box-shadow: 0 6px 14px -8px rgba(23, 39, 71, .3); }
.btn-ok { background: linear-gradient(180deg, #2FB491, #1E9E7B); border-color: rgba(30, 158, 123, .5); color: #fff; }

:focus-visible { outline: 2.5px solid rgba(91, 141, 239, .65); outline-offset: 2px; border-radius: 8px; }

/* ---------- cards: soft lift + hairline highlight ---------- */
.card {
  transition: transform .22s var(--ease), box-shadow .22s var(--ease), border-color .22s var(--ease);
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 2px 4px rgba(23, 39, 71, .05), 0 18px 40px -16px rgba(23, 39, 71, .22);
  border-color: rgba(255, 107, 80, .35);
  text-decoration: none;
}
.card h3 { transition: color .18s var(--ease); }
.card:hover h3 { color: var(--accent-deep); }
.panel { box-shadow: var(--shadow-sm); }
.panel:hover { box-shadow: 0 2px 4px rgba(23, 39, 71, .04), 0 14px 34px -18px rgba(23, 39, 71, .18); }
.panel { transition: box-shadow .2s var(--ease); }

/* ---------- clamp utility: cards never overflow with text ---------- */
.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- subnav: pill style ---------- */
.subnav a { transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--ease); border-radius: 999px; }
.subnav a:hover { transform: translateY(-1px); }

/* ---------- badges: crisper ---------- */
.badge { letter-spacing: .015em; font-weight: 650; }
.badge-flag { background: linear-gradient(135deg, var(--accent), #E4573F); border: 0; box-shadow: 0 2px 8px -2px rgba(255, 107, 80, .5); }

/* ---------- progress chip in nav ---------- */
.progress-chip { transition: box-shadow .2s var(--ease), transform .2s var(--ease); }
.progress-chip:hover { transform: translateY(-1px); box-shadow: 0 6px 16px -8px rgba(23, 39, 71, .3); }
.progress-chip .bar { background: rgba(23, 39, 71, .1); border-radius: 99px; overflow: hidden; }
.progress-chip .bar i {
  background: linear-gradient(90deg, var(--nerdlyy-coral), #FF8A70);
  border-radius: 99px;
  transition: width .5s var(--ease);
}

/* ---------- streak chip in nav ---------- */
.streak-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  font-size: .93rem;
  text-decoration: none;
  white-space: nowrap;
  transition: color .18s var(--ease), background .18s var(--ease);
}
.streak-chip:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.streak-chip svg { width: 15px; height: 15px; color: var(--nerdlyy-coral); flex: none; }
.streak-chip b { color: var(--text); font-weight: 700; }

/* ---------- announcement banner ---------- */
.announce {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 16px;
  border: 1px solid rgba(91, 141, 239, .3);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  background: linear-gradient(180deg, rgba(141, 181, 244, .16), rgba(141, 181, 244, .08));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: announce-in .35s var(--ease);
  position: relative;
  z-index: 80;
}
.announce.announce-warn { border-color: rgba(232, 169, 61, .45); background: linear-gradient(180deg, rgba(255, 209, 102, .25), rgba(255, 209, 102, .1)); }
.announce.announce-coral { border-color: rgba(255, 107, 80, .35); background: linear-gradient(180deg, rgba(255, 107, 80, .13), rgba(255, 107, 80, .06)); }
@keyframes announce-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.announce-ic { flex: none; width: 20px; height: 20px; margin-top: 2px; color: var(--blue-deep); }
.announce-warn .announce-ic { color: #C77C00; }
.announce-coral .announce-ic { color: var(--accent-deep); }
.announce-body { flex: 1; min-width: 0; }
.announce-body strong { display: block; font-size: .86rem; color: var(--text); }
.announce-body p { margin: 1px 0 0; font-size: .8rem; color: var(--text-2); }
.announce a { font-weight: 650; white-space: nowrap; }
.announce-close {
  flex: none;
  width: 26px; height: 26px;
  border: 0;
  background: rgba(23, 39, 71, .06);
  border-radius: 8px;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s;
}
.announce-close:hover { background: rgba(23, 39, 71, .12); }

/* ---------- TL;DR callout on lessons ---------- */
.tl-dr {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: linear-gradient(135deg, rgba(157, 217, 199, .16), rgba(141, 181, 244, .1));
  border: 1px solid rgba(47, 169, 140, .28);
  border-radius: var(--r-md);
  padding: 13px 16px;
  margin: 0 0 18px;
}
.tl-dr-label {
  flex: none;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #14735A;
  background: rgba(157, 217, 199, .3);
  border: 1px solid rgba(47, 169, 140, .35);
  border-radius: 999px;
  padding: 3px 9px;
  margin-top: 2px;
}
.tl-dr p { margin: 0; font-size: .95rem; font-weight: 550; color: var(--text); }

/* ---------- equation explain buttons ---------- */
.eq { position: relative; }
.eq-explain {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(91, 141, 239, .4);
  background: rgba(141, 181, 244, .12);
  color: var(--blue-deep);
  font: 650 .68rem/1.4 var(--font);
  cursor: pointer;
  vertical-align: middle;
  transition: background .16s var(--ease), transform .16s var(--ease), box-shadow .16s var(--ease);
}
.eq-explain:hover { background: rgba(141, 181, 244, .26); transform: translateY(-1px); box-shadow: 0 4px 10px -4px rgba(91, 141, 239, .5); }
.eq-explain svg { width: 13px; height: 13px; }

/* ==========================================================================
   Gamification — XP, streaks, achievements
   ========================================================================== */
.stat-hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 15px 16px 13px;
  position: relative;
  overflow: hidden;
}
.stat-tile::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), rgba(255, 107, 80, 0));
  opacity: .8;
}
.stat-tile .n { font-size: 1.65rem; font-weight: 800; letter-spacing: -.02em; color: var(--text); line-height: 1.1; }
.stat-tile .l { font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); margin-top: 3px; }
.stat-tile.tile-gold::before { background: linear-gradient(90deg, #E8A93D, rgba(255, 209, 102, 0)); }
.stat-tile.tile-mint::before { background: linear-gradient(90deg, #2FA98C, rgba(157, 217, 199, 0)); }
.stat-tile.tile-blue::before { background: linear-gradient(90deg, #5B8DEF, rgba(141, 181, 244, 0)); }

.level-bar {
  height: 10px;
  border-radius: 99px;
  background: rgba(23, 39, 71, .08);
  overflow: hidden;
  margin: 8px 0 4px;
}
.level-bar i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--nerdlyy-coral), #FFB03A);
  box-shadow: 0 0 10px rgba(255, 107, 80, .45);
  transition: width .6s var(--ease);
}

.heat-strip { display: flex; gap: 3px; flex-wrap: wrap; }
.heat-strip .hd {
  width: 13px; height: 13px;
  border-radius: 3.5px;
  background: rgba(23, 39, 71, .07);
}
.heat-strip .hd[data-l="1"] { background: #BFE6DA; }
.heat-strip .hd[data-l="2"] { background: #7BCDB6; }
.heat-strip .hd[data-l="3"] { background: #2FA98C; }
.heat-strip .hd[data-l="4"] { background: #14735A; }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; }
.ach {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 14px;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s var(--ease);
}
.ach:hover { transform: translateY(-2px); box-shadow: 0 10px 26px -14px rgba(23, 39, 71, .28); }
.ach.is-unlocked { border-color: rgba(232, 169, 61, .45); background: linear-gradient(160deg, #FFFDF6, #FFF7E4); }
.ach-ic {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: rgba(23, 39, 71, .06);
  color: var(--text-3);
}
.ach.is-unlocked .ach-ic {
  background: linear-gradient(135deg, #FFD166, #FFB03A);
  color: #6B4A00;
  box-shadow: 0 4px 12px -4px rgba(232, 169, 61, .65);
}
.ach-ic svg { width: 22px; height: 22px; }
.ach-body strong { display: block; font-size: .87rem; }
.ach-body small { color: var(--text-2); font-size: .74rem; line-height: 1.45; display: block; margin-top: 2px; }
.ach-body .ach-when { color: var(--ok); font-size: .68rem; font-weight: 650; }
.ach.is-locked { opacity: .72; }

/* ==========================================================================
   Practice — Exam Mode
   ========================================================================== */
.exam-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.exam-timer {
  font: 700 1.05rem/1 var(--mono);
  padding: 9px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  letter-spacing: .04em;
  min-width: 96px;
  text-align: center;
}
.exam-timer.warn { background: #C77C00; animation: pulse-soft 1s infinite; }
.exam-timer.over { background: var(--err); }
@keyframes pulse-soft { 50% { opacity: .72; } }
.exam-progress {
  height: 7px;
  border-radius: 99px;
  background: rgba(23, 39, 71, .08);
  overflow: hidden;
  margin: 4px 0 16px;
}
.exam-progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #FF9A80); transition: width .3s var(--ease); }
.exam-q { font-size: 1.06rem; font-weight: 650; margin: 4px 0 14px; }
.exam-opt {
  display: flex;
  width: 100%;
  text-align: left;
  align-items: flex-start;
  gap: 11px;
  background: var(--panel);
  border: 1.5px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 13px 15px;
  margin: 0 0 9px;
  font: 500 .92rem/1.5 var(--font);
  color: var(--text);
  cursor: pointer;
  transition: border-color .16s var(--ease), background .16s var(--ease), transform .16s var(--ease);
}
.exam-opt:hover { border-color: rgba(91, 141, 239, .55); transform: translateY(-1px); }
.exam-opt .key {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(23, 39, 71, .06);
  font: 700 .74rem/1 var(--font);
  color: var(--text-2);
}
.exam-opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.exam-opt.correct .key { background: var(--ok); color: #fff; }
.exam-opt.wrong { border-color: rgba(214, 58, 58, .55); background: var(--err-soft); }
.exam-opt.wrong .key { background: var(--err); color: #fff; }
.exam-opt:disabled { cursor: default; }
.exam-explain {
  border-radius: var(--r-md);
  padding: 12px 15px;
  font-size: .88rem;
  line-height: 1.55;
  border: 1px solid rgba(30, 158, 123, .35);
  background: var(--ok-soft);
  margin: 4px 0 12px;
}
.exam-explain.bad { border-color: rgba(214, 58, 58, .4); background: var(--err-soft); }
.exam-result-chapter { display: flex; align-items: center; gap: 10px; margin: 7px 0; }
.exam-result-chapter .bar { flex: 1; height: 8px; border-radius: 99px; background: rgba(23, 39, 71, .08); overflow: hidden; }
.exam-result-chapter .bar i { display: block; height: 100%; border-radius: 99px; }
.exam-result-chapter .lbl { flex: none; width: 190px; font-size: .78rem; font-weight: 600; color: var(--text-2); }
.exam-result-chapter .pct { flex: none; width: 44px; text-align: right; font: 700 .8rem/1 var(--font); }

/* ==========================================================================
   Flashcards — spaced repetition
   ========================================================================== */
.fc-stage { perspective: 1400px; max-width: 620px; margin: 0 auto; }
.fc-card {
  position: relative;
  min-height: 300px;
  border-radius: 20px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .5s var(--ease);
  outline: none;
}
.fc-card.is-flipped { transform: rotateY(180deg); }
.fc-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 20px;
  border: 1px solid var(--line-soft);
  background: var(--panel);
  box-shadow: 0 3px 6px rgba(23, 39, 71, .05), 0 22px 44px -20px rgba(23, 39, 71, .25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
}
.fc-face-back { transform: rotateY(180deg); background: linear-gradient(165deg, #FFFFFF, #F6F9FF); border-color: rgba(91, 141, 239, .35); }
.fc-kicker { font-size: .62rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-deep); }
.fc-face-front .fc-main { font-size: 1.28rem; font-weight: 700; line-height: 1.4; letter-spacing: -.01em; }
.fc-face-front .fc-math { font-size: 1.55rem; font-family: var(--mono); font-weight: 650; }
.fc-face-back .fc-main { font-size: 1rem; line-height: 1.65; color: var(--text-2); }
.fc-hint { position: absolute; bottom: 14px; left: 0; right: 0; font-size: .68rem; color: var(--text-3); }
.fc-actions { display: flex; gap: 9px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.fc-btn-again { border-color: rgba(214, 58, 58, .5); color: var(--err); }
.fc-btn-good { border-color: rgba(30, 158, 123, .5); color: var(--ok); }
.fc-btn-easy { border-color: rgba(91, 141, 239, .5); color: var(--blue-deep); }
.fc-count { text-align: center; font-size: .76rem; color: var(--text-3); margin-top: 10px; }

/* ==========================================================================
   Formula sheet
   ========================================================================== */
.fsheet-card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 16px 18px;
  margin-bottom: 14px;
  break-inside: avoid;
}
.fsheet-card h3 { display: flex; align-items: center; gap: 9px; font-size: .98rem; margin-bottom: 10px; }
.fsheet-card h3 img { width: 26px; height: 26px; }
.fsheet-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.fsheet-table td { padding: 7px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.fsheet-table tr:last-child td { border-bottom: 0; }
.fsheet-table .f-what { width: 42%; color: var(--text-2); font-weight: 550; }
.fsheet-table .f-eq { font-family: var(--mono); color: var(--text); }
@media print {
  .site-header, .site-footer, .subnav, .announce, .btn, .no-print { display: none !important; }
  body { background: #fff; }
  .fsheet-card { border: 1px solid #bbb; page-break-inside: avoid; }
  .container { max-width: 100%; }
}

/* ==========================================================================
   Social links (footer + about)
   ========================================================================== */
.social-row { display: flex; gap: 9px; align-items: center; margin-top: 10px; }
.social-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 11px;
  background: rgba(250, 248, 243, .09);
  border: 1px solid rgba(250, 248, 243, .16);
  color: #E8ECF5;
  transition: background .18s var(--ease), transform .18s var(--ease), color .18s var(--ease);
}
.social-btn:hover { background: rgba(255, 107, 80, .9); border-color: rgba(255, 107, 80, .9); color: #fff; transform: translateY(-2px); }
.social-btn svg { width: 17px; height: 17px; }
.site-footer .social-row { margin-top: 12px; }
.about-social { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.about-social .social-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 18px 13px 14px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.about-social .social-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px -14px rgba(23, 39, 71, .3); border-color: rgba(255, 107, 80, .4); text-decoration: none; }
.about-social .social-card svg { width: 21px; height: 21px; }
.about-social .social-card small { display: block; font-weight: 500; color: var(--text-3); font-size: .72rem; }

/* ---------- footer polish ---------- */
.site-footer {
  background:
    radial-gradient(700px 240px at 12% 0%, rgba(255, 107, 80, .12), transparent 60%),
    radial-gradient(900px 260px at 88% 10%, rgba(141, 181, 244, .1), transparent 55%),
    var(--nerdlyy-ink);
  color: #D7DEEC;
}
.site-footer h4 { color: #fff; font-size: .92rem; letter-spacing: .01em; }
.site-footer a { color: #B9C4DA; transition: color .16s var(--ease); }
.site-footer a:hover { color: #FFB4A3; text-decoration: none; }
.site-footer .footer-note { color: #8C99B4; font-size: .74rem; border-top: 1px solid rgba(250, 248, 243, .1); padding-top: 14px; margin-top: 22px; }

/* ---------- misc polish ---------- */
.toast {
  box-shadow: 0 8px 30px -8px rgba(23, 39, 71, .35);
  border-radius: 12px;
  animation: toast-in .3s var(--spring);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
input:focus, select:focus, textarea:focus { border-color: rgba(91, 141, 239, .55); box-shadow: 0 0 0 3px rgba(91, 141, 239, .12); }
@media (prefers-reduced-motion: reduce) {
  .card:hover, .btn:hover { transform: none; }
}

/* AI cross-page continuation notice */
.ai-page-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 4px 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(255, 209, 102, .2), rgba(255, 107, 80, .08));
  border: 1px solid rgba(232, 169, 61, .4);
  color: #8A5B00;
  font: 650 .72rem/1.4 var(--font);
  animation: announce-in .3s var(--ease);
}
.ai-page-note svg { width: 14px; height: 14px; flex: none; }

/* text input (same family as num-input/select-input) */
.text-input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: .9rem;
}
.text-input:focus { border-color: var(--nerdlyy-blue); outline: 3px solid rgba(141, 181, 244, .35); outline-offset: 0; }

/* 3D lab shared scene toolbar (photo + fullscreen) */
.lab3d-toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 7px;
  z-index: 5;
}
.lab3d-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(23, 39, 71, .88);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 9px;
  padding: 6px 11px;
  font: 650 .72rem/1 var(--font);
  cursor: pointer;
  transition: background .16s var(--ease), transform .16s var(--ease);
}
.lab3d-tool:hover { background: var(--nerdlyy-coral, #FF6B50); transform: translateY(-1px); }
.lab3d-tool svg { width: 14px; height: 14px; }
@media (max-width: 640px) { .lab3d-tool span { display: none; } .lab3d-tool { padding: 8px; } }

.sim-wrap { position: relative; }

/* ========================================================================
   Responsive layout + lab visibility corrections
   Keep the original paper / navy / coral brand; only tighten geometry and
   improve legibility on small screens.
   ======================================================================== */
.brand-copy {
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  line-height: 1.08;
}
.brand-name { display: block; line-height: 1.12; white-space: nowrap; }
.brand .brand-sub {
  margin-top: 2px;
  line-height: 1.1;
  letter-spacing: .09em;
  font-size: .62rem;
  white-space: nowrap;
}

/* Lab stages have a little more depth and a clearer frame, matching the
   contrast changes in the actual WebGL scene backgrounds. */
.sim-wrap {
  background: linear-gradient(180deg, #DDE6F3, #E7EDF7);
  border-color: #9DAFC9;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.65), 0 5px 18px rgba(23,39,71,.07);
}
.sim-loading { background: #E3EBF6; }
.sim-wrap canvas { filter: saturate(1.08) contrast(1.04); }
.sim-hint, .sim-badge { border-color: #AABBD2; color: #172747; }

@media (max-width: 840px) {
  .container { padding-left: 18px; padding-right: 18px; }
  .header-inner { gap: 12px; }
  .brand { min-width: 0; flex: 1 1 auto; gap: 9px; }
  .brand-copy { min-width: 0; }
  .nav-toggle { flex: none; white-space: nowrap; }
  .main-nav {
    left: 0; right: 0; width: 100%; max-width: 100vw;
    max-height: calc(100dvh - 64px); overflow-y: auto;
    overscroll-behavior: contain;
    padding-left: 18px; padding-right: 18px;
  }
  .main-nav > a:not(.streak-chip) { display: flex; align-items: center; width: 100%; min-height: 44px; }
  .main-nav .streak-chip, .main-nav .progress-chip, .main-nav .nav-auth {
    box-sizing: border-box; width: 100%; margin: 4px 0; justify-content: flex-start;
  }
  .hero-grid, .lab-layout, .two-col { grid-template-columns: minmax(0, 1fr); }
  .hero-grid > *, .two-col > *, .lab-layout > * { min-width: 0; }
  .page-head .desc { max-width: 100%; }
  .section-head { align-items: flex-start; }
  .panel-head > * { min-width: 0; max-width: 100%; }
  .kv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar { display: grid; grid-template-columns: minmax(0, 1fr); }
  .filter-bar .search { min-width: 0; width: 100%; }
  .filter-bar select { width: 100%; min-width: 0; }
  .module-head { align-items: flex-start; flex-wrap: wrap; }
  .footer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 18px; }
  .footer-grid > div:first-child { grid-column: 1 / -1; }
  .subnav {
    position: static; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    max-width: 100%; padding: 8px 0 12px; margin-bottom: 18px;
    -webkit-overflow-scrolling: touch; scrollbar-width: thin;
  }
  .subnav a { flex: 0 0 auto; white-space: nowrap; }
  .ask-box .ask-row { flex-wrap: wrap; }
  .ask-box .ask-row > * { min-width: 0; }
  .table-wrap { max-width: 100%; overflow-x: auto; }
  .fsheet-table { min-width: 520px; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .container { padding-left: 15px; padding-right: 15px; }
  .header-inner { min-height: 62px; gap: 8px; }
  .brand { gap: 8px; font-size: 1.03rem; }
  .brand img { width: 32px; height: 32px; }
  .brand-name { line-height: 1.12; }
  .brand .brand-sub { margin-top: 2px; font-size: .56rem; letter-spacing: .065em; }
  .nav-toggle { padding: 8px 10px; font-size: .86rem; border-radius: 10px; }
  .main-nav { padding: 10px 15px 16px; }
  .hero { padding: 34px 0 24px; }
  .hero h1 { max-width: none; font-size: clamp(1.8rem, 7vw, 2.35rem); line-height: 1.13; }
  .hero .lede { font-size: 1rem; line-height: 1.6; }
  .hero-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; margin-top: 20px; }
  .hero-actions .btn { width: 100%; min-width: 0; padding: 12px 14px; font-size: .91rem; }
  .section { padding: 26px 0; }
  .section + .section { padding-top: 4px; }
  .section-head { gap: 8px; margin-bottom: 14px; }
  .section-head h2 { padding-left: 10px; font-size: 1.25rem; }
  .grid-cards { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .card { padding: 16px; }
  .panel { border-radius: 15px; }
  .panel-head { align-items: flex-start; padding: 12px 13px; gap: 9px; }
  .panel-head h3 { font-size: .9rem; flex-wrap: wrap; }
  .panel-body { padding: 14px; }
  .page-head { padding: 6px 0 18px; margin-bottom: 18px; }
  .page-head h1 { font-size: clamp(1.55rem, 6vw, 2rem); line-height: 1.16; overflow-wrap: anywhere; }
  .page-head .desc { font-size: .94rem; line-height: 1.58; }
  .page-head .meta-row { gap: 8px 14px; }
  .page-head .badges { gap: 6px; }
  .badge { max-width: 100%; white-space: normal; }
  .subnav { gap: 6px; }
  .subnav a { font-size: .74rem; padding: 6px 11px; }
  .kv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kv { min-width: 0; overflow-wrap: anywhere; }
  .sim-wrap { min-height: 280px; border-radius: 12px; }
  .sim-wrap.tall { height: clamp(320px, 108vw, 420px); min-height: 320px; }
  .sim-wrap.medium { height: clamp(260px, 78vw, 340px); min-height: 260px; }
  .sim-badge { top: 8px; left: 8px; padding: 4px 8px; font-size: .68rem; }
  .sim-hint { left: 8px; bottom: 8px; max-width: calc(100% - 16px); font-size: .68rem; }
  .sim-wrap canvas { max-width: 100%; }
  .eq { white-space: normal; overflow-wrap: anywhere; font-size: .83rem; padding: 9px 10px; }
  .eq-explain { margin: 7px 0 0; }
  .btn-row { gap: 8px; }
  .btn-row > .btn { flex: 1 1 auto; }
  .ask-box { padding: 12px; }
  .ask-box .ask-row { flex-direction: column; align-items: stretch; }
  .ask-box .ask-row > * { width: 100%; }
  .stat-row, .stat-hero { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat, .stat-tile { min-width: 0; padding: 12px; }
  .stat .n, .stat-tile .n { font-size: 1.35rem; overflow-wrap: anywhere; }
  .ach-grid { grid-template-columns: minmax(0, 1fr); }
  .ach { padding: 12px; }
  .filter-bar { gap: 8px; }
  .filter-bar input[type="search"], .filter-bar select { min-height: 42px; }
  .table-wrap { border-radius: 11px; }
  .about-social { display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .about-social .social-card { min-width: 0; padding: 12px; }
  .footer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 21px 14px; }
  .site-footer { padding: 28px 0; }
  .footer-note { font-size: .72rem; line-height: 1.55; }
  .lab3d-toolbar { top: 8px; right: 8px; gap: 5px; }
  .lab3d-tool { min-width: 34px; min-height: 34px; justify-content: center; }
  .user-menu-panel { max-width: calc(100vw - 24px); }
  input, select, textarea, button { max-width: 100%; }
  pre { max-width: 100%; overflow-x: auto; }
}

@media (max-width: 370px) {
  .container { padding-left: 12px; padding-right: 12px; }
  .brand .brand-sub { font-size: .52rem; letter-spacing: .035em; }
  .header-inner { gap: 6px; }
  .nav-toggle { padding: 7px 8px; }
  .kv-grid, .stat-row, .stat-hero { grid-template-columns: minmax(0, 1fr); }
  .panel-head { padding-left: 11px; padding-right: 11px; }
  .panel-body { padding: 12px; }
  .sim-wrap.tall { height: 320px; }
}

/* ==========================================================================
   Subjects — chooser gate, switch control (header) & switch banner (footer)
   ========================================================================== */
.subject-switch {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px; border: 1.5px solid var(--line);
  background: var(--panel-2); border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
.subject-switch .ss-opt {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; padding: 6px 12px;
  border-radius: 999px; font: 700 .78rem/1.2 var(--font);
  color: var(--text-3); cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.subject-switch .ss-opt .ic { width: 14px; height: 14px; }
.subject-switch .ss-opt:hover { color: var(--text); background: rgba(23,39,71,.07); }
.subject-switch .ss-opt.ss-active {
  background: var(--nerdlyy-ink); color: #fff; cursor: default;
  box-shadow: 0 2px 6px rgba(23,39,71,.35);
}
.subject-switch .ss-opt.ss-active:hover { background: var(--nerdlyy-ink); color: #fff; }
.subject-switch .ss-arrow { display: inline-flex; align-items: center; color: var(--text-3); padding: 0 1px; }
.subject-switch .ss-arrow .ic { width: 13px; height: 13px; }
.subject-switch .ss-short { display: none; }
@media (max-width: 640px) {
  .subject-switch .ss-long { display: none; }
  .subject-switch .ss-short { display: inline; }
  .subject-switch .ss-opt { padding: 6px 9px; }
}

.subject-switch-bar {
  margin-top: 22px; padding: 13px 18px;
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--panel-2), #EDF3FB 55%, var(--accent-soft));
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}
.subject-switch-bar .ssb-copy { display: inline-flex; align-items: center; gap: 9px; font-size: .88rem; color: var(--text-2); }
.subject-switch-bar .ssb-copy .ic { width: 18px; height: 18px; color: var(--accent); flex: none; }
.subject-switch-bar .ssb-copy strong { color: var(--text); }
.subject-switch-bar .ssb-btn { display: inline-flex; align-items: center; gap: 7px; }
.subject-switch-bar .ssb-btn .ic { width: 15px; height: 15px; }

/* chooser gate */
.choose-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 22px; }
.choose-card {
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  background: var(--panel); border: 1.5px solid var(--line-soft); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); text-decoration: none; color: var(--text);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.choose-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); text-decoration: none; border-color: var(--accent); }
.choose-card.choose-last { border-color: var(--ok); }
.choose-art { position: relative; padding: 26px 26px 0; display: flex; justify-content: center; }
.choose-art .illus { position: relative; z-index: 1; }
.choose-art .blob { position: absolute; z-index: 0; width: 78%; top: 6%; left: 11%; opacity: .35; }
.choose-cs .choose-art .blob { opacity: .3; }
.choose-body { padding: 18px 24px 26px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.choose-head { display: flex; align-items: center; gap: 12px; }
.choose-head h2 { margin: 0; font-size: 1.5rem; }
.choose-ic {
  width: 46px; height: 46px; border-radius: 13px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); border: 1.5px solid rgba(255, 107, 80, .25);
}
.choose-ic img { width: 30px; height: 30px; }
.choose-ic.tint-blue { background: rgba(141, 181, 244, .16); border-color: rgba(141, 181, 244, .4); }
.choose-body > p { color: var(--text-2); margin: 2px 0 4px; }
.choose-facts { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 7px; }
.choose-facts li { position: relative; padding-left: 24px; font-size: .9rem; color: var(--text-2); }
.choose-facts li::before {
  content: ""; position: absolute; left: 2px; top: 7px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent-soft); border: 3px solid var(--accent);
}
.choose-cs .choose-facts li::before { background: rgba(141, 181, 244, .25); border-color: var(--blue-deep); }
.choose-facts strong { color: var(--text); }
.choose-go { margin-top: auto; align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; }
.choose-go .ic { width: 17px; height: 17px; }
@media (max-width: 760px) {
  .choose-art { padding-top: 18px; }
  .choose-art .illus { width: 210px; height: 210px; }
}

/* ==========================================================================
   Code editor + output console (Computer Science pages)
   ========================================================================== */
.cse-wrap {
  display: flex; align-items: stretch;
  background: #141B2E;                       /* ink-deep editor shell */
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  overflow: hidden; min-height: 220px;
  --ed-bg: #141B2E; --ed-line: #1D2742;
  --ed-fg: #E7EDFB; --ed-com: #7C8BAD; --ed-str: #FFD166;
  --ed-kw: #FF8A73; --ed-num: #9DD9C7; --ed-bi: #8DB5F4; --ed-fn: #C6B3F5; --ed-deco: #F2B880;
}
.cse-gutter {
  flex: none; min-width: 3.1em; padding: 12px 8px 12px 0; text-align: right;
  font-family: var(--mono); font-size: var(--cse-fs, .86rem); line-height: 1.55;
  color: #6478A4; background: var(--ed-line); white-space: pre;
  border-right: 1px solid rgba(255,255,255,.06);
  overflow: hidden; user-select: none;
}
.cse-stack { position: relative; flex: 1; min-width: 0; }
.cse-active {
  position: absolute; left: 0; right: 0; top: 0;
  height: 1.4em; transform: translateY(0);
  background: rgba(141, 181, 244, .08);
  border-left: 2px solid rgba(141, 181, 244, .45);
  pointer-events: none; z-index: 0; opacity: 0; transition: opacity .12s;
}
.cse-pre, .cse-text {
  margin: 0; padding: 12px 14px;
  font-family: var(--mono); font-size: var(--cse-fs, .86rem); line-height: 1.55;
  tab-size: 4; white-space: pre; word-wrap: normal; overflow-wrap: normal;
}
.cse-pre {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  color: var(--ed-fg); z-index: 1;
}
/* the global inline-code look must not leak into the editor overlay */
.cse-pre code {
  background: transparent; border: 0; padding: 0; border-radius: 0;
  font-size: inherit; white-space: inherit;
}
.cse-text {
  position: relative; display: block; width: 100%; height: 100%; min-height: 220px;
  background: transparent; border: 0; outline: none; resize: vertical;
  color: transparent; caret-color: #FFD166; overflow: auto; z-index: 2;
}
.cse-text::selection { background: rgba(141, 181, 244, .30); }
.tok-kw { color: var(--ed-kw); font-weight: 600; }
.tok-str { color: var(--ed-str); }
.tok-num { color: var(--ed-num); }
.tok-bi { color: var(--ed-bi); }
.tok-fn { color: var(--ed-fn); }
.tok-com { color: var(--ed-com); font-style: italic; }
.tok-deco { color: var(--ed-deco); }
/* rainbow brackets — nesting depth rotates through three readable hues */
.tok-br { font-weight: 600; }
.tok-br0 { color: #FFD76D; }
.tok-br1 { color: #6FB7FF; }
.tok-br2 { color: #FF9AA8; }
.cse-wrap {
  --cse-guide: color-mix(in srgb, var(--ed-fg) 9%, transparent);
}
/* indent guides: one faint dashed stop at every 4-character indent level.
   Hidden under soft word wrap, where column alignment no longer holds. */
.cse-pre {
  background-image: repeating-linear-gradient(90deg,
    transparent 0, transparent calc(4ch - 1px),
    var(--cse-guide) calc(4ch - 1px), var(--cse-guide) 4ch);
  background-clip: content-box;
}
.cse-wrap.word-wrap .cse-pre { background-image: none; }

/* ---------- suggestion dropdown (base — every page hosting N.editor) ---- */
.cse-suggest {
  position: absolute; z-index: 30; min-width: 220px; max-width: min(340px, 92%);
  max-height: 238px; overflow: auto; padding: 4px;
  background: #20242E; border: 1px solid rgba(255,255,255,.15); border-radius: 9px;
  box-shadow: 0 14px 34px rgba(0,0,0,.45); color: #E7EDFB;
  font: 12.5px/1.4 var(--mono);
}
.cse-suggest-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 6px 8px; border: 0; border-radius: 6px; background: transparent;
  color: inherit; text-align: left; cursor: pointer; font: inherit;
}
.cse-suggest-item.active { background: rgba(141,181,244,.20); }
.cse-suggest-kind {
  display: inline-grid; place-items: center; width: 17px; height: 17px; flex: none;
  border-radius: 5px; font: 700 10px/1 var(--font);
}
.cse-kind-keyword { background: rgba(255,138,115,.14); color: #FF8A73; border: 1px solid rgba(255,138,115,.35); }
.cse-kind-builtin { background: rgba(141,181,244,.14); color: #8DB5F4; border: 1px solid rgba(141,181,244,.35); }
.cse-kind-module  { background: rgba(157,217,199,.14); color: #9DD9C7; border: 1px solid rgba(157,217,199,.35); }
.cse-kind-word    { background: rgba(124,139,173,.16); color: #7C8BAD; border: 1px solid rgba(124,139,173,.4); }
.cse-suggest-label { color: #B9C4DE; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cse-suggest-label b { color: #FFFFFF; font-weight: 700; }
/* v6 — per-item detail column + sticky doc footer under the list */
.cse-suggest-detail {
  margin-left: auto; padding-left: 10px; flex: none; max-width: 48%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: #7C8BAD; font: 10.5px/1.3 var(--font);
}
.cse-suggest-doc {
  position: sticky; bottom: -4px; display: flex; justify-content: space-between;
  align-items: center; gap: 10px; margin: 2px -4px -4px; padding: 5px 8px;
  border-top: 1px solid rgba(255,255,255,.10); background: #262B37;
  color: #9AA7C4; font: 10.5px/1.35 var(--font); border-radius: 0 0 8px 8px;
}
.cse-suggest-doc-sig { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.cse-suggest-doc-keys { flex: none; color: #66738F; }

/* ---------- v6 live decorations: matching bracket + active block guides ---
   Positioned by the editor with real glyph metrics; hidden under soft word
   wrap (column math does not hold there) and when the editor is unfocused. */
.cse-guides { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.cse-bracket-hl {
  position: absolute; display: none; pointer-events: none; box-sizing: border-box;
  border: 1px solid rgba(141,181,244,.85); border-radius: 2.5px;
  background: rgba(141,181,244,.24);
  box-shadow: 0 0 0 1px rgba(141,181,244,.18);
}
.cse-guide-line {
  position: absolute; width: 2px; border-radius: 1px; pointer-events: none;
  background: color-mix(in srgb, var(--ed-fg, #e7edfb) 13%, transparent);
}
.cse-guide-line.cse-guide-on { background: rgba(141,181,244,.55); }

/* ---------- find & replace bar (base) ---------- */
.cse-findbar {
  position: absolute; top: 6px; right: 10px; z-index: 40;
  display: flex; flex-direction: column; gap: 5px; padding: 6px;
  background: #20242E; border: 1px solid rgba(255,255,255,.16); border-radius: 9px;
  box-shadow: 0 12px 30px rgba(0,0,0,.42);
}
.cse-find-row { display: flex; align-items: center; gap: 4px; }
.cse-find-toggle {
  border: 0; background: transparent; color: #8FA6CF; cursor: pointer;
  width: 20px; padding: 2px 0; border-radius: 4px; transition: transform .15s ease;
}
.cse-find-toggle.open { transform: rotate(180deg); }
.cse-find-input {
  width: 190px; background: #141821; border: 1px solid rgba(255,255,255,.16); border-radius: 6px;
  color: #E7EDFB; font: 12px var(--mono); padding: 4px 8px; outline: none;
}
.cse-find-input:focus { border-color: #8DB5F4; }
.cse-find-count { font: 11px var(--mono); color: #8FA6CF; min-width: 58px; text-align: center; white-space: nowrap; }
.cse-find-btn {
  border: 1px solid transparent; background: transparent; color: #B9C4DE;
  border-radius: 5px; cursor: pointer; font: 12px var(--mono); padding: 3px 7px; white-space: nowrap;
}
.cse-find-btn:hover { background: rgba(141,181,244,.15); color: #fff; }
.cse-find-case.on { border-color: rgba(141,181,244,.55); color: #8DB5F4; background: rgba(141,181,244,.12); }
.cse-find-wide { border: 1px solid rgba(255,255,255,.16); }
.cse-find-replace { display: flex; gap: 4px; align-items: center; }
.cse-find-replace .cse-find-input { width: 148px; }

/* ---------- interactive terminal input row (VS Code style) ---------- */
.term-input-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; margin-top: 4px;
  border-top: 1px dashed rgba(255,255,255,.16);
  background: rgba(141,181,244,.06); border-radius: 6px;
}
.term-input-glyph { color: #8DB5F4; flex: none; }
/* The program's own input() prompt, INLINE before the caret —
   `input("Enter age: ")` renders as:  Enter age: ▍  on one line. */
.term-input-prompt {
  flex: none; color: #FFD166; font-family: var(--mono); font-size: inherit;
  white-space: pre-wrap; text-shadow: 0 1px 0 rgba(0,0,0,.4);
}
.term-input-row.has-prompt .term-input-glyph { display: none; }
.term-input-field {
  flex: 1 1 auto; min-width: 40px; background: transparent; border: 0; outline: none;
  color: #EAF1FF; font-family: var(--mono); font-size: inherit; caret-color: #FFD166;
}
.term-input-hint { flex: none; font: 10.5px var(--mono); color: #6478A4; white-space: nowrap; }
.code-console .out-ok { color: #3DDC97; font-weight: 600; }
.code-console .out-input { color: #B9C4DE; font-style: italic; }
/* Transcript of pre-fed prompt+value / bare prompt echoes — reads like real
   terminal output, so NO italic; visually distinct from program stdout. */
.code-console .out-stdio { color: #FFD166; }

/* ---------- TERMINAL (output console) ------------------------------------
   Deliberately darker + higher contrast than the rest of the theme: a real
   terminal look. Scoped strictly to .term / .code-console — the Nerdlyy
   paper theme is untouched. */
.term {
  background: #0B1220;
  border: 1.5px solid #26375C;
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04), 0 2px 10px rgba(9,14,28,.25);
}
.term-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 13px; background: #121C36; border-bottom: 1px solid #223050;
}
.term-dots { display: inline-flex; gap: 6px; flex: none; }
.term-dots i { width: 10px; height: 10px; border-radius: 50%; display: block; }
.term-dots i:nth-child(1) { background: #FF6159; }
.term-dots i:nth-child(2) { background: #FFBD2E; }
.term-dots i:nth-child(3) { background: #2ACB42; }
.term-title {
  font: 700 .66rem/1.3 var(--mono); letter-spacing: .14em; text-transform: uppercase;
  color: #8CA2CC; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.term-status { margin-left: auto; font: .72rem/1.4 var(--mono); color: #9FB2D8; white-space: nowrap; }
.code-console {
  background: #0B1220; color: #EAF1FF;
  border: 1.5px solid #26375C; border-radius: var(--r-md);
  font-family: var(--mono); font-size: .86rem; line-height: 1.62;
  padding: 13px 16px; min-height: 150px; max-height: 480px; overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere;
  text-shadow: 0 1px 0 rgba(0,0,0,.4);
}
.term .code-console { border: 0; border-radius: 0; max-height: none; }
.code-console .out-stderr { color: #FFB3A1; }
.code-console .out-error  { color: #FF9A85; font-weight: 600; white-space: pre-wrap; }
.code-console .out-meta   { color: #8FA6CF; font-style: italic; }
.code-console .out-ok     { color: #63E6BE; }
.code-console .out-warn   { color: #FFD166; }
.code-console .out-stdin  { color: #93C5FD; }
.code-console:empty::before { content: attr(data-empty); color: #6D82AD; font-style: italic; }
.code-console::-webkit-scrollbar { width: 11px; height: 11px; }
.code-console::-webkit-scrollbar-thumb { background: #2C3D66; border-radius: 8px; border: 3px solid #0B1220; }
.code-console::-webkit-scrollbar-thumb:hover { background: #3A4E80; }
.code-console::-webkit-scrollbar-track { background: transparent; }
@supports (scrollbar-color: red blue) {
  .code-console { scrollbar-color: #2C3D66 #0B1220; scrollbar-width: thin; }
}

/* challenge test list */
.test-list { display: grid; gap: 9px; }
.test-row { border: 1.5px solid var(--line-soft); border-radius: var(--r-sm); background: var(--panel-2); overflow: hidden; }
.test-row.pass { border-color: rgba(30, 158, 123, .5); background: var(--ok-soft); }
.test-row.fail { border-color: rgba(214, 58, 58, .45); background: var(--err-soft); }
.test-head { display: flex; align-items: center; gap: 9px; padding: 9px 12px; font-size: .88rem; font-weight: 600; }
.test-head .t-ic { flex: none; width: 18px; height: 18px; display: inline-flex; }
.test-head .t-ic.pass { color: var(--ok); }
.test-head .t-ic.fail { color: var(--err); }
.test-body { padding: 0 12px 11px; font-size: .8rem; display: grid; gap: 7px; }
.test-io { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.test-io > div { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 8px; padding: 7px 9px; min-width: 0; }
.test-io .lbl { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); font-weight: 700; margin-bottom: 3px; }
.test-io pre { margin: 0; font-family: var(--mono); font-size: .78rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 150px; overflow: auto; }
@media (max-width: 640px) { .test-io { grid-template-columns: 1fr; } }

.diff-badge { display: inline-flex; align-items: center; gap: 6px; font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; border: 1.5px solid; }
.diff-starter { color: #0F766E; border-color: rgba(45,212,191,.55); background: rgba(45,212,191,.14); }
.diff-easy { color: #157A5F; border-color: rgba(30,158,123,.5); background: var(--ok-soft); }
.diff-medium { color: #5B8DEF; border-color: rgba(91,141,239,.5); background: rgba(141,181,244,.16); }
.diff-hard { color: #A87B00; border-color: rgba(168,123,0,.45); background: var(--warn-soft); }
.diff-extreme { color: #C04B23; border-color: rgba(228,87,63,.5); background: var(--accent-soft); }
.diff-brutal { color: #B03A3A; border-color: rgba(214,58,58,.55); background: var(--err-soft); }

/* ==========================================================================
   Computer Science pages — playground codebase, exam text, misc
   ========================================================================== */
.exam-q { white-space: pre-wrap; }

.snippet-list { display: grid; gap: 10px; }
.snippet-row {
  display: flex; gap: 12px; align-items: center;
  border: 1.5px solid var(--line-soft); border-radius: var(--r-sm);
  background: var(--panel-2); padding: 10px 14px;
}
.snippet-row:hover { border-color: var(--accent); }

@media (max-width: 640px) {
  .pg-io-grid { grid-template-columns: 1fr !important; }
  .pg-status { text-align: left !important; }
}

/* ==========================================================================
   Python IDE layout (cs-playground) — explorer / tabbar / toolbar / editor /
   resizable terminal panel / status bar. Professional VS-Code-like shell,
   still wearing Nerdlyy paper + ink colors.
   ========================================================================== */
.ide {
  display: grid; grid-template-columns: 232px minmax(0, 1fr);
  background: var(--panel); border: 1.5px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-height: 700px;
}
.ide-side {
  background: linear-gradient(180deg, #F2F5FA, #ECF1F8);
  border-right: 1.5px solid var(--line-soft);
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.ide-side-head {
  padding: 13px 14px 8px; font: 800 .66rem/1 var(--font);
  letter-spacing: .16em; text-transform: uppercase; color: var(--text-3);
  display: flex; align-items: center; justify-content: space-between;
}
.ide-files { flex: 1; overflow: auto; padding: 2px 8px 12px; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.ide-file {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 0; background: transparent; border-radius: 8px; padding: 7px 9px;
  font: 500 .84rem/1.3 var(--mono); color: var(--text-2); cursor: pointer;
  transition: background .12s, color .12s;
}
.ide-file:hover { background: rgba(255,255,255,.85); color: var(--text); }
.ide-file.active { background: #fff; color: var(--text); font-weight: 700; box-shadow: inset 0 0 0 1.5px var(--line), var(--shadow-sm); }
.ide-file .f-ic { color: var(--blue-deep); flex: none; width: 14px; height: 14px; display: inline-flex; }
.ide-file .f-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ide-file .f-del {
  opacity: 0; border: 0; background: transparent; color: var(--text-3);
  cursor: pointer; font-size: .82rem; line-height: 1; padding: 3px 5px; border-radius: 6px; flex: none;
}
.ide-file:hover .f-del, .ide-file.active .f-del { opacity: .75; }
.ide-file .f-del:hover { color: var(--err); opacity: 1; background: var(--err-soft); }
.ide-side-foot { padding: 10px 10px; border-top: 1.5px solid var(--line-soft); display: flex; gap: 6px; flex-wrap: wrap; }
.ide-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ide-tabbar {
  display: flex; align-items: flex-end; gap: 2px; padding: 7px 10px 0;
  background: #EDF2F9; border-bottom: 1.5px solid var(--line-soft); flex-wrap: wrap;
}
.ide-tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px;
  font: 600 .84rem/1 var(--mono); color: var(--text-2);
  border: 1.5px solid transparent; border-bottom: 0; border-radius: 10px 10px 0 0;
  position: relative; top: 1.5px;
}
.ide-tab.active { background: var(--panel); border-color: var(--line-soft); color: var(--text); }
.ide-tab .t-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }
.ide-toolbar {
  display: flex; align-items: center; gap: 7px; padding: 9px 12px;
  background: var(--panel); border-bottom: 1.5px solid var(--line-soft); flex-wrap: wrap;
}
.ide-toolbar .spacer { flex: 1; }
.ide-editor { flex: 1; min-height: 380px; display: flex; min-width: 0; }
.ide-editor .cse-wrap { flex: 1; border: 0; border-radius: 0; min-height: 0; }
.ide-editor .cse-text { resize: none; height: 100%; }
.ide-split {
  height: 7px; flex: none; position: relative; cursor: row-resize;
  background: #EDF2F9; border-top: 1.5px solid var(--line-soft); border-bottom: 1.5px solid var(--line-soft);
  touch-action: none;
}
.ide-split::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%); width: 48px; height: 3px; border-radius: 3px;
  background: #B9C6DC; transition: background .12s;
}
.ide-split:hover::after, .ide-split.dragging::after { background: var(--accent); }
.ide-term {
  height: var(--term-h, 300px); min-height: 130px; flex: none;
  display: flex; flex-direction: column; background: #0B1220;
}
.ide-term-tabs {
  display: flex; gap: 2px; align-items: center; padding: 6px 10px 0;
  background: #121C36; border-bottom: 1px solid #223050; flex: none;
}
.ide-ttab {
  font: 700 .68rem/1 var(--mono); letter-spacing: .12em; text-transform: uppercase;
  color: #8CA2CC; background: transparent; border: 0; cursor: pointer;
  padding: 9px 13px; border-radius: 8px 8px 0 0; border-bottom: 2px solid transparent;
}
.ide-ttab:hover { color: #C6D4F2; }
.ide-ttab.active { color: #EAF1FF; border-bottom-color: var(--accent); }
.ide-term .code-console { flex: 1; min-height: 0; max-height: none; }
.ide-stdin {
  display: none; flex: 1; min-height: 0; resize: none; border: 0; outline: none;
  background: #0B1220; color: #93C5FD; padding: 13px 16px;
  font: .86rem/1.62 var(--mono); white-space: pre;
}
.ide-stdin::placeholder { color: #6D82AD; }
.ide-term[data-tab="input"] .code-console { display: none; }
.ide-term[data-tab="input"] .ide-stdin { display: block; }
.ide-status {
  display: flex; align-items: center; gap: 14px; padding: 7px 14px; flex: none;
  background: var(--nerdlyy-ink); color: #B9C7E6;
  font: 500 .74rem/1.3 var(--mono);
}
.ide-status .badge { font-size: .68rem; }
.ide-status .st-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.ide-status .st-sep { opacity: .35; }
.ide-status select {
  background: #22335C; color: #EAF1FF; border: 1px solid #33477A; border-radius: 6px;
  font: 600 .72rem/1.3 var(--mono); padding: 2px 4px; cursor: pointer;
}
.ide-status .st-strong { color: #EAF1FF; font-weight: 700; }
.ide-status .st-ok { color: #63E6BE; }
.ide-status .st-warn { color: #FFD166; }
.ide-status .spacer { flex: 1; }
@media (max-width: 860px) {
  .ide { grid-template-columns: 1fr; min-height: 0; }
  .ide-side { border-right: 0; border-bottom: 1.5px solid var(--line-soft); }
  .ide-files { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; padding: 4px 10px 10px; align-items: flex-start; }
  .ide-file { width: auto; flex: none; height: auto; white-space: nowrap; }
  .ide-file .f-del { display: none; }
  .ide-side-foot { border-top: 0; padding-top: 0; }
  .ide-editor { min-height: 300px; }
  .ide-term { height: var(--term-h, 240px); }
  .ide-status { flex-wrap: wrap; gap: 8px 12px; }
}

/* packages modal (playground) */
.pkg-overlay {
  position: fixed; inset: 0; z-index: 1400; display: flex; align-items: center; justify-content: center;
  background: rgba(13, 21, 41, .55); backdrop-filter: blur(3px); padding: 18px;
}
.pkg-panel {
  width: min(560px, 100%); background: var(--panel); border-radius: var(--r-lg);
  border: 1.5px solid var(--line); box-shadow: 0 24px 60px rgba(9, 14, 28, .4);
  overflow: hidden; max-height: min(640px, 92vh); display: flex; flex-direction: column;
}
.pkg-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1.5px solid var(--line-soft); }
.pkg-head h3 { margin: 0; font-size: 1.02rem; }
.pkg-body { padding: 16px 18px; overflow: auto; display: grid; gap: 12px; }
.pkg-row { display: flex; gap: 8px; }
.pkg-row input { flex: 1; }
.pkg-note { font-size: .8rem; color: var(--text-2); margin: 0; }
.pkg-log {
  background: #0B1220; color: #B9C7E6; border-radius: var(--r-sm);
  font: .78rem/1.55 var(--mono); padding: 10px 12px; max-height: 180px; overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere; display: none;
}
.pkg-log.show { display: block; }

/* fullscreen support (editor.fullscreen helper): native :fullscreen + class fallback */
.ide:fullscreen, .ide.ny-fs {
  border-radius: 0; border: 0; min-height: 0; width: 100vw; height: 100vh;
}
.ide.ny-fs { position: fixed; inset: 0; z-index: 1300; }
.panel.ny-fs { position: fixed; inset: 0; z-index: 1300; border-radius: 0; margin: 0; overflow: auto; }
body.ny-fs-lock { overflow: hidden; }
.ide:fullscreen .ide-editor, .ide.ny-fs .ide-editor { min-height: 0; }
.ide:fullscreen .cse-text, .ide.ny-fs .cse-text { min-height: 0; }
.challenge-ide-wrap { display: grid; gap: 10px; }
.challenge-ide-wrap .cse-text { min-height: 320px; }
@media (min-width: 941px) {
  .two-col.two-col-ide { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
}
@media (max-width: 940px) {
  .two-col.two-col-ide { grid-template-columns: minmax(0, 1fr); }
}

/* Local enhancement safeguards (kit: nerdlyy-local-enhancements.css)
   Keep reveal-on-scroll content visible when printing, and keep MathML
   formulas readable inside formula-sheet table cells. */
@media print {
  .nyx-reveal.nyx-reveal-ready:not(.nyx-is-visible) { opacity: 1 !important; transform: none !important; }
}
.fsheet-table .nyx-math-rendered { padding: .35rem .5rem; margin: 0; }
.fsheet-table math { font-size: 1.05em; }

/* Header hardening (v3.5): between the mobile burger and ~1500px the full
   nav row (links + subject switch + streak + progress + auth) can exceed
   the viewport. Let it wrap onto a second header line instead of
   overflowing horizontally.
   v5.5 alignment fix: at those widths the brand sat flush against the top
   edge ("logo stuck to the top") — balanced padding + row gap now keep the
   logo and every wrapped row optically centred. */
@media (min-width: 841px) and (max-width: 1560px) {
  .header-inner { flex-wrap: wrap; padding-top: 13px; padding-bottom: 13px; row-gap: 10px; align-items: center; }
  .main-nav { flex-wrap: wrap; row-gap: 3px; justify-content: flex-end; align-items: center; }
}

/* ---------- solved challenge cards (Programming Labs listing) ------------- */
.card.card-solved { border-color: color-mix(in srgb, var(--ok) 52%, var(--line)); }
.card.card-solved .solved-tick {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--ok-soft); color: var(--ok);
  font-weight: 700; font-size: .8rem; vertical-align: middle;
  border: 1px solid rgba(30, 158, 123, .35);
}

/* ================= LEADERBOARD (v3.8) ================= */
.podium-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; max-width: 760px; margin: 0 auto; }
.podium-card { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r-lg, 16px); padding: 20px 16px 16px; text-align: center; position: relative; box-shadow: var(--shadow-sm); }
.podium-1 { border: 2px solid #E8B93B; background: linear-gradient(180deg, rgba(232,185,59,.10), var(--panel) 60%); }
.podium-2 { border-color: #AEB8C4; }
.podium-3 { border-color: #C98A5E; }
.podium-name { font-weight: 700; margin-top: 9px; }
.podium-score { font: 800 1.7rem/1.1 var(--font); color: var(--nerdlyy-coral, #FF6B50); margin: 4px 0 2px; }
.podium-rank { margin-top: 8px; font: 700 .95rem/1 var(--font); }
.lb-av { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; border: 2px solid var(--line-soft); display: inline-block; background: var(--panel-2, #f2f5fb); }
.lb-av-fallback { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--nerdlyy-navy, #172747), #2B4C8C); }
.lb-av-sm { width: 26px; height: 26px; font-size: .72rem; }
.lb-av-sm.lb-av-fallback { width: 26px; height: 26px; }
.lb-cell-name { display: inline-flex; align-items: center; gap: 8px; }
.lb-rank { font-weight: 700; white-space: nowrap; }
.lb-medal { font-size: 1.05rem; }
.lb-row-me { background: rgba(141, 181, 244, .10); }
.lb-row-me td { border-top: 1px solid rgba(141,181,244,.35); border-bottom: 1px solid rgba(141,181,244,.35); }
#lb-table th, #lb-table td { vertical-align: middle; }
/* v5 — ADMIN badge on staff rows (same palette: navy ink on soft coral) */
.lb-admin-badge {
  display: inline-block; vertical-align: middle; margin-left: 2px;
  font: 800 .58rem/1 var(--font); letter-spacing: .06em;
  color: #fff; background: linear-gradient(135deg, var(--nerdlyy-navy, #172747), #2B4C8C);
  border: 1px solid rgba(23, 39, 71, .25);
  border-radius: 999px; padding: 3px 7px 2px;
}
.podium-name .lb-admin-badge { margin-left: 4px; }
@media (max-width: 640px) {
  #lb-table th:nth-child(5), #lb-table td:nth-child(5),
  #lb-table th:nth-child(6), #lb-table td:nth-child(6) { display: none; }
}

/* ================= FIRST-VISIT SIGN-IN NUDGE (v3.8) ================= */
.auth-nudge-overlay {
  position: fixed; inset: 0; z-index: 1200;
  background: rgba(10, 18, 38, .55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: ai-msg-in .18s ease;
}
.auth-nudge {
  position: relative; width: 100%; max-width: 430px;
  background: var(--panel, #fff); color: var(--text);
  border-radius: 20px; box-shadow: 0 24px 70px rgba(9, 14, 28, .4);
  padding: 30px 26px 24px; text-align: center;
  border: 1px solid var(--line-soft);
}
.auth-nudge-close {
  position: absolute; top: 10px; right: 12px;
  border: 0; background: transparent; color: var(--text-2, #5C6B85);
  font: 400 22px/1 var(--font); cursor: pointer; padding: 6px 8px; border-radius: 8px;
}
.auth-nudge-close:hover { background: var(--panel-2, #f2f5fb); }
.auth-nudge-ava { width: 62px; height: 62px; margin: 0 auto 12px; border-radius: 50%; background: #fff; border: 2px solid var(--line-soft); padding: 6px; box-shadow: var(--shadow-sm); }
.auth-nudge-ava img { width: 100%; height: 100%; object-fit: contain; }
.auth-nudge h3 { margin: 0 0 6px; font-size: 1.25rem; }
.auth-nudge-sub { margin: 0 0 16px; color: var(--text-2, #5C6B85); font-size: .92rem; }
.auth-nudge-list { list-style: none; margin: 0 0 18px; padding: 0; text-align: left; display: grid; gap: 8px; }
.auth-nudge-list li { display: flex; gap: 9px; align-items: flex-start; font-size: .9rem; }
.auth-nudge-list .tick {
  flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%;
  background: rgba(61, 220, 151, .16); color: #1FA36B;
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 11px/18px var(--font);
}
.auth-nudge .btn-row { flex-direction: column; gap: 9px; }
.auth-nudge .btn-row .btn { width: 100%; justify-content: center; }
.auth-nudge-note { margin: 12px 0 0; font-size: .74rem; color: var(--text-2, #5C6B85); }

/* ================= AI challenge review (v3.8) ================= */
.ai-review-box {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 12px; padding: 11px 14px;
  border: 1px dashed rgba(141, 181, 244, .5); border-radius: 10px;
  background: rgba(141, 181, 244, .07);
}
.ai-review-box .ai-review-copy { flex: 1 1 240px; }
.ai-review-feedback { margin: 8px 0 0; flex: 1 1 100%; color: var(--text-2, #5C6B85); }
.ai-verdict {
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
  margin-top: 8px; padding: 7px 11px; border-radius: 8px; font-size: .82rem;
}
.ai-verdict-pass { background: rgba(61, 220, 151, .12); border: 1px solid rgba(61, 220, 151, .4); }
.ai-verdict-fail { background: rgba(255, 154, 133, .10); border: 1px solid rgba(255, 154, 133, .38); }
.ai-verdict-tag { font-weight: 700; white-space: nowrap; }
.ai-verdict-pass .ai-verdict-tag { color: #178A5F; }
.ai-verdict-fail .ai-verdict-tag { color: #C04B23; }
.ai-verdict-reason { color: var(--text-2, #5C6B85); }

/* ======================= Leaderboard tabs (v3.9) ========================= */
.lb-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 18px;
}
.lb-tab {
  border: 1px solid var(--line, #D8E0EC);
  background: var(--surface, #fff);
  color: var(--text-1, #1C2740);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, border-color .18s ease, transform .18s ease;
}
.lb-tab:hover { transform: translateY(-1px); border-color: var(--brand, #3D6DEB); }
.lb-tab:focus-visible { outline: 2px solid var(--brand, #3D6DEB); outline-offset: 2px; }
.lb-tab-active {
  background: linear-gradient(135deg, var(--brand, #3D6DEB), #6A8DFF);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px rgba(61, 109, 235, .28);
}
.lb-row-me td { background: rgba(61, 109, 235, .07); }
/* v6 SHOW EVERYONE — the whole board scrolls; the header stays pinned.
   The name search rides in the panel head on wide screens and wraps under
   the title on phones. */
.lb-table-wrap { max-height: 560px; overflow-y: auto; overscroll-behavior: contain; }
.lb-table-wrap thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface, #fff);
  box-shadow: 0 1px 0 var(--line-soft, #E3E9F4);
}
.lb-search {
  width: 180px; max-width: 46vw; padding: 7px 12px; font-size: 13px;
  border-radius: 999px;
}
@media (max-width: 640px) {
  .lb-search { width: 100%; max-width: none; }
  .lb-table-wrap { max-height: 70vh; }
}

/* ══════════════════ v5 — search / demo / PWA / feedback ══════════════════ */

/* ---------- header search button (v5: icon-only — see js/core/search.js) ---------- */
.nav-search {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface, #fff); color: var(--ink, #172747);
  border: 1px solid var(--line, rgba(23,39,71,.14)); border-radius: 10px;
  width: 32px; height: 32px; padding: 0; cursor: pointer; font: inherit; font-size: .82rem;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.nav-search:hover { border-color: var(--accent, #3d6deb); box-shadow: 0 2px 10px rgba(61,109,235,.18); transform: translateY(-1px); }
.nav-search svg { width: 15px; height: 15px; flex: none; }

/* ---------- home-page search pill ---------- */
.hero-search { margin-top: 24px; display: flex; justify-content: center; }
.hero-search-btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--surface, #fff); color: var(--text-2, #3D4C6E);
  border: 1px solid var(--line, rgba(23,39,71,.14)); border-radius: 999px;
  padding: 11px 20px; cursor: pointer; font: inherit; font-size: .95rem;
  box-shadow: 0 6px 22px rgba(10, 18, 35, .08);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
  max-width: 92vw;
}
.hero-search-btn:hover { border-color: var(--accent, #3d6deb); box-shadow: 0 10px 28px rgba(61,109,235,.2); transform: translateY(-1px); color: var(--text); }
.hero-search-btn svg { width: 16px; height: 16px; flex: none; color: var(--accent, #3d6deb); }
.hs-kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .68rem;
  border: 1px solid var(--line, rgba(23,39,71,.18)); border-radius: 6px;
  padding: 2px 7px; opacity: .75; white-space: nowrap; background: var(--panel-2, #F3F6FB);
}
@media (max-width: 560px) { .hs-kbd { display: none; } }

/* ---------- search overlay ---------- */
.search-overlay {
  position: fixed; inset: 0; z-index: 220;
  background: rgba(13, 22, 40, .55); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 9vh 16px 16px;
}
.search-panel {
  width: min(660px, 100%); max-height: 76vh;
  background: var(--paper, #fff); border-radius: 16px;
  box-shadow: 0 30px 80px rgba(10, 18, 35, .35);
  display: flex; flex-direction: column; overflow: hidden;
}
.search-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line, rgba(23,39,71,.12));
}
.search-glass { font-size: 1.25rem; opacity: .55; }
.search-head input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 1.02rem; color: var(--ink, #172747); min-width: 0;
}
.search-head kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .68rem;
  border: 1px solid var(--line, rgba(23,39,71,.2)); border-radius: 6px; padding: 2px 7px; opacity: .6;
}
.search-list { overflow-y: auto; padding: 6px 8px 10px; flex: 1; }
.search-group {
  font-size: .68rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted, #5b6b8c); padding: 10px 10px 4px;
}
.search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; text-decoration: none;
  color: var(--ink, #172747);
}
.search-item.sel, .search-item:hover { background: rgba(61, 109, 235, .09); }
.search-item .si-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item .si-title mark { background: rgba(255, 199, 0, .4); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-item .si-sub {
  flex: 1.2; min-width: 0; font-size: .78rem; color: var(--muted, #5b6b8c);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-item .si-go { opacity: 0; color: var(--accent, #3d6deb); font-weight: 700; }
.search-item.sel .si-go, .search-item:hover .si-go { opacity: 1; }
.search-empty { padding: 26px 14px; text-align: center; color: var(--muted, #5b6b8c); }
.search-foot {
  padding: 8px 16px; border-top: 1px solid var(--line, rgba(23,39,71,.12));
  font-size: .72rem; color: var(--muted, #5b6b8c);
}

/* ---------- demo pill ---------- */
.demo-pill {
  position: fixed; left: 16px; bottom: 16px; z-index: 130;
  display: flex; align-items: center; gap: 9px; max-width: min(420px, calc(100vw - 32px));
  background: #172747; color: #fff; border-radius: 12px;
  padding: 9px 12px; font-size: .8rem; line-height: 1.35;
  box-shadow: 0 12px 30px rgba(10, 18, 35, .35);
}
.demo-pill .demo-dot { width: 8px; height: 8px; border-radius: 50%; background: #ffd75e; display: inline-block; flex: none; }
.demo-pill strong { color: #ffd75e; }
.demo-pill .demo-reset {
  border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff;
  border-radius: 8px; padding: 3px 10px; cursor: pointer; font: inherit; font-size: .76rem; flex: none;
}
.demo-pill .demo-reset:hover { background: rgba(255,255,255,.14); }

/* ---------- PWA install pill (REMOVED in v5 — Nerdlyy stays online;
   the install prompt / service worker / manifest were taken out on purpose) */

/* ---------- feedback widget ---------- */
.fb-launcher {
  position: fixed; right: 20px; bottom: 88px; z-index: 94;
  width: 46px; height: 46px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--paper, #fff); color: var(--ink, #172747);
  border: 1px solid var(--line, rgba(23,39,71,.16));
  box-shadow: 0 8px 22px rgba(10, 18, 35, .16);
  font-size: 1.15rem; display: inline-flex; align-items: center; justify-content: center;
  transition: transform .15s ease, box-shadow .15s ease;
}
.fb-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(10, 18, 35, .22); }
.fb-overlay {
  position: fixed; inset: 0; z-index: 221;
  background: rgba(13, 22, 40, .5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.fb-modal {
  width: min(460px, 100%); background: var(--paper, #fff); border-radius: 16px;
  box-shadow: 0 30px 80px rgba(10, 18, 35, .35); padding: 20px;
}
.fb-modal h3 { margin: 0 0 4px; }
.fb-modal .fb-sub { margin: 0 0 14px; color: var(--muted, #5b6b8c); font-size: .84rem; }
.fb-kinds { display: flex; gap: 8px; margin-bottom: 12px; }
.fb-kind {
  flex: 1; text-align: center; padding: 8px 4px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line, rgba(23,39,71,.16)); background: transparent; font: inherit; font-size: .84rem;
}
.fb-kind.on { border-color: var(--accent, #3d6deb); background: rgba(61,109,235,.09); color: var(--accent, #3d6deb); font-weight: 700; }
.fb-modal textarea {
  width: 100%; min-height: 110px; resize: vertical; font: inherit; font-size: .92rem;
  border: 1px solid var(--line, rgba(23,39,71,.2)); border-radius: 10px; padding: 10px 12px;
  color: var(--ink, #172747); background: transparent; box-sizing: border-box;
}
.fb-modal textarea:focus { outline: 2px solid rgba(61,109,235,.4); border-color: var(--accent, #3d6deb); }
.fb-email {
  width: 100%; margin-top: 10px; font: inherit; font-size: .9rem;
  border: 1px solid var(--line, rgba(23,39,71,.2)); border-radius: 10px; padding: 9px 12px;
  color: var(--ink, #172747); background: transparent; box-sizing: border-box;
}
.fb-note { font-size: .74rem; color: var(--muted, #5b6b8c); margin: 10px 0 0; }
.fb-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- class page (v5) ---------- */
.join-row, .create-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.join-input {
  font: inherit; font-size: 1rem; padding: 10px 14px;
  border: 1px solid var(--line, rgba(23,39,71,.2)); border-radius: 10px;
  background: transparent; color: var(--ink, #172747);
}
.join-input.grow { flex: 1; min-width: 220px; }
#join-code {
  width: 140px; text-align: center; letter-spacing: .35em; font-weight: 700;
  text-transform: uppercase; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
#join-code:focus { outline: 2px solid rgba(61,109,235,.4); border-color: var(--accent, #3d6deb); }
.class-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--line, rgba(23,39,71,.12));
  border-radius: 12px; margin-bottom: 10px; flex-wrap: wrap;
}
.class-row-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.class-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700;
  letter-spacing: .25em; background: rgba(61,109,235,.1); color: var(--accent, #3d6deb);
  border: 1px dashed rgba(61,109,235,.4); border-radius: 8px; padding: 3px 10px 3px 13px;
}
.class-code-big { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .25em; }
.weak-topic { margin: 1px 2px 1px 0; display: inline-block; }
.badge-warn { background: rgba(255, 176, 32, .16); color: #8a5a00; }

/* ==========================================================================
   v6 — Mobile layout corrections
   Small-screen geometry only: stacks, boxes and icon sizing. No palette or
   component redesign. Kept at the end of the file so these rules win over
   the older responsive blocks above.
   ========================================================================== */

/* Subject switch icons are injected as bare inline SVGs (no .ic class).
   Without an explicit box they expand to the flex line and turn the footer
   switch button into a giant arrow. Give every injected switch icon a fixed
   optical size in both the header pill and the footer banner. */
.subject-switch .ss-opt > svg,
.subject-switch .ss-arrow > svg,
.subject-switch-bar .ssb-btn > svg {
  width: 15px;
  height: 15px;
  flex: none;
  display: block;
}
.subject-switch .ss-opt > svg { width: 14px; height: 14px; }

/* Mobile: stack the profile's two-column account/study cards. The inline
   grid-template-columns on #profile-content wins over the global .grid-cards
   breakpoint, which used to squeeze the Study data card into a narrow strip. */
@media (max-width: 640px) {
  #profile-content > .grid-cards {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #profile-content .card {
    padding: 16px !important;
  }
  #profile-content .kv-grid[style*="1fr 1fr 1fr"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #profile-name,
  #profile-email {
    overflow-wrap: anywhere;
  }
  #profile-content .btn-row > .btn {
    width: 100%;
  }
}

/* Footer subject-switch banner: one clean column on phones, with the copy
   aligned to its icon and a full-width action. The injected swap SVG is
   already sized by the rule above. */
@media (max-width: 640px) {
  .subject-switch-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 11px;
    padding: 13px 14px;
  }
  .subject-switch-bar .ssb-copy {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: .82rem;
    line-height: 1.5;
  }
  .subject-switch-bar .ssb-copy .ic {
    margin-top: 1px;
  }
  .subject-switch-bar .ssb-text {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .subject-switch-bar .ssb-btn {
    width: 100%;
    justify-content: center;
    white-space: normal;
  }
}

/* First-visit sign-in nudge: on short phones the dialog could exceed the
   viewport. Keep it scrollable inside the overlay instead of clipping. */
@media (max-width: 480px) {
  .auth-nudge-overlay {
    padding: 14px;
  }
  .auth-nudge {
    max-height: calc(100dvh - 28px);
    overflow-y: auto;
    padding: 26px 18px 20px;
    border-radius: 18px;
  }
  .auth-nudge h3 { font-size: 1.12rem; }
  .auth-nudge-sub { font-size: .86rem; }
  .auth-nudge-list li { font-size: .84rem; }
}

/* The AI launcher's desktop copy rule comes later in the file than the old
   mobile hide rule, so the label stayed visible on phones and covered the
   page/footer. Restore the compact icon-only launcher on small screens. */
@media (max-width: 640px) {
  .ai-launcher-copy,
  .ai-launcher-label,
  .ai-launcher-arrow {
    display: none !important;
  }
  .ai-launcher {
    padding: 8px;
    gap: 0;
  }
  .ai-launcher-ic {
    width: 40px;
    height: 40px;
  }
}

/* The header uses the 2:1 transparent logo PNG inside a square box. The
   default object-fit: fill squeezed the mark horizontally; cover keeps its
   aspect ratio and crops only the transparent side padding. */
.brand > img {
  object-fit: cover;
  object-position: center;
  flex: none;
}

/* Arena lobby: grid items default to min-width:auto, so a wide mode-card
   image could force the single mobile column wider than the viewport.
   Let the lobby panel and its cards shrink to the column. */
.arena-grid,
.arena-grid > *,
#arena-create-panel,
#ar-mode-grid,
.ar-mode-card,
.ar-mode-art {
  min-width: 0;
}
.ar-mode-art img {
  max-width: 100%;
}
