:root {
  --bg: #07090d;
  --ink: #eef1f5;
  --ink-2: #c3cad4;
  --muted: #7f8896;
  --line: rgba(255, 255, 255, 0.12);
  --line-2: rgba(255, 255, 255, 0.22);
  --panel: rgba(10, 13, 18, 0.62);
  --panel-solid: rgba(10, 13, 18, 0.86);
  --cyan: #9fdcff;
  --cyan-2: #5fc3ff;
  --amber: #ffb963;
  --red: #ff5c55;
  --font: 'Segoe UI', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Roboto, Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

/* ----------------------------------------------------------------- brand */
.brand {
  display: flex;
  align-items: baseline;
  gap: 0.08em;
  font-size: 22px;
  letter-spacing: 0.32em;
  line-height: 1;
  text-transform: uppercase;
  margin: 0;
}
.brand .b-play {
  font-weight: 300;
  color: var(--ink-2);
}
.brand .b-road {
  font-weight: 700;
  color: var(--ink);
}
.brand.big {
  font-size: clamp(24px, 6.4vw, 34px);
  letter-spacing: 0.17em;
  white-space: nowrap;
}

/* ----------------------------------------------------------------- screens */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  pointer-events: none;
}
.screen.show {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease;
  pointer-events: auto;
}

#loading {
  background: radial-gradient(120% 90% at 50% 60%, #0d1118 0%, #05070a 70%);
}
.load-wrap {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.load-bar {
  height: 2px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.load-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #d6dde6, var(--cyan));
  transform-origin: 0 50%;
  transform: scaleX(0);
  transition: transform 0.25s ease;
}
.load-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.error {
  font-size: 13px;
  line-height: 1.5;
  color: #ffd2cf;
  border-left: 2px solid var(--red);
  padding: 8px 12px;
  background: rgba(255, 92, 85, 0.08);
}

#menu {
  justify-content: flex-start;
  align-items: flex-end;
  background: linear-gradient(90deg, rgba(5, 7, 10, 0.78) 0%, rgba(5, 7, 10, 0.35) 42%, rgba(5, 7, 10, 0) 65%);
}
.menu-card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px 24px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#menu .menu-card {
  margin: 0 0 4vh 4vw;
}
.menu-card.compact {
  width: min(320px, 100%);
}
.eyebrow {
  font-size: 10.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
}
.tagline {
  margin: -2px 0 6px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-2);
  font-weight: 300;
}
.title {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
#start-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field span,
.select span {
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.field input {
  appearance: none;
  border: 1px solid var(--line-2);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  padding: 12px 14px;
  font-size: 16px;
  letter-spacing: 0.04em;
  border-radius: 2px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.field input:focus {
  border-color: var(--cyan-2);
  box-shadow: 0 0 0 3px rgba(95, 195, 255, 0.15);
}
.field-error {
  font-size: 12px;
  color: var(--amber);
  margin-top: -4px;
}
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink);
  padding: 12px 16px;
  font-size: 12.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  touch-action: manipulation;
}
.btn:hover {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.05);
}
.btn:focus-visible,
.icon:focus-visible,
select:focus-visible {
  outline: 2px solid var(--cyan-2);
  outline-offset: 2px;
}
.btn.primary {
  background: var(--ink);
  color: #07090d;
  border-color: var(--ink);
  font-weight: 600;
  padding: 15px 16px;
}
.btn.primary:hover {
  background: #fff;
}
.btn.ghost {
  flex: 1;
  font-size: 11px;
  padding: 11px 10px;
}
.row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: wrap;
}
.select {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}
.select select {
  appearance: none;
  background: rgba(0, 0, 0, 0.35) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a94a3'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--ink);
  border: 1px solid var(--line-2);
  padding: 7px 26px 7px 10px;
  font-size: 13px;
  border-radius: 2px;
}
.controls-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  margin: 0 1px;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  font: 600 10.5px/18px var(--font);
  text-align: center;
  color: var(--ink-2);
}
.fine {
  margin: 0;
  font-size: 10.5px;
  line-height: 1.5;
  color: #616a77;
}
.only-touch {
  display: none;
}
@media (hover: none) and (pointer: coarse) {
  .only-touch {
    display: block;
  }
  .only-desktop {
    display: none;
  }
}

