/* Minimalist Dakar Maritime Glassmorphic HUD & Landing Experience */
:root {
  --bg-glass: rgba(11, 17, 26, 0.58);
  --bg-glass-strong: rgba(10, 15, 24, 0.80);
  --border-glass: rgba(255, 255, 255, 0.14);
  --border-gold: rgba(244, 196, 78, 0.45);
  --text-main: #f4f6f8;
  --text-muted: #9aa7b8;
  --accent-gold: #f4c44e;
  --accent-emerald: #10b981;
  --accent-coral: #ef4444;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #0d141e;
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}
canvas#game-canvas {
  cursor: grab;
  touch-action: none;
}
canvas#game-canvas.dragging {
  cursor: grabbing;
}

.hidden {
  display: none !important;
}

/* Loading Screen with Full-Bleed Rotating HD Soumbédioune Showcase */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: #0d141e;
  overflow: hidden;
  transition: opacity 0.55s ease;
}
#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
.loader-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}
.loader-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transform: scale(1.0);
  transition: opacity 1.05s ease, transform 5.5s ease-out;
  will-change: opacity, transform;
}
.loader-slide.active {
  opacity: 1;
  transform: scale(1.06);
}
.loader-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      rgba(8, 13, 21, 0.34) 0%,
      rgba(8, 13, 21, 0.04) 24%,
      rgba(8, 13, 21, 0.05) 56%,
      rgba(8, 13, 21, 0.78) 100%);
}
.loader-content {
  position: relative;
  z-index: 2;
  width: 100%;
  padding: clamp(18px, 3vw, 34px);
  display: flex;
  justify-content: center;
}
.loader-card {
  width: min(760px, 100%);
  background: rgba(10, 15, 24, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  padding: 18px 22px;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.55);
}
.loader-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.loader-sub {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-gold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.loader-title {
  font-size: clamp(22px, 2.8vw, 30px);
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.08;
  color: var(--text-main);
}
.loader-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 6px;
}
.loader-dot {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.28);
  transition: width 0.35s ease, background 0.35s ease;
}
.loader-dot.active {
  width: 22px;
  background: var(--accent-gold);
}
.loader-meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.loader-caption {
  font-size: 13px;
  font-weight: 600;
  color: rgba(244, 246, 248, 0.92);
}
.loader-pct {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold);
}
.loader-bar-wrap {
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
  overflow: hidden;
}
.loader-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-emerald), var(--accent-gold));
  transition: width 0.22s ease-out;
}
.loader-bottom-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 10px;
}
.loader-status {
  font-size: 12px;
  color: var(--text-muted);
}
.loader-tip {
  font-size: 12px;
  color: rgba(244, 196, 78, 0.88);
}

/* Start Menu Overlay over Live 3D Soumbédioune Bay */
#menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px 34px;
  background: linear-gradient(90deg, rgba(8, 13, 21, 0.72) 0%, rgba(8, 13, 21, 0.28) 52%, rgba(8, 13, 21, 0.08) 100%);
  pointer-events: none;
}

.menu-header {
  max-width: 520px;
}
.menu-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--accent-gold);
  margin-bottom: 8px;
}
.menu-title {
  font-size: clamp(28px, 3.6vw, 44px);
  font-weight: 800;
  line-height: 1.04;
  letter-spacing: -0.02em;
  margin: 0 0 8px 0;
}
.menu-subtitle {
  font-size: 14px;
  color: rgba(244, 246, 248, 0.78);
  line-height: 1.45;
  margin: 0;
}

.menu-body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.menu-panel {
  width: min(460px, 100%);
  background: var(--bg-glass-strong);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

.panel-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.course-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.course-card {
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 10px;
  padding: 9px 11px;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.16s ease;
}
.course-card:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.25);
}
.course-card.active {
  background: rgba(244, 196, 78, 0.14);
  border-color: var(--accent-gold);
}
.course-card-name {
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.25;
  margin-bottom: 3px;
}
.course-card-meta {
  font-size: 10.5px;
  color: var(--text-muted);
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.mode-guide-box {
  background: rgba(244, 196, 78, 0.08);
  border: 1px solid rgba(244, 196, 78, 0.28);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 14px;
  font-size: 11px;
  line-height: 1.42;
  color: rgba(244, 246, 248, 0.88);
}
.mode-guide-box strong {
  color: var(--accent-gold);
}
.mode-guide-box code {
  background: rgba(255, 255, 255, 0.12);
  padding: 1px 4px;
  border-radius: 4px;
  font-family: inherit;
  font-weight: 700;
  color: #ffffff;
}
.mode-btn {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}
.mode-btn.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: var(--accent-emerald);
  color: #ffffff;
}

