@font-face { font-family: 'Big Shoulders Display'; src: url(/fonts/big-shoulders-display-latin-600-normal.woff2) format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Big Shoulders Display'; src: url(/fonts/big-shoulders-display-latin-800-normal.woff2) format('woff2'); font-weight: 800; font-display: swap; }
@font-face { font-family: 'Big Shoulders Display'; src: url(/fonts/big-shoulders-display-latin-900-normal.woff2) format('woff2'); font-weight: 900; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url(/fonts/atkinson-hyperlegible-latin-400-normal.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url(/fonts/atkinson-hyperlegible-latin-700-normal.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Courier Prime'; src: url(/fonts/courier-prime-latin-400-normal.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Courier Prime'; src: url(/fonts/courier-prime-latin-700-normal.woff2) format('woff2'); font-weight: 700; font-display: swap; }
:root {
  --board: #1c1d21; --flap: #2a2c32; --flap-hi: #33363d; --flap-ink: #edebe4; --rule: #3a3d45; --dim: #8d8f96;
  --paper: #f3eedc; --paper-edge: #e2dbc2; --ink: #23303f; --stamp: #c2372b;
  --lamp-red: #ff4a3d; --lamp-green: #5fd068; --lamp-amber: #ffb02e; --lamp-blue: #4aa8ff;
  --display: 'Big Shoulders Display', 'Arial Narrow', sans-serif;
  --body: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --type: 'Courier Prime', 'Courier New', monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--board); color: var(--flap-ink); font: 17px/1.45 var(--body); -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--lamp-amber); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---------- split-flap ---------- */
.flaps { display: inline-flex; gap: 0.08em; }
.flap {
  position: relative; display: inline-grid; place-items: center;
  width: 0.78em; height: 1.18em;
  background: linear-gradient(var(--flap-hi) 0 49%, #15161a 49% 51%, var(--flap) 51%);
  border-radius: 0.09em; font-family: var(--display); font-weight: 800; color: var(--flap-ink); line-height: 1;
}
.flap.flip { animation: flip 0.32s ease-in both; }
@keyframes flip {
  0% { transform: scaleY(1); }
  45%, 55% { transform: scaleY(0.05); filter: brightness(0.6); }
  100% { transform: scaleY(1); }
}
@media (prefers-reduced-motion: reduce) { .flap.flip { animation: none; } }

/* ---------- host ---------- */
.host { min-height: 100vh; padding: 3vh 3.5vw; display: flex; flex-direction: column; gap: 3vh; font-size: 1.6vw; }
.host-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 3vw; }
.wordmark { font: 900 5.4vw/0.86 var(--display); margin: 0; }
.wordmark small { display: block; font: 400 1.4vw/1.35 var(--body); color: var(--dim); margin-top: 1.6vh; max-width: 40ch; }
.join-box { display: flex; gap: 2vw; align-items: center; }
.join-box .code { font-size: 6vw; margin-top: 1vh; }
.join-box .how { font-size: 1.3vw; color: var(--dim); text-align: right; }
.join-box .how strong { color: var(--flap-ink); display: block; font-size: 1.8vw; }
.qr { background: var(--flap-ink); padding: 0.7vw; border-radius: 0.4vw; width: 12vw; height: 12vw; }
.qr svg { width: 100%; height: 100%; display: block; }

.lobby-crews { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5vw; flex: 1; }
.lobby-crew { border-top: 0.5vw solid var(--c); padding-top: 1.2vh; }
.lobby-crew h2 { font: 800 2.6vw/1 var(--display); margin: 0 0 1.5vh; display: flex; justify-content: space-between; }
.lobby-crew h2 span { color: var(--dim); font-weight: 600; }
.chips { display: flex; flex-direction: column; gap: 0.8vh; }
.chip { display: flex; justify-content: space-between; align-items: center; background: var(--flap); border: 0; border-radius: 0.3vw; padding: 0.7vh 0.8vw; font-size: 1.4vw; text-align: left; }
.chip:hover { background: var(--flap-hi); }
.chip .off { color: var(--dim); font-size: 1vw; }
.chip.offline { opacity: 0.55; }
.lobby-empty { color: var(--dim); font-size: 1.2vw; margin: 0; }

.host-actions { display: flex; justify-content: space-between; align-items: center; gap: 2vw; }
.host-actions p { color: var(--dim); margin: 0; font-size: 1.2vw; }
.big-btn { background: var(--flap-ink); color: var(--board); border: 0; font: 800 2.2vw/1 var(--display); padding: 1.6vh 2.6vw; border-radius: 0.4vw; box-shadow: 0 0.5vh 0 #9c9a92; }
.big-btn:active { transform: translateY(0.4vh); box-shadow: 0 0.1vh 0 #9c9a92; }
.big-btn:disabled { opacity: 0.4; cursor: default; }
.ghost-btn { background: none; border: 1px solid var(--rule); color: var(--dim); padding: 1vh 1.4vw; border-radius: 0.4vw; font-size: 1.1vw; }

.board-head { display: flex; justify-content: space-between; align-items: flex-end; }
.board-head h2 { font: 800 2.6vw/1 var(--display); margin: 0; color: var(--dim); }
.board-head .clock { font-size: 7vw; }
.board-head .clock.low .flap { color: var(--lamp-red); }
.board { display: flex; flex-direction: column; gap: 1.4vh; flex: 1; }
.board-cols, .row { display: grid; grid-template-columns: 3.4fr 3fr 2fr 2fr 2.8fr; gap: 1.5vw; align-items: center; }
.board-cols { color: var(--dim); font-size: 1.1vw; padding: 0 1.2vw 0 1.8vw; }
.row { background: #232429; border-left: 0.6vw solid var(--c); border-radius: 0.3vw; padding: 2.6vh 1.2vw; font-size: 2.4vw; }
.row .crew { font: 800 3vw/1 var(--display); }
.row .rel { font-size: 1.15vw; color: var(--dim); margin-top: 0.6vh; font-family: var(--body); }
.row .flaps { font-size: 2.6vw; }
.mods { display: flex; gap: 0.6vw; }
.mod-pip { width: 2vw; height: 2vw; border-radius: 50%; background: var(--flap); border: 2px solid var(--rule); }
.mod-pip.done { background: var(--lamp-green); border-color: var(--lamp-green); box-shadow: 0 0 1vw rgba(95, 208, 104, 0.6); }
.strikes { display: flex; gap: 0.5vw; }
.strike { width: 1.8vw; height: 1.8vw; border-radius: 50%; background: #3a1e1c; }
.strike.on { background: var(--lamp-red); box-shadow: 0 0 1vw var(--lamp-red); }
.row.outage { animation: alarm 0.6s steps(2) 4; }
.row.defused .status .flap { color: var(--lamp-green); }
.row.outage .status .flap, .row.timeout .status .flap { color: var(--lamp-red); }
@keyframes alarm { 50% { background: #5a1f1a; } }
.row .pts { font: 700 1.5vw/1 var(--display); color: var(--dim); margin-top: 0.8vh; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; background: rgba(20, 20, 24, 0.72); }
.overlay div { font: 900 9vw/0.9 var(--display); text-align: center; animation: slam 0.35s cubic-bezier(.2,1.6,.4,1) both; }
.overlay small { display: block; font: 700 2vw/1.2 var(--body); margin-top: 2vh; color: var(--flap-ink); }
.overlay.bad div { color: var(--lamp-red); }
.overlay.good div { color: var(--lamp-green); }
@keyframes slam { from { transform: scale(1.6); opacity: 0; } }

.results { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5vw; align-items: end; flex: 1; }
.podium { display: flex; flex-direction: column; justify-content: flex-end; }
.podium .bar { background: var(--c); border-radius: 0.4vw 0.4vw 0 0; color: var(--board); padding: 1.5vh 1vw; display: flex; flex-direction: column; justify-content: space-between; }
.podium .bar strong { font: 900 4.4vw/1 var(--display); }
.podium .bar span { font: 800 2.2vw/1 var(--display); }
.podium p { margin: 1vh 0 0; color: var(--dim); font-size: 1.1vw; min-height: 3em; }

/* ---------- phone ---------- */
.phone { min-height: 100svh; display: flex; flex-direction: column; max-width: 520px; margin: 0 auto; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
.phone h1 { font: 900 52px/0.88 var(--display); margin: 12px 0 10px; }
.phone .lede { color: var(--dim); margin: 0 0 24px; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-weight: 700; margin-bottom: 6px; }
.field input { width: 100%; font: 700 22px var(--body); color: var(--flap-ink); background: var(--flap); border: 2px solid var(--rule); border-radius: 8px; padding: 12px 14px; }
.field input.code-in { font: 800 44px/1 var(--display); letter-spacing: 0.35em; text-transform: uppercase; text-align: center; padding: 8px 0 8px 0.35em; }
.crew-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.crew-pick button { border: 2px solid var(--rule); background: var(--flap); border-radius: 10px; padding: 14px 12px; text-align: left; font: 800 22px/1 var(--display); }
.crew-pick button::before { content: ''; display: block; width: 26px; height: 6px; border-radius: 3px; background: var(--c); margin-bottom: 10px; }
.crew-pick button[aria-pressed='true'] { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, var(--flap)); }
.primary { width: 100%; margin-top: 22px; border: 0; border-radius: 10px; padding: 16px; background: var(--flap-ink); color: var(--board); font: 800 28px/1 var(--display); box-shadow: 0 5px 0 #9c9a92; }
.primary:active { transform: translateY(4px); box-shadow: 0 1px 0 #9c9a92; }
.error { color: var(--lamp-red); font-weight: 700; min-height: 1.5em; margin: 10px 0 0; }

.status-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; min-height: 36px; }
.status-bar .crew-tag { font: 800 22px/1 var(--display); display: flex; align-items: center; gap: 8px; }
.status-bar .crew-tag::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.status-bar .flaps { font-size: 30px; }
.status-bar .strikes { gap: 6px; }
.status-bar .strike { width: 16px; height: 16px; }

.waiting { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 10px; }
.waiting .big { font: 900 64px/0.9 var(--display); color: var(--c); }
.waiting p { color: var(--dim); margin: 0; }
.countdown { font: 900 180px/1 var(--display); text-align: center; flex: 1; display: grid; place-items: center; color: var(--c); }

/* operator device */
.device { flex: 1; display: flex; flex-direction: column; gap: 14px; background: var(--c); border-radius: 22px; padding: 14px; box-shadow: inset 0 -6px 0 rgba(0,0,0,0.22), inset 0 2px 0 rgba(255,255,255,0.35); }
.device.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@media (prefers-reduced-motion: reduce) { .device.shake { animation: none; } }
.label { background: #f7f5ee; color: #1c1d21; border-radius: 6px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; font-family: var(--type); font-size: 15px; box-shadow: 0 2px 0 rgba(0,0,0,0.25); }
.label .cap { font-size: 11px; color: #5c5f66; }
.label .serial { font-size: 26px; font-weight: 700; letter-spacing: 0.04em; line-height: 1.1; }
.label .relname { grid-column: 1 / -1; font-family: var(--body); font-size: 13px; color: #5c5f66; border-top: 1px dashed #c9c6bb; padding-top: 6px; }
.lamp { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.lamp i { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #1c1d21; }
.lamp i.green { background: var(--lamp-green); } .lamp i.amber { background: var(--lamp-amber); }
.lamp i.red { background: var(--lamp-red); } .lamp i.blue { background: var(--lamp-blue); }
.seg { font: 800 34px/1 var(--display); background: #1c1d21; color: var(--lamp-red); padding: 4px 10px; border-radius: 4px; text-align: center; }
.mod-tabs { display: flex; gap: 6px; }
.mod-tabs button { flex: 1; border: 0; border-radius: 8px; padding: 10px 4px; background: rgba(0,0,0,0.22); color: #fff; font: 700 14px var(--body); display: flex; align-items: center; justify-content: center; gap: 6px; }
.mod-tabs button[aria-selected='true'] { background: #1c1d21; }
.mod-tabs button i { width: 10px; height: 10px; border-radius: 50%; background: #55575d; }
.mod-tabs button i.done { background: var(--lamp-green); box-shadow: 0 0 6px var(--lamp-green); }
.panel { flex: 1; background: #1c1d21; border-radius: 14px; padding: 16px; display: flex; flex-direction: column; justify-content: center; gap: 12px; min-height: 320px; position: relative; }
.panel .hint { color: var(--dim); font-size: 14px; margin: 0 0 6px; text-align: center; }
.panel.solved::after { content: 'Fixed'; position: absolute; inset: 0; display: grid; place-items: center; font: 900 72px var(--display); color: var(--lamp-green); background: rgba(28,29,33,0.85); border-radius: 14px; }

.wire { position: relative; height: 46px; border: 0; background: none; width: 100%; padding: 0; display: block; }
.wire::before, .wire::after { content: ''; position: absolute; top: 17px; height: 12px; background: var(--w); border-radius: 6px; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.25); }
.wire::before { left: 18px; right: 18px; }
.wire .post { position: absolute; top: 11px; width: 24px; height: 24px; border-radius: 5px; background: #8d8f96; box-shadow: inset 0 -3px 0 #5c5f66; }
.wire .post.l { left: 0; } .wire .post.r { right: 0; }
.wire.cut::before { right: 54%; transform: rotate(7deg); transform-origin: left center; }
.wire.cut::after { left: 54%; right: 18px; transform: rotate(-7deg); transform-origin: right center; }
.wire[data-c='red'] { --w: #e5412f; } .wire[data-c='blue'] { --w: #2f7de5; }
.wire[data-c='yellow'] { --w: #f2c230; } .wire[data-c='white'] { --w: #f1f0ea; } .wire[data-c='black'] { --w: #000; }
.wire[data-c='black']::before, .wire[data-c='black']::after { box-shadow: 0 0 0 2px #55575d; }

.switches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.sw { border: 0; background: #2a2c32; border-radius: 10px; height: 124px; position: relative; padding: 0; }
.sw::after { content: ''; position: absolute; left: 50%; width: 30px; height: 54px; margin-left: -15px; border-radius: 8px; background: linear-gradient(#f1f0ea, #b9b7af); top: 8px; transition: top 0.12s; box-shadow: 0 3px 0 #5c5f66; }
.sw[data-v='D']::after { top: 60px; }
.sw span { position: absolute; bottom: -24px; left: 0; right: 0; text-align: center; color: var(--dim); font-size: 13px; }
.apply { margin-top: 30px; border: 0; border-radius: 10px; padding: 14px; background: var(--lamp-amber); color: #1c1d21; font: 800 24px/1 var(--display); box-shadow: 0 4px 0 #a86f12; }
.apply:active { transform: translateY(3px); box-shadow: 0 1px 0 #a86f12; }

.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.key { aspect-ratio: 1.3; border: 0; border-radius: 12px; background: #f1f0ea; color: #1c1d21; font: 400 52px/1 'Times New Roman', serif; box-shadow: 0 5px 0 #8d8f96; position: relative; }
.key:active { transform: translateY(4px); box-shadow: 0 1px 0 #8d8f96; }
.key.lit { background: #d9f7dc; }
.key.lit::after { content: ''; position: absolute; top: 8px; right: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--lamp-green); }

/* manual */
.manual { flex: 1; display: flex; flex-direction: column; }
.manual .who { color: var(--dim); margin: 0 0 12px; }
.manual .who strong { color: var(--flap-ink); }
.page-tabs { display: flex; gap: 6px; }
.page-tabs button { border: 0; background: var(--paper-edge); color: var(--ink); border-radius: 8px 8px 0 0; padding: 9px 14px; font: 700 14px var(--type); opacity: 0.7; }
.page-tabs button[aria-selected='true'] { background: var(--paper); opacity: 1; }
.page { flex: 1; background: var(--paper); color: var(--ink); border-radius: 0 8px 8px 8px; padding: 18px 18px 24px; font: 16px/1.5 var(--type); box-shadow: 0 3px 0 var(--paper-edge); }
.page.solo { border-radius: 8px; }
.page h2 { font: 700 24px/1.1 var(--type); margin: 0 0 4px; }
.page .sub { margin: 0 0 14px; font-size: 13px; color: #5d6773; }
.page h3 { font: 700 15px var(--type); margin: 16px 0 6px; border-bottom: 1.5px solid var(--ink); padding-bottom: 2px; }
.page ol { margin: 0; padding-left: 1.4em; }
.page li { margin-bottom: 6px; }
.page table { border-collapse: collapse; width: 100%; font-size: 15px; }
.page th, .page td { border: 1.5px solid var(--ink); padding: 6px 4px; text-align: center; }
.page td.pat { font-size: 20px; letter-spacing: 0.08em; }
.stamp { display: inline-block; border: 2.5px solid var(--stamp); color: var(--stamp); font: 700 12px var(--type); padding: 2px 8px; transform: rotate(-3deg); margin-bottom: 10px; }
.trace-cols { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.trace-cols div { border: 1.5px solid var(--ink); border-radius: 4px; display: flex; flex-direction: column; align-items: center; padding: 4px 0; font: 26px/1.4 'Times New Roman', serif; }
.trace-cols b { font: 700 12px var(--type); }

.result { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 8px; }
.result .big { font: 900 68px/0.9 var(--display); }
.result .big.good { color: var(--lamp-green); } .result .big.bad { color: var(--lamp-red); }
.result p { color: var(--dim); margin: 0; }
.conn { position: fixed; top: 0; left: 0; right: 0; background: var(--lamp-amber); color: #1c1d21; text-align: center; font-weight: 700; padding: 6px; font-size: 14px; z-index: 10; }
.code-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-weight: 700; }
.host-link { color: var(--flap-ink); font-weight: 700; font-size: 15px; text-decoration: none; border: 2px solid var(--rule); border-radius: 999px; padding: 5px 14px; }
.host-link:active { background: var(--flap); }
