/* ============================================================
   FuncQBank — "printed mathematics textbook / exam booklet"
   Warm parchment · serif typography · fountain-pen blue · red-pen accents
   ============================================================ */

:root {
  --font-display: "Fraunces", "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
  --font-serif: "Newsreader", "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;

  --paper: #f1eadb;             /* page background, warm parchment */
  --paper-2: #e9dfcb;
  --sheet: #fcf9f2;             /* card / question sheet */
  --sheet-edge: #fffdf8;

  --ink: #221f25;               /* primary text, warm near-black */
  --ink-2: #5b5349;
  --ink-3: #8d8273;
  --line: #ddd0b8;              /* hairline rules */
  --line-2: #c9b99c;

  --blue: #2a3d86;              /* fountain-pen blue — primary */
  --blue-deep: #1e2c63;
  --blue-soft: #e6e8f3;
  --green: #2c7a4f;
  --green-soft: #e0ecdf;
  --red: #ad3528;               /* grading-pen red */
  --red-soft: #f2e1dc;
  --gold: #a9781f;
  --gold-soft: #f0e6cf;

  --radius: 10px;
  --radius-sm: 7px;
  --surface-hi: #fff;            /* hover-raised surface (light: pure white) */
  --on-primary: #fbf8f1;         /* text on the blue primary button */
  --shadow-sm: 0 1px 2px rgba(60, 45, 15, .05);
  --shadow: 0 1px 2px rgba(60, 45, 15, .05), 0 14px 34px -18px rgba(60, 45, 15, .30);
  --shadow-lg: 0 2px 4px rgba(60, 45, 15, .06), 0 30px 60px -28px rgba(60, 45, 15, .40);
  --maxw: 880px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }

html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }

html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #161412;
  --paper-2: #1f1b17;
  --sheet: #211d1a;
  --sheet-edge: #2a2521;
  --ink: #f2e9dc;
  --ink-2: #d2c4b2;
  --ink-3: #a89682;
  --line: #4b4036;
  --line-2: #66584b;
  --blue: #8aa4ff;
  --blue-deep: #b7c3ff;
  --blue-soft: #27314f;
  --green: #6cc08b;
  --green-soft: #20382b;
  --red: #f08b7c;
  --red-soft: #3a2320;
  --gold: #e1b96d;
  --gold-soft: #3a2d16;
  --surface-hi: #322c27;         /* hover-raised surface stays dark, just lighter than the card */
  --on-primary: #15131a;         /* dark text on the lightened blue primary button */
}

html[data-theme="dark"] body::before { opacity: .16; mix-blend-mode: screen; }
html[data-theme="dark"] body {
  background-image:
    radial-gradient(120% 90% at 50% -10%, #211d1a 0%, rgba(33, 29, 26, 0) 55%),
    linear-gradient(0deg, var(--paper-2), var(--paper));
}
html[data-theme="dark"] .stem strong { box-shadow: none; text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: .15em; }
/* 暗色下选项序号底色变浅，白字会糊；强制用深色文字保证对比 */
html[data-theme="dark"] .option.selected .lab,
html[data-theme="dark"] .option.correct .lab,
html[data-theme="dark"] .option.wrong .lab { color: #15131a; }

body {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.7;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(120% 90% at 50% -10%, #f7f1e5 0%, rgba(247, 241, 229, 0) 55%),
    linear-gradient(0deg, var(--paper-2), var(--paper));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* subtle paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-deep); }

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }

/* ---------- layout ---------- */
.wrap { position: relative; z-index: 1; max-width: var(--maxw); margin: 0 auto; padding: 0 22px; }
.wrap.wide { max-width: 1240px; }
.page { padding: 30px 0 90px; }
.muted { color: var(--ink-3); }
.sans { font-family: var(--font-sans); }

/* ---------- top bar ---------- */
.topbar {
  position: relative; z-index: 5;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--sheet), color-mix(in srgb, var(--sheet) 88%, var(--paper)));
  box-shadow: var(--shadow-sm);
}
.topbar .wrap { display: flex; align-items: center; gap: 18px; height: 64px; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 1.34rem; letter-spacing: -.02em; color: var(--ink); display: flex; align-items: center; gap: .5rem; }
.brand .glyph { color: var(--blue); font-style: italic; }
.brand .glyph::after { content: "∫"; }
.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; font-family: var(--font-sans); font-size: .95rem; }
.nav-scroll { display: flex; align-items: center; gap: 4px; }
.nav a, .nav form button, .theme-toggle {
  padding: 7px 13px; border-radius: 8px; color: var(--ink-2);
  font-family: var(--font-sans); font-size: .92rem; line-height: 1;
}
.nav a:hover { background: var(--paper-2); color: var(--ink); }
.nav a.active { color: var(--blue); background: var(--blue-soft); }

