@import url("assets/fonts.css");

:root {
  --ink: #0b0c10;
  --graphite: #1b1f26;
  --amber: #ff7a1a;
  --pink: #ff2e93;
  --gold: #e8b54b;
  --chrome: #c9d1d9;
  --silver: #f4eff1;
  --display: "Alfa Slab One", Georgia, serif;
  --text: "Archivo", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #05060a;
  color: var(--silver);
  font-family: var(--text);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit; color: inherit; background: none; border: none; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
button:focus-visible, input:focus-visible {
  outline: 1px solid var(--amber);
  outline-offset: 2px;
}

#app { position: fixed; inset: 0; overflow: hidden; }

/* ---------------------------------------------------------------- start */
#startScreen {
  position: absolute; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center;
  background: #07080c;
  transition: opacity .45s ease;
}
#startScreen.hidden { opacity: 0; pointer-events: none; }

#startScreen .backdrop {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 55%;
  filter: saturate(1.02) brightness(1.02);
}

.startInner {
  position: relative; z-index: 2;
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: max(2vh, 12px) 4vw 3vh;
}

.wordmarkWrap { margin-top: 2vh; text-align: center; pointer-events: none; }
.wordmark {
  width: min(46vw, 640px); max-width: 86vw; height: auto;
  display: block; margin: 0 auto;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,.85));
}
.threed {
  font-family: var(--display);
  font-size: clamp(14px, 2.1vw, 30px);
  letter-spacing: .42em;
  color: var(--gold);
  margin-top: -.2em;
  text-shadow: 0 2px 0 #6b4a12, 0 0 18px rgba(232,181,75,.45);
}

.startDrive {
  position: relative;
  margin-top: auto;
  margin-bottom: 4vh;
  width: clamp(190px, 22vw, 300px);
  aspect-ratio: 1;
  display: grid; place-items: center;
  transition: transform .18s ease, filter .18s ease;
}
.startDrive img { position: absolute; inset: 0; width: 100%; height: 100%; }
.startDrive .prompt {
  position: relative; z-index: 2;
  font-family: var(--display);
  font-size: clamp(11px, 1.25vw, 17px);
  letter-spacing: .2em;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255,122,26,.35), 0 2px 0 #3a2606;
  text-align: center; line-height: 1.5;
  transform: translateY(2px);
}
.startDrive .prompt small {
  display: block;
  font-family: var(--mono); font-size: 9px; letter-spacing: .34em;
  color: #99887a; margin-top: 6px;
}
.startDrive:hover, .startDrive:focus-visible { transform: scale(1.035); filter: brightness(1.12); }
.startDrive:active { transform: scale(.985); }

.ownerKeyBtn {
  position: absolute; left: max(14px, 2.4vw); bottom: max(12px, 2.6vh);
  z-index: 4; display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 6px 2px;
  color: var(--gold);
  opacity: .9;
}
.ownerKeyBtn img { width: 26px; height: auto; filter: sepia(.85) saturate(2.4) hue-rotate(-12deg) brightness(1.12) drop-shadow(0 0 6px rgba(232,181,75,.4)); }
.ownerKeyBtn span {
  font-family: var(--text); font-size: 9px; letter-spacing: .3em;
  text-transform: uppercase; color: #b99a60;
}
.ownerKeyBtn:hover { opacity: 1; }

.startNote {
  position: absolute; right: max(14px, 2.4vw); bottom: max(14px, 2.8vh);
  font-family: var(--mono); font-size: 9px; letter-spacing: .16em;
  color: #7d6a55; text-transform: uppercase;
}

/* ---------------------------------------------------------------- race */
#race { position: absolute; inset: 0; z-index: 10; opacity: 0; pointer-events: none; transition: opacity .5s ease; }
#race.live { opacity: 1; pointer-events: auto; }

