:root {
  --bg: #0b0f17;
  --surface: #131a26;
  --surface-2: #1a2435;
  --border: #253247;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #2563eb;
  --danger: #f43f5e;
  --success: #22c55e;
  --warn: #fbbf24;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

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

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

/* ==================== TOP BAR ==================== */
.topbar {
  height: 54px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  padding: 3px 7px;
  border-radius: 5px;
  letter-spacing: 0.08em;
}

.brand-title {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--text);
}

.mode-tabs {
  display: flex;
  background: var(--bg);
  padding: 4px;
  border-radius: 9px;
  border: 1px solid var(--border);
  gap: 4px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--accent-2);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.car-pills {
  display: flex;
  align-items: center;
  gap: 6px;
}

.car-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.car-pill:hover {
  border-color: var(--accent);
  color: var(--text);
}

.car-pill.active {
  background: rgba(56, 189, 248, 0.14);
  border-color: var(--accent);
  color: #fff;
}

.car-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  border-color: var(--accent);
}

/* ==================== STAGE ==================== */
.stage-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  padding: 14px 18px 12px;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 10px;
}

.view.active {
  display: flex;
}

.canvas-frame {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0a0d14;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.race-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #101820;
}

#race-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

#race-canvas.toem-ink {
  filter: grayscale(100%) sepia(16%) contrast(1.42) brightness(1.14);
}

.hud-btn.active {
  background: #f5efe2;
  color: #181c20;
  border-color: #f5efe2;
}

/* ==================== RACE HUD ==================== */
.hud-top-left {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.hud-card {
  background: rgba(11, 15, 23, 0.78);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 8px;
  padding: 6px 11px;
  display: flex;
  flex-direction: column;
  min-width: 66px;
}

.hud-card.wide {
  min-width: 106px;
}

.hud-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud-val {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  line-height: 1.15;
}

.hud-val small {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.hud-val.accent {
  color: var(--warn);
}

.mono {
  font-family: var(--font-mono);
}

.hud-top-right {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
}

.hud-select, .hud-btn {
  background: rgba(11, 15, 23, 0.84);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(148, 163, 184, 0.28);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.hud-btn:hover, .hud-select:hover {
  border-color: var(--accent);
}

.hud-bottom-left {
  position: absolute;
  bottom: 14px;
  left: 14px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}

.speedo {
  background: rgba(11, 15, 23, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 10px;
  padding: 8px 14px;
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.speed-num {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  min-width: 54px;
  text-align: right;
  line-height: 1;
}

.speed-unit {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
}

.boost-wrap {
  background: rgba(11, 15, 23, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 10px;
  padding: 8px 12px;
  width: 175px;
}

.boost-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 5px;
}

.drift-pill {
  background: #64748b;
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.drift-pill.tier-1 {
  background: #0ea5e9;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.7);
}

.drift-pill.tier-2 {
  background: #f97316;
  box-shadow: 0 0 8px rgba(251, 146, 60, 0.75);
}

.drift-pill.tier-3 {
  background: #c026d3;
  box-shadow: 0 0 10px rgba(232, 121, 249, 0.85);
}

.boost-track {
  height: 8px;
  background: #1e293b;
  border-radius: 4px;
  overflow: hidden;
}

.boost-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #fb923c);
  transition: width 0.06s linear;
}

/* Center Countdown / Finish Overlay */
.race-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 74px;
  gap: 8px;
  background: transparent;
  pointer-events: none;
}

.race-overlay.interactive {
  justify-content: center;
  padding-top: 0;
  pointer-events: auto;
  background: rgba(11, 15, 23, 0.68);
  backdrop-filter: blur(4px);
}

.overlay-title {
  font-family: var(--font-mono);
  font-size: 64px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.65);
  letter-spacing: 0.04em;
}

.overlay-sub {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--warn);
  font-weight: 700;
}

.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 12px;
  color: var(--muted);
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

/* ==================== STUDIO LAYOUT ==================== */
.studio-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 14px;
}

.studio-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef2f7;
  cursor: grab;
}

.studio-frame:active {
  cursor: grabbing;
}

