/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #334155;
  --accent: #f97316;
  --accent2: #fb923c;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --border: #334155;
  --nav-h: 64px;
  --header-h: 52px;
  --radius: 12px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--nav-h);
  height: 100vh;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  overflow: hidden;
}

/* ===== HEADER ===== */
#header {
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 100;
}

.logo { font-size: 18px; font-weight: 800; letter-spacing: -0.5px; }
.logo-accent { color: var(--accent); font-size: 18px; font-weight: 800; }

.gps-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 20px;
}
.gps-off  { background: #374151; color: var(--text2); }
.gps-on   { background: #14532d; color: var(--green); }
.gps-wait { background: #1c3a5f; color: var(--blue); animation: pulse 1.2s infinite; }

@keyframes pulse { 50% { opacity: 0.5; } }

/* ===== MAIN / PAGES ===== */
#main {
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.page {
  display: none;
  position: absolute;
  inset: 0;
}
.page.active { display: flex; flex-direction: column; }

/* ===== RECORD PAGE ===== */
.map-area {
  flex: 1;
  position: relative;
  min-height: 0;
}

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

/* Speed circle: always-on top-right overlay */
.map-speed-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  width: 64px;
  height: 64px;
  background: rgba(15, 23, 42, 0.90);
  border: 2px solid var(--accent);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.overlay-speed-val {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.overlay-speed-label {
  font-size: 9px;
  color: var(--text2);
  margin-top: 2px;
  letter-spacing: 0.3px;
}

/* Segment layer toggle button */
.map-seg-layer-btn {
  position: absolute;
  top: 82px;
  left: 10px;
  z-index: 1000;
  width: 34px;
  height: 34px;
  background: rgba(15, 23, 42, 0.90);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.map-seg-layer-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(249, 115, 22, 0.12);
}
.map-seg-layer-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Segment active HUD: bottom of map */
.seg-map-hud {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  background: rgba(15, 23, 42, 0.92);
  border-top: 1px solid var(--accent);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.seg-map-hud-left {
  flex: 1;
  min-width: 0;
}

.seg-map-hud-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.seg-map-waiting {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.seg-map-dist-label {
  font-size: 12px;
  color: var(--text2);
}

.seg-map-dist-val {
  font-size: 28px;
  font-weight: 900;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.seg-map-dist-unit {
  font-size: 12px;
  color: var(--text2);
}

.seg-map-time-val {
  font-size: 26px;
  font-weight: 900;
  color: var(--green);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.btn-seg-stop-map {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.leaflet-container {
  background: #0c1a2e !important;
}

.record-hud {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
}

.hud-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.hud-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 10px 6px;
  text-align: center;
}

.hud-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hud-label {
  font-size: 10px;
  color: var(--text2);
  margin-top: 4px;
  white-space: nowrap;
}

.hud-buttons {
  display: flex;
  gap: 10px;
}

.btn-record {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.3px;
}

.btn-start {
  background: var(--accent);
  color: #fff;
}
.btn-start:active { transform: scale(0.97); }

.btn-stop {
  background: var(--red);
  color: #fff;
  animation: rec-pulse 1.5s infinite;
}

@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

.btn-secondary {
  width: 80px;
  height: 48px;
  background: var(--bg2);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:not([disabled]):hover { color: var(--text); border-color: var(--accent); }
.btn-secondary[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ===== SEGMENT PAGE ===== */
#page-segment { overflow: hidden; }

.page-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.section-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 16px;
}

.card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

.segment-setup { display: flex; flex-direction: column; gap: 0; }

.segment-point {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}

.point-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

.start-icon { background: #14532d; color: var(--green); }
.end-icon   { background: #7f1d1d; color: var(--red); }

.point-info { flex: 1; }
.point-label { font-weight: 600; font-size: 13px; }
.point-coord { font-size: 11px; color: var(--text2); margin-top: 2px; font-family: monospace; }

.btn-small {
  background: var(--bg3);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-small:hover { background: var(--accent); color: #fff; }

.segment-divider {
  height: 1px;
  background: var(--border);
  margin: 0 48px;
}

.segment-radius {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.segment-radius label { font-size: 13px; color: var(--text2); white-space: nowrap; }
.segment-radius input[type=range] { flex: 1; accent-color: var(--accent); }
.segment-radius span { font-size: 13px; color: var(--accent); font-weight: 700; min-width: 38px; text-align: right; }

.seg-timer-big {
  font-size: 42px;
  font-weight: 900;
  text-align: center;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
  padding: 10px 0;
}

.seg-status-text {
  text-align: center;
  font-size: 13px;
  color: var(--text2);
  margin-top: 4px;
}

.seg-records { display: flex; flex-direction: column; gap: 8px; }

.seg-record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg3);
  border-radius: 10px;
}

.seg-record-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
}

.rank-1 { background: #78350f; color: #fbbf24; }
.rank-2 { background: #374151; color: #e5e7eb; }
.rank-3 { background: #431407; color: #fb923c; }
.rank-n { background: var(--bg2); color: var(--text2); }

.seg-record-time { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.seg-record-date { font-size: 11px; color: var(--text2); }

.seg-record-best { color: var(--green); }

/* ===== DATA PAGE ===== */
#page-data { overflow: hidden; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-val {
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 12px;
  color: var(--text2);
  margin-top: 4px;
}

canvas {
  width: 100% !important;
  max-height: 180px;
}

/* ===== HISTORY PAGE ===== */
#page-history { overflow: hidden; }

.history-item {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.history-item:hover { background: var(--bg3); }

.history-icon {
  width: 42px;
  height: 42px;
  background: #431407;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.history-icon svg {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.history-info { flex: 1; min-width: 0; }
.history-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 12px; color: var(--text2); margin-top: 3px; }

.history-stats { text-align: right; flex-shrink: 0; }
.history-speed { font-size: 18px; font-weight: 800; color: var(--accent); }
.history-speed-label { font-size: 11px; color: var(--text2); }

.history-delete {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.history-delete:hover { background: var(--red); color: #fff; }

/* ===== BOTTOM NAV ===== */
#bottom-nav {
  height: var(--nav-h);
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  transition: color 0.15s;
  padding: 0;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

.nav-btn.active, .nav-btn:hover {
  color: var(--accent);
}

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  align-items: flex-end;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 80dvh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

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

.modal-header span { font-size: 17px; font-weight: 700; }

.modal-close {
  background: var(--bg3);
  border: none;
  color: var(--text2);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body { padding: 20px; }

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

.modal-stat {
  background: var(--bg3);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.modal-stat-val { font-size: 22px; font-weight: 800; color: var(--accent); }
.modal-stat-label { font-size: 11px; color: var(--text2); margin-top: 2px; }

.modal-mini-map {
  width: 100%;
  height: 200px;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

/* ===== UTILS ===== */
.empty-hint {
  text-align: center;
  color: var(--text2);
  padding: 30px 20px;
  font-size: 14px;
}

/* ===== AUTH SCREEN ===== */
.auth-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-screen.active { display: flex; }

.auth-container {
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 6px;
}
.auth-logo .logo       { font-size: 32px; font-weight: 800; }
.auth-logo .logo-accent { font-size: 32px; font-weight: 800; color: var(--accent); }

.auth-desc {
  text-align: center;
  color: var(--text2);
  font-size: 14px;
  margin-bottom: 32px;
}

.auth-tabs {
  display: flex;
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  height: 38px;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--text2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.auth-tab.active { background: var(--bg3); color: var(--text); }

.auth-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.auth-error:not(:empty) { display: block; }

.auth-success {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  color: #86efac;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.auth-success:not(:empty) { display: block; }

.auth-field {
  margin-bottom: 14px;
}
.auth-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 6px;
}
.auth-field input {
  width: 100%;
  height: 48px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  padding: 0 14px;
  outline: none;
  transition: border-color 0.15s;
}
.auth-field input:focus { border-color: var(--accent); }
.auth-field input::placeholder { color: var(--bg3); }

.auth-btn {
  width: 100%;
  height: 50px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
  transition: opacity 0.15s;
}
.auth-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-btn:not(:disabled):active { opacity: 0.85; }

/* ===== USER BUTTON ===== */
.btn-user {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg2);
  border: none;
  border-radius: 20px;
  color: var(--text2);
  cursor: pointer;
  padding: 6px 10px 6px 8px;
  transition: color 0.15s;
}
.btn-user:hover { color: var(--text); }
.btn-user svg { width: 18px; height: 18px; flex-shrink: 0; }

.user-email {
  font-size: 11px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== HEADER RIGHT LAYOUT ===== */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== SEGMENT PAGE ===== */
.seg-timer-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #1c1c2e;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
}

.seg-banner-info { flex: 1; min-width: 0; }
.seg-banner-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-banner-status { font-size: 12px; margin-top: 2px; }
.seg-banner-status.waiting { color: var(--blue); }
.seg-banner-status.running { color: var(--green); }

.seg-banner-time {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.btn-seg-stop {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

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

.btn-add-seg {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-add-seg:active { opacity: 0.8; }

.seg-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.seg-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.seg-card-name { font-size: 15px; font-weight: 700; }

.seg-card-actions { display: flex; gap: 6px; }

.btn-seg-records {
  background: var(--bg3);
  color: var(--text2);
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-seg-records:hover { color: var(--text); }

.btn-seg-start {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn-seg-start:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-seg-delete {
  background: transparent;
  color: var(--text2);
  border: none;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  cursor: pointer;
}
.btn-seg-delete:hover { background: var(--red); color: #fff; }

.seg-card-info { display: flex; flex-wrap: wrap; gap: 6px; }

.seg-point-badge, .seg-radius-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: monospace;
}
.start-badge { background: #14532d; color: #86efac; }
.end-badge   { background: #7f1d1d; color: #fca5a5; }
.seg-radius-badge { background: var(--bg3); color: var(--text2); }

.seg-records-list { display: flex; flex-direction: column; gap: 8px; }

/* ===== ADD SEGMENT FORM ===== */
.seg-form-section {
  background: var(--bg3);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.seg-form-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 12px;
}

.btn-map-pick {
  width: 100%;
  height: 42px;
  background: var(--bg2);
  color: var(--text2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
  transition: all 0.15s;
}
.btn-map-pick:hover { border-color: var(--accent); color: var(--accent); }

.seg-coord-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.seg-coord-row input {
  height: 40px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 0 10px;
  outline: none;
  width: 100%;
}
.seg-coord-row input:focus { border-color: var(--accent); }

.coord-badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: monospace;
  display: inline-block;
}
.coord-set   { background: #14532d; color: #86efac; }
.coord-unset { background: var(--bg2); color: var(--text2); }

/* ===== MAP PICKER MODAL ===== */
.modal-fullscreen {
  align-items: stretch !important;
  padding: 0 !important;
}

.map-picker-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--bg);
}

.map-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 16px;
  font-weight: 700;
}

#picker-map {
  flex: 1;
  min-height: 0;
}

.map-picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.picker-coord-text {
  font-size: 13px;
  color: var(--text2);
  font-family: monospace;
  flex: 1;
}

/* Leaflet dark theme overrides */
.leaflet-tile { filter: brightness(0.7) saturate(0.8); }
.leaflet-control-zoom a { background: var(--bg2) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-popup-content-wrapper {
  background: var(--bg2) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6) !important;
}
.leaflet-popup-tip { background: var(--bg2) !important; }
.leaflet-popup-content { margin: 10px 14px !important; font-size: 13px; line-height: 1.6; }
.leaflet-popup-close-button { color: var(--text2) !important; }

/* ===== HISTORY BADGES ===== */
.history-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.history-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.badge-run     { background: #1e3a5f; color: #93c5fd; }
.badge-seg     { background: #431407; color: var(--accent); }
.badge-segname { background: var(--bg3); color: var(--text2); }

/* ===== CHALLENGE PAGE ===== */
.challenge-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.challenge-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.challenge-name  { font-size: 15px; font-weight: 700; }
.challenge-desc  { font-size: 12px; color: var(--text2); margin-top: 3px; }

.btn-challenge-start {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-challenge-start:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-challenge-board {
  background: var(--bg3);
  color: var(--text2);
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-challenge-board:hover { color: var(--text); }

/* ===== LEADERBOARD ===== */
.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.leaderboard-item:last-child { border-bottom: none; }
.lb-email {
  flex: 1;
  font-size: 12px;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== ADMIN BUTTON ===== */
.btn-admin {
  background: var(--bg2);
  border: none;
  color: var(--text2);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
}
.btn-admin:hover { color: var(--accent); }

/* ===== ADMIN PANEL ===== */
.admin-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--bg);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 16px;
  font-weight: 700;
}

.admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.admin-tab {
  flex: 1;
  height: 42px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s;
}
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}
.admin-content.active { display: block; }

.admin-user-group { margin-bottom: 20px; }
.admin-user-email {
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.admin-record-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(51,65,85,0.5);
}
.admin-record-row:last-child { border-bottom: none; }
