/* Style tokens and the page frame are copied from march-sim (see docs/MERGE.md); the rest is this simulator's own. */
:root {
  --bg: #15181c; --panel: #1e2228; --panel2: #262b33; --line: #343a44;
  --text: #e6e8eb; --muted: #9aa3ad; --accent: #e0a526; --red: #d9413d; --green: #4caf6e; --blue: #4d9be6;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; display: flex; flex-direction: column; min-height: 100vh; }
button, input, textarea, select { font: inherit; }
h2 { font-size: 15px; margin: 0; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
h2 small { text-transform: none; font-weight: normal; margin-left: 6px; }
.mono { font-variant-numeric: tabular-nums; }
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 4px 10px; font-size: 13px; }

/* top bar */
#topbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 800; letter-spacing: .12em; color: var(--accent); font-size: 18px; background: none; border: 0; cursor: pointer; padding: 0; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; white-space: nowrap; }
.chip.warn { border-color: var(--red); color: #ff9b98; }
.chip.ok { border-color: var(--green); color: #9fe0b4; }
.tension { display: flex; align-items: center; gap: 8px; }
.tlabel { font-size: 12px; color: var(--muted); }
.tbar { position: relative; width: 150px; height: 16px; background: #0e1013; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
#tfill { height: 100%; width: 0; transition: width .4s, background .4s; }
#tfill.high { background: var(--red); } #tfill.mid { background: var(--accent); } #tfill.low { background: var(--green); }
#tnum { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 0 3px #000; }
.controls { display: flex; gap: 6px; margin-left: auto; }

/* layout */
#layout { display: grid; grid-template-columns: 300px minmax(320px, 1fr); gap: 12px; padding: 12px; flex: 1; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); gap: 8px; }
.panel-body { padding: 10px 12px; overflow: auto; flex: 1; }

/* the six steps and the memo */
.steps { list-style: none; margin: 0 0 10px; padding: 0; }
.steps li { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px 7px 34px; margin-bottom: 6px; position: relative; background: var(--panel2); }
.steps li::before { content: attr(data-n); }
.steps li b { display: block; font-size: 14px; }
.steps li span { display: none; font-size: 12.5px; color: #cfd4da; }
.steps li.current { border-color: var(--accent); } .steps li.current span { display: block; }
.steps li::after { content: ""; position: absolute; left: 10px; top: 10px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); }
.steps li.done::after { background: var(--green); border-color: var(--green); }
.steps li.current::after { border-color: var(--accent); }
.memo { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel2); font-size: 13.5px; }
.memo summary { padding: 8px 10px; cursor: pointer; }
.memo p { margin: 0; padding: 0 10px 10px; color: #cfd4da; }
.memo-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 10px 8px; color: #cfd4da; }
.memo-cols p { padding: 4px 0 0; }

/* scene */
#scene { position: relative; display: flex; flex-direction: column; gap: 8px; min-height: 0; min-width: 0; }
.stage-wrap { position: relative; width: 100%; max-width: 820px; margin: 0 auto; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #0e1013; flex: none; }
#sceneHost svg { display: block; width: 100%; height: auto; }
.bubble { position: absolute; top: 8px; max-width: 46%; background: #fff; color: #111; border-radius: 14px; padding: 6px 12px; font-size: 13.5px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 3; }
.bubble.show { opacity: 1; }
.hintbox { background: #11303a; border: 1px solid #4dd2ff; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.hintbox div { color: #bdf0ff; font-size: 13px; }
.signs { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; background: var(--panel); }
.signs h3 { margin: 0 0 4px; font-size: 14px; color: var(--accent); }
.signs ul { margin: 0; padding-left: 18px; font-size: 14px; }
.signs .ctx { margin-top: 6px; font-size: 13px; color: var(--muted); }
.log { font-size: 13px; overflow: auto; border-top: 1px solid var(--line); padding-top: 6px; flex: 1 1 auto; min-height: 90px; }
.log div { padding: 2px 4px; color: #cfd4da; border-radius: 4px; }
.log .new { background: rgba(224,165,38,.16); }
.log .t { color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }
.log .warn { color: #ffb3b0; } .log .death { color: var(--red); font-weight: 600; } .log .ok { color: #9fe0b4; } .log .find { color: #f3d58a; } .log .say { color: #fff; font-style: italic; } .log .sys { color: var(--muted); }
.busy { position: absolute; inset: 0; background: rgba(21,24,28,.75); z-index: 16; display: grid; place-content: center; justify-items: center; border-radius: var(--radius); }
.busy-label { font-size: 16px; margin-bottom: 10px; text-align: center; padding: 0 12px; }
.busy-bar { width: 240px; max-width: 80vw; height: 10px; background: #0e1013; border-radius: 5px; overflow: hidden; }
#busyFill { height: 100%; width: 0; background: var(--accent); }

/* the scene drawing */
.scene-svg .sky { fill: #1c2431; } .scene-svg .sky.calm { fill: #27323f; } .scene-svg .room { fill: #20252d; }
.scene-svg .ground { fill: #2b2f36; }
.scene-svg .cover rect, .scene-svg .cover path { fill: #3a424e; stroke: #566070; stroke-width: 2; }
.scene-svg .ruins path, .scene-svg .wall rect { fill: #333a44; }
.scene-svg .bench rect { fill: #4a4132; } .scene-svg .beam { stroke: #333a44; stroke-width: 6; }
.scene-svg .lamp path { stroke: #566070; stroke-width: 3; fill: none; } .scene-svg .lamp circle { fill: #e8d48a; }
.scene-svg .alarm circle { fill: var(--red); animation: alarm 1s infinite; }
.scene-svg .scenelabel { fill: #9aa3ad; font-size: 13px; text-anchor: middle; }
.scene-svg .dist { stroke: #9aa3ad; stroke-width: 2; stroke-dasharray: 6 5; fill: none; }
.scene-svg .blasts circle { fill: #ff8a3d; opacity: .0; animation: blast .9s infinite; transform-box: fill-box; transform-origin: center; }
.scene-svg .blasts circle:nth-child(2) { animation-delay: .3s; } .scene-svg .blasts circle:nth-child(3) { animation-delay: .6s; }
.scene-svg.firing .sky { fill: #3a2024; }
@keyframes blast { 0% { opacity: .85; transform: scale(.3); } 100% { opacity: 0; transform: scale(1.5); } }
@keyframes alarm { 50% { opacity: .25; } }
.fig .limb { stroke: var(--tone, #9aa3ad); stroke-width: 5; stroke-linecap: round; fill: none; }
.fig .head { fill: #2a3039; stroke: var(--tone, #9aa3ad); stroke-width: 4; }
.fig .f-dot { fill: #e6e8eb; } .fig .f-line { stroke: #e6e8eb; stroke-width: 1.6; fill: none; stroke-linecap: round; } .fig .f-ring { stroke: #e6e8eb; stroke-width: 1.4; fill: none; }
.fig .tear { stroke: #6ec6ff; stroke-width: 2; fill: none; stroke-linecap: round; }
.fig .figlabel { fill: #e6e8eb; font-size: 13px; text-anchor: middle; }
.fig.you .body { --tone: #4d9be6; }
.crowd .limb { stroke: #566070; stroke-width: 4; fill: none; stroke-linecap: round; } .crowd .head { fill: #2a3039; stroke: #566070; stroke-width: 3; }
.fig.jitter .body { animation: jitter .25s infinite; } .fig.tremble .body { animation: jitter .12s infinite; }
.fig.wave .body { animation: wave .6s infinite alternate; } .fig.pace .body { animation: pace 1.6s infinite alternate ease-in-out; } .fig.sway .body { animation: sway 2s infinite alternate ease-in-out; }
@keyframes jitter { 0% { transform: translateX(-1.5px); } 100% { transform: translateX(1.5px); } }
@keyframes wave { to { transform: translateY(-4px); } } @keyframes pace { to { transform: translateX(30px); } } @keyframes sway { to { transform: rotate(4deg); } }
@media (prefers-reduced-motion: reduce) { .fig .body, .scene-svg .blasts circle, .scene-svg .alarm circle { animation: none !important; } }

/* actions */
.agroup { margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.agroup > h3 { margin: 0; padding: 8px 10px; font-size: 14px; background: var(--panel2); cursor: pointer; display: flex; justify-content: space-between; }
.agroup > h3 small { color: var(--muted); }
.aitems { display: none; padding: 6px; gap: 5px; flex-direction: column; }
.agroup.open .aitems { display: flex; }
.aitem { display: flex; justify-content: space-between; gap: 8px; text-align: left; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 14px; }
.aitem:hover { border-color: var(--accent); }
.aitem i { color: var(--muted); font-style: normal; font-size: 12px; white-space: nowrap; }
.aitem.hint { border-color: #4dd2ff; color: #bdf0ff; animation: hintBlink .8s ease-in-out infinite; }
@keyframes hintBlink { 50% { box-shadow: 0 0 0 4px rgba(77,210,255,.4); } }
.identify { border: 1px solid var(--accent); border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 5px; }
.identify h3 { margin: 2px 4px 4px; font-size: 14px; color: var(--accent); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: max(12px, env(safe-area-inset-top)) 12px; overflow-y: auto; height: 100vh; height: 100dvh; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(560px, 100%); margin: auto; flex: none; overflow-wrap: anywhere; }
.modal-box h1 { margin: 0 0 6px; color: var(--accent); letter-spacing: .12em; }
.modal-box label { display: block; margin: 12px 0 8px; color: var(--muted); font-size: 13px; }
.modal-box input[type=text], .modal-box select { width: 100%; background: #0e1013; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 16px; margin-top: 4px; }
.modal-box .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.modal-box .row .btn { flex: 1 1 auto; }
.howto { color: #cfd4da; font-size: 14px; padding-left: 20px; }
.codebox { margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; }
.codebox input { text-transform: uppercase; letter-spacing: .2em; font-family: ui-monospace, Menlo, monospace; }
.codebox .btn { margin-top: 6px; }
.codemsg { font-size: 13px; margin-top: 6px; color: var(--muted); } .codemsg.bad { color: #ff9b98; }

/* result */
.debrief-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.score { font-size: 42px; font-weight: 800; color: var(--accent); }
.outcome { font-size: 20px; font-weight: 700; } .outcome.dead { color: var(--red); } .outcome.alive { color: var(--green); }
#debrief h3 { margin: 16px 0 6px; font-size: 15px; }
.finding { padding: 6px 10px; border-left: 3px solid var(--line); margin-bottom: 5px; font-size: 14px; background: var(--panel2); border-radius: 0 6px 6px 0; }
.finding.critical { border-color: var(--red); } .finding.major { border-color: #e98b3a; } .finding.minor { border-color: #b8b8b8; } .finding.good { border-color: var(--green); }
.finding .sev { font-size: 11px; text-transform: uppercase; color: var(--muted); margin-right: 6px; }
.parts { width: 100%; font-size: 14px; border-collapse: collapse; } .parts td { padding: 3px 6px; border-bottom: 1px solid var(--line); } .parts td:last-child { text-align: right; } .parts .pen td { color: #ff9b98; }
.timeline { width: 100%; font-size: 13px; border-collapse: collapse; margin-top: 6px; }
.timeline td { padding: 3px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.timeline tr.bad td:first-child { color: var(--red); }
.runcode { margin-bottom: 10px; padding: 8px 10px; border: 1px dashed var(--accent); border-radius: 8px; } .runcode b { font-family: ui-monospace, Menlo, monospace; letter-spacing: .2em; font-size: 18px; } .runcode.bad { border-color: var(--red); }
.debrief-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.debrief-actions .btn { width: 100%; min-width: 0; text-align: center; white-space: normal; line-height: 1.2; padding: 9px 10px; }
#resultTab { display: none; } #resultTab .result-body { padding: 14px; overflow-y: auto; }
#resultTabBtn[hidden], #resultBtn[hidden] { display: none; }

/* tabs (mobile) */
#tabs { display: none; }
@media (max-width: 900px) {
  #layout { display: block; padding: 8px 8px calc(16px + env(safe-area-inset-bottom)); }
  #tabs { display: flex; position: sticky; top: 0; z-index: 25; background: var(--panel); border-bottom: 1px solid var(--line); }
  #tabs button { flex: 1; background: none; border: 0; color: var(--muted); padding: 10px 2px; font-size: 13.5px; border-bottom: 3px solid transparent; }
  #tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
  #topbar { position: static; padding: 6px 10px; gap: 6px 8px; }
  .brand { display: none; }
  .tension { flex: 1 1 120px; } .tbar { flex: 1; width: auto; }
  .tlabel { display: none; }
  .controls { margin-left: auto; }
  #layout > [data-tab] { display: none !important; }
  #layout > [data-tab].active-tab { display: flex !important; }
  #resultBtn { display: none !important; } #resultClose { display: none; }
  .bubble { max-width: 60%; font-size: 12.5px; padding: 4px 9px; }
  .modal-box { padding: 14px; }
}
@media (min-width: 901px) {
  body { height: 100vh; overflow: hidden; }
  #layout { overflow: hidden; }
  #layout > aside, #scene { min-height: 0; height: 100%; }
  #scene { overflow-y: auto; overflow-x: hidden; }
  body.result-open #resultTab { display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 45; background: var(--bg); overflow: hidden; }
  body.result-open #resultTab .result-body { width: min(900px, 100%); margin: 0 auto; flex: 1; }
  #resultTab .panel-head { max-width: 900px; width: 100%; margin: 0 auto; }
}
@media (max-width: 340px) { .debrief-actions { grid-template-columns: 1fr; } }


/* the stage: tiles either side of the person (as in MARCH), the picture between */
.stage { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; width: 100%; align-items: start; flex: none; }
.stage-wrap { max-width: none; margin: 0; min-width: 0; }
.side-actions { display: grid; grid-template-columns: 70px; gap: 6px; align-content: start; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 66px; padding: 8px 4px 6px; background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; color: var(--text); cursor: pointer; }
.tile:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.tile:disabled { opacity: .35; cursor: default; }
.tile .cap { font-size: 11.5px; line-height: 1.15; text-align: center; }
.tile .badge { position: absolute; top: 3px; right: 5px; font-size: 10px; font-style: normal; color: var(--muted); }
.tile.hint { border-color: #4dd2ff; color: #bdf0ff; animation: hintBlink .8s ease-in-out infinite; }
.icon { flex: none; }
.popover { position: fixed; z-index: 30; background: var(--panel2); border: 1px solid var(--accent); border-radius: 10px; padding: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.popover h4 { margin: 0 0 6px; font-size: 13px; color: var(--accent); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.popover .close { cursor: pointer; color: var(--muted); background: none; border: 0; font-size: 15px; }
.pitems { display: flex; flex-direction: column; gap: 5px; }
.pnav { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; color: var(--muted); font-size: 13px; }
.pnav .btn { min-width: 44px; }
.toasts { position: absolute; left: 6px; right: 6px; top: 6px; z-index: 4; display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.toast { pointer-events: auto; background: rgba(30,34,40,.92); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 7px; padding: 4px 9px; font-size: 13px; animation: toastIn .3s ease-out; }
.toast.ok { border-left-color: var(--green); } .toast.warn, .toast.death { border-left-color: var(--red); color: #ffd0ce; } .toast.find { border-left-color: #f3d58a; } .toast.say { border-left-color: #fff; font-style: italic; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }
.autohelp { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.autohelp input { accent-color: var(--accent); }
.bubble { top: auto; bottom: 8px; }
@media (max-width: 900px) {
  .stage { grid-template-columns: 58px minmax(0, 1fr) 58px; gap: 5px; }
  .side-actions { grid-template-columns: 58px; gap: 5px; }
  .tile { min-height: 56px; padding: 6px 2px 4px; }
  .tile .cap { font-size: 10px; }
  .tile .badge { right: 3px; }
  .toast { font-size: 12px; padding: 3px 7px; }
}

/* top bar as in MARCH: one compact row, the orange home button, icon chips, the bar takes the room that is left */
#topbar { display: flex !important; flex-wrap: nowrap; align-items: center; gap: 8px; padding: 4px 10px; padding-top: max(4px, env(safe-area-inset-top)); min-height: 0; position: sticky; }
#topbar .brand.home { display: inline-flex !important; align-items: center; justify-content: center; flex: none; background: #f07d1a; color: #fff; border: 0; border-radius: 9px; padding: 0 12px; height: 24px; font-size: 13px; font-weight: 800; letter-spacing: .12em; line-height: 1.15; cursor: pointer; box-shadow: 0 1px 0 rgba(0,0,0,.35); }
#topbar .brand.home:hover { background: #ff8e2e; } #topbar .brand.home:active { transform: translateY(1px); }
#topbar .chip.ic { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; font-size: 12px; line-height: 1.2; height: 24px; flex: none; }
#topbar .chip.ic b { font-weight: 600; font-variant-numeric: tabular-nums; }
#topbar .chip.ok { border-color: var(--green); color: #9fe0b4; }
.hpwrap { flex: 1 1 auto; min-width: 90px; display: flex; align-items: center; gap: 6px; color: var(--red); }
.hpbar { position: relative; flex: 1; height: 20px; border-radius: 10px; background: #0e1013; border: 1px solid var(--line); overflow: hidden; }
#tfill { border-radius: 9px 0 0 9px; }
#tnum { font-size: 12px; }
#topbar .controls { display: flex; align-items: center; gap: 4px; margin-left: auto; flex: none; }
#topbar .btn.small { padding: 2px 8px; font-size: 13px; height: 24px; line-height: 1; }
.autohelp { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 24px; margin: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); color: var(--muted); cursor: pointer; }
.autohelp input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.autohelp:has(input:checked) { color: #bdf0ff; border-color: #4dd2ff; background: #10303b; }
.autohelp:has(input:focus-visible) { outline: 2px solid var(--accent); }
@media (max-width: 900px) { #topbar { position: static; } #topbar .brand { display: inline-flex !important; } }
@media (max-width: 520px) { #placeChip { display: none !important; } #topbar { gap: 6px; padding: 4px 8px; } #topbar .chip.ic { padding: 2px 5px; font-size: 11.5px; } .hpwrap { min-width: 60px; } #resultBtn { display: none !important; } }
.toasts { position: static; left: auto; right: auto; top: auto; }

/* the pop-up: all the actions at once, cards in two columns */
.popover { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); overflow-y: auto; }
.pitems { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pitems .aitem { flex-direction: column; justify-content: space-between; min-height: 58px; font-size: 13px; padding: 7px 8px; gap: 4px; }
.pitems .aitem i { align-self: flex-end; }
