/* fow-cache demo styles. */
[hidden] { display: none !important; }
img { max-width: 100%; }
body { margin: 0; }

/* Layout: control bar + score strip, then three columns: User 1 chat | the guard's decision trace + cache | User 2 chat. Stage view keeps only the three columns. */
:root {
  --bg: #eef1f3;
  --panel: #ffffff;
  --sunk: #f5f7f8;
  --ink: #141a21;
  --muted: #5d6874;
  --line: #d9dfe4;
  --accent: #c76d00;        /* Jev: every yes/no decision */
  --accent-soft: #fbecd6;
  --hit: #12805a;
  --hit-soft: #ddf2e8;
  --trap: #c2362b;
  --trap-soft: #fbe3e0;
  --ub-bg: #1e2833;
  --ub-fg: #f3f6f8;
  --bb-bg: #eef1f4;
  --say-bg: #1b2129;
  --say-fg: #f5f7f9;
  --font-display: "Familjen Grotesk", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1217; --panel: #161c23; --sunk: #11161c; --ink: #e7ecf0; --muted: #94a0ac; --line: #29313a;
    --accent: #f0a443; --accent-soft: #3a2a13; --hit: #3cc58d; --hit-soft: #133126; --trap: #f2695e; --trap-soft: #3b1a17;
    --ub-bg: #dfe6ec; --ub-fg: #121820; --bb-bg: #1f262e; --say-bg: #f3f5f7; --say-fg: #141a21; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1217; --panel: #161c23; --sunk: #11161c; --ink: #e7ecf0; --muted: #94a0ac; --line: #29313a;
  --accent: #f0a443; --accent-soft: #3a2a13; --hit: #3cc58d; --hit-soft: #133126; --trap: #f2695e; --trap-soft: #3b1a17;
  --ub-bg: #dfe6ec; --ub-fg: #121820; --bb-bg: #1f262e; --say-bg: #f3f5f7; --say-fg: #141a21; color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 14px; line-height: 1.45;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 18px 28px;
}
.wrap { max-width: 1320px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
button, select { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* top bar */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-family: var(--font-display); font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.brand span { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; background: var(--sunk); border: 1px solid var(--line); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 7px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); min-width: 84px; }
.btn:disabled { opacity: .45; cursor: default; }
.controls select { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 8px; }
.kbd { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

/* score strip */
.scores { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1.6fr; gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile .lab { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.tile .val { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .sub { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile.money .val { color: var(--hit); }
.bump { animation: bump .6s ease; }
@keyframes bump { 30% { transform: scale(1.035); box-shadow: 0 0 0 3px var(--hit-soft); } }
.tile.plain .val { font-size: 17px; font-family: var(--font-body); font-weight: 600; letter-spacing: 0; }
.tile.plain .val .bad { color: var(--trap); }
.scale { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.scale button { border: 0; background: transparent; padding: 1px 7px; font-size: 10.5px; cursor: pointer; color: var(--muted); letter-spacing: .02em; text-transform: none; }
.scale button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.intro { color: var(--muted); max-width: 90ch; margin: 0; }
.intro b { color: var(--ink); font-weight: 600; }

/* main grid */
.stage { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.08fr) minmax(0,1fr); gap: 12px; align-items: stretch; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; min-width: 0; height: 640px; }
.ph { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-family: var(--font-display); background: var(--ub-bg); color: var(--ub-fg); flex: none; }
.ph .t { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.ph .s { font-size: 12px; color: var(--muted); }
.stage-saved { display: none; margin-left: auto; text-align: right; font-family: var(--font-mono); font-size: 11px; color: var(--muted); line-height: 1.25; border-radius: 8px; padding: 3px 6px; }
.stage-saved b { display: block; font-family: var(--font-display); font-size: 20px; color: var(--hit); font-variant-numeric: tabular-nums; }
.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.empty { color: var(--muted); font-size: 13px; margin: auto; text-align: center; max-width: 30ch; }

.b { max-width: 88%; padding: 9px 12px; border-radius: 14px; animation: rise .35s ease both; overflow-wrap: anywhere; }
.b.user { align-self: flex-end; background: var(--ub-bg); color: var(--ub-fg); border-bottom-right-radius: 4px; }
.b.bot { align-self: flex-start; background: var(--bb-bg); border-bottom-left-radius: 4px; }
.b.bot.cached { background: var(--hit-soft); box-shadow: inset 0 0 0 1.5px var(--hit); }
.b .badge { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.b.cached .badge { color: var(--hit); font-weight: 600; }
.b.ghost { align-self: flex-start; background: transparent; border: 1.5px dashed var(--trap); color: var(--muted); }
.b.ghost .gl { font-family: var(--font-mono); font-size: 10.5px; color: var(--trap); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.b.ghost .gt { text-decoration: line-through; text-decoration-color: var(--trap); }
.b.ghost .gw { margin-top: 6px; font-size: 12px; color: var(--trap); }
.typing { align-self: flex-start; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-family: var(--font-mono); animation: rise .3s ease both; }
.dots { display: inline-flex; gap: 3px; background: var(--bb-bg); padding: 9px 11px; border-radius: 14px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* guard panel */
.guard .ph .avatar { background: var(--accent); color: var(--panel); font-size: 13px; }
.trace { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.turn { border: 1px solid var(--line); border-radius: 10px; background: var(--sunk); animation: rise .3s ease both; }
.turn .th { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; font-size: 12px; font-weight: 600; cursor: pointer; }
.turn .th .who { color: var(--muted); font-family: var(--font-mono); font-weight: 500; }
.turn .steps { display: flex; flex-direction: column; gap: 8px; padding: 0 10px 10px; }
.turn.collapsed .steps { display: none; }
.pill { font-family: var(--font-mono); font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 99px; letter-spacing: .03em; white-space: nowrap; }
.pill.hit { background: var(--hit-soft); color: var(--hit); }
.pill.miss { background: var(--panel); color: var(--muted); border: 1px solid var(--line); }
.pill.block { background: var(--trap-soft); color: var(--trap); }
.pill.run { background: var(--accent-soft); color: var(--accent); }
.step { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; animation: rise .3s ease both; display: flex; flex-direction: column; gap: 6px; }
.step .sh { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600; }
.step .sh .k { font-family: var(--font-mono); font-weight: 500; color: var(--muted); font-size: 11px; }
.step.jev { border-color: var(--accent); }
.step.jev .sh .name { color: var(--accent); }
.step .q { font-size: 12.5px; color: var(--muted); }
.step .q b { color: var(--ink); font-weight: 500; }
.gauge { position: relative; height: 8px; border-radius: 99px; background: var(--sunk); border: 1px solid var(--line); overflow: visible; }
.gfill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 99px; background: var(--accent); transition: width .7s cubic-bezier(.2,.7,.2,1); }
.gtick { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); border-radius: 2px; }
.gmeta { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.gmeta .p { color: var(--ink); font-weight: 600; }
.verdict { font-size: 12px; font-weight: 600; }
.verdict.ok { color: var(--hit); } .verdict.no { color: var(--trap); }
.rw { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.rw div { background: var(--sunk); border-radius: 6px; padding: 6px 8px; font-size: 12.5px; min-width: 0; }
.rw small { display: block; font-family: var(--font-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
mark { background: var(--trap-soft); color: var(--trap); font-weight: 600; border-radius: 3px; padding: 0 2px; }
.note { font-size: 12px; color: var(--ink); border-left: 2px solid var(--accent); padding-left: 8px; }

.cache { border-top: 1px solid var(--line); padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; max-height: 210px; overflow-y: auto; }
.cache h3 { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); display: flex; justify-content: space-between; }
#cache-list { display: flex; flex-direction: column; gap: 6px; }
.entry { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 12px; display: flex; flex-direction: column; gap: 2px; animation: rise .35s ease both; transition: box-shadow .3s, border-color .3s; }
.entry .ek { font-weight: 600; }
.entry .ea { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .em { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
.entry.cand { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.entry.served { border-color: var(--hit); box-shadow: 0 0 0 3px var(--hit-soft); }
.entry.rejected { border-color: var(--trap); box-shadow: 0 0 0 3px var(--trap-soft); }

/* the narrator's speech bubble */
.callout { position: fixed; top: 0; left: 0; z-index: 30; max-width: min(320px, calc(100vw - 16px)); background: var(--say-bg); color: var(--say-fg);
  border-radius: 12px; padding: 10px 13px 9px; font-size: 13.5px; line-height: 1.45; box-shadow: 0 8px 28px rgba(0,0,0,.22); cursor: pointer; animation: pop .22s ease both; }
.callout .ct b { font-weight: 600; }
.callout .hint { margin-top: 6px; font-family: var(--font-mono); font-size: 10.5px; opacity: .6; letter-spacing: .03em; }
.callout .hint:empty { display: none; }
.callout .tail { position: absolute; left: calc(var(--tail-x, 50%) - 7px); width: 14px; height: 14px; background: var(--say-bg); transform: rotate(45deg); border-radius: 2px; }
.callout[data-side="below"] .tail { top: -6px; }
.callout[data-side="above"] .tail { bottom: -6px; }
@keyframes pop { from { opacity: 0; scale: .94; } }
.focus-ring { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 10px; }

.coin { position: fixed; z-index: 20; pointer-events: none; font-family: var(--font-mono); font-weight: 700; font-size: 13px; color: var(--hit); background: var(--hit-soft); border: 1px solid var(--hit); padding: 3px 8px; border-radius: 99px; transition: transform .9s cubic-bezier(.5,0,.3,1), opacity .9s; }

.corner { display: none; position: fixed; z-index: 25; right: max(10px, env(safe-area-inset-right, 0px)); bottom: max(10px, env(safe-area-inset-bottom, 0px)); gap: 4px; opacity: .18; transition: opacity .2s; }
.corner:hover, .corner:focus-within { opacity: 1; }
.corner button { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 4px 9px; font-size: 12px; cursor: pointer; }
.corner button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.foot { font-size: 12px; color: var(--muted); max-width: 110ch; display: flex; flex-direction: column; gap: 4px; }
.foot code { font-family: var(--font-mono); font-size: 11.5px; }

/* stage view: only the three columns */
body.stage-only .top, body.stage-only .scores, body.stage-only .intro, body.stage-only .foot { display: none; }
body.stage-only .wrap { max-width: 1480px; }
body.stage-only .panel { height: calc(100dvh - 46px); min-height: 480px; }
body.stage-only .stage-saved { display: block; }
body.stage-only .corner { display: flex; }

@media (max-width: 1020px) {
  .scores { grid-template-columns: 1fr 1fr; }
  .stage { grid-template-columns: 1fr; }
  .panel, body.stage-only .panel { height: auto; min-height: 0; }
  .msgs, .trace { max-height: 460px; min-height: 160px; }
}
@media (max-width: 460px) {
  .scores { grid-template-columns: 1fr; }
  .rw { grid-template-columns: 1fr; }
  .tile .val { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
