:root {
  font-family: Inter, system-ui, sans-serif;
  color: #f3f5e9;
  background: #182d31;
  font-synthesis: none;
  --lime: #dff38b
}

.mode-entry-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.mode-entry-actions button { min-height: 44px; }
body.rally-open .brand { display: none; }
#rally-panel { position: absolute; inset: 0; background: #172721; }
#rally-viewport { position: absolute; inset: 0; }
.rally-toolbar, .rally-info {
  position: absolute; z-index: 1; padding: 12px; border-radius: 12px;
  background: #14231eed; left: max(12px, env(safe-area-inset-left));
}
.rally-toolbar {
  top: max(10px, env(safe-area-inset-top));
  right: max(68px, calc(env(safe-area-inset-right) + 56px));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.rally-toolbar h1 { font-size: 20px; margin: 0; }
.rally-toolbar p, .rally-info p { font-size: 13px; margin: 4px 0; }
.rally-toolbar button { flex-shrink: 0; }
.rally-info {
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: min(440px, calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
}
.rally-info button { margin-top: 8px; }
.rally-route-label { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
#rally-preview-position { display: block; width: 100%; min-width: 200px; height: 28px; margin: 0; accent-color: var(--lime); touch-action: pan-x; }
#rally-panel button { min-height: 44px; padding: 10px 12px; touch-action: manipulation; }
#rally-panel[data-race-state="running"] .rally-toolbar { display: none; }
#rally-run-hud {
  position: absolute; z-index: 1; top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
  pointer-events: none;
}
.rally-timing {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  align-items: start; gap: 4px; margin-right: 56px; padding: 8px;
  border-radius: 10px; background: #14231eed; text-align: center;
  font-variant-numeric: tabular-nums;
}
.rally-timing strong { display: block; font-size: 18px; line-height: 1.2; white-space: nowrap; }
.rally-best strong { font-size: clamp(10px, 3vw, 16px); }
.rally-hud-label { display: block; font-size: 10px; line-height: 1.3; color: #d0d9c9; }
.rally-clock #rally-time { font-size: clamp(22px, 4vw, 34px); color: var(--lime); }
#rally-progress-bar { display: block; width: 100%; max-width: 100px; height: 4px; margin: 4px auto 0; border: 0; border-radius: 2px; overflow: hidden; background: #516056; accent-color: var(--lime); }
#rally-progress-bar::-webkit-progress-bar { background: #516056; }
#rally-progress-bar::-webkit-progress-value { background: var(--lime); }
#rally-progress-bar::-moz-progress-bar { background: var(--lime); }
.rally-run-tools { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
#rally-notice { margin: 0; padding: 6px 8px; border-radius: 8px; background: #14231eed; font-size: 11px; line-height: 1.4; }
#rally-notice.rally-warning { color: #ffe1a2; border-left: 3px solid #ffe1a2; }
#rally-driving-actions { display: flex; gap: 8px; margin-left: auto; flex-shrink: 0; pointer-events: auto; }
#rally-driving-actions button { background: #14231eed; font-size: 13px; }
#rally-recover { touch-action: none !important; user-select: none; -webkit-touch-callout: none; }
#rally-info { max-height: calc(100% - 110px); overflow-y: auto; }
#rally-navigation {
  position: absolute; z-index: 1; top: max(41%, calc(env(safe-area-inset-top) + 120px));
  left: 50%; transform: translateX(-50%); max-width: 170px;
  display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 2px 6px;
  padding: 6px 9px; border-radius: 9px; background: #14231eed; color: var(--lime);
  pointer-events: none; font-size: 12px; line-height: 1.3;
}
#rally-navigation.rally-turn-sharp { color: #ffe1a2; }
#rally-turn-arrow { font-size: 30px; line-height: 1; }
#rally-turn-label, #rally-turn-distance { display: block; }
#rally-turn-distance { color: #f3f5e9; font-variant-numeric: tabular-nums; }
#rally-turn-then { grid-column: 1 / -1; font-size: 10px; color: #f3f5e9; }
#rally-sensor-notice #tilt-live-status:not([hidden]) {
  display: block; margin: 6px 0 0; width: fit-content; max-width: 100%;
  background: #14231eed; border-radius: 8px; padding: 6px 8px; font-size: 11px; line-height: 1.4;
}
@media (max-width: 480px) {
  .rally-run-tools { flex-wrap: wrap; }
  #rally-driving-actions { order: -1; }
  .rally-hud-label { font-size: 9px; }
}
#credits-dialog { overflow-wrap: anywhere; }
#credits-dialog a { color: var(--lime); }
@media (max-width: 360px) {
  .mode-entry-actions button { padding: 10px 12px; font-size: 13px; }
  .rally-toolbar { padding: 8px; }
  .rally-toolbar h1 { font-size: 17px; }
  .rally-toolbar p { font-size: 11px; }
}

* {
  box-sizing: border-box
}

body {
  margin: 0;
  overflow: hidden
}

button,
input {
  font: inherit
}

button {
  cursor: pointer;
  color: #1b3336;
  background: var(--lime);
  border: 0;
  border-radius: 10px;
  padding: 13px 22px;
  font-weight: 750
}

button:hover {
  filter: brightness(1.06)
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #ffc780;
  outline-offset: 3px
}

button:disabled {
  opacity: .5
}

button.secondary {
  color: #e4ecd8;
  background: #ffffff12;
  border: 1px solid #ffffff29
}

button.icon {
  font-size: 22px;
  padding: 8px 13px;
  background: #183337d9;
  color: #e9f3d3
}

#pause-button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 4px;
  font-size: 12px;
}

[hidden] {
  display: none !important
}

#game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  touch-action: none
}