.btn-launch {
  width: 100%;
  padding: 13px 18px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, #f4c44e, #e59a28);
  color: #11161d;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(244, 196, 78, 0.25);
  transition: transform 0.14s ease, filter 0.14s ease;
}
.btn-launch:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.controls-legend {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 11.5px;
  color: rgba(244, 246, 248, 0.82);
  line-height: 1.65;
  pointer-events: auto;
}
.controls-legend kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 10.5px;
  color: var(--accent-gold);
}

/* Minimalist In-Race HUD */
#hud-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.glass-pill {
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 10px 14px;
  pointer-events: auto;
}

.hud-rank-box {
  display: flex;
  align-items: baseline;
  gap: 14px;
  white-space: nowrap;
}
.hud-pos {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent-gold);
  white-space: nowrap;
}
.hud-pos span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.hud-timer {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.hud-gate-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Crisp Horizon Compass Tape */
.compass-wrap {
  position: relative;
  flex: 0 0 auto;
  width: clamp(190px, 24vw, 280px);
  height: 36px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  mask-image: linear-gradient(90deg, transparent 0%, black 18%, black 82%, transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, black 18%, black 82%, transparent 100%);
}
.compass-track {
  position: relative;
  width: 100%;
  height: 100%;
}
.compass-tick {
  position: absolute;
  top: 7px;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
}
.compass-gate-chevron {
  position: absolute;
  bottom: 3px;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 7px solid var(--accent-gold);
}
.compass-center-mark {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 8px;
  background: #ffffff;
}

.hud-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}
.hud-btn {
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(11, 17, 26, 0.68);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  border-radius: 99px;
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.hud-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.9;
}
.hud-btn:hover,
.hud-btn:focus-visible {
  background: rgba(19, 29, 43, 0.88);
  border-color: var(--accent-gold);
  color: #ffffff;
}

.hud-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.speed-cluster {
  display: flex;
  align-items: center;
  gap: 16px;
}
.speed-val {
  font-size: 40px;
  font-weight: 800;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}
.speed-unit {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.prop-meter {
  width: 170px;
}
.prop-meter-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.prop-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  overflow: hidden;
}
.prop-bar-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, var(--accent-emerald), var(--accent-gold));
  transition: width 0.08s linear;
}

.countdown-banner {
  position: fixed;
  top: 26%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(40px, 6vw, 68px);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-shadow: 0 8px 32px rgba(0, 0, 0, 0.65);
  color: var(--accent-gold);
  pointer-events: none;
  z-index: 30;
}

.split-toast {
  position: fixed;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 16px;
  border-radius: 99px;
  background: rgba(16, 185, 129, 0.24);
  border: 1px solid rgba(16, 185, 129, 0.55);
  color: #ecfdf5;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.split-toast.show {
  opacity: 1;
}

/* Pause & Finish Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 18, 0.68);
  backdrop-filter: blur(10px);
}
.modal-card {
  width: min(440px, 92vw);
  background: var(--bg-glass-strong);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
}
.modal-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}
.btn-secondary {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-glass);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  font-weight: 600;
  cursor: pointer;
}

/* V4 Progression, Crew Selector, Telemetry & Sabar Rhythm */
.menu-kicker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.captain-rank-pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 99px;
  background: rgba(244, 196, 78, 0.16);
  border: 1px solid var(--border-gold);
  color: var(--accent-gold);
}