.studio-frame.drag-over {
  outline: 3px dashed var(--accent-2);
  outline-offset: -6px;
}

#studio-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(37, 99, 235, 0.88);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  pointer-events: none;
}

.studio-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.panel-kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.panel-help {
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.slider-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.slider-meta strong {
  color: var(--text);
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 2px;
}

.chk {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.mini-selects {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mini-selects label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.mini-selects select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 12px;
}

.primary-btn, .secondary-btn {
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
}

.primary-btn:hover {
  filter: brightness(1.08);
}

.secondary-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.secondary-btn:hover {
  border-color: var(--accent);
}

.full {
  width: 100%;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.import-status {
  font-size: 11.5px;
  min-height: 16px;
  color: var(--success);
}

.import-status.err {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

/* ==================== MARIO KART LOBBY / GARAGE ==================== */
.lobby-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1.25fr 1.05fr;
  gap: 14px;
}

.lobby-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
}

.lobby-step-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.step-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
}

.step-sub {
  font-size: 11px;
  color: var(--muted);
}

/* Pilot Avatar Cards */
.pilot-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  flex: 1;
}

.pilot-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 11px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: all 0.14s ease;
}

.pilot-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.pilot-card.active {
  background: rgba(56, 189, 248, 0.12);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.45), 0 8px 20px rgba(0, 0, 0, 0.25);
}

.pilot-canvas {
  width: 58px;
  height: 58px;
  flex-shrink: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0d1422;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.pilot-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.pilot-name {
  font-weight: 800;
  font-size: 14px;
  color: #fff;
}

.pilot-role {
  display: inline-block;
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--role-col, #38bdf8) 22%, transparent);
  color: var(--role-col, #38bdf8);
  border: 1px solid color-mix(in srgb, var(--role-col, #38bdf8) 45%, transparent);
}

.pilot-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

/* Car Turntable & Specs */
.turntable-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0d1422;
  flex: 1;
  display: flex;
  flex-direction: column;
}

#lobby-car-canvas {
  width: 100%;
  flex: 1;
  min-height: 220px;
  display: block;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.turntable-caption {
  padding: 10px 14px;
  background: rgba(11, 15, 23, 0.85);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.car-big-title {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 800;
  color: #fff;
}

.car-tagline {
  font-size: 11px;
  color: var(--accent);
  text-align: right;
}

.car-select-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.car-select-btn {
  flex: 1 1 22%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.14s ease;
}

.car-select-btn:hover {
  color: #fff;
  border-color: var(--accent);
}

.car-select-btn.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: var(--accent);
  color: #fff;
}

.specs-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: #0e1420;
  border: 1px solid var(--border);
  border-radius: 11px;
  margin-top: auto;
}

.spec-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.spec-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.spec-head strong {
  color: #fff;
}

.spec-bonus {
  font-style: normal;
  color: var(--warn);
  font-weight: 800;
  font-size: 11px;
}

.spec-bar {
  position: relative;
  height: 9px;
  border-radius: 5px;
  background: #1e293b;
  overflow: hidden;
}

.spec-fill-base {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
  transition: width 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.spec-fill-bonus {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, #f59e0b, #fde047);
  transition: left 0.28s cubic-bezier(0.22, 1, 0.36, 1), width 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Track Cards & Season Pills */
.track-grid {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.track-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 9px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.14s ease;
}

.track-card:hover {
  border-color: var(--accent);
}

.track-card.active {
  background: rgba(56, 189, 248, 0.13);
  border-color: var(--accent);
}

.track-mini-canvas {
  width: 84px;
  height: 54px;
  flex-shrink: 0;
  background: #0d1422;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.track-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.track-card-title {
  font-weight: 800;
  font-size: 13px;
  color: #fff;
}

.track-card-diff {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--warn);
  font-weight: 700;
}

.track-card-sub {
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.25;
}

.lobby-sub-block {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.pill-choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.pill-choice {
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.14s ease;
}

.pill-choice:hover {
  color: #fff;
  border-color: var(--accent);
}

.pill-choice.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--accent);
  color: #fff;
}

.launch-btn {
  margin-top: auto;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: 11px;
  background: linear-gradient(135deg, #f97316, #eab308);
  color: #0b0f17;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(249, 115, 22, 0.35);
  transition: transform 0.12s ease, filter 0.15s ease;
}

.launch-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.launch-btn:active {
  transform: translateY(1px);
}

/* ==================== MOBILE MULTI-TOUCH CONTROLS ==================== */
#race-canvas,
#studio-canvas {
  touch-action: none;
}

.touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 12px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  z-index: 12;
  touch-action: none;
}

.touch-left,
.touch-right {
  pointer-events: auto;
  touch-action: none;
}

/* Mode 1: Split Left / Right Rally Buttons with seamless thumb slide-across */
.touch-steer-buttons {
  display: flex;
  gap: 10px;
  padding: 4px;
  touch-action: none;
}

.steer-key {
  width: 82px;
  height: 74px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.56);
  border: 2px solid rgba(148, 163, 184, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 900;
  color: rgba(241, 245, 249, 0.85);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.36);
  pointer-events: none;
  transition: transform 0.06s ease, background 0.07s ease, border-color 0.07s ease, color 0.07s ease;
}