canvas {
  display: block;
  width: 100%;
  height: 100%
}

.brand {
  position: absolute;
  top: max(22px, env(safe-area-inset-top));
  left: max(28px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 4;
  pointer-events: none;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px
}

.brand>b {
  background: var(--lime);
  color: #234348;
  border-radius: 9px;
  padding: 10px;
  font-size: 25px;
  letter-spacing: -2px
}

.brand>b span {
  font-size: 18px
}

.brand small {
  display: block;
  color: #b1c4b4;
  font-size: 8px;
  letter-spacing: 2px;
  margin-top: 5px
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: linear-gradient(115deg, #10282bf5, #153135ee 60%, #233f35de);
  padding: 110px max(5vw, env(safe-area-inset-left)) 30px;
  overflow: auto
}

.menu-title h1 {
  font-size: clamp(32px, 5vw, 66px);
  line-height: 1.04;
  letter-spacing: -2px;
  margin: 12px 0 20px
}

.menu-title em {
  font-style: normal;
  color: var(--lime)
}

.menu-title>p:last-child {
  color: #b9cabb;
  font-size: 14px
}

.menu-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1000px;
  margin: 22px 0 12px
}

.menu-nav a,
.menu-nav-button {
  min-height: 44px;
  padding: 11px 15px;
  border: 1px solid #ffffff29;
  border-radius: 10px;
  background: #ffffff0d;
  color: #e4ecd8;
  font-size: 11px;
  font-weight: 750;
  text-decoration: none
}

.menu-nav a:first-child { background: var(--lime); color: #1b3336; }

.menu-section {
  max-width: 1000px;
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid #ffffff1f;
  border-radius: 14px;
  background: #081b1d38;
  scroll-margin-top: 20px
}

.section-heading { display: flex; align-items: center; gap: 10px; }
.section-heading p { margin: 0; }
.section-heading h2 { margin: 0; font-size: 20px; }
.selection-summary { margin: 12px 0 0; color: var(--lime); font-size: 13px; font-weight: 700; }
.track-title { margin: 20px 0 -12px; color: #dce8d2; font-size: 14px; }

.eyebrow {
  font-size: 10px;
  letter-spacing: 2.4px;
  color: #c1d79b;
  font-weight: 750
}

.track-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 28px;
  max-width: 1000px
}

.track-card {
  display: grid;
  grid-template-columns: 1fr 130px;
  text-align: left;
  align-items: center;
  gap: 12px;
  padding: 22px 26px;
  background: #ffffff08;
  color: #f4f5e6;
  border: 1px solid #ffffff26;
  border-radius: 14px
}

.track-card:hover {
  border-color: var(--lime);
  background: #dff38b10
}

.track-card[aria-pressed="true"] {
  border: 2px solid var(--lime);
  background: #dff38b18;
  box-shadow: 0 0 0 3px #dff38b18
}

.track-card h2 {
  font-size: 28px;
  letter-spacing: -1px;
  margin: 0 0 6px
}

.track-card p {
  font-size: 11px;
  color: #b9cbb9;
  margin: 6px 0
}

.track-card .record {
  color: var(--lime);
  margin-top: 18px;
  font-variant-numeric: tabular-nums
}

.medal {
  font-weight: 800;
  letter-spacing: .5px;
  font-variant-numeric: tabular-nums
}

.track-card .medal { color: #d0ddc9; }
.medal-bronze { color: #e3a56f !important; }
.medal-gold { color: #ffd65a !important; }
#medal-result { margin: 3px 0 10px; }

.track-card svg {
  width: 130px;
  height: 100px
}

.track-card .start {
  display: block;
  margin-top: 15px;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--lime)
}

.start-selection {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #dff38b12
}

.start-selection p { margin: 0; color: #e6f5c0; font-size: 13px; font-weight: 750; }
.start-selection button { min-width: 190px; min-height: 52px; }

@media(max-width:500px) {
  .start-selection { align-items: stretch; flex-direction: column; }
  .start-selection button { width: 100%; min-width: 0; }
}

.menu-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 25px;
  max-width: 1000px
}

.menu-footer p {
  margin-right: auto;
  font-size: 11px;
  color: #b9cbb9
}

.menu-footer small {
  display: block;
  font-size: 9px;
  margin-top: 10px;
  color: #91a999
}

.menu-footer button {
  font-size: 11px;
  padding: 10px 13px
}

.touch-help {
  display: none
}

#hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  right: max(20px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  pointer-events: none;
  z-index: 2;
  text-shadow: 0 2px 6px #152a2b
}

#hud>div {
  background: #173237d9;
  border: 1px solid #cee1c422;
  padding: 9px 15px;
  border-radius: 9px
}

#hud span {
  display: block;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: #d0ddc9
}

#hud strong {
  font-size: 25px;
  font-variant-numeric: tabular-nums
}

#hud .hud-time {
  text-align: center;
  margin: auto;
  padding: 8px 22px
}

