:root {
  --ink: #05080d;
  --ink-2: #0a1018;
  --plate: rgba(7, 11, 17, 0.82);
  --plate-soft: rgba(7, 11, 17, 0.58);
  --brass: #c9a35f;
  --brass-hi: #f0d49a;
  --brass-dim: rgba(201, 163, 95, 0.42);
  --amber: #f2a038;
  --amber-soft: rgba(242, 160, 56, 0.55);
  --cyan: #6fd6e8;
  --cyan-soft: rgba(111, 214, 232, 0.32);
  --teal: #1e6b63;
  --red: #d94236;
  --green: #2f6b4d;
  --silver: #e8edf2;
  --text: #e9e2d2;
  --muted: #9b9486;
  --display: "Chakra Petch", "Arial Narrow", sans-serif;
  --body: "Barlow Semi Condensed", "Arial Narrow", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--text);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body { touch-action: none; }

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% 108%, rgba(242, 160, 56, 0.18), transparent 48%),
    radial-gradient(100% 70% at 50% 38%, rgba(30, 107, 99, 0.12), transparent 60%),
    linear-gradient(180deg, #05080d 0%, #071019 55%, #0a0c0d 100%);
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 1.1s ease;
}
#app.ready #view { opacity: 1; }

/* ---------- wet lens ---------- */
.lens {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}
.rain-layer {
  position: absolute;
  inset: -30% -20%;
  background-image:
    repeating-linear-gradient(104deg,
      transparent 0 23px,
      rgba(202, 226, 235, 0.11) 23px 24px,
      transparent 24px 67px,
      rgba(202, 226, 235, 0.055) 67px 68px,
      transparent 68px 118px);
  background-size: 100% 100%;
  opacity: 0.55;
  animation: rainShift 0.62s linear infinite;
  filter: blur(0.2px);
}
.rain-b {
  background-image:
    repeating-linear-gradient(99deg,
      transparent 0 41px,
      rgba(255, 226, 184, 0.075) 41px 42px,
      transparent 42px 91px,
      rgba(198, 224, 235, 0.08) 91px 92px,
      transparent 92px 156px);
  opacity: 0.4;
  animation-duration: 1.05s;
  animation-direction: reverse;
}
.smear {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(80% 36% at 50% 0%, rgba(255, 213, 150, 0.05), transparent 72%),
    radial-gradient(60% 30% at 24% 12%, rgba(255, 224, 180, 0.04), transparent 75%),
    linear-gradient(180deg, rgba(3, 6, 10, 0.04), transparent 26%, transparent 74%, rgba(3, 6, 10, 0.28));
}
.grain {
  position: absolute;
  inset: -10%;
  opacity: 0.11;
  mix-blend-mode: screen;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  animation: grainShift 0.9s steps(2) infinite;
}
.vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 95% at 50% 48%, transparent 48%, rgba(2, 4, 7, 0.28) 78%, rgba(1, 3, 6, 0.56) 100%),
    linear-gradient(180deg, rgba(2, 4, 7, 0.34), transparent 16%, transparent 82%, rgba(2, 4, 7, 0.44));
}

@keyframes rainShift {
  from { transform: translate3d(0, -9%, 0); }
  to { transform: translate3d(-1.4%, 9%, 0); }
}
@keyframes grainShift {
  0% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(-1.2%, 0.8%, 0); }
  100% { transform: translate3d(0.7%, -0.9%, 0); }
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 8;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) clamp(10px, 2.4vw, 26px) 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}
#app.ready .hud { opacity: 1; }

.plate {
  position: relative;
  border: 1px solid var(--brass-dim);
  border-radius: 7px;
  background:
    linear-gradient(155deg, rgba(23, 33, 42, 0.86), rgba(5, 8, 12, 0.68) 42%, rgba(5, 8, 12, 0.82));
  box-shadow:
    inset 0 1px 0 rgba(255, 232, 188, 0.16),
    inset 0 0 0 1px rgba(3, 6, 9, 0.5),
    inset 0 -1px 0 rgba(111, 214, 232, 0.2),
    0 8px 26px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(7px) saturate(112%);
  -webkit-backdrop-filter: blur(7px) saturate(112%);
}
.plate::before,
.plate::after {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9b6, #8b6b34 60%, #2d2414);
  box-shadow: 0 0 5px rgba(255, 205, 120, 0.32);
  top: 5px;
}
.plate::before { left: 5px; }
.plate::after { right: 5px; }