/* ---------- user dropdown ---------- */
.usermenu { position: relative; }
.usermenu .who {
  display: inline-flex; align-items: center; gap: .4em;
  padding: 7px 11px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--ink-2); cursor: pointer;
  font-family: var(--font-sans); font-size: .92rem; line-height: 1;
}
.usermenu .who:hover { background: var(--paper-2); color: var(--ink); }
.usermenu .caret { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; transition: transform .15s ease; }
.usermenu.open .who { background: var(--paper-2); color: var(--ink); }
.usermenu.open .caret { transform: rotate(180deg); }
.usermenu-pop {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 150px;
  background: var(--sheet); border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 5px; z-index: 20;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s;
}
.usermenu.open .usermenu-pop { opacity: 1; visibility: visible; transform: none; }
.usermenu-pop form { margin: 0; }
.usermenu-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border: none; border-radius: 6px; background: transparent;
  color: var(--ink); cursor: pointer; font-family: var(--font-sans); font-size: .9rem; line-height: 1.2;
}
.usermenu-item:hover { background: var(--red-soft); color: var(--red); }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--sheet-edge); color: var(--ink-2); cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.theme-toggle:hover { background: var(--paper-2); color: var(--ink); border-color: var(--ink-3); }
.theme-toggle svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.theme-toggle[data-mode="light"] svg circle { fill: currentColor; stroke: none; }
.theme-toggle[data-mode="dark"] svg path { fill: currentColor; stroke: none; }
.theme-toggle[data-mode="system"] svg path { fill: currentColor; stroke: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  font-family: var(--font-sans); font-size: .95rem; font-weight: 500; line-height: 1;
  padding: 11px 18px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--sheet); color: var(--ink); cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  box-shadow: var(--shadow-sm); text-align: center;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); border-color: var(--blue-deep); color: var(--on-primary); box-shadow: 0 1px 0 var(--blue-deep), 0 10px 22px -12px rgba(42, 61, 134, .8); }
.btn-primary:hover { background: var(--blue-deep); color: var(--on-primary); }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, var(--line-2)); }
.btn-danger:hover { background: var(--red-soft); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--paper-2); }
.btn-sm { padding: 7px 12px; font-size: .87rem; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .35em;
  font-family: var(--font-sans); font-size: .76rem; font-weight: 600; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-2);
  color: var(--ink-2); background: var(--paper); white-space: nowrap;
}
.badge.single { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 30%, var(--line)); background: var(--blue-soft); }
.badge.multiple { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 30%, var(--line)); background: var(--gold-soft); }
.badge.judge { color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, var(--line)); background: var(--green-soft); }
.badge.flagged { color: var(--red); background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 30%, var(--line)); }
.badge.pending { color: var(--ink-2); }
.badge.verified { color: var(--green); background: var(--green-soft); }

/* ---------- sheet / card ---------- */
.sheet {
  background: linear-gradient(180deg, var(--sheet-edge), var(--sheet));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 26px 30px;
}

/* ---------- home ---------- */
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 8px; }
.hero h1 { font-size: 2.3rem; margin: 0; }
.hero .lead { color: var(--ink-2); font-size: 1.02rem; }
.stat-strip { display: flex; gap: 26px; font-family: var(--font-sans); }
.stat .n { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; line-height: 1; }
.stat .k { font-size: .8rem; color: var(--ink-3); letter-spacing: .03em; }
.stat .n.blue { color: var(--blue); } .stat .n.red { color: var(--red); }

.quick { display: flex; gap: 12px; flex-wrap: wrap; margin: 22px 0 34px; }