#live-delta {
  display: block;
  min-height: 16px;
  margin-top: 1px;
  color: #d0ddc9;
  font: 750 13px/1.2 inherit;
  font-variant-numeric: tabular-nums
}

#live-delta.ahead {
  color: var(--lime)
}

#live-delta.behind {
  color: #ffad8f
}

#hud .hud-time>div {
  display: flex;
  gap: 20px;
  margin-top: 5px
}

#hud .hud-time>div span {
  font-size: 8px;
  letter-spacing: .5px
}

#hud b {
  color: #e7efda;
  font-size: 11px;
  font-variant-numeric: tabular-nums
}

#hud button {
  pointer-events: auto
}

#hud .hud-speed {
  text-align: right
}

#race-message {
  position: absolute;
  top: 105px;
  left: 50%;
  transform: translateX(-50%);
  color: #ffe0a4;
  font-size: 12px;
  text-align: center;
  text-shadow: 0 2px 5px #17272b;
  pointer-events: none;
  z-index: 2
}

#countdown {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: 110px;
  font-weight: 900;
  color: var(--lime);
  text-shadow: 0 5px 30px #183538;
  z-index: 2;
  pointer-events: none
}

.compact {
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 65px 20px 20px
}

.compact h1 {
  font-size: 40px;
  letter-spacing: -1px;
  margin: 8px 0
}

.compact>p {
  font-size: 13px;
  color: #c0d0bf;
  margin: 8px 0
}

.actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px
}

.total {
  margin: 14px 0
}

.total span {
  display: block;
  font-size: 9px;
  letter-spacing: 2px
}

.total strong {
  font-size: 42px;
  font-variant-numeric: tabular-nums;
  color: var(--lime)
}

#lap-results {
  list-style: none;
  padding: 0;
  margin: 5px 0;
  width: 260px
}

#lap-results li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #ffffff20;
  font-variant-numeric: tabular-nums;
  font-size: 12px
}

#lap-results .sector-results {
  display: block;
  margin-top: 4px;
  color: #d0ddc9;
  font-size: 11px;
  font-variant-numeric: tabular-nums
}

#new-record {
  color: var(--lime)
}

#penalties {
  font-size: 10px
}

#auto-restart {
  margin: 4px 0 0;
  color: var(--lime);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  font-variant-numeric: tabular-nums
}

#touch-controls {
  position: absolute;
  bottom: max(15px, env(safe-area-inset-bottom));
  left: max(22px, env(safe-area-inset-left));
  right: max(22px, env(safe-area-inset-right));
  display: none;
  align-items: end;
  justify-content: space-between;
  z-index: 2;
  pointer-events: none
}

/* Keep iOS driving gestures local, leaving menu scrolling and form selection available. */
#touch-controls,
#touch-controls *,
#hotlap-restart {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none
}

#steering {
  pointer-events: auto;
  width: 210px;
  height: 95px;
  border-radius: 50px;
  border: 1px solid #ffffff65;
  background: #1730359c;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  color: #ecf4d9;
  font-size: 27px;
  touch-action: none
}

.pedals {
  display: grid;
  grid-template-columns: 85px 88px 88px;
  gap: 10px;
  align-items: end;
  pointer-events: auto
}

.pedals button {
  height: 76px;
  padding: 8px;
  font-size: 12px;
  border: 1px solid #f7f8df66;
  background: #203c42cb;
  color: #eef3df
}

.pedals #gas {
  height: 95px;
  background: #dff38bdb;
  color: #1b363b
}

.pedals #handbrake {
  height: 48px;
  font-size: 10px
}

.pedals button:active {
  background: #fff0ba;
  color: #243d3a
}

dialog {
  background: #203a3e;
  color: #edf2df;
  border: 1px solid #839b83;
  border-radius: 16px;
  padding: 28px;
  max-width: 420px;
  width: 90%;
  max-height: 90dvh;
  overflow: auto
}

dialog::backdrop {
  background: #0c202bd9
}

dialog p,
dialog small {
  font-size: 12px;
  line-height: 1.6;
  color: #c0d3bd
}

dialog label {
  display: block;
  margin: 12px 0;
  font-size: 12px
}

dialog input {
  display: block;
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #90a492;
  margin-top: 5px;
  background: #ecf0e4
}

dialog button {
  margin: 5px 0
}

.close {
  float: right;
  padding: 3px 12px
}

#auth-error {
  color: #ffb59b
}

.racing .brand {
  display: none
}

@media(pointer:coarse) {
  #touch-controls {
    display: flex
  }

  .touch-help {
    display: inline
  }

  .desktop-help {
    display: none
  }
}