.lap-plate {
  width: clamp(136px, 39vw, 190px);
  padding: 8px 11px 7px;
}
.plate-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}
.lap-word,
.best-word {
  font-family: var(--display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.19em;
  color: var(--brass-hi);
}
.lap-count {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.04em;
}
.lap-time {
  font-size: clamp(24px, 7.2vw, 32px);
  line-height: 1.04;
  font-weight: 700;
  letter-spacing: -0.045em;
  color: #fff5dd;
  text-shadow: 0 0 18px rgba(255, 203, 115, 0.16);
  font-variant-numeric: tabular-nums;
}
.best-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 7px;
  margin-top: 1px;
}
.best-time {
  font-size: 11px;
  font-weight: 500;
  color: #cfc8b8;
  font-variant-numeric: tabular-nums;
}

.order-plate {
  width: clamp(142px, 41vw, 196px);
  padding: 8px 9px 7px;
}
.order-list { display: flex; flex-direction: column; gap: 3px; }
.order-row {
  display: grid;
  grid-template-columns: 11px 8px 1fr auto;
  align-items: center;
  gap: 5px;
  height: 14px;
  font-family: var(--body);
  font-size: 10.5px;
  line-height: 1;
}
.order-rank {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
}
.order-chip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: 0 0 6px currentColor;
  background: currentColor;
}
.order-name {
  color: #d6cfbe;
  letter-spacing: 0.08em;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.order-gap {
  color: #a9a291;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.order-row.mine .order-name { color: #fff6df; }
.order-row.mine .order-gap { color: var(--cyan); }
.order-row.mine .order-rank { color: var(--cyan); }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}
.overlay button { pointer-events: auto; }
.hidden { display: none !important; }

.start-screen {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  background:
    linear-gradient(180deg, rgba(3, 6, 10, 0.6) 0%, rgba(3, 6, 10, 0.2) 34%, rgba(3, 6, 10, 0.02) 58%, rgba(3, 6, 10, 0.32) 84%, rgba(3, 6, 10, 0.6) 100%);
  transition: opacity 0.7s ease, visibility 0.7s;
}
#app.racing .start-screen,
#app.counting .start-screen,
#app.finish-pending .start-screen,
#app.finished .start-screen {
  opacity: 0;
  visibility: hidden;
}
.start-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: calc(env(safe-area-inset-top, 0px) + clamp(82px, 13.5vh, 140px));
  padding: 0 16px;
  text-align: center;
}
.hero-emblem {
  position: relative;
  width: clamp(78px, 20vw, 132px);
  height: auto;
  margin-bottom: 3px;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.6));
  z-index: 3;
}
.hero-wordmark {
  position: relative;
  z-index: 1;
  width: min(90vw, 660px);
  height: auto;
  filter: drop-shadow(0 16px 34px rgba(0, 0, 0, 0.68)) saturate(1.03);
}
.hero-tag {
  margin: 10px 0 0;
  font-family: var(--display);
  font-size: clamp(9px, 2.5vw, 12px);
  font-weight: 500;
  letter-spacing: 0.24em;
  color: #d6bb82;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}
.primary-btn {
  position: relative;
  min-width: clamp(188px, 52vw, 292px);
  height: 46px;
  margin-top: clamp(0px, 0.6vh, 4px);
  padding: 0 24px;
  border: 1px solid rgba(214, 179, 106, 0.85);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(31, 85, 80, 0.88), rgba(10, 35, 36, 0.9) 54%, rgba(5, 20, 22, 0.94));
  color: #f6e8c8;
  font-family: var(--display);
  font-size: clamp(14px, 4vw, 17px);
  font-weight: 700;
  letter-spacing: 0.19em;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 238, 196, 0.35),
    inset 0 0 22px rgba(111, 214, 232, 0.1),
    0 0 0 1px rgba(4, 15, 17, 0.9),
    0 10px 28px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.primary-btn::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(111, 214, 232, 0.2);
  border-radius: 5px;
  pointer-events: none;
}
.primary-btn:active { transform: scale(0.98); }
.primary-btn:not(:disabled):hover {
  filter: brightness(1.12);
  box-shadow:
    inset 0 1px 0 rgba(255, 238, 196, 0.4),
    inset 0 0 26px rgba(111, 214, 232, 0.15),
    0 0 0 1px rgba(4, 15, 17, 0.9),
    0 0 26px rgba(242, 160, 56, 0.16),
    0 10px 28px rgba(0, 0, 0, 0.5);
}
.primary-btn:disabled {
  cursor: default;
  color: #b8ab8f;
  filter: saturate(0.5);
  opacity: 0.78;
}
.primary-btn.compact {
  min-width: 0;
  width: 100%;
  height: 46px;
  margin-top: 0;
  font-size: 13px;
}
.load-row.done { display: none; }
.load-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: clamp(188px, 52vw, 292px);
  margin-top: 6px;
}
.load-track {
  width: 100%;
  height: 1px;
  background: rgba(255, 235, 198, 0.14);
  overflow: hidden;
  border-radius: 2px;
}
.load-fill {
  width: 4%;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--cyan) 66%, var(--brass-hi));
  box-shadow: 0 0 10px rgba(111, 214, 232, 0.55);
  transition: width 0.45s ease;
}
.load-note {
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: #9d9a8c;
}
.start-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + clamp(112px, 19vh, 162px));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: var(--display);
  font-size: 8.5px;
  font-weight: 500;
  letter-spacing: 0.19em;
  color: rgba(213, 194, 156, 0.48);
  pointer-events: none;
}
.start-foot i {
  width: 16px;
  height: 1px;
  background: rgba(213, 194, 156, 0.22);
}