.course-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.course-medal-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.course-medal-badge.gold { background: rgba(244, 196, 78, 0.25); color: #fcd34d; border: 1px solid rgba(244, 196, 78, 0.55); }
.course-medal-badge.silver { background: rgba(203, 213, 225, 0.22); color: #e2e8f0; border: 1px solid rgba(203, 213, 225, 0.45); }
.course-medal-badge.bronze { background: rgba(217, 119, 6, 0.24); color: #fdba74; border: 1px solid rgba(217, 119, 6, 0.48); }
.course-best {
  font-size: 10px;
  color: var(--accent-emerald);
  margin-top: 2px;
  font-weight: 600;
}

.crew-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 16px;
}
.crew-btn {
  text-align: left;
  padding: 8px 9px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.16s ease;
}
.crew-btn:hover {
  background: rgba(255, 255, 255, 0.09);
}
.crew-btn.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: #38bdf8;
}
.crew-btn-title {
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 2px;
}
.crew-btn-sub {
  font-size: 9.8px;
  color: var(--text-muted);
  line-height: 1.25;
}

.combo-pill {
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: rgba(244, 196, 78, 0.2);
  border: 1px solid var(--border-gold);
  color: var(--accent-gold);
}

.callout-banner {
  position: fixed;
  top: 20.5%;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 99px;
  background: rgba(14, 165, 233, 0.24);
  border: 1px solid rgba(56, 189, 248, 0.65);
  color: #e0f2fe;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 28;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.hud-telemetry-pill {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-width: 256px;
}
.turbo-bar-bg {
  width: 100%;
  height: 7px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  overflow: hidden;
}
.turbo-bar-fill {
  height: 100%;
  width: 65%;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8, #f4c44e);
  transition: width 0.08s linear;
}
.turbo-bar-fill.active {
  filter: brightness(1.25);
  box-shadow: 0 0 12px rgba(244, 196, 78, 0.8);
}

.sabar-track {
  position: relative;
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.11);
  border-radius: 99px;
  overflow: hidden;
}
.sabar-sweet-spot {
  position: absolute;
  left: 41%;
  width: 18%;
  top: 0;
  bottom: 0;
  background: rgba(244, 196, 78, 0.42);
  border-left: 1px solid var(--accent-gold);
  border-right: 1px solid var(--accent-gold);
}
.sabar-cursor {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 5px;
  border-radius: 3px;
  background: #ffffff;
  box-shadow: 0 0 8px #ffffff;
  left: 50%;
  transform: translateX(-50%);
}

.current-pill {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #67e8f9;
  text-align: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(6, 182, 212, 0.18);
  border: 1px solid rgba(34, 211, 238, 0.45);
}

.finish-medal {
  display: inline-block;
  padding: 5px 14px;
  margin-bottom: 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: rgba(244, 196, 78, 0.22);
  border: 1px solid var(--border-gold);
  color: var(--accent-gold);
}
.finish-xp-line {
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 0;
}

/* V5 Tactical Vigie Proue, Heading-Up Mini-Chart, Trim Optimal & 2T Heat Gauge */
.vigie-banner {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 29;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.42);
  white-space: nowrap;
}
.vigie-banner.danger {
  background: rgba(220, 38, 38, 0.28);
  border: 1px solid rgba(248, 113, 113, 0.85);
  color: #fee2e2;
}
.vigie-banner.warn {
  background: rgba(217, 119, 6, 0.28);
  border: 1px solid rgba(251, 191, 36, 0.82);
  color: #fef3c7;
}
.vigie-banner.tip {
  background: rgba(8, 145, 178, 0.26);
  border: 1px solid rgba(34, 211, 238, 0.75);
  color: #cffafe;
}

.hud-bottom-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}
.minimap-card {
  padding: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
#hud-minimap {
  display: block;
  border-radius: 8px;
  background: rgba(7, 15, 25, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.09);
}
.minimap-turn {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-gold);
  text-transform: uppercase;
}

.prop-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
}
.trim-badge {
  font-size: 9.5px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 99px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.trim-badge.optimal { background: rgba(16, 185, 129, 0.22); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.55); }
.trim-badge.warn { background: rgba(245, 158, 11, 0.22); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.55); }

