:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c1f24;
  --muted: #5d6673;
  --border: #dde1e7;
  --accent: #2f5bd3;
  --accent-soft: #e6ecfb;
  --ok: #1d7a46;
  --ok-soft: #e3f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --code-bg: #eef1f5;
  --heat-1: #f6d3cf;
  --heat-2: #e9988f;
  --heat-3: #c9473d;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --surface: #1d2025;
    --surface-2: #262a31;
    --text: #e6e8eb;
    --muted: #9aa3ae;
    --border: #343941;
    --accent: #7aa2ff;
    --accent-soft: #24304d;
    --ok: #5fcf8e;
    --ok-soft: #173826;
    --bad: #ff8a80;
    --bad-soft: #43201e;
    --warn: #f0c060;
    --warn-soft: #3a2f12;
    --code-bg: #262a31;
    --heat-1: #4a2724;
    --heat-2: #8a3a33;
    --heat-3: #d4574b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1d2025;
  --surface-2: #262a31;
  --text: #e6e8eb;
  --muted: #9aa3ae;
  --border: #343941;
  --accent: #7aa2ff;
  --accent-soft: #24304d;
  --ok: #5fcf8e;
  --ok-soft: #173826;
  --bad: #ff8a80;
  --bad-soft: #43201e;
  --warn: #f0c060;
  --warn-soft: #3a2f12;
  --code-bg: #262a31;
  --heat-1: #4a2724;
  --heat-2: #8a3a33;
  --heat-3: #d4574b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
