/* Self-hosted Iowan Old Style (the Thinking Machines brand serif). Only the
   regular weight ships as a webfont, so bold is synthesized — same as their site.
   Named distinctly so Apple devices, which have the real family (with true bold),
   still prefer the system font. */
@font-face {
  font-family: "Iowan Old Style Web";
  src: url("/fonts/iowan-old-style_regular.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Light "academic paper" theme */
  --bg: #ffffff;
  --paper: #faf8f3;          /* warm paper for bands / insets */
  --bg-elev: #ffffff;        /* cards */
  --bg-elev-2: #f4f2ec;      /* warm inset */
  --code-bg: #fbfaf6;        /* editor / code panels */
  --border: #e5e1d8;
  --border-soft: #efece4;
  --text: #1c1b19;           /* warm ink */
  --text-dim: #5c574f;
  --text-faint: #938c80;
  --accent: #a1670c;         /* warm amber-orange */
  --accent-strong: #83530a;
  --accent-2: #b0812f;       /* antique gold */
  --accent-soft: rgba(161,103,12,0.09);
  --green: #1a7f37;
  --red: #c0392b;
  --amber: #9a6a00;
  --easy: #1a7f37;
  --medium: #9a6a00;
  --hard: #c0392b;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(28,27,25,0.05), 0 1px 3px rgba(28,27,25,0.06);
  --shadow: 0 6px 24px rgba(28,27,25,0.08);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Iowan Old Style Web", "Charter", "Bitstream Charter",
    "Palatino Linotype", "Palatino", "Sorts Mill Goudy", "Hoefler Text", Georgia,
    "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
button { font-family: var(--sans); cursor: pointer; }
::selection { background: rgba(161,103,12,0.16); }

/* ---------- top bar (journal masthead) ---------- */
.topbar {
  display: flex; align-items: center; gap: 26px;
  padding: 0 26px; height: 62px;
  background: rgba(255,255,255,0.86);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand-mark { width: 30px; height: 30px; object-fit: contain; border-radius: 7px; display: block; }
.brand-name { font-family: var(--serif); font-weight: 700; font-size: 20px; letter-spacing: -0.2px; white-space: nowrap; }
.accent { color: var(--accent); }
/* Wrapper is transparent to layout on desktop (nav + user-area stay direct flex
   items); it becomes the dropdown container on mobile. */
.topbar-menu { display: contents; }
.nav-toggle {
  display: none; margin-left: auto; font-size: 20px; line-height: 1;
  background: transparent; border: 1px solid var(--border); border-radius: 9px;
  width: 40px; height: 38px; color: var(--text-dim); align-items: center; justify-content: center;
}
.nav-toggle:hover { background: var(--bg-elev-2); color: var(--text); }
.nav { display: flex; gap: 4px; }
.nav-link {
  font-family: var(--sans); color: var(--text-dim); padding: 7px 12px; border-radius: 8px;
  font-weight: 500; font-size: 14px;
}
.nav-link:hover { background: var(--bg-elev-2); color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.user-area { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* ---- mobile top bar: collapse nav + user-area into a hamburger dropdown ---- */
@media (max-width: 720px) {
  .topbar { gap: 12px; padding: 0 16px; height: 56px; }
  .brand-mark { width: 26px; height: 26px; }
  .brand-name { font-size: 17px; }
  .nav-toggle { display: inline-flex; }
  .topbar-menu { display: none; }
  .topbar.menu-open .topbar-menu {
    display: flex; flex-direction: column; align-items: stretch; gap: 6px;
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-elev); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow); padding: 10px 14px 14px; z-index: 30;
  }
  .topbar.menu-open .nav { display: flex; flex-direction: column; gap: 2px; }
  .topbar.menu-open .nav-link { padding: 11px 12px; font-size: 15px; }
  .topbar.menu-open .user-area {
    margin: 4px 0 0; padding-top: 12px; border-top: 1px solid var(--border-soft);
    flex-direction: column; align-items: stretch; gap: 10px;
  }
  .topbar.menu-open .user-chip { justify-content: flex-start; }
}

.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip .uname { font-family: var(--sans); font-weight: 600; font-size: 14px; }
.solved-chip {
  font-family: var(--sans);
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  padding: 4px 11px; border-radius: 20px; font-size: 13px; color: var(--text-dim);
}

/* ---------- buttons ---------- */
.btn {
  font-family: var(--sans);
  border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--text); padding: 8px 15px; border-radius: 9px;
  font-size: 14px; font-weight: 600; transition: 0.12s; box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: #d4cec1; background: #fbfaf7; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--bg-elev-2); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
/* Soft-green call-to-action — lighter and friendlier than the amber primary.
   Used for the main "do it" buttons (Run tests, Check answer) and the Sign-up
   CTA. Rest: the pale green of the Easy chip; hover: deepens to solid green. */
.btn-green { background: rgba(26,127,55,0.10); border-color: rgba(26,127,55,0.30); color: var(--easy); }
.btn-green:hover { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- view ---------- */
.view { max-width: 1180px; margin: 0 auto; padding: 34px 24px 72px; }

/* ---------- hero / masthead ---------- */
.hero { margin-bottom: 30px; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.hero .eyebrow {
  font-family: var(--sans); text-transform: uppercase; letter-spacing: 0.16em;
  font-size: 11.5px; font-weight: 700; color: var(--accent); margin-bottom: 10px;
}
.hero h1 { font-family: var(--serif); font-size: 38px; line-height: 1.12; margin: 0 0 10px; letter-spacing: -0.4px; font-weight: 700; }
.hero p { color: var(--text-dim); margin: 0; max-width: 680px; font-size: 18px; }
.hero p strong { color: var(--text); }

/* Personalized progress bar (right-aligned, non-invasive) */
.you-progress-row { display: flex; justify-content: flex-end; margin: -8px 0 16px; }
.you-progress { display: inline-flex; align-items: center; gap: 10px; font-family: var(--sans); font-size: 12.5px; color: var(--text-dim); }
.you-progress .yp-label { font-weight: 600; }
.you-progress .yp-bar { width: 130px; height: 7px; background: var(--bg-elev-2); border: 1px solid var(--border-soft); border-radius: 999px; overflow: hidden; }
.you-progress .yp-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .35s ease; }
.you-progress .yp-count { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.you-progress .yp-count span { color: var(--text-faint); font-weight: 500; }

.filters { display: flex; gap: 8px; margin: 22px 0; flex-wrap: wrap; }
.chip {
  font-family: var(--sans);
  border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--text-dim); padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 500;
}
.chip:hover { border-color: #d4cec1; }
.chip.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* Category filter chips — multi-select, union. Smaller than difficulty chips. */
.cat-filters { display: flex; flex-wrap: wrap; gap: 7px; margin: -2px 0 18px; }
.cat-chip {
  font-family: var(--sans); border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--text-dim); padding: 4px 11px; border-radius: 20px; font-size: 12px; font-weight: 500;
  transition: border-color .12s, color .12s, background .12s;
}
.cat-chip:hover { border-color: #d4cec1; }
.cat-chip.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* ---------- problems table ---------- */
.list-controls {
  display: flex; align-items: center; gap: 12px; margin: 22px 0 16px; flex-wrap: wrap;
}
.list-controls .filters { margin: 0; }
.search-wrap { position: relative; flex: 1 1 290px; max-width: 410px; }
.search-input {
  width: 100%; height: 42px; padding: 0 42px 0 42px;
  border: 1px solid var(--border); border-radius: 11px; background: var(--code-bg);
  color: var(--text); font-family: var(--sans); font-size: 14px;
  box-shadow: inset 0 1px 1px rgba(28,27,25,0.03), var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search-input:focus { outline: none; background: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-input::placeholder { color: var(--text-faint); }
.search-ic {
  position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%);
  fill: none; stroke: var(--text-faint); stroke-width: 1.8; stroke-linecap: round; pointer-events: none;
}
.random-pick { white-space: nowrap; color: var(--accent); background: var(--accent-soft); border-color: rgba(161,103,12,.22); }
.list-count { margin-left: auto; color: var(--text-faint); font: 12px var(--sans); white-space: nowrap; }
.q-empty { padding: 34px; text-align: center; color: var(--text-dim); font-family: var(--sans); }
.q-table { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.q-row {
  display: grid; grid-template-columns: 40px 1fr 130px 180px;
  align-items: center; gap: 12px;
  padding: 15px 20px; border-bottom: 1px solid var(--border-soft);
  cursor: pointer; transition: 0.1s;
}
.q-row:last-child { border-bottom: none; }
.q-row:hover { background: var(--paper); }
.q-row.head { cursor: default; color: var(--text-faint); font-family: var(--sans); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
.q-row.head:hover { background: transparent; }
.th-sort { cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 4px; transition: color .12s; }
.th-sort:hover { color: var(--text-dim); }
.th-sort.active { color: var(--accent); }
.th-sort .sort-arrow { font-size: 12px; line-height: 1; }
.q-status { text-align: center; }
.q-status .q-dot {
  width: 21px; height: 21px; border-radius: 50%; box-sizing: border-box;
  border: 2px solid var(--border); display: inline-flex; align-items: center;
  justify-content: center; vertical-align: middle;
}
.q-row:hover .q-status .q-dot:not(.solved) { border-color: #cdc6b8; }
/* Solved: pale-green fill (the "Easy" chip colour) with a small, light green
   tick — quiet enough not to draw the eye, but clearly a done state. */
.q-status .q-dot.solved {
  background: rgba(26,127,55,0.10); border-color: rgba(26,127,55,0.22); color: var(--easy);
  font-size: 9.5px; font-weight: 600; line-height: 1;
}
.q-title { font-family: var(--serif); font-weight: 400; font-size: 17px; color: var(--text); letter-spacing: .01em; transition: color .12s; }
.q-row:hover .q-title { color: var(--accent); }
.q-cat { color: var(--text-dim); font-family: var(--sans); font-size: 13px; }

/* ---------- papers ---------- */
.papers-table { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.paper-row {
  display: grid; grid-template-columns: 1fr auto;
  align-items: center; gap: 16px;
  padding: 16px 20px; border-bottom: 1px solid var(--border-soft);
}
.paper-row:last-child { border-bottom: none; }
.paper-row.head { color: var(--text-faint); font-family: var(--sans); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
.paper-info { cursor: pointer; }
.paper-info .paper-link { color: var(--text); display: inline-block; font-size: 17px; }
.paper-info:hover .paper-link { color: var(--accent); }
.paper-info .paper-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.paper-meta { color: var(--text-dim); font-family: var(--sans); font-size: 13px; margin-top: 3px; }
.paper-tag { display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 20px; padding: 1px 9px; }
.paper-actions { display: flex; align-items: center; gap: 10px; }
.paper-solved { font-family: var(--sans); font-size: 12.5px; color: var(--green); font-weight: 600; }
/* Per-paper progress: coding problems solved + quiz questions answered correctly. */
.paper-progress { display: flex; align-items: center; gap: 10px; margin-top: 9px; max-width: 460px; }
.pp-track { flex: 1; height: 7px; background: var(--bg-elev-2); border: 1px solid var(--border-soft); border-radius: 999px; overflow: hidden; }
.pp-fill { height: 100%; background: var(--green); border-radius: 999px; transition: width .35s ease; }
.pp-label { font-family: var(--sans); font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 40px; }
.paper-hero { margin-bottom: 18px; }
.paper-byline { font-family: var(--sans); font-size: 14px; color: var(--text-dim); margin-top: 12px; }
.paper-body { margin-top: 20px; }
@media (max-width: 640px) {
  .paper-row { grid-template-columns: 1fr; }
  .paper-actions { flex-wrap: wrap; }
}
.badge {
  font-family: var(--sans);
  display: inline-block; padding: 3px 11px; border-radius: 20px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.01em;
}
.badge.Easy { color: var(--easy); background: rgba(26,127,55,0.10); }
.badge.Medium { color: var(--medium); background: rgba(154,106,0,0.12); }
.badge.Hard { color: var(--hard); background: rgba(192,57,43,0.10); }

/* ---------- problem detail ---------- */
.pd { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
@media (max-width: 960px) { .pd { grid-template-columns: 1fr; } }

.back { font-family: var(--sans); color: var(--text-dim); font-size: 14px; display: inline-flex; gap: 6px; margin-bottom: 16px; }
.back:hover { color: var(--accent); text-decoration: none; }

.panel { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.pd-desc { padding: 30px 34px; }
.pd-desc h1 { font-family: var(--serif); font-size: 28px; line-height: 1.15; margin: 0 0 12px; letter-spacing: -0.3px; font-weight: 700; }
/* Solved check-circle sitting inline right after the problem title (LeetCode-style
   "Solved" mark, in our green). Hidden until solved; on a fresh solve .emerge
   plays a subtle scale-in pop. */
.pd-solved {
  display: none; vertical-align: middle; position: relative; top: -0.06em;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--green); color: #fff;
  font-family: var(--sans); font-size: 12px; font-weight: 700; line-height: 1;
}
.pd-solved.is-solved { display: inline-flex; align-items: center; justify-content: center; }
.pd-solved.emerge { animation: solved-emerge 0.45s cubic-bezier(0.34, 1.4, 0.5, 1); }
@keyframes solved-emerge {
  0%   { transform: scale(0);    opacity: 0; }
  60%  { transform: scale(1.14); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .pd-solved.emerge { animation: none; } }

/* ---- Description / Solution tabs (left pane) ---- */
.pd-tabs {
  display: flex; gap: 4px; align-items: flex-end;
  padding: 0 18px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 3;
}
.pd-tab {
  font-family: var(--sans); font-size: 13.5px; font-weight: 600;
  color: var(--text-dim); background: none; border: none;
  padding: 12px 14px 11px; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: 0.12s;
}
.pd-tab:hover { color: var(--text); }
.pd-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- reference solution pane ---- */
.pd-solution .sol-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 16px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.sol-title { font-family: var(--serif); font-size: 21px; font-weight: 700; margin: 0; }
.sol-sub { font-family: var(--sans); font-size: 13.5px; color: var(--text-dim); margin: 5px 0 0; line-height: 1.5; }
.sol-code {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; overflow-x: auto;
}
.sol-code pre { margin: 0; }
.sol-code pre.hl code { font-family: var(--mono); font-size: 13px; line-height: 1.6; white-space: pre; color: var(--text); }
.sol-empty { color: var(--text-dim); font-family: var(--sans); font-size: 15px; padding: 20px 0; }

/* spoiler gate */
.sol-gate {
  text-align: center; max-width: 460px; margin: 8vh auto 0;
  padding: 34px 28px; background: var(--paper);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.sol-gate-icon { font-size: 34px; margin-bottom: 10px; }
.sol-gate .sol-title { margin-bottom: 10px; }
.sol-gate p { font-family: var(--sans); font-size: 14.5px; color: var(--text-dim); line-height: 1.6; margin: 0 0 22px; }
.sol-gate p strong { color: var(--text); }
.pd-meta { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; flex-wrap: wrap; font-family: var(--sans); padding-bottom: 18px; border-bottom: 1px solid var(--border-soft); }
.pd-meta .solved-tag { color: var(--green); font-weight: 600; font-size: 13px; }
.pd-meta .paper-link {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--accent); font-size: 12.5px; font-weight: 600;
  padding: 3px 11px; border: 1px solid rgba(161,103,12,.22); border-radius: 20px;
  background: var(--accent-soft); white-space: nowrap;
}
.pd-meta .paper-link:hover { background: var(--accent); color: #fff; text-decoration: none; }
/* Clickable category chip (topic tag) — neutral pill that highlights to accent
   on hover; clicking filters the Problems list to this category. */
.pd-meta .q-cat-chip {
  font-family: var(--sans); font-size: 12.5px; font-weight: 500;
  color: var(--text-dim); background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: 20px; padding: 3px 11px;
  white-space: nowrap; transition: color .12s, border-color .12s, background .12s;
}
.pd-meta .q-cat-chip:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* markdown — reads like a paper */
.md { color: var(--text); font-size: 17px; line-height: 1.75; }
.md > p:first-of-type { font-size: 18.5px; }
.md p { margin: 14px 0; }
.md h2 {
  font-family: var(--serif); font-size: 15px; margin: 26px 0 10px;
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--accent);
}
.md ul { margin: 12px 0; padding-left: 24px; }
.md li { margin: 6px 0; }
.md strong { color: var(--text); font-weight: 700; }
.md em { font-style: italic; }
.md code.inline { font-family: var(--mono); background: var(--bg-elev-2); padding: 1px 6px; border-radius: 5px; font-size: 0.86em; color: #7c2d8b; }
.md pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px; overflow-x: auto; margin: 14px 0;
}
/* ---- inline diagrams (author-authored SVG figures) ---- */
.md .fig {
  margin: 20px 0; padding: 18px 16px; text-align: center;
  background: var(--paper); border: 1px solid var(--border); border-radius: 10px;
  overflow-x: auto;
}
/* Figures carry only a viewBox (no intrinsic px size), so cap them here — else
   they scale up to fill the whole panel and dwarf the text. */
.md .fig svg { width: 100%; max-width: 440px; max-height: 300px; height: auto; display: block; margin: 0 auto; }
.md .fig figcaption {
  margin-top: 12px; font-family: var(--sans); font-size: 12.5px; color: var(--text-dim);
  line-height: 1.5; max-width: 560px; margin-left: auto; margin-right: auto;
}
.md .fig figcaption a { color: var(--accent); }
.md pre code { font-family: var(--mono); font-size: 13px; color: #24292f; }

/* ```matrix -> visual 0/1 grid (1s highlighted, 0s muted) */
.md .mtx-fig { margin: 20px 0; text-align: center; }
.md .mtx-grid {
  display: inline-flex; flex-direction: column; gap: 5px; padding: 12px;
  background: var(--paper); border: 1px solid var(--border); border-radius: 10px;
  max-width: 100%; overflow-x: auto;
}
.md .mtx-row { display: flex; gap: 5px; }
.md .mtx-cell {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center;
  font-family: var(--mono); font-size: 14px; border-radius: 6px;
  background: var(--bg-elev-2); color: var(--text-faint); border: 1px solid var(--border-soft);
}
.md .mtx-cell.one { background: var(--accent-soft); color: var(--accent); border-color: rgba(161,103,12,.32); font-weight: 700; }
.md .mtx-cell.zero { color: var(--text-faint); opacity: 0.7; }
.md .mtx-fig figcaption { margin-top: 12px; font-family: var(--sans); font-size: 12.5px; color: var(--text-dim); }
.md .formula {
  text-align: center; background: var(--paper); border: 1px solid var(--border);
  border-left: 3px solid var(--accent-2); padding: 18px 20px; border-radius: 8px;
  margin: 18px 0; overflow-x: auto; color: var(--text);
}
/* ---- self-contained math rendering ---- */
.math {
  font-family: "Latin Modern Math", "Cambria Math", "Charter", Georgia, "Times New Roman", serif;
  line-height: 2.2; white-space: normal; word-spacing: 0.02em;
}
.md .formula .math { font-size: 1.28rem; }
.md .imath, p .math, li .math { font-size: 1.04em; }
.math .mvar { font-style: italic; }
.math .mtext, .math .mop { font-style: normal; font-family: var(--sans); }
.math .mop { padding: 0 0.12em 0 0.05em; }
.math sup { font-size: 0.72em; vertical-align: super; line-height: 0; }
.math sub { font-size: 0.72em; vertical-align: sub; line-height: 0; }
.math .mfrac {
  display: inline-flex; flex-direction: column; text-align: center;
  vertical-align: middle; margin: 0 0.2em; font-size: 0.96em;
}
.math .mfrac .mnum { border-bottom: 1px solid currentColor; padding: 0 0.4em 0.06em; }
.math .mfrac .mden { padding: 0.06em 0.4em 0; }
/* Radical: enlarge the √ glyph and top-align it so its rising diagonal meets the
   vinculum (the radicand's top border), forming one continuous √‾‾‾ shape. A
   baseline-aligned glyph leaves the bar floating detached above the sign. */
.math .msqrt, .qmath .msqrt { display: inline-flex; align-items: flex-start; vertical-align: middle; }
.math .msqrt .mrad, .qmath .msqrt .mrad { font-size: 1.2em; line-height: 0.9; margin-right: -0.12em; }
/* line-height:1.2 overrides the .math container's large 2.2 leading, which
   otherwise drops the radicand well below the vinculum (esp. tall radicands). */
.math .msqrt .munder, .qmath .msqrt .munder { border-top: 1px solid currentColor; padding: 0.06em 0.28em 0 0.02em; line-height: 1.2; }
/* Shrink a superscript INSIDE the radicand (e.g. σ²+ε) so it doesn't inflate the
   box height and drop the vinculum far above the content, leaving it drooping. */
.math .msqrt .munder sup, .qmath .msqrt .munder sup { font-size: 0.62em; vertical-align: 0.42em; }
/* When the radicand is a fraction it's ~2 lines tall, so grow the √ glyph to
   enclose it (a fixed 1.2em √ would float small in the upper-left otherwise). */
.math .msqrt:has(.mfrac) .mrad, .qmath .msqrt:has(.mfrac) .mrad { font-size: 1.85em; line-height: 0.8; }

/* Quiz ASCII-math typesetting (typesetMath): crisp inline scripts + radical. */
.qmath sub, .qmath sup { font-size: 0.74em; line-height: 0; }
.qmath sub { vertical-align: -0.28em; }
.qmath sup { vertical-align: super; }
/* Extra headroom under the quiz radical's vinculum: quiz radicands like √ᾱ_t use
   a combining macron (ᾱ) that otherwise collides with the vinculum. */
.qmath .msqrt .munder { padding-top: 0.22em; }

/* Accents (\hat, \bar, \overline): float above an inline-block base so the base
   keeps the text baseline. A flex column drops the whole glyph below the line. */
.math .macc { position: relative; display: inline-block; line-height: 1; }
.math .macc-b { display: inline-block; }
.math .macc-t {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: -0.44em; font-size: 0.72em; line-height: 1; pointer-events: none;
}
.math .macc-bar {
  left: 0; right: 0; transform: none; top: 0; height: 0.46em;
  border-top: 1px solid currentColor; font-size: 0;
}
/* \dot accent (ẋ): the dot-above glyph sits high in its box — nudge it down. */
.math .macc-dot { top: -0.30em; font-size: 1em; }
/* Relations & binary operators (\times, \le, \to, …): symmetric side space. */
.math .mrel { margin: 0 0.22em; }
.math .msp-thin { display: inline-block; width: 0.16em; }
.math .msp { display: inline-block; width: 0.3em; }
.math .msp-q { display: inline-block; width: 1em; }
.math .msp-qq { display: inline-block; width: 2em; }
/* \binom{n}{k} — stacked column in parentheses, no fraction bar */
.math .mbinom { display: inline-flex; align-items: center; }
.math .mbinom .mbinom-col { display: inline-flex; flex-direction: column; text-align: center; line-height: 1.05; padding: 0 0.15em; font-size: 0.95em; }
.math .mbb { font-weight: 700; }
/* \left / \right delimiters — scaled up to match the (usually tall) content
   they wrap: fractions, radicals, floor brackets. */
.math .mdelim { font-size: 1.5em; line-height: 0; vertical-align: -0.28em; }

/* editor column */
.pd-code { display: flex; flex-direction: column; gap: 14px; }
.editor-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--code-bg); box-shadow: var(--shadow-sm); }
.editor-bar { display: flex; align-items: center; justify-content: space-between; padding: 9px 14px; background: var(--bg-elev-2); border-bottom: 1px solid var(--border); }
.editor-bar .fname { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.editor-bar .actions { display: flex; gap: 8px; }
.lang-select {
  font-family: var(--sans); font-size: 13px; font-weight: 600; color: var(--text);
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 26px 5px 10px; cursor: pointer; box-shadow: var(--shadow-sm);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235c574f' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.lang-select:hover { border-color: #d4cec1; }
.lang-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.editor {
  display: grid; grid-template-columns: auto 1fr;
  max-height: 440px; overflow: auto;
}
.gutter {
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  padding: 12px 8px 12px 14px; color: #b8b2a4;
  text-align: right; user-select: none; background: var(--code-bg);
  white-space: pre;
}
/* Syntax-highlight overlay: a <pre> painted behind a transparent-text textarea.
   Both must share identical box metrics so glyphs line up exactly. */
.code-area { position: relative; }
.code-area .hl,
.code-area .code-input {
  margin: 0; border: 0; padding: 12px;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  tab-size: 4; -moz-tab-size: 4; white-space: pre; overflow-wrap: normal; word-break: normal;
  letter-spacing: 0;
}
.code-area .hl {
  position: absolute; inset: 0; margin: 0; pointer-events: none; overflow: hidden;
  color: #24292f; background: var(--code-bg);
}
.code-area .hl code { font: inherit; white-space: pre; }
.code-area .code-input {
  position: relative; display: block; width: 100%; min-height: 360px;
  background: transparent; color: transparent; caret-color: var(--text);
  resize: none; outline: none; overflow: auto;
}
.code-area .code-input::selection { background: rgba(161,103,12,0.20); }
/* GitHub-light token palette */
.t-kw  { color: #cf222e; }
.t-str { color: #0a3069; }
.t-com { color: #6e7781; font-style: italic; }
.t-num { color: #0550ae; }
.t-fn  { color: #6639ba; }
.t-bi  { color: #953800; }
.t-op  { color: #cf222e; }

.run-actions { display: flex; gap: 10px; }
.run-actions .spacer { flex: 1; }
/* Logged-out sign-in prompt shown under the (CTA-ified) Run button. Kept quiet so
   the anonymous editor experience stays pleasant, not nagging. */
.run-gate-note { font-family: var(--sans); font-size: 13px; color: var(--text-dim); margin-top: -4px; }
.run-gate-note a { color: var(--accent); font-weight: 600; text-decoration: none; }
.run-gate-note a:hover { text-decoration: underline; }

/* Code / theory workspace */
.workspace-tabs { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--bg-elev-2); flex: none; }
.workspace-tab { border: 0; background: transparent; color: var(--text-dim); border-radius: 7px; padding: 7px 18px; font: 600 13px var(--sans); }
.workspace-tab.active { background: var(--bg); color: var(--accent); box-shadow: var(--shadow-sm); }
.workspace-panel { flex: none; }
.code-workspace { display: flex; flex-direction: column; gap: 14px; }
.quiz-workspace { border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; background: var(--bg); box-shadow: var(--shadow-sm); }
.quiz-page { max-width: 760px; margin: 0 auto 60px; border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 34px; background: var(--bg); box-shadow: var(--shadow-sm); }
/* Inside a paper, the quiz box spans the full width so it aligns with the code table. */
.quiz-page.paper-quiz { max-width: none; margin: 0 0 60px; }

/* Paper Progress sub-tab */
.paper-prog { padding: 28px 30px; }
.ppg-overall { margin-bottom: 26px; }
.ppg-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.ppg-title { font-family: var(--serif); font-weight: 700; font-size: 19px; }
.ppg-pct { font-family: var(--serif); font-weight: 700; font-size: 34px; color: var(--accent); line-height: 1; }
.ppg-pct span { font-size: 18px; color: var(--text-faint); }
.ppg-track { height: 12px; }
.ppg-signin { display: flex; align-items: center; gap: 14px; justify-content: space-between; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid rgba(161,103,12,.22); border-radius: 10px;
  padding: 11px 14px; margin-bottom: 18px; font-family: var(--sans); font-size: 13.5px; color: var(--text-dim); }
.ppg-signin strong { color: var(--text); }
.ppg-signin .btn { white-space: nowrap; }
.quiz-anon-note { font-family: var(--sans); font-size: 13px; color: var(--text-dim); }
.ppg-rows { display: flex; flex-direction: column; gap: 14px; }
.ppg-row-top { display: flex; align-items: baseline; justify-content: space-between; }
.ppg-name { font-family: var(--sans); font-size: 14px; font-weight: 600; color: var(--text-dim); }
/* Clickable shortcut rows -> their sub-tab. */
.ppg-link { cursor: pointer; border-radius: 10px; padding: 10px 12px; margin: 0 -12px; transition: background .12s; }
.ppg-link:hover { background: var(--bg-elev-2); }
.ppg-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ppg-link:hover .ppg-name { color: var(--text); }
.ppg-go { color: var(--text-faint); font-weight: 700; transition: color .12s, transform .12s; display: inline-block; }
.ppg-link:hover .ppg-go { color: var(--accent); transform: translateX(2px); }
.ppg-count { font-family: var(--mono); font-size: 14px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.ppg-count b { color: var(--text); font-weight: 700; }
.paper-prog .cat-bar { height: 10px; }
.quiz-cats { justify-content: center; margin: 6px auto 22px; max-width: 820px; }
.quiz-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.quiz-head h2 { margin: 5px 0 0; font: 700 23px/1.3 var(--serif); }
/* Keep "New question" a single line, pinned to the top-right; the long prompt
   otherwise squeezes the flex item and wraps it onto two lines. */
.quiz-head .btn { flex: none; white-space: nowrap; }
.quiz-kicker { color: var(--accent); text-transform: uppercase; letter-spacing: .12em; font: 700 11px var(--sans); }
.quiz-instruction { color: var(--text-dim); margin: 12px 0 20px; font: 14px var(--sans); }
.quiz-choices { display: flex; flex-direction: column; gap: 10px; }
.quiz-choice { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 12px; padding: 13px 15px; border: 1px solid var(--border); border-radius: 9px; font: 14px/1.45 var(--sans); cursor: pointer; transition: .12s; }
.quiz-choice:hover { border-color: #cfc8ba; background: var(--paper); }
.quiz-choice.correct { border-color: rgba(26,127,55,.45); background: rgba(26,127,55,.07); }
.quiz-choice.incorrect { border-color: rgba(192,57,43,.45); background: rgba(192,57,43,.06); }
.quiz-actions { margin-top: 20px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.quiz-actions #quiz-next { margin-left: auto; }
/* Paper quiz is a stepper: Check on the left, Prev/Next grouped on the right. */
.paper-quiz .quiz-actions #quiz-prev { margin-left: auto; }
.paper-quiz .quiz-actions #quiz-next { margin-left: 0; }
.quiz-progress { flex: none; white-space: nowrap; font: 600 12px var(--sans); color: var(--text-faint); background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 11px; }
.quiz-feedback { margin-top: 16px; padding: 13px 15px; border-radius: 8px; font: 14px/1.55 var(--sans); }
.quiz-feedback.success { background: rgba(26,127,55,.08); color: #145f2a; }
.quiz-feedback.retry { background: rgba(154,106,0,.09); color: #725000; }

/* quiz figure — an original, attributed diagram shown above the prompt */
.quiz-figure { margin: 6px 0 20px; padding: 0; }
.quiz-figure-svg { background: #fbf9f4; border: 1px solid var(--border); border-radius: 10px; padding: 16px; display: flex; justify-content: center; overflow-x: auto; }
.quiz-figure-svg svg { width: 100%; max-width: 480px; max-height: 320px; height: auto; }
.quiz-figure-cap { margin-top: 9px; color: var(--text-dim); font: 13px/1.5 var(--sans); }
.quiz-figure-src { margin-top: 4px; font: 11.5px var(--sans); color: var(--text-dim); letter-spacing: .01em; }
.quiz-figure-src a { color: var(--accent); }
/* visual answer choices — a per-choice diagram above its text label */
.quiz-choice-visual { grid-template-columns: 18px 1fr; align-items: start; }
.quiz-choice-visual .quiz-choice-img { grid-column: 2; display: block; background: #fbf9f4; border: 1px solid var(--border-soft); border-radius: 7px; padding: 8px; margin-bottom: 7px; }
.quiz-choice-visual .quiz-choice-img svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.quiz-choice-visual > span { grid-column: 2; }
.quiz-choice-visual input { grid-row: 1; align-self: start; margin-top: 3px; }
/* "Related paper" chip on a theory question linked to a paper */
.quiz-paper-chip { display: inline-flex; align-items: center; gap: 6px; margin: 2px 0 16px; font: 600 12.5px var(--sans); color: var(--accent); background: var(--accent-soft); border: 1px solid rgba(161,103,12,.22); border-radius: 20px; padding: 5px 13px; transition: .12s; }
.quiz-paper-chip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* display-formula card under a quiz prompt (typesetMath, reuses the .mfrac styling) */
.quiz-formula { margin: 2px 0 18px; padding: 14px 18px; background: #fbf9f4; border: 1px solid var(--border); border-radius: 10px; text-align: center; font-size: 20px; line-height: 1.5; color: var(--text); overflow-x: auto; }
.quiz-formula .qmath { display: inline-block; white-space: nowrap; }
/* the shared stacked-fraction styling, also inside inline quiz math (.qmath) */
.qmath .mfrac { display: inline-flex; flex-direction: column; text-align: center; vertical-align: middle; margin: 0 0.2em; font-size: 0.96em; }
.qmath .mfrac .mnum { border-bottom: 1px solid currentColor; padding: 0 0.4em 0.06em; }
.qmath .mfrac .mden { padding: 0.06em 0.4em 0; }

/* "all caught up" state when every question in the pool is already solved */
.quiz-done { text-align: center; padding: 40px 24px; }
.quiz-done-emoji { font-size: 40px; line-height: 1; margin-bottom: 10px; }
.quiz-done h2 { font-family: var(--serif); font-size: 24px; margin: 0 0 8px; }
.quiz-done p { color: var(--text-dim); font: 15px/1.6 var(--sans); margin: 0 auto; max-width: 420px; }

/* results */
.results { padding: 0; overflow: hidden; }
/* Stylish pass/fail summary banner at the top of the results. */
.results-head {
  padding: 13px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 11px;
  font-family: var(--sans); font-size: 14.5px; color: var(--text);
}
.results-head .rs-badge {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff;
}
.results-head .rs-summary { font-weight: 500; }
.results-head .rs-summary b { font-weight: 700; font-variant-numeric: tabular-nums; }
.results-head.pass  { background: rgba(26,127,55,.08);  border-bottom-color: rgba(26,127,55,.22); }
.results-head.pass  .rs-badge { background: var(--green); }
.results-head.pass  .rs-summary b { color: var(--green); }
.results-head.fail  { background: rgba(192,57,43,.06);  border-bottom-color: rgba(192,57,43,.20); }
.results-head.fail  .rs-badge { background: var(--red); }
.results-head.fail  .rs-summary b { color: var(--red); }
.results-head.error { background: rgba(154,106,0,.07);  border-bottom-color: rgba(154,106,0,.22); }
.results-head.error .rs-badge { background: var(--amber); }

/* Non-invasive button spinner (shown while "Run tests" is running). */
.run-actions .btn-primary { min-width: 128px; }
.btn.is-loading { pointer-events: none; }
/* Standard arc spinner: a ring in the button's own text colour (currentColor,
   so it reads on the green button) with one transparent quarter, making the
   rotation obvious. A calm ~0.9s turn — the old 0.6s solid ring spun too fast. */
.btn-spinner {
  display: inline-block; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: btn-spin 0.9s linear infinite; vertical-align: -2px;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
.cases { padding: 10px 10px 14px; display: flex; flex-direction: column; gap: 7px; }
.case {
  border: 1px solid var(--border-soft); border-radius: 8px;
  background: var(--bg); overflow: hidden;
}
.case.pass { background: rgba(26,127,55,0.03); }
.case.fail { background: rgba(192,57,43,0.03); }
.case-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 13px;
  cursor: pointer; font-family: var(--sans); font-size: 13.5px;
}
.case-head .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.case.pass .dot { background: var(--green); }
.case.fail .dot { background: var(--red); }
.case .cname { font-weight: 600; }
.case .csub { font-size: 12px; color: var(--text-faint); font-weight: 400; }
.case .ctag { margin-left: auto; font-size: 12px; color: var(--text-faint); }
/* Per-test I/O: labelled Input / Expected / Your output blocks, each a mono value chip. */
.case-body { padding: 2px 13px 13px 31px; font-family: var(--sans); }
.io-field { margin: 9px 0; }
.io-field:first-child { margin-top: 4px; }
.io-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); margin-bottom: 4px;
}
.io-val {
  margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; color: var(--text);
  background: var(--code-bg); border: 1px solid var(--border-soft); border-radius: 6px;
  padding: 7px 9px; white-space: pre-wrap; word-break: break-word; overflow-x: auto; max-height: 220px;
}
.io-val.ok  { background: rgba(26,127,55,0.07);  border-color: rgba(26,127,55,0.22); }
.io-val.bad { background: rgba(192,57,43,0.06); border-color: rgba(192,57,43,0.22); color: #b3271f; }
.io-val.muted { color: var(--text-dim); }
.stdout-box {
  margin: 6px 14px 14px; background: var(--code-bg); border: 1px solid var(--border-soft);
  border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 12.5px;
  color: var(--text-dim); white-space: pre-wrap; max-height: 160px; overflow: auto;
}
.stdout-box .lbl { color: var(--text-faint); display: block; margin-bottom: 4px; font-family: var(--sans); }
/* Per-test print output, shown inside that test's case body. */
.case-out {
  margin: 8px 0 2px; background: var(--code-bg); border: 1px solid var(--border-soft);
  border-radius: 6px; padding: 8px 10px; font-family: var(--mono); font-size: 12px;
  color: var(--text-dim); white-space: pre-wrap; max-height: 140px; overflow: auto;
}
.case-out .lbl { color: var(--text-faint); display: block; margin-bottom: 3px; font-size: 11px; font-family: var(--sans); }

/* hints */
.hint-panel { padding: 18px 20px; }
.hint-panel h3 { font-family: var(--serif); margin: 0 0 4px; font-size: 17px; }
.hint-panel .sub { font-family: var(--sans); color: var(--text-faint); font-size: 12.5px; margin-bottom: 12px; }
.hint-list { display: flex; flex-direction: column; gap: 9px; margin-bottom: 12px; }
.hint-item {
  background: var(--paper); border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent-2); border-radius: 6px;
  padding: 11px 13px; font-size: 15px; line-height: 1.6;
}
.hint-item .src { font-family: var(--sans); font-size: 11px; color: var(--text-faint); margin-top: 6px; }
.hint-item .lvl { font-family: var(--sans); color: var(--accent-2); font-weight: 700; font-size: 12px; }

.review-panel { padding: 18px 20px; }
.review-panel h3 { font-family: var(--serif); margin: 0 0 4px; font-size: 17px; }
.review-panel .sub { font-family: var(--sans); color: var(--text-faint); font-size: 12.5px; margin-bottom: 12px; }
.review-body { font-size: 15px; line-height: 1.6; }
.review-content {
  background: var(--paper); border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent); border-radius: 6px;
  padding: 12px 14px;
}
.review-content h1, .review-content h2, .review-content h3 {
  font-family: var(--sans); font-weight: 700; font-size: 14px; margin: 12px 0 5px;
}
.review-content h1:first-child, .review-content h2:first-child, .review-content h3:first-child,
.review-content p:first-child { margin-top: 0; }
.review-content p { margin: 6px 0; }
.review-content ul, .review-content ol { margin: 6px 0 6px 18px; }
.review-content li { margin: 3px 0; }
.review-loading { font-family: var(--sans); color: var(--text-faint); font-size: 13px; padding: 4px 0; }
.review-src { font-family: var(--sans); font-size: 11px; color: var(--text-faint); margin-top: 8px; }

/* ---------- leaderboard ---------- */
.lb-table { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; max-width: 760px; background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.lb-row {
  display: grid; grid-template-columns: 64px 1fr repeat(4, 74px);
  align-items: center; gap: 10px; padding: 15px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.lb-row:last-child { border-bottom: none; }
.lb-row.head { color: var(--text-faint); font-family: var(--sans); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
.lb-rank { font-family: var(--sans); font-weight: 700; color: var(--text-dim); }
.lb-rank.top { color: var(--accent-2); }
.lb-name { font-family: var(--serif); font-weight: 600; font-size: 17px; }
.lb-solved { text-align: right; color: var(--text-dim); font-family: var(--sans); }
/* Mobile: drop the Easy/Medium/Hard breakdown, keep Rank · User · Solved. */
@media (max-width: 640px) {
  .lb-row { grid-template-columns: 44px 1fr 60px; padding: 14px 14px; gap: 8px; }
  .lb-row > :nth-child(3), .lb-row > :nth-child(4), .lb-row > :nth-child(5) { display: none; }
  .lb-name { font-size: 16px; }
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(28,27,25,0.38);
  display: flex; align-items: center; justify-content: center; z-index: 40;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px; width: 392px; max-width: calc(100vw - 32px);
  padding: 26px; position: relative; box-shadow: var(--shadow);
}
.modal-close { position: absolute; top: 16px; right: 16px; background: transparent; border: none; color: var(--text-dim); font-size: 16px; }
.tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--bg-elev-2); padding: 4px; border-radius: 10px; }
.tab { font-family: var(--sans); flex: 1; background: transparent; border: none; color: var(--text-dim); padding: 8px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.tab.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }
.auth-form .field { margin-bottom: 14px; }
.auth-form label { font-family: var(--sans); display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; font-weight: 500; }
.auth-form input {
  font-family: var(--sans);
  width: 100%; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-error { font-family: var(--sans); color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 6px; }

/* ---------- report an issue ---------- */
/* Muted trigger link under the problem description — quiet until hovered. */
.report-issue {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  color: var(--text-faint); background: transparent; border: none;
  padding: 6px 0; margin-top: 22px; display: inline-flex; align-items: center; gap: 6px;
  transition: color .12s;
}
.report-issue:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.report-modal { width: 440px; }
.report-title { font-family: var(--serif); font-size: 22px; font-weight: 700; margin: 0 0 2px; }
.report-sub { font-family: var(--sans); color: var(--text-dim); font-size: 13.5px; margin: 0 0 18px; }
.report-form label { font-family: var(--sans); display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; font-weight: 500; }
.report-form select,
.report-form textarea {
  font-family: var(--sans); width: 100%; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px;
}
.report-form textarea { resize: vertical; min-height: 92px; line-height: 1.5; }
.report-form select:focus,
.report-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.report-error { font-family: var(--sans); color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.report-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---------- toast ---------- */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 11px;
  padding: 13px 17px; min-width: 250px; box-shadow: var(--shadow);
  animation: slidein 0.2s ease;
}
.toast.success { border-left-color: var(--green); }
.toast .t-title { font-family: var(--sans); font-weight: 700; margin-bottom: 2px; }
.toast .t-body { font-family: var(--sans); color: var(--text-dim); font-size: 13px; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.hidden { display: none !important; }
.center-note { text-align: center; color: var(--text-dim); padding: 60px 20px; }
.loading { color: var(--text-faint); padding: 40px; text-align: center; font-family: var(--sans); }
.progress-bar { height: 7px; background: var(--bg-elev-2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---------- Google button + divider ---------- */
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #1f2328; border-color: #d0d7de; margin-bottom: 14px;
}
.btn-google:hover { background: #f6f8fa; border-color: #d0d7de; }
.or-divider { font-family: var(--sans); display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 12px; margin: 4px 0 18px; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- profile ---------- */
.profile { display: grid; grid-template-columns: 310px 1fr; gap: 22px; align-items: start; }
@media (max-width: 900px) { .profile { grid-template-columns: 1fr; } }
.profile-main { display: flex; flex-direction: column; gap: 22px; }

.id-card { padding: 26px; text-align: center; }
.avatar {
  width: 88px; height: 88px; border-radius: 50%; margin: 0 auto 14px;
  display: grid; place-items: center; font-family: var(--serif); font-size: 38px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow-sm);
}
.id-name { font-family: var(--serif); font-size: 22px; font-weight: 700; }
.id-rank { font-family: var(--sans); margin-top: 14px; color: var(--text-dim); font-size: 14px; }
.id-rank b { color: var(--text); }
.id-solved { font-family: var(--sans); margin-top: 14px; color: var(--text-dim); }
.id-solved .big { font-family: var(--serif); font-size: 30px; font-weight: 700; color: var(--accent); }
.id-since { font-family: var(--sans); margin-top: 18px; font-size: 12.5px; color: var(--text-faint); border-top: 1px solid var(--border-soft); padding-top: 14px; }

.card-title { font-family: var(--serif); font-size: 18px; margin: 0 0 16px; font-weight: 700; }

.overview { padding: 24px 26px; }
.ov-top { display: flex; align-items: center; gap: 30px; flex-wrap: wrap; }
.donut-wrap { position: relative; width: 156px; height: 156px; flex: none; }
.donut { width: 156px; height: 156px; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.donut-num { font-family: var(--serif); font-size: 28px; font-weight: 700; }
.donut-num span { font-size: 15px; color: var(--text-faint); font-weight: 600; }
.donut-sub { font-family: var(--sans); color: var(--green); font-size: 13px; font-weight: 600; margin-top: 2px; }
.diff-boxes { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 160px; }
.diff-box {
  background: var(--paper); border: 1px solid var(--border-soft); border-radius: 8px;
  padding: 10px 15px; display: flex; align-items: center; justify-content: space-between;
}
.diff-box .db-label { font-family: var(--sans); font-weight: 700; font-size: 13px; }
.diff-box.Easy .db-label { color: var(--easy); }
.diff-box.Medium .db-label { color: var(--medium); }
.diff-box.Hard .db-label { color: var(--hard); }
.diff-box .db-val { font-family: var(--mono); font-weight: 700; }
.diff-box .db-val span { color: var(--text-faint); font-weight: 500; }

.stat-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 22px; }
@media (max-width: 560px) { .stat-tiles { grid-template-columns: repeat(2, 1fr); } }
.stat-tile { background: var(--paper); border: 1px solid var(--border-soft); border-radius: 8px; padding: 14px; text-align: center; }
.st-num { font-family: var(--serif); font-size: 22px; font-weight: 700; }
.st-lbl { font-family: var(--sans); font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* Solved-quiz card — mirrors the Solved overview, single accent ring, no split */
.quiz-overview { padding: 24px 26px; }
.quiz-overview .donut-sub { color: var(--accent); }
.quiz-summary { flex: 1; min-width: 160px; }
.qs-num { font-family: var(--serif); font-size: 34px; font-weight: 700; line-height: 1; }
.qs-num span { font-size: 18px; color: var(--text-faint); font-weight: 600; }
.qs-lbl { font-family: var(--sans); font-size: 14px; color: var(--text-dim); margin-top: 8px; max-width: 230px; }

.cat-card { padding: 22px 26px; }
.cat-row { display: grid; grid-template-columns: 160px 1fr 54px; align-items: center; gap: 14px; padding: 7px 0; }
.cat-name { font-family: var(--sans); font-size: 13.5px; color: var(--text-dim); }
.cat-bar { height: 8px; background: var(--bg-elev-2); border-radius: 5px; overflow: hidden; }
.cat-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 5px; }
.cat-count { font-family: var(--mono); font-size: 12.5px; color: var(--text-dim); text-align: right; }

.heat-card { padding: 22px 26px; overflow-x: auto; }
.heat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.heat-meta { font-family: var(--sans); color: var(--text-dim); font-size: 12.5px; }
.hm-grid {
  display: grid; grid-template-rows: repeat(7, 12px); grid-auto-flow: column;
  grid-auto-columns: 12px; gap: 3px; margin: 16px 0 10px; width: max-content;
}
.hm-cell { width: 12px; height: 12px; border-radius: 2px; background: #ebedf0; display: inline-block; }
.hm-cell.l0 { background: #ebedf0; }
.hm-cell.l1 { background: #9be9a8; }
.hm-cell.l2 { background: #40c463; }
.hm-cell.l3 { background: #30a14e; }
.hm-cell.l4 { background: #216e39; }
.heat-legend { font-family: var(--sans); display: flex; align-items: center; gap: 4px; color: var(--text-faint); font-size: 12px; }
.heat-legend .hm-cell { width: 11px; height: 11px; }

.recent-card { padding: 22px 26px; }
.recent-row {
  display: grid; grid-template-columns: 24px 1fr auto auto; align-items: center; gap: 12px;
  padding: 11px 8px; border-radius: 8px; color: var(--text);
}
.recent-row:hover { background: var(--paper); text-decoration: none; }
.rr-title { font-family: var(--serif); font-weight: 600; font-size: 16px; }
.rr-time { font-family: var(--sans); color: var(--text-faint); font-size: 12.5px; }
.empty-note { color: var(--text-dim); }

/* ---------- avatars (Google profile picture) ---------- */
.avatar { position: relative; overflow: hidden; }
.avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.chip-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); display: block; }

/* ---------- full-screen problem-solving layout (LeetCode-style) ---------- */
body.solving #view { max-width: none; margin: 0; padding: 0; height: calc(100vh - 62px); overflow: hidden; }
.solve { display: flex; flex-direction: column; height: 100%; }
.solve-top {
  display: flex; align-items: center; gap: 16px; flex: none;
  padding: 9px 20px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.solve-top .back { margin: 0; }
.solve-top .solve-title { font-family: var(--serif); font-weight: 700; font-size: 15px; color: var(--text-dim); }

/* ‹ › shuffle — in-workspace problem stepper (LeetCode-style) */
.solve-nav { display: inline-flex; align-items: center; gap: 5px; }
.solve-nav .nav-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 29px; height: 29px; padding: 0; border-radius: 7px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-dim);
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.solve-nav .nav-btn svg {
  width: 16px; height: 16px; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.solve-nav .nav-btn:hover { background: var(--bg-elev-2); color: var(--accent); border-color: var(--accent); }
.solve-nav .nav-pos {
  margin-left: 3px; font: 12px var(--sans); color: var(--text-faint);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
@media (max-width: 560px) { .solve-nav .nav-pos { display: none; } }
.solve-split { display: flex; flex: 1; min-height: 0; }
.pd-pane { height: 100%; overflow: auto; }
.pd-left { flex: 0 0 48%; background: var(--bg); }
.pd-right {
  flex: 1; min-width: 0; background: var(--bg);
  padding: 16px 18px 26px; display: flex; flex-direction: column; gap: 14px;
}
.pd-divider {
  flex: none; width: 7px; cursor: col-resize; background: var(--border-soft);
  position: relative; transition: background 0.12s;
}
.pd-divider:hover { background: var(--accent-soft); }
.pd-divider::before {
  content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 2px; height: 34px; background: var(--text-faint); border-radius: 2px; opacity: 0.45;
}
.pd-divider::after { content: ''; position: absolute; top: 0; bottom: 0; left: -4px; right: -4px; } /* wider hit area */
.solving .pd-desc { padding: 26px 30px 40px; }
.solving .editor { max-height: none; }          /* editor grows; the pane scrolls */
.solving .code-workspace .editor-wrap { min-height: calc(100vh - 208px); display: flex; flex-direction: column; }
.solving .code-workspace .editor { flex: 1; min-height: 520px; }
.solving .code-workspace .code-area { min-height: 100%; }
.solving .code-workspace .code-input { min-height: 100%; }
.solving .run-actions { flex: none; }
/* Results/hints must keep their natural height so the pane scrolls to reach every
   test case — otherwise flex-shrink collapses the panel and `.results { overflow:hidden }`
   clips the lower cases, making them unreachable. */
.solving .pd-right .results,
.solving .pd-right .hint-panel,
.solving .pd-right .review-panel { flex: none; }

@media (max-width: 860px) {
  body.solving #view { height: auto; overflow: visible; }
  .solve-split { flex-direction: column; }
  .pd-pane { height: auto; overflow: visible; }
  .pd-left { flex: none; }
  .pd-divider { display: none; }
  .solving .code-workspace .editor-wrap { min-height: 560px; }
}

@media (max-width: 700px) {
  .q-row { grid-template-columns: 32px 1fr 100px; padding: 13px 12px; }
  .q-row > :nth-child(4) { display: none; }
  .random-pick { order: 3; }
  .list-count { order: 4; }
}

/* ---------- problem search + controls ---------- */
.list-controls { display: flex; align-items: center; gap: 14px; margin: 22px 0; flex-wrap: wrap; }
.list-controls .filters { margin: 0; }
.search-wrap { position: relative; display: flex; align-items: center; }
.search-ic { position: absolute; left: 11px; font-size: 12px; opacity: 0.55; pointer-events: none; }
.search-input {
  font-family: var(--sans); font-size: 14px; color: var(--text);
  padding: 8px 14px 8px 32px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-elev); width: 300px; max-width: 60vw; box-shadow: var(--shadow-sm);
}
.search-input::placeholder { color: var(--text-faint); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.list-count { margin-left: auto; font-family: var(--sans); font-size: 13px; color: var(--text-faint); }
.q-empty { padding: 30px 20px; text-align: center; color: var(--text-dim); font-family: var(--sans); }
