/* Layout: one-screen handheld tool. Header bar, scan field, big verdict slab, tally strip, recent-scan list. Setup is a second view. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #17202b;
  --muted: #5d6877;
  --line: #d4dae2;
  --accent: #1f4f8f;
  --accent-ink: #ffffff;
  --keep: #13804a;
  --keep-soft: #dff3e8;
  --remove: #c2261f;
  --remove-soft: #fbe3e1;
  --unknown: #b26b00;
  --unknown-soft: #fff0d6;
  --idle-soft: #e4e9ef;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10151c; --surface: #18202a; --ink: #e6ebf1; --muted: #93a0b0; --line: #2b3542;
    --accent: #6ea2e6; --accent-ink: #0b1420;
    --keep: #3ccf84; --keep-soft: #123526; --remove: #ff6b62; --remove-soft: #3d1715;
    --unknown: #f2a93b; --unknown-soft: #3a2a10; --idle-soft: #1f2833;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10151c; --surface: #18202a; --ink: #e6ebf1; --muted: #93a0b0; --line: #2b3542;
  --accent: #6ea2e6; --accent-ink: #0b1420;
  --keep: #3ccf84; --keep-soft: #123526; --remove: #ff6b62; --remove-soft: #3d1715;
  --unknown: #f2a93b; --unknown-soft: #3a2a10; --idle-soft: #1f2833;
  color-scheme: dark;
}
[hidden] { display: none !important; }
html, body { height: 100%; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body {
  margin: 0; line-height: 1.4;
  background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
* { box-sizing: border-box; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px;
  display: flex; align-items: center; gap: 12px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .01em; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.chip {
  font-size: 12px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 45vw;
}
.chip.example { color: var(--unknown); border-color: var(--unknown); }
.spacer { flex: 1; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 12px;
  font-size: 14px; font-weight: 600; min-height: 40px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--remove); }
.btn:disabled { opacity: .45; cursor: default; }

main {
  max-width: 640px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 16px 32px;
  display: flex; flex-direction: column; gap: 14px;
}

/* Scan view */
.scanrow { display: flex; gap: 8px; }
.scanrow input {
  flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 20px; font-weight: 500; letter-spacing: .04em;
  border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface);
}
.scanrow input:focus { border-color: var(--accent); outline: none; }
.hint { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--keep); }

.verdict {
  border-radius: 16px; padding: 22px 20px; min-height: 210px;
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
  background: var(--idle-soft); border: 3px solid transparent; transition: background .12s;
}
.verdict .word { font-size: clamp(44px, 14vw, 76px); font-weight: 700; line-height: 1; letter-spacing: .02em; text-transform: uppercase; }
.verdict .code { font-family: var(--font-mono); font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.verdict .desc { font-size: 16px; color: var(--muted); overflow-wrap: anywhere; }
.verdict .note { font-size: 13px; font-weight: 600; }
.verdict.idle .word { font-size: 22px; text-transform: none; color: var(--muted); font-weight: 600; letter-spacing: 0; }
.verdict.keep { background: var(--keep-soft); border-color: var(--keep); }
.verdict.keep .word, .verdict.keep .note { color: var(--keep); }
.verdict.remove { background: var(--remove-soft); border-color: var(--remove); }
.verdict.remove .word, .verdict.remove .note { color: var(--remove); }
.verdict.unknown { background: var(--unknown-soft); border-color: var(--unknown); }
.verdict.unknown .word, .verdict.unknown .note { color: var(--unknown); }
@keyframes pop { from { transform: scale(.97); } to { transform: none; } }
.verdict.flash { animation: pop .14s ease-out; }
@media (prefers-reduced-motion: reduce) { .verdict.flash { animation: none; } .verdict { transition: none; } }

.tally { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tally div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.tally b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tally span { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.tally .k b { color: var(--keep); } .tally .r b { color: var(--remove); } .tally .u b { color: var(--unknown); }

.listhead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.listhead h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; flex: 1; }
.log { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.log li { display: grid; grid-template-columns: 6px 1fr auto; gap: 10px; align-items: center; padding: 9px 12px 9px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }
.log .stripe { align-self: stretch; }
.log .stripe.keep { background: var(--keep); } .log .stripe.remove { background: var(--remove); } .log .stripe.unknown { background: var(--unknown); }
.log .main { min-width: 0; }
.log .c { font-family: var(--font-mono); font-size: 14px; font-weight: 600; }
.log .d { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log .v { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; text-align: right; }
.log .v.keep { color: var(--keep); } .log .v.remove { color: var(--remove); } .log .v.unknown { color: var(--unknown); }
.log .t { display: block; font-weight: 400; color: var(--muted); letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
.empty { padding: 16px; color: var(--muted); font-size: 14px; }

/* Setup view */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card h2 { margin: 0; font-size: 17px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; max-width: 65ch; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 600; }
.field select, .field input[type=text] { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: var(--surface); min-height: 42px; }
.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); font-size: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.drop.over { border-color: var(--accent); color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } .tally b { font-size: 19px; } }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; background: transparent; padding: 6px 10px; font-size: 13px; font-weight: 600; min-height: 34px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on.keep { background: var(--keep); color: #fff; }
.seg button.on.remove { background: var(--remove); color: #fff; }
.seg button.on.unknown { background: var(--unknown); color: #fff; }
.maprow { display: flex; align-items: center; gap: 10px; padding-block: 6px; border-top: 1px solid var(--line); }
.maprow:first-child { border-top: 0; }
.maprow .val { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 14px; overflow-wrap: anywhere; }
.maprow .n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.preview { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.preview table { border-collapse: collapse; font-size: 13px; width: 100%; }
.preview th, .preview td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.preview th { background: var(--idle-soft); font-weight: 600; }
.preview td.hl, .preview th.hl { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.warn { color: var(--unknown); font-size: 13px; font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; z-index: 20;
  max-width: calc(100% - 32px);
}
.confirm { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; }
textarea.copybox { width: 100%; min-height: 120px; font-family: var(--font-mono); font-size: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 8px; }
.rulerow { display: grid; grid-template-columns: minmax(0, 1fr) 64px 84px auto; gap: 6px; align-items: center; }
.rulerow select, .rulerow input { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--surface); min-height: 42px; min-width: 0; width: 100%; }
.and { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 2px; }
