:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232b;
  --line: #2a313b;
  --text: #e6e9ee;
  --muted: #8d97a5;
  --accent: #4da3ff;
  --ok: #3ccf8e;
  --warn: #f2b541;
  --bad: #ff6b6b;
  --pos: #3ccf8e;
  --neg: #ff5c5c;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; cursor: pointer; line-height: 1.2;
}
button:hover:not(:disabled) { border-color: #44505f; background: #252b35; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #1f5fa8; border-color: #2f74c4; }
button.primary:hover:not(:disabled) { background: #2569b8; }
button.ok { background: #17573c; border-color: #22825a; }
button.ok:hover:not(:disabled) { background: #1c6a49; }
button.bad { background: #6b2323; border-color: #963434; }
button.ghost { background: transparent; border-color: transparent; }
button.active { border-color: var(--accent); background: #1b3350; }
input[type=text], input[type=password], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; width: 100%; min-height: 52px; }
kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; padding: 1px 5px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); background: var(--bg);
}
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 28px 24px;
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p { margin: 0 0 18px; }
.auth-card label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 13px; }
.auth-card input { width: 100%; }
.auth-card button { width: 100%; margin-top: 18px; padding: 9px; }
.error { color: var(--bad); min-height: 20px; margin-top: 10px; font-size: 13px; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-rows: 46px 1fr; height: 100vh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 0 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); min-width: 0;
}
.brand { font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.brand span { color: var(--accent); }
.progress { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 13px; white-space: nowrap; }
.bar { width: 120px; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); width: 0; }
.topbar .spacer { flex: 1; }
.main { display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-scroll { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.group-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.group-title b { font-size: 16px; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px; background: #2b3542; color: #cfd8e3; }
.tag.spot { background: #33304a; color: #c9c0ff; }
.tag.done { background: #173d2c; color: #8ce0b6; }
.tag.lock { background: #4a3a17; color: #f2d48a; }
.hint { color: #c4ccd6; line-height: 1.55; font-size: 13px; margin: 6px 0 10px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-all; }
.idchip {
  display: inline-block; margin: 0 4px 3px 0; padding: 0 6px; border-radius: 4px; cursor: pointer;
  font-family: ui-monospace, Menlo, monospace; font-size: 12px; border: 1px solid transparent; line-height: 18px;
}
.idchip:hover { border-color: #ffffff66; }
.idchip.gone { text-decoration: line-through; opacity: .6; }
.verdicts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.verdicts button { text-align: left; padding: 8px; }
.verdicts button small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.nav-row { display: flex; gap: 6px; margin-top: 10px; }
.nav-row button { flex: 1; }
.list { max-height: 320px; overflow-y: auto; margin: 0 -4px; }
.list .item {
  display: flex; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 5px; cursor: pointer; font-size: 13px;
}
.list .item:hover { background: #262d37; }
.list .item.cur { background: #1b3350; }
.list .item .k { flex: 1; color: #cfd8e3; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #56606d; flex: none; }
.dot.done { background: var(--ok); }
.dot.lock { background: var(--warn); }
.filters { display: flex; gap: 6px; margin-bottom: 8px; }
.filters select { flex: 1; padding: 4px 6px; }
.sel-info { font-size: 13px; line-height: 1.6; }
.ops-list { font-size: 12px; max-height: 180px; overflow-y: auto; }
.ops-list div { padding: 3px 0; border-bottom: 1px solid #232932; display: flex; gap: 6px; }
.ops-list .undone { opacity: .5; text-decoration: line-through; }

/* ---------- viewer ---------- */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #07090b; }
.toolbar {
  display: flex; gap: 6px; align-items: center; padding: 6px 10px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.toolbar button { padding: 5px 9px; font-size: 13px; }
.toolbar button kbd { margin-left: 4px; }
.toolbar label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.toolbar input[type=range] { width: 80px; }
.views { flex: 1; display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); grid-template-rows: 1fr 1fr; gap: 4px; padding: 4px; min-height: 0; }
.view { position: relative; background: #000; border: 1px solid #1c2129; border-radius: 4px; overflow: hidden; min-height: 0; }
.view.big { grid-row: 1 / span 2; }
.view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.view .label {
  position: absolute; left: 8px; top: 6px; font-size: 12px; color: #c7d0db; background: #000a; padding: 2px 7px;
  border-radius: 4px; pointer-events: none; font-family: ui-monospace, Menlo, monospace;
}
.view .swap { position: absolute; right: 6px; top: 5px; padding: 2px 7px; font-size: 12px; background: #000a; }
.view.focus { border-color: #2f74c4; }
.statusbar {
  display: flex; gap: 16px; padding: 4px 12px; font-size: 12px; color: var(--muted); background: var(--panel);
  border-top: 1px solid var(--line); font-family: ui-monospace, Menlo, monospace; white-space: nowrap; overflow: hidden;
}
.statusbar b { color: var(--text); font-weight: 500; }
.proposal-bar {
  display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: #2a2412; border-bottom: 1px solid #5a4a1c;
  font-size: 13px;
}
.proposal-bar .warn { color: var(--warn); }
.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: 420px; }
.toast { background: #222831; border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 12px; border-radius: 6px; font-size: 13px; box-shadow: 0 6px 24px #0008; }
.toast.err { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
.modal-back { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 12px; font-size: 17px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.empty { padding: 30px 10px; text-align: center; color: var(--muted); line-height: 1.7; }

/* ---------- admin ---------- */
.admin { max-width: 1100px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.admin h2 { font-size: 16px; margin: 0 0 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.linkbox { display: flex; gap: 6px; margin-top: 10px; }
.linkbox input { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.checks { display: flex; gap: 10px; flex-wrap: wrap; }
.checks label { display: flex; gap: 4px; align-items: center; }

@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { max-height: 42vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .views { grid-template-columns: 1fr; grid-template-rows: 2fr 1fr 1fr; }
  .view.big { grid-row: auto; }
  .progress .bar { display: none; }
}
.auth-card p.foot { margin: 16px 0 0; font-size: 12px; text-align: center; }
.topbar { min-height: 46px; }