#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 46%, rgba(0,0,0,0) 38%, rgba(0,0,0,.42) 100%),
    linear-gradient(180deg, rgba(0,0,0,.35), rgba(0,0,0,0) 18%, rgba(0,0,0,0) 76%, rgba(0,0,0,.4));
}

/* HUD */
.hud { position: absolute; z-index: 20; }

#hudTop {
  top: max(10px, 1.6vh); right: max(10px, 1.4vw);
  display: flex; align-items: center; gap: clamp(3px, .5vw, 8px);
  padding: 6px 8px;
  background: linear-gradient(180deg, rgba(14,16,20,.82), rgba(8,9,12,.74));
  border: 1px solid rgba(232,181,75,.22);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.06);
  backdrop-filter: blur(2px);
}
.hudBtn {
  position: relative;
  width: clamp(27px, 3.1vw, 40px); height: clamp(27px, 3.1vw, 40px);
  display: grid; place-items: center;
  border-radius: 6px;
  opacity: .82;
  transition: opacity .15s, background .15s, box-shadow .15s;
}
.hudBtn img, .hudBtn svg { width: 88%; height: 88%; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(0,0,0,.8)); }
.hudBtn:hover { opacity: 1; background: rgba(255,122,26,.1); }
.hudBtn.on {
  opacity: 1;
  background: rgba(255,122,26,.16);
  box-shadow: inset 0 0 0 1px rgba(255,122,26,.5), 0 0 14px rgba(255,122,26,.28);
}
.hudBtn[data-act="owner"] img, .pauseOwner img { filter: sepia(.85) saturate(2.4) hue-rotate(-12deg) brightness(1.12); }
.hudBtn::after {
  content: attr(data-label);
  position: absolute; top: calc(100% + 7px); right: 0;
  font-family: var(--mono); font-size: 8px; letter-spacing: .16em;
  color: #ffd7a8; white-space: nowrap; text-transform: uppercase;
  background: rgba(8,9,12,.92); border: 1px solid rgba(232,181,75,.24);
  padding: 3px 5px; border-radius: 3px;
  opacity: 0; transform: translateY(-3px); pointer-events: none;
  transition: opacity .15s, transform .15s;
}
.hudBtn:hover::after, .hudBtn:focus-visible::after { opacity: 1; transform: none; }

/* telemetry */
#telemetry {
  left: max(12px, 2vw); bottom: max(12px, 2.2vh);
  font-family: var(--mono); font-size: clamp(8px, .8vw, 11px);
  letter-spacing: .13em; color: var(--amber);
  text-transform: uppercase;
  text-shadow: 0 0 8px rgba(255,122,26,.4);
  display: flex; flex-wrap: wrap; gap: 4px 14px; max-width: 52vw;
  opacity: .92;
}
#telemetry b { color: var(--silver); font-weight: 400; }
#telemetry .dim { color: #b07a45; }

/* gauge */
#gaugeWrap {
  right: max(8px, 1.5vw); bottom: max(6px, 1.2vh);
  width: clamp(118px, 21vmin, 236px);
  aspect-ratio: 1;
  filter: drop-shadow(0 10px 24px rgba(0,0,0,.7));
}
#gaugeWrap > img { position: absolute; inset: 0; width: 100%; height: 100%; }
#needle {
  position: absolute; left: 50%; top: 50%;
  width: 2.4%; height: 33%;
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) rotate(225deg);
  background: linear-gradient(180deg, #ffd3e4 0%, #ff2e93 28%, #d81a6f 100%);
  border-radius: 2px 2px 1px 1px;
  box-shadow: 0 0 8px rgba(255,46,147,.85);
  will-change: transform;
  z-index: 3;
}
#needle::after {
  content: ""; position: absolute; left: 50%; top: -3px; transform: translateX(-50%);
  width: 240%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff2c4, #e8b54b 55%, #7d5a18 100%);
  box-shadow: 0 0 6px rgba(0,0,0,.8);
}
.gaugeDigits {
  position: absolute; left: 50%; top: 64%; transform: translate(-50%, 0);
  z-index: 4; text-align: center; pointer-events: none;
  font-family: var(--mono); color: var(--silver);
  text-shadow: 0 0 6px rgba(0,0,0,.9);
  line-height: 1;
}
.gaugeDigits .spd {
  font-size: clamp(15px, 2.5vmin, 28px); font-weight: 700; letter-spacing: .02em;
  color: #f4eff1;
}
.gaugeDigits .unit {
  display: block; font-size: clamp(5px, .72vmin, 8px); letter-spacing: .22em;
  color: #b07a45; margin-top: 3px;
}
.gaugeDigits .gear {
  display: inline-block; margin-top: 4px;
  font-size: clamp(7px, 1vmin, 11px); letter-spacing: .15em;
  color: var(--pink); border-top: 1px solid rgba(232,181,75,.35); padding-top: 3px;
}

