:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #d9dde3;
  --text: #1c2430;
  --muted: #5b6573;
  --accent: #1f5fa8;
  --accent-text: #ffffff;
  --accent-soft: #e5eef9;
  --focus: #2f7ad6;
  --todo-bg: #e5eef9;   --todo-fg: #1d4f8c;
  --busy-bg: #efe8fa;   --busy-fg: #5a3a8f;
  --wait-bg: #fbf1dc;   --wait-fg: #7a5200;
  --stop-bg: #fbe5e3;   --stop-fg: #9a2a20;
  --done-bg: #e2f3e7;   --done-fg: #1e6a37;
  --open-bg: #eef0f3;   --open-fg: #4a5361;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --surface: #1a2029;
    --surface-2: #222a35;
    --border: #323c4a;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --accent: #5b9be6;
    --accent-text: #0d1520;
    --accent-soft: #1f3048;
    --focus: #7ab2f0;
    --todo-bg: #1f3048;  --todo-fg: #a9c9f2;
    --busy-bg: #2e2542;  --busy-fg: #cdb8f2;
    --wait-bg: #3a2f17;  --wait-fg: #f0cf87;
    --stop-bg: #41201d;  --stop-fg: #f3a79f;
    --done-bg: #183323;  --done-fg: #95dbaa;
    --open-bg: #262e39;  --open-fg: #b7c0cc;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c;
  --surface: #1a2029;
  --surface-2: #222a35;
  --border: #323c4a;
  --text: #e6eaf0;
  --muted: #9aa5b4;
  --accent: #5b9be6;
  --accent-text: #0d1520;
  --accent-soft: #1f3048;
  --focus: #7ab2f0;
  --todo-bg: #1f3048;  --todo-fg: #a9c9f2;
  --busy-bg: #2e2542;  --busy-fg: #cdb8f2;
  --wait-bg: #3a2f17;  --wait-fg: #f0cf87;
  --stop-bg: #41201d;  --stop-fg: #f3a79f;
  --done-bg: #183323;  --done-fg: #95dbaa;
  --open-bg: #262e39;  --open-fg: #b7c0cc;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
a:focus-visible, button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.45rem; font-weight: 600; }
h2 { font-size: 1.08rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.num { font-variant-numeric: tabular-nums; }

/* Header */
.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top-inner {
  max-width: 1080px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; min-width: 0; margin-right: auto; text-decoration: none; color: inherit; }
.brand strong { font-size: 1rem; font-weight: 600; }
.brand span { font-size: .82rem; color: var(--muted); }
.who { font-size: .86rem; color: var(--muted); }
.theme-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.theme-switch button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: .8rem;
  padding: 4px 10px; cursor: pointer;
}
.theme-switch button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

.proto {
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: .8rem; color: var(--muted);
}
.proto .top-inner { padding: 6px 16px; }
.proto button { font-size: .8rem; }

main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 48px; }

/* Breadcrumb */
.crumbs { font-size: .86rem; margin-bottom: 10px; color: var(--muted); }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card > h2 { margin-bottom: 10px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

/* Badges */
.badge {
  display: inline-block; white-space: nowrap; border-radius: 999px; padding: 2px 10px;
  font-size: .78rem; font-weight: 600; line-height: 1.6;
}
.tone-todo { background: var(--todo-bg); color: var(--todo-fg); }
.tone-busy { background: var(--busy-bg); color: var(--busy-fg); }
.tone-wait { background: var(--wait-bg); color: var(--wait-fg); }
.tone-stop { background: var(--stop-bg); color: var(--stop-fg); }
.tone-done { background: var(--done-bg); color: var(--done-fg); }
.tone-open { background: var(--open-bg); color: var(--open-fg); }
.kind { font-size: .72rem; letter-spacing: .04em; border: 1px solid var(--border); color: var(--muted); border-radius: 4px; padding: 0 6px; font-weight: 600; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 4px 12px; font: inherit; font-size: .84rem; cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text); font-weight: 600; }
.chip .n { color: var(--muted); margin-left: 4px; }