/* ----------------------------------------------------------------- HUD */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}
#hud[hidden] {
  display: none;
}
.hud-tl,
.hud-tr {
  position: absolute;
  top: calc(18px + var(--safe-t));
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hud-tl {
  left: calc(22px + var(--safe-l));
}
.hud-tr {
  right: calc(70px + var(--safe-r));
  align-items: flex-end;
}
.lbl {
  font-size: 10px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--muted);
}
.num.big {
  font-size: 34px;
  font-weight: 300;
  letter-spacing: 0.02em;
  line-height: 1.05;
}
.sub {
  display: flex;
  gap: 14px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.sub b {
  color: var(--ink-2);
  font-weight: 600;
}
.speed {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.speed .num.big {
  font-size: 44px;
  font-weight: 200;
}
.unit {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.next-chip {
  position: absolute;
  left: 50%;
  top: calc(20px + var(--safe-t));
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: rgba(8, 10, 14, 0.45);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
  opacity: 0;
  transition: opacity 0.25s ease;
  white-space: nowrap;
}
.next-chip.show {
  opacity: 1;
}
.next-chip b {
  color: var(--amber);
  font-weight: 600;
}
.next-chip.tall b {
  color: var(--red);
}

.combo {
  position: absolute;
  left: 50%;
  top: calc(60px + var(--safe-t));
  transform: translateX(-50%);
  font-size: 13px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--cyan);
  opacity: 0;
  white-space: nowrap;
}
.combo b {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
  margin-left: 6px;
}
.combo.show {
  opacity: 1;
}
.combo.pop {
  animation: pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.combo.lost {
  color: var(--amber);
}

.flash {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.flash-title {
  text-transform: uppercase;
  font-size: clamp(28px, 7vw, 54px);
  font-weight: 200;
  letter-spacing: 0.42em;
  margin-right: -0.42em;
  color: var(--ink);
}
.flash-sub {
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: 0.24em;
  color: var(--cyan);
  text-transform: uppercase;
}
.flash.show {
  animation: flash 1.1s ease-out forwards;
}
.flash.warn .flash-title {
  text-transform: uppercase;
  color: var(--amber);
}
.flash.crash .flash-title {
  text-transform: uppercase;
  color: var(--red);
  font-weight: 300;
}

.hud-bottom {
  position: absolute;
  left: 50%;
  bottom: calc(22px + var(--safe-b));
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.state-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pill {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.24em;
  padding: 4px 10px;
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  background: rgba(8, 10, 14, 0.45);
}
.pill.ready {
  color: var(--cyan);
  border-color: rgba(159, 220, 255, 0.5);
}
.pill.air {
  color: #07090d;
  background: var(--cyan);
  border-color: var(--cyan);
}
.pill.warn {
  color: var(--amber);
  border-color: rgba(255, 185, 99, 0.5);
}
.alt {
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ink-2);
}
.fuel-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.fuel-bar {
  position: relative;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  overflow: hidden;
}
.fuel-bar i {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #6fbfe8, #c8ecff);
  transform-origin: 0 50%;
  transform: scaleX(1);
}
.fuel-bar.low i {
  background: linear-gradient(90deg, #d98a3c, var(--amber));
}
.fuel-bar .ticks {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), rgba(7, 9, 13, 0.85) calc(10% - 1px) 10%);
}

/* ----------------------------------------------------------------- toolbar */
#toolbar {
  position: absolute;
  top: calc(14px + var(--safe-t));
  right: calc(14px + var(--safe-r));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
  z-index: 5;
}
.icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: rgba(8, 10, 14, 0.5);
  color: var(--ink-2);
  cursor: pointer;
  border-radius: 2px;
  fill: currentColor;
  touch-action: manipulation;
}
.icon[hidden] {
  display: none;
}
.icon:hover {
  color: var(--ink);
  border-color: var(--line-2);
}
#mute-btn .off {
  display: none;
}
#mute-btn[aria-pressed='true'] .on {
  display: none;
}
#mute-btn[aria-pressed='true'] .off {
  display: block;
}

