:root {
  --ember: #ff8a3c;
  --ember-deep: #c65a1e;
  --gold: #ffd9a0;
  --ink: #1a0d08;
  --panel: rgba(24, 12, 8, 0.82);
  --line: rgba(255, 190, 120, 0.35);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #1a0d08;
  font-family: Georgia, 'Times New Roman', serif; color: #ffe6c8;
  -webkit-user-select: none; user-select: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
kbd {
  display: inline-block; min-width: 1.6em; text-align: center;
  padding: 1px 7px 2px; border: 1px solid var(--line); border-bottom-width: 3px;
  border-radius: 5px; background: rgba(255,220,180,.08);
  font-family: 'Courier New', monospace; font-size: .82em; color: var(--gold);
}
button { font-family: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.screen-dim { background: radial-gradient(ellipse at center, rgba(20,8,4,.35), rgba(10,4,2,.72)); backdrop-filter: blur(2px); }

#startScreen {
  background: radial-gradient(ellipse at 50% 118%, rgba(255,150,60,.28), rgba(20,8,4,0) 55%);
  justify-content: center;
}
.start-inner { max-width: 660px; padding: 24px 30px; animation: rise .9s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.kicker { letter-spacing: .42em; font-size: 12px; color: var(--ember); text-transform: uppercase; font-family: 'Courier New', monospace; }
#startScreen h1 {
  font-size: clamp(56px, 9vw, 96px); font-weight: 400; letter-spacing: .04em;
  color: #ffe9c9; line-height: 1.02; margin: 10px 0 18px;
  text-shadow: 0 0 34px rgba(255,140,50,.45), 0 2px 0 rgba(60,20,5,.6);
}
.goal { font-size: clamp(17px, 2.1vw, 22px); color: #ffd9a8; font-style: italic; }
.par-line { margin: 14px 0 20px; font-family: 'Courier New', monospace; font-size: 14px; letter-spacing: .12em; color: #f0b070; }
.par-line strong { color: #ffe9c9; }

.controls {
  display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px 14px;
  max-width: 560px; margin: 0 auto 14px; text-align: left;
}
.ctl { font-size: 13.5px; color: #e8c49a; display: flex; align-items: center; gap: 8px; }
.keys { white-space: nowrap; }
.hint-small { font-size: 12.5px; color: #b98d63; max-width: 470px; margin: 0 auto 16px; line-height: 1.45; }

.best-line { font-family: 'Courier New', monospace; letter-spacing: .1em; font-size: 13px; color: #ffc27a; margin-bottom: 16px; min-height: 1.2em; }

.btn-primary {
  display: inline-block; border: 1px solid rgba(255,210,150,.6); border-radius: 999px;
  background: linear-gradient(180deg, #ff9a3e, #d95f1e);
  color: #2a0e02; font-size: 19px; letter-spacing: .22em; text-transform: uppercase;
  padding: 13px 58px; box-shadow: 0 0 34px rgba(255,140,50,.4), inset 0 1px 0 rgba(255,255,255,.5);
  transition: transform .15s ease, box-shadow .15s ease;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 0 46px rgba(255,150,60,.55), inset 0 1px 0 rgba(255,255,255,.5); }
.press-enter { margin-top: 10px; font-size: 12px; color: #b98d63; letter-spacing: .08em; }
.btn-ghost {
  display: block; margin: 18px auto 0; background: transparent; color: #e8b988;
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 22px; font-size: 13px; letter-spacing: .05em;
}
.btn-ghost:hover { background: rgba(255,190,120,.08); color: var(--gold); }
.webgl-note { margin-top: 14px; color: #ffb08a; font-size: 13px; }

/* ---------- panels ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 34px 44px; min-width: 340px; max-width: 480px;
  box-shadow: 0 30px 80px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,220,170,.18);
}
.panel h2 { font-size: 40px; font-weight: 400; color: #ffe9c9; letter-spacing: .04em; margin: 6px 0 4px; }
.panel-sub { color: #c99a6e; font-style: italic; margin-bottom: 20px; }
.panel .btn-primary { margin-top: 6px; }

.medal { margin: 14px auto 6px; animation: pop .6s cubic-bezier(.2,1.6,.4,1) both .15s; }
@keyframes pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }
.medal-text { font-family: 'Courier New', monospace; letter-spacing: .34em; color: #ffcf8a; font-size: 17px; margin-top: 6px; }
.medal-sub { color: #c99a6e; font-size: 12.5px; margin-top: 2px; }
.no-medal { color: #b98d63; font-size: 13px; margin: 16px 0 4px; font-style: italic; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 26px; margin: 18px 0 14px; }
.stat { border: 1px solid rgba(255,190,120,.18); border-radius: 10px; padding: 10px 8px; background: rgba(255,170,90,.05); }
.stat-label { font-family: 'Courier New', monospace; font-size: 10.5px; letter-spacing: .22em; color: #b98d63; }
.stat-value { font-size: 27px; color: #ffe9c9; margin-top: 3px; font-variant-numeric: tabular-nums; }

.btn-row { display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap; }
.btn-row .btn-ghost { display: inline-block; margin: 0; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; font-variant-numeric: tabular-nums; }
.hud-label { font-family: 'Courier New', monospace; font-size: 10px; letter-spacing: .26em; color: rgba(255,220,170,.75); }
.hud-label-inline { font-family: 'Courier New', monospace; font-size: 10px; letter-spacing: .26em; color: rgba(255,220,170,.6); margin-left: 8px; }
.hud-tl { position: absolute; top: 18px; left: 22px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.hud-island { font-size: 23px; color: #ffe9c9; letter-spacing: .03em; margin: 2px 0 4px; }
.hud-rings { font-size: 20px; color: #ffd9a0; font-family: 'Courier New', monospace; }
.hud-rings .dim { color: rgba(255,220,170,.45); }

.hud-tc { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); text-align: center; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.hud-time { font-size: 33px; color: #ffe9c9; font-family: 'Courier New', monospace; letter-spacing: .08em; }
.hud-par { font-size: 11px; letter-spacing: .3em; color: rgba(255,210,150,.8); font-family: 'Courier New', monospace; margin-top: 1px; }
.hud-time.over { color: #ff9d6e; }

.hud-tr { position: absolute; top: 18px; right: 22px; text-align: right; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.hud-speed { font-size: 36px; color: #ffe9c9; font-family: 'Courier New', monospace; line-height: 1; }

/* altitude tape */
#altTape {
  position: absolute; right: 26px; top: 50%; transform: translateY(-50%);
  width: 12px; height: 42vh; border-radius: 7px; overflow: hidden;
  background: rgba(20,10,6,.55); border: 1px solid rgba(255,200,130,.35);
}
#altFill {
  position: absolute; bottom: 0; left: 0; right: 0; height: 35%;
  background: linear-gradient(180deg, #ffd27a, #ff8a3c 60%, #d94e16);
  box-shadow: 0 0 12px rgba(255,150,60,.6); transition: height .18s linear;
}
#altReadout { position: absolute; right: 46px; top: 50%; transform: translateY(-50%); font-family: 'Courier New', monospace; font-size: 17px; color: #ffd9a0; text-shadow: 0 1px 4px #000; }
.hud-altlabel { position: absolute; right: 22px; top: calc(50% + 22vh); font-family: 'Courier New', monospace; font-size: 10px; letter-spacing: .3em; color: rgba(255,220,170,.75); }

/* next ring indicator */
#nextRing {
  position: absolute; right: 24px; bottom: 84px; width: 96px; text-align: center;
  padding: 10px 6px 8px; border-radius: 12px;
  background: rgba(30,14,8,.55); border: 1px solid rgba(255,200,130,.3);
  backdrop-filter: blur(2px);
}
#nextArrow { display: block; margin: 0 auto; transition: transform .12s linear; filter: drop-shadow(0 0 6px rgba(255,170,70,.7)); }
#nextDist { font-family: 'Courier New', monospace; color: #ffd9a0; font-size: 15px; margin-top: 4px; }

/* stall + penalty + banner */
#stallWarn {
  position: absolute; top: 24%; left: 50%; transform: translate(-50%, -8px);
  font-family: 'Courier New', monospace; letter-spacing: .3em; font-size: 17px; color: #ffb03c;
  border: 1px solid rgba(255,176,60,.6); border-radius: 8px; padding: 8px 20px;
  background: rgba(40,16,4,.72); opacity: 0; transition: opacity .15s; pointer-events: none;
  animation: stallBlink .5s steps(2) infinite;
}
@keyframes stallBlink { 50% { color: #ff5f2e; border-color: rgba(255,95,46,.8); } }
#stallWarn.show { opacity: 1; }

#penalty {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, 0) scale(.8);
  font-family: 'Courier New', monospace; font-size: 40px; color: #ff7a4d; opacity: 0;
  text-shadow: 0 0 18px rgba(255,110,50,.6); pointer-events: none;
}
#penalty.show { animation: penUp 1.6s ease-out both; }
@keyframes penUp {
  0% { opacity: 0; transform: translate(-50%, 14px) scale(.8); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -34px) scale(.9); }
}

#banner {
  position: absolute; top: 16%; left: 50%; transform: translate(-50%, -10px);
  font-size: 30px; letter-spacing: .18em; color: #ffe0ae; opacity: 0;
  text-shadow: 0 0 26px rgba(255,160,70,.65), 0 2px 2px rgba(0,0,0,.5);
  pointer-events: none; white-space: nowrap; text-transform: uppercase;
}
#banner.show { animation: bannerIn 2.4s ease-out both; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, 12px); }
  12% { opacity: 1; transform: translate(-50%, 0); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}

#crashFlash {
  position: fixed; inset: 0; z-index: 15; background: radial-gradient(ellipse at center, rgba(190,230,255,.0), rgba(215,235,255,.85));
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
#crashFlash.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
}
@media (max-width: 760px) {
  .controls { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .hud-island { font-size: 18px; }
  #altTape { display: none; }
  .hud-altlabel { display: none; }
  #altReadout { right: 20px; top: auto; bottom: 120px; transform: none; }
}