@media(max-height:550px) {
  .brand {
    top: 13px;
    left: 22px;
    font-size: 10px
  }

  .brand>b {
    font-size: 19px;
    padding: 7px
  }

  .screen {
    padding: 65px 25px 15px
  }

  .menu-title {
    display: flex;
    align-items: center;
    gap: 22px
  }

  .menu-title .eyebrow {
    display: none
  }

  .menu-title h1 {
    font-size: 27px;
    margin: 0;
    letter-spacing: -1px
  }

  .menu-title>p:last-child {
    font-size: 11px;
    max-width: 210px
  }

  .track-list {
    margin-top: 13px;
    gap: 15px
  }

  .track-card {
    padding: 12px 18px;
    grid-template-columns: 1fr 105px
  }

  .track-card h2 {
    font-size: 23px
  }

  .track-card svg {
    width: 105px;
    height: 72px
  }

  .track-card .record {
    margin-top: 9px
  }

  .track-card .start {
    margin-top: 8px
  }

  .menu-footer {
    margin-top: 12px
  }

  .menu-footer small {
    margin-top: 5px;
    font-size: 8px
  }

  .menu-footer p {
    font-size: 9px
  }

  .compact {
    padding: 45px 15px 10px
  }

  .compact h1 {
    font-size: 26px
  }

  .compact .total {
    margin: 4px 0
  }

  .total strong {
    font-size: 30px
  }

  .compact>p {
    margin: 3px 0;
    font-size: 11px
  }

  .compact .actions {
    margin-top: 10px
  }

  .compact button {
    font-size: 11px;
    padding: 11px 15px
  }

  #lap-results li {
    padding: 4px 0
  }

  #hud strong {
    font-size: 20px
  }

  #hud>div {
    padding: 6px 10px
  }

  #hud .hud-time {
    padding: 6px 14px
  }

  #race-message {
    top: 83px;
    font-size: 10px
  }

  #steering {
    width: 185px;
    height: 82px
  }

  .pedals {
    grid-template-columns: 70px 75px 80px;
    gap: 8px
  }

  .pedals button {
    height: 66px
  }

  .pedals #gas {
    height: 82px
  }

  #touch-controls {
    bottom: max(12px, env(safe-area-inset-bottom))
  }
}

@media(max-width:650px) and (min-height:551px) {
  .track-list {
    grid-template-columns: 1fr
  }

  .screen {
    padding: 95px 20px 20px
  }

  .menu-footer {
    flex-wrap: wrap
  }

  .menu-title h1 {
    font-size: 35px
  }

  .track-card {
    padding: 12px
  }

  .menu-footer p {
    width: 100%
  }
}

@media(max-height:550px) {
  .pedals #brake {
    font-size: 10px;
    padding: 6px
  }
}