.steer-key.active {
  background: rgba(37, 99, 235, 0.78);
  border-color: #7dd3fc;
  color: #fff;
  transform: scale(0.94);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.48);
}

/* Mode 2: Full Left-Half Screen Floating Dynamic Drag Steering */
.touch-drag-zone {
  position: absolute;
  left: 0;
  top: 44px;
  bottom: 0;
  width: 48%;
  pointer-events: auto;
  touch-action: none;
  display: flex;
  align-items: flex-end;
  padding: 0 0 max(16px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.drag-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: rgba(226, 232, 240, 0.65);
  background: rgba(15, 23, 42, 0.48);
  border: 1px dashed rgba(148, 163, 184, 0.38);
  padding: 8px 16px;
  border-radius: 999px;
  pointer-events: none;
}

.floating-joy {
  position: fixed;
  width: 112px;
  height: 46px;
  margin-left: -56px;
  margin-top: -23px;
  border-radius: 23px;
  background: rgba(15, 23, 42, 0.52);
  border: 1.5px solid rgba(125, 211, 252, 0.65);
  pointer-events: none;
  z-index: 20;
}

.floating-joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 36px;
  margin-left: -18px;
  margin-top: -18px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.85);
  border: 2px solid #e0f2fe;
}

.touch-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.touch-mini-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.touch-chip {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid rgba(148, 163, 184, 0.42);
  background: rgba(15, 23, 42, 0.62);
  color: #cbd5e1;
  font-size: 16px;
  display: grid;
  place-items: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
}

.touch-chip.active {
  background: rgba(37, 99, 235, 0.45);
  border-color: #38bdf8;
  color: #fff;
}

.touch-action-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.touch-btn {
  border-radius: 50%;
  border: 2px solid rgba(248, 250, 252, 0.34);
  background: rgba(15, 23, 42, 0.58);
  color: #f8fafc;
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 0.03em;
  display: grid;
  place-items: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.38);
  touch-action: none;
  transition: transform 0.06s ease, background 0.08s ease;
}

.touch-btn:active,
.touch-btn.pressed {
  transform: scale(0.92);
}

.touch-btn-gas {
  width: 78px;
  height: 78px;
  font-size: 12px;
  background: rgba(22, 163, 74, 0.62);
  border-color: rgba(134, 239, 172, 0.88);
}
.touch-btn-gas.pressed {
  background: rgba(34, 197, 94, 0.92);
}

.touch-btn-drift {
  width: 68px;
  height: 68px;
  background: rgba(37, 99, 235, 0.58);
  border-color: rgba(125, 211, 252, 0.82);
}
.touch-btn-drift.pressed {
  background: rgba(56, 189, 248, 0.88);
}

.touch-btn-boost {
  width: 54px;
  height: 54px;
  font-size: 9.5px;
  background: rgba(234, 88, 12, 0.56);
  border-color: rgba(253, 224, 71, 0.82);
}
.touch-btn-boost.pressed {
  background: rgba(251, 146, 60, 0.9);
}

