/* SANDSTORM GP — HUD & screens */
:root {
  --amber: #ffb347;
  --amber-hot: #ff6a2b;
  --sand: #e8c07a;
  --ink: #140b06;
  --panel: rgba(20, 11, 6, 0.62);
  --edge: rgba(255, 179, 71, 0.35);
  --good: #9fe870;
  --warn: #ffcf5c;
  --bad: #ff4f3e;
  --tether: #58c8ff;
  --font: "Lucida Console", Monaco, "Courier New", monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--ink); }
body { font-family: var(--font); color: var(--sand); -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; opacity: 0; transition: opacity .3s; }
canvas#fx.on { opacity: 1; }

.hidden { display: none !important; }
.dim { opacity: .55; }

/* ---------- generic screen overlays ---------- */
.screen {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; text-align: center; padding: 24px;
  background: radial-gradient(ellipse at 50% 30%, rgba(46,20,8,.25), rgba(10,5,3,.78) 75%);
}
.screen.translucent { background: rgba(12, 6, 3, 0.72); backdrop-filter: blur(3px); }
.screen h1 { font-size: clamp(44px, 9vw, 96px); letter-spacing: .08em; color: var(--sand);
  text-shadow: 0 0 26px rgba(255, 122, 40, .55), 0 4px 0 #7a3416, 0 6px 14px rgba(0,0,0,.6); line-height: 1; }
.screen h2 { font-size: clamp(28px, 6vw, 52px); letter-spacing: .12em; color: var(--sand);
  text-shadow: 0 0 18px rgba(255,122,40,.45); }
.title-eyebrow { letter-spacing: .42em; font-size: clamp(10px, 2vw, 14px); color: var(--amber); opacity: .85; }
.title-sub { letter-spacing: .18em; font-size: clamp(11px, 2.2vw, 15px); opacity: .8; margin-top: 10px; }
.title-stack { display: flex; flex-direction: column; align-items: center; animation: titleFloat 5s ease-in-out infinite; }
@keyframes titleFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.menu-col { display: flex; flex-direction: column; gap: 12px; align-items: stretch; min-width: min(320px, 84vw); }
.menu-col.row { flex-direction: row; justify-content: center; flex-wrap: wrap; }
.menu-btn {
  font-family: var(--font); letter-spacing: .18em; font-size: 15px;
  padding: 13px 26px; cursor: pointer;
  background: linear-gradient(#2a170b, #1a0d06); color: var(--sand);
  border: 1px solid var(--edge); border-radius: 3px;
  box-shadow: 0 0 0 rgba(255,150,50,0), inset 0 0 12px rgba(255,140,40,.06);
  transition: transform .08s, box-shadow .2s, border-color .2s, color .2s;
}
.menu-btn:hover, .menu-btn:focus-visible { border-color: var(--amber); color: #fff0d8;
  box-shadow: 0 0 18px rgba(255,150,60,.35), inset 0 0 12px rgba(255,140,40,.12); outline: none; }
.menu-btn:active { transform: scale(.97); }
.menu-btn.primary { border-color: var(--amber-hot); color: #ffe9c9; font-size: 17px; padding: 16px 26px;
  box-shadow: 0 0 22px rgba(255,106,43,.35), inset 0 0 16px rgba(255,110,40,.15); animation: pulseBtn 2.2s ease-in-out infinite; }
@keyframes pulseBtn { 0%,100% { box-shadow: 0 0 16px rgba(255,106,43,.28), inset 0 0 14px rgba(255,110,40,.12);}
  50% { box-shadow: 0 0 30px rgba(255,106,43,.5), inset 0 0 18px rgba(255,110,40,.2);} }
.menu-btn.small { font-size: 12px; padding: 9px 18px; opacity: .9; }
.best-badge { font-size: 13px; letter-spacing: .2em; color: var(--warn); opacity: .9; min-height: 16px; }

#help-panel { max-width: min(520px, 92vw); background: var(--panel); border: 1px solid var(--edge);
  border-radius: 4px; padding: 16px 18px; }
#help-panel table { width: 100%; border-collapse: collapse; font-size: 13px; }
#help-panel td { padding: 5px 8px; text-align: left; border-bottom: 1px dashed rgba(232,192,122,.15); }
#help-panel td:first-child { color: var(--amber); letter-spacing: .12em; }
.help-note { margin-top: 12px; font-size: 12px; line-height: 1.55; opacity: .82; text-align: left; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.hud-box { position: absolute; background: var(--panel); border: 1px solid var(--edge);
  border-radius: 4px; padding: 8px 12px; box-shadow: inset 0 0 14px rgba(255,140,40,.05); }

#standings { top: calc(10px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); min-width: 128px; }
.pos-num { font-size: 34px; color: #fff; font-weight: bold; }
.pos-den { font-size: 15px; opacity: .6; margin-left: 2px; }
#standings-list { margin-top: 4px; font-size: 10.5px; line-height: 1.65; letter-spacing: .04em; }
#standings-list .row-me { color: var(--amber); }
#standings-list .row-gap { float: right; opacity: .75; }

#lapbox { top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); text-align: center; }
#lap-line { font-size: 15px; letter-spacing: .22em; color: var(--amber); }
#race-time { font-size: 21px; color: #fff; margin-top: 2px; letter-spacing: .06em; }
#best-line { font-size: 10.5px; letter-spacing: .18em; opacity: .75; margin-top: 2px; }

.icon-btn { pointer-events: auto; position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  z-index: 12; background: var(--panel); border: 1px solid var(--edge); color: var(--sand);
  width: 44px; height: 44px; border-radius: 4px; font-size: 15px; cursor: pointer; font-family: var(--font); }
.icon-btn:active { transform: scale(.94); border-color: var(--amber); }

#speedbox { bottom: calc(14px + env(safe-area-inset-bottom)); left: calc(14px + env(safe-area-inset-left)); text-align: right; min-width: 132px; }
#speed-num { font-size: 44px; font-weight: bold; color: #fff; line-height: .95; text-shadow: 0 0 14px rgba(255,180,80,.35); font-variant-numeric: tabular-nums; }
#speed-unit { font-size: 11px; letter-spacing: .3em; opacity: .7; }
#throttle-pips { margin-top: 5px; font-size: 10px; letter-spacing: .1em; color: var(--amber); }

#heatbox { bottom: calc(14px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(300px, 46vw); text-align: center; }
#heat-label { font-size: 10px; letter-spacing: .32em; opacity: .8; }
#heat-bar { position: relative; height: 12px; margin-top: 5px; background: rgba(0,0,0,.55);
  border: 1px solid rgba(232,192,122,.25); border-radius: 2px; overflow: hidden; }
#heat-fill { position: absolute; inset: 0; width: 0%;
  background: linear-gradient(90deg, #7fd15a, #ffd23e 55%, #ff7a2b 78%, #ff3d20);
  transition: width .09s linear; }
#heat-danger { position: absolute; top: 0; bottom: 0; left: 78%; width: 1.5px; background: #ff5040; box-shadow: 0 0 6px #ff5040; }
#boost-hint { margin-top: 5px; font-size: 10.5px; letter-spacing: .24em; color: var(--good); transition: color .2s, opacity .2s; }
#boost-hint.hot { color: var(--bad); animation: blinkHot .5s steps(2) infinite; }
#boost-hint.cooling { color: var(--warn); opacity: .8; }
@keyframes blinkHot { 50% { opacity: .25; } }

#hullbox { bottom: calc(14px + env(safe-area-inset-bottom)); right: calc(14px + env(safe-area-inset-right)); text-align: left; }
#hull-label { font-size: 10px; letter-spacing: .32em; opacity: .8; }
#hull-bar { width: 130px; height: 10px; margin-top: 5px; background: rgba(0,0,0,.55); border: 1px solid rgba(232,192,122,.25); border-radius: 2px; overflow: hidden; }
#hull-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff5040, #ffd23e 45%, #9fe870 70%); transition: width .25s; }
#minimap { display: block; margin-top: 8px; opacity: .92; image-rendering: pixelated; }

/* flash messages */
#flash { position: absolute; top: 34%; left: 50%; transform: translate(-50%,-50%) scale(.8);
  font-size: clamp(26px, 6vw, 54px); letter-spacing: .2em; color: #fff; opacity: 0; white-space: nowrap;
  text-shadow: 0 0 24px rgba(255,120,40,.8), 0 3px 0 rgba(0,0,0,.4); }
#flash.show { animation: flashIn .95s cubic-bezier(.17,.89,.32,1.28) forwards; }
@keyframes flashIn { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.7);} 14% { opacity: 1; transform: translate(-50%,-50%) scale(1.06);}
  30% { transform: translate(-50%,-50%) scale(1);} 78% { opacity: 1;} 100% { opacity: 0; transform: translate(-50%,-56%) scale(.98);} }
