:root {
  --bg: #0e0e11;
  --panel: #16161a;
  --panel-2: #1c1c22;
  --line: #26262e;
  --ink: #e9e9ee;
  --ink-dim: #9a9aa6;
  --ink-faint: #63636f;
  --accent: #f0b429;
  --yes: #35b37e;
  --no: #e5484d;
  --radius: 14px;
  --tile-red: #e5484d;
  --tile-blue: #4b8ef7;
  --tile-green: #35b37e;
  --tile-yellow: #f0c419;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
main { max-width: 680px; margin: 0 auto; padding: 0 14px 48px; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  max-width: 680px; margin: 0 auto; padding: 14px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; letter-spacing: .16em; font-size: 15px;
}
.razor {
  width: 14px; height: 14px; flex: none;
  background: var(--accent);
  clip-path: polygon(0 100%, 100% 0, 100% 100%);
}
.puzzle-meta { flex: 1; color: var(--ink-dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--panel-2); color: var(--ink-dim);
  border: 1px solid var(--line); cursor: pointer; font-size: 13px; font-weight: 600;
}
.icon-btn:hover { color: var(--ink); border-color: #3a3a44; }
.icon-btn[aria-pressed="true"] { color: var(--bg); background: var(--accent); border-color: var(--accent); }

.prompt { color: var(--ink-dim); font-size: 13px; margin: 14px 2px 12px; }
.prompt b { color: var(--ink); font-weight: 600; }

/* ---- evidence board ---- */
.board { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h2 {
  display: flex; align-items: center; gap: 6px;
  margin: 0 0 10px; font-size: 11px; letter-spacing: .14em; color: var(--ink-faint); font-weight: 700;
}
.dot { width: 7px; height: 7px; border-radius: 50%; }
.col-yes .dot { background: var(--yes); }
.col-no .dot { background: var(--no); }
.col-yes { box-shadow: inset 0 1px 0 rgba(53,179,126,.15); }
.col-no { box-shadow: inset 0 1px 0 rgba(229,72,77,.15); }
.stack { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; scrollbar-width: thin; }
.stack:empty::after { content: "—"; color: var(--ink-faint); font-size: 13px; }

.row-card { cursor: pointer; transition: background .12s; display: flex; gap: 3px; align-items: center; padding: 5px 6px; background: var(--panel-2); border-radius: 9px; flex-wrap: wrap; }
.stack .row-card:hover { background: #24242c; }
.exam-card .row-card { cursor: default; }
.row-card.fresh { animation: pop .28s ease-out; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---- tiles ---- */
.tile { display: block; flex: none; }
.tile-btn { padding: 4px; border-radius: 9px; background: transparent; border: 2px solid transparent; cursor: pointer; line-height: 0; }
.tile-btn.sel { border-color: var(--accent); background: rgba(240,180,41,.10); }

/* ---- composer ---- */
.composer { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.composer-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.label { font-size: 11px; letter-spacing: .14em; color: var(--ink-faint); font-weight: 700; }
.counter { font-size: 12px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.tray {
  display: flex; gap: 2px; align-items: center; justify-content: flex-start; flex-wrap: wrap;
  min-height: 62px; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 6px;
}
.palette { margin: 10px 0; display: flex; flex-direction: column; gap: 3px; }
.pal-label { font-size: 9px; letter-spacing: .16em; color: var(--ink-faint); text-transform: uppercase; margin-top: 5px; }
.pal-row { display: flex; gap: 6px; }
.pal-btn {
  flex: 1; min-height: 42px; border-radius: 10px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 13px; font-weight: 600; line-height: 0;
}
.pal-btn:hover { border-color: #3a3a44; }
.pal-btn.on { border-color: var(--accent); background: rgba(240,180,41,.12); }
.pal-btn.wide { line-height: 1.2; color: var(--ink-dim); }
.pal-word { line-height: 1; font-size: 12px; color: var(--ink-dim); }
.pal-btn.on .pal-word { color: var(--ink); }
.pal-len .pal-btn { min-height: 38px; }

.primary {
  width: 100%; min-height: 50px; margin-top: 4px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--accent); color: #17130a; font-size: 16px; font-weight: 700; letter-spacing: .01em;
}
.primary:disabled { opacity: .45; cursor: default; }
.primary:not(:disabled):active { transform: translateY(1px); }
.composer-foot { display: flex; gap: 8px; margin-top: 10px; }
.ghost {
  flex: 1; min-height: 40px; border-radius: 10px; cursor: pointer;
  background: transparent; border: 1px solid var(--line); color: var(--ink-dim); font-size: 13px; font-weight: 600;
}
.ghost:hover:not(:disabled) { color: var(--ink); border-color: #3a3a44; }
.ghost:disabled { opacity: .4; cursor: default; }
.ghost.center { flex: none; width: 100%; margin-top: 8px; }
.hints { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.hint { font-size: 13px; color: var(--accent); background: rgba(240,180,41,.08); border-left: 2px solid var(--accent); padding: 7px 10px; border-radius: 0 8px 8px 0; }

/* ---- exam ---- */
.exam { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.exam-title { margin: 0 0 4px; font-size: 18px; }
.exam-sub { margin: 0 0 14px; font-size: 13px; color: var(--ink-dim); }
.exam-cards { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.exam-card { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 10px; padding: 7px; }
.exam-card .row-card { flex: 1; background: transparent; padding: 0; }
.judge { display: flex; gap: 4px; flex: none; }
.judge button {
  width: 42px; height: 34px; border-radius: 8px; cursor: pointer;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink-faint); font-size: 12px; font-weight: 700;
}
.judge button.on-yes { background: var(--yes); border-color: var(--yes); color: #06180f; }
.judge button.on-no { background: var(--no); border-color: var(--no); color: #1d0507; }

/* ---- result ---- */
.result { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }
.result-badge { font-size: 22px; font-weight: 800; margin-bottom: 10px; }
.result-badge.win { color: var(--yes); }
.result-badge.lose { color: var(--ink-dim); }
.result-rule { color: var(--ink-dim); font-size: 14px; line-height: 1.7; }
.result-rule b { color: var(--ink); font-size: 16px; }
.result-stats { display: flex; justify-content: center; gap: 22px; margin: 16px 0; flex-wrap: wrap; }
.stat { text-align: center; }
.stat .n { display: block; font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 10px; letter-spacing: .12em; color: var(--ink-faint); text-transform: uppercase; }
.share-box {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink-dim); font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 10px; resize: none; margin-bottom: 8px;
}
.next-in { color: var(--ink-faint); font-size: 12px; margin: 12px 0 0; font-variant-numeric: tabular-nums; }
.footnote { text-align: center; color: var(--ink-faint); font-size: 12px; margin-top: 26px; }
.linkish { background: none; border: 0; color: var(--accent); font-size: 12px; cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.practice-actions { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.practice-actions .label { display: block; margin-bottom: 8px; }
.practice-actions .pal-row { display: flex; gap: 6px; }
.badge-practice { color: var(--accent); font-weight: 700; letter-spacing: .12em; }

/* ---- dialog + toast ---- */
dialog {
  max-width: 460px; width: calc(100% - 32px); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--ink); padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,.72); }
dialog h2 { margin: 0 0 12px; font-size: 19px; }
dialog p, dialog li { color: var(--ink-dim); font-size: 14px; }
dialog ol { padding-left: 20px; }
dialog li { margin-bottom: 8px; }
dialog b { color: var(--ink); }
.help-note { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 14px; font-size: 13px; color: var(--ink-faint); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 50;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); animation: rise .2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 420px) {
  .board { gap: 6px; }
  .col { padding: 8px; }
  .prompt { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
