:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6b6b6b;
  --faint: #9a9a9a;
  --line: #e5e5e5;
  --soft: #f5f5f5;
  --softer: #fafafa;
  --select: #0b57d0;
  --select-soft: #eef3fd;
  --ok: #0a7f3f;
  --warn: #9a5b00;
  --bad: #c4291c;
  --ins: #e6f4ea;
  --del: #fbeaea;
  --radius: 6px;
  --rail: 232px;
  --panel: 372px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--select); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Layout: mobile first, the stage owns the screen */
.app { display: grid; grid-template-rows: 52px 1fr; grid-template-columns: 1fr; height: 100dvh; }
.topbar { grid-row: 1; display: flex; align-items: center; justify-content: space-between; padding: 0 8px; border-bottom: 1px solid var(--line); }
.wordmark { font-weight: 650; letter-spacing: -0.01em; font-size: 16px; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; background: none; border: 0; border-radius: var(--radius); }
.icon-btn:hover { background: var(--soft); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.stage { grid-row: 2; position: relative; overflow: hidden; display: flex; flex-direction: column; min-width: 0; outline: none; }
.rail, .panel { position: fixed; top: 0; bottom: 0; z-index: 20; background: var(--bg); overflow: auto; transition: transform .18s ease; }
.rail { left: 0; width: min(84vw, 300px); transform: translateX(-102%); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.panel { right: 0; width: min(92vw, 420px); transform: translateX(102%); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.app.rail-open .rail, .app.panel-open .panel { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(17,17,17,.18); z-index: 15; }

@media (min-width: 1000px) {
  .app { grid-template-rows: 1fr; grid-template-columns: var(--rail) 1fr var(--panel); }
  .app.no-panel { grid-template-columns: var(--rail) 1fr 0; }
  .topbar { display: none; }
  .rail, .panel { position: static; transform: none; width: auto; z-index: auto; }
  .stage { grid-row: 1; grid-column: 2; }
  .rail { grid-column: 1; }
  .panel { grid-column: 3; }
  .app.no-panel .panel { display: none; }
  .scrim { display: none; }
}

/* Rail */
.rail .brand { padding: 22px 20px 18px; font-weight: 650; font-size: 17px; letter-spacing: -0.015em; display: flex; justify-content: space-between; align-items: baseline; }
.rail .brand small { font-weight: 400; color: var(--faint); font-size: 11px; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; padding: 0 10px; gap: 1px; }
.nav button { text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: var(--radius); color: var(--muted); }
.nav button:hover { background: var(--soft); color: var(--fg); }
.nav button[aria-current="page"] { color: var(--fg); background: var(--soft); font-weight: 550; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 22px 20px 6px; }
.filelist { list-style: none; margin: 0; padding: 0 10px; flex: 1; overflow: auto; }
.filelist li button { width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: var(--radius); display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: baseline; }
.filelist li button:hover { background: var(--soft); }
.filelist li button[aria-current="true"] { background: var(--soft); }
.filelist .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .fmeta { color: var(--faint); font-size: 11px; text-transform: uppercase; }
.rail-foot { padding: 14px 20px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-direction: column; }
.rail-foot .local { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); display: inline-block; }

/* Buttons and controls */
.btn { border: 1px solid var(--line); background: var(--bg); padding: 7px 12px; border-radius: var(--radius); line-height: 1.3; }
.btn:hover { border-color: #cfcfcf; background: var(--softer); }
.btn.primary { background: var(--fg); border-color: var(--fg); color: #fff; }
.btn.primary:hover { background: #2a2a2a; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--soft); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); padding: 2px; gap: 2px; background: var(--bg); flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 4px; color: var(--muted); font-size: 13px; }
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--soft); color: var(--fg); font-weight: 550; }
input[type=text], input[type=number], textarea, select { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; background: var(--bg); width: 100%; }
textarea { resize: vertical; }
label.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
label.check input { margin-top: 3px; accent-color: var(--fg); }
.field { display: grid; gap: 4px; margin: 10px 0; }
.field > span { font-size: 12px; color: var(--muted); }

/* Panel */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 0; }
.tabs { display: flex; gap: 2px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 8px 10px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--fg); }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--fg); font-weight: 550; }
.panel-body { padding: 4px 16px 24px; overflow: auto; flex: 1; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 550; margin: 20px 0 6px; }
.panel h3:first-child { margin-top: 14px; }
.lede { color: var(--muted); margin: 12px 0 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.status { display: flex; gap: 8px; align-items: baseline; padding: 6px 0; }
.status .mark { font-weight: 700; width: 14px; flex: none; }
.status > span:last-child { min-width: 0; overflow-wrap: anywhere; }
summary { cursor: pointer; padding: 4px 0; }
.pass .mark { color: var(--ok); }
.fail .mark { color: var(--bad); }
.note { padding: 8px 10px; background: var(--soft); border-radius: var(--radius); margin: 8px 0; color: #333; font-size: 13px; }
.note.warn { background: #fff7e8; color: #5c3a00; }
.note.bad { background: #fdeeee; color: #7a1b13; }
.err { color: var(--bad); margin: 8px 0; }

/* Findings */
.group { border-top: 1px solid var(--line); padding: 10px 0 6px; }
.group:first-of-type { border-top: 0; }
.group-title { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
.group-title .count { color: var(--faint); font-weight: 400; font-size: 12px; }
.group-explain { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.finding { border-radius: var(--radius); margin: 0 -8px; }
.finding > button { width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: var(--radius); display: grid; gap: 1px; }
.finding > button:hover { background: var(--softer); }
.finding.open > button { background: var(--soft); }
.finding.marked .t > span:first-child::after { content: "  · will be removed"; color: var(--faint); font-size: 11px; white-space: nowrap; }
.finding .t { display: flex; gap: 6px; align-items: baseline; justify-content: space-between; }
.finding .v { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finding .more { padding: 4px 8px 10px; font-size: 13px; }
.badge { font-size: 10.5px; letter-spacing: .03em; padding: 1px 6px; border-radius: 3px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; font-weight: 500; }
.badge.heuristic { border-color: #e7cf9c; color: var(--warn); background: #fffaf0; }
.badge.unknown { border-color: #d8d8d8; color: var(--muted); background: var(--soft); }
.badge.review { border-color: #e7cf9c; color: var(--warn); }
.badge.op { font-family: var(--mono); font-size: 10px; }

/* Stage */
.stage-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 52px; flex-wrap: wrap; }
.stage-bar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.stage-bar .spacer { flex: 1; }
.empty { flex: 1; display: grid; place-items: center; padding: 24px; }
.drop { width: min(560px, 100%); border: 1px dashed #cfcfcf; border-radius: 10px; padding: 56px 28px; text-align: center; transition: border-color .12s, background .12s; }
.drop:hover, .drop.over { border-color: var(--fg); background: var(--softer); }
.drop h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 6px; }
.drop p { color: var(--muted); margin: 0 0 20px; }
.drop .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.dropveil { position: fixed; inset: 0; background: rgba(255,255,255,.88); display: grid; place-items: center; z-index: 50; font-size: 18px; font-weight: 600; }
.dropveil > div { border: 1px dashed var(--fg); border-radius: 10px; padding: 40px 64px; }

/* Image viewer */
.viewer { position: relative; flex: 1; overflow: hidden; background: var(--softer); touch-action: none; cursor: grab; user-select: none; }
.viewer.dragging { cursor: grabbing; }
.viewer .world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.viewer .world img { display: block; image-rendering: auto; max-width: none; }
.viewer.pixelated .world img { image-rendering: pixelated; }
.viewer .after { position: absolute; inset: 0; }
.viewer .handle { position: absolute; top: 0; bottom: 0; width: 0; }
.viewer .handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: calc(-1px * var(--inv)); width: calc(2px * var(--inv)); background: #fff; box-shadow: 0 0 0 calc(1px * var(--inv)) rgba(0,0,0,.25); }
.viewer .grip { transform: scale(var(--inv)); position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: #fff; border: 1px solid rgba(0,0,0,.18); display: grid; place-items: center; cursor: ew-resize; font-size: 12px; color: var(--muted); }
.corner { position: absolute; top: 12px; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; background: rgba(255,255,255,.92); padding: 3px 8px; border-radius: 4px; pointer-events: none; }
.corner.l { left: 12px; } .corner.r { right: 12px; }
.split { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); min-height: 0; }
.split .viewer { background: var(--softer); }
@media (max-width: 700px) { .split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; } }
.zoombar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 3px; z-index: 2; }
.zoombar button { border: 0; background: none; padding: 4px 9px; border-radius: 5px; color: var(--muted); min-width: 32px; }
.zoombar button:hover { background: var(--soft); color: var(--fg); }
.zoombar .z { min-width: 54px; text-align: center; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); }
.caption { padding: 8px 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.caption strong { color: var(--fg); font-weight: 550; }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }

/* Document and text */
.reader { flex: 1; overflow: auto; padding: 32px 24px 64px; }
.reader .page { max-width: 720px; margin: 0 auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.7; }
.reader .page.code { font-family: var(--mono); font-size: 13px; line-height: 1.6; max-width: 960px; white-space: pre; overflow-x: auto; }
.chg { border-radius: 3px; cursor: pointer; }
.chg del { background: var(--del); color: #8a1f17; text-decoration: line-through; text-decoration-thickness: 1px; }
.chg ins { background: var(--ins); color: #0c5a30; text-decoration: none; }
.chg.off del { background: none; color: inherit; text-decoration: underline dotted var(--faint); text-underline-offset: 3px; }
.chg.off ins { display: none; }
.chg.focus { outline: 2px solid var(--select); outline-offset: 1px; }
.prot { background: var(--soft); border-radius: 2px; }
.editor { flex: 1; border: 0; border-radius: 0; padding: 32px max(24px, calc(50% - 360px)); font-size: 15px; line-height: 1.7; resize: none; outline: none; }
.change { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--soft); }
.change input { margin-top: 3px; accent-color: var(--fg); }
.change .d { overflow-wrap: anywhere; }
.change .r { color: var(--faint); font-size: 11.5px; font-family: var(--mono); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.stats div { background: var(--softer); border: 1px solid var(--soft); border-radius: var(--radius); padding: 8px; }
.stats b { display: block; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--muted); }

/* Lab */
.tree { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.tree ul { list-style: none; margin: 0; padding-left: 14px; border-left: 1px solid var(--line); margin-left: 6px; }
.tree button { width: 100%; text-align: left; background: none; border: 0; padding: 4px 6px; border-radius: 4px; display: flex; gap: 8px; justify-content: space-between; }
.tree button:hover { background: var(--softer); }
.tree button[aria-current="true"] { background: var(--select-soft); }
.tree .k { color: var(--faint); font-size: 11px; }
.tree .payload { color: var(--muted); }
.tree .trailing { color: var(--warn); }
.hex { font-family: var(--mono); font-size: 12px; line-height: 1.65; white-space: pre; overflow-x: auto; }
.hex .o { color: var(--faint); }
.hex .sel { background: var(--select-soft); color: var(--select); }
.hex .a { color: var(--muted); }
.hexnav { display: flex; gap: 6px; align-items: center; margin: 10px 0; }
.hexnav input { width: 120px; font-family: var(--mono); font-size: 12px; }
canvas.hist { width: 100%; height: 140px; display: block; border: 1px solid var(--line); border-radius: var(--radius); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 1fr; padding: 7px 0 7px 14px; border-left: 1px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -4px; top: 13px; width: 7px; height: 7px; border-radius: 50%; background: var(--bg); border: 1px solid var(--fg); }
.timeline li.claim::before { border-style: dashed; border-color: var(--faint); }
.timeline .when { font-family: var(--mono); font-size: 12px; }
.viewpick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.viewpick select { width: auto; }

/* Batch */
.progress { height: 2px; background: var(--soft); }
.progress > div { height: 100%; background: var(--fg); transition: width .2s; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 500; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 8px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); }
.table td { padding: 8px 12px; border-bottom: 1px solid var(--soft); vertical-align: top; }
.table td.name, .table td.mono { overflow-wrap: anywhere; }
@media (max-width: 700px) { .table th:nth-child(4), .table td:nth-child(4) { display: none; } .table td, .table th { padding: 8px; } }
.scroll { flex: 1; overflow: auto; }
.st-ok { color: var(--ok); } .st-fail { color: var(--bad); } .st-run { color: var(--select); } .st-warn { color: var(--warn); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Utilities (no inline styles: CSP forbids them) */
[data-u="pad-li"] { padding:4px 10px; }
[data-u="rel-flex"] { position:relative; display:flex; min-height:0; }
[data-u="rel-flex1"] { position:relative; flex:1; display:flex; min-height:0; }
[data-u="p12"] { padding:12px; }
[data-u="p0"] { padding:0; }
[data-u="mt8"] { margin-top:8px; }
[data-u="mt6"] { margin-top:6px; }
[data-u="mt18"] { margin-top:18px; }
[data-u="mt14"] { margin-top:14px; }
[data-u="mt12"] { margin-top:12px; }
[data-u="py2"] { padding:2px 0; }
[data-u="w550"] { font-weight:550; }
[data-u="grid6"] { display:grid; gap:6px; }
[data-u="p16"] { padding:16px; }
[data-u="grid2"] { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
[data-u="row6"] { display:flex; gap:6px; margin-bottom:6px; }
[data-u="cap"] { text-transform:capitalize; }
[data-u="sugg"] { padding:6px 0; border-bottom:1px solid var(--soft); }
[data-u="grid6-mt12"] { display:grid; gap:6px; margin-top:12px; }
