/* Static, signal study: a locked room is three bars, one per person, each as
 * tall as that person's chance at the door. Open rooms are plain floor where
 * the crew stand. Everything with a plus sign is heat. */

@font-face { font-family: "Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("./fonts/IBMPlexMono-500.woff2") format("woff2"); }
@font-face { font-family: "Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("./fonts/IBMPlexSans-400.woff2") format("woff2"); }

:root {
  color-scheme: light;
  --bg: #ffffff; --ink: #000000; --text: #111111; --sub: #5e5e5e; --line: #d4d4d4;
  --guide: #8f8f8f; --band: rgba(0,0,0,.05); --grain: multiply;
  --blue: #2463eb; --yellow: #ffd600; --red: #e52a2a;
  --mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000; --ink: #ffffff; --text: #ededed; --sub: #a6a6a6; --line: #2f2f2f;
    --guide: #8f8f8f; --band: rgba(255,255,255,.07); --grain: screen;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000; --ink: #ffffff; --text: #ededed; --sub: #a6a6a6; --line: #2f2f2f;
  --guide: #8f8f8f; --band: rgba(255,255,255,.07); --grain: screen;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
[hidden] { display: none !important; }

/* The page itself picks up grain as heat rises. */
body::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 5; background: url("./noise.svg"); mix-blend-mode: var(--grain); opacity: calc(var(--static, 0) * .5); transition: opacity .6s; }
body.jolt::after { opacity: .9; transition: none; }

#app { height: 100dvh; min-height: 30rem; max-width: 46rem; margin: 0 auto; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 10px; padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }

/* ---------- top: progress and tools ---------- */
.top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.job { margin: 0; font: 500 .9375rem/1 var(--mono); font-variant-numeric: tabular-nums; }
.job span { color: var(--sub); margin-left: .9em; }
.tools { display: flex; gap: 4px; margin-right: -10px; }
.ib { width: 44px; height: 44px; display: grid; place-items: center; }
.ib svg { width: 24px; height: 24px; }

/* ---------- heat ---------- */
.heat-row { margin: 0 0 6px; display: flex; align-items: center; gap: 8px; min-height: 22px; font: 500 .9375rem/1 var(--mono); font-variant-numeric: tabular-nums; }
.heat-word { font-family: var(--sans); font-weight: 400; }
.heat-max { margin-left: auto; color: var(--sub); }
.chip, .tag { display: inline-grid; place-items: center; height: 20px; min-width: 20px; padding: 0 5px; font: 500 .75rem/1 var(--mono); font-variant-numeric: tabular-nums; border: 1.5px solid var(--ink); }
.chip.sure, .tag.sure, .tag.q { background: var(--ink); color: var(--bg); }
.chip.risk, .tag.risk { border-style: dashed; }
.chip.was { border-color: transparent; color: var(--sub); padding: 0; animation: was 2.6s forwards; }
@keyframes was { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
.heat { position: relative; height: 14px; border: 1.5px solid var(--ink); overflow: hidden; }
.heat > div { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .45s cubic-bezier(.2,.7,.2,1); }
.heat-fill { background: var(--ink); }
.heat-sure { background: var(--guide); }
.heat-maybe { background: repeating-linear-gradient(-45deg, var(--guide) 0 1.5px, transparent 1.5px 5px); }
.heat-notch { position: absolute; left: 60%; top: 0; bottom: 0; width: 2px; background: var(--guide); }

/* ---------- board ---------- */
.board { min-height: 0; display: grid; place-items: center; overflow: auto; }
.scene { position: relative; flex: none; --room: 100px; --tok: calc(var(--room) * .38); --in: calc(var(--room) * .09); }
.lines, .moves { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.lines line { stroke: var(--guide); stroke-width: 1.5; }
.moves { z-index: 4; }
.moves polygon { stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; }

.room { position: absolute; width: var(--room); height: var(--room); background: var(--bg); border: 2px solid var(--ink); }
.room.open { border: 1.5px solid var(--guide); }
.room.open.exit.ready { border: 3px solid var(--ink); }
.room.jolt { animation: jolt .42s steps(2, end) 2; }
.room.opened { animation: opened .7s ease-out; }
@keyframes jolt { 0% { transform: translate(0,0); } 25% { transform: translate(-3px,2px); } 50% { transform: translate(3px,-2px); } 75% { transform: translate(-2px,-1px); } 100% { transform: translate(0,0); } }
@keyframes opened { from { background: var(--ink); } to { background: var(--bg); } }

.tags { position: absolute; left: -2px; right: -2px; bottom: calc(100% + 4px); display: flex; gap: 4px; align-items: center; pointer-events: none; }
.tags .tag.risk, .tags .tag.sure:not(.q) { margin-left: auto; }
.tags .tag.lead { border-width: 0 0 1.5px; padding: 0; }

.floor { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }
.room.target .floor { z-index: 3; }
.floor:disabled { pointer-events: none; }

/* three bars: who can get in, and how surely */
.cols { position: absolute; inset: 6px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; z-index: 2; }
.room.open .cols { display: none; }
.col { --c: var(--blue); display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 3px; min-width: 0; }
.col[data-c="1"] { --c: var(--yellow); }
.col[data-c="2"] { --c: var(--red); }
.track { position: relative; border: 1px solid var(--line); overflow: hidden; }
.fill { position: absolute; inset: auto 0 0 0; height: calc(var(--p, 0) * 100%); background: var(--c); opacity: .34; transition: height .35s cubic-bezier(.2,.7,.2,1), opacity .2s; }
.num { height: 1.05em; font: 500 clamp(.6875rem, calc(var(--room) * .12), .9375rem)/1 var(--mono); font-variant-numeric: tabular-nums; text-align: center; color: var(--sub); }
.col.can .track { border-color: var(--ink); }
.col.can .fill { opacity: 1; box-shadow: inset 0 2px 0 var(--ink); }
.col.can .num { color: var(--text); }
.col.can:hover .track { box-shadow: 0 0 0 1.5px var(--ink); }
.col.on .track { box-shadow: 0 0 0 2.5px var(--ink); }
.col.on .num { background: var(--ink); color: var(--bg); }
.col.mute .fill { opacity: .12; box-shadow: none; }
.col.mute .track { border-color: var(--line); }
.col.mute .num { color: var(--line); }
.col.missed .track { animation: missed .9s steps(3, end); }
/* last turn's miss stays struck through until the next plan */
.col.miss .track::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top right, transparent calc(50% - 1.25px), var(--ink) calc(50% - 1.25px) calc(50% + 1.25px), transparent calc(50% + 1.25px)); }
@keyframes missed { 0%, 100% { background: transparent; } 20%, 60% { background: var(--ink); } }
.invite .col:enabled .fill { animation: invite 1.6s ease-in-out 3; animation-delay: calc(var(--i, 0) * .16s + .5s); }
@keyframes invite { 0%, 100% { transform: none; } 40% { transform: translateY(-5px); } }

/* open rooms: one marker in the free quadrant */
.mark { position: absolute; right: var(--in); bottom: var(--in); width: var(--tok); height: var(--tok); display: none; place-items: end; color: var(--guide); pointer-events: none; }
.mark svg { width: 68%; height: 68%; }
.room.exit .mark.m-exit, .room.found .mark.m-found { display: grid; }
.room.exit.ready .mark.m-exit, .room.found .mark.m-found { color: var(--ink); }
.room.exit.found .mark.m-exit { display: none; }

/* ---------- crew ---------- */
.tok { --c: var(--blue); --sym: #fff; position: absolute; left: 0; top: 0; width: var(--tok); height: var(--tok); z-index: 3; transition: transform .5s cubic-bezier(.2,.8,.2,1); }
.tok[data-c="1"] { --c: var(--yellow); --sym: #000; }
.tok[data-c="2"] { --c: var(--red); --sym: #000; }
.tok svg { display: block; width: 100%; height: 100%; }
.tok .tile { fill: var(--c); }
.tok .sym { fill: none; stroke: var(--sym); stroke-width: 1.7; stroke-linecap: square; }
.scene.still .tok { transition: none; }
.tok.picked { outline: 3px solid var(--ink); outline-offset: 3px; }
.tok.hit svg { animation: jolt .42s steps(2, end) 2; }
.tok .hp { position: absolute; left: 0; top: calc(100% + 3px); display: flex; gap: 2px; }
.tok .hp i { width: 5px; height: 5px; background: var(--ink); }
.tok .hp i.lost { background: none; box-shadow: inset 0 0 0 1px var(--guide); }
.ghost { position: absolute; left: 0; top: 0; width: var(--tok); height: var(--tok); z-index: 2; border: 2px dashed var(--ink); background: color-mix(in srgb, var(--c) 30%, transparent); pointer-events: none; }
.ghost[data-c="0"] { --c: var(--blue); } .ghost[data-c="1"] { --c: var(--yellow); } .ghost[data-c="2"] { --c: var(--red); }

/* ---------- result: takes the approach row's place, so the board holds still ---------- */
.done { align-self: center; min-width: 0; }
.done h2 { margin: 0; font: 400 1.0625rem/1.2 var(--sans); }
.done p { margin: 2px 0 0; color: var(--sub); font: 400 .8125rem/1.3 var(--sans); }

/* ---------- the turn: how, then go ---------- */
.bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1.5px solid var(--ink); }
.seg button { height: 56px; display: grid; align-content: center; justify-items: center; gap: 3px; }
.seg button + button { border-left: 1.5px solid var(--ink); }
.ap-name { font-size: 1.0625rem; line-height: 1; }
.ap-cost { font: 500 .75rem/1 var(--mono); color: var(--sub); }
.seg button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.seg button[aria-checked="true"] .ap-cost { color: inherit; }
.seg:focus-within :focus-visible { outline-offset: -6px; outline-color: var(--guide); }
.go { height: 56px; min-width: 6.5rem; padding: 0 1.25rem; font-size: 1.0625rem; background: var(--ink); color: var(--bg); border: 1.5px solid var(--ink); }
.go:disabled { background: none; color: var(--guide); border-color: var(--line); }
.bar.over .seg { display: none; }

/* ---------- sheets ---------- */
.sheet { width: min(30rem, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0 20px 20px; border: 1.5px solid var(--ink); background: var(--bg); color: var(--text); }
.sheet::backdrop { background: color-mix(in srgb, var(--bg) 82%, transparent); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-right: -10px; }
.sheet-head h2 { margin: 0; font: 500 1rem/1 var(--mono); }
.legend { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 14px; }
.legend li { display: grid; grid-template-columns: 52px 1fr; gap: 14px; align-items: center; line-height: 1.45; }
.lg { display: grid; place-items: center; }
.lg-exit svg { width: 30px; height: 30px; }
.lg-bars { display: flex; align-items: flex-end; gap: 3px; width: 46px; height: 46px; padding: 4px; border: 2px solid var(--ink); }
.lg-bars i { flex: 1; height: calc(var(--p) * 100%); background: var(--c); box-shadow: inset 0 2px 0 var(--ink); }
.setting-row { display: flex; align-items: center; justify-content: space-between; min-height: 52px; border-top: 1px solid var(--line); }
.text-action { min-height: 44px; padding: 0 2px; text-decoration: underline; text-underline-offset: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .fill { forced-color-adjust: none; }
  .tok .tile { forced-color-adjust: none; }
}

/* Double-tap zoom: touch-action is intersected across every ancestor, so
   manipulation on the root stops double-tap zoom page-wide (readouts, gaps
   between controls, sheet backdrops) while pinch zoom still works. */
html, body { touch-action: manipulation; }