#split-flash { position: absolute; top: 44%; left: 50%; transform: translateX(-50%);
  font-size: clamp(15px, 3.4vw, 24px); letter-spacing: .18em; color: var(--good); opacity: 0; white-space: nowrap; text-shadow: 0 0 12px rgba(0,0,0,.7); }
#split-flash.show { animation: splitUp 1.4s ease-out forwards; }
#split-flash.bad { color: var(--bad); }
@keyframes splitUp { 0% { opacity: 0; transform: translateX(-50%) translateY(8px);} 15% { opacity: 1; transform: translateX(-50%) translateY(0);}
  75% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) translateY(-14px);} }

#vignette { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s;
  background: radial-gradient(ellipse at center, transparent 46%, rgba(200, 30, 10, .55) 100%); }
#speedlines { position: absolute; inset: 0; pointer-events: none; opacity: 0; mix-blend-mode: screen;
  background: repeating-conic-gradient(from 0deg at 50% 50%, transparent 0deg 3.1deg, rgba(255,220,170,.05) 3.1deg 3.55deg);
  mask-image: radial-gradient(circle at center, transparent 38%, black 78%);
  -webkit-mask-image: radial-gradient(circle at center, transparent 38%, black 78%);
  transition: opacity .25s; }

/* countdown */
#countdown { position: fixed; inset: 0; z-index: 26; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#count-num { font-size: clamp(90px, 22vw, 210px); font-weight: bold; color: var(--amber);
  text-shadow: 0 0 40px rgba(255,110,40,.75), 0 6px 0 #6b2d10; }