.chapter { margin: 34px 0; }
.chapter > h2 {
  font-size: 1.05rem; font-family: var(--font-sans); font-weight: 700; letter-spacing: .04em;
  color: var(--ink-3); text-transform: none; display: flex; align-items: center; gap: 12px;
}
.chapter > h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.sec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 14px; margin-top: 14px; }
.sec-card {
  display: block; background: linear-gradient(180deg, var(--sheet-edge), var(--sheet));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 17px 18px 15px;
  box-shadow: var(--shadow-sm); transition: transform .12s ease, box-shadow .18s ease, border-color .15s ease;
  position: relative; overflow: hidden;
}
.sec-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--blue); opacity: .0; transition: opacity .15s; }
.sec-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line-2); }
.sec-card:hover::before { opacity: .85; }
.sec-card .code { font-family: var(--font-display); font-size: 1.45rem; font-weight: 600; color: var(--ink); }
.sec-card .name { color: var(--ink); font-size: 1.05rem; margin-top: 1px; }
.sec-card .row { display: flex; align-items: center; justify-content: space-between; }
.sec-card .meta { display: flex; gap: 10px; align-items: center; font-family: var(--font-sans); font-size: .8rem; color: var(--ink-3); margin-top: 12px; }
.sec-card .wrongtag { color: var(--red); }
.bar { height: 5px; border-radius: 4px; background: var(--paper-2); overflow: hidden; margin-top: 10px; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), color-mix(in srgb, var(--blue) 60%, var(--green))); }

/* ---------- practice ---------- */
.practice-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.practice-head .title { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; }
.practice-head .sub { color: var(--ink-3); font-family: var(--font-sans); font-size: .9rem; }
.toolbar { display: flex; gap: 8px; align-items: center; font-family: var(--font-sans); }

.practice-tools { display: flex; justify-content: flex-start; margin: -4px 0 12px; }
.progress-line { display: flex; align-items: center; gap: 12px; font-family: var(--font-sans); font-size: .85rem; color: var(--ink-3); margin-bottom: 16px; }
.progress-line .bar { flex: 1; margin: 0; }
.progress-line .progress-main { color: var(--blue); font-weight: 700; white-space: nowrap; }
.progress-line .pos { white-space: nowrap; }
.progress-line .wrongcount { color: var(--ink-3); white-space: nowrap; }
.progress-line .wrongcount.has { color: var(--red); font-weight: 600; }

.qsheet { position: relative; }
.qmeta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; font-family: var(--font-sans); }
.qmeta .num { font-family: var(--font-display); font-size: 1.05rem; color: var(--ink-3); font-weight: 600; }
.qmeta .points { font-size: .8rem; color: var(--ink-3); }
.master-progress {
  margin-left: auto; padding: 5px 10px; border-radius: 999px;
  background: var(--gold-soft); color: var(--gold); font-size: .78rem; font-weight: 700;
}
.master-progress.done { background: var(--green-soft); color: var(--green); }
.btn-mastered {
  color: var(--red); background: var(--sheet-edge);
  border-color: color-mix(in srgb, var(--red) 45%, var(--line-2));
  box-shadow: var(--shadow-sm);
}
.btn-mastered:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }

.stem { font-size: 1.22rem; line-height: 1.75; margin-bottom: 22px; }
.stem strong { font-weight: 700; color: var(--red); box-shadow: inset 0 -.5em 0 var(--red-soft); }