.touch-btn-brake {
  width: 48px;
  height: 48px;
  font-size: 8.5px;
  background: rgba(225, 29, 72, 0.48);
  border-color: rgba(253, 164, 175, 0.68);
}
.touch-btn-brake.pressed {
  background: rgba(244, 63, 94, 0.85);
}

/* ==================== FORCE LANDSCAPE OVERLAY ON MOBILE PORTRAIT ==================== */
.rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: radial-gradient(circle at 50% 40%, #162235, #090d16 75%);
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
}

.rotate-card {
  width: 100%;
  max-width: 310px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 20px;
  border-radius: 18px;
  background: rgba(19, 26, 38, 0.92);
  border: 1.5px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.rotate-icon {
  font-size: 52px;
  line-height: 1;
  animation: phoneRotateHint 2.1s ease-in-out infinite;
}

@keyframes phoneRotateHint {
  0%, 15% { transform: rotate(0deg); }
  45%, 70% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

.rotate-title {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #f8fafc;
}

.rotate-sub {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

/* Show Force-Landscape blocker automatically on mobile/narrow portrait screens! */
@media (orientation: portrait) and (max-width: 760px),
       (orientation: portrait) and (pointer: coarse) and (max-width: 900px) {
  .app-shell {
    display: none;
  }
  .rotate-overlay {
    display: flex;
  }
}

/* Desktop passthrough for wizard wrappers */
.wizard-bar,
.mobile-only-btn {
  display: none;
}

.car-step-body,
.car-step-left,
.track-step-body,
.track-step-side {
  display: contents;
}

/* When touch controls are active, go full-bleed in race (hide app topbar & desktop hints!) */
body.touch-active .hud-bottom-left {
  bottom: 94px;
}

body.touch-active .boost-head kbd,
body.touch-active .controls-bar {
  display: none;
}

body.touch-active.in-race .topbar {
  display: none;
}

body.touch-active.in-race .stage-wrap {
  padding: 0;
}

body.touch-active.in-race .race-frame {
  border-radius: 0;
  border: none;
}

body.touch-active .mobile-only-btn {
  display: inline-flex;
}

/* Clean brake & gas touch pedals */
.touch-btn-gas {
  width: 82px;
  height: 82px;
  font-size: 13px;
}

.touch-btn-brake {
  width: 64px;
  height: 64px;
  font-size: 10px;
}

/* ==================== RESPONSIVE ZERO-SCROLL WIZARD & MOBILE ==================== */
@media (max-width: 1680px) {
  .car-pills {
    display: none;
  }
}

/* Activate Zero-Scroll 3-Step Garage Wizard on tablets, phones & mobile landscape */
@media (max-width: 1050px), (max-height: 560px) {
  #view-lobby {
    overflow: hidden;
    gap: 6px;
  }

  .wizard-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    flex-shrink: 0;
  }

  .wizard-steps {
    display: flex;
    gap: 5px;
  }

  .wizard-pill {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 800;
    padding: 5px 10px;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.14s ease;
  }

  .wizard-pill.active {
    background: var(--accent-2);
    border-color: var(--accent);
    color: #fff;
  }

  .wizard-nav {
    display: flex;
    gap: 6px;
  }

  .wizard-nav-btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 800;
    padding: 5px 12px;
    border-radius: 7px;
    cursor: pointer;
  }

  .wizard-nav-btn.primary {
    background: linear-gradient(135deg, #2563eb, #38bdf8);
    border-color: transparent;
    color: #fff;
  }

  .wizard-nav-btn.launch {
    background: linear-gradient(135deg, #f97316, #eab308);
    border-color: transparent;
    color: #0b0f17;
  }

  .lobby-grid {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .lobby-col {
    display: none;
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: 8px 10px;
    overflow: hidden;
  }

  .lobby-col.active-step {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .lobby-step-head {
    display: none;
  }

  /* STEP 1: 4 Pilot Cards side-by-side (zero scroll!) */
  .pilot-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    height: 100%;
    align-content: center;
  }

  .pilot-card {
    flex-direction: column;
    text-align: center;
    padding: 10px 8px;
    gap: 6px;
    justify-content: center;
  }

  .pilot-role {
    align-self: center;
  }

  .pilot-desc {
    font-size: 10px;
  }

  /* STEP 2: Left = 3D Turntable + Compact Specs | Right = 3x3 Car Grid (zero scroll!) */
  .car-step-body {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .car-step-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    overflow: hidden;
  }

  .turntable-card {
    flex: 1;
    min-height: 0;
  }

  #lobby-car-canvas {
    width: 100%;
    height: 100%;
    min-height: 110px;
  }

  .turntable-caption {
    padding: 5px 9px;
  }

  .car-big-title {
    font-size: 12.5px;
  }

  .car-tagline {
    display: none;
  }

  .specs-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px 10px;
    padding: 6px 9px;
    flex-shrink: 0;
  }

  .spec-head {
    font-size: 9.5px;
  }

  .spec-bar {
    height: 5px;
  }

  .car-select-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 1fr;
    gap: 6px;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .car-select-btn {
    padding: 5px 6px;
    font-size: 10.5px;
    gap: 5px;
    min-width: 0;
    text-align: center;
    flex-direction: column;
  }

  /* STEP 3: Left = 2x3 Track Grid | Right = Season + Mode + Launch (zero scroll!) */
  .track-step-body {
    display: grid;
    grid-template-columns: 1.7fr 1fr;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .track-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 1fr;
    gap: 6px;
    max-height: none;
    height: 100%;
    overflow: hidden;
    padding-right: 0;
  }

  .track-card {
    padding: 4px 6px;
    gap: 6px;
  }

  .track-card:first-child {
    grid-column: 1 / -1;
  }

  .track-mini-canvas {
    width: 54px;
    height: 34px;
  }

  .track-card-title {
    font-size: 11.5px;
  }

  .track-card-diff {
    font-size: 9px;
  }

  .track-card-sub {
    display: none;
  }

  .track-step-side {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 6px;
    min-height: 0;
    overflow: hidden;
  }

  .lobby-sub-block {
    gap: 4px;
  }

  .panel-kicker {
    font-size: 9px;
  }

  .pill-choice {
    padding: 5px 6px;
    font-size: 10.5px;
  }

  .launch-btn {
    padding: 10px 12px;
    font-size: 13.5px;
    margin-top: 0;
  }
}

@media (max-width: 960px) {
  .topbar {
    height: 40px;
    padding: 0 10px;
    gap: 6px;
  }
  .brand-title,
  .car-pills {
    display: none;
  }
  .tab-btn {
    padding: 5px 10px;
    font-size: 11.5px;
  }
  .stage-wrap {
    padding: 6px;
  }
  #view-race {
    gap: 4px;
  }
  .studio-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .studio-panel {
    max-height: 36dvh;
  }
}