#runClock {
  left: 50%; top: max(10px, 1.6vh); transform: translateX(-50%);
  font-family: var(--mono); font-size: clamp(9px, 1vw, 13px);
  letter-spacing: .26em; color: #e7c78f; opacity: .85;
  text-align: center;
}
#runClock small { display: block; font-size: 7px; letter-spacing: .4em; color: #8d7358; margin-top: 3px; }

/* touch driving */
#touchPad { display: none; }
@media (pointer: coarse) {
  #touchPad {
    display: flex; gap: 8px;
    left: max(10px, 2vw); bottom: calc(max(10px, 2vh) + 26px);
    z-index: 21;
  }
  #touchPad button {
    width: 58px; height: 58px; border-radius: 50%;
    border: 1px solid rgba(232,181,75,.4);
    background: radial-gradient(circle at 50% 35%, rgba(40,44,52,.85), rgba(10,11,14,.85));
    color: var(--gold); font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
    display: grid; place-items: center;
    touch-action: none;
  }
  #touchPad button:active { background: rgba(255,122,26,.25); }
  #telemetry { bottom: auto; top: max(52px, 8vh); max-width: 46vw; }
}

/* ---------------------------------------------------------------- owner console */
#console {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  transform: translateY(102%);
  transition: transform .55s cubic-bezier(.22,.9,.24,1);
  padding: 0 clamp(6px, 1.2vw, 20px) clamp(6px, 1.2vh, 14px);
  will-change: transform;
}
#console.open { transform: translateY(0); }
.consolePlate {
  position: relative;
  margin: 0 auto;
  width: min(1080px, 95vw, 84vh);
  background: url("assets/owner_console.webp") center / 100% 100% no-repeat;
  aspect-ratio: 1024 / 436;
  padding: 4.2% 4.2% 3.4%;
}
.consoleChase {
  position: absolute; top: .7%; left: 4%; right: 4%; height: 3px;
  background: linear-gradient(90deg, transparent, #ffd79a, #ff7a1a, transparent);
  opacity: 0; border-radius: 2px;
}
#console.open .consoleChase { animation: chase .9s ease-out .12s 1 both; }
@keyframes chase {
  0% { opacity: 0; transform: scaleX(.05); transform-origin: left; }
  25% { opacity: 1; }
  100% { opacity: 0; transform: scaleX(1); transform-origin: left; }
}

.consoleGrid {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr minmax(200px, 35%);
  grid-template-rows: 1fr auto;
  gap: 2% 2.6%;
  min-height: 0;
  z-index: 2;
}
.consoleTop {
  grid-column: 1; grid-row: 1;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; min-height: 0;
  padding: 0 1% 0 1.5%;
}
.consoleTitle {
  font-family: var(--display); font-size: clamp(9px, 1.05vw, 15px);
  letter-spacing: .16em; color: var(--gold); white-space: nowrap;
  text-shadow: 0 1px 0 #000;
}
.consolePips { display: flex; gap: 5px; align-items: center; }
.pip {
  width: 5px; height: 5px; border-radius: 50%;
  background: #3a2a12; box-shadow: inset 0 0 2px #000;
  transition: background .12s, box-shadow .12s;
}
.pip.lit { background: var(--amber); box-shadow: 0 0 7px rgba(255,122,26,.95); }

.log {
  grid-column: 1; grid-row: 1;
  align-self: end;
  height: 100%;
  padding: 22px 2% 0 1.5%;
  overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
  font-family: var(--mono);
  font-size: clamp(9px, .84vw, 12px);
  line-height: 1.45;
  color: #c8beb2;
  mask-image: linear-gradient(180deg, transparent 0, #000 16%);
}
.log .row { white-space: pre-wrap; word-break: break-word; opacity: .55; }
.log .row:nth-last-child(1) { opacity: 1; }
.log .row:nth-last-child(2) { opacity: .92; }
.log .row:nth-last-child(3) { opacity: .8; }
.log .row.cmd { color: var(--amber); }
.log .row.err { color: var(--amber); }
.log .row.ok { color: #e8d9c0; }
.log .row .tag { color: #8b6a3e; }

.cmdList {
  grid-column: 2; grid-row: 1 / span 2;
  align-self: stretch;
  overflow: auto;
  padding: 18px 2% 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 10px;
  align-content: start;
  font-family: var(--mono);
  font-size: clamp(8px, .72vw, 10.5px);
  letter-spacing: .02em;
  scrollbar-width: none;
}
.cmdList::-webkit-scrollbar { display: none; }
.cmdList button {
  text-align: left; color: #9d866c; padding: 2px 0; white-space: nowrap;
  border-bottom: 1px solid rgba(255,122,26,.06);
  overflow: hidden; text-overflow: ellipsis;
}
.cmdList button:hover { color: #ffd7a8; }
.cmdList .head {
  color: #7a5f3f; font-size: .82em; letter-spacing: .18em;
  padding: 5px 0 2px; grid-column: 1 / -1; text-transform: uppercase;
}

.inputRow {
  grid-column: 1; grid-row: 2;
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 3.5% 2%;
  font-family: var(--mono);
  font-size: clamp(9px, .8vw, 12px);
  color: var(--amber);
}
.inputRow .caretKey { color: #7a5f3f; }
#cmdInput {
  flex: 1; min-width: 0;
  font-family: var(--mono); font-size: inherit;
  color: #ffd7a8; background: transparent; border: none;
  caret-color: var(--amber);
  -webkit-user-select: text; user-select: text;
}
#cmdInput::placeholder { color: #5f4a33; }
.blockCaret {
  width: .62em; height: 1.05em; background: var(--amber);
  box-shadow: 0 0 8px rgba(255,122,26,.6);
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------------------------------------------------------------- pause / results */
#pause {
  position: absolute; inset: 0; z-index: 45;
  display: none;
  align-items: center; justify-content: center;
  padding: 18px;
  background: radial-gradient(ellipse at 50% 50%, rgba(6,7,10,.62), rgba(4,5,8,.9));
  backdrop-filter: blur(3px) saturate(.8);
}
#pause.show { display: flex; }
.pauseCard {
  width: min(520px, 94vw);
  background:
    linear-gradient(180deg, rgba(26,29,35,.97), rgba(12,14,18,.98));
  border: 1px solid rgba(232,181,75,.45);
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,.85), inset 0 1px 0 rgba(255,255,255,.08);
  padding: 18px clamp(16px, 3vw, 30px) 20px;
  position: relative;
  overflow: hidden;
}
.pauseCard::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, #ffb15e, transparent);
  box-shadow: 0 0 12px rgba(255,122,26,.5);
}
.pauseCard .miniMark { width: min(190px, 52%); display: block; margin: 0 auto 4px; }
.pauseCard .cardTitle {
  text-align: center; font-family: var(--text); text-transform: uppercase;
  font-size: 9px; letter-spacing: .42em; color: #a98a5c; margin: 2px 0 16px;
}
.runStats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 16px;
}
.stat {
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(0,0,0,.25));
  border: 1px solid rgba(232,181,75,.18); border-radius: 6px;
  padding: 8px 6px; text-align: center;
}
.stat .k {
  font-family: var(--mono); font-size: 7px; letter-spacing: .24em;
  color: #8d7358; text-transform: uppercase;
}
.stat .v {
  font-family: var(--mono); font-size: clamp(14px, 2.2vw, 21px);
  color: var(--silver); margin-top: 3px; letter-spacing: .02em;
}
.stat .v small { font-size: .55em; color: #b07a45; letter-spacing: .1em; }
.cardButtons { display: flex; gap: 10px; }
.plateBtn {
  flex: 1; padding: 11px 8px 12px;
  border: 1px solid rgba(232,181,75,.4); border-radius: 8px;
  background: linear-gradient(180deg, #22262e, #12151a);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.09), 0 4px 10px rgba(0,0,0,.5);
  font-family: var(--display);
  font-size: clamp(9px, 1.05vw, 12px);
  letter-spacing: .13em; color: var(--gold);
  transition: filter .15s, transform .12s;
}
.plateBtn:hover { filter: brightness(1.22); }
.plateBtn:active { transform: translateY(1px); }
.plateBtn.primary { border-color: rgba(255,122,26,.65); color: #ffd2a5; box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 0 18px rgba(255,122,26,.18); }
.pauseOwner { display: flex; justify-content: center; margin-top: 14px; }
.pauseOwner button {
  display: flex; align-items: center; gap: 8px; opacity: .75;
  color: var(--gold); font-size: 8px; letter-spacing: .28em; text-transform: uppercase;
}
.pauseOwner img { width: 17px; }
.pauseOwner button:hover { opacity: 1; }
.bestLine {
  text-align: center; font-family: var(--mono); font-size: 8px; letter-spacing: .2em;
  color: #7d674e; margin-bottom: 12px; text-transform: uppercase;
}

/* boot / loading */
#boot {
  position: absolute; inset: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: #06070b; color: #b99a60;
  font-family: var(--mono); font-size: 10px; letter-spacing: .34em;
  text-transform: uppercase; transition: opacity .4s ease;
}
#boot.gone { opacity: 0; pointer-events: none; }
#boot .bar { width: min(240px, 50vw); height: 2px; background: #241b10; overflow: hidden; }
#boot .bar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #ff7a1a, #ffd79a); transition: width .3s; }

/* flash + damage */
#flash {
  position: absolute; inset: 0; z-index: 25; pointer-events: none;
  background: radial-gradient(circle at 50% 60%, rgba(255,122,26,.6), transparent 70%);
  opacity: 0;
}
#flash.hit { animation: hitFlash .4s ease-out; }
@keyframes hitFlash { 0% { opacity: 1; } 100% { opacity: 0; } }

@media (max-width: 720px) {
  .wordmark { width: min(64vw, 440px); }
  .consoleGrid { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .cmdList { display: none; }
  .startDrive { margin-bottom: 6vh; }
  #telemetry { font-size: 8px; }
  .hudBtn[data-act="owner"] img, .pauseOwner img { filter: sepia(.85) saturate(2.4) hue-rotate(-12deg) brightness(1.12); }
.hudBtn::after { display: none; }
  .runStats { gap: 5px; }
}

@media (orientation: portrait) {
  #startScreen .backdrop { object-position: 50% 50%; }
  .wordmark { width: min(82vw, 520px); margin-top: 6vh; }
  .startDrive { width: min(46vw, 260px); }
  .hudBtn { width: 30px; height: 30px; }
  #gaugeWrap { width: clamp(112px, 30vmin, 190px); }
  .log { font-size: 9px; padding-top: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  #console { transition-duration: .01s; }
  .blockCaret { animation: none; }
}