.options { display: flex; flex-direction: column; gap: 11px; }
.option {
  display: flex; gap: 14px; align-items: flex-start; padding: 13px 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--sheet-edge);
  cursor: pointer; transition: border-color .12s, background .12s, box-shadow .12s; user-select: none;
}
.option:hover { border-color: var(--line-2); background: var(--surface-hi); }
.option .lab {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line-2);
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; font-size: .95rem;
  color: var(--ink-2); background: var(--paper); transition: all .12s;
}
.option .otext { flex: 1; }
/* 多选用圆角矩形序号、单选用圆形序号，呼应「可多选 / 仅单选」的认知 */
.options.multiple .option .lab { border-radius: var(--radius-sm); }
.option.selected { border-color: var(--blue); background: var(--blue-soft); }
.option.selected .lab { background: var(--blue); color: #fff; border-color: var(--blue); }
.option.correct { border-color: var(--green); background: var(--green-soft); }
.option.correct .lab { background: var(--green); color: #fff; border-color: var(--green); }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option.wrong .lab { background: var(--red); color: #fff; border-color: var(--red); }
.option .mark { font-family: var(--font-sans); font-weight: 700; align-self: center; }
.option.correct .mark { color: var(--green); } .option.wrong .mark { color: var(--red); }
.revealed .option { cursor: default; }

/* judge buttons */
.judge { display: flex; gap: 16px; }
.judge button {
  flex: 1; padding: 22px; border-radius: var(--radius); border: 1.5px solid var(--line-2);
  background: var(--sheet-edge); cursor: pointer; font-family: var(--font-display); font-size: 1.3rem; color: var(--ink);
  display: flex; align-items: center; justify-content: center; gap: 10px; transition: all .12s;
}
.judge button .ic { font-size: 1.5rem; }
.judge button[data-v="正确"] .ic { color: var(--green); }
.judge button[data-v="错误"] .ic { color: var(--red); }
.judge button:hover { border-color: var(--ink-3); transform: translateY(-1px); }
.judge button.selected { border-color: var(--blue); background: var(--blue-soft); }
.judge button.correct { border-color: var(--green); background: var(--green-soft); }
.judge button.wrong { border-color: var(--red); background: var(--red-soft); }

/* reveal area */
.actions { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; align-items: center; }
.reveal {
  margin-top: 22px; border-top: 1px dashed var(--line-2); padding-top: 20px;
  animation: rise .25s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.verdict { font-family: var(--font-sans); font-weight: 700; display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px; font-size: .9rem; }
.verdict.ok { color: var(--green); background: var(--green-soft); }
.verdict.no { color: var(--red); background: var(--red-soft); }
.answer-line { font-family: var(--font-sans); margin-top: 14px; font-size: 1rem; }
.answer-line b { font-family: var(--font-display); font-size: 1.15rem; color: var(--blue); letter-spacing: .05em; }
.explanation { margin-top: 14px; padding: 14px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.explanation .h { font-family: var(--font-sans); font-size: .78rem; font-weight: 700; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 6px; }

/* bottom navigation + answer card grid */
.qnav { display: flex; align-items: center; justify-content: space-between; margin-top: 26px; gap: 12px; font-family: var(--font-sans); }
.gridnav {
  margin-top: 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 8px;
  padding: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
.gridnav.hidden { display: none; }
.gridnav button {
  aspect-ratio: 1; border-radius: 7px; border: 1px solid var(--line-2); background: var(--sheet-edge);
  font-family: var(--font-sans); font-size: .82rem; color: var(--ink-2); cursor: pointer; transition: all .1s;
}
.gridnav button:hover { border-color: var(--ink-3); }
.gridnav button.correct { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.gridnav button.wrong { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.gridnav button.seen { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 40%, var(--line)); }
.gridnav button.cur { outline: 2px solid var(--blue); outline-offset: 1px; font-weight: 700; color: var(--ink); }

/* ---------- forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-family: var(--font-sans); font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], input[type=search], textarea, select {
  width: 100%; font-family: var(--font-serif); font-size: 1rem; color: var(--ink);
  padding: 11px 13px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--sheet-edge); transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
textarea { resize: vertical; line-height: 1.6; }
.hint { font-family: var(--font-sans); font-size: .78rem; color: var(--ink-3); margin-top: 5px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 30px 18px; }
.auth-card { width: 100%; max-width: 410px; }
.auth-card .brand { font-size: 1.8rem; justify-content: center; margin-bottom: 4px; }
.auth-card .tag { text-align: center; color: var(--ink-3); font-family: var(--font-sans); font-size: .9rem; margin-bottom: 24px; }
.alert { font-family: var(--font-sans); font-size: .9rem; padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; }
.alert.err { background: var(--red-soft); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 30%, var(--line)); }
.alert.info { background: var(--blue-soft); color: var(--blue-deep); border: 1px solid color-mix(in srgb, var(--blue) 25%, var(--line)); }

/* ---------- admin ---------- */
.adminbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-family: var(--font-sans); margin-bottom: 18px; }
.filterpill { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--sheet); color: var(--ink-2); font-size: .85rem; cursor: pointer; }
.filterpill.on { background: var(--ink); color: var(--sheet); border-color: var(--ink); }
.filterpill.on.flag { background: var(--red); border-color: var(--red); color: #fff; }

.qlist { display: flex; flex-direction: column; gap: 10px; }
.qrow {
  display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; background: var(--sheet);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); transition: border-color .12s;
}
.qrow:hover { border-color: var(--line-2); }
.qrow .body { flex: 1; min-width: 0; }
.qrow .stem-snip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--ink); }
.qrow .sub { font-family: var(--font-sans); font-size: .78rem; color: var(--ink-3); margin-top: 5px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.edit-grid { display: grid; grid-template-columns: minmax(220px, 0.82fr) minmax(300px, 1fr) minmax(320px, 1.04fr); gap: 22px; align-items: start; }
.pane-label { font-family: var(--font-sans); font-size: .76rem; font-weight: 700; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 8px; }
.imgpane { position: sticky; top: 18px; }
.imgpane img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); background: #fff; }
.qpreview-pane { position: sticky; top: 18px; }
.qpreview { padding: 20px 22px; }
.qpreview .stem { font-size: 1.08rem; margin-bottom: 16px; }
.qpreview .options { gap: 8px; }
.qpreview .option { padding: 9px 12px; cursor: default; }
.qpreview .reveal { margin-top: 16px; }
.search-form { display: flex; gap: 10px; margin-bottom: 22px; flex-wrap: wrap; }
.search-form input[type=search] { flex: 1; min-width: 220px; }
.search-form select { width: auto; }
.opt-editor { display: flex; flex-direction: column; gap: 8px; }
.opt-editor .opt-row { display: flex; gap: 8px; align-items: center; }
.opt-editor .opt-row input.lab { width: 56px; text-align: center; font-family: var(--font-display); }
.preview-box { margin-top: 8px; padding: 14px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); min-height: 40px; }
.raw-dump { font-family: ui-monospace, monospace; font-size: .78rem; white-space: pre-wrap; word-break: break-word; color: var(--ink-2); max-height: 240px; overflow: auto; background: var(--paper); padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); }
details summary { cursor: pointer; font-family: var(--font-sans); font-size: .85rem; color: var(--ink-3); }