/* Mobile landscape optimization (iPhone/Android sideways!) */
@media (max-height: 520px) and (max-width: 960px) {
  .topbar {
    height: 36px;
    padding: 0 8px;
  }
  .brand-badge {
    display: none;
  }
  .stage-wrap {
    padding: 4px;
  }
  .hud-top-left,
  .hud-top-right {
    top: 4px;
    gap: 4px;
  }
  .hud-card {
    padding: 3px 7px;
  }
  .hud-card.wide {
    min-width: auto;
  }
  .hud-label {
    font-size: 8px;
  }
  .hud-val {
    font-size: 12px;
  }
  .hud-card:nth-child(4) {
    display: none;
  }
  .hud-select,
  .hud-btn {
    padding: 4px 7px;
    font-size: 10.5px;
  }
  #select-season,
  #select-mode,
  #btn-toem-ink {
    display: none;
  }
  body.touch-active .hud-bottom-left {
    bottom: 84px;
  }
  .speedo {
    padding: 4px 8px;
  }
  .speed-num {
    font-size: 18px;
  }
  .boost-wrap {
    width: 110px;
    padding: 4px 7px;
  }
  .touch-controls {
    padding: 6px max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .steer-key {
    width: 76px;
    height: 68px;
    font-size: 26px;
  }
  .touch-btn-gas {
    width: 74px;
    height: 74px;
    font-size: 12px;
  }
  .touch-btn-brake {
    width: 58px;
    height: 58px;
    font-size: 9.5px;
  }
}
