:root {
  --gold: #ffd23f;
  --navy: #1b2a4d;
  --red: #e0392b;
  --cyan: #3ee6ff;
  --bg: #07090f;
  --panel: rgba(10, 14, 26, 0.92);
  --line: #2b3a5c;
  --text: #eef2fb;
  --muted: #98a3bf;
  --font: 'Press Start 2P', 'Courier New', Courier, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html { height: 100%; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
html, body {
  margin: 0; padding: 0; width: 100%;
  background: var(--bg); color: var(--text); font-family: var(--font);
  overflow: hidden; touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body { position: fixed; inset: 0; height: 100%; height: 100dvh; }
button { -webkit-touch-callout: none; font-family: inherit; }
.hidden { display: none !important; }
#safeProbe { position: fixed; left: 0; top: 0; width: 0; height: 0; visibility: hidden; pointer-events: none; padding: var(--sat) var(--sar) var(--sab) var(--sal); }

.kbd-only, .touch-only { display: none; }
body.is-desktop .kbd-only { display: block; }
body.is-desktop .row.kbd-only { display: flex; }
body.is-touch .touch-only { display: block; }
body.is-desktop span.kbd-only, body.is-touch span.touch-only { display: inline; }

#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
body.locked #gl { cursor: none; }

/* goal red-light flash */
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 3; background: var(--red); opacity: 0; transition: opacity .12s; }
#flash.on { opacity: .35; }

/* ---- HUD */
#hud { position: fixed; inset: 0; z-index: 4; pointer-events: none; font-size: clamp(9px, 2.1vmin, 13px); }
#hudTop {
  position: absolute; left: 0; right: 0; top: calc(50px + var(--sat));
  display: flex; justify-content: center; gap: 10px; padding: 0 calc(10px + var(--sar)) 0 calc(10px + var(--sal));
}
.hudbox { background: rgba(5,8,16,.72); border: 2px solid var(--line); border-radius: 4px; padding: 7px 10px; letter-spacing: 1px; white-space: nowrap; }
#hudMode { color: var(--cyan); }
#hudScore { color: var(--gold); }
#hudTimerWrap { position: relative; width: 150px; overflow: hidden; text-align: center; }
#hudTimer { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: linear-gradient(90deg, #2b7bd6, #3ee6ff); transform-origin: 0 50%; }
#hudTimerWrap.warn #hudTimer { background: linear-gradient(90deg, #c0392b, #ff7a5c); }
#hudTimerTxt { position: relative; z-index: 1; color: #fff; text-shadow: 1px 1px 0 #000; }
#hudSpeed { position: absolute; left: calc(14px + var(--sal)); bottom: calc(14px + var(--sab)); color: var(--muted); font-size: .9em; text-shadow: 1px 1px 0 #000; }
#crosshair { position: absolute; left: 50%; top: 40%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; border: 2px solid rgba(255,255,255,.9); box-shadow: 0 0 0 1px rgba(0,0,0,.5), inset 0 0 0 1px rgba(0,0,0,.5); }
#powerWrap { position: absolute; left: 50%; bottom: calc(26% + var(--sab)); width: 140px; height: 12px; margin-left: -70px; background: rgba(0,0,0,.55); border: 2px solid #fff; border-radius: 3px; overflow: hidden; }
#powerBar { height: 100%; width: 0; background: linear-gradient(90deg, #4ade80, #ffd23f, #e0392b); }
#banner {
  position: absolute; left: 0; right: 0; top: 34%; text-align: center;
  font-size: clamp(26px, 8vmin, 64px); color: var(--gold); letter-spacing: 3px;
  text-shadow: 3px 3px 0 #7a1b12, 6px 6px 0 #000, 0 0 30px rgba(255,210,63,.6);
  animation: pop .35s ease-out;
}
#banner.red { color: #ff5a4a; text-shadow: 3px 3px 0 #3a0a06, 6px 6px 0 #000; }
#banner.blue { color: var(--cyan); text-shadow: 3px 3px 0 #0a3a4a, 6px 6px 0 #000; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
#subBanner { position: absolute; left: 0; right: 0; top: calc(34% + clamp(40px, 10vmin, 80px)); text-align: center; font-size: clamp(10px, 2.6vmin, 16px); color: #fff; text-shadow: 2px 2px 0 #000; letter-spacing: 1px; line-height: 1.7; }
#hint { position: absolute; left: 0; right: 0; bottom: calc(14px + var(--sab)); text-align: center; color: var(--muted); font-size: .85em; text-shadow: 1px 1px 0 #000; padding: 0 60px; line-height: 1.7; }
body.is-touch #hint { pointer-events: auto; }
body.is-touch.mech #hint { padding: 0 236px 0 150px; }
/* boost meter (demo) + speed lines */
#boostWrap { position: absolute; left: calc(14px + var(--sal)); bottom: calc(36px + var(--sab)); width: 120px; height: 10px; background: rgba(0,0,0,.55); border: 2px solid #fff; border-radius: 3px; }
#boostBar { height: 100%; width: 100%; background: linear-gradient(90deg, #3ee6ff, #4ade80); transition: width .08s linear; }
#boostWrap.low #boostBar { background: #e0392b; }
#boostWrap span { position: absolute; left: 0; top: -15px; font-size: 8px; color: var(--muted); letter-spacing: 1px; text-shadow: 1px 1px 0 #000; }
#speedLines {
  position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: 0; transition: opacity .12s;
  background: repeating-conic-gradient(from 0deg at 50% 45%, rgba(255,255,255,0) 0deg 6.5deg, rgba(255,255,255,.4) 7deg 7.6deg);
  -webkit-mask-image: radial-gradient(circle at 50% 45%, transparent 36%, #000 82%); mask-image: radial-gradient(circle at 50% 45%, transparent 36%, #000 82%);
}

/* ---- touch controls */
#touchUI { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#joyZone { position: absolute; left: 0; top: 0; bottom: 0; width: 42%; pointer-events: auto; touch-action: none; }
#aimZone { position: absolute; right: 0; top: 0; bottom: 0; width: 58%; pointer-events: auto; touch-action: none; }
#joyBase { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(255,255,255,.55); background: rgba(255,255,255,.08); display: none; }
#joyBase.on { display: block; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255,210,63,.85); border: 2px solid #1a1200; }
#tbtns { position: absolute; right: calc(12px + var(--sar)); bottom: calc(12px + var(--sab)); display: flex; flex-direction: column; align-items: flex-end; gap: 10px; pointer-events: none; }
.tbtn {
  pointer-events: auto; touch-action: none; border-radius: 50%; cursor: pointer;
  font-size: 11px; letter-spacing: 1px; color: var(--text); background: rgba(5,8,16,.7); border: 2px solid rgba(255,255,255,.6);
  display: flex; align-items: center; justify-content: center;
}
.tbtn.big { width: 84px; height: 84px; background: rgba(255,210,63,.9); color: #1a1200; border: 3px solid #1a1200; font-size: 12px; box-shadow: 0 5px 0 #7a5c00, 0 8px 18px rgba(0,0,0,.5); }
.tbtn.big.charging { background: #ff7a5c; }
.tbtn.mid { width: 60px; height: 60px; }
.tbtn.small { width: 48px; height: 48px; font-size: 9px; }
.tbtn:active { transform: translateY(2px); filter: brightness(1.1); }
/* demo-mode buttons: a 2-column pad left of the main column */
#demoTBtns { position: absolute; right: calc(108px + var(--sar)); bottom: calc(12px + var(--sab)); display: grid; grid-template-columns: 52px 52px; gap: 8px; pointer-events: none; }
.tbtn.demo { width: 52px; height: 52px; border-radius: 12px; font-size: 8px; letter-spacing: 0; }
.tbtn.demo.wide { grid-column: 1 / span 2; width: 112px; }
.tbtn.demo.on { background: rgba(62,230,255,.85); color: #04202a; }

/* ---- chrome */
#chrome { position: fixed; left: 0; right: 0; top: 0; z-index: 7; display: flex; align-items: flex-start; gap: 8px; padding: calc(6px + var(--sat)) calc(8px + var(--sar)) 0 calc(8px + var(--sal)); pointer-events: none; }
#chrome .spacer { flex: 1; }
.cornerbtn {
  pointer-events: auto; height: 36px; min-width: 36px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: rgba(5,8,16,.8); border: 2px solid var(--line); border-radius: 4px;
  color: var(--text); text-decoration: none; font: inherit; font-size: 10px; letter-spacing: 1px; cursor: pointer; text-transform: uppercase; white-space: nowrap;
}
.cornerbtn:hover { border-color: var(--gold); color: var(--gold); }
body.is-touch .cornerbtn { height: 44px; padding: 0 12px; font-size: 10px; }
body.compact .cornerbtn { padding: 0 8px; font-size: 9px; }
body.compact #backBtn { width: 44px; padding: 0; font-size: 13px; }

/* ---- menus */
#overlay { position: fixed; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center; padding: calc(54px + var(--sat)) calc(12px + var(--sar)) calc(12px + var(--sab)) calc(12px + var(--sal)); background: rgba(4,7,14,.55); font-size: clamp(9px, 2.2vmin, 13px); pointer-events: auto; }
#overlay.hidden { display: none; }
#overlay.seethrough { background: transparent; pointer-events: none; }
.card { background: var(--panel); border: 2px solid var(--line); border-radius: 6px; padding: 1.4em 1.6em; max-width: 720px; width: 100%; max-height: 100%; overflow-y: auto; touch-action: pan-y; pointer-events: auto; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.6); }
.logo { font-size: 2.6em; line-height: 1.05; color: var(--gold); text-shadow: 3px 3px 0 #7a1b12, 6px 6px 0 #1b2a4d; letter-spacing: .06em; }
.logo span { color: #fff; }
.sub { color: var(--cyan); letter-spacing: 3px; margin: .9em 0 1.1em; font-size: .85em; }
.sub2 { color: var(--muted); margin-top: 1em; line-height: 1.8; }
.h2 { font-size: 1.6em; color: var(--gold); letter-spacing: 2px; }
.modes { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: .6em 0; }
.mbtn { flex: 1 1 160px; min-height: 56px; background: #121a2c; color: var(--text); border: 2px solid var(--line); border-radius: 4px; cursor: pointer; font-size: .95em; letter-spacing: 1px; padding: 10px 8px; line-height: 1.5; }
.mbtn small { display: block; font-size: .7em; color: var(--muted); margin-top: 4px; }
.mbtn:hover { border-color: var(--gold); color: var(--gold); }
.mbtn.primary { background: var(--gold); color: #1a1200; border-color: var(--gold); }
.mbtn.primary small { color: #5a4300; }
.row { display: flex; align-items: center; justify-content: center; gap: 12px; margin: .7em 0; flex-wrap: wrap; }
.lbl { color: var(--muted); letter-spacing: 2px; }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg button { background: #121a2c; color: var(--muted); border: 0; padding: 10px 12px; min-height: 40px; cursor: pointer; font-size: .85em; letter-spacing: 1px; }
.seg button.on { background: var(--cyan); color: #04202a; }
.best { color: var(--muted); font-size: .8em; margin: .4em 0 .8em; letter-spacing: 1px; line-height: 1.7; }
.howto { text-align: left; border-top: 2px solid var(--line); padding-top: .9em; font-size: .78em; line-height: 1.9; color: var(--muted); }
.howto .h { color: var(--gold); letter-spacing: 2px; margin-bottom: .4em; }
.howto b { color: var(--text); }
#resBody { margin: 1em 0; line-height: 2; color: var(--text); }
#resBody .big { font-size: 1.8em; color: var(--gold); margin: .3em 0; }
#resBody .new { color: #4ade80; }
#resBody table { margin: 0 auto; border-collapse: collapse; font-size: .85em; }
#resBody td { padding: 2px 10px; }
body.is-touch .mbtn, body.is-touch .seg button { min-height: 44px; }
body.compact .card { padding: .9em 1em; }
body.compact .logo { font-size: 2em; }
body.compact .howto { font-size: .72em; line-height: 1.7; }

/* ---- admin / demo panel (?admin=1). Scrollable column on the right; sliders are generated from the tuning tables. */
#adminPanel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); z-index: 9;
  background: rgba(6,9,18,.95); border-left: 2px solid var(--line); color: var(--text);
  font-size: 10px; line-height: 1.6; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; pointer-events: auto;
  padding: calc(8px + var(--sat)) calc(10px + var(--sar)) calc(12px + var(--sab)) 10px;
}
#adminPanel .ah { display: flex; justify-content: space-between; align-items: center; color: var(--gold); letter-spacing: 2px; margin-bottom: 6px; }
#adminPanel button { font: inherit; font-size: 9px; background: #121a2c; color: var(--text); border: 2px solid var(--line); border-radius: 4px; padding: 0 8px; min-height: 32px; cursor: pointer; letter-spacing: 1px; }
#adminPanel button:hover, #adminPanel button.on { border-color: var(--gold); color: var(--gold); }
#adminPanel .seg button { border: 0; border-radius: 0; }
#adminPanel .seg button.on { background: var(--cyan); color: #04202a; }
#adminPanel .aread { background: rgba(0,0,0,.4); border: 1px solid var(--line); padding: 6px 8px; margin: 0 0 8px; white-space: pre-wrap; color: var(--cyan); font: inherit; font-size: 9px; line-height: 1.7; }
#adminPanel .arow { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin: 6px 0; }
#adminPanel .albl { color: var(--muted); letter-spacing: 1px; }
#adminPanel .achk { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; cursor: pointer; }
#adminPanel .achk input { width: 18px; height: 18px; margin: 0; accent-color: var(--gold); }
#adminPanel .abtns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
#adminPanel .anote { color: var(--muted); font-size: 8px; line-height: 1.6; margin: 4px 0 8px; }
#adminPanel details { border-top: 1px solid var(--line); padding: 2px 0 4px; }
#adminPanel summary { cursor: pointer; color: var(--gold); letter-spacing: 1px; padding: 7px 0; list-style: none; }
#adminPanel summary::-webkit-details-marker { display: none; }
#adminPanel summary::before { content: '+ '; }
#adminPanel details[open] summary::before { content: '- '; }
#adminPanel .aslider { display: grid; grid-template-columns: 90px 1fr 54px; gap: 6px; align-items: center; min-height: 28px; }
#adminPanel .aslider input { width: 100%; height: 28px; margin: 0; accent-color: var(--gold); touch-action: pan-y; }
#adminPanel .ak { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#adminPanel .av { text-align: right; color: #fff; }
body.admin-open #chrome { padding-right: calc(min(380px, 92vw) + 8px + var(--sar)); }   /* keep the corner buttons clear of the panel */
body.is-touch #adminPanel button { min-height: 44px; }
body.is-touch #adminPanel .aslider { min-height: 40px; }
body.is-touch #adminPanel .aslider input { height: 40px; }

/* ---- rotate hint for phones in portrait */
#rotateHint {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 18px;
  background: #07090f; color: var(--gold); text-align: center;
  font-size: clamp(12px, 3.6vw, 16px); line-height: 1.9; padding: 24px;
}
#rotateHint small { display: block; color: var(--muted); font-size: .7em; margin-top: 6px; }
#rotateHint .phone { width: 38px; height: 66px; border: 3px solid var(--gold); border-radius: 7px; animation: rot 1.6s ease-in-out infinite; }
@keyframes rot { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(90deg); } }
@media (orientation: portrait) and (max-width: 900px) { #rotateHint { display: flex; } }

.ctrldesc { text-align: center; color: var(--muted); font-size: .8em; margin: -.3em 0 .6em; }
body.is-desktop .ctrldesc.kbd-only { display: block; }
#crosshair.net { width: 22px; height: 22px; margin: -11px 0 0 -11px; border: 3px solid #ffd23f; box-shadow: 0 0 0 2px rgba(0,0,0,.6), 0 0 12px rgba(255,210,63,.8); }

/* phones: show where the left thumb moves you (David on his iPhone: "i cannot move" - the joystick was invisible
   until you touched the right spot). Ghost stick in the move zone; hidden while the real stick is in use. */
#joyZone::after {
  content: 'MOVE'; position: absolute; left: 24px; bottom: 24px; width: 104px; height: 104px; border-radius: 50%;
  border: 2px dashed rgba(255,255,255,.7); background: rgba(5,8,16,.5); color: #fff;
  display: flex; align-items: center; justify-content: center; font-family: inherit; font-size: 12px; letter-spacing: 1px;
  pointer-events: none; animation: joyGhost 1.6s ease-in-out infinite;
}
#joyZone:has(#joyBase.on)::after { display: none; }
@keyframes joyGhost { 50% { opacity: .45; } }
#joyZone::after { bottom: 44px; }    /* sit above the speed readout */