#count-num.tick { animation: countPop 1s ease-out forwards; }
#count-num.go { color: var(--good); text-shadow: 0 0 46px rgba(140,255,90,.8), 0 6px 0 #24551a; animation: goFade .9s ease-out forwards; }
@keyframes countPop { 0% { opacity: 0; transform: scale(1.7);} 18% { opacity: 1; transform: scale(1);} 100% { opacity: 1; transform: scale(1);} }
@keyframes goFade { 0% { opacity: 0; transform: scale(1.6);} 20% { opacity: 1; transform: scale(1);} 70% { opacity: 1;} 100% { opacity: 0; transform: scale(.95);} }

/* crash overlay */
#crash-overlay { position: fixed; inset: 0; z-index: 24; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: radial-gradient(ellipse at center, transparent 30%, rgba(120,10,0,.5) 100%); pointer-events: none; }
#crash-title { font-size: clamp(36px, 8vw, 72px); letter-spacing: .22em; color: #ffd9c0;
  text-shadow: 0 0 30px rgba(255,60,20,.85), 0 4px 0 #571503; animation: crashShake .5s linear infinite; }
@keyframes crashShake { 0%,100% { transform: translate(0,0);} 25% { transform: translate(-2px,1px);} 50% { transform: translate(2px,-1px);} 75% { transform: translate(-1px,-1px);} }
#crash-sub { letter-spacing: .2em; font-size: clamp(11px, 2.4vw, 15px); color: var(--warn); }
#crash-bar { width: min(280px, 60vw); height: 8px; border: 1px solid var(--edge); background: rgba(0,0,0,.5); border-radius: 2px; overflow: hidden; }
#crash-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ff7a2b, #ffd23e); }

#wrongway { position: fixed; top: 22%; left: 50%; transform: translateX(-50%); z-index: 22;
  font-size: clamp(18px, 4vw, 32px); letter-spacing: .3em; color: var(--bad);
  text-shadow: 0 0 18px rgba(255,50,30,.8); animation: blinkHot .6s steps(2) infinite; pointer-events: none; }

