:root {
  --paper: #fcfbf9;
  --paper-2: #f4f1ec;
  --ink: #22262e;
  --ink-2: #4a505b;
  --muted: #6b7180;
  --line: #e3ded6;
  --accent: #fb6b00;
  --accent-ink: #b84d00;
  --accent-soft: #fff1e5;
  --ok: #1f7a4a;
  --ok-soft: #e7f4ec;
  --bad: #b3261e;
  --bad-soft: #fbeaea;
  --warn: #8a5a00;
  --warn-soft: #fff6dd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(34, 38, 46, .06), 0 8px 24px rgba(34, 38, 46, .06);
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 110% -10%, rgba(251, 107, 0, .07), transparent 60%),
    linear-gradient(var(--paper), var(--paper));
  min-height: 100vh;
}
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background-image: linear-gradient(rgba(34, 38, 46, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(34, 38, 46, .035) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, black, transparent 70%);
}

a { color: var(--accent-ink); }
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(252, 251, 249, .85);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.topbar img { height: 34px; width: auto; display: block; }
.topbar .tag { font-family: var(--mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); text-align: right; }

.wrap { max-width: 760px; margin: 0 auto; padding: clamp(20px, 5vw, 48px) 16px 96px; }
.wrap.wide { max-width: 1180px; }

