* { margin: 0; padding: 0; box-sizing: border-box; }
  :root {
    --surface: rgba(10,10,10,0.92);
    --border: rgba(255,255,255,0.08);
    --text: #e8e8e8;
    --dim: #555;
    --accent: #E10600;
    --accent-glow: rgba(225,6,0,0.25);
  }
  body {
    font-family: 'Instrument Sans', sans-serif;
    background: #0a0a0a;
    color: var(--text);
    overflow: hidden;
    height: 100vh; width: 100vw;
    user-select: none;
  }

  #map { position: absolute; inset: 0; z-index: 1; }

  /* Welcome screen */
  .welcome-screen {
    position: fixed; inset: 0; z-index: 9999;
    background: #0a0a0a;
    display: flex; align-items: stretch;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: opacity 0.7s ease, visibility 0.7s ease;
  }
  .welcome-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

  .welcome-body {
    flex: 1; display: flex; flex-direction: column;
    padding: 60px 80px; justify-content: center; max-width: 900px; margin: 0 auto;
    min-height: min-content;
    width: 100%;
  }

  .welcome-title {
    font-family: 'Instrument Sans', sans-serif;
    font-size: clamp(36px, 5vw, 60px); font-weight: 700;
    line-height: 1.05; letter-spacing: -1px;
    color: var(--text); margin-bottom: 16px;
  }
  .welcome-title em {
    font-style: normal; color: var(--accent);
  }

  .welcome-subtitle {
    font-family: 'DM Mono', monospace; font-size: 12px;
    color: var(--dim); letter-spacing: 0.5px; line-height: 1.7;
    margin-bottom: 24px; max-width: 520px;
  }

  /* Steps list */
  .welcome-steps {
    display: grid; grid-template-columns: 1fr 1fr;
    column-gap: 48px; row-gap: 0;
    margin-bottom: 48px;
    border-top: 1px solid var(--border);
  }
  .welcome-step {
    display: flex; flex-direction: column; gap: 6px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
  }
  .step-label {
    font-family: 'Instrument Sans', sans-serif; font-size: 13px;
    font-weight: 600; color: var(--text);
  }
  .step-right {
    display: contents;
  }
  .step-desc {
    font-family: 'DM Mono', monospace; font-size: 10px;
    color: var(--dim); line-height: 1.6; letter-spacing: 0.2px;
  }
  .step-keys {
    display: flex; gap: 4px; align-items: center; flex-wrap: wrap;
  }
  .step-key {
    display: inline-block; font-family: 'DM Mono', monospace; font-size: 9px;
    color: var(--dim); border: 1px solid rgba(255,255,255,0.1);
    padding: 1px 6px; border-radius: 2px; background: rgba(255,255,255,0.04);
    white-space: nowrap;
  }
  @media (max-width: 700px) {
    .welcome-steps { grid-template-columns: 1fr; }
    .welcome-body { padding: 0 32px; }
  }

  /* Bottom row */
  .btn-start {
    font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500;
    letter-spacing: 2px; text-transform: uppercase;
    background: var(--accent); color: #fff; border: none;
    padding: 14px 36px; cursor: pointer;
    transition: all 0.2s; outline: none;
    position: relative; overflow: hidden;
  }
  .btn-start::after {
    content: ''; position: absolute; inset: 0;
    background: rgba(255,255,255,0); transition: background 0.2s;
  }
  .btn-start:hover::after { background: rgba(255,255,255,0.1); }
  .btn-start:active { transform: scale(0.98); }

  /* Welcome background grid */
  .welcome-grid {
    position: absolute; inset: 0; pointer-events: none; overflow: hidden; opacity: 0.03;
    background-image:
      linear-gradient(rgba(255,255,255,0.5) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255,255,255,0.5) 1px, transparent 1px);
    background-size: 60px 60px;
  }
  .welcome-grid::after {
    content: ''; position: absolute; inset: 0;
    background: radial-gradient(ellipse at 60% 50%, #0a0a0a 30%, transparent 80%);
  }

  /* Loading splash (shown after Get Started) */
  .loading-splash {
    position: fixed; inset: 0; z-index: 9998;
    background: #0a0a0a;
    display: flex; align-items: center; justify-content: center;
    flex-direction: column; gap: 20px;
    transition: opacity 0.6s ease, visibility 0.6s ease;
    pointer-events: none; opacity: 0; visibility: hidden;
  }
  .loading-splash.visible { opacity: 1; visibility: visible; pointer-events: all; }
  .loading-splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
  .loading-title {
    font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500;
    letter-spacing: 3px; text-transform: uppercase;
    display: flex; align-items: center; gap: 10px;
  }
  .loading-title .dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: pulse-dot 1.2s ease infinite; }
  @keyframes pulse-dot { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.7); } }
  .loading-bar-track {
    width: 200px; height: 2px; background: var(--border); border-radius: 1px; overflow: hidden;
  }
  .loading-bar-fill {
    height: 100%; width: 0%; background: var(--accent); border-radius: 1px;
  }
  .loading-bar-fill.animating {
    animation: load-fill 1.8s ease-out forwards;
  }
  @keyframes load-fill { 0% { width: 0%; } 60% { width: 70%; } 100% { width: 100%; } }

  /* UI chrome */
  .top-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 24px;
    background: linear-gradient(to bottom, rgba(10,10,10,0.85) 40%, transparent);
    pointer-events: none;
    opacity: 0; animation: fade-in 0.5s ease 0.4s forwards;
  }
  @keyframes fade-in { to { opacity: 1; } }
  .top-bar > * { pointer-events: all; }
  .logo {
    font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500;
    letter-spacing: 3px; text-transform: uppercase;
    display: flex; align-items: center; gap: 10px;
  }
  .logo-dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; }
  .logo-sub { font-size: 9px; letter-spacing: 1.5px; color: var(--dim); margin-left: 8px; }
  .controls { display: flex; align-items: center; gap: 6px; }
  .btn {
    font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 1px;
    text-transform: uppercase; padding: 8px 14px;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--dim); cursor: pointer; transition: all 0.2s;
    backdrop-filter: blur(20px); outline: none;
    position: relative;
  }
  .btn:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }
  .btn.danger:hover { color: var(--accent); border-color: rgba(225,6,0,0.3); }
  .btn.active { color: var(--accent); border-color: rgba(225,6,0,0.3); }
  .btn:active { transform: scale(0.97); }
  .btn .shortcut {
    font-size: 8px; color: #333; margin-left: 6px; letter-spacing: 0;
  }

  .panel {
    position: fixed; z-index: 100; background: var(--surface);
    border: 1px solid var(--border); backdrop-filter: blur(30px);
    padding: 20px 24px; transition: opacity 0.3s, transform 0.3s;
    border-radius: 2px;
  }
  .panel.hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }
  .stats-panel { bottom: 24px; left: 24px; min-width: 260px; }
  .sector-panel { bottom: 24px; right: 24px; }
  .panel-label {
    font-family: 'DM Mono', monospace; font-size: 9px; letter-spacing: 2px;
    text-transform: uppercase; color: var(--dim); margin-bottom: 14px;
    display: flex; align-items: center; gap: 8px;
  }
  .panel-label::before {
    content: ''; width: 3px; height: 10px; background: var(--accent); border-radius: 1px;
  }
  .stat-row {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: 5px 0; border-bottom: 1px solid var(--border);
  }
  .stat-row:last-child { border-bottom: none; }
  .stat-key { font-family: 'DM Mono', monospace; font-size: 10px; color: var(--dim); }
  .stat-value { font-family: 'DM Mono', monospace; font-size: 13px; font-weight: 500; }
  .unit { font-size: 9px; color: var(--dim); margin-left: 2px; }
  .hl { color: var(--accent); }

  .sector-item {
    display: flex; align-items: center; gap: 8px; padding: 3px 0;
    font-family: 'DM Mono', monospace; font-size: 10px; color: var(--dim);
  }
  .sector-dot { width: 8px; height: 8px; border-radius: 50%; }

  .instructions {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    z-index: 100; font-family: 'DM Mono', monospace; font-size: 10px;
    letter-spacing: 1px; color: var(--dim); background: var(--surface);
    border: 1px solid var(--border); padding: 10px 18px;
    backdrop-filter: blur(20px); transition: opacity 0.3s; white-space: nowrap;
    border-radius: 2px;
  }
  .instructions.hidden { opacity: 0; pointer-events: none; }



  /* Export toast */
  .toast {
    position: fixed; top: 60px; left: 50%; transform: translateX(-50%) translateY(-20px);
    z-index: 9999; font-family: 'DM Mono', monospace; font-size: 10px;
    letter-spacing: 1px; color: var(--text); background: var(--surface);
    border: 1px solid rgba(225,6,0,0.3); padding: 10px 20px;
    backdrop-filter: blur(20px); opacity: 0; pointer-events: none;
    transition: opacity 0.3s, transform 0.3s; border-radius: 2px;
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

  /* Location dropdown */
  .location-dropdown {
    position: relative; margin-left: 12px;
  }
  .location-menu {
    position: absolute; top: calc(100% + 6px); left: 0;
    background: var(--surface); border: 1px solid var(--border);
    backdrop-filter: blur(30px); border-radius: 2px;
    min-width: 280px; z-index: 200;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  }
  .location-menu.hidden {
    opacity: 0; transform: translateY(-6px); pointer-events: none;
  }
  .location-menu-scroll {
    max-height: 420px; overflow-y: auto; padding: 4px 0;
    scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
  }
  .location-menu-scroll::-webkit-scrollbar { width: 4px; }
  .location-menu-scroll::-webkit-scrollbar-track { background: transparent; }
  .location-menu-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
  .location-item {
    font-family: 'DM Mono', monospace; font-size: 10px;
    letter-spacing: 0.5px; padding: 9px 16px; cursor: pointer;
    color: var(--dim); transition: all 0.15s ease;
    display: flex; justify-content: space-between; align-items: center;
  }
  .location-item:hover { color: var(--text); background: rgba(255,255,255,0.04); }
  .location-item.active { color: var(--accent); }
  .location-detail {
    font-size: 9px; color: #333; margin-left: 12px; text-transform: uppercase;
    letter-spacing: 1px;
  }
  .location-item:hover .location-detail { color: var(--dim); }
  .location-item.active .location-detail { color: rgba(225,6,0,0.5); }

  /* Share modal */
  .share-overlay {
    position: fixed; inset: 0; z-index: 9998;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.25s ease, visibility 0.25s ease;
  }
  .share-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
  .share-modal {
    background: var(--surface); border: 1px solid var(--border);
    backdrop-filter: blur(30px); padding: 28px 32px;
    min-width: 480px; max-width: 90vw; border-radius: 2px;
  }
  .share-desc {
    font-size: 12px; color: var(--dim); margin-bottom: 18px; line-height: 1.5;
  }
  .share-url-row {
    display: flex; gap: 6px; margin-bottom: 18px;
  }
  .share-url-input {
    flex: 1; font-family: 'DM Mono', monospace; font-size: 10px;
    background: rgba(255,255,255,0.04); border: 1px solid var(--border);
    color: var(--text); padding: 10px 12px; outline: none;
    letter-spacing: 0.3px; border-radius: 2px;
  }
  .share-url-input:focus { border-color: rgba(255,255,255,0.15); }
  .share-copy-btn { white-space: nowrap; }
  .share-copy-btn.copied { color: #3DDC84; border-color: rgba(61,220,132,0.3); }
  .share-actions { display: flex; justify-content: flex-end; }


  /* Settings location submenu (inline within settings panel) */
  .settings-location-submenu {
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,0.25);
    margin-bottom: 2px;
  }
  .settings-location-submenu.hidden { display: none; }
  .settings-location-submenu .location-menu-scroll { max-height: 220px; }
  .settings-location-submenu .location-item { padding: 8px 24px; font-size: 10px; }
  #locationChevron {
    display: inline-block;
    transition: transform 0.2s ease;
  }
  #locationChevron.open { transform: rotate(90deg); }

  /* Tools dropdown (mobile only — hidden on desktop) */
  .tools-dropdown { position: relative; display: none; }
  .tools-menu {
    position: absolute; top: calc(100% + 6px); right: 0;
    background: var(--surface); border: 1px solid var(--border);
    backdrop-filter: blur(30px); border-radius: 2px;
    min-width: 192px; z-index: 200;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    transition: opacity 0.2s ease, transform 0.2s ease;
    padding: 4px 0;
  }
  .tools-menu.hidden { opacity: 0; transform: translateY(-6px); pointer-events: none; }

  /* Settings menu scrollable to accommodate location submenu */
  .settings-menu {
    max-height: 80vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
  }
  .settings-menu::-webkit-scrollbar { width: 4px; }
  .settings-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

  .welcome-mobile-disclaimer {
    display: none;
    margin-bottom: 24px;
  }

  @media (max-width: 768px) {
    #statsPanel, #sectorPanel, #exportBtn { display: none !important; }
    .top-bar { padding: 12px 16px; }
    .controls { gap: 4px; }
    .btn { padding: 8px 10px; font-size: 9px; }
    .instructions { display: none !important; }
    /* Hide individual action buttons; show Tools dropdown instead */
    #clearBtn, #undoBtn, #closeBtn, #shareBtn { display: none !important; }
    .tools-dropdown { display: block; }
    /* Welcome screen: smaller padding, top-aligned so it scrolls naturally */
    .welcome-body {
      padding: 40px 24px 60px;
      justify-content: flex-start;
    }
    .welcome-title { font-size: clamp(28px, 8vw, 44px); }
    .welcome-mobile-disclaimer {
      display: block;
      font-family: 'DM Mono', monospace; font-size: 10px;
      color: var(--dim); letter-spacing: 0.3px; line-height: 1.6;
      margin-top: 20px;
      padding: 10px 14px;
      border: 1px solid var(--border);
      border-left: 2px solid rgba(225,6,0,0.4);
      background: rgba(225,6,0,0.04);
    }
  }
  /* Welcome start row */
  .welcome-start-row {
    display: flex; align-items: center; gap: 0;
    margin-bottom: 40px;
  }
  .welcome-location-dropdown {
    position: relative;
  }
  .welcome-location-btn {
    font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500;
    letter-spacing: 1px; text-transform: uppercase;
    background: rgba(255,255,255,0.05); color: var(--dim);
    border: 1px solid rgba(255,255,255,0.1); border-right: none;
    padding: 14px 20px; cursor: pointer;
    transition: all 0.2s; outline: none;
    white-space: nowrap;
  }
  .welcome-location-btn:hover { color: var(--text); background: rgba(255,255,255,0.08); }
  .welcome-location-dropdown .location-menu {
    bottom: calc(100% + 6px); top: auto; left: 0;
  }

  /* Settings dropdown */
  .settings-dropdown {
    position: relative;
  }
  .settings-menu {
    position: absolute; top: calc(100% + 6px); right: 0;
    background: var(--surface); border: 1px solid var(--border);
    backdrop-filter: blur(30px); border-radius: 2px;
    min-width: 264px; z-index: 200;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    transition: opacity 0.2s ease, transform 0.2s ease;
    padding: 4px 0;
  }
  .settings-menu.hidden { opacity: 0; transform: translateY(-6px); pointer-events: none; }
  .settings-item {
    display: flex; justify-content: space-between; align-items: center;
    font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 0.5px;
    padding: 10px 16px; cursor: pointer; color: var(--dim);
    transition: all 0.15s ease; border-bottom: 1px solid var(--border);
  }
  .settings-item:last-child { border-bottom: none; }
  .settings-item:not(.settings-item-inactive):hover { color: var(--text); background: rgba(255,255,255,0.04); }
  .settings-item-inactive { cursor: default; opacity: 0.4; }
  .settings-item-label { flex: 1; }
  .settings-toggle {
    font-size: 9px; letter-spacing: 1.5px; font-weight: 500;
    padding: 2px 7px; border-radius: 2px; border: 1px solid;
  }
  .settings-toggle.on { color: #3DDC84; border-color: rgba(61,220,132,0.35); }
  .settings-toggle.off { color: var(--dim); border-color: rgba(255,255,255,0.1); }
  .settings-item-soon {
    font-size: 9px; letter-spacing: 1px; color: #333;
  }
  .settings-item-chevron {
    font-size: 14px; color: var(--dim); line-height: 1;
  }
  .settings-item:hover .settings-item-chevron { color: var(--text); }

  /* Race type badge */
  .race-type-badge {
    font-size: 9px; letter-spacing: 1.5px; font-weight: 500;
    padding: 2px 7px; border-radius: 2px; border: 1px solid;
    transition: color 0.2s, border-color 0.2s;
  }
  .rt-f1  { color: #E10600; border-color: rgba(225,6,0,0.35); }
  .rt-gt3 { color: #FFD23F; border-color: rgba(255,210,63,0.35); }
  .rt-motogp { color: #818cf8; border-color: rgba(129,140,248,0.35); }

  /* Changelog modal */
  .changelog-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 14px;
  }
  .changelog-modal {
    max-width: 520px; max-height: 70vh;
    display: flex; flex-direction: column;
  }
  .changelog-body {
    overflow-y: auto; flex: 1;
    margin-bottom: 18px;
    scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
  }
  .changelog-body::-webkit-scrollbar { width: 4px; }
  .changelog-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
  .changelog-version { padding: 14px 0; border-bottom: 1px solid var(--border); }
  .changelog-version:last-child { border-bottom: none; }
  .changelog-version-header {
    display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px;
  }
  .changelog-version-num {
    font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500;
    color: var(--accent); letter-spacing: 1px;
  }
  .changelog-version-date {
    font-family: 'DM Mono', monospace; font-size: 10px; color: var(--dim);
  }
  .changelog-entries {
    list-style: none; padding: 0;
  }
  .changelog-entries li {
    font-family: 'DM Mono', monospace; font-size: 10px; color: var(--dim);
    line-height: 1.7; padding: 1px 0; padding-left: 14px; position: relative;
  }
  .changelog-entries li::before {
    content: '–'; position: absolute; left: 0; color: #333;
  }

  /* Mobile-only items — hidden on desktop, visible on mobile */
  .mobile-only { display: none; }
  @media (max-width: 640px) {
    .mobile-only { display: flex; }
  }

  /* Mapbox overrides */
  .mapboxgl-ctrl-attrib { font-family: 'DM Mono', monospace !important; font-size: 9px !important; }
  .mapboxgl-ctrl-group { display: none !important; }
  .mapboxgl-canvas { cursor: crosshair !important; }