:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --good: #059669;
  --bad: #dc2626;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 24px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; color: var(--ink); }
.topbar nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.who { color: var(--muted); font-size: 14px; }
main { max-width: 1240px; margin: 0 auto; padding: 24px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }
h1 { font-size: 24px; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 20px 0 10px; }
h3 { font-size: 16px; margin: 8px 0; }
.muted { color: var(--muted); font-size: 13px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--accent-soft); }
.flash.error { background: #fee2e2; color: #991b1b; }
.flash.ok { background: #d1fae5; color: #065f46; }

.level-tabs { display: flex; gap: 8px; margin: 0 0 14px; }
.level-tabs a { padding: 7px 16px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.level-tabs a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.level-tabs a:hover { text-decoration: none; }
.board-badge { display: inline-block; background: #fef3c7; color: #92400e; border-radius: 4px; padding: 0 4px; font-size: 10px; font-weight: 700; vertical-align: 1px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; background: var(--card); padding: 14px; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 16px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea, button {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
button, .button { cursor: pointer; background: var(--accent-soft); color: var(--accent); border: 1px solid #c7d2fe; padding: 8px 12px; border-radius: 8px; display: inline-block; }
button.primary, .button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:hover, .button:hover { filter: brightness(0.97); text-decoration: none; }

.result-head { display: flex; justify-content: space-between; color: var(--muted); margin: 8px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.cards.compact { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.card-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pick { font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.pill { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.pill.marks { background: #fef3c7; color: #92400e; }
.thumb { display: block; background: #f9fafb; border: 1px solid var(--line); border-radius: 8px; height: 190px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; object-position: top center; background: #fff; }
.noimg { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: #f3f4f6; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.tag.muted { color: var(--muted); }
.open { margin-top: auto; font-size: 14px; }
.export-bar { display: flex; gap: 8px; margin: 16px 0; }
.pager { display: flex; gap: 16px; justify-content: center; margin: 20px 0; }

.auth-card { max-width: 420px; margin: 40px auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.auth-card label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.auth-card input, .auth-card select { width: 100%; margin-top: 4px; }
.auth-card button { width: 100%; }

.detail-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.question-body, .answer, .question-block { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 14px 0; }
img.full { max-width: 100%; display: block; margin: 8px auto; border: 1px solid var(--line); border-radius: 8px; }
.thumb-lg { max-width: 320px; display: block; margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; }
details.answer summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.answer-text { white-space: pre-wrap; line-height: 1.6; padding: 6px 0; }
.answer-key { font-weight: 700; color: var(--accent); }
.question-block h2 { margin-top: 0; }
.answer-form { margin: 10px 0; padding: 10px; background: #fafafa; border-radius: 8px; }
.option { margin-right: 16px; }
.result { font-size: 14px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: #f9fafb; font-size: 13px; color: var(--muted); }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; background: var(--card); padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.topic-check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
.print-item { page-break-after: always; }

/* browse layout */
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.browse-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
.sidebar { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.sidebar h3 { margin: 10px 4px 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.subject-list { display: flex; flex-direction: column; gap: 2px; }
.side-item, .topic-item { display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 7px; color: var(--ink); font-size: 13px; }
.side-item:hover, .topic-item:hover { background: #f3f4f6; text-decoration: none; }
.side-item.active, .topic-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-item em, .topic-item em { font-style: normal; color: var(--muted); font-size: 11px; }
.topic-tree details { margin-bottom: 4px; }
.topic-tree summary { cursor: pointer; padding: 5px 6px; font-size: 13px; color: var(--muted); border-radius: 6px; }
.topic-tree summary:hover { background: #f3f4f6; }
.topic-item { padding-left: 14px; font-size: 12.5px; }
.side-filter { width: 100%; padding: 6px 8px; margin: 0 0 6px; font-size: 12px; }
.grow { flex: 1 1 180px; }
.view-toggle { display: flex; gap: 4px; }
.view-toggle a { padding: 3px 8px; border-radius: 6px; color: var(--muted); }
.view-toggle a.active { background: var(--accent-soft); color: var(--accent); }
.question-table td { vertical-align: middle; }
.question-table td:nth-child(2) { min-width: 260px; }

.assign-meta { display: flex; flex-wrap: wrap; gap: 12px; background: var(--card); border: 1px solid var(--line); padding: 12px; border-radius: 12px; margin-bottom: 12px; }
.assign-meta label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1 1 220px; }
.sticky-submit { position: sticky; bottom: 16px; display: flex; justify-content: flex-end; padding: 10px 0; }
.progress-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 10px 0 16px; }
.progress-text { font-size: 14px; margin-bottom: 8px; }
.progress-bar { height: 8px; background: #eef2ff; border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); }
.svg-page svg { max-width: 100%; height: auto; display: block; margin: 8px auto; background: #fff; }
.text-layer { white-space: pre-wrap; font-size: 12px; color: var(--muted); background: #f9fafb; padding: 12px; border-radius: 8px; }
.correct-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.correct-layout label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.correct-layout textarea { width: 100%; margin-top: 4px; }
@media (max-width: 760px) { .correct-layout { grid-template-columns: 1fr; } }

/* rendered paper */
.paper-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 16px; }
.paper-stack { display: flex; flex-direction: column; gap: 20px; align-items: center; }
.paper-page { width: min(820px, 100%); background: #fff; border: 1px solid #dfe3ea; border-radius: 4px; box-shadow: 0 4px 18px rgba(15, 23, 42, .08); padding: 26px 30px 16px; }
.paper-inner { overflow: hidden; }
.paper-inner svg { width: 100%; height: auto; display: block; }
.paper-page-no { text-align: center; color: #9ca3af; font-size: 11px; margin-top: 10px; }
.answer-inner { border-left: 3px solid #c7d2fe; padding-left: 12px; }
@media (max-width: 600px) { .paper-page { padding: 16px 12px 12px; } }
@media print {
  .paper-page { box-shadow: none; border: none; width: 100%; padding: 0; page-break-after: always; }
  .paper-page-no { display: none; }
}

/* reader: reflowed question typography */
.reader-sheet { width: min(860px, 100%); margin: 0 auto; background: #fff; border: 1px solid #dfe3ea;
                border-radius: 6px; box-shadow: 0 4px 18px rgba(15, 23, 42, .07);
                padding: 34px 46px 40px; font-size: 17px; line-height: 1.72; }
.reader-answers { box-shadow: none; border-left: 3px solid #c7d2fe; margin-top: 4px; }
.reader-sheet .q-para { margin: 12px 0; }
.reader-sheet .q-para p { margin: 0; }
.reader-sheet .q-center { text-align: center; }
.reader-sheet .q-line { display: flex; align-items: baseline; gap: 8px; min-height: 1.75em; }
.reader-sheet .q-line > p { flex: 1; margin: 0; }
.reader-sheet .q-line .mk { color: var(--muted); font-size: 13px; white-space: nowrap; }
.reader-sheet .q-line.mark-only { justify-content: flex-end; min-height: 0; margin: 2px 0 10px; }
.reader-sheet .answer-line { display: flex; align-items: flex-end; flex-wrap: wrap; min-height: 1.6em; }
.reader-sheet .fill { flex: 1; min-width: 60px; border-bottom: 1px dotted #4b5563; margin-left: 6px;
                     transform: translateY(-4px); align-self: flex-end; }
.reader-sheet .rule-line { height: 1.95em; border-bottom: 1px dotted #4b5563; margin: 2px 0; }
.reader-sheet .q-figure { margin: 18px 0; text-align: center; }
.reader-sheet .q-figure svg { max-width: 100%; height: auto; }
.reader-sheet .q-figure.q-page svg { width: 100%; }
.reader-sheet .q-table { border-collapse: collapse; margin: 14px 0; font-size: 16px; }
.reader-sheet .q-table td { border: 1px solid #374151; padding: 5px 14px; vertical-align: top; }
.reader-sheet .q-table td.tick { min-width: 46px; background: #fcfcfd; }
.reader-sheet .q-table tr.hdr td { text-align: center; background: #fbfbfc; }
.reader-sheet .q-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.reader-sheet .q-table td.opt { text-align: center; font-weight: 600; }
.reader-sheet .q-dialogue { border-collapse: collapse; margin: 10px 0 14px; }
.reader-sheet .q-dialogue td { vertical-align: top; padding: 1px 0; line-height: 1.55; }
.reader-sheet .q-dialogue td.spk { width: 92px; padding-right: 16px; white-space: nowrap; }
.reader-sheet .q-code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 14.5px;
                        line-height: 1.62; background: #f8fafc; border: 1px solid #e5e7eb;
                        border-radius: 6px; padding: 12px 16px; margin: 12px 0; white-space: pre-wrap; }
.reader-sheet sup, .reader-sheet sub { font-size: .72em; line-height: 0; }
.reader-sheet .mcq-answer { margin: 6px 0; font-size: 18px; }
.reader-sheet .mcq-answer strong { font-size: 22px; color: var(--accent); }
.reader-answers img.full { max-width: 100%; width: auto; height: auto; margin: 10px auto; }
@media (max-width: 600px) {
  .reader-sheet { padding: 18px 16px 24px; font-size: 16px; }
}
@media print {
  .reader-sheet { width: 100%; border: none; box-shadow: none; padding: 0; }
  .reader-sheet .q-figure.q-page { page-break-after: always; }
}

@media (max-width: 900px) {
  main { padding: 14px; }
  .browse-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .subject-list { flex-direction: row; flex-wrap: wrap; }
  .side-item { flex: 0 0 auto; }
  .topbar { padding: 10px 14px; }
  .topbar nav { gap: 10px; font-size: 13px; }
  .brand { font-size: 16px; }
  h1 { font-size: 20px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .thumb { height: 150px; }
  .filters { padding: 10px; }
  .filters label { flex: 1 1 130px; }
}
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  .topbar nav { justify-content: flex-end; }
  .thumb { height: 190px; }
  .detail-head h1 { font-size: 18px; }
  .table { display: block; overflow-x: auto; }
}

@media print {
  .topbar, footer, .button, button { display: none; }
  main { max-width: none; padding: 0; }
}

/* sidebar board groups */
.board-group { margin: 0 0 2px; }
.board-group > summary { cursor: pointer; padding: 6px 8px; font-size: 13px; color: var(--muted); border-radius: 7px; display: flex; justify-content: space-between; align-items: center; }
.board-group > summary:hover { background: #f3f4f6; }
.board-group > summary em { font-style: normal; font-size: 11px; }
.board-group .side-item { padding-left: 16px; }