/* Screen list */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list table { width: 100%; border-collapse: collapse; }
.list th, .list td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.list th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover td { background: var(--surface-2); }
.list .scr { font-weight: 600; white-space: nowrap; }
.list .next { color: var(--muted); font-size: .88rem; }
.list a.rowlink { color: inherit; text-decoration: none; }
@media (max-width: 680px) {
  .list thead { display: none; }
  .list table, .list tbody, .list tr, .list td { display: block; width: 100%; }
  .list tr { border-bottom: 1px solid var(--border); padding: 10px 14px; }
  .list tr:last-child { border-bottom: 0; }
  .list td { border: 0; padding: 2px 0; }
  .list td.when { font-size: .8rem; color: var(--muted); }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 6px; padding: 8px 14px; font: inherit; font-size: .9rem; font-weight: 500;
  cursor: pointer; text-decoration: none; min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { border-color: var(--stop-fg); color: var(--stop-fg); }
.btn[disabled] { opacity: .5; cursor: not-allowed; filter: none; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; text-decoration: underline; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 520px) { .btns.stack .btn { flex: 1 1 100%; } }

/* Files */
.files { list-style: none; margin: 0; padding: 0; }
.files li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.files li:last-child { border-bottom: 0; }
.files .fname { font-weight: 500; overflow-wrap: anywhere; }
.files .meta { font-size: .82rem; color: var(--muted); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; font-size: .92rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

/* Progress */
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; }
.progress .p-done { background: var(--done-fg); }
.progress .p-park { background: var(--wait-fg); opacity: .8; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .84rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* Question list */
.qlist { list-style: none; margin: 0; padding: 0; }
.qlist li { border-bottom: 1px solid var(--border); }
.qlist li:last-child { border-bottom: 0; }
.qlist a { display: grid; grid-template-columns: 2.2rem 1fr auto; gap: 10px; align-items: baseline; padding: 9px 4px; color: inherit; text-decoration: none; }
.qlist a:hover { background: var(--surface-2); }
.qlist .qn { color: var(--muted); font-variant-numeric: tabular-nums; }
.qlist .qref { display: block; font-size: .8rem; color: var(--muted); }

/* Question page */
.qnav { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.qnav .count { font-weight: 600; }
.qhead { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; color: var(--muted); font-size: .86rem; }
.qtitle { font-size: 1.2rem; margin-bottom: 10px; }
.block-label { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.rec { background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; padding: 10px 12px; margin: 12px 0 4px; }
.answer-box { margin-top: 16px; }
textarea, input[type="text"] {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px;
}
textarea { min-height: 88px; resize: vertical; }
.hint { font-size: .82rem; color: var(--muted); margin: 4px 0 10px; }
.err { font-size: .84rem; color: var(--stop-fg); margin: 4px 0 8px; }
.saved { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; background: var(--surface-2); }
.saved .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }

/* Thread */
.thread { list-style: none; margin: 0 0 12px; padding: 0; }
.thread li { padding: 10px 12px; border-radius: 6px; margin-bottom: 8px; border: 1px solid var(--border); }
.thread li.you { background: var(--surface-2); margin-left: 24px; }
.thread li.them { background: var(--surface); margin-right: 24px; }
.thread .who { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
@media (max-width: 520px) { .thread li.you { margin-left: 10px; } .thread li.them { margin-right: 10px; } }

/* Notices */
.notice { border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; font-size: .92rem; }
.notice.warn { background: var(--wait-bg); color: var(--wait-fg); }
.notice.stop { background: var(--stop-bg); color: var(--stop-fg); }
.notice.ok { background: var(--done-bg); color: var(--done-fg); }
.notice.info { background: var(--accent-soft); color: var(--text); }

/* Lock table */
table.plain { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.plain th, table.plain td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
table.plain th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.tablewrap { overflow-x: auto; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; }
.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; }

/* Dialog */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 14, 20, .5); }
.dlg-body { padding: 18px; }
.dlg-body h2 { margin-bottom: 10px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 6px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

footer { max-width: 1080px; margin: 0 auto; padding: 0 16px 32px; font-size: .8rem; color: var(--muted); }