.heat-bar-bg {
  position: relative;
  width: 100%;
  height: 7px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  overflow: hidden;
}
.heat-redzone {
  position: absolute;
  left: 80%;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(239, 68, 68, 0.34);
}
.heat-limit-tick {
  position: absolute;
  left: 80%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(254, 202, 202, 0.85);
  z-index: 2;
}
.heat-bar-fill {
  position: relative;
  z-index: 1;
  height: 100%;
  width: 12%;
  background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444);
  transition: width 0.1s linear;
}
.heat-hint {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.heat-hint.ok { color: #6ee7b7; }
.heat-hint.warn { color: #fcd34d; }
.heat-hint.danger { color: #fca5a5; }
.bilge-pill {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.07em;
  color: #fecaca;
  text-align: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.25);
  border: 1px solid rgba(248, 113, 113, 0.55);
}

/* Touch Legend & Multi-Touch Cockpit Controls */
.touch-legend {
  display: none;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 11px;
  color: rgba(244, 246, 248, 0.88);
  line-height: 1.5;
  pointer-events: auto;
}
.touch-legend strong {
  color: var(--accent-gold);
}
html.is-touch .controls-legend {
  display: none;
}
html.is-touch .touch-legend {
  display: block;
}

.touch-controls {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
html.is-touch #hud-overlay:not(.hidden) .touch-controls {
  display: block;
}

.touch-stick-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: min(50%, calc(100% - 210px));
  height: 58%;
  pointer-events: auto;
  touch-action: none;
}

.touch-stick {
  position: absolute;
  left: calc(var(--sal) + 74px);
  top: calc(100% - var(--sab) - 78px);
  width: 116px;
  height: 116px;
  margin: -58px 0 0 -58px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.72);
  background: rgba(11, 17, 26, 0.36);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0.56;
  transition: opacity 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  pointer-events: none;
}
.touch-stick.active {
  opacity: 1;
}
.touch-stick.state-fwd {
  border-color: #10b981;
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.36);
}
.touch-stick.state-rev {
  border-color: #ef4444;
  box-shadow: 0 0 18px rgba(239, 68, 68, 0.42);
}

.stick-arrow {
  position: absolute;
  font-size: 9px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.54);
  pointer-events: none;
}
.stick-arrow.up { top: 6px; left: 50%; transform: translateX(-50%); }
.stick-arrow.down { bottom: 6px; left: 50%; transform: translateX(-50%); }
.stick-arrow.left { left: 7px; top: 50%; transform: translateY(-50%); }
.stick-arrow.right { right: 7px; top: 50%; transform: translateY(-50%); }