/* results */
.results-head { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#res-eyebrow { letter-spacing: .4em; font-size: 13px; color: var(--amber); }
#res-place { font-size: clamp(52px, 12vw, 110px); color: #fff; text-shadow: 0 0 34px rgba(255,130,50,.7), 0 5px 0 #6b2d10; }
#res-flavor { font-size: clamp(12px, 2.6vw, 16px); letter-spacing: .1em; opacity: .85; }
#results-table { border-collapse: collapse; font-size: clamp(12px, 2.8vw, 16px); min-width: min(430px, 88vw); }
#results-table td, #results-table th { padding: 7px 14px; text-align: left; border-bottom: 1px dashed rgba(232,192,122,.18); letter-spacing: .05em; }
#results-table th { color: var(--amber); font-weight: normal; letter-spacing: .22em; font-size: .8em; opacity: .85; }
#results-table tr.me td { color: var(--amber); background: rgba(255,150,50,.07); }
#results-table td.num, #results-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.results-stats { font-size: 12px; letter-spacing: .14em; opacity: .8; display: flex; gap: 26px; flex-wrap: wrap; justify-content: center; }

/* ---------- touch controls ---------- */
#touch-ui { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#steer-zone { position: absolute; left: 0; bottom: 0; top: 0; width: 46%;
  pointer-events: auto; touch-action: none; }
#steer-knob { position: absolute; bottom: calc(120px + env(safe-area-inset-bottom)); left: 50%;
  width: 74px; height: 74px; margin-left: -37px; border-radius: 50%;
  border: 2px solid var(--edge); background: rgba(20,11,6,.35);
  transition: transform .12s ease-out, border-color .2s, background .2s; opacity: .85; }
#steer-zone.active #steer-knob { border-color: var(--amber); background: rgba(255,150,50,.18); }
.steer-hint { position: absolute; bottom: calc(146px + env(safe-area-inset-bottom)); font-size: 22px; color: var(--sand); opacity: .35; }
.steer-hint.left { left: calc(50% - 86px); } .steer-hint.right { left: calc(50% + 66px); }
#steer-inv { position: absolute; bottom: calc(202px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 9px; letter-spacing: .22em; color: var(--amber); opacity: .6; white-space: nowrap; }
#touch-buttons { position: absolute; right: calc(12px + env(safe-area-inset-right)); bottom: calc(96px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px; align-items: flex-end; pointer-events: none; }
.touch-btn { pointer-events: auto; width: 96px; height: 96px; border-radius: 50%;
  font-family: var(--font); font-size: 13px; letter-spacing: .14em; color: var(--sand);
  background: rgba(20,11,6,.5); border: 2px solid var(--edge); touch-action: none; }
.touch-btn.primary { border-color: var(--amber-hot); color: #ffe9c9; box-shadow: 0 0 18px rgba(255,106,43,.3); }
.touch-btn.pressed { background: rgba(255,140,50,.35); transform: scale(.93); }
.touch-btn:disabled { opacity: .35; }

/* webgl error */
#webgl-error p { max-width: 400px; line-height: 1.6; opacity: .85; }

/* ---------- responsive / mobile ---------- */
@media (max-width: 720px), (max-height: 460px) {
  #speedbox { min-width: 0; padding: 6px 9px; }
  #speed-num { font-size: 30px; }
  #standings { padding: 6px 8px; min-width: 0; }
  .pos-num { font-size: 24px; }
  #standings-list { font-size: 9px; }
  #race-time { font-size: 15px; }
  #lapbox { padding: 5px 9px; }
  /* keep hull/minimap clear of the touch button stack:
     restack to top-right under the pause button on touch devices */
  #hullbox { bottom: auto; }
  body.touch #hullbox {
    top: calc(62px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
    padding: 4px 7px;
  }
  #hull-bar { width: 84px; }
  #minimap { width: 88px; height: 64px; margin-top: 4px; }
  #heatbox { width: 40vw; padding: 5px 8px; }
  #best-line { display: none; }
}