.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink); margin: 0 0 10px; }
h1 { font-size: clamp(28px, 5vw, 42px); line-height: 1.12; letter-spacing: -.02em; margin: 0 0 14px; font-weight: 700; }
h2 { font-size: 22px; line-height: 1.25; margin: 0 0 12px; letter-spacing: -.01em; }
h3 { font-size: 16px; margin: 0 0 8px; }
.lead { font-size: 18px; color: var(--ink-2); margin: 0 0 24px; max-width: 60ch; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 28px; padding: 0; list-style: none; }
.chips li { font-family: var(--mono); font-size: 13px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: #fff; }

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(18px, 3vw, 28px); }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 15px; }
.field input {
  font-size: 17px; padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); outline: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 10px; border: 1.5px solid var(--ink);
  background: var(--ink); color: #fff; font-weight: 600; cursor: pointer;
  transition: transform .08s, background .15s, box-shadow .15s;
}
.btn:hover { box-shadow: 0 6px 18px rgba(34, 38, 46, .18); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #1b1206; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
.btn.block { width: 100%; }

.notice { border-radius: 10px; padding: 12px 14px; margin: 0 0 18px; font-size: 15px; border: 1px solid; }
.notice.warn { background: var(--warn-soft); border-color: #f0d68a; color: var(--warn); }
.notice.err { background: var(--bad-soft); border-color: #efc1be; color: var(--bad); }
.notice.ok { background: var(--ok-soft); border-color: #b9dfc8; color: var(--ok); }
.hidden { display: none !important; }

/* ---------------- quiz ---------------- */
.progress { position: sticky; top: 63px; z-index: 9; background: rgba(252, 251, 249, .92); backdrop-filter: blur(6px); padding: 10px 0 12px; margin: -8px 0 18px; }
.progress .row { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--mono); font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.progress .row b { color: var(--ink); font-size: 15px; }
.bar { height: 6px; background: var(--paper-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .35s cubic-bezier(.2, .8, .2, 1); }

.qpart { font-family: var(--mono); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-ink); margin: 0 0 8px; }
.qtext { font-size: clamp(19px, 3.2vw, 23px); line-height: 1.4; font-weight: 600; margin: 0 0 22px; }
fieldset { border: 0; padding: 0; margin: 0; }
.opts { display: grid; gap: 10px; }
.opt { position: relative; display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: start; padding: 14px 16px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; transition: border-color .15s, background .15s, transform .1s; }
.opt:hover { border-color: #cfc7bb; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt .key { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-family: var(--mono); font-weight: 600; border: 1.5px solid var(--line); background: var(--paper); transition: all .15s; }
.opt .txt { padding-top: 5px; }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt:has(input:checked) .key { background: var(--accent); border-color: var(--accent); color: #1b1206; }
.opt:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

.qnav { display: flex; gap: 10px; justify-content: space-between; margin-top: 26px; }
.qnav .btn { flex: 1; max-width: 220px; }
.saved { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: center; margin-top: 14px; min-height: 18px; }

.map { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; margin-top: 28px; }
.map button { height: 42px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff; font-family: var(--mono); font-size: 14px; cursor: pointer; color: var(--ink-2); }
.map button.done { background: var(--ink); color: #fff; border-color: var(--ink); }
.map button.cur { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border: 1.5px solid var(--line); }
.legend i.d { background: var(--ink); border-color: var(--ink); }

.review-list { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 6px; }
.review-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 15px; }
.review-list li button { flex: none; }

.done-mark { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; margin-bottom: 18px; animation: pop .5s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.fade-in { animation: fade .28s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

dialog { border: 0; border-radius: var(--radius); padding: 24px; max-width: 440px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(34, 38, 46, .45); backdrop-filter: blur(2px); }
dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ---------------- admin ---------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 0 0 22px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 13px; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 18px; }
.toolbar .spacer { flex: 1; }
.switch { display: inline-flex; align-items: center; gap: 12px; padding: 8px 14px 8px 8px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; }
.switch .knob { width: 46px; height: 26px; border-radius: 99px; background: #d9d4cc; position: relative; transition: background .2s; }
.switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch[aria-checked="true"] { border-color: var(--ok); color: var(--ok); }
.switch[aria-checked="true"] .knob { background: var(--ok); }
.switch[aria-checked="true"] .knob::after { transform: translateX(20px); }
.inline-num { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.inline-num input { width: 70px; padding: 8px; border: 1.5px solid var(--line); border-radius: 8px; font-size: 16px; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-family: var(--mono); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 500; background: var(--paper); }
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: var(--paper); }
td.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.scorebar { display: inline-block; width: 90px; height: 8px; background: var(--paper-2); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-right: 8px; }
.scorebar span { display: block; height: 100%; background: var(--ink); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.wip { background: var(--warn-soft); color: var(--warn); }
.badge.ai { background: var(--accent-soft); color: var(--accent-ink); }

.heat { display: grid; grid-template-columns: repeat(13, 1fr); gap: 5px; margin: 10px 0 0; }
@media (max-width: 640px) { .heat { grid-template-columns: repeat(7, 1fr); } }
.heat div { border-radius: 8px; padding: 6px 4px; text-align: center; font-family: var(--mono); font-size: 12px; line-height: 1.25; border: 1px solid rgba(0, 0, 0, .05); }
.heat b { display: block; font-size: 13px; }

.panel { margin: 22px 0; }
.ai-box { border-left: 4px solid var(--accent); background: #fff; border-radius: 0 12px 12px 0; padding: 16px 18px; border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.ai-box ul { margin: 6px 0 12px; padding-left: 20px; }
.ai-box p { margin: 6px 0 12px; }
.ai-meta { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

.drawer { position: fixed; inset: 0; background: rgba(34, 38, 46, .4); z-index: 50; display: flex; justify-content: flex-end; }
.drawer .sheet { width: min(860px, 100%); height: 100%; overflow-y: auto; background: var(--paper); padding: 22px clamp(16px, 3vw, 32px) 60px; animation: slide .25s cubic-bezier(.2, .8, .2, 1); }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.qa { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 10px; }
.qa.ok { border-left: 4px solid var(--ok); }
.qa.bad { border-left: 4px solid var(--bad); }
.qa.none { border-left: 4px solid #c9c2b6; }
.qa .q { font-weight: 600; margin: 0 0 8px; }
.qa ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14.5px; }
.qa li { padding: 5px 8px; border-radius: 6px; }
.qa li.correct { background: var(--ok-soft); }
.qa li.chosen-bad { background: var(--bad-soft); text-decoration: line-through; text-decoration-color: rgba(179, 38, 30, .5); }
.qa .ref { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.pairs { font-size: 14px; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

@media print {
  body { background: #fff; }
  body::before, .topbar, .toolbar, .no-print, #dashboard { display: none !important; }
  .drawer { position: static; background: none; display: block; }
  .drawer .sheet { width: 100%; height: auto; overflow: visible; padding: 0; animation: none; background: #fff; }
  .qa { break-inside: avoid; }
}
