/* ─── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0a0a;
  --panel:     #141414;
  --panel2:    #1a1a1a;
  --border:    #222;
  --border2:   #2a2a2a;
  --gold:      #fdbe40;
  --gold-dim:  #c8962e;
  --green:     #1f5c2e;
  --green-lit: #2d8a44;
  --red:       #c0392b;
  --text:      #e8e8e8;
  --text-dim:  #888;
  --text-mute: #555;
  --font:      'Inter', system-ui, sans-serif;
  --radius:    10px;
  --radius-sm: 6px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ─── Screens ───────────────────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.hidden { display: none !important; }

/* Token Screen */
.token-card, .upload-card {
  width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: 0 32px 80px rgba(0,0,0,.6);
}
.token-logo, .upload-logo { margin-bottom: 20px; }
.brand-logo { height: 72px; width: auto; display: block; margin: 0 auto; }
.header-logo-img { height: 36px; width: auto; display: block; }
.token-card h1, .upload-card h1 {
  font-size: 22px; font-weight: 700; letter-spacing: -.3px;
  color: var(--text); margin-bottom: 6px;
}
.token-sub, .upload-sub {
  color: var(--text-dim); font-size: 13px; margin-bottom: 32px;
}
.token-form { text-align: left; }
.token-form label {
  display: block; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-dim); margin-bottom: 8px;
}
.token-form input {
  width: 100%; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 13px;
  transition: border-color .2s;
}
.token-form input:focus { outline: none; border-color: var(--gold); }
.token-hint {
  font-size: 12px; color: var(--text-mute); margin: 10px 0 20px;
}
.token-hint a { color: var(--gold); text-decoration: none; }
.token-hint a:hover { text-decoration: underline; }

/* Buttons */
.btn-primary {
  width: 100%; padding: 13px;
  background: var(--gold); color: #0a0a0a;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .2s, transform .1s;
}
.btn-primary:hover { background: #ffc93d; }
.btn-primary:active { transform: scale(.98); }
.btn-ghost {
  background: none; border: 1px solid var(--border2);
  color: var(--text-dim); padding: 10px 18px;
  border-radius: var(--radius-sm); font-family: var(--font);
  font-size: 13px; cursor: pointer; margin-top: 16px;
  transition: border-color .2s, color .2s;
}
.btn-ghost:hover { border-color: var(--text-dim); color: var(--text); }
.btn-ghost-sm {
  background: none; border: 1px solid var(--border);
  color: var(--text-dim); padding: 7px 14px;
  border-radius: var(--radius-sm); font-family: var(--font);
  font-size: 12px; cursor: pointer; transition: all .2s;
}
.btn-ghost-sm:hover { border-color: var(--gold); color: var(--gold); }

/* Drop Zone */
.drop-zone {
  border: 2px dashed var(--border2);
  border-radius: var(--radius);
  padding: 40px 24px;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 16px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--gold);
  background: rgba(253,190,64,.04);
}
.drop-icon { margin-bottom: 14px; }
.drop-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.drop-sub { font-size: 13px; color: var(--text-dim); }
.drop-link { color: var(--gold); cursor: pointer; }
.upload-hint { font-size: 12px; color: var(--text-mute); margin-bottom: 8px; }

/* Loading */
.loading-card {
  display: flex; flex-direction: column;
  align-items: center; gap: 20px; color: var(--text-dim);
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── App Layout ────────────────────────────────────────────────── */
#app {
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}

/* Header */
#app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { flex-shrink: 0; }
.header-route {
  font-size: 13px; color: var(--text-dim); margin-left: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 280px;
}
.header-stats {
  display: flex; align-items: center; gap: 0;
  font-size: 12px;
}
.stat-pill {
  display: flex; flex-direction: column; align-items: center;
  padding: 0 16px; border-right: 1px solid var(--border);
}
.stat-pill:last-child { border-right: none; }
.stat-value { font-size: 15px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 10px; font-weight: 500; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-mute); margin-top: 1px; }
.stat-value.gold { color: var(--gold); }
.stat-value.green { color: var(--green-lit); }
.stat-value.red { color: #e05c50; }

/* Main layout */
#main-layout {
  display: flex; flex: 1; overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden;
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.sidebar-section { padding: 14px 0; }
.sidebar-heading {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text-mute);
  padding: 0 14px 10px;
}

/* KM Split items */
.split-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
}
.split-item:hover { background: var(--panel2); }
.split-item.active {
  background: rgba(253,190,64,.07);
  border-left-color: var(--gold);
}
.split-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--border2); display: flex;
  align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
  color: var(--text-dim);
}
.split-item.active .split-num { background: var(--gold); color: #0a0a0a; }
.split-details { flex: 1; min-width: 0; }
.split-gain {
  font-size: 12px; font-weight: 600;
  display: flex; gap: 6px;
}
.split-up { color: var(--green-lit); }
.split-dn { color: #e05c50; }
.split-grad { font-size: 10px; color: var(--text-mute); margin-top: 1px; }
.split-spark {
  width: 48px; height: 22px; flex-shrink: 0;
}

/* Centre */
#centre {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

/* Map */
#map-container {
  flex: 1; position: relative; overflow: hidden;
}
#map { position: absolute; inset: 0; }

/* Map overlay controls */
#map-overlay-controls {
  position: absolute; top: 12px; right: 12px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 5;
}
.map-ctrl-btn {
  width: 34px; height: 34px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-dim);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.map-ctrl-btn:hover { border-color: var(--gold); color: var(--gold); }

/* Mapbox overrides */
.mapboxgl-ctrl-bottom-left, .mapboxgl-ctrl-bottom-right,
.mapboxgl-ctrl-top-left, .mapboxgl-ctrl-top-right { display: none; }
.mapboxgl-canvas { outline: none; }

/* Elevation */
#elevation-container {
  height: 160px; flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
}
#elevation-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 4px;
  flex-shrink: 0;
}
.elev-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .7px; color: var(--text-mute);
}
.elev-hover-info {
  font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums;
}
#elevation-chart-wrap {
  flex: 1; position: relative; overflow: hidden;
}
#elevation-canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
#elev-crosshair {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: rgba(253,190,64,.6); pointer-events: none;
}
#elev-tooltip {
  position: absolute; top: 8px;
  background: var(--panel2); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 7px 10px;
  font-size: 11px; pointer-events: none; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  line-height: 1.7;
}
.tt-row { display: flex; justify-content: space-between; gap: 16px; }
.tt-key { color: var(--text-mute); }
.tt-val { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Route marker popups / labels */
.km-marker {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--gold);
  color: var(--gold); font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font); cursor: default;
}
.start-marker {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--green-lit); border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(45,138,68,.35);
}
.finish-marker {
  width: 12px; height: 12px; border-radius: 50%;
  background: #e05c50; border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(192,57,43,.35);
}
.hover-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--gold); border: 2px solid #fff;
  margin-left: -6px; margin-top: -6px;
  box-shadow: 0 0 0 3px rgba(253,190,64,.3);
}

/* Responsive */
@media (max-width: 768px) {
  #sidebar { display: none; }
  .token-card, .upload-card { width: 90vw; padding: 36px 24px; }
  .header-stats .stat-pill:nth-child(n+4) { display: none; }
}
