:root {
  --ink: #1c2a26; --ink2: #243630; --g1: #36543f; --g2: #496B50; --g4: #78965F; --g6: #A9BE80;
  --paper: #f7f1e1; --paper2: #EDE3CD; --sand: #DED2AC; --s2: #B7A17B; --teal: #3f8a83; --teal2: #6fb3a5;
  --red: #b5473a; --gold: #e9b949; --gold2: #f6dc85; --plum: #6a5470; --w1: #4b6d80;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --deck-h: 0px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); font: 16px/1.4 var(--font); overflow: hidden; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
a { color: var(--teal); }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#screen { position: relative; flex: 1 1 auto; overflow: hidden; background: #101915; min-height: 0; }
#world { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); image-rendering: pixelated; image-rendering: crisp-edges; display: block; touch-action: none; }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 8px; pointer-events: none; z-index: 5; }
#place { background: rgba(28,42,38,.82); border: 2px solid var(--g2); border-radius: 6px; padding: 3px 10px; font-weight: 700; font-size: 13px; letter-spacing: .04em; opacity: 0; transition: opacity .4s; }
#place.show { opacity: 1; }
#hud-buttons { display: flex; gap: 6px; pointer-events: auto; }
.hudbtn { position: relative; display: flex; align-items: center; gap: 6px; background: rgba(28,42,38,.88); border: 2px solid var(--g2); border-radius: 8px; padding: 6px 10px; min-height: 40px; font-weight: 700; font-size: 13px; }
.hudbtn:hover { border-color: var(--g6); }
.badge { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; line-height: 18px; border: 2px solid var(--ink); }
.ico { width: 16px; height: 16px; display: inline-block; background: currentColor; -webkit-mask: var(--m) center/contain no-repeat; mask: var(--m) center/contain no-repeat; }
.ico-book { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 2h5l1 1 1-1h5v11H9l-1 1-1-1H2z'/%3E%3C/svg%3E"); }
.ico-menu { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 3h12v2H2zM2 7h12v2H2zM2 11h12v2H2z'/%3E%3C/svg%3E"); }
#objective { position: absolute; left: 8px; top: 44px; max-width: min(70%, 360px); background: rgba(247,241,225,.92); color: var(--ink); border-left: 4px solid var(--gold); border-radius: 4px; padding: 4px 8px; font-size: 12px; font-weight: 600; z-index: 4; pointer-events: none; }

/* ---------- dialogue ---------- */
#dialog { position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 10; display: flex; gap: 10px; align-items: flex-start; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 10px; box-shadow: inset 0 0 0 2px var(--sand), 0 4px 0 rgba(0,0,0,.35); padding: 10px 12px 12px; max-height: 60%; overflow: auto; }
#dlg-portrait { width: 64px; height: 64px; image-rendering: pixelated; background: var(--sand); border: 2px solid var(--ink); border-radius: 6px; flex: none; }
#dlg-body { flex: 1; min-width: 0; }
#dlg-name { display: inline-block; background: var(--teal); color: var(--paper); font-weight: 800; font-size: 13px; letter-spacing: .04em; padding: 1px 8px; border-radius: 4px; margin-bottom: 4px; }
#dlg-text { margin: 0; font-size: 17px; line-height: 1.38; font-weight: 600; min-height: 2.6em; white-space: pre-wrap; }
#dlg-more { position: absolute; right: 12px; bottom: 6px; color: var(--red); animation: bob .8s steps(2) infinite; font-size: 12px; }
@keyframes bob { 50% { transform: translateY(3px); } }
#dlg-choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.choice { background: var(--paper2); color: var(--ink); border: 2px solid var(--ink); border-radius: 6px; padding: 7px 12px; font-weight: 700; font-size: 15px; min-height: 40px; text-align: left; }
.choice.sel, .choice:hover { background: var(--ink); color: var(--paper); }
.choice.sel::before { content: '▶ '; }

/* ---------- toasts ---------- */
#toasts { position: absolute; left: 50%; top: 52px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 12; pointer-events: none; width: max-content; max-width: 92%; }
.toast { background: var(--ink); color: var(--paper); border: 2px solid var(--gold); border-radius: 8px; padding: 6px 12px; font-weight: 700; font-size: 14px; box-shadow: 0 3px 0 rgba(0,0,0,.4); animation: pop .25s ease-out; transition: opacity .5s, transform .5s; }
.toast.evidence { border-color: var(--gold); } .toast.evidence::before { content: '◆ '; color: var(--gold); }
.toast.theory { border-color: var(--teal2); } .toast.theory::before { content: '✎ '; color: var(--teal2); }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }

/* ---------- panels (notebook, exhibits, menus) ---------- */
#panel { position: absolute; inset: 0; z-index: 20; background: rgba(16,25,21,.86); display: flex; align-items: stretch; justify-content: center; padding: 10px; -webkit-user-select: text; user-select: text; }
.sheet { position: relative; width: min(100%, 860px); background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; box-shadow: inset 0 0 0 2px var(--sand); display: flex; flex-direction: column; overflow: hidden; }
.sheet > header { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--ink); color: var(--paper); }
.sheet > header h2 { margin: 0; font-size: 16px; letter-spacing: .05em; flex: 1; }
.sheet .close { background: var(--red); border: 2px solid var(--paper); color: #fff; border-radius: 8px; min-width: 40px; min-height: 36px; font-weight: 800; }
.sheet .body { flex: 1; overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.tabs { display: flex; gap: 4px; padding: 6px 8px 0; background: var(--sand); flex-wrap: wrap; }
.tabs button { background: var(--paper2); border: 2px solid var(--ink); border-bottom: 0; border-radius: 8px 8px 0 0; padding: 6px 12px; font-weight: 800; font-size: 13px; color: var(--ink); min-height: 36px; }
.tabs button[aria-selected=true] { background: var(--paper); }
.muted { color: #6b6457; }
.small { font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.card { background: #fffaf0; border: 2px solid var(--ink); border-radius: 8px; padding: 8px 10px; text-align: left; color: var(--ink); }
button.card { width: 100%; }
button.card:hover, button.card.sel { background: var(--ink); color: var(--paper); }
button.card:hover .muted, button.card.sel .muted { color: var(--sand); }
.card h3 { margin: 0 0 2px; font-size: 15px; }
.card .meta { font-size: 12px; color: #6b6457; }
/* field guide: what each project is built with, its highlights, a real image and the source */
.grid2.guide { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card.project .built { margin: 6px 0; }
.card.project .hl { margin: 6px 0; padding-left: 18px; }
.card.project .hl li { margin: 3px 0; }
.card.project figure { margin: 8px 0 4px; }
.card.project img { display: block; width: 100%; height: auto; border: 2px solid var(--ink); border-radius: 6px; background: var(--sand); }
.card.project figcaption, .card.project .src { font-size: 12px; color: #6b6457; }
.card.project figcaption { margin-top: 4px; }
.card.project .src { margin: 4px 0 6px; }
/* exhibits end with the same card, collapsed, outside their own scrolling body */
.sheet > details.from-project { flex: none; max-height: 55%; overflow: auto; border-top: 3px solid var(--ink); background: var(--paper2); color: var(--ink); }
.sheet > details.from-project > summary { cursor: pointer; padding: 10px 12px; min-height: 40px; font-weight: 800; font-size: 13px; letter-spacing: .03em; }
.sheet > details.from-project > .card { margin: 0 10px 10px; }
.card.disproved { opacity: .7; } .card.disproved .claim { text-decoration: line-through; text-decoration-color: var(--red); text-decoration-thickness: 2px; }
.stamp { display: inline-block; border: 2px solid var(--red); color: var(--red); font-weight: 900; font-size: 11px; letter-spacing: .1em; padding: 0 5px; transform: rotate(-4deg); border-radius: 3px; }
.btn { background: var(--ink); color: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 8px 14px; font-weight: 800; min-height: 40px; }
.btn.alt { background: var(--paper2); color: var(--ink); }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ev-ico { width: 32px; height: 32px; image-rendering: pixelated; float: left; margin: 0 8px 0 0; background: var(--sand); border-radius: 4px; }
.board-sentence { font-size: 18px; line-height: 2.1; font-weight: 700; }
.board-sentence select { font: inherit; font-size: 16px; padding: 4px 6px; border: 2px solid var(--ink); border-radius: 6px; background: #fffaf0; color: var(--ink); max-width: 100%; }
.verdict { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--paper2); border: 2px dashed var(--s2); font-weight: 600; }

/* exhibit devices */
.device { background: #17221e; color: #d9efe4; border-radius: 10px; padding: 10px; border: 3px solid #0d1411; box-shadow: inset 0 0 0 2px #2f4a40; }
.device canvas { width: 100%; display: block; image-rendering: pixelated; border-radius: 6px; background: #0e1714; touch-action: none; }
.device .readout { font: 13px/1.4 var(--mono); color: #a8e0c8; }
.device .btn { background: #2f4a40; border-color: #6fb3a5; color: #e9fff4; }
.device .btn.gold { background: var(--gold); color: var(--ink); border-color: var(--gold2); }
.device input[type=range] { width: 100%; accent-color: var(--teal2); }
.phones { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.phone { background: #0e1714; border: 2px solid #3a564b; border-radius: 10px; padding: 6px; font: 12px/1.3 var(--mono); min-height: 92px; }
.phone .who { color: var(--gold2); font-weight: 700; }
.phone .msg { margin-top: 3px; padding: 3px 5px; border-radius: 6px; background: #22352e; }
.phone .msg.out { background: #3f8a83; color: #fff; margin-left: 10px; }
.phone.skipped { opacity: .5; }
.phone.won { border-color: var(--gold); }
.lot { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }

/* ---------- control deck (DS-style lower screen on phones) ---------- */
#deck { flex: none; display: none; align-items: center; justify-content: space-between; gap: 6px; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(#22332d, #1a2823); border-top: 3px solid #0e1714; touch-action: none; }
body.touch #deck { display: flex; }
body.touch #hud-buttons { display: none; }
@media (orientation: landscape) and (max-height: 540px) { body.touch #hud-buttons { display: flex; } }
#deck { --u: min(52px, 11vw); }
#pad { position: relative; width: calc(var(--u) * 2.9); height: calc(var(--u) * 2.9); flex: none; touch-action: none; }
#pad button { position: absolute; width: var(--u); height: var(--u); background: #33463f; border: 3px solid #0e1714; padding: 0; touch-action: none; }
#pad button::after { content: ''; position: absolute; inset: 0; margin: auto; width: 0; height: 0; border: 8px solid transparent; }
#pad [data-dir=up] { left: calc(var(--u) * .95); top: 0; border-radius: 8px 8px 0 0; } #pad [data-dir=up]::after { border-bottom-color: #a9be80; top: -10px; }
#pad [data-dir=down] { left: calc(var(--u) * .95); bottom: 0; border-radius: 0 0 8px 8px; } #pad [data-dir=down]::after { border-top-color: #a9be80; bottom: -10px; }
#pad [data-dir=left] { left: 0; top: calc(var(--u) * .95); border-radius: 8px 0 0 8px; } #pad [data-dir=left]::after { border-right-color: #a9be80; left: -10px; }
#pad [data-dir=right] { right: 0; top: calc(var(--u) * .95); border-radius: 0 8px 8px 0; } #pad [data-dir=right]::after { border-left-color: #a9be80; right: -10px; }
#pad .hub { position: absolute; left: calc(var(--u) * .95); top: calc(var(--u) * .95); width: var(--u); height: var(--u); background: #33463f; border-top: 3px solid #33463f; pointer-events: none; }
#pad button.down { background: #4c665b; transform: scale(.96); }
#deck-mid { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.pill { background: #2c3d37; border: 2px solid #0e1714; color: var(--sand); border-radius: 20px; padding: 6px 10px; font-size: 12px; font-weight: 800; letter-spacing: .03em; min-height: 40px; min-width: 66px; }
#ab { position: relative; width: calc(var(--u) * 2.75); height: calc(var(--u) * 2.5); flex: none; }
#ab button { position: absolute; border-radius: 50%; border: 3px solid #0e1714; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; touch-action: none; padding: 0; }
#ab b { font-size: 20px; }
#ab span { font-size: 11px; font-weight: 800; margin-top: 3px; max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-a { right: 0; top: 0; width: calc(var(--u) * 1.6); height: calc(var(--u) * 1.6); background: #b5473a; color: #fff; }
#btn-a:disabled { background: #5e3a35; color: #c7a8a2; opacity: 1; cursor: default; }
#btn-a.ready { box-shadow: 0 0 0 3px var(--gold2); }
#btn-b { left: 0; bottom: 0; width: calc(var(--u) * 1.25); height: calc(var(--u) * 1.25); background: #4b6d80; color: #fff; }
#ab button.down { transform: scale(.94); filter: brightness(1.15); }

/* landscape phones: controls overlay the screen edges */
@media (orientation: landscape) and (max-height: 540px) {
  body.touch #deck { position: absolute; inset: auto 0 0 0; background: none; border: 0; pointer-events: none; padding: 0 12px calc(8px + env(safe-area-inset-bottom)); }
  body.touch #deck > * { pointer-events: auto; opacity: .82; }
  body.touch #deck-mid { display: none; }
  #dialog { left: 170px; right: 170px; }
}
/* desktop: wider dialogue, keyboard hints */
@media (min-width: 900px) and (pointer: fine) {
  #dialog { left: 50%; transform: translateX(-50%); width: min(760px, calc(100% - 24px)); }
}

/* ---------- title ---------- */
#title { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: safe center; overflow-y: auto; gap: 10px; text-align: center; padding: 16px; background: linear-gradient(rgba(16,25,21,.55), rgba(16,25,21,.35) 40%, rgba(16,25,21,.75)), radial-gradient(ellipse at 50% 110%, rgba(233,185,73,.35), transparent 60%); }
#title h1 { margin: 0; font-size: clamp(30px, min(9vw, 8vh), 64px); letter-spacing: .08em; color: var(--paper); text-shadow: 3px 3px 0 var(--ink), 0 0 0 var(--ink); font-weight: 900; line-height: 1; }
#title .sub { font-size: clamp(14px, 3.6vw, 20px); color: var(--gold2); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; text-shadow: 2px 2px 0 var(--ink); }
#title .menu { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; min-width: 240px; }
body:has(#title:not([hidden])) #place { display: none; }
/* the field guide and settings open from the title screen: keep their panel above it */
body:has(#title:not([hidden])) #panel { z-index: 31; }
@media (max-height: 700px) { #title { gap: 6px; } #title .menu { margin-top: 6px; } #title .menu button { padding: 8px 14px; } #title .fine { display: none; } }
#title .menu button { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 10px; padding: 10px 16px; font-weight: 900; font-size: 16px; box-shadow: 0 4px 0 var(--ink); }
#title .menu button:hover, #title .menu button:focus-visible { background: var(--gold2); }
#title .fine { font-size: 12px; color: var(--sand); max-width: 480px; text-shadow: 1px 1px 0 var(--ink); }
#fade { position: absolute; inset: 0; background: #0b1210; opacity: 0; pointer-events: none; z-index: 25; transition: opacity .35s; }
#fade.on { opacity: 1; }

body.reduced *, body.reduced *::before, body.reduced *::after { animation: none !important; transition: none !important; }

/* ---------- workshop (Hashbrown) ---------- */
#workshop { position: fixed; inset: 0; z-index: 60; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); background: #f3e6cf; color: var(--ink); display: flex; flex-direction: column; -webkit-user-select: none; user-select: none; }
#workshop header { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--ink); color: var(--paper); }
#workshop header h2 { margin: 0; font-size: 15px; flex: 1; letter-spacing: .04em; }
#ws-main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 0; }
#ws-stage { position: relative; display: flex; align-items: center; justify-content: center; background: #1c2a26; min-height: 0; }
#ws-canvas { width: 100%; max-height: 100%; aspect-ratio: 16/9; display: block; touch-action: none; cursor: grab; }
#ws-deck { overflow: auto; padding: 10px; background: var(--paper); border-left: 3px solid var(--ink); }
#ws-deck h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin: 12px 0 6px; color: #6b6457; }
#ws-deck .chips { display: flex; flex-wrap: wrap; gap: 5px; }
#ws-deck .chips button { background: var(--paper2); border: 2px solid var(--ink); border-radius: 16px; padding: 5px 10px; font-weight: 700; font-size: 13px; min-height: 34px; color: var(--ink); }
#ws-deck .chips button[aria-pressed=true] { background: var(--ink); color: var(--paper); }
#ws-deck .sl { display: grid; grid-template-columns: 90px 1fr; gap: 6px; align-items: center; font-size: 12px; font-weight: 700; }
#ws-deck input[type=range] { width: 100%; accent-color: var(--teal); }
#ws-hint { position: absolute; left: 10px; bottom: 10px; right: 10px; text-align: center; color: var(--paper); font-weight: 800; font-size: 14px; text-shadow: 1px 1px 0 #000; pointer-events: none; transition: opacity .6s; }
#ws-acts { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
#ws-acts button { background: rgba(247,241,225,.94); border: 2px solid var(--ink); border-radius: 18px; padding: 6px 12px; font-weight: 800; min-height: 38px; color: var(--ink); }
@media (max-width: 760px), (orientation: portrait) {
  .ws-sub { display: none; }
  #ws-main { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
  #ws-stage { flex: none; flex-direction: column; align-items: stretch; }
  #ws-canvas { width: 100%; height: auto; max-height: none; }
  #ws-acts { position: static; display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; background: var(--ink); }
  #ws-acts button { min-height: 36px; padding: 4px 10px; font-size: 14px; }
  #ws-hint { position: static; padding: 0 8px 8px; background: var(--ink); font-size: 12px; }
  #ws-deck { flex: 1; min-height: 0; min-width: 0; border-left: 0; border-top: 3px solid var(--ink); }
}

/* diagnostics */
#diag { position: absolute; right: 6px; bottom: 6px; z-index: 50; background: rgba(0,0,0,.75); color: #9f9; font: 11px/1.3 var(--mono); padding: 6px 8px; border-radius: 6px; pointer-events: none; white-space: pre; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