.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #d1d5db 84%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  will-change: transform;
  pointer-events: none;
}
.touch-stick.state-fwd .touch-stick-knob {
  background: radial-gradient(circle at 35% 30%, #d1fae5, #34d399 86%);
}
.touch-stick.state-rev .touch-stick-knob {
  background: radial-gradient(circle at 35% 30%, #fee2e2, #f87171 86%);
}

/* Right-thumb circular action fan (mobile standard) */
.touch-fan {
  position: absolute;
  right: calc(12px + var(--sar));
  bottom: calc(12px + var(--sab));
  width: 204px;
  height: 170px;
  pointer-events: none;
  touch-action: none;
}

.touch-fan-btn {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  pointer-events: auto;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.78);
  color: #ffffff;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.42);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  transition: transform 0.06s ease, filter 0.08s ease, border-color 0.12s ease, background 0.12s ease;
}
.touch-fan-btn.pressed,
.touch-fan-btn.turbo-on {
  transform: scale(0.92);
  filter: brightness(1.28);
}

.fan-primary {
  width: 88px;
  height: 88px;
  right: 2px;
  bottom: 2px;
  background: rgba(16, 185, 129, 0.56);
  border-color: rgba(110, 231, 183, 0.92);
}
.fan-primary .fan-label {
  font-size: 13.5px;
  line-height: 1.05;
}
.fan-primary .fan-sub {
  margin-top: 2px;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.9;
}
.fan-primary .fan-ring {
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid rgba(244, 196, 78, 0);
  transform: scale(var(--sabar-scale, 1));
  pointer-events: none;
  transition: transform 0.06s linear, border-color 0.1s ease;
}
.fan-primary.heat-warn {
  background: rgba(217, 119, 6, 0.68);
  border-color: #fbbf24;
}
.fan-primary.heat-danger {
  background: rgba(220, 38, 38, 0.78);
  border-color: #fca5a5;
  box-shadow: 0 0 18px rgba(239, 68, 68, 0.72);
}
.fan-primary.role-sabar {
  background: rgba(6, 95, 70, 0.62);
  border-color: rgba(56, 189, 248, 0.85);
}
.fan-primary.role-sabar .fan-ring {
  border-color: rgba(56, 189, 248, 0.58);
}
.fan-primary.role-sabar.sabar-hot {
  background: rgba(244, 196, 78, 0.86);
  border-color: #fef08a;
  color: #11161d;
  text-shadow: none;
  box-shadow: 0 0 22px rgba(244, 196, 78, 0.82);
}
.fan-primary.role-sabar.sabar-hot .fan-ring {
  border-color: #fde047;
  transform: scale(1.0);
}

.fan-turbo {
  width: 62px;
  height: 62px;
  right: 100px;
  bottom: 4px;
  font-size: 10.5px;
  background: rgba(24, 34, 52, 0.66);
  border-color: rgba(148, 163, 184, 0.55);
  color: rgba(226, 232, 240, 0.82);
}
.fan-turbo.turbo-ready {
  background: rgba(202, 138, 4, 0.68);
  border-color: #f4c44e;
  color: #fffbeb;
  box-shadow: 0 0 14px rgba(244, 196, 78, 0.45);
}
.fan-turbo.turbo-on {
  background: rgba(244, 196, 78, 0.86);
  border-color: #fef08a;
  color: #11161d;
  text-shadow: none;
}

.fan-rev {
  width: 56px;
  height: 56px;
  right: 8px;
  bottom: 102px;
  font-size: 10px;
  background: rgba(153, 27, 27, 0.58);
  border-color: rgba(248, 113, 113, 0.78);
}

.touch-trim-arc {
  position: absolute;
  right: 78px;
  bottom: 102px;
  display: flex;
  gap: 5px;
  pointer-events: auto;
}
.touch-trim-btn {
  appearance: none;
  -webkit-appearance: none;
  min-width: 56px;
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(11, 17, 26, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-main);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  touch-action: none;
  cursor: pointer;
}
.touch-trim-btn.pressed {
  background: rgba(244, 196, 78, 0.36);
  border-color: var(--accent-gold);
  transform: scale(0.95);
}
.touch-trim-btn.advice {
  border-color: var(--accent-gold);
  color: #fde68a;
  box-shadow: 0 0 10px rgba(244, 196, 78, 0.4);
}

.touch-onboarding {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}
.touch-tip-badge {
  position: absolute;
  padding: 8px 11px;
  border-radius: 10px;
  background: rgba(11, 17, 26, 0.84);
  border: 1px solid rgba(244, 196, 78, 0.78);
  color: rgba(244, 246, 248, 0.94);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  max-width: 175px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}
.touch-tip-badge strong {
  display: block;
  color: var(--accent-gold);
  font-size: 11.5px;
  margin-bottom: 2px;
}
.touch-tip-badge.tip-left {
  left: calc(12px + var(--sal));
  bottom: calc(146px + var(--sab));
}
.touch-tip-badge.tip-right {
  right: calc(12px + var(--sar));
  bottom: calc(188px + var(--sab));
  text-align: right;
}

/* Tablet & Compact Laptop Layout */
@media (max-width: 1024px) {
  #menu-overlay {
    padding: calc(16px + var(--sat)) calc(18px + var(--sar)) calc(20px + var(--sab)) calc(18px + var(--sal));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    gap: 14px;
    pointer-events: auto;
  }
  .menu-body {
    align-items: flex-start;
  }
  #hud-overlay {
    padding: calc(12px + var(--sat)) calc(14px + var(--sar)) calc(12px + var(--sab)) calc(14px + var(--sal));
  }
  html.is-touch .hud-bottom {
    margin-bottom: calc(174px + var(--sab));
  }
  .minimap-card canvas {
    width: 102px;
    height: 102px;
  }
}

