:root {
  --bg: #0b0d10;
  --panel: #14171c;
  --panel-2: #1b1f26;
  --panel-3: #232833;
  --border: #2a303a;
  --text: #e7e9ec;
  --muted: #9aa3ad;
  --faint: #6b7480;
  --accent: #5aa2ff;
  --accent-strong: #2f7be6;
  --accent-soft: rgba(90, 162, 255, 0.14);
  --good: #3fb67d;
  --good-soft: rgba(63, 182, 125, 0.15);
  --bad: #ef6a5f;
  --bad-soft: rgba(239, 106, 95, 0.15);
  --warn: #d9a92f;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }

/* ---------- buttons & inputs ---------- */
button, .btn {
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { background: #2b313d; border-color: #3a414d; text-decoration: none; }
.btn { display: inline-block; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.primary:hover:not(:disabled) { background: #3b88f2; border-color: #3b88f2; }
.danger { color: #ffb4ad; border-color: #5a2e2b; background: #2a1715; }
.danger:hover:not(:disabled) { background: #3a1d1a; }
.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.ghost:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.small.btn, button.small { padding: 5px 10px; font-size: 13px; }

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
textarea { resize: vertical; min-height: 70px; }
textarea.code { font-family: var(--mono); font-size: 12.5px; line-height: 1.45; min-height: 220px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 14px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent-strong); }

/* ---------- layout pieces ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar .brand { font-weight: 650; letter-spacing: -0.01em; }
.topbar .brand small { color: var(--faint); font-weight: 500; margin-left: 6px; }
.page { max-width: 1100px; margin: 0 auto; padding: 28px 20px 60px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--muted);
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pill.open { color: #9fe2bf; background: var(--good-soft); border-color: #24563d; }
.pill.closed { color: #c9ced4; }
.pill.draft { color: #f2d48b; background: rgba(217, 169, 47, 0.12); border-color: #5b4a1d; }
.pill.good { color: #9fe2bf; background: var(--good-soft); border-color: #24563d; }
.pill.bad { color: #ffb4ad; background: var(--bad-soft); border-color: #5a2e2b; }
.progress { height: 6px; background: var(--panel-3); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s; }
.error-box {
  color: #ffc9c4;
  background: var(--bad-soft);
  border: 1px solid #5a2e2b;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
}
.note-box {
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--panel-3);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 1000;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  max-width: min(90vw, 560px);
}
.toast.bad { border-color: #5a2e2b; color: #ffc9c4; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); }
.login-card h1 { margin-bottom: 4px; }

/* ---------- dialogs ---------- */
dialog {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.wide { width: min(1200px, calc(100vw - 32px)); height: min(860px, calc(100vh - 32px)); padding: 0; }

/* ---------- reading view ---------- */
body.reader { overflow: hidden; }
.read-app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.read-top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  min-height: 56px;
}
.read-top .case-counter { font-weight: 650; font-variant-numeric: tabular-nums; }
.read-top .progress { width: 180px; }
.read-main { display: grid; grid-template-columns: 1fr 360px; min-height: 0; }
.viewer-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #000; }
.panes { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 1fr; }
.panes.two { grid-template-columns: 1fr 1fr; gap: 6px; background: var(--panel); }
.pane-tag {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 2;
  padding: 3px 12px;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 750;
  color: #fff;
  background: rgba(20, 23, 28, 0.85);
  border: 1px solid var(--border);
  pointer-events: none;
}
.revisit-banner {
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  color: #1b1500;
  background: var(--warn);
}
.viewer-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: transparent; color: var(--muted); padding: 6px 11px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--text); }
.canvas-wrap { position: relative; min-height: 0; min-width: 0; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.canvas-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.55);
  font-size: 15px;
  pointer-events: none;
}
.side {
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-scroll { flex: 1 1 auto; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 22px; }
.side-foot { border-top: 1px solid var(--border); padding: 14px 18px; display: flex; flex-direction: column; gap: 8px; }
.attrs { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14.5px; }
.attrs dt { color: var(--muted); }
.attrs dd { margin: 0; font-weight: 550; }
.question { display: flex; flex-direction: column; gap: 10px; }
.question .qlabel { font-weight: 600; font-size: 15px; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.choice {
  padding: 14px 10px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 10px;
  background: var(--panel-2);
  border: 2px solid var(--border);
}
.choice.on { border-color: var(--accent); background: var(--accent-soft); color: #fff; }
.scale { display: flex; flex-direction: column; gap: 6px; }
.dots { display: flex; justify-content: space-between; gap: 6px; }
.bands { display: grid; grid-template-columns: repeat(auto-fit, minmax(58px, 1fr)); gap: 6px; }
.band {
  padding: 10px 4px;
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  border-radius: 9px;
  border: 2px solid var(--border);
  background: var(--panel-2);
}
.band.on { border-color: var(--accent); background: var(--accent-soft); color: #fff; }
.band.fill { background: rgba(90, 162, 255, 0.08); }
.choice:disabled, .dot:disabled, .band:disabled { opacity: 0.85; cursor: default; }
.dot {
  flex: 1;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--panel-2);
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 15px;
  padding: 0;
}
.dot::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--faint);
  display: block;
  margin-bottom: 2px;
}
.dot { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.dot.on { border-color: var(--accent); background: var(--accent-soft); }
.dot.on::before { background: var(--accent); border-color: var(--accent); }
.dot.fill::before { background: rgba(90, 162, 255, 0.45); border-color: var(--accent); }
.scale-labels { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.next-btn { padding: 13px; font-size: 16px; }
.center-panel { display: grid; place-items: center; height: 100%; padding: 24px; background: var(--bg); overflow: auto; }
.read-app > .center-panel { grid-row: 1 / -1; }
.center-panel .card { max-width: 620px; width: 100%; display: flex; flex-direction: column; gap: 16px; }
.verdict { border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.verdict.good { background: var(--good-soft); border: 1px solid #24563d; }
.verdict.bad { background: var(--bad-soft); border: 1px solid #5a2e2b; }
.verdict .big { font-size: 20px; font-weight: 700; }
.strip { display: flex; flex-wrap: wrap; gap: 5px; }
.strip button {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  border-radius: 7px;
}
.strip button.good { background: var(--good-soft); border-color: #24563d; }
.strip button.bad { background: var(--bad-soft); border-color: #5a2e2b; }
.strip button.here { outline: 2px solid var(--accent); outline-offset: 1px; }
.strip button.current { border-color: var(--accent); color: var(--accent); }
.case-group-head { display: flex; justify-content: space-between; align-items: baseline; }
kbd {
  font-family: var(--mono);
  font-size: 12px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel-2);
}
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs button { background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 10px 14px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.round-list { display: grid; gap: 10px; }
.round-item { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.round-item:hover { border-color: #3a414d; }
.section { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.attr-pick { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 12px; align-items: center; }
.secret {
  font-family: var(--mono);
  font-size: 17px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px dashed var(--accent);
  user-select: all;
}

@media (max-width: 900px) {
  .read-main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { border-left: none; border-top: 1px solid var(--border); max-height: 45vh; }
  .grid-2 { grid-template-columns: 1fr; }
}
