/* MAT-SA Agent. Monochrome per MAT-SA standard: black on white, white on black, grey.
   State is shown by form (solid, outline, dashed, struck), never by colour alone. */
:root {
  --bg: #ffffff; --fg: #0a0a0a; --muted: #666666; --faint: #8f8f8f; --line: #e6e6e6; --panel: #fafafa; --inv: #ffffff;
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0a0a0a; --fg: #ededed; --muted: #a1a1a1; --faint: #707070; --line: #262626; --panel: #111111; --inv: #0a0a0a; color-scheme: dark; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; text-wrap: balance; }
h1 { font-size: clamp(24px, 4vw, 32px); font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow { font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* shell */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line); }
.top-inner, .wrap { max-width: 1040px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top-inner { display: flex; align-items: center; gap: 16px; height: 56px; }
.top-inner > form { margin-left: auto; }
.brand { font: 700 15px var(--sans); letter-spacing: -0.01em; text-decoration: none; white-space: nowrap; }
.brand span { font: 500 11px var(--mono); color: var(--muted); margin-left: 6px; letter-spacing: .06em; }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a { text-decoration: none; font-size: 14px; color: var(--muted); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
nav.tabs a.on { color: var(--fg); background: var(--panel); }
nav.tabs a .count { font: 500 11px var(--mono); margin-left: 4px; }
.wrap { padding-block: 28px 72px; display: flex; flex-direction: column; gap: 28px; }
@media (max-width: 640px) {
  .top-inner { height: auto; flex-wrap: wrap; padding-block: 10px 6px; gap: 6px; }
  nav.tabs { order: 3; flex-basis: 100%; }
  .wrap { padding-block: 20px 60px; gap: 22px; }
}

/* blocks */
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.head > div:first-child { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tile { padding: 14px 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; text-decoration: none; min-width: 0; }
.tile:last-child { border-right: 0; }
.tile b { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tile span { font-size: 13px; color: var(--muted); }
.tile:hover { background: var(--panel); }
@media (max-width: 640px) { .tiles { grid-template-columns: 1fr 1fr; } .tile:nth-child(2) { border-right: 0; } .tile:nth-child(-n+2) { border-bottom: 1px solid var(--line); } }

.section { display: flex; flex-direction: column; gap: 0; }
.section > h2 { padding-bottom: 10px; border-bottom: 1px solid var(--fg); display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.section > h2 small { font: 400 12px var(--mono); color: var(--muted); }
.row { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 4px 14px; padding: 14px 0; border-bottom: 1px solid var(--line); text-decoration: none; align-items: start; }
a.row:hover { background: var(--panel); }
.row .body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.row .body p { overflow-wrap: anywhere; }
.row .side { text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.row.plain { grid-template-columns: minmax(0, 1fr) auto; }
.empty { padding: 18px 0; color: var(--muted); border-bottom: 1px solid var(--line); }

/* score + pills */
.score { font: 600 18px var(--mono); font-variant-numeric: tabular-nums; width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; }
.score.hi { background: var(--fg); color: var(--inv); border-color: var(--fg); }
.score.mid { border: 2px solid var(--fg); }
.score.lo { color: var(--faint); border-style: dashed; }
.pill { display: inline-block; font: 600 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--fg); white-space: nowrap; }
.pill.solid { background: var(--fg); color: var(--inv); }
.pill.dash { border-style: dashed; color: var(--muted); border-color: var(--faint); }
.pill.ghost { border-color: var(--line); color: var(--muted); }
.pill.strike { border-color: var(--line); color: var(--faint); text-decoration: line-through; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; }

/* forms */
form.inline { display: inline; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form { grid-template-columns: 1fr; } }
label { display: flex; flex-direction: column; gap: 5px; font: 500 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
input, select, textarea { font: 400 15px var(--sans); color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; text-transform: none; letter-spacing: 0; }
textarea { min-height: 84px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.btn { font: 500 14px var(--sans); padding: 9px 16px; border-radius: 8px; border: 1px solid var(--fg); background: var(--fg); color: var(--inv); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* detail */
.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 28px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); font: 500 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; padding-top: 3px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 8px; } }
ul.clean { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.quote { border-left: 2px solid var(--fg); padding: 6px 10px; background: var(--panel); font-size: 14px; border-radius: 0 6px 6px 0; }
.quote.bad { border-left-style: dashed; color: var(--muted); }
pre.box { white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.6 var(--mono); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin: 0; max-height: 520px; overflow: auto; }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font: 500 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
td.num { font-variant-numeric: tabular-nums; }

/* flash */
.flash { padding: 12px 14px; border-radius: 8px; border: 1px solid var(--fg); font-size: 14px; }
.flash.error { border-width: 2px; }
.flash.ok { border-color: var(--line); background: var(--panel); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth .card { width: 100%; max-width: 380px; gap: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.filters label { min-width: 140px; flex: 1; }
.chip { text-decoration: none; font-size: 13px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); }
.chip.on { background: var(--fg); color: var(--inv); border-color: var(--fg); }
details summary { cursor: pointer; font-size: 14px; color: var(--muted); }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

/* layout helpers (no inline styles: the security policy blocks them) */
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.stack.tight { gap: 14px; }
.stack.mini { gap: 8px; }
.mt { margin-top: 8px; }
.pop { min-width: 220px; }
.w180 { min-width: 180px; }
.measure { max-width: 65ch; }
.wrapany { overflow-wrap: anywhere; }
.pad10 { padding: 10px 0 !important; }
pre.box.short { max-height: 260px; }
.between { justify-content: space-between; }
.gap14 { gap: 14px; }
select.auto { width: auto; }
.off { color: var(--muted); }
.struck { text-decoration: line-through; color: var(--muted); }
.quote.fail { border-left-width: 4px; }
@media (max-width: 640px) { .pop, .w180 { min-width: 0; width: 100%; } }

/* ---------------- Live view: a deliberate dark stage in both themes ---------------- */
.live { --st-bg: #050505; --st-fg: #f2f2f2; --st-dim: #8a8a8a; --st-line: #1f1f1f; --st-panel: #0c0c0c;
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: calc(100vh - 57px);
  background: var(--st-bg); color: var(--st-fg); }
.live-stage { position: relative; min-height: 520px; overflow: hidden; border-right: 1px solid var(--st-line); }
.live-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.live-hud { position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); right: 16px; display: flex; gap: 10px; align-items: center; z-index: 2; }
.live-hud.hud-top { top: 18px; }
.live-hud.hud-bottom { bottom: 18px; flex-wrap: wrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--st-dim); flex: none; }
.live-dot.on { background: var(--st-fg); box-shadow: 0 0 0 4px rgba(255,255,255,.12); animation: livepulse 1.2s ease-in-out infinite; }
@keyframes livepulse { 50% { box-shadow: 0 0 0 8px rgba(255,255,255,0); } }
.live-state { font: 600 12px var(--mono); letter-spacing: .14em; }
.live-say { position: absolute; left: 0; right: 0; bottom: 74px; text-align: center; padding: 0 20px; z-index: 2;
  font: 500 clamp(15px, 2.2vw, 20px)/1.4 var(--sans); letter-spacing: -0.01em; text-wrap: balance; color: var(--st-fg); }
.live-btn { font: 500 13px var(--sans); padding: 8px 14px; border-radius: 8px; border: 1px solid #3a3a3a; background: rgba(0,0,0,.4);
  color: var(--st-fg); cursor: pointer; text-decoration: none; }
.live-btn.solid { background: var(--st-fg); color: #050505; border-color: var(--st-fg); }
.live-btn[disabled] { opacity: .45; cursor: default; }
.live-btn:focus-visible { outline: 2px solid var(--st-fg); outline-offset: 2px; }
.live-side { display: flex; flex-direction: column; min-width: 0; max-height: calc(100vh - 57px); }
.live-counters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--st-line); }
.live-counters div { padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--st-line); min-width: 0; }
.live-counters div:last-child { border-right: 0; }
.live-counters b { font: 600 24px var(--mono); font-variant-numeric: tabular-nums; }
.live-counters span { font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--st-dim); }
.live-panel { padding: 16px; border-bottom: 1px solid var(--st-line); display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.live-panel.grow { flex: 1; overflow: hidden; }
.live-panel h2 { font: 500 11px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--st-dim); }
.live-found { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.live-card { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; text-decoration: none; color: var(--st-fg);
  padding: 10px; border: 1px solid #2a2a2a; border-radius: 8px; background: var(--st-panel); animation: cardin .5s ease-out; }
.live-card:hover { border-color: #555; }
.live-card b { font: 600 18px var(--mono); display: grid; place-items: center; height: 44px; border-radius: 6px; background: var(--st-fg); color: #050505; }
.live-card b.mid { background: transparent; color: var(--st-fg); border: 2px solid var(--st-fg); }
.live-card strong { font-size: 13px; display: block; }
.live-card span { font-size: 12px; color: #b5b5b5; display: block; overflow-wrap: anywhere; }
@keyframes cardin { from { opacity: 0; transform: translateY(6px); } }
.live-empty { font-size: 13px; color: var(--st-dim); }
.live-log { list-style: none; margin: 0; padding: 0; font: 12px/1.55 var(--mono); color: #b8b8b8; overflow-y: auto; height: 100%;
  display: flex; flex-direction: column; gap: 2px; }
.live-log li { display: grid; grid-template-columns: 44px 52px minmax(0, 1fr); gap: 8px; }
.live-log li .t { color: #5f5f5f; }
.live-log li .k { color: var(--st-fg); }
.live-log li.dim { color: #6b6b6b; }
.live-log li.err .k, .live-log li.err { color: #fff; text-decoration: underline dotted; }
.live-log li .m { overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .live { grid-template-columns: 1fr; }
  .live-stage { min-height: 64vh; border-right: 0; border-bottom: 1px solid var(--st-line); }
  .live-side { max-height: none; }
  .live-log { max-height: 320px; }
  .live-say { bottom: 70px; }
}
@media (prefers-reduced-motion: reduce) { .live-dot.on, .live-card { animation: none; } }