/* Phone Portrait (e.g. 390x844, 375x667, 430x932) */
@media (max-width: 640px) and (orientation: portrait) {
  .loader-content {
    padding: 12px calc(12px + var(--sar)) calc(14px + var(--sab)) calc(12px + var(--sal));
  }
  .loader-card {
    padding: 14px 16px;
  }
  .loader-title {
    font-size: 20px;
  }
  .loader-sub {
    font-size: 10px;
    letter-spacing: 0.14em;
  }
  .loader-tip {
    font-size: 11px;
  }

  #menu-overlay {
    padding: calc(14px + var(--sat)) calc(12px + var(--sar)) calc(18px + var(--sab)) calc(12px + var(--sal));
    background: linear-gradient(180deg, rgba(8, 13, 21, 0.78) 0%, rgba(8, 13, 21, 0.45) 45%, rgba(8, 13, 21, 0.80) 100%);
  }
  .menu-title {
    font-size: 26px;
  }
  .menu-subtitle {
    font-size: 12.5px;
    line-height: 1.35;
  }
  .menu-panel {
    width: 100%;
    padding: 14px;
  }
  .course-card {
    padding: 8px 9px;
  }
  .course-card-name {
    font-size: 11.5px;
  }
  .crew-btn-sub {
    display: none;
  }
  .crew-btn {
    padding: 8px 6px;
    text-align: center;
  }

  #hud-overlay {
    padding: calc(8px + var(--sat)) calc(8px + var(--sar)) calc(8px + var(--sab)) calc(8px + var(--sal));
  }
  .hud-top {
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }
  .hud-top > .glass-pill:first-child {
    order: 1;
    padding: 6px 9px;
    flex: 1 1 auto;
    min-width: 0;
  }
  .hud-pos {
    font-size: 20px;
  }
  .hud-pos span {
    font-size: 11px;
  }
  .hud-timer {
    font-size: 13px;
  }
  .hud-gate-sub {
    font-size: 9.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hud-actions {
    order: 2;
    gap: 4px;
    flex-wrap: nowrap;
  }
  .hud-btn {
    padding: 7px 7px;
    font-size: 10px;
    min-height: 36px;
  }
  .compass-wrap {
    order: 3;
    width: 100%;
    height: 26px;
    padding: 3px 10px;
  }
  .compass-tick {
    top: 4px;
    font-size: 9px;
  }
  .vigie-banner {
    top: calc(var(--sat) + 94px);
    max-width: 92vw;
    white-space: normal;
    text-align: center;
    font-size: 10px;
    padding: 5px 11px;
  }
  .split-toast {
    top: calc(var(--sat) + 128px);
    font-size: 11px;
  }
  .callout-banner {
    top: 32%;
    font-size: 11px;
  }

  .hud-bottom {
    align-items: stretch;
    gap: 6px;
  }
  html.is-touch .hud-bottom {
    margin-bottom: calc(174px + var(--sab));
  }
  .hud-bottom-left {
    flex-direction: row;
    align-items: stretch;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
  }
  .minimap-card {
    padding: 4px;
    justify-content: center;
  }
  #hud-minimap {
    width: 56px;
    height: 56px;
  }
  .minimap-turn {
    font-size: 8.5px;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .speed-cluster {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 4px;
    padding: 6px 8px;
    flex: 1 1 auto;
    min-width: 0;
  }
  .speed-val {
    font-size: 22px;
  }
  .speed-unit {
    font-size: 9px;
  }
  .prop-meter {
    width: 100%;
  }
  .prop-meter-top {
    font-size: 9.5px;
    margin-bottom: 3px;
  }
  .prop-sub-row {
    margin-top: 3px;
    gap: 4px;
  }
  .trim-badge {
    font-size: 8.5px;
    padding: 1px 5px;
  }
  .hud-telemetry-pill {
    flex: 0 0 122px;
    min-width: 0;
    padding: 6px 8px;
    gap: 5px;
    justify-content: center;
  }
  .current-pill,
  .bilge-pill {
    font-size: 8.8px;
    padding: 2px 4px;
  }

  .touch-stick {
    left: calc(var(--sal) + 66px);
    top: calc(100% - var(--sab) - 74px);
    width: 108px;
    height: 108px;
    margin: -54px 0 0 -54px;
  }
  .touch-stick-knob {
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
  }
  .touch-fan {
    right: calc(8px + var(--sar));
    bottom: calc(8px + var(--sab));
    width: 194px;
    height: 162px;
  }
  .fan-primary {
    width: 82px;
    height: 82px;
  }
  .fan-turbo {
    width: 58px;
    height: 58px;
    right: 92px;
  }
  .fan-rev {
    width: 52px;
    height: 52px;
    bottom: 94px;
  }
  .touch-trim-arc {
    right: 70px;
    bottom: 92px;
  }
  .touch-tip-badge.tip-left,
  .touch-tip-badge.tip-right {
    bottom: calc(272px + var(--sab));
  }
  .touch-trim-btn {
    min-width: 50px;
    min-height: 30px;
    padding: 3px 6px;
    font-size: 9px;
  }
}

