/**
 * style.css - Layout and components. The visual theme (race-broadcast look:
 * solid panels, red / signal-yellow accents, condensed type) is the
 * "Paddock theme" layer at the end of this file.
 */

/* ==========================================================================
   1. Design Tokens & CSS Custom Properties
   ========================================================================== */
:root {
  --color-bg: #090c15;
  --color-bg-alt: #101524;
  --color-surface: rgba(18, 26, 42, 0.78);
  --color-surface-hover: rgba(28, 38, 58, 0.88);
  --color-surface-solid: #151d2e;
  --color-text-main: #f0f4f8;
  --color-text-muted: #8e9cb2;
  --color-text-dim: #5c6a80;

  /* Neon Racing Accents */
  --accent-cyan: #00e5ff;
  --accent-cyan-glow: rgba(0, 229, 255, 0.4);
  --accent-green: #00ff88;
  --accent-green-glow: rgba(0, 255, 136, 0.4);
  --accent-red: #ff3366;
  --accent-red-glow: rgba(255, 51, 102, 0.4);
  --accent-amber: #ffaa00;
  --accent-gold: #ffd700;
  --accent-purple: #b366ff;

  /* Glassmorphism Surface Settings */
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-border-focus: rgba(0, 229, 255, 0.6);
  --glass-blur: 16px;
  --glass-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.1);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Consolas", "Roboto Mono", "Courier New", monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   2. Base Reset & Full-Screen Canvas Layout
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--color-bg);
  color: var(--color-text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

.game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.game-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 1;
  background: #080a10;
}

/* Common Helper Classes */
.hidden {
  display: none !important;
}

.uppercase {
  text-transform: uppercase;
}

/* ==========================================================================
   3. Glassmorphism Panels & Cards
   ========================================================================== */
.glass-panel {
  background: var(--color-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--glass-shadow);
}

.glass-card {
  background: linear-gradient(135deg, rgba(20, 29, 46, 0.82), rgba(11, 16, 26, 0.92));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* ==========================================================================
   4. Form Elements & Interactive Controls
   ========================================================================== */
.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 5px;
}

.text-input,
.select-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  background: rgba(10, 14, 22, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-main);
  font-family: var(--font-sans);
  font-size: 13px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.text-input:focus,
.select-input:focus {
  outline: none;
  border-color: var(--glass-border-focus);
  box-shadow: 0 0 0 2px var(--accent-cyan-glow);
}

.select-input option {
  background: var(--color-bg-alt);
  color: var(--color-text-main);
}

.input-with-button {
  display: flex;
  gap: 8px;
}

.input-with-button .text-input {
  flex: 1;
}

/* Standard Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: linear-gradient(135deg, #00b4d8, #0077b6);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--accent-cyan-glow);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #00e5ff, #0096c7);
  box-shadow: 0 6px 20px var(--accent-cyan-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
  color: var(--color-text-main);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

/* ==========================================================================
   5. In-Game Racing HUD Overlay
   ========================================================================= */
.hud-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  transition: opacity var(--transition-normal);
}

.hud-overlay.hud-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* Instruments Panel (Top-Left) */
.hud-panel-instruments {
  width: 260px;
  padding: 14px 16px;
  pointer-events: auto;
}

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

.hud-speedometer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

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

.hud-value-container {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.hud-digital-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 900;
  color: var(--accent-cyan);
  text-shadow: 0 0 10px var(--accent-cyan-glow);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

.hud-unit {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text-muted);
}

.hud-gauge-wrapper {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 4px;
}

.hud-gauge-bar {
  height: 100%;
  background: linear-gradient(90deg, #00ff88 0%, #00e5ff 60%, #ff3366 100%);
  border-radius: var(--radius-full);
  transition: width 0.06s linear;
}

.hud-offtrack-badge {
  margin-top: 6px;
  padding: 4px 8px;
  background: rgba(255, 51, 102, 0.25);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius-sm);
  color: #ff6688;
  font-size: 10px;
  font-weight: 800;
  text-align: center;
  animation: pulse-warning 1s infinite alternate;
}

@keyframes pulse-warning {
  from { opacity: 0.7; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1.02); }
}

.hud-instrument-divider {
  height: 1px;
  background: var(--glass-border);
  margin: 12px 0 10px 0;
}

.hud-lap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.hud-metric-box {
  display: flex;
  flex-direction: column;
}

.hud-metric-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text-main);
  font-feature-settings: "tnum";
}

.highlight-best .hud-metric-value {
  color: var(--accent-gold);
}

.hud-split-container {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--glass-border);
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
}

.hud-split-value.split-ahead {
  color: var(--accent-green);
  font-weight: 800;
}

.hud-split-value.split-behind {
  color: var(--accent-red);
  font-weight: 800;
}

/* Center Notification Banner */
.hud-center-banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 229, 255, 0.15);
  border: 1px solid var(--accent-cyan);
  border-radius: var(--radius-lg);
  padding: 12px 28px;
  box-shadow: 0 0 30px var(--accent-cyan-glow);
  animation: banner-pop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.hud-banner-text {
  font-size: 26px;
  white-space: nowrap;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 0.1em;
  text-align: center;
  text-shadow: 0 0 12px var(--accent-cyan-glow);
}

@keyframes banner-pop {
  0% { transform: translate(-50%, -10px) scale(0.9); opacity: 0; }
  100% { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

/* Leaderboard (Top-Right) */
.hud-panel-leaderboard {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 290px;
  padding: 12px 14px;
  pointer-events: auto;
}

.hud-leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.hud-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent-cyan);
}

.hud-room-tag {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
}

.hud-leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.hud-leaderboard-table th {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--color-text-dim);
  text-align: left;
  padding-bottom: 4px;
}

.hud-leaderboard-table td {
  padding: 4px 2px;
  font-family: var(--font-mono);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.hud-driver-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans) !important;
  font-weight: 600;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-color-pill {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  display: inline-block;
  flex-shrink: 0;
}

.hud-leaderboard-row.local-player {
  background: rgba(0, 229, 255, 0.12);
  border-left: 2px solid var(--accent-cyan);
}

.hud-leaderboard-row.local-player .hud-driver-cell {
  color: var(--accent-cyan);
}

/* Controls Hint (Bottom-Left) & Ping Badge (Bottom-Right) */
.hud-controls-hint {
  position: absolute;
  bottom: 20px;
  left: 20px;
  padding: 8px 12px;
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--color-text-muted);
}

.hud-controls-hint kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  border-radius: 3px;
  padding: 1px 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: #fff;
}

.hud-net-badge {
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-family: var(--font-mono);
}

.ping-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green-glow);
}

/* ==========================================================================
   6. Pre-Race Countdown Overlay
   ========================================================================== */
.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(5, 8, 15, 0.35);
  backdrop-filter: blur(4px);
}

.countdown-number {
  font-size: 130px;
  font-weight: 900;
  color: var(--accent-cyan);
  text-shadow: 0 0 40px var(--accent-cyan-glow);
  animation: countdown-pop 0.9s ease-out infinite;
}

@keyframes countdown-pop {
  0% { transform: scale(1.4); opacity: 0.2; }
  40% { transform: scale(1); opacity: 1; }
  85% { transform: scale(0.95); opacity: 1; }
  100% { transform: scale(0.8); opacity: 0; }
}

/* ==========================================================================
   7. Pre-Game Lobby Overlay & Customization Grid
   ========================================================================== */
.lobby-overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 50%, rgba(18, 25, 40, 0.75) 0%, rgba(7, 10, 18, 0.9) 100%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.lobby-container {
  width: 100%;
  max-width: 1080px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--glass-border);
}

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

.brand-icon {
  font-size: 32px;
}

.brand-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #ffffff;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--color-text-muted);
}

.lobby-connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-full);
}

.status-dot.connected {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green-glow);
}

.status-dot.disconnected {
  background: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red-glow);
}

/* 3-Column Lobby Grid */
.lobby-main-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr;
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
}

.lobby-section {
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #ffffff;
  margin-bottom: 14px;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.section-header-row .section-title {
  margin-bottom: 0;
}

.roster-counter {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-cyan);
}

.badge-host {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  background: rgba(255, 170, 0, 0.2);
  border: 1px solid var(--accent-amber);
  border-radius: var(--radius-full);
  color: var(--accent-amber);
}

/* Vehicle Livery Customization */
.customization-group {
  margin-top: 10px;
}

.car-preview-container {
  display: flex;
  gap: 16px;
  align-items: center;
  background: rgba(9, 13, 22, 0.65);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 12px;
}

.preview-badge-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: radial-gradient(circle, rgba(28, 40, 64, 0.6) 0%, rgba(10, 14, 24, 0.9) 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 6px;
}

.car-preview-canvas {
  display: block;
}

.preview-badge-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--color-text-dim);
}

.color-selection-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-palette-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text-muted);
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.color-swatch-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  padding: 0;
  background-color: var(--swatch-color);
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.color-swatch-btn:hover {
  transform: scale(1.1);
  border-color: #ffffff;
}

.color-swatch-btn.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--color-bg), 0 0 8px var(--swatch-color);
  transform: scale(1.08);
}

.custom-color-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.custom-picker-label {
  font-size: 11px;
  color: var(--color-text-muted);
}

.color-swatch-input {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0;
  cursor: pointer;
  background: none;
}

.color-swatch-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-swatch-input::-webkit-color-swatch {
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
}

.hex-text-input {
  width: 80px;
  height: 28px;
  padding: 0 6px;
  background: rgba(10, 14, 22, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-main);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
}

/* Roster List in Lobby */
.roster-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 160px;
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.roster-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(11, 16, 26, 0.65);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
}

.roster-card.is-local {
  border-color: var(--accent-cyan);
  background: rgba(0, 229, 255, 0.08);
}

.roster-card-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.roster-driver-name {
  font-weight: 700;
  font-size: 13px;
}

.roster-card-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ready-pill {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.ready-pill.ready {
  background: rgba(0, 255, 136, 0.2);
  border: 1px solid var(--accent-green);
  color: var(--accent-green);
}

.ready-pill.waiting {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--color-text-muted);
}

/* Ready Button */
.lobby-ready-actions {
  margin-top: auto;
}