a { color: var(--accent); }
button, select, input, textarea { font: inherit; color: inherit; }
code, pre { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; }
pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; white-space: pre; margin: 8px 0; }
pre code { background: none; padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* 상단 막대 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px max(16px, calc((100% - 860px) / 2));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.sync { font-size: 0.75rem; color: var(--muted); }
.sync.busy { color: var(--accent); }
.sync.error { color: var(--bad); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.stats .big { font-size: 1.6rem; font-weight: 700; }
.rowbtns { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
td.rowbtns { display: table-cell; text-align: right; white-space: normal !important; min-width: 120px; }
td.rowbtns > * { margin: 2px 0 2px 4px; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.tablewrap + .tablewrap { margin-top: 12px; }
.bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; justify-content: flex-end; }
.progress { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 160px; }
.progress .track { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress .fill { height: 100%; background: var(--accent); transition: width .2s; }

main { max-width: 860px; margin: 0 auto; padding: 20px 16px 80px; }
h1 { font-size: 1.5rem; margin: 8px 0 4px; }
h2 { font-size: 1.15rem; margin: 32px 0 12px; }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; text-decoration: none; color: var(--text); display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #10131a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #10131a; } }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 3px 10px; font-size: 0.875rem; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }

/* 홈 */
.weeks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.week h3, .examcard h3 { margin: 0 0 8px; font-size: 1rem; }
.examcard { display: block; text-decoration: none; color: var(--text); }
.examcard:hover { border-color: var(--accent); }
.inprogress { color: var(--accent); margin-top: 4px; font-weight: 600; }
.inprogress-card { border-color: var(--accent); background: var(--accent-soft); margin-top: 16px; }
.setlink { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; margin: 0 -10px; border-radius: 8px; text-decoration: none; color: var(--text); }
.setlink:hover { background: var(--surface-2); }
.tag { font-size: 0.75rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.variant { background: var(--accent-soft); color: var(--accent); }
.tag.exam { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.tag.mark-unsure { background: var(--warn-soft); color: var(--warn); }
.tag.mark-guess { background: var(--bad-soft); color: var(--bad); }
.form-row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 10px 0; }
.form-row > .label { width: 90px; color: var(--muted); font-size: 0.9rem; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 3px 12px; cursor: pointer; user-select: none; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.chip:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.chip input { margin: 0; }
select { border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; background: var(--surface); }
.errors { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }

/* 시험 회차 기록 */
.tablewrap { padding: 0; overflow-x: auto; }
table.hist { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.hist th, .hist td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.hist td.small { white-space: normal; min-width: 140px; }
.hist th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.hist tr:last-child td { border-bottom: 0; }
.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 4px; }
.cell, .navcell {
  position: relative; display: grid; place-items: center; height: 34px; border-radius: 6px;
  font-size: 0.8rem; text-decoration: none; color: var(--text);
  border: 1px solid var(--border); background: var(--surface);
}
.cell.unseen { color: var(--muted); border-style: dashed; }
.cell.w0:not(.unseen) { background: var(--ok-soft); border-color: transparent; }
.cell.w1 { background: var(--heat-1); border-color: transparent; }
.cell.w2 { background: var(--heat-2); border-color: transparent; }
.cell.w3 { background: var(--heat-3); border-color: transparent; color: #fff; }
.cell:hover, .navcell:hover { outline: 2px solid var(--accent); }
.dot { position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; }
.dot.unsure { background: var(--warn); }
.dot.guess { background: var(--bad); }
.navcard h2 { margin-top: 0; }
.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 4px; }
.navcell.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* 오답·체크 목록 */
.qlist { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 6px; }
.qrow { display: flex; gap: 8px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.qrow > a { flex: 1; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; text-decoration: none; color: var(--text); min-width: 0; }
.qrow:hover { border-color: var(--accent); }
.qrow .snip { flex-basis: 100%; font-size: 0.92rem; }

/* 문항 */
.q { margin: 16px 0; }
.q.is-ok { border-left: 4px solid var(--ok); }
.q.is-wrong { border-left: 4px solid var(--bad); }
.only-wrong .q.is-ok { display: none; }
.q-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.q-num { font-weight: 700; }
.stars { color: var(--warn); font-size: 0.85rem; letter-spacing: 1px; }
.marks { margin-left: auto; display: inline-flex; gap: 4px; }
.mark {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 1px 10px; font-size: 0.8rem; cursor: pointer;
}
.mark:hover { border-color: var(--warn); }
.mark-unsure[aria-pressed="true"] { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); font-weight: 600; }
.mark-guess[aria-pressed="true"] { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); font-weight: 600; }
.stem { white-space: pre-wrap; margin: 4px 0 12px; font-weight: 500; }
.stem.md, .md { white-space: normal; }
.stem.md p, .md p { margin: 0 0 8px; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 1.4em; }
.md blockquote, .verdict blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--warn); background: var(--warn-soft); border-radius: 0 6px 6px 0; font-size: 0.92rem; }
.opts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.opt {
  width: 100%; text-align: left; display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: var(--surface); cursor: pointer; white-space: pre-wrap;
}
.opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.opt:disabled { cursor: default; }
.opt .n { flex: none; width: 1.6em; height: 1.6em; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 0.85rem; font-weight: 600; margin-top: 1px; }
.opt .t { flex: 1; }
.opt.picked { border-color: var(--accent); background: var(--accent-soft); }
.opt.picked .n { background: var(--accent); color: var(--surface); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .n { background: var(--ok); color: var(--surface); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .n { background: var(--bad); color: var(--surface); }
.badge { flex: none; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; margin-top: 2px; }
.badge.right { background: var(--ok); color: var(--surface); }
.badge.mine { background: var(--bad); color: var(--surface); }
.note { margin: 4px 2px 0 40px; font-size: 0.92rem; color: var(--muted); white-space: pre-wrap; }
.note b { color: var(--text); font-weight: 600; }
textarea.written {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: var(--surface); font-family: var(--mono); font-size: 0.92rem; resize: vertical;
}
textarea.written:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea.written[readonly] { background: var(--surface-2); }

.verdict { margin-top: 14px; padding: 12px 14px; border-radius: 8px; }
.verdict.ok { background: var(--ok-soft); }
.verdict.no { background: var(--bad-soft); }
.verdict.skip, .verdict.solution { background: var(--surface-2); }
.verdict .title { font-weight: 700; margin-bottom: 4px; }
.verdict.ok .title { color: var(--ok); }
.verdict.no .title { color: var(--bad); }
.verdict > p { margin: 4px 0; white-space: pre-wrap; }
.selfgrade { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.flag { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 0.92rem; }
details { margin-top: 8px; font-size: 0.92rem; }
details summary { cursor: pointer; color: var(--muted); }
details p { margin: 6px 0; }
details > p { white-space: pre-wrap; }
details.more .md { margin-top: 6px; }
.refs { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }

.summary { margin: 16px 0; }
.summary h2 { margin-top: 0; }
.summary > p { margin: 10px 0 4px; }
.score { font-size: 2rem; font-weight: 700; }
.wronglist { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
dialog.choose {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px; width: min(420px, calc(100vw - 32px));
}
dialog.choose::backdrop { background: rgb(0 0 0 / .45); }
dialog.choose h2 { margin: 0 0 6px; }
.choose-btns { display: grid; gap: 8px; margin-top: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

@media (max-width: 560px) {
  .form-row > .label { width: 100%; }
  .note { margin-left: 4px; }
  .marks { margin-left: 0; }
}