/* ---------- countdown ---------- */
.countdown {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(50% 42% at 50% 50%, rgba(3, 6, 10, 0.22), transparent 72%);
}
#countdown-number {
  font-family: var(--display);
  font-size: clamp(86px, 24vw, 190px);
  font-weight: 700;
  line-height: 1;
  color: #fff1cf;
  text-shadow:
    0 0 18px rgba(242, 160, 56, 0.55),
    0 0 70px rgba(242, 160, 56, 0.32),
    0 8px 0 rgba(63, 42, 15, 0.6);
  animation: countPulse 0.78s ease-out both;
}
@keyframes countPulse {
  0% { transform: scale(1.28); opacity: 0; }
  18% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.94); opacity: 0.92; }
}

/* ---------- toast ---------- */
.race-toast {
  position: absolute;
  left: 50%;
  top: clamp(104px, 17vh, 170px);
  z-index: 9;
  transform: translate(-50%, -8px);
  padding: 7px 16px;
  border-top: 1px solid rgba(111, 214, 232, 0.35);
  border-bottom: 1px solid rgba(201, 163, 95, 0.35);
  background: linear-gradient(90deg, transparent, rgba(5, 9, 13, 0.75) 18%, rgba(5, 9, 13, 0.75) 82%, transparent);
  font-family: var(--display);
  font-size: clamp(11px, 3vw, 14px);
  font-weight: 600;
  letter-spacing: 0.16em;
  color: #f5e7c7;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: nowrap;
}
.race-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- finish ---------- */
.finish-screen {
  z-index: 9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  overflow-y: auto;
  background:
    radial-gradient(70% 50% at 50% 0%, rgba(242, 160, 56, 0.12), transparent 70%),
    linear-gradient(180deg, rgba(3, 6, 10, 0.6), rgba(3, 6, 10, 0.26) 32%, rgba(3, 6, 10, 0.72) 100%);
  backdrop-filter: blur(1.5px);
  -webkit-backdrop-filter: blur(1.5px);
  pointer-events: auto;
}
.finish-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: min(100%, 620px);
  padding-top: 2px;
}
.finish-emblem {
  width: clamp(48px, 12vw, 76px);
  height: auto;
  filter: drop-shadow(0 5px 12px rgba(0, 0, 0, 0.6));
}
.finish-wordmark {
  width: clamp(180px, 56vw, 350px);
  height: auto;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.62));
}
.finish-card {
  width: min(94vw, 520px);
  margin-top: 2px;
  padding: clamp(14px, 3.6vw, 22px);
  border: 1px solid rgba(201, 163, 95, 0.56);
  border-radius: 13px;
  background:
    linear-gradient(160deg, rgba(24, 34, 42, 0.92), rgba(7, 12, 17, 0.9) 38%, rgba(5, 9, 13, 0.94)),
    rgba(6, 10, 14, 0.92);
  box-shadow:
    inset 0 1px 0 rgba(255, 237, 198, 0.16),
    inset 0 0 0 1px rgba(3, 6, 9, 0.6),
    inset 0 -1px 0 rgba(111, 214, 232, 0.2),
    0 22px 70px rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(12px) saturate(110%);
  -webkit-backdrop-filter: blur(12px) saturate(110%);
  position: relative;
  overflow: hidden;
}
.finish-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(114deg, transparent 0 38%, rgba(240, 212, 154, 0.05) 38.4%, transparent 39.2%),
    linear-gradient(104deg, transparent 0 66%, rgba(111, 214, 232, 0.04) 66.4%, transparent 67.2%);
  pointer-events: none;
}
.finish-eyebrow {
  position: relative;
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: #938b79;
}
.finish-title-row {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(201, 163, 95, 0.28);
}
.finish-title-row h2 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(19px, 5.4vw, 27px);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff1d4;
}
.finish-place {
  font-size: clamp(22px, 6.4vw, 32px);
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 16px rgba(111, 214, 232, 0.32);
}
.result-table {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
}
.result-row {
  display: grid;
  grid-template-columns: 17px 9px 1fr auto;
  align-items: center;
  gap: 7px;
  min-height: 24px;
  padding: 3px 5px;
  border-radius: 4px;
  font-family: var(--body);
  font-size: clamp(11px, 3.1vw, 13px);
  color: #d3ccbc;
}
.result-row .result-rank {
  font-family: var(--mono);
  font-size: 10px;
  color: #918a7b;
}
.result-row .result-chip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}
.result-row .result-name {
  font-weight: 600;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.result-row .result-time {
  font-family: var(--mono);
  font-size: 10px;
  color: #b8b1a2;
  font-variant-numeric: tabular-nums;
}
.result-row.mine {
  background: linear-gradient(90deg, rgba(111, 214, 232, 0.14), rgba(111, 214, 232, 0.035));
  border: 1px solid rgba(111, 214, 232, 0.3);
  color: #f5f9f8;
}
.result-row.mine .result-time { color: var(--cyan); }
.result-row.mine .result-rank { color: var(--cyan); }

.split-head {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 13px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(201, 163, 95, 0.28);
  font-family: var(--display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--brass-hi);
}
.split-head .mono { font-size: 12px; letter-spacing: 0.02em; color: #f4e8cc; }
.split-list { position: relative; display: flex; flex-direction: column; gap: 2px; margin-top: 5px; }
.split-row {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  font-family: var(--body);
  font-size: 11.5px;
  color: #c8c1b2;
}
.split-row .split-lap {
  font-family: var(--display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: #9f9788;
}
.split-row .split-time {
  font-family: var(--mono);
  font-size: 11px;
  color: #e5ddcb;
}
.split-row .split-tag {
  font-family: var(--display);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.13em;
  color: var(--amber);
  border: 1px solid rgba(242, 160, 56, 0.45);
  border-radius: 3px;
  padding: 2px 5px;
}
.split-row .split-tag.empty { border-color: transparent; }
.split-row.best .split-time { color: var(--amber); }
.finish-actions {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}
.ghost-btn {
  height: 46px;
  border: 1px solid rgba(201, 163, 95, 0.32);
  border-radius: 8px;
  background: rgba(255, 244, 218, 0.03);
  color: #c9c1b0;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.13em;
  cursor: pointer;
}
.ghost-btn:hover { background: rgba(255, 244, 218, 0.07); color: #f0e4c8; }

/* ---------- pause ---------- */
.paused {
  z-index: 11;
  display: grid;
  place-items: center;
  background: rgba(2, 5, 8, 0.62);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  pointer-events: auto;
}
.pause-card {
  width: min(82vw, 340px);
  padding: 24px 22px;
  text-align: center;
  border: 1px solid rgba(201, 163, 95, 0.55);
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(24, 34, 42, 0.95), rgba(5, 9, 13, 0.95));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
}
.pause-kicker {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.18em;
  color: #9d9585;
}
.pause-card h2 {
  margin: 6px 0 4px;
  font-family: var(--display);
  font-size: 30px;
  letter-spacing: 0.1em;
  color: #fff0d1;
}
.pause-card p {
  margin: 0 0 18px;
  font-family: var(--body);
  font-size: 13px;
  color: #a9a190;
}

/* ---------- controls ---------- */
.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding:
    0 clamp(12px, 3vw, 30px)
    calc(env(safe-area-inset-bottom, 0px) + clamp(13px, 3.2vh, 28px));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#app.ready .controls { opacity: 1; }
#app.finished .controls,
#app.finish-pending .controls { opacity: 0; }
#app.finished .hud { opacity: 0; }
.control-cluster {
  display: flex;
  gap: clamp(7px, 2vw, 12px);
  pointer-events: auto;
}
.control {
  position: relative;
  width: clamp(58px, 17.4vw, 80px);
  height: clamp(58px, 17.4vw, 80px);
  padding: 0;
  border: 1px solid rgba(201, 163, 95, 0.68);
  border-radius: 11px;
  background:
    radial-gradient(120% 100% at 38% 18%, rgba(83, 143, 137, 0.42), transparent 54%),
    linear-gradient(158deg, rgba(31, 73, 72, 0.82), rgba(8, 26, 29, 0.86) 62%, rgba(5, 16, 19, 0.92));
  box-shadow:
    inset 0 1px 0 rgba(255, 238, 194, 0.3),
    inset 0 0 0 3px rgba(4, 15, 18, 0.62),
    inset 0 0 18px rgba(111, 214, 232, 0.08),
    0 0 0 1px rgba(3, 10, 12, 0.75),
    0 7px 19px rgba(0, 0, 0, 0.5);
  color: #e8c98d;
  cursor: pointer;
  touch-action: none;
  transition: transform 0.08s ease, box-shadow 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.control::before,
.control::after {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #ffedc3, #a17436 58%, #33230f);
  box-shadow: 0 0 4px rgba(255, 211, 139, 0.36);
  top: 4px;
  pointer-events: none;
}
.control::before { left: 4px; }
.control::after { right: 4px; }
.control svg {
  width: 58%;
  height: 58%;
  display: block;
  margin: auto;
  fill: currentColor;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
  transition: filter 0.1s ease;
}
.control.throttle svg { fill: #f0d49a; }
.control.brake svg { fill: #cfb27c; }
.control.active,
.control:active {
  transform: scale(0.955);
  border-color: rgba(111, 214, 232, 0.9);
  color: #fff3d5;
  box-shadow:
    inset 0 1px 0 rgba(255, 245, 210, 0.4),
    inset 0 0 0 3px rgba(4, 15, 18, 0.58),
    inset 0 0 24px rgba(111, 214, 232, 0.26),
    0 0 0 1px rgba(3, 10, 12, 0.75),
    0 0 26px rgba(111, 214, 232, 0.3),
    0 5px 14px rgba(0, 0, 0, 0.5);
}
.control.active svg { filter: drop-shadow(0 0 8px rgba(255, 224, 165, 0.6)); }
#app.idle .control,
#app.counting .control { opacity: 0.45; filter: saturate(0.5); pointer-events: none; }

.key-hint {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 5;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.12em;
  color: rgba(213, 194, 156, 0.42);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#app.ready .key-hint { opacity: 1; }
#app.racing .key-hint,
#app.counting .key-hint,
#app.finished .key-hint { opacity: 0; }
@media (hover: none), (pointer: coarse) {
  .key-hint { display: none; }
}

/* ---------- fatal ---------- */
.fatal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(2, 5, 8, 0.82);
  pointer-events: auto;
}
.fatal-card {
  width: min(84vw, 380px);
  padding: 22px;
  text-align: center;
  border: 1px solid rgba(201, 163, 95, 0.5);
  border-radius: 12px;
  background: #0a1018;
}
.fatal-card h2 { margin: 0 0 8px; font-family: var(--display); letter-spacing: 0.08em; }
.fatal-card p { margin: 0 0 16px; color: #b7af9d; font-size: 14px; }

/* ---------- layout ---------- */
@media (orientation: portrait) {
  .hud { padding-top: calc(env(safe-area-inset-top, 0px) + 8px); }
  .start-hero { margin-top: calc(env(safe-area-inset-top, 0px) + clamp(84px, 13vh, 128px)); }
}
@media (orientation: landscape) {
  .start-hero {
    margin-top: calc(env(safe-area-inset-top, 0px) + clamp(36px, 8vh, 70px));
  }
  .hero-wordmark { width: min(60vw, 560px); }
  .hero-emblem { width: clamp(70px, 13vh, 110px); margin-bottom: 2px; }
  .hero-tag { margin-top: 5px; }
  .primary-btn { height: 44px; margin-top: 6px; }
  .start-foot { bottom: calc(env(safe-area-inset-bottom, 0px) + 82px); }
  .controls {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  }
  .control { width: clamp(56px, 11vh, 72px); height: clamp(56px, 11vh, 72px); }
  .finish-screen { flex-direction: row; align-items: center; justify-content: center; gap: clamp(14px, 3vw, 34px); padding-top: calc(env(safe-area-inset-top, 0px) + 18px); }
  .finish-head { flex-direction: column; align-items: center; width: auto; padding-top: 12px; }
  .finish-emblem { width: clamp(62px, 10vh, 92px); }
  .finish-wordmark { width: min(34vw, 340px); }
  .finish-card { width: min(54vw, 520px); max-height: calc(100vh - 32px); overflow-y: auto; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .start-hero { margin-top: calc(env(safe-area-inset-top, 0px) + 18px); }
  .hero-emblem { width: 44px; margin-bottom: 1px; }
  .hero-wordmark { width: min(44vw, 390px); }
  .hero-tag { font-size: 7px; margin-top: 2px; }
  .primary-btn { height: 34px; min-width: 176px; margin-top: 4px; font-size: 11px; }
  .load-row { margin-top: 4px; }
  .start-foot { display: none; }
  .finish-card { padding: 12px 14px; }
  .finish-title-row h2 { font-size: 18px; }
  .split-head { margin-top: 7px; }
  .finish-actions { margin-top: 8px; }
  .finish-head { padding-top: 0; }
  .finish-emblem { width: 54px; }
  .finish-wordmark { width: 210px; }
}
@media (max-width: 360px) {
  .lap-plate { width: 136px; }
  .order-plate { width: 138px; }
  .hero-wordmark { width: 94vw; }
  .control { width: 58px; height: 58px; }
  .control-cluster { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .rain-layer, .grain { animation: none; }
  #countdown-number { animation-duration: 0.01s; }
}

/* the best-lap ghost, kept out of the position list */
.ghost-line .best-word { color: #63cfff; }
.ghost-line .best-time { color: #a9f2ff; }