.btn-ready {
  width: 100%;
  height: 46px;
  font-size: 15px;
  background: linear-gradient(135deg, #00ff88, #00b359);
  color: #07170e;
  box-shadow: 0 4px 18px var(--accent-green-glow);
}

.btn-ready:hover:not(:disabled) {
  background: linear-gradient(135deg, #26ff9a, #00cc66);
  box-shadow: 0 6px 24px var(--accent-green-glow);
}

.btn-ready.ready-active {
  background: linear-gradient(135deg, #ff3366, #cc1144);
  color: #ffffff;
  box-shadow: 0 4px 18px var(--accent-red-glow);
}

/* Active Track Box */
.active-track-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(10, 14, 22, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.track-info {
  display: flex;
  flex-direction: column;
}

.track-name {
  font-weight: 700;
  font-size: 12px;
}

.track-dim {
  font-size: 10px;
  color: var(--color-text-dim);
}

.settings-actions {
  margin-top: 14px;
}

.settings-actions .btn {
  width: 100%;
}

/* ==========================================================================
   8. Custom Map Modal & Dialog Styles
   ========================================================================== */
.modal-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  padding: 0;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(20, 29, 46, 0.95), rgba(10, 15, 25, 0.98));
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75);
  color: var(--color-text-main);
  max-width: 640px;
  width: 90%;
  max-height: 90vh;
  overflow: hidden;
  z-index: 100;
}

.modal-dialog::backdrop {
  background: rgba(4, 7, 13, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--glass-border);
}

.modal-title {
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.modal-close-btn:hover {
  color: #ffffff;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.map-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 15, 26, 0.5);
  border: 2px dashed rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  text-align: center;
  margin-bottom: 16px;
}

.map-drop-zone:hover,
.map-drop-zone.drag-over {
  border-color: var(--accent-cyan);
  background: rgba(0, 229, 255, 0.08);
}

.drop-zone-icon {
  font-size: 32px;
  margin-bottom: 6px;
}

.drop-zone-primary {
  font-weight: 700;
  margin-bottom: 2px;
}

.drop-zone-secondary {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}

.hidden-file-input {
  display: none;
}

.map-calibration-grid {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
}

.calibration-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(8, 12, 20, 0.8);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 10px;
}

.map-preview-canvas {
  width: 240px;
  height: 240px;
  background: #000000;
  border-radius: var(--radius-sm);
  display: block;
}

.map-file-info {
  margin-top: 8px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--color-text-dim);
}

.calibration-inputs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.coord-fieldset {
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.coord-legend {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text-muted);
  padding: 0 4px;
}

.coord-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
  gap: 6px;
  margin-top: 4px;
}

.coord-input {
  height: 32px;
  padding: 0 6px;
  background: rgba(10, 14, 22, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-main);
  font-family: var(--font-mono);
  font-size: 11px;
  width: 100%;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--glass-border);
}

.status-msg {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.status-msg.error {
  background: rgba(255, 51, 102, 0.2);
  border: 1px solid var(--accent-red);
  color: #ff6688;
}

.status-msg.success {
  background: rgba(0, 255, 136, 0.2);
  border: 1px solid var(--accent-green);
  color: #33ff99;
}

/* ==========================================================================
   9. Podium & Game Over Dialog
   ========================================================================== */
#game-over-dialog {
  max-width: 480px;
}

.podium-body {
  padding: 24px;
}

.podium-standings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.podium-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(12, 17, 28, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
}

.podium-rank-1 {
  border-color: var(--accent-gold);
  background: rgba(255, 215, 0, 0.1);
}

.podium-rank-2 {
  border-color: #c0c0c0;
  background: rgba(192, 192, 192, 0.1);
}

.podium-rank-3 {
  border-color: #cd7f32;
  background: rgba(205, 127, 50, 0.1);
}

/* ==========================================================================
   10. Responsive Breakpoints
   ========================================================================== */
@media (max-width: 1024px) {
  .lobby-main-grid {
    grid-template-columns: 1fr 1fr;
  }
  .lobby-section:nth-child(3) {
    grid-column: span 2;
  }
  .hud-panel-instruments {
    width: 220px;
  }
  .hud-panel-leaderboard {
    width: 240px;
  }
}

@media (max-width: 768px) {
  .lobby-overlay {
    padding: 10px;
  }
  .lobby-main-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }
  .lobby-section:nth-child(3) {
    grid-column: span 1;
  }
  .hud-panel-leaderboard {
    display: none; /* Hide heavy table on small mobile screens */
  }
  .hud-panel-instruments {
    width: 190px;
    padding: 10px;
  }
  .map-calibration-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   11. UI Refresh: position, personal best, start lights, vignette, touch
   ========================================================================== */
.hud-top-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.hud-position-box {
  display: flex;
  flex-direction: column;
}

.hud-position-value {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.hud-position-value small {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-left: 2px;
}

.hud-speedometer {
  flex-direction: column;
  align-items: flex-end;
}

.hud-digital-value.speed-high {
  color: var(--accent-red);
  text-shadow: 0 0 12px var(--accent-red-glow);
}

.hud-pb-row {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hud-pb-value {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-purple);
}

.hud-pb-value.pb-flash {
  animation: pb-flash 0.6s ease-in-out 4;
}

@keyframes pb-flash {
  50% { color: #ffffff; text-shadow: 0 0 10px var(--accent-purple); }
}

.hud-split-label {
  color: var(--color-text-muted);
}

.hud-bottom-right {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.hud-icon-btn {
  width: 34px;
  height: 30px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  color: var(--color-text-main);
}

.hud-icon-btn:hover {
  background: var(--color-surface-hover);
}

.hud-controls-hint {
  transition: opacity 0.6s ease;
}

.hud-controls-hint.faded {
  opacity: 0;
}

.hud-controls-hint kbd + kbd {
  margin-left: 2px;
}

/* Off-track red edge glow */
.offtrack-vignette {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  box-shadow: inset 0 0 120px 30px rgba(255, 40, 80, 0.55);
}

.offtrack-vignette.active {
  opacity: 1;
}

/* F1-style start lights */
.start-lights {
  display: flex;
  gap: 18px;
  padding: 14px 20px;
  background: rgba(8, 10, 16, 0.85);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.start-light {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #2a1518;
  border: 2px solid #3a2226;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}

.start-light.on {
  background: #ff2340;
  border-color: #ff6680;
  box-shadow: 0 0 24px rgba(255, 35, 64, 0.85);
}

.start-lights.go .start-light {
  background: #00ff88;
  border-color: #7dffc0;
  box-shadow: 0 0 24px rgba(0, 255, 136, 0.85);
}

/* Lobby helpers */
.section-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 900;
  color: #05202a;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

.form-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--color-text-dim);
  line-height: 1.5;
}

.ready-hint {
  margin: 0 0 10px;
  text-align: center;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.settings-actions .form-hint {
  text-align: center;
}

.roster-empty {
  margin: auto;
  font-size: 12px;
  color: var(--color-text-dim);
  text-align: center;
}

.podium-detail {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: right;
}

.podium-detail strong {
  display: block;
  font-size: 14px;
  color: var(--color-text-main);
}

/* Touch controls: only on touch-first devices */
.touch-controls {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 64px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
  }
  .touch-group {
    display: flex;
    gap: 14px;
  }
  .touch-btn {
    pointer-events: auto;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.25);
    background: rgba(15, 20, 30, 0.55);
    color: #ffffff;
    font-size: 24px;
    font-weight: 800;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }
  .touch-btn.pressed {
    background: rgba(0, 229, 255, 0.35);
    border-color: var(--accent-cyan);
  }
  .touch-gas.pressed {
    background: rgba(0, 255, 136, 0.35);
    border-color: var(--accent-green);
  }
  .touch-brake.pressed {
    background: rgba(255, 51, 102, 0.35);
    border-color: var(--accent-red);
  }
  .hud-controls-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .countdown-number,
  .hud-offtrack-badge,
  .hud-center-banner,
  .hud-pb-value.pb-flash {
    animation: none;
  }
}

/* Finish-line grace countdown */
.hud-finish-timer {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: var(--radius-full);
  background: rgba(255, 215, 0, 0.16);
  border: 1px solid var(--accent-gold);
  color: #fff3b0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
  box-shadow: 0 0 18px rgba(255, 215, 0, 0.25);
  font-variant-numeric: tabular-nums;
}

.hud-finish-timer.urgent {
  background: rgba(255, 51, 102, 0.22);
  border-color: var(--accent-red);
  color: #ffd0da;
  animation: pulse-warning 0.5s infinite alternate;
}

/* ==========================================================================
   12. Real circuits: track picker, preview, gear indicator
   ========================================================================== */
.track-preview-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(10, 14, 22, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 12px;
}

.track-preview-canvas {
  width: 110px;
  height: 88px;
  flex: none;
  border-radius: 6px;
  background: radial-gradient(circle at 50% 40%, rgba(70, 130, 80, 0.35), rgba(20, 28, 38, 0.6));
}

.track-preview-card .track-info {
  gap: 3px;
  min-width: 0;
}

.track-preview-card .track-name {
  font-size: 14px;
}

.track-preview-card .track-dim {
  font-size: 11px;
  line-height: 1.4;
}

.my-track-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.my-track-row .select-input {
  flex: 1;
  min-width: 0;
}

.my-track-row a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.hud-gear-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 34px;
}

.hud-gear-value {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  color: #ffd60a;
  font-variant-numeric: tabular-nums;
}

.driver-assists {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0 4px;
}

.ed-check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--color-text-muted);
  cursor: pointer;
}

/* 13. Quick match, bots, slipstream */
.btn-quick-match {
  width: 100%;
  margin-top: 10px;
}

.online-stats {
  margin-top: 6px;
  text-align: center;
}

.online-stats:empty {
  display: none;
}

.badge-bot {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(120, 160, 255, 0.18);
  color: #9db7ff;
  white-space: nowrap;
}



/* ==========================================================================
   14. Paddock theme — race-broadcast look
   Solid panels, hairline rules, racing red + signal yellow, condensed
   italic numerals. No blur, no glow.
   ========================================================================== */
:root {
  --color-bg: #0c0c0e;
  --color-bg-alt: #121215;
  --color-surface: rgba(18, 18, 21, 0.94);
  --color-surface-hover: #1d1d22;
  --color-surface-solid: #141417;
  --color-text-main: #eceae5;
  --color-text-muted: #9b9892;
  --color-text-dim: #66645f;
  --line: #2a2a30;
  --line-strong: #3b3b42;

  --accent-red: #e10600;
  --accent-yellow: #ffcf1a;
  --accent-cyan: var(--accent-yellow);
  --accent-green: #2ecc71;
  --accent-gold: var(--accent-yellow);
  --accent-amber: var(--accent-yellow);
  --accent-purple: #a96bff;
  --accent-cyan-glow: transparent;
  --accent-green-glow: transparent;
  --accent-red-glow: transparent;

  --glass-border: var(--line);
  --glass-border-focus: var(--color-text-main);
  --glass-shadow: none;

  --font-display: "Barlow Condensed", "Arial Narrow", "PingFang TC", "Noto Sans TC", sans-serif;
  --font-sans: "Noto Sans TC", -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: "Barlow Condensed", "SF Mono", Consolas, monospace;
  --radius-sm: 2px;
  --radius-md: 3px;
  --radius-lg: 4px;
}