/* ----------------------------------------------------------------- touch */
#touch {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  touch-action: none;
}
#touch[hidden] {
  display: none;
}
.steer-hint {
  position: absolute;
  bottom: calc(40px + var(--safe-b));
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 200;
  color: rgba(255, 255, 255, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}
.steer-hint.left {
  left: calc(18px + var(--safe-l));
}
.steer-hint.right {
  right: calc(18px + var(--safe-r));
}
#thrust-btn {
  position: absolute;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translateX(-50%);
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 1px solid rgba(159, 220, 255, 0.55);
  background: radial-gradient(circle at 50% 40%, rgba(159, 220, 255, 0.22), rgba(8, 10, 14, 0.55) 70%);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.22em;
  touch-action: none;
}
#thrust-btn.active {
  background: radial-gradient(circle at 50% 40%, rgba(200, 236, 255, 0.55), rgba(40, 90, 120, 0.5) 70%);
  border-color: var(--cyan);
}
body.touch .hud-bottom {
  bottom: calc(212px + var(--safe-b));
  width: min(300px, calc(100vw - 32px));
}

/* ----------------------------------------------------------------- game over / board */
#gameover {
  background: radial-gradient(80% 80% at 50% 50%, rgba(5, 7, 10, 0.25), rgba(5, 7, 10, 0.75));
}
#pause {
  background: rgba(5, 7, 10, 0.55);
}
.pb {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #07090d;
  background: var(--cyan);
  padding: 5px 10px;
}
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.stats > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stats span {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.stats b {
  font-size: 20px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.share-box textarea {
  width: 100%;
  resize: none;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink-2);
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.5;
  user-select: text;
  -webkit-user-select: text;
}
#board {
  background: rgba(5, 7, 10, 0.6);
  z-index: 10;
}
.board {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
  counter-reset: rank;
}
.board li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.board li .r {
  color: var(--muted);
  font-size: 12px;
}
.board li .n {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board li .s {
  font-weight: 600;
}
.board li .m {
  grid-column: 2 / 4;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin-top: -4px;
}
.board li.me .n,
.board li.me .s {
  color: var(--cyan);
}
.board .empty {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

#debug {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font: 11px/1.45 ui-monospace, Consolas, monospace;
  color: #9fe;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 8px;
  white-space: pre;
  pointer-events: none;
}
.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
}

@keyframes pop {
  0% {
    transform: translateX(-50%) scale(0.7);
  }
  100% {
    transform: translateX(-50%) scale(1);
  }
}
@keyframes flash {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.96);
    letter-spacing: 0.3em;
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -54%) scale(1.02);
  }
}

/* ----------------------------------------------------------------- responsive */
@media (max-width: 640px) {
  #menu {
    align-items: flex-end;
    justify-content: center;
    background: linear-gradient(0deg, rgba(5, 7, 10, 0.88) 0%, rgba(5, 7, 10, 0.4) 55%, rgba(5, 7, 10, 0) 80%);
  }
  #menu .menu-card {
    margin: 0;
    padding: 20px 18px 18px;
    gap: 11px;
  }
  .num.big {
    font-size: 26px;
  }
  .speed .num.big {
    font-size: 32px;
  }
  .hud-tl {
    left: calc(14px + var(--safe-l));
    top: calc(12px + var(--safe-t));
  }
  .hud-tr {
    right: calc(62px + var(--safe-r));
    top: calc(12px + var(--safe-t));
  }
  .sub {
    gap: 8px;
    font-size: 10px;
  }
  .next-chip {
    top: calc(84px + var(--safe-t));
    font-size: 10px;
  }
  .combo {
    top: calc(118px + var(--safe-t));
  }
  .stats b {
    font-size: 17px;
  }
}
@media (max-height: 520px) and (orientation: landscape) {
  #menu .menu-card {
    margin: 0 0 0 3vw;
    max-height: calc(100vh - 24px);
  }
  .tagline {
    display: none;
  }
  #thrust-btn {
    bottom: calc(24px + var(--safe-b));
    width: 88px;
    height: 88px;
  }
  body.touch .hud-bottom {
    bottom: calc(18px + var(--safe-b));
    left: auto;
    right: calc(20px + var(--safe-r));
    transform: none;
    width: 220px;
  }
  .steer-hint {
    bottom: calc(24px + var(--safe-b));
  }
  .next-chip {
    bottom: auto;
    top: calc(14px + var(--safe-t));
  }
}

@media (prefers-reduced-motion: reduce) {
  .screen,
  .screen.show,
  .load-bar i,
  .next-chip {
    transition: none;
  }
  .combo.pop {
    animation: none;
  }
  .flash.show {
    animation: flash-static 1.1s steps(1, end) forwards;
  }
  @keyframes flash-static {
    0% {
      opacity: 1;
    }
    100% {
      opacity: 0;
    }
  }
}