/* Garage: compact controls also fit the landscape phone menu. */
.garage { max-width: 1000px; margin-top: 18px; }
.garage h3 { font-size: 14px; margin: 0 0 8px; }
#car-list { display: flex; gap: 8px; flex-wrap: wrap; }
.car-option { background: #ffffff12; color: #f3f5e9; border: 2px solid transparent; padding: 9px 18px; }
.car-option[aria-pressed="true"] { border-color: var(--car-color); background: #ffffff24; color: var(--car-color); }
#car-details { color: #b9cabb; font-size: 12px; line-height: 1.5; margin: 8px 0 0; }
#menu { touch-action: pan-y; }
@media(max-height:550px) {
  .garage { margin-top: 8px; }
  .garage h2 { display: inline-block; margin: 0 10px 0 0; font-size: 12px; }
  #car-list { display: inline-flex; gap: 5px; }
  .car-option { padding: 6px 12px; font-size: 12px; }
  #car-details { font-size: 10px; margin-top: 4px; }
}

/* Support links stay on non-driving screens, outside driving controls. */
.support-card { display: flex; align-items: center; gap: 16px; text-align: left; max-width: 610px; padding: 14px 18px; margin-top: 20px; border: 1px solid #dff38b40; border-radius: 12px; background: #dff38b0a; }
.support-card img { width: 44px; height: 44px; object-fit: contain; flex: 0 0 auto; }
.support-card div { flex: 1 1 auto; }
.support-card strong { font-size: 13px; }
.support-card p { font-size: 11px; color: #b9cbb9; margin: 5px 0 0; }
.support-card a { color: var(--lime); font-size: 12px; font-weight: 750; flex-shrink: 0; padding: 12px 0; }
.support-card a:focus-visible { outline: 3px solid #ffc780; outline-offset: 3px; }
.menu-support { max-width: 1000px; justify-content: space-between; margin-top: 18px; }
.finish-support { max-width: 680px; justify-content: space-between; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
@media(max-height:550px) { #pause-panel, #finish-panel { justify-content: flex-start; } .support-card { margin-top: 12px; padding: 8px 14px; } .menu-support p, .finish-support p { margin-top: 2px; } .finish-support { margin-top: 8px; } }
@media(max-width:500px) { .support-card { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 4px 10px; } .support-card img { width: 36px; height: 36px; grid-row: 1; } .support-card a { grid-column: 1 / -1; } }

/* Configurable social links live only on non-driving screens. */
.social-section { max-width: 1000px; margin-top: 18px; text-align: left; }
.social-section h2 { margin: 0 0 9px; font-size: 14px; }
.social-list { display: flex; flex-wrap: wrap; gap: 9px; }
.social-tile { display: grid; place-items: center; align-content: center; gap: 6px; width: 92px; aspect-ratio: 1; padding: 9px; border: 1px solid #ffffff2e; border-radius: 10px; background: #ffffff0d; color: #f3f5e9; text-align: center; font-size: 11px; font-weight: 750; overflow-wrap: anywhere; }
.social-tile:hover { border-color: var(--lime); background: #dff38b12; }
.social-tile:focus-visible { outline: 3px solid #ffc780; outline-offset: 3px; }
.social-tile img { width: 44px; height: 44px; object-fit: contain; }
.social-compact { max-width: 680px; margin-top: 10px; }
.social-compact .social-tile { width: 64px; padding: 6px; font-size: 9px; }
.social-compact .social-tile img { width: 30px; height: 30px; }
@media(max-height:550px) { .social-section { margin-top: 9px; } .social-section h2 { margin-bottom: 5px; font-size: 11px; } .social-tile { width: 58px; padding: 5px; font-size: 8px; } .social-tile img { width: 27px; height: 27px; } }
@media(max-width:500px) { .social-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); } .social-tile, .social-compact .social-tile { width: auto; max-width: none; aspect-ratio: auto; min-height: 72px; } }

@media(max-width:650px) {
  .menu-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .menu-nav a, .menu-nav-button { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; text-align: center; }
  .menu-section { padding: 15px; }
}

.mode-switch { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.mode-switch [aria-pressed="true"] { background: var(--lime); color: #1b3336; }
.menu-footer { flex-wrap: wrap; }
#hotlap-restart { position: absolute; z-index: 2; top: max(100px, calc(env(safe-area-inset-top) + 90px)); left: max(20px, env(safe-area-inset-left)); min-height: 44px; background: #183337ed; border-color: #dff38b99; }
#ghost-toggle { position: absolute; z-index: 2; top: max(100px, calc(env(safe-area-inset-top) + 90px)); right: max(20px, env(safe-area-inset-right)); min-height: 44px; background: #183337ed; }
#ghost-toggle[aria-pressed="true"] { border-color: var(--lime); color: var(--lime); }
#ghost-toggle:disabled { opacity: .55; }
#leaderboard-panel { touch-action: pan-y; }
.ranking-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ranking-header h1 { font-size: clamp(23px, 4vw, 38px); margin: 0; }
#leaderboard-panel h2 { font-size: 18px; margin-top: 28px; }
#leaderboard-panel p { color: #bacdb7; max-width: 850px; line-height: 1.5; font-size: 13px; }
#leaderboard-panel select { max-width: 100%; padding: 10px; border-radius: 6px; font: inherit; background: #eaf0db; }
.table-scroll { overflow-x: auto; touch-action: pan-x pan-y; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; max-width: 1000px; font-size: 14px; text-align: left; }
th, td { padding: 12px 8px; border-bottom: 1px solid #ffffff24; }
th { color: var(--lime); }
td { overflow-wrap: anywhere; }
#local-results td:nth-child(3) { white-space: nowrap; font-variant-numeric: tabular-nums; }
dialog a { color: var(--lime); }
#tutorial-dialog { width: min(760px, calc(100vw - 28px)); max-width: 760px; max-height: calc(100dvh - 28px); overflow: auto; }
#tutorial-dialog h2 { margin: 7px 42px 8px 0; font-size: clamp(23px, 4vw, 34px); }
.tutorial-controls { display: grid; grid-template-columns: repeat(5, minmax(105px, 1fr)); gap: 8px; margin: 20px 0; }
.tutorial-controls>div { display: flex; min-height: 116px; flex-direction: column; align-items: center; justify-content: center; gap: 7px; padding: 12px 8px; border: 1px solid #ffffff24; border-radius: 10px; background: #ffffff09; text-align: center; }
.tutorial-controls span { min-height: 20px; color: #aebfae; font-size: 12px; line-height: 1.4; }
.tutorial-controls strong { font-size: 12px; }
kbd, .control-symbol { display: inline-block; min-width: 34px; padding: 6px 8px; border: 1px solid #ffffff43; border-bottom-width: 3px; border-radius: 6px; background: #244247; color: var(--lime); font: 750 12px/1 system-ui, sans-serif; text-align: center; }
.tutorial-tip { line-height: 1.5; }
#tutorial-extra { margin: 16px 0; }
#tutorial-extra summary { cursor: pointer; padding: 10px 0; }
.tutorial-actions { position: sticky; bottom: -1px; padding: 12px 0; background: #203a3e; display: flex; justify-content: flex-end; gap: 8px; }
.tutorial-actions button { min-height: 44px; padding: 12px 8px; font-size: 13px; }
#tutorial-dialog { scroll-padding-bottom: 90px; }
.touch-tutorial { display: none; }
.tutorial-controls > .tutorial-tip { grid-column: 1 / -1; }
@media(pointer:coarse) { .desktop-tutorial { display: none; } .touch-tutorial { display: grid; } }
@media(max-width:700px), (max-height:550px) {
  #tutorial-dialog { padding: 18px; }
  .tutorial-controls { grid-template-columns: repeat(2, minmax(110px, 1fr)); margin: 12px 0; }
  .tutorial-controls>div { min-height: 88px; }
  .tutorial-tip { font-size: 11px; }
}
@media(min-width:560px) and (max-height:550px) {
  .tutorial-controls { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media(max-height:550px) {
  .mode-switch { margin-top: 8px; }
  .mode-switch button { padding: 9px 13px; font-size: 11px; }
  #hotlap-restart { top: 92px; padding: 10px 15px; }
  #ghost-toggle { top: 92px; padding: 10px 15px; }
}
@media(max-width:500px) {
  table { font-size: 11px; }
  th, td { padding: 10px 4px; }
  .ranking-header { flex-wrap: wrap; }
}

#sound-dialog h2 { padding-right: 40px; }
#sound-dialog label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 0; }
#sound-dialog output { color: var(--lime); font-variant-numeric: tabular-nums; }
#sound-dialog input[type="range"] { padding: 0; min-height: 32px; accent-color: var(--lime); background: transparent; touch-action: pan-y; }
#sound-dialog input:focus-visible { outline: 3px solid #ffc780; outline-offset: 3px; }
#sound-dialog .rally-ghost-option { align-items: center; min-height: 44px; }
#rally-ghost-enabled { width: 24px; height: 24px; min-height: 24px; margin: 0; flex-shrink: 0; accent-color: var(--lime); }

#fullscreen-button { position: fixed; z-index: 21; top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); width: 44px; height: 44px; padding: 4px; font-size: 25px; background: #183337ed; }
#fullscreen-status { position: fixed; z-index: 22; top: 58px; right: 12px; max-width: min(320px, calc(100vw - 24px)); padding: 12px; border-radius: 10px; background: #183337; color: #edf2df; font-size: 13px; }
#hud { right: max(66px, calc(env(safe-area-inset-right) + 54px)); }
:fullscreen { background: #182d31; }

/* One viewport for the lobby; longer choices scroll inside native dialogs. */
#menu.lobby {
  padding: max(84px, calc(env(safe-area-inset-top) + 72px)) max(20px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(160px, 230px) minmax(0, 680px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-content: center;
  gap: 16px 32px;
  overflow: hidden;
}
.lobby-heading { grid-column: 1 / -1; }
.lobby-heading h1 { margin: 0; font-size: clamp(24px, 3vw, 36px); }
.lobby-heading .eyebrow { margin: 0 0 4px; }
.lobby-nav { display: grid; align-content: center; gap: 10px; }
.lobby-nav button { display: flex; align-items: center; gap: 10px; min-height: 48px; font-size: 14px; padding: 10px 14px; text-align: left; }
.lobby-nav button span[aria-hidden] { color: var(--lime); font-size: 22px; width: 24px; text-align: center; }
#account-button { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby-car { min-height: 0; min-width: 0; margin: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; background: radial-gradient(ellipse, #dff38b18, transparent 68%); }
#lobby-car { min-height: 0; width: 100%; height: 100%; }
.lobby-car figcaption { text-align: center; display: grid; gap: 4px; }
.lobby-car figcaption strong { color: var(--lime); font-size: 26px; }
.lobby-car figcaption span { color: #bacdb7; font-size: 14px; }
.lobby-start { grid-column: 1 / -1; display: grid; justify-items: center; gap: 12px; }
.lobby-start .selection-summary { margin: 0; text-align: center; font-size: 14px; line-height: 1.4; }
.next-target { margin: 0; padding: 6px 10px; border-left: 3px solid var(--lime); background: #dff38b0c; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.next-target strong { display: block; color: var(--lime); }
.next-target span { display: block; }
.lobby-start .next-target { max-width: 100%; text-align: center; }
#finish-next-target { margin: 10px 0; }
#start-selected { width: min(100%, 440px); min-height: 56px; font-size: 20px; }
.lobby-dialog { width: min(920px, calc(100vw - 24px)); max-width: 920px; max-height: calc(100dvh - 24px); padding: 0 18px 18px; touch-action: pan-y; }
.panel-header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; background: #203a3e; }
.panel-header h2 { font-size: 20px; margin: 0; }
.panel-header button { flex-shrink: 0; }
.lobby-dialog button, .lobby-dialog a { min-height: 44px; touch-action: manipulation; }
.lobby-dialog .menu-section { margin-top: 8px; padding: 14px; }
.lobby-dialog .mode-switch { flex-wrap: wrap; }
.lobby-dialog .track-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 12px; }
.lobby-dialog .track-card { grid-template-columns: minmax(0, 1fr) 80px; padding: 16px; }
.lobby-dialog .track-card svg { width: 100%; }
.lobby-dialog .track-card h2 { font-size: 24px; }
.lobby-dialog .start-selection { flex-wrap: wrap; }
@media (max-width: 600px) and (orientation: portrait) {
  #menu.lobby { padding: max(76px, calc(env(safe-area-inset-top) + 64px)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); grid-template-columns: 1fr; grid-template-rows: auto minmax(80px, 1fr) auto auto; gap: 12px; }
  .lobby-heading { grid-row: 1; }
  .lobby-car { grid-row: 2; }
  .lobby-nav { grid-row: 3; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .lobby-nav button { flex-direction: column; justify-content: center; gap: 2px; padding: 6px 2px; min-height: 60px; }
  .lobby-start { grid-row: 4; gap: 8px; }
  .lobby-car figcaption { gap: 0; }
  .lobby-car figcaption strong { font-size: 22px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #menu.lobby { padding: max(66px, calc(env(safe-area-inset-top) + 56px)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); grid-template-columns: minmax(228px, .85fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 8px 16px; }
  .lobby-heading { display: none; }
  .lobby-nav { grid-column: 1; grid-row: 1 / 3; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .lobby-nav button { min-height: 44px; padding: 6px; gap: 5px; }
  .lobby-car { grid-column: 2; grid-row: 1; }
  .lobby-car figcaption strong { font-size: 22px; }
  .lobby-start { grid-column: 2; grid-row: 2; gap: 6px; }
  .lobby-start .selection-summary { font-size: 13px; }
  #start-selected { min-height: 48px; padding: 8px 12px; }
}

@media(pointer:coarse) and (orientation:landscape) {
  #hud { top: max(8px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); gap: 8px; }
  #hud > div, #hud .hud-time { padding: 4px 8px; }
  #hud strong { display: block; font-size: 16px; line-height: 19px; }
  #hud .hud-time { padding: 2px 8px; font-size: 11px; line-height: 11px; }
  #hud span { font-size: 8px; letter-spacing: .5px; }
  #hud .hud-time > div { gap: 8px; margin-top: 2px; }
  #hud .hud-time > div span, #hud b { font-size: 8px; }
  #live-delta { font-size: 11px; line-height: 13px; min-height: 13px; }
  #pause-button { min-width: 44px; min-height: 44px; }
  #race-message { top: 76px; font-size: 10px; }
  #hotlap-restart, #ghost-toggle { top: max(92px, calc(env(safe-area-inset-top) + 78px)); }
  #touch-controls { left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); gap: 16px; }
  #steering { width: clamp(140px, 25vw, 210px); flex-shrink: 0; }
  .pedals { grid-template-columns: 60px clamp(100px, 16vw, 140px) clamp(82px, 12vw, 110px); gap: 8px; }
  .pedals #brake { height: clamp(94px, 27vh, 116px); font-size: 13px; border: 2px solid #ffc780; background: #794337dd; }
  .pedals #gas { height: clamp(94px, 27vh, 116px); }
}

/* Portrait reserves the middle of the screen for the road and the bottom for thumbs. */
@media(pointer:coarse) and (orientation:portrait) {
  #hud {
    top: calc(max(10px, env(safe-area-inset-top)) + 54px);
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 72px;
    gap: 6px;
  }
  #hud > div, #hud .hud-time { padding: 6px 4px; margin: 0; }
  #hud strong { display: block; font-size: 19px; line-height: 24px; }
  #hud .hud-lap strong { font-size: 16px; white-space: nowrap; }
  #hud span { font-size: 9px; letter-spacing: 0; }
  #hud b { font-size: 10px; }
  #hud .hud-speed { text-align: center; }
  #hud .hud-time > div { flex-wrap: wrap; justify-content: center; gap: 2px 8px; margin-top: 3px; }
  #hud .hud-time > div span { font-size: 9px; }
  #live-delta { font-size: 13px; line-height: 16px; }
  #pause-button { position: absolute; right: 54px; top: -54px; width: 44px; height: 44px; }
  #hotlap-restart, #ghost-toggle { top: calc(max(10px, env(safe-area-inset-top)) + 154px); font-size: 12px; padding: 10px 14px; }
  #hotlap-restart { left: max(12px, env(safe-area-inset-left)); }
  #ghost-toggle { right: max(12px, env(safe-area-inset-right)); }
  #race-message { top: calc(max(10px, env(safe-area-inset-top)) + 204px); width: calc(100% - 24px); font-size: 11px; }
  #touch-controls {
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr);
    gap: 12px;
  }
  #steering { width: 100%; max-width: 210px; height: 100px; padding: 0 8px; font-size: 21px; }
  .pedals { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .pedals #handbrake { grid-column: 1 / -1; height: 44px; font-size: 11px; }
  .pedals #gas, .pedals #brake { height: 100px; font-size: 11px; padding: 4px; }
  .pedals #brake { border: 2px solid #ffc780; background: #794337dd; }
  #pause-panel, #finish-panel { justify-content: flex-start; padding-top: max(70px, calc(env(safe-area-inset-top) + 60px)); padding-bottom: max(20px, env(safe-area-inset-bottom)); touch-action: pan-y; }
  .compact .actions { flex-shrink: 0; }
  .compact .actions button { min-height: 44px; }
}

#language-select, #rally-quality { width: 100%; min-height: 44px; margin: 8px 0 18px; padding: 8px; font: inherit; }

/* Arrow mode reserves its own steering column; active tilt uses two thumb pedals. */
#steering { display: flex; gap: 8px; padding: 0; background: transparent; border: 0; }
#steering button { flex: 1; min-width: 44px; min-height: 64px; padding: 4px; font-size: 28px; background: #183337e8; color: #e9f3d3; border: 1px solid #ffffff55; }
#touch-controls .pedals { margin-left: auto; }
@media(pointer:coarse) and (orientation:portrait) {
  #touch-controls .pedals { grid-column: 2; margin-left: 0; }
}
@media(pointer:coarse) {
  #touch-controls.tilt-active { display: block; }
  #touch-controls.tilt-active .pedals {
    width: 100%; margin: 0; pointer-events: none;
    grid-template-columns: clamp(100px, 26vw, 150px) minmax(0, 1fr) clamp(100px, 26vw, 150px);
    grid-template-rows: 44px clamp(94px, 22vh, 116px); gap: 8px;
  }
  #touch-controls.tilt-active .pedals button { pointer-events: auto; width: 100%; }
  #touch-controls.tilt-active .pedals #handbrake { grid-column: 3; grid-row: 1; height: 44px; }
  #touch-controls.tilt-active .pedals #brake { grid-column: 1; grid-row: 2; height: 100%; }
  #touch-controls.tilt-active .pedals #gas { grid-column: 3; grid-row: 2; height: 100%; }
}
#steering-settings { border: 1px solid #ffffff29; border-radius: 10px; margin: 8px 0 20px; min-width: 0; }
#steering-mode { display: block; width: 100%; min-height: 44px; margin: 8px 0 16px; font: inherit; }
#tilt-sensitivity { width: 100%; min-height: 44px; }
#tilt-preview { position: relative; height: 24px; margin: 12px 0; border: 1px solid #789293; border-radius: 12px; background: linear-gradient(90deg, #1b3943 46%, #8db7ac 49%, #8db7ac 51%, #1b3943 54%); }
#tilt-preview span { position: absolute; left: var(--tilt-position, 50%); top: 3px; width: 16px; height: 16px; transform: translateX(-50%); border-radius: 50%; background: #ffe1a2; }
#tilt-dialog button { min-height: 44px; margin: 6px 0; }
/* Leave a clear centre around Rally's car, including the arrow fallback. */
@media (pointer:coarse) and (orientation:landscape) {
  body.rally-open #touch-controls:not(.tilt-active) .pedals {
    grid-template-columns: clamp(100px, 16vw, 140px) clamp(82px, 12vw, 110px);
    grid-template-rows: 44px clamp(94px, 27vh, 116px);
  }
  body.rally-open #touch-controls:not(.tilt-active) #handbrake { grid-column: 2; grid-row: 1; height: 44px; }
  body.rally-open #touch-controls:not(.tilt-active) #brake { grid-column: 1; grid-row: 2; }
  body.rally-open #touch-controls:not(.tilt-active) #gas { grid-column: 2; grid-row: 2; }
}
@media (pointer:coarse) and (orientation:portrait) {
  body.rally-open #touch-controls,
  body.rally-open #touch-controls.tilt-active {
    display: grid; grid-template-columns: 100px minmax(0, 1fr) 100px;
    grid-template-rows: 64px 96px; gap: 8px;
  }
  body.rally-open #touch-controls .pedals { display: contents; }
  body.rally-open #touch-controls #steering { grid-column: 1; grid-row: 1; height: 64px; }
  body.rally-open #touch-controls .pedals #handbrake { grid-column: 3; grid-row: 1; height: 44px; align-self: end; }
  body.rally-open #touch-controls .pedals #brake { grid-column: 1; grid-row: 2; height: 96px; }
  body.rally-open #touch-controls .pedals #gas { grid-column: 3; grid-row: 2; height: 96px; }
}
#tilt-live-status { display: none; }
@media(pointer:coarse) {
  body.racing #tilt-live-status { display: block; position: absolute; z-index: 2; left: 12px; bottom: 170px; width: min(290px, calc(100% - 24px)); margin: 0; padding: 6px 10px; background: #183337e8; font-size: 12px; pointer-events: none; }
}

/* Two vector dials share the existing HUD values; no extra animation loop. */
#hud .hud-speed { display: flex; gap: 4px; padding: 0; border: 0; background: none; text-shadow: none; }
.gauge { width: 112px; flex: 0 0 auto; }
.gauge svg { display: block; width: 100%; overflow: visible; }
.gauge-face { fill: #142a30ed; stroke: #8ba6a8; stroke-width: 2; }
.gauge-scale line { stroke: #e7efda; stroke-width: 1.5; }
.gauge-scale .minor { stroke: #8ba6a8; stroke-width: 1; }
.gauge-scale text { fill: #e7efda; font-size: 10px; font-variant-numeric: tabular-nums; }
.gauge-needle { fill: #f2a777; }
.gauge-hub { fill: #e7efda; stroke: #142a30; stroke-width: 1.5; }
.gauge-value, .gauge-unit, .gauge-caption, .gauge-multiplier { fill: #e7efda; text-anchor: middle; }
.gauge-value { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.gauge-unit, .gauge-multiplier { font-size: 10px; }
.gauge-caption { font-size: 12px; font-weight: 650; }
@media (max-width: 900px), (pointer: coarse) {
  .gauge { width: 76px; }
}
@media (pointer: fine) {
  #hotlap-restart, #ghost-toggle { top: max(136px, calc(env(safe-area-inset-top) + 124px)); }
}
@media (pointer: coarse) and (orientation: landscape) {
  #hud .hud-time > span { line-height: 10px; }
  #hud .hud-time strong { line-height: 17px; }
  #hud .hud-time #live-delta { min-height: 11px; line-height: 11px; }
  #hud .hud-time > div, #hud .hud-time > div span { line-height: 9px; }
}
@media (pointer: coarse) and (orientation: portrait) {
  #hud { grid-template-columns: minmax(0, 1fr) 176px; gap: 4px; }
  #hud .hud-lap { position: absolute; top: -54px; left: 0; width: 48px; }
  #hud .gauge { width: 86px; }
  #hud .hud-time { padding: 4px 2px; }
  #hud .hud-time strong { font-size: 16px; line-height: 20px; }
  #hud .hud-time > div { display: grid; gap: 2px; }
  #hud .hud-time > div > span { display: flex; justify-content: space-between; gap: 4px; }
  #hud .hud-time > div span { font-size: 8px; }
  #hud .hud-time > div b { font-size: 9px; }
  #hotlap-restart, #ghost-toggle { top: calc(max(10px, env(safe-area-inset-top)) + 174px); }
  #race-message { top: calc(max(10px, env(safe-area-inset-top)) + 224px); }
}