body { background: var(--color-bg); }

.glass-panel,
.glass-card,
.modal-dialog {
  background: var(--color-surface);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: 1px solid var(--line);
  box-shadow: none;
}

.modal-dialog { background: var(--color-surface-solid); border-top: 3px solid var(--accent-red); }
.modal-dialog::backdrop { background: rgba(5, 5, 6, 0.8); backdrop-filter: none; -webkit-backdrop-filter: none; }
.modal-title { font-family: var(--font-display); font-size: 22px; font-weight: 700; font-style: italic; letter-spacing: 0.02em; text-transform: uppercase; }

/* ---- Type ---- */
.form-label,
.hud-label,
.hud-title,
.track-dim,
.roster-counter {
  font-family: var(--font-display);
  letter-spacing: 0.05em;
}

.form-label { font-size: 13px; font-weight: 600; color: var(--color-text-muted); text-transform: none; margin-bottom: 6px; }
.form-hint { color: var(--color-text-dim); font-size: 12px; }

/* ---- Inputs ---- */
.text-input,
.select-input,
.hex-text-input {
  background: #0f0f12;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.text-input:focus,
.select-input:focus { border-color: var(--color-text-main); box-shadow: none; }

.ed-check input[type="checkbox"],
.driver-assists input[type="checkbox"] { accent-color: var(--accent-red); width: 15px; height: 15px; }
.ed-check { color: var(--color-text-main); font-size: 13px; }

/* ---- Buttons ---- */
.btn {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.btn:active { transform: translateY(1px); }
.btn-sm { font-size: 14px; }

.btn-primary { background: var(--accent-red); color: #fff; box-shadow: none; }
.btn-primary:hover:not(:disabled) { background: #ff2414; box-shadow: none; }

.btn-secondary { background: transparent; border: 1px solid var(--line-strong); color: var(--color-text-main); }
.btn-secondary:hover:not(:disabled) { background: #1a1a1e; border-color: var(--color-text-muted); }

.btn-quick-match { border-color: var(--accent-yellow); color: var(--accent-yellow); }
.btn-quick-match:hover:not(:disabled) { background: var(--accent-yellow); color: #111; border-color: var(--accent-yellow); }

.btn-ready { height: 52px; font-size: 22px; font-style: italic; background: var(--accent-red); color: #fff; box-shadow: none; }
.btn-ready:hover:not(:disabled) { background: #ff2414; box-shadow: none; }
.btn-ready.ready-active { background: transparent; color: var(--accent-yellow); border: 2px solid var(--accent-yellow); box-shadow: none; }

/* ---- Lobby ---- */
.lobby-overlay {
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 14px),
    rgba(9, 9, 11, 0.9);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.lobby-container { border-top: 3px solid var(--accent-red); background: var(--color-surface-solid); }
.lobby-header { padding: 16px 22px; border-bottom: 1px solid var(--line); }

.brand-mark {
  width: 34px;
  height: 34px;
  flex: none;
  background: repeating-conic-gradient(#eceae5 0 25%, #111 0 50%) 0 0 / 11.33px 11.33px;
  border: 1px solid #eceae5;
  transform: skewX(-10deg);
}

.brand-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 26px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.02em;
  line-height: 1;
}

.brand-tag {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.12em;
  color: var(--accent-red);
}

.brand-subtitle { font-family: var(--font-display); font-size: 14px; letter-spacing: 0.06em; color: var(--color-text-muted); margin-top: 4px; }

.status-dot { border-radius: 0; width: 8px; height: 8px; }
.status-dot.connected { background: var(--accent-green); box-shadow: none; }
.status-dot.disconnected { background: var(--accent-red); box-shadow: none; }
.lobby-connection-status { font-family: var(--font-display); font-size: 14px; letter-spacing: 0.04em; color: var(--color-text-muted); }

.lobby-main-grid { gap: 0; padding: 0; }
.lobby-section { background: transparent; border: none; border-right: 1px solid var(--line); border-radius: 0; padding: 18px 20px; }
.lobby-section:last-child { border-right: none; }

.section-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  gap: 10px;
}

.section-step {
  width: auto;
  height: auto;
  min-width: 0;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  color: var(--accent-red);
  font-size: 22px;
  font-weight: 800;
}

.roster-counter { font-size: 18px; font-weight: 700; color: var(--color-text-muted); }

.car-preview-container,
.preview-badge-wrapper { background: #0f0f12; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.preview-badge-wrapper { background: #0a0a0c; }
.color-swatch-btn { border-radius: 0; border: 2px solid transparent; }
.color-swatch-btn:hover { transform: none; border-color: var(--color-text-muted); }
.color-swatch-btn.active { border-color: #fff; box-shadow: 0 0 0 2px var(--color-bg); transform: none; }

/* Roster: flat timing-sheet rows */
.roster-list { gap: 0; border-top: 1px solid var(--line); }
.roster-card {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: 0;
  padding: 9px 10px;
}
.roster-card.is-local { background: rgba(255, 207, 26, 0.06); border-left-color: var(--accent-yellow); }
.roster-card .hud-color-pill { width: 4px; height: 18px; border-radius: 0; }
.roster-driver-name { font-family: var(--font-display); font-size: 17px; font-weight: 700; letter-spacing: 0.02em; }

.ready-pill { background: none !important; border: none !important; border-radius: 0; padding: 0; font-family: var(--font-display); font-size: 13px; letter-spacing: 0.06em; }
.ready-pill.ready { color: var(--accent-green); }
.ready-pill.waiting { color: var(--color-text-dim); }

.badge-host,
.badge-bot {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  border-radius: 0;
  background: none;
}
.badge-host { color: #111; background: var(--accent-yellow); border: none; }
.badge-bot { color: var(--color-text-muted); border: 1px solid var(--line-strong); cursor: help; }

.online-stats { font-family: var(--font-display); font-size: 13px; letter-spacing: 0.04em; color: var(--color-text-muted); }
.online-stats::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; background: var(--accent-green); vertical-align: 1px; }

.track-preview-card { background: #0f0f12; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.track-name { font-family: var(--font-display); font-size: 17px; font-weight: 700; letter-spacing: 0.02em; }

/* ---- In-race HUD ---- */
.hud-panel-instruments { background: rgba(10, 10, 12, 0.86); border: none; border-left: 3px solid var(--accent-red); }

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

.hud-position-value,
.hud-digital-value,
.hud-gear-value,
.hud-metric-value,
.hud-pb-value,
.countdown-number,
.hud-banner-text {
  font-family: var(--font-display);
  font-style: italic;
  text-shadow: none;
}

.hud-position-value { font-size: 40px; font-weight: 800; }
.hud-digital-value { font-size: 40px; font-weight: 800; color: #fff; }
.hud-digital-value.speed-high { color: var(--accent-red); text-shadow: none; }
.hud-gear-value { color: var(--accent-yellow); }
.hud-metric-value { font-size: 20px; font-weight: 700; }
.hud-pb-value { font-size: 17px; }

.hud-gauge-wrapper { height: 5px; border-radius: 0; background: #26262b; }
.hud-gauge-bar {
  border-radius: 0;
  background: linear-gradient(90deg, #2ecc71 0 55%, #ffcf1a 55% 80%, #e10600 80% 100%);
  background-size: 260px 100%;
}

.hud-offtrack-badge { background: var(--accent-red); border: none; border-radius: 0; color: #fff; font-family: var(--font-display); font-size: 14px; letter-spacing: 0.04em; animation: none; }

.hud-draft,
.hud-autopilot {
  margin-top: 6px;
  padding: 2px 8px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  white-space: nowrap;
}
.hud-draft { color: #0c0c0e; background: #7fd4ff; }
.hud-autopilot { color: #0c0c0e; background: var(--accent-yellow); }

/* Leaderboard as a timing tower */
.hud-panel-leaderboard { width: 260px; padding: 0; background: rgba(10, 10, 12, 0.86); border: none; }
.hud-leaderboard-header { margin: 0; padding: 8px 12px; background: var(--accent-red); }
.hud-title { font-size: 16px; font-weight: 800; font-style: italic; color: #fff; text-transform: uppercase; }
.hud-room-tag { font-family: var(--font-display); font-size: 13px; color: rgba(255, 255, 255, 0.8); }
.hud-leaderboard-table-wrap { padding: 2px 0 4px; }
.hud-leaderboard-table th { font-family: var(--font-display); font-size: 12px; color: var(--color-text-dim); padding: 4px 8px 2px; }
.hud-leaderboard-table td { font-family: var(--font-display); font-size: 16px; padding: 3px 8px; border-bottom: 1px solid #1b1b1f; }
.hud-leaderboard-table td.col-pos { width: 34px; font-weight: 800; font-style: italic; color: #111; background: #eceae5; text-align: center; }
.hud-driver-cell { font-family: var(--font-display) !important; font-weight: 700; font-size: 16px; max-width: 130px; }
.hud-leaderboard-table .hud-color-pill { width: 3px; height: 15px; border-radius: 0; }
.hud-leaderboard-row.local-player { background: rgba(255, 207, 26, 0.1); border-left: none; }
.hud-leaderboard-row.local-player td.col-pos { background: var(--accent-yellow); }
.hud-leaderboard-row.local-player .hud-driver-cell { color: var(--accent-yellow); }

/* Banners, countdown, finish timer */
.hud-center-banner { background: rgba(10, 10, 12, 0.92); border: none; border-left: 4px solid var(--accent-red); border-radius: 0; box-shadow: none; padding: 10px 26px; }
.hud-banner-text { font-size: 30px; font-weight: 800; letter-spacing: 0.03em; }

.countdown-overlay { background: rgba(5, 5, 6, 0.35); backdrop-filter: none; }
.countdown-number { color: #fff; font-weight: 900; }

.hud-controls-hint { background: rgba(10, 10, 12, 0.8); border: none; }
.hud-controls-hint kbd { background: #eceae5; color: #111; border: none; border-radius: 1px; font-family: var(--font-display); font-weight: 700; font-size: 12px; }
.hud-net-badge { font-family: var(--font-display); font-size: 14px; }
.hud-net-badge,
.hud-icon-btn { background: rgba(10, 10, 12, 0.8); border: none; }
.hud-icon-btn { display: inline-flex; align-items: center; justify-content: center; }
.ping-dot { border-radius: 0; box-shadow: none; }

/* Results */
.podium-row { background: transparent; border: none; border-bottom: 1px solid var(--line); border-radius: 0; }
.podium-driver { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 18px; }
.podium-pos {
  min-width: 30px;
  padding: 2px 0;
  text-align: center;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  font-style: italic;
  color: #111;
  background: #eceae5;
}
.podium-rank-1 .podium-pos { background: var(--accent-yellow); }
.podium-pos.is-dnf { font-size: 14px; background: #2a2a30; color: var(--color-text-muted); }
.podium-detail strong { font-family: var(--font-display); font-style: italic; font-size: 20px; }

/* Touch controls */
.touch-btn { border-radius: 4px; background: rgba(10, 10, 12, 0.7); border: 1px solid var(--line-strong); font-family: var(--font-display); font-weight: 700; }

/* ==========================================================================
   15. Start screen / room screen (two-step lobby)
   ========================================================================== */
.lobby-overlay[data-view="start"] .room-only,
.lobby-overlay[data-view="room"] .start-only { display: none !important; }

.lobby-container { max-width: 1000px; max-height: 94vh; }
.start-view,
.room-view {
  display: grid;
  overflow-y: auto;
  min-height: 0;
}
.start-view { grid-template-columns: minmax(260px, 0.9fr) 1.3fr; }
.room-view { grid-template-columns: 1.15fr 1fr; }
.start-view > section,
.room-view > section { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.start-driver,
.room-track { border-right: 1px solid var(--line); }

/* Mode tiles */
.mode-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  font: inherit;
  color: var(--color-text-main);
  background: #0f0f12;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
div.mode-tile { cursor: default; }
button.mode-tile:hover,
button.mode-tile:focus-visible { background: var(--color-surface-hover); border-left-color: var(--accent-red); outline: none; }
.mode-tile.mode-primary { border-left-color: var(--accent-yellow); background: rgba(255, 207, 26, 0.05); }
.mode-tile.mode-primary:hover { border-left-color: var(--accent-yellow); background: rgba(255, 207, 26, 0.1); }
.mode-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: 0.02em;
  line-height: 1.1;
}
.mode-primary .mode-title { color: var(--accent-yellow); }
.mode-desc { font-size: 13px; color: var(--color-text-muted); }
.mode-tile .online-stats { margin-top: 4px; }
.mode-friends .input-with-button { width: 100%; margin-top: 6px; }

.start-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--color-text-dim);
}
.start-footer a { color: var(--color-text-muted); }
#gamepad-status { color: var(--accent-green); }

/* Room bar in the header */
.room-bar { display: flex; align-items: center; gap: 8px; }
.room-bar-label { font-family: var(--font-display); font-size: 13px; letter-spacing: 0.08em; color: var(--color-text-dim); }
.room-code {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent-yellow);
  margin-right: 4px;
}

/* Room view */
.room-track .track-preview-card { display: flex; gap: 14px; align-items: center; padding: 12px; }
.room-track .track-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.room-track .track-name { font-size: 22px; }
.track-dim { font-size: 13px; color: var(--color-text-muted); }
.settings-form { display: flex; flex-direction: column; gap: 12px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-2 > .hidden { display: none; }
.form-row-2 .form-group,
.settings-form .form-group { margin: 0; }
.advanced-settings { border-top: 1px solid var(--line); padding-top: 10px; }
.advanced-settings > summary {
  cursor: pointer;
  list-style: none;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}
.advanced-settings > summary::-webkit-details-marker { display: none; }
.advanced-settings > summary::before { content: "+ "; color: var(--accent-red); }
.advanced-settings[open] > summary::before { content: "– "; }
.advanced-body { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.my-track-row { display: flex; gap: 8px; margin-top: 6px; }
.my-track-row .select-input { flex: 1; min-width: 0; }
.roster-meta { display: flex; align-items: center; gap: 8px; }
.room-grid .roster-list { flex: 1; min-height: 120px; overflow-y: auto; }
.lobby-ready-actions { display: flex; flex-direction: column; gap: 6px; }
.lobby-ready-actions .btn-ready { width: 100%; padding: 14px; font-size: 20px; }
.ready-hint { text-align: center; margin: 0; }

/* Toast */
.ui-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 60;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 18px;
  background: #111114;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent-yellow);
  color: var(--color-text-main);
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.03em;
  transition: opacity 0.2s, transform 0.2s;
}
.ui-toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .start-view,
  .room-view { grid-template-columns: 1fr; }
  .start-driver,
  .room-track { border-right: none; border-bottom: 1px solid var(--line); }
  .lobby-header { flex-wrap: wrap; gap: 10px; }
  .room-bar { order: 3; width: 100%; }
  .brand-subtitle { display: none; }
}
.start-driver .color-palette { grid-template-columns: repeat(auto-fill, 30px); gap: 8px; }
.start-driver .color-swatch-btn { width: 30px; height: 30px; }

/* ==========================================================================
   16. Finish card (HUD) and results screen
   ========================================================================== */
.hud-finish-card {
  position: absolute;
  top: 92px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: stretch;
  min-width: 320px;
  background: rgba(10, 10, 12, 0.92);
  border: 1px solid var(--line-strong);
  border-top: 3px solid var(--accent-red);
  pointer-events: none;
  font-family: var(--font-display);
}
.hud-finish-card.is-winner { border-top-color: var(--accent-yellow); }
.hud-finish-card.animate { animation: finish-in 0.55s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes finish-in {
  from { opacity: 0; transform: translate(-50%, -18px) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
.finish-flag {
  width: 30px;
  flex: none;
  background: repeating-conic-gradient(#eceae5 0 25%, #111 0 50%) 0 0 / 15px 15px;
  animation: flag-wave 0.9s linear infinite;
}
@keyframes flag-wave { to { background-position: 0 30px; } }
.finish-main { display: flex; flex-direction: column; justify-content: center; padding: 8px 16px; border-right: 1px solid var(--line); }
.finish-kicker { font-size: 13px; font-weight: 700; letter-spacing: 0.16em; color: var(--accent-red); }
.is-winner .finish-kicker { color: var(--accent-yellow); }
.finish-pos { font-size: 44px; font-weight: 900; font-style: italic; line-height: 1; }
.finish-info { display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 8px 16px; }
.finish-info strong { font-size: 26px; font-style: italic; letter-spacing: 0.02em; }
.finish-info span { font-size: 14px; color: var(--color-text-muted); letter-spacing: 0.03em; }
.finish-sub { color: var(--accent-green) !important; }

/* Results dialog: the cool-down lap stays visible behind it */
.results-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-top: 3px solid var(--accent-red);
  background: rgba(16, 16, 19, 0.96);
  color: var(--color-text-main);
  overflow: hidden;
}
.results-dialog[open] { animation: results-in 0.5s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes results-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.results-dialog::backdrop { background: linear-gradient(180deg, rgba(5, 5, 6, 0.15), rgba(5, 5, 6, 0.55)); }
.results { display: flex; flex-direction: column; max-height: calc(100vh - 44px); }
.results-head { display: flex; align-items: center; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.results-flag { width: 42px; height: 42px; flex: none; background: repeating-conic-gradient(#eceae5 0 25%, #111 0 50%) 0 0 / 14px 14px; transform: skewX(-10deg); }
.results-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.results-kicker { font-family: var(--font-display); font-size: 13px; font-weight: 700; letter-spacing: 0.16em; color: var(--accent-red); }
.results-title h2 { font-family: var(--font-display); font-size: 30px; font-weight: 900; font-style: italic; line-height: 1.05; margin: 0; }
.results-meta { font-size: 13px; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results-me { display: flex; align-items: baseline; gap: 6px; font-family: var(--font-display); }
.results-me-label { font-size: 13px; letter-spacing: 0.08em; color: var(--color-text-muted); }
.results-me strong { font-size: 40px; font-weight: 900; font-style: italic; line-height: 1; }
.results-me.is-winner strong { color: var(--accent-yellow); }
.results-me span:last-child { color: var(--color-text-muted); font-size: 18px; }

.results-podium { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 10px; padding: 18px 28px 0; border-bottom: 1px solid var(--line); }
.podium-step { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; animation: step-up 0.6s cubic-bezier(0.16, 1, 0.3, 1) both; animation-delay: calc(0.25s + var(--i) * 0.18s); }
@keyframes step-up { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }
.podium-car { width: 18px; height: 30px; background: var(--car); clip-path: polygon(50% 0, 100% 85%, 82% 100%, 18% 100%, 0 85%); }
.podium-name { font-family: var(--font-display); font-size: 18px; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-name em { font-style: normal; font-size: 12px; margin-left: 6px; padding: 0 5px; background: var(--accent-yellow); color: #111; }
.podium-time { font-family: var(--font-display); font-style: italic; font-size: 15px; color: var(--color-text-muted); }
.podium-block { width: 100%; display: flex; justify-content: center; align-items: flex-start; padding-top: 6px; background: #1c1c21; border: 1px solid var(--line-strong); border-bottom: none; }
.podium-block span { font-family: var(--font-display); font-size: 30px; font-weight: 900; font-style: italic; color: var(--color-text-muted); }
.place-1 .podium-block { height: 86px; background: linear-gradient(180deg, rgba(255, 207, 26, 0.18), #1c1c21); border-color: var(--accent-yellow); }
.place-1 .podium-block span { color: var(--accent-yellow); font-size: 40px; }
.place-2 .podium-block { height: 62px; }
.place-3 .podium-block { height: 46px; }
.podium-step.is-empty { visibility: hidden; }

.results-table-head,
.result-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) 118px 96px; align-items: center; gap: 10px; padding: 0 20px; }
.results-table-head { padding-top: 10px; padding-bottom: 6px; font-family: var(--font-display); font-size: 12px; letter-spacing: 0.1em; color: var(--color-text-dim); }
.results-table { overflow-y: auto; min-height: 0; }
.result-row {
  min-height: 44px;
  border-top: 1px solid var(--line);
  border-left: 3px solid transparent;
  animation: row-in 0.45s ease both;
  animation-delay: calc(0.6s + var(--i) * 0.06s);
}
@keyframes row-in { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
.result-row.is-me { background: rgba(255, 207, 26, 0.07); border-left-color: var(--accent-yellow); }
.result-row.is-dnf { color: var(--color-text-muted); }
.result-pos { font-family: var(--font-display); font-size: 22px; font-weight: 900; font-style: italic; text-align: center; }
.result-driver { display: flex; align-items: center; gap: 8px; min-width: 0; }
.result-color { width: 4px; height: 20px; flex: none; }
.result-name { font-family: var(--font-display); font-size: 18px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-tag { font-family: var(--font-display); font-size: 12px; padding: 0 5px; border: 1px solid var(--line-strong); color: var(--color-text-muted); flex: none; }
.result-tag.is-me { background: var(--accent-yellow); border-color: var(--accent-yellow); color: #111; }
.result-time,
.result-best { display: flex; flex-direction: column; font-family: var(--font-display); line-height: 1.1; }
.result-time strong { font-size: 18px; font-style: italic; }
.result-time small,
.result-best small { font-size: 11px; color: var(--color-text-dim); letter-spacing: 0.04em; }
.result-best { font-size: 16px; color: var(--color-text-muted); }
.result-best.is-fastest { color: #c77dff; }
.result-best.is-fastest small { color: #c77dff; }
.results-actions { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.results-actions .btn { min-width: 130px; }
.results-hint { margin-left: auto; font-family: var(--font-display); font-size: 12px; color: var(--color-text-dim); }

@media (max-width: 600px) {
  .hud-finish-card { min-width: 0; width: calc(100vw - 32px); top: 70px; }
  .finish-pos { font-size: 34px; }
  .results-table-head,
  .result-row { grid-template-columns: 34px 1fr 96px; padding: 0 12px; }
  .results-table-head span:last-child,
  .result-best { display: none; }
  .results-podium { padding: 12px 12px 0; }
  .results-me strong { font-size: 30px; }
  .results-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .hud-finish-card.animate, .results-dialog[open], .podium-step, .result-row, .finish-flag { animation: none; }
}

/* ==========================================================================
   17. Instruments: rev lights, pedals, G-force ball
   ========================================================================== */
.hud-revs {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 3px;
  margin-top: 8px;
  padding: 4px 5px;
  background: #050506;
  border-radius: 3px;
}
.hud-revs .led {
  display: block;
  height: 7px;
  border-radius: 50%;
  background: #1c1c21;
  transition: background-color 0.05s linear, box-shadow 0.05s linear;
}
.hud-revs .led-g.on { background: #2ecc71; box-shadow: 0 0 6px rgba(46, 204, 113, 0.8); }
.hud-revs .led-r.on { background: #ff2a1a; box-shadow: 0 0 6px rgba(255, 42, 26, 0.8); }
.hud-revs .led-b.on { background: #3d7bff; box-shadow: 0 0 7px rgba(61, 123, 255, 0.9); }
.hud-revs.shift .led { background: #3d7bff; box-shadow: 0 0 8px rgba(61, 123, 255, 0.95); animation: rev-flash 0.12s steps(2) infinite; }
@keyframes rev-flash { 50% { opacity: 0.25; } }

.hud-telemetry {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.hud-pedals { display: flex; gap: 4px; height: 38px; }
.hud-pedal {
  position: relative;
  width: 8px;
  height: 100%;
  background: #1c1c21;
  border-radius: 2px;
  overflow: hidden;
}
.hud-pedal span {
  position: absolute;
  inset: 0;
  transform-origin: bottom;
  transform: scaleY(0);
  background: #2ecc71;
}
.hud-pedal-brake span { background: var(--accent-red); }

.hud-gball {
  position: relative;
  justify-self: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background:
    linear-gradient(#2a2a30, #2a2a30) center / 1px 100% no-repeat,
    linear-gradient(#2a2a30, #2a2a30) center / 100% 1px no-repeat,
    #101013;
  border: 1px solid var(--line-strong, #3b3b42);
}
.hud-gball-ring {
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  border: 1px dashed #34343b;
}
.hud-gdot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--accent-yellow, #ffcf1a);
  box-shadow: 0 0 6px rgba(255, 207, 26, 0.7);
}
.hud-gread {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
}
.hud-gread small { font-size: 11px; margin-left: 2px; color: var(--color-text-muted); font-style: normal; }

@media (max-width: 720px) {
  .hud-telemetry { display: none; }
  .hud-revs .led { height: 5px; }
}

/* ==========================================================================
   18. F1 start gantry, controls tutorial, gamepad focus
   ========================================================================== */
.countdown-overlay { justify-content: flex-start; padding-top: 9vh; background: transparent; backdrop-filter: none; }
.countdown-overlay:not(.is-go) .countdown-number { display: none; }
.countdown-overlay.is-go .countdown-number {
  display: block;
  font-size: clamp(56px, 10vw, 110px);
  color: #fff;
  letter-spacing: 0.04em;
  animation: go-out 0.9s ease-out forwards;
}
@keyframes go-out {
  0% { opacity: 0; transform: scale(0.7); }
  15% { opacity: 1; transform: scale(1.05); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.15); }
}
.start-gantry {
  position: relative;
  padding: 10px 16px 12px;
  background: linear-gradient(#18181c, #0b0b0d);
  border: 1px solid #2c2c33;
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6);
}
.start-gantry::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -9vh;
  width: 60%;
  height: 9vh;
  transform: translateX(-50%);
  border-left: 6px solid #1b1b1f;
  border-right: 6px solid #1b1b1f;
}
.start-gantry .start-lights {
  display: flex;
  gap: 12px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
.light-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: #050506;
  border-radius: 6px;
  border: 1px solid #222228;
}
.light-col .start-light {
  width: clamp(26px, 4vw, 40px);
  height: clamp(26px, 4vw, 40px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #2b1416, #160a0b 70%);
  border: 2px solid #2a1517;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
  transition: background 0.05s linear, box-shadow 0.05s linear;
}
.light-col.on .start-light {
  background: radial-gradient(circle at 35% 35%, #ff9a8f, #ff1a0a 45%, #b30000 100%);
  border-color: #ff4a3a;
  box-shadow: 0 0 22px rgba(255, 30, 10, 0.9), 0 0 50px rgba(255, 30, 10, 0.35);
}
/* Lights out: nothing lit (the old green "GO" state is gone, as in F1). */
.start-lights.go .start-light { background: radial-gradient(circle at 35% 35%, #2b1416, #160a0b 70%); box-shadow: none; }

/* Tutorial */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at top, rgba(225, 6, 0, 0.18), transparent 60%), rgba(6, 6, 8, 0.92);
  overflow-y: auto;
}
.tutorial-card {
  width: min(860px, 100%);
  background: #121215;
  border: 1px solid var(--line, #2a2a30);
  border-top: 3px solid var(--accent-red);
  border-radius: 10px;
  padding: 22px 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: tutorial-in 0.35s ease-out;
}
@keyframes tutorial-in { from { opacity: 0; transform: translateY(12px); } }
.tutorial-head { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.tutorial-title { font-family: var(--font-display); font-size: 28px; font-weight: 800; font-style: italic; margin: 0; }
.tutorial-sub { margin: 2px 0 0; color: var(--color-text-muted); font-size: 14px; }
.tutorial-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tutorial-col { background: #0c0c0e; border: 1px solid var(--line, #2a2a30); border-radius: 8px; padding: 14px 16px; }
.tutorial-col-title { margin: 0 0 10px; font-size: 13px; letter-spacing: 0.12em; color: var(--accent-yellow, #ffcf1a); }
.keymap { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; align-items: center; }
.keymap dt { display: flex; gap: 4px; flex-wrap: wrap; }
.keymap dd { margin: 0; color: var(--color-text-main); font-size: 14px; }
.tutorial-card kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  font: 700 13px var(--font-sans);
  color: #fff;
  background: linear-gradient(#2c2c33, #1d1d22);
  border: 1px solid #3b3b42;
  border-bottom-width: 3px;
  border-radius: 6px;
}
.tutorial-card kbd.pad { background: linear-gradient(#24303a, #182028); border-color: #2f4250; }
.tutorial-card kbd.pad.round { border-radius: 50%; width: 28px; padding: 0; }
.tutorial-tip { margin: 12px 0 0; color: var(--color-text-muted); font-size: 13px; }
.pad-tester { margin-top: 14px; padding: 12px 16px; background: #0c0c0e; border: 1px dashed #34343b; border-radius: 8px; }
.pad-tester-status { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; }
.pad-tester-bars { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin-top: 10px; align-items: center; }
.pt-steer { position: relative; height: 10px; background: #1c1c21; border-radius: 5px; }
.pt-steer::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: #3b3b42; }
.pt-steer span { position: absolute; left: calc(50% - 7px); top: -2px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent-yellow, #ffcf1a); transition: transform 0.05s linear; }
.pt-pedal { position: relative; height: 10px; background: #1c1c21; border-radius: 5px; overflow: hidden; }
.pt-pedal span { position: absolute; inset: 0; transform-origin: left; transform: scaleX(0); background: #2ecc71; }
.pt-pedal.brake span { background: var(--accent-red); }
.pt-pedal em { position: absolute; right: 4px; top: -16px; font-size: 11px; font-style: normal; color: var(--color-text-muted); }
.pad-tester-bars .pt-pedal { margin-top: 12px; overflow: visible; }
.pad-tester-help { margin: 10px 0 0; font-size: 12px; color: var(--color-text-dim, #66645f); line-height: 1.5; }
.tutorial-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.tutorial-skip { display: flex; gap: 6px; align-items: center; color: var(--color-text-muted); font-size: 13px; cursor: pointer; }
.pad-hint { display: none; margin-left: 6px; opacity: 0.8; }
body.has-gamepad .pad-hint { display: inline; }
.status-dot.connected { background: #2ecc71; box-shadow: 0 0 8px rgba(46, 204, 113, 0.7); }
.link-button { background: none; border: none; padding: 0; color: var(--color-text-muted); text-decoration: underline; cursor: pointer; font: inherit; }
.link-button:hover { color: #fff; }

/* Gamepad focus: a clear ring so you always see where A will press. */
body.pad-nav :focus {
  outline: 3px solid var(--accent-yellow, #ffcf1a) !important;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(255, 207, 26, 0.18) !important;
}

@media (max-width: 720px) {
  .tutorial-grid { grid-template-columns: 1fr; }
  .tutorial-card { padding: 16px; }
  .pad-tester-bars { grid-template-columns: 1fr; }
}

/* ==========================================================================
   19. Simpler HUD and results
   ========================================================================== */
.hud-lap-grid { grid-template-columns: repeat(3, 1fr); }
.results-dialog { width: min(520px, calc(100vw - 32px)); }
.results-title h2.is-winner { color: var(--accent-yellow); }
.result-row { grid-template-columns: 40px minmax(0, 1fr) auto; min-height: 40px; animation-delay: calc(0.25s + var(--i) * 0.05s); }
.result-row.place-1 .result-pos { color: var(--accent-yellow); }
.result-row.place-2 .result-pos { color: #d8d8de; }
.result-row.place-3 .result-pos { color: #d28b4b; }
.result-time { font-family: var(--font-display); font-size: 18px; font-style: italic; text-align: right; }
.result-fastest { color: #c77dff; font-size: 14px; flex: none; }
.results-actions .btn { flex: 1; }

.hud-reset-hint {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(12, 12, 14, 0.88);
  border: 1px solid var(--accent-yellow, #ffcf1a);
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  pointer-events: none;
  animation: reset-pulse 1.4s ease-in-out infinite;
}
.hud-reset-hint kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; padding: 0 6px;
  font: 700 13px var(--font-sans); color: #111;
  background: var(--accent-yellow, #ffcf1a); border-radius: 5px;
}
.hud-reset-hint kbd.round { border-radius: 50%; }
.hud-reset-hint .pad-only { display: none; }
body.has-gamepad .hud-reset-hint .pad-only { display: inline-flex; }
@keyframes reset-pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 207, 26, 0.15); } }
.hud-lap-grid .hud-metric-value { white-space: nowrap; font-size: 17px; }

/* ==========================================================================
   20. Driving guide cue, podium
   ========================================================================== */
.form-hint-inline { font-weight: 400; color: var(--color-text-dim, #66645f); font-size: 12px; }
.driver-assists .select-input { width: 100%; margin-top: 4px; }

.hud-brake-cue {
  position: absolute;
  left: 50%;
  top: 92px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 18px 6px 12px;
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.08em;
  color: #fff;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.hud-brake-cue.is-brake { background: #e10600; animation: cue-flash 0.32s steps(2) infinite; }
.hud-brake-cue.is-lift { background: #e0a400; color: #111; }
.cue-bars { display: flex; gap: 3px; }
.cue-bars i { width: 6px; height: 20px; background: currentColor; transform: skewX(-18deg); opacity: 0.9; }
.hud-brake-cue.is-lift .cue-bars i:nth-child(3) { opacity: 0.25; }
@keyframes cue-flash { 50% { filter: brightness(1.35); } }

/* Podium */
.podium-stage {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 8px;
  padding: 18px 24px 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 50% 70% at 50% 0%, rgba(255, 255, 255, 0.10), transparent 70%),
    radial-gradient(ellipse 30% 60% at 18% 0%, rgba(255, 255, 255, 0.05), transparent 70%),
    radial-gradient(ellipse 30% 60% at 82% 0%, rgba(255, 255, 255, 0.05), transparent 70%),
    linear-gradient(#141418, #0d0d10);
  border-bottom: 1px solid var(--line);
}
.podium-spot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  animation: podium-rise 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(var(--d) * 1s);
}
@keyframes podium-rise { from { opacity: 0; transform: translateY(40px); } }
.podium-car-canvas { width: 54px; height: 72px; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.5)); }
.podium-name {
  max-width: 100%;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.podium-name em { font-style: normal; font-size: 11px; margin-left: 5px; padding: 0 5px; background: var(--accent-yellow); color: #111; border-radius: 3px; }
.podium-gap { font-family: var(--font-display); font-style: italic; font-size: 13px; color: var(--color-text-muted); margin-bottom: 6px; }
.podium-block {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-top: 8px;
  background: linear-gradient(180deg, #2a2a31, #18181c);
  border: 1px solid #3b3b42;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.podium-block span { font-family: var(--font-display); font-size: 34px; font-weight: 900; font-style: italic; color: #8d8d96; }
.place-1 .podium-block { height: 92px; background: linear-gradient(180deg, #5a4808, #221d08 70%); border-color: #ffcf1a; }
.place-1 .podium-block span { color: #ffcf1a; font-size: 46px; text-shadow: 0 0 18px rgba(255, 207, 26, 0.5); }
.place-2 .podium-block { height: 64px; border-color: #c9c9d1; }
.place-2 .podium-block span { color: #d8d8de; }
.place-3 .podium-block { height: 46px; border-color: #b87333; }
.place-3 .podium-block span { color: #d28b4b; }
.podium-spot.is-me .podium-name { color: var(--accent-yellow); }
.podium-spot.is-empty { visibility: hidden; }
.podium-trophy {
  position: absolute;
  top: -6px;
  right: 10%;
  width: 22px;
  height: 26px;
  background:
    linear-gradient(#ffcf1a, #ffcf1a) 50% 100% / 14px 4px no-repeat,
    linear-gradient(#e0a400, #e0a400) 50% 82% / 4px 8px no-repeat,
    radial-gradient(circle at 50% 0, #ffe27a 0 9px, transparent 10px) 50% 0 / 22px 14px no-repeat;
  filter: drop-shadow(0 0 6px rgba(255, 207, 26, 0.6));
  animation: trophy-shine 2.4s ease-in-out infinite;
}
@keyframes trophy-shine { 50% { transform: translateY(-3px) rotate(-6deg); } }
.podium-confetti { position: absolute; inset: 0; pointer-events: none; }
.podium-confetti i {
  position: absolute;
  top: -12px;
  width: 6px;
  height: 10px;
  opacity: 0;
  animation: confetti-fall linear both;
}
@keyframes confetti-fall {
  0% { opacity: 1; transform: translateY(0) rotate(0); }
  100% { opacity: 0; transform: translateY(240px) rotate(540deg); }
}
@media (prefers-reduced-motion: reduce) {
  .podium-spot, .podium-trophy, .podium-confetti i, .hud-brake-cue.is-brake { animation: none; }
  .podium-confetti { display: none; }
}
@media (max-width: 600px) {
  .podium-stage { padding: 12px 10px 0; }
  .place-1 .podium-block { height: 70px; }
  .place-2 .podium-block { height: 50px; }
  .place-3 .podium-block { height: 36px; }
}

/* ==========================================================================
   21. Menus over the circuit flyover
   The menus float over a slow flyover of the real circuit. Panels are near-
   solid dark sheets with hairline edges — flat colour, no glow, no gradients
   on controls — so the scenery is the only decoration.
   ========================================================================== */
:root {
  --sheet: rgba(16, 16, 19, 0.93);
  --sheet-solid: #131316;
  --edge: rgba(255, 255, 255, 0.08);
  --edge-strong: rgba(255, 255, 255, 0.15);
  --radius-card: 6px;
  --radius-ctl: 4px;
}

/* Lobby: darken the flyover just enough for the sheet to read */
.lobby-overlay {
  background: rgba(8, 8, 10, 0.45);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.lobby-container {
  background: var(--sheet);
  border: 1px solid var(--edge);
  border-top: 3px solid var(--accent-red);
  border-radius: var(--radius-card);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.5);
  animation: sheet-in 0.3s ease-out;
}
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.lobby-header { border-bottom-color: var(--edge); }

/* Connection: silent while online, a plain red line when something is wrong */
.lobby-connection-status { color: #ff6b5e; }
.lobby-connection-status.is-quiet { visibility: hidden; }
.lobby-connection-status .status-dot { display: none; }

.start-driver,
.room-track { border-right-color: var(--edge); }

/* Inputs */
.text-input,
.select-input,
.hex-text-input {
  background: #0d0d10;
  border: 1px solid var(--edge-strong);
  border-radius: var(--radius-ctl);
}
.text-input:focus,
.select-input:focus { border-color: #eceae5; box-shadow: none; }

/* Buttons: flat */
.btn { border-radius: var(--radius-ctl); }
.btn-primary,
.btn-ready { background: var(--accent-red); box-shadow: none; }
.btn-primary:hover:not(:disabled),
.btn-ready:hover:not(:disabled) { background: #f51d10; box-shadow: none; }
.btn-secondary { background: transparent; border-color: var(--edge-strong); }
.btn-secondary:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); }

/* Driver card */
.car-preview-container,
.preview-badge-wrapper { border-radius: var(--radius-ctl); border-color: var(--edge); }
.car-preview-container { background: #0e0e11; }
.color-swatch-btn { border-radius: 3px; }
.color-swatch-btn.active { box-shadow: 0 0 0 2px #0c0c0e, 0 0 0 3px #eceae5; }

/* Mode tiles */
.mode-tile {
  border-radius: var(--radius-ctl);
  border: 1px solid var(--edge);
  border-left: 4px solid var(--edge-strong);
  background: #0f0f12;
  transition: background 0.12s, border-color 0.12s;
}
button.mode-tile:hover,
button.mode-tile:focus-visible { background: #18181c; border-left-color: var(--accent-red); }
.mode-tile.mode-primary { border-left-color: var(--accent-yellow); background: #121210; }
.mode-tile.mode-primary:hover,
.mode-tile.mode-primary:focus-visible { background: #1a1914; border-left-color: var(--accent-yellow); }

/* Where the flyover is: a small caption, bottom-left */
.menu-location {
  position: absolute;
  left: 26px;
  bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-width: min(400px, 38vw);
  color: #eceae5;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
.menu-location-kicker { display: none; }
#menu-location-name { font-family: var(--font-display); font-size: 20px; font-weight: 800; font-style: italic; }
#menu-location-note { font-size: 12.5px; color: rgba(236, 234, 229, 0.75); }
.lobby-overlay[data-view="room"] .menu-location { display: none; }
@media (max-width: 1100px), (max-height: 640px) { .menu-location { display: none; } }

/* Room: track card with the landscape preview */
.room-track .track-preview-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--edge);
  border-radius: var(--radius-ctl);
  background: #0e0e11;
}
.room-track .track-preview-canvas {
  display: block;
  width: 100%;
  height: 170px;
  background: #15171c;
}
.room-track .track-info { padding: 11px 14px 12px; gap: 2px; }
.room-track .track-name { font-family: var(--font-display); font-size: 25px; font-weight: 800; font-style: italic; line-height: 1.1; }
.track-scenery { font-size: 13px; color: var(--color-text-muted); }
.track-pb { font-size: 13px; color: var(--color-text-muted); }
.track-pb strong { font-family: var(--font-display); font-size: 16px; font-style: italic; color: var(--accent-yellow); margin-left: 4px; }

/* Dialogs */
.modal-dialog { border-radius: var(--radius-card); }

/* In-race HUD: a touch of rounding, flat colour */
.hud-panel-instruments,
.hud-panel-leaderboard { border-radius: 4px; overflow: hidden; }
.hud-center-banner,
.hud-net-badge,
.hud-icon-btn,
.ui-toast { border-radius: 4px; }

/* Brake cue: "get ready" is an outline, "brake" is solid red */
.hud-brake-cue.is-prep {
  background: rgba(12, 12, 14, 0.82);
  color: #ffcf1a;
  box-shadow: inset 0 0 0 2px #ffcf1a;
}
.hud-brake-cue.is-prep .cue-bars i:nth-child(n+2) { opacity: 0.2; }
.hud-brake-cue.is-brake { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .lobby-container { animation: none; }
}

/* Leave the race: asks once more before it really leaves */
.hud-quit-btn { width: auto; padding: 0 10px; font-size: 13px; }
.hud-quit-btn.is-confirm { background: #d81e1e; color: #fff; }

/* =====================================================================
   Phones & tablets (body.is-touch is set from JS on touch-first devices)
   ===================================================================== */
.hud-overlay.hud-hidden * { pointer-events: none !important; }
.touch-only, .touch-only-block { display: none; }
body.is-touch .touch-only { display: inline; }
body.is-touch .touch-only-block { display: block; }
body.is-touch .desk-only { display: none !important; }
body.is-touch .hud-reset-hint .key-only,
body.is-touch .hud-reset-hint .pad-only { display: none !important; }
body.is-touch .hud-reset-hint { pointer-events: auto; cursor: pointer; bottom: auto; top: 30%; }

html, body { overscroll-behavior: none; }
body.is-touch {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body.is-touch .game-canvas,
body.is-touch .hud-overlay { touch-action: none; }
body.is-touch input, body.is-touch textarea, body.is-touch select { -webkit-user-select: text; user-select: text; }

/* Old round buttons are replaced by a steering pad + pedals */
.touch-controls { display: none !important; }
body.is-touch .touch-controls {
  display: block !important;
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.touch-steer {
  /* The whole left half below the dashboard steers; the dial follows the thumb. */
  position: absolute;
  left: 0;
  top: 26%;
  bottom: 0;
  width: 50%;
  pointer-events: auto;
  touch-action: none;
}
.touch-steer-vis {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(80%, 260px);
  height: 100px;
  pointer-events: none;
}
.touch-steer.active .touch-steer-vis .touch-steer-label { opacity: 0; }
.touch-steer-rail {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 38px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.22);
}
.touch-steer-rail::after {
  content: '';
  position: absolute;
  left: 50%;
  top: -6px;
  width: 2px;
  height: 16px;
  margin-left: -1px;
  background: rgba(255, 255, 255, 0.4);
}
.touch-steer-knob {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: 44px;
  height: 44px;
  margin-left: -22px;
  border-radius: 50%;
  background: rgba(10, 10, 12, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.65);
  will-change: transform;
}
.touch-steer.active .touch-steer-knob { background: #d81e1e; border-color: #fff; }
.touch-steer-label {
  position: absolute;
  left: 20px;
  bottom: 66px;
  font-style: normal;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  transition: opacity 0.3s;
}
.touch-steer.used .slide-label { opacity: 0; }
.tilt-label { display: none; }
body.steer-tilt .slide-label { display: none; }
body.steer-tilt .tilt-label { display: inline; }
/* Auto-throttle: the throttle pedal is not needed. */
body.is-touch.auto-gas .touch-gas { display: none; }
body.is-touch.auto-gas .touch-brake { width: 110px; height: min(150px, 40vh); }
/* Buttons that sit over the steering half stay tappable. */
body.is-touch .hud-chat, body.is-touch .hud-reset-hint { z-index: 6; }
body.is-touch .touch-controls { z-index: 2; }
.touch-pedals {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  align-items: flex-end;
  pointer-events: none;
}
body.is-touch .touch-btn {
  pointer-events: auto;
  touch-action: none;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(10, 10, 12, 0.62);
  color: #fff;
  font-family: var(--font-body, sans-serif);
  font-size: 15px;
  font-weight: 700;
}
body.is-touch .touch-brake { width: 82px; height: 92px; }
body.is-touch .touch-gas { width: 94px; height: min(150px, 40vh); }
body.is-touch .touch-btn.pressed { border-color: #fff; }
body.is-touch .touch-gas.pressed { background: #23864a; }
body.is-touch .touch-brake.pressed { background: #d81e1e; }

/* Compact dashboard; buttons and minimap move to the top right */
body.is-touch .hud-overlay {
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left));
}
body.is-touch .hud-panel-instruments { transform: scale(0.74); transform-origin: top left; }
body.is-touch .hud-telemetry,
body.is-touch .hud-revs,
body.is-touch .hud-panel-leaderboard { display: none; }
body.is-touch .hud-bottom-right {
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  bottom: auto;
}
body.is-touch .hud-controls-hint { display: none; }
@media (max-height: 430px) {
  body.is-touch .hud-panel-instruments { transform: scale(0.62); }
  body.is-touch .hud-instrument-divider,
  body.is-touch .hud-split-container { display: none !important; }
}

/* Lobby / dialogs on small screens: scroll instead of overflowing */
body.is-touch .tutorial-overlay { overflow-y: auto; -webkit-overflow-scrolling: touch; }
body.is-touch .lobby-overlay { overflow-y: auto; -webkit-overflow-scrolling: touch; }
/* Tall cards in short windows: centred when they fit, scrollable from the top when not */
.tutorial-overlay { align-items: flex-start; }
.tutorial-card { margin: auto; }
body.is-touch .tutorial-grid { grid-template-columns: 1fr; }
body.is-touch .tutorial-card { padding: 16px 18px; }

/* ================================================================== */
/* Sector times, DRS, weather, spectating, chat, replay, settings      */
/* ================================================================== */

.hud-sectors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; }
.hud-sector {
  display: flex; flex-direction: column; align-items: center; padding: 3px 4px;
  background: rgba(255, 255, 255, 0.04); border-bottom: 3px solid var(--line-strong);
  font-family: var(--font-mono); line-height: 1.1;
}
.hud-sector em { font-style: normal; font-size: 10px; color: var(--color-text-dim); letter-spacing: 0.08em; }
.hud-sector b { font-size: 15px; font-weight: 700; color: var(--color-text-muted); }
.hud-sector.is-purple { border-color: #a96bff; background: rgba(169, 107, 255, 0.16); }
.hud-sector.is-purple b { color: #d2b4ff; }
.hud-sector.is-green { border-color: #2ecc71; background: rgba(46, 204, 113, 0.14); }
.hud-sector.is-green b { color: #8ff0b6; }
.hud-sector.is-yellow { border-color: #ffcf1a; background: rgba(255, 207, 26, 0.1); }
.hud-sector.is-yellow b { color: #ffe27a; }

.hud-flags-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.hud-flags-row:empty { display: none; }
.hud-drs, .hud-session-label, .hud-weather {
  font-family: var(--font-display); font-weight: 800; font-size: 14px; letter-spacing: 0.06em;
  padding: 2px 8px; border: 1px solid var(--line-strong); color: var(--color-text-muted);
}
.hud-drs.is-off { opacity: 0.55; }
.hud-drs.is-ready { color: #0c0c0e; background: #2ecc71; border-color: #2ecc71; animation: drs-blink 0.6s steps(2) infinite; }
.hud-drs.is-open { color: #0c0c0e; background: #8ff0b6; border-color: #fff; }
@keyframes drs-blink { 50% { background: #1e8a4c; } }
.hud-session-label { color: #0c0c0e; background: var(--accent-yellow); border-color: var(--accent-yellow); }
.hud-weather { color: #bfe3ff; border-color: #3a6d96; background: rgba(40, 90, 140, 0.3); }

.touch-drs { display: none; }
body.is-touch .touch-drs:not(.hidden) { display: block; width: 74px; height: 64px; background: rgba(30, 138, 76, 0.75); }
body.is-touch .touch-drs.pressed { background: #2ecc71; color: #0c0c0e; }

.hud-spectating {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; pointer-events: auto;
}
.spec-kicker { font-family: var(--font-display); font-weight: 800; color: var(--accent-yellow); letter-spacing: 0.06em; }
.spec-name { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.spec-name i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.spec-hint { font-size: 12px; color: var(--color-text-muted); display: flex; gap: 6px; align-items: center; }
.spec-btn { width: 34px; height: 30px; font-size: 18px; color: #fff; background: rgba(255,255,255,0.08); border: 1px solid var(--line-strong); border-radius: 3px; }
body.is-touch .spec-btn { display: inline-block; }
body:not(.is-touch) .spec-btn { display: none; }
body.is-spectating .touch-pedals, body.is-spectating .touch-steer { display: none; }

.chat-feed {
  position: absolute; left: 20px; bottom: 210px; display: flex; flex-direction: column; gap: 4px;
  pointer-events: none; max-width: 320px;
}
body.is-touch .chat-feed { left: 50%; transform: translateX(-50%); bottom: auto; top: 64px; align-items: center; }
.chat-line {
  display: flex; align-items: center; gap: 6px; padding: 4px 10px; font-size: 13px;
  background: rgba(12, 12, 14, 0.82); border-left: 3px solid var(--line-strong); transition: opacity 0.8s;
}
.chat-line.is-me { border-left-color: var(--accent-yellow); }
.chat-line.fade { opacity: 0; }
.chat-line i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chat-line b { font-weight: 700; color: var(--color-text-muted); white-space: nowrap; }
.hud-chat { position: absolute; right: 20px; bottom: 70px; pointer-events: auto; }
body.is-touch .hud-chat { right: auto; left: max(10px, env(safe-area-inset-left)); bottom: auto; top: 50%; }
.chat-menu {
  position: absolute; right: 0; bottom: 46px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 6px; width: 280px;
}
body.is-touch .chat-menu { right: auto; left: 0; bottom: auto; top: 46px; }
.chat-menu.hidden { display: none; }
.chat-menu-item {
  display: flex; align-items: center; gap: 6px; padding: 7px 8px; font: inherit; font-size: 13px; text-align: left;
  color: var(--color-text-main); background: #17171b; border: 1px solid var(--line); border-radius: 3px; cursor: pointer;
}
.chat-menu-item:hover { background: #222228; border-color: var(--line-strong); }
.chat-menu-item kbd { font-size: 10px; padding: 0 4px; border: 1px solid var(--line-strong); color: var(--color-text-muted); }

.room-chat { margin: 12px 0 4px; }
.room-chat-feed { display: flex; flex-direction: column; gap: 3px; max-height: 110px; overflow-y: auto; margin-bottom: 6px; }
.room-chat-feed:empty { display: none; }
.room-chat-buttons { display: flex; flex-wrap: wrap; gap: 4px; }
.chat-chip { padding: 4px 9px; font-size: 12px; }

/* Qualifying results */
.quali-results {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 40;
  width: min(420px, 92vw); padding: 16px 18px;
}
.quali-title { font-family: var(--font-display); font-size: 20px; font-weight: 800; margin: 0 0 10px; color: var(--accent-yellow); }
.quali-list, .champ-table, .champ-calendar { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.quali-list li, .champ-table li, .champ-calendar li {
  display: grid; grid-template-columns: 28px 10px 1fr auto; align-items: center; gap: 8px;
  padding: 5px 8px; background: #141417; border-left: 3px solid transparent; font-size: 14px;
}
.quali-list li.is-me, .champ-table li.is-me { border-left-color: var(--accent-yellow); background: #1c1b14; }
.quali-list i, .champ-table i { width: 10px; height: 10px; border-radius: 50%; }
.q-pos, .c-pos { font-family: var(--font-display); font-weight: 800; color: var(--color-text-muted); }
.q-time, .c-pts { font-family: var(--font-mono); font-weight: 700; }
.champ-calendar li { grid-template-columns: 40px 1fr auto auto; font-size: 13px; }
.champ-calendar li.is-done { opacity: 0.6; }
.champ-calendar li.is-next { border-left-color: var(--accent-red); background: #1c1416; }
.cal-round { font-family: var(--font-display); font-weight: 800; color: var(--color-text-dim); }
.cal-date { color: var(--color-text-dim); font-size: 12px; }
.cal-res { font-family: var(--font-mono); color: var(--accent-yellow); min-width: 64px; text-align: right; }
#champ-dialog .modal-body { max-height: 70vh; overflow-y: auto; }

/* Results additions */
.results-champ { padding: 10px 20px 0; }
.results-champ-title { font-family: var(--font-display); font-size: 18px; font-weight: 800; margin: 0 0 8px; color: var(--accent-yellow); }
.results-champ .champ-table { max-height: 220px; overflow-y: auto; }
.result-penalty { margin-left: 6px; font-size: 12px; font-weight: 700; color: #ff7a6b; }
.car-num { font-family: var(--font-display); font-weight: 800; color: var(--accent-yellow); }

/* Replay bar */
.replay-bar {
  position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; flex-wrap: wrap; justify-content: center;
  width: min(860px, 96vw);
}
.replay-live { font-family: var(--font-display); font-weight: 800; color: #0c0c0e; background: var(--accent-red); padding: 2px 8px; letter-spacing: 0.08em; }
.replay-car { display: inline-flex; align-items: center; gap: 6px; min-width: 110px; font-weight: 700; }
.replay-car i { width: 10px; height: 10px; border-radius: 50%; }
.replay-scrub { flex: 1; min-width: 120px; accent-color: var(--accent-yellow); }
.replay-time { font-family: var(--font-mono); font-size: 14px; color: var(--color-text-muted); min-width: 86px; text-align: right; }
body.is-replay .hud-overlay { display: none; }

/* Start screen additions */
.mode-tile.mode-champ { padding: 0; border-left-color: var(--accent-red); }
.mode-tile-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; padding: 14px 16px 6px;
  font: inherit; color: inherit; text-align: left; background: none; border: 0; cursor: pointer;
}
.mode-tile-btn:hover, .mode-tile-btn:focus-visible { background: #18181c; outline: none; }
.mode-champ .mode-title { color: #ff5a4f; }
.champ-actions { display: flex; gap: 14px; padding: 0 16px 10px; }
.champ-actions .hidden { display: none; }
.livery-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.select-sm { padding: 4px 8px; font-size: 13px; width: auto; min-width: 0; }
.number-input { width: 64px; padding: 4px 8px; }
.lang-select { margin-left: auto; }

/* Settings dialog */
.settings-dialog { width: min(620px, 94vw); }
.settings-body { display: flex; flex-direction: column; gap: 18px; max-height: 70vh; overflow-y: auto; }
.settings-section-title { font-family: var(--font-display); font-size: 17px; font-weight: 800; margin: 0 0 8px; letter-spacing: 0.03em; }
.keybind-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin-bottom: 8px; }
.keybind-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.keybind-btn { min-width: 96px; }
.keybind-btn.is-listening { border-color: var(--accent-yellow); color: var(--accent-yellow); }
.range-input { width: 100%; accent-color: var(--accent-yellow); }
.settings-body output { font-family: var(--font-mono); color: var(--accent-yellow); margin-left: 6px; }
@media (max-width: 560px) { .keybind-list { grid-template-columns: 1fr; } }
/* Landscape notes are only written in Chinese. */
html:not([lang="zh-Hant"]) .track-scenery,
html:not([lang="zh-Hant"]) #menu-location-note { display: none; }
body.is-spectating .hud-panel-instruments { display: none; }

/* Narrow phones: keep the "自訂" colour label on one line. */
.custom-picker-label { white-space: nowrap; flex-shrink: 0; }

/* Settings: touch-only options and the steering mode buttons */
.seg-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
body:not(.is-touch) .touch-setting { display: none; }
#settings-dialog:not(.tilt-on) .tilt-only { display: none; }

/* Gap to the car ahead / behind under the position (shown when the full standings are hidden) */
.hud-gaps { display: none; }
body.is-touch .hud-gaps:not(.hidden) {
  display: flex; flex-direction: column; gap: 1px; margin-top: 2px;
  font-family: var(--font-mono); font-size: 12px; font-weight: 700; line-height: 1.2;
}
#hud-gap-ahead { color: #ffd23f; }
#hud-gap-behind { color: #9fd8ff; }
.hud-leaderboard-table td.col-best { text-align: right; font-variant-numeric: tabular-nums; }
.hud-leaderboard-table th.col-best { text-align: right; }

/* World records and the daily challenge */
.rec-table { list-style: none; margin: 8px 0 12px; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.rec-table li { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; padding: 5px 8px; background: #141417; border-left: 3px solid transparent; font-size: 14px; }
.rec-table li.is-me { border-left-color: var(--accent-yellow); background: #1c1b14; }
.rec-table .rec-pos { font-family: var(--font-mono); color: var(--color-text-dim); }
.rec-table .rec-time { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.rec-table li.rec-empty { display: block; color: var(--color-text-dim); }
#records-dialog .modal-body { max-height: 72vh; overflow-y: auto; }
.mode-tile.mode-daily { border-left-color: #f5c400; }
.mode-daily .mode-title { color: #ffd23f; }

/* Add to home screen / install hint (start screen) */
.install-hint { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-top: 4px; background: #16202a; border-left: 3px solid #3ad7ff; font-size: 13px; color: var(--color-text-main); }
.install-hint.hidden { display: none; }
.install-hint #install-hint-text { flex: 1; }
.install-hint .link-button { font-size: 18px; line-height: 1; }

.rating-tag { display: block; font-size: 12px; font-family: var(--font-mono); color: #ffd23f; margin-top: 2px; }

/* Tyre wear gauge and pit stop */
.hud-tyres { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 11px; font-weight: 700; color: var(--color-text-main); }
.hud-tyres.hidden { display: none; }
.hud-tyres-bar { width: 56px; height: 6px; background: rgba(255,255,255,0.12); border-radius: 3px; overflow: hidden; }
.hud-tyres-bar i { display: block; height: 100%; width: 100%; background: #2ecc71; }
.hud-tyres.is-pit { color: #ffd23f; }
body.is-touch .touch-pit:not(.hidden) { display: block; width: 74px; height: 52px; background: rgba(20, 60, 120, 0.75); }
body.is-touch .touch-pit.pressed { background: #ffd23f; color: #111; }
.touch-pit.hidden { display: none; }

/* ==================================================================== */
/* UI polish (2026-11): phone layouts, mode tiles, HUD fixes             */
/* ==================================================================== */

/* Mode tiles: a chevron that slides on hover, tighter rhythm */
button.mode-tile,
.mode-tile-btn { position: relative; padding-right: 40px; }
button.mode-tile::after,
.mode-tile-btn::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 9px;
  height: 9px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: translateY(-50%) rotate(45deg);
  opacity: 0.35;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}
button.mode-tile:hover::after,
button.mode-tile:focus-visible::after,
.mode-tile-btn:hover::after,
.mode-tile-btn:focus-visible::after { opacity: 0.9; transform: translate(4px, -50%) rotate(45deg); }
.mode-primary::after { color: var(--accent-yellow); }
button.mode-tile:active,
.mode-tile-btn:active { transform: scale(0.99); }
.start-modes { gap: 10px; }

/* Standings: keep the short column headings on one line */
.hud-panel-leaderboard th { white-space: nowrap; }

/* Pit button: quieter than DRS / brake, yellow when a stop is on */
body.is-touch .touch-pit:not(.hidden) {
  width: 64px;
  height: 44px;
  font-size: 14px;
  background: rgba(12, 12, 14, 0.7);
  border: 1px solid rgba(255, 210, 63, 0.6);
  color: #ffd23f;
}
body.is-touch .touch-pit.pressed { background: #ffd23f; color: #111; border-color: #ffd23f; }

/* Narrow screens (portrait phones, small tablets): play first, car second */
@media (max-width: 820px) {
  .start-modes { order: -1; border-bottom: 1px solid var(--line); }
  .section-step { display: none; }
  .start-driver { border-bottom: none; }
  .room-view .lobby-ready-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 0 -22px -20px;
    padding: 10px 22px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, #0c0c0e 70%, rgba(12, 12, 14, 0));
  }
}

/* Phones in landscape: everything on one screen, two columns */
@media (max-height: 500px) and (orientation: landscape) {
  .lobby-overlay { padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left)); }
  .lobby-container { max-width: 100%; width: 100%; max-height: calc(100dvh - 12px); }
  .lobby-header { padding: 8px 14px; flex-wrap: nowrap; }
  .brand-title { font-size: 20px; }
  .brand-mark { width: 26px; height: 26px; }
  .room-bar { order: 0; width: auto; }
  .room-code { font-size: 18px; }

  .start-view { grid-template-columns: 1.35fr 1fr; }
  .room-view { grid-template-columns: 1fr 1fr; }
  .start-view > section,
  .room-view > section { padding: 10px 14px; gap: 8px; overflow-y: auto; min-height: 0; }
  .start-view, .room-view { overflow: hidden; }
  .start-modes { order: -1; border-bottom: none; border-right: 1px solid var(--line); }
  .start-driver { border-right: none; border-bottom: none; }
  .section-title { font-size: 15px; margin: 0; }

  .start-view > .start-modes { display: grid; grid-template-columns: 1fr 1fr; align-content: start; }
  .section-step { display: none; }
  .start-modes > .section-title,
  .start-modes > .mode-primary,
  .start-modes > .install-hint,
  .start-modes > .start-footer { grid-column: 1 / -1; }
  .mode-tile { padding: 9px 12px; gap: 2px; }
  button.mode-tile, .mode-tile-btn { padding-right: 30px; }
  button.mode-tile::after, .mode-tile-btn::after { right: 12px; }
  .mode-tile-btn { padding: 9px 30px 9px 12px; }
  .mode-title { font-size: 18px; }
  .mode-desc { font-size: 11.5px; line-height: 1.35; }
  .mode-friends .input-with-button { margin-top: 4px; }
  .start-footer { font-size: 12px; }

  .car-preview-container { gap: 10px; }
  .preview-badge-wrapper { display: none; }
  .start-driver .form-group { margin: 0; }

  .room-track .track-preview-canvas { max-height: 84px; object-fit: cover; }
  .room-track .track-name { font-size: 18px; }
  .room-view .lobby-ready-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 0 -14px -10px;
    padding: 8px 14px;
    background: linear-gradient(to top, #0c0c0e 70%, rgba(12, 12, 14, 0));
  }
  .lobby-ready-actions .btn-ready { padding: 10px; font-size: 18px; }
}

/* Phone HUD: the instrument card is scaled down, so give it room for all three columns */
@media (max-height: 430px) {
  body.is-touch .hud-panel-instruments { width: 236px; }
}
