:root {
  --x: #ff9e1f; --y: #66d1ff; --x-ink: #b84d00; --y-ink: #00529e;
  --phos: #80ffc7; --screen: #0d384d; --glow: #1a5c70;
  --ink: #33241a; --sand: #cab387; --neon: #73ff40;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: #edcfa1; color: #eaf6f4; line-height: 1.55;
  padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
/* Fixed desert backdrop (a pseudo-element, because iOS ignores background-attachment: fixed) */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: url(/assets/backdrop.webp) center / cover; }
main { max-width: 1240px; margin: 0 auto; overflow-x: clip; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* ---------- Worn sheet metal ---------- */
.plate {
  position: relative; border-radius: 24px; background: var(--sand) center / cover;
  box-shadow: inset 2px 2px 1px rgba(255,255,255,.65), inset -2px -3px 2px rgba(0,0,0,.4), 0 6px 14px rgba(0,0,0,.35);
}
.plate.tall { background-image: url(/assets/panel-tall.webp); }
.plate.wide { background-image: url(/assets/panel-wide.webp); }
.plate.square { background-image: url(/assets/panel-square.webp); }
.screws { position: absolute; inset: 7px; pointer-events: none; }
.screws {
  background:
    var(--screw) left top, var(--screw) right top, var(--screw) left bottom, var(--screw) right bottom;
  background-repeat: no-repeat; background-size: 14px 14px;
  --screw: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Ccircle cx='7.5' cy='8' r='6' fill='%23000' opacity='.3'/%3E%3Ccircle cx='7' cy='7' r='6' fill='%23999'/%3E%3Ccircle cx='5.5' cy='5.5' r='2.5' fill='%23ddd'/%3E%3Cpath d='M3 7h8M7 3v8' stroke='%232e2e2e' stroke-width='1.7' stroke-linecap='round' transform='rotate(24 7 7)'/%3E%3C/svg%3E");
}

/* ---------- Console layout ---------- */
.console {
  display: grid; gap: 12px; padding-top: 12px;
  grid-template-columns: minmax(0,1fr) minmax(0,var(--board)) minmax(0,1fr);
  --board: min(52vw, 640px, calc(100vh - 220px));
  --board: min(52vw, 640px, calc(100svh - 220px));
  justify-content: center;
}
@media (min-width: 761px) { .console { --board: clamp(340px, calc(100svh - 220px), min(52vw, 640px)); } }
.side { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 22px 14px; min-width: 0; }
.right .knob-unit { margin-top: auto; }
.knob-unit { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.grill { width: 100%; max-width: 220px; margin-top: auto; }
.center { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.island { padding: 10px 28px; display: flex; align-items: center; gap: 10px; min-height: 82px; }

.phosphor {
  flex: 1; min-width: 0; border-radius: 999px; min-height: 58px;
  background: radial-gradient(ellipse at center, var(--glow), var(--screen));
  box-shadow: inset 0 3px 8px rgba(0,0,0,.65), 0 1px 0 rgba(255,255,255,.6);
  color: var(--phos); text-shadow: 0 0 6px rgba(128,255,199,.65);
}
.hud { display: grid; grid-template-columns: repeat(3,1fr); align-items: center; text-align: center; }
.hud div + div { border-left: 1px solid rgba(128,255,199,.25); }
.hud small { display: block; font-size: 11px; letter-spacing: 1.5px; opacity: .75; font-weight: 700; }
.hud b { font-size: clamp(19px, 2.6vw, 30px); line-height: 1.1; font-variant-numeric: tabular-nums; }
.message { display: grid; place-items: center; text-align: center; padding: 4px 18px; font-weight: 700; font-size: 15px; line-height: 1.25; }
.zap {
  flex: none; width: 62px; height: 62px; border-radius: 50%; cursor: pointer; touch-action: manipulation;
  border: 3px solid rgba(255,255,255,.55); color: #fff; font: 700 15px "Helvetica Neue", Arial, sans-serif; letter-spacing: 1px;
  background: radial-gradient(circle at 35% 30%, #eb6b38, #8c331a); box-shadow: 1px 4px 6px rgba(0,0,0,.45);
}
.zap:active { transform: translateY(2px); box-shadow: 0 1px 3px rgba(0,0,0,.45); }

.radar { aspect-ratio: 1; width: 100%; }
.radar canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.radar .screws { z-index: 1; }

/* ---------- Knobs ---------- */
.dial {
  position: relative; width: min(100%, 250px); aspect-ratio: 1; border-radius: 50%;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; cursor: grab;
}
.dial:active { cursor: grabbing; }
.dial:focus-visible { outline: 3px dashed var(--ink); }
.gauge { position: absolute; inset: 0; width: 100%; height: 100%; }
.knob { position: absolute; inset: 13%; }
.knob > img { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.jewel {
  position: absolute; inset: 30%; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle, #222, #080808); pointer-events: none;
  border: 3px solid #cfd3d6; box-shadow: 0 2px 4px rgba(0,0,0,.5), inset 0 0 8px #000;
}
.jewel img { position: absolute; top: 17%; left: 50%; height: 66%; width: auto; transform: translateX(-50%); mix-blend-mode: screen; }
.caption { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink); }
.engraved { font-size: 12px; font-weight: 700; letter-spacing: 1.5px; }
.readout {
  background: var(--screen); border: 3px solid #b3c2c9; border-radius: 10px; padding: 1px 12px;
  font-size: clamp(17px, 2vw, 24px); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}
[data-axis="x"] .readout { color: var(--x); text-shadow: 0 0 6px var(--x); }
[data-axis="y"] .readout { color: var(--y); text-shadow: 0 0 6px var(--y); }
.hint { font-size: 13px; font-weight: 700; white-space: nowrap; }
[data-axis="x"] .hint { color: var(--x-ink); }
[data-axis="y"] .hint { color: var(--y-ink); }

/* ---------- Neon sign ---------- */
.sign { position: relative; width: 100%; max-width: 260px; aspect-ratio: 711/369; }
.sign::before { content: ""; position: absolute; inset: 9% 5%; background: linear-gradient(#292929, #0f0f0f); border-radius: 10px; box-shadow: 2px 4px 8px rgba(0,0,0,.45); }
.sign img { position: absolute; inset: 0; width: 100%; height: 100%; }
.sign .glow { mix-blend-mode: screen; animation: flicker 8s infinite; }
@keyframes flicker { 0%,91%,93%,95%,100% { opacity: 1 } 92%,94% { opacity: .45 } }

.actions { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 240px; text-align: center; }
.button {
  display: inline-block; text-decoration: none; text-align: center; color: #fff; font-weight: 700; font-size: 14px;
  padding: 10px 16px; border-radius: 999px; border: 2px solid rgba(255,255,255,.55);
  background: linear-gradient(#eb6b38, #a8401c); box-shadow: 0 3px 6px rgba(0,0,0,.35);
}
.button.ghost { background: linear-gradient(var(--glow), var(--screen)); }
.keys {
  margin: 14px auto 36px; max-width: 720px; text-align: center; font-size: 13px; font-weight: 700; color: var(--ink);
  background: rgba(255,255,255,.55); border-radius: 12px; padding: 8px 14px;
}

/* ---------- Story panels ---------- */
.story { max-width: 820px; margin: 0 auto 28px; padding: 24px; scroll-margin-top: 12px; }
.screen {
  border-radius: 14px; padding: clamp(20px, 4vw, 36px);
  background: radial-gradient(ellipse at 50% 30%, var(--glow), var(--screen) 75%);
  box-shadow: inset 0 4px 14px rgba(0,0,0,.7), 0 1px 0 rgba(255,255,255,.6);
}
.eyebrow { color: var(--phos); font-size: 12px; font-weight: 700; letter-spacing: 2px; margin-bottom: 8px; }
h2 { font-size: clamp(23px, 3.6vw, 34px); line-height: 1.2; margin-bottom: 14px; color: #fff; }
.screen p + p { margin-top: 12px; }
.big { text-align: center; font-size: 56px; font-weight: 700; color: #fff; }
.x { color: var(--x); text-shadow: 0 0 10px var(--x); }
.y { color: var(--y); text-shadow: 0 0 10px var(--y); }
.g { color: var(--neon); text-shadow: 0 0 10px var(--neon); }
.note { font-size: 14px; opacity: .75; border-top: 1px solid rgba(128,255,199,.3); padding-top: 12px; }
.cards { max-width: 820px; margin: 0 auto 28px; display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.cards .plate { padding: 18px; display: flex; }
.cards .screen { flex: 1; padding: 18px; }
h3 { font-size: 24px; margin-bottom: 6px; }

footer {
  display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; margin: 0 auto;
  padding: 18px 12px calc(24px + env(safe-area-inset-bottom)); font-size: 13px; font-weight: 700; color: var(--ink);
}
footer a { color: var(--ink); }

/* ---------- Narrow side consoles ---------- */
@media (max-width: 1000px) and (min-width: 761px) {
  .console { gap: 8px; }
  .side { padding: 20px 8px; }
  .island { padding: 8px 18px; }
  .button { font-size: 12px; padding: 8px; }
  .hint { font-size: 11px; }
}

/* ---------- Phones and portrait: sign, radar, then both knobs under it ---------- */
@media (max-width: 760px), (max-width: 1100px) and (orientation: portrait) {
  .console { grid-template-columns: 1fr 1fr; gap: 8px; max-width: 560px; margin: 0 auto; --board: 100%; }
  .side { display: contents; }
  .side > .screws, .grill { display: none; }
  .sign { grid-column: 1 / -1; order: 1; justify-self: center; }
  .center { grid-column: 1 / -1; order: 2; }
  .knob-unit { order: 3; margin: 0; padding: 12px 6px; border-radius: 20px; background: url(/assets/panel-square.webp) center / cover; box-shadow: inset 2px 2px 1px rgba(255,255,255,.65), inset -2px -3px 2px rgba(0,0,0,.4), 0 5px 10px rgba(0,0,0,.3); }
  .right .knob-unit { margin: 0; flex-direction: column-reverse; }
  .actions { grid-column: 1 / -1; order: 4; justify-self: center; margin-top: 6px; }
  .engraved { display: none; }
  .island { min-height: 62px; padding: 6px 16px; }
  .phosphor { min-height: 48px; }
  /* Shrink the radar on short screens so both knobs stay on the first screen */
  .radar { width: min(100%, max(240px, calc(100vh - 410px))); width: min(100%, max(240px, calc(100svh - 410px))); align-self: center; }
  .sign { max-width: 150px; }
  .dial { width: min(100%, 190px); }
  .cards { grid-template-columns: 1fr; }
  .story { padding: 16px; }
}

/* ---------- Phone held sideways: the whole console on one screen, like the app ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  .console { grid-template-columns: minmax(0,1fr) var(--board) minmax(0,1fr); gap: 6px; max-width: none; padding-top: 6px; --board: calc(100svh - 122px); }
  .side { display: flex; padding: 10px 6px; gap: 4px; }
  .center { grid-column: auto; order: 0; gap: 4px; }
  .side > .screws { display: block; }
  .grill, .actions, .engraved, .hint { display: none; }
  .sign { order: 0; max-width: 150px; }
  .knob-unit { order: 0; padding: 0; background: none; box-shadow: none; gap: 2px; }
  .left .knob-unit { margin: 0; }
  .right .knob-unit { margin-top: auto; flex-direction: column; }
  .dial { width: min(100%, 52svh); }
  .readout { font-size: 15px; }
  .island { min-height: 0; padding: 4px 12px; }
  .island .screws { display: none; }
  .phosphor { min-height: 40px; }
  .hud small { font-size: 9px; }
  .hud b { font-size: 17px; }
  .message { font-size: 12px; padding: 2px 10px; }
  .zap { width: 42px; height: 42px; font-size: 11px; }
}

/* Short portrait phones (or Safari with its toolbars): tighten so the knobs fit */
@media (orientation: portrait) and (max-width: 760px) and (max-height: 760px) {
  .console { gap: 5px; padding-top: 6px; }
  .center { gap: 5px; }
  .sign { max-width: 104px; }
  .hint { display: none; }
  .island { min-height: 52px; padding: 4px 14px; }
  .phosphor { min-height: 42px; }
  .message { font-size: 13px; }
  .zap { width: 46px; height: 46px; font-size: 12px; }
  .radar { width: min(100%, max(230px, calc(100svh - 425px))); }
  .knob-unit { padding: 6px; gap: 2px; }
  .dial { width: min(100%, 145px); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .sign .glow { animation: none; }
}