/* Phone Landscape (e.g. 844x390, 667x375) — Zero overlap center HUD corridor */
@media (max-height: 520px) and (orientation: landscape) {
  .loader-content {
    padding: 10px calc(16px + var(--sar)) calc(10px + var(--sab)) calc(16px + var(--sal));
  }
  .loader-card {
    padding: 12px 16px;
  }
  .loader-top-row {
    margin-bottom: 8px;
  }
  .loader-title {
    font-size: 20px;
  }
  .loader-tip {
    display: none;
  }

  #menu-overlay {
    padding: calc(10px + var(--sat)) calc(14px + var(--sar)) calc(14px + var(--sab)) calc(14px + var(--sal));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    gap: 8px;
    pointer-events: auto;
  }
  .menu-header {
    max-width: 100%;
  }
  .menu-title {
    font-size: 22px;
    margin-bottom: 2px;
  }
  .menu-subtitle {
    display: none;
  }
  .menu-body {
    gap: 10px;
    align-items: flex-start;
  }
  .menu-panel {
    width: min(540px, 100%);
    padding: 12px;
  }
  .course-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 10px;
  }
  .course-card {
    padding: 6px 8px;
  }
  .course-card-name {
    font-size: 11px;
  }
  .mode-row {
    margin-bottom: 10px;
  }
  .crew-row {
    margin-bottom: 10px;
  }

  #hud-overlay {
    padding: calc(6px + var(--sat)) calc(10px + var(--sar)) calc(6px + var(--sab)) calc(10px + var(--sal));
  }
  .hud-top {
    gap: 8px;
    align-items: center;
  }
  .hud-top > .glass-pill:first-child {
    padding: 5px 10px;
  }
  .hud-rank-box {
    gap: 8px;
  }
  .hud-pos {
    font-size: 19px;
  }
  .hud-timer {
    font-size: 13px;
  }
  .hud-gate-sub {
    font-size: 9.5px;
  }
  .compass-wrap {
    width: 150px;
    height: 28px;
    padding: 3px 8px;
  }
  .compass-tick {
    top: 4px;
    font-size: 9px;
  }
  .hud-btn {
    padding: 5px 8px;
    font-size: 10px;
    min-height: 32px;
  }
  .vigie-banner {
    top: calc(var(--sat) + 52px);
    font-size: 10px;
    padding: 4px 11px;
  }
  .split-toast {
    top: calc(var(--sat) + 84px);
    font-size: 11px;
  }
  .callout-banner {
    top: 28%;
    font-size: 11px;
  }

  html.is-touch .hud-bottom {
    margin-bottom: 0;
    margin-left: calc(136px + var(--sal));
    margin-right: calc(192px + var(--sar));
    justify-content: center;
    align-items: flex-end;
    gap: 6px;
  }
  .hud-bottom-left {
    flex-direction: row;
    align-items: flex-end;
    gap: 6px;
  }
  .minimap-card {
    padding: 4px;
  }
  #hud-minimap {
    width: 50px;
    height: 50px;
  }
  .minimap-turn {
    font-size: 8px;
  }
  .speed-cluster {
    padding: 5px 8px;
    gap: 8px;
  }
  .speed-val {
    font-size: 22px;
  }
  .speed-unit {
    font-size: 9px;
  }
  .prop-meter {
    width: 112px;
  }
  .prop-meter-top {
    font-size: 9.5px;
    margin-bottom: 3px;
  }
  .hud-telemetry-pill {
    min-width: 132px;
    padding: 5px 8px;
    gap: 4px;
  }

  .touch-stick {
    left: calc(var(--sal) + 64px);
    top: calc(100% - var(--sab) - 66px);
    width: 104px;
    height: 104px;
    margin: -52px 0 0 -52px;
  }
  .touch-stick-knob {
    width: 42px;
    height: 42px;
    margin: -21px 0 0 -21px;
  }
  .touch-fan {
    right: calc(8px + var(--sar));
    bottom: calc(6px + var(--sab));
    width: 184px;
    height: 150px;
  }
  .fan-primary {
    width: 78px;
    height: 78px;
  }
  .fan-turbo {
    width: 56px;
    height: 56px;
    right: 88px;
  }
  .fan-rev {
    width: 50px;
    height: 50px;
    bottom: 90px;
  }
  .touch-trim-arc {
    right: 68px;
    bottom: 86px;
  }
  .touch-trim-btn {
    min-width: 48px;
    min-height: 28px;
    padding: 3px 6px;
    font-size: 8.5px;
  }
}