.table { width: 100%; border-collapse: collapse; font-family: var(--font-sans); font-size: .92rem; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.table th { color: var(--ink-3); font-size: .8rem; font-weight: 700; letter-spacing: .03em; }

.flaglist { font-family: var(--font-sans); font-size: .82rem; color: var(--red); margin: 0; padding-left: 18px; }

.errpage { min-height: 60vh; display: grid; place-items: center; text-align: center; }
.errpage .code { font-family: var(--font-display); font-size: 5rem; color: var(--line-2); line-height: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .edit-grid { grid-template-columns: 1fr; }
  .imgpane, .qpreview-pane { position: static; }
  .imgpane img { max-width: 460px; }
}
@media (max-width: 760px) {
  body { font-size: 17px; }
  .wrap { padding: 0 18px; }
  .wrap.wide { padding: 0 14px; }
  .page { padding: 20px 0 74px; }
  .sheet { padding: 22px 20px; border-radius: 14px; }
  .imgpane { position: static; }

  .topbar { position: sticky; top: 0; }
  .topbar .wrap {
    height: auto; padding-top: 8px; padding-bottom: 9px;
    align-items: stretch; gap: 8px; flex-direction: column;
  }
  .brand {
    min-width: 0; width: fit-content; max-width: 100%;
    font-size: 1.12rem; gap: .42rem; white-space: nowrap;
  }
  .brand .glyph::after { font-size: 1.35rem; line-height: 1; }
  .nav {
    width: 100%; margin: 0; gap: 8px; justify-content: space-between;
    overflow: visible;
  }
  .nav-scroll {
    min-width: 0; flex: 1; display: flex; align-items: center; gap: 6px;
    overflow-x: auto; overscroll-behavior-x: contain;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .nav-scroll::-webkit-scrollbar { display: none; }
  .nav a, .theme-toggle, .usermenu { flex: 0 0 auto; }
  .nav a, .nav form button, .theme-toggle, .usermenu .who {
    min-height: 38px; padding: 9px 12px; border-radius: 11px;
    font-size: .9rem; white-space: nowrap;
  }
  .theme-toggle { width: 38px; }
  .usermenu .who { max-width: 128px; background: color-mix(in srgb, var(--paper-2) 56%, transparent); }
  .usermenu .who { overflow: hidden; text-overflow: ellipsis; }
  .usermenu-pop { right: 8px; }

  .hero { gap: 14px; margin-bottom: 4px; }
  .hero h1 { font-size: 2rem; line-height: 1.12; }
  .hero .lead { font-size: .96rem; line-height: 1.55; }
  .stat-strip { width: 100%; gap: 0; justify-content: space-between; padding-right: 10px; }
  .quick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 18px 0 28px; }
  .quick .btn { width: 100%; min-height: 48px; padding: 12px 10px; }
  .chapter { margin: 28px 0; }
  .chapter > h2 { font-size: .98rem; gap: 10px; }
  .sec-grid { grid-template-columns: 1fr; gap: 14px; }
  .sec-card { padding: 20px 20px 18px; border-radius: 16px; }

  .practice-head { gap: 8px; margin-bottom: 14px; }
  .practice-head .title { font-size: 1.58rem; line-height: 1.18; }
  .practice-head .sub { font-size: .86rem; line-height: 1.5; }
  .practice-tools { margin: 0 0 14px; }
  .progress-line {
    display: grid; grid-template-columns: auto minmax(72px, 1fr) auto;
    gap: 8px 10px; align-items: center; margin-bottom: 14px;
  }
  .progress-line .bar { min-width: 72px; }
  .progress-line .wrongcount { grid-column: 1 / 2; }
  .progress-line #btn-grid {
    grid-column: 3 / 4; grid-row: auto; align-self: center;
    min-height: 34px; padding: 8px 12px; border-radius: 10px;
  }

  .qsheet { padding: 24px 22px; }
  .qmeta { gap: 8px; margin-bottom: 18px; }
  .qmeta .num { width: 100%; font-size: .98rem; }
  .master-progress { margin-left: 0; }
  .stem { font-size: 1.13rem; line-height: 1.72; margin-bottom: 20px; }
  .options { gap: 12px; }
  .option { gap: 12px; padding: 15px 14px; border-radius: 12px; }
  .option .lab { width: 32px; height: 32px; }
  .actions { gap: 10px; margin-top: 22px; }
  .actions .btn { min-height: 44px; }
  .judge { gap: 12px; }
  .judge button { padding: 18px 12px; }
  .gridnav { margin-top: 18px; padding: 14px; gap: 7px; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); }
  .qnav { margin-top: 22px; align-items: stretch; }
  .qnav .btn { min-width: 104px; min-height: 56px; white-space: normal; }
  #kbd-hint { flex: 1; text-align: center; line-height: 1.45; align-self: center; }

  .search-form { display: grid; grid-template-columns: 1fr; gap: 10px; }
  .search-form input[type=search], .search-form select { min-width: 0; width: 100%; }
  .opt-editor .opt-row { display: grid; grid-template-columns: 54px minmax(0, 1fr) 44px; gap: 8px; }
}

@media (max-width: 420px) {
  .wrap { padding: 0 14px; }
  .page { padding-top: 18px; }
  .sheet { padding: 20px 16px; }
  .quick { grid-template-columns: 1fr; }
  .quick .btn { justify-content: center; }
  .stat .n { font-size: 1.52rem; }
  .stat .k { font-size: .76rem; }
  .qsheet { padding: 22px 18px; }
  .progress-line { grid-template-columns: 1fr auto; }
  .progress-line .bar { grid-column: 1 / -1; grid-row: 2; }
  .progress-line .wrongcount { grid-column: 1 / 2; grid-row: 3; }
  .progress-line #btn-grid { grid-column: 2 / 3; grid-row: 1; }
  .progress-line .pos { grid-column: 1 / 2; }
  .qnav .btn { min-width: 92px; padding-inline: 12px; }
}
