@import url('https://fonts.googleapis.com/css2?family=Bungee&family=Space+Grotesk:wght@400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

:root {
  /* Ink-violet base, not flat black - a night-race floodlit feel that
     still leaves room for 20 procedurally-generated team colors to read
     clearly against it. */
  --bg: #120D1F;
  --bg-panel: #1D1730;
  --bg-panel-2: #271F42;
  --border: #392C57;

  --text: #F3EFFF;
  --text-dim: #A79BC9;

  /* Tabloid/broadcast accent trio - loud on purpose. */
  --accent: #FF3D8A;     /* hot pink - primary CTA, "breaking", live */
  --accent-2: #35E0C4;   /* track teal - success/positive/green-flag */
  --gold: #FFD23F;       /* caution yellow - money, odds, warnings */
  --flag-red: #FF5266;   /* red-flag - loss/DNF/danger, distinct from hot pink */
  --silver: #C9D2DE;
  --bronze: #D38B5D;
  --bg-input: #150F26;

  --font-display: 'Bungee', 'Arial Black', sans-serif;
  --font-body: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Space Mono', 'SF Mono', Consolas, monospace;
  font-family: var(--font-body);
}

/* ==========================================================================
   Alternate color themes - same type system, shapes, and layout throughout;
   only the palette changes. Applied via a data-theme attribute on <html>,
   toggled by the little swatch picker (see .theme-switcher below).
   ========================================================================== */

/* "Checkered Riot" - classic livery pairing (safety orange + racing blue)
   on a warm charcoal base. Closer to real motorsport color language than
   the default's neon-tabloid energy. */
[data-theme="checkered"] {
  --bg: #161213;
  --bg-panel: #221C1D;
  --bg-panel-2: #2E2527;
  --border: #4A3A3A;
  --text: #FBEFE8;
  --text-dim: #B89C90;
  --accent: #FF6B1A;
  --accent-2: #3D8BFF;
  --gold: #FFE156;
  --flag-red: #FF3B3B;
  --bg-input: #120E0F;
}

/* "Neon Paddock" - electric violet + lime on near-black blue. The most
   unhinged of the four - leans hardest into the Chaos-archetype energy. */
[data-theme="neon"] {
  --bg: #0A0E1A;
  --bg-panel: #131A2E;
  --bg-panel-2: #1C2540;
  --border: #2E3A5C;
  --text: #EAF0FF;
  --text-dim: #8B9AC2;
  --accent: #B24BFF;
  --accent-2: #C6FF3D;
  --gold: #FFB84D;
  --flag-red: #FF3D6E;
  --bg-input: #0D1220;
}

/* "Tabloid Ink" - vintage newsprint: masthead red + mustard gold on warm
   dark brown. The most grounded/least neon of the four. */
[data-theme="tabloid"] {
  --bg: #1A1410;
  --bg-panel: #241C16;
  --bg-panel-2: #302520;
  --border: #4A3A2E;
  --text: #F7ECDD;
  --text-dim: #B8A48E;
  --accent: #E63946;
  --accent-2: #6FCF97;
  --gold: #F4A62A;
  --flag-red: #8B1E2B;
  --bg-input: #140F0C;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-body); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; letter-spacing: 0.3px; }

.hidden { display: none !important; }
.muted { color: var(--text-dim); font-weight: 400; font-size: 0.85em; }

/* ---------------- Signature: angled broadcast-graphic panels ----------------
   The recurring visual device across the app - a diagonal cut on one
   corner, echoing F1 broadcast lower-thirds and livery graphics. Applied
   via clip-path so it needs no extra markup. Two sizes: -lg for hero
   panels/cards, -sm for compact chips/buttons where a full-size cut
   would eat too much into small content. */
.cut-corner {
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
}
.cut-corner-sm {
  clip-path: polygon(0 0, calc(100% - 7px) 0, 100% 7px, 100% 100%, 0 100%);
}
.hazard-stripe {
  background: repeating-linear-gradient(135deg, var(--gold) 0 10px, #1a1428 10px 20px);
}

/* ---------------- Theme switcher (floating, self-contained) ---------------- */
.theme-switcher { position: fixed; left: 16px; bottom: 16px; z-index: 200; }
.theme-switcher-toggle {
  width: 42px; height: 42px; background: var(--bg-panel); border: 1px solid var(--border);
  color: var(--text); font-size: 18px; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}
.theme-switcher-panel {
  position: absolute; bottom: calc(100% + 8px); left: 0; background: var(--bg-panel);
  border: 1px solid var(--border); border-top: 3px solid var(--accent); padding: 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.5); width: 168px;
}
.theme-switcher-panel.hidden { display: none; }
.theme-swatch-row { display: flex; align-items: center; gap: 8px; padding: 5px 4px; cursor: pointer; }
.theme-swatch-row:hover { background: var(--bg-panel-2); }
.theme-swatch-row.active { background: var(--bg-panel-2); }
.theme-swatch-dots { display: flex; flex-shrink: 0; }
.theme-swatch-dots span { width: 12px; height: 12px; border-radius: 50%; margin-left: -4px; border: 1px solid rgba(0,0,0,0.3); }
.theme-swatch-dots span:first-child { margin-left: 0; }
.theme-swatch-label { font-size: 12.5px; color: var(--text); }

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--bg-panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 8px, var(--gold) 8px 16px);
}
.brand { font-family: var(--font-display); font-size: 18px; letter-spacing: 0.5px; color: var(--accent); }
.tabs { display: flex; gap: 6px; }
.tab-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  padding: 9px 16px; cursor: pointer; font-size: 13.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px; font-family: var(--font-body);
  clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 9px, 100% 100%, 0 100%);
}
.tab-btn:hover { color: var(--text); background: var(--bg-panel-2); }
.tab-btn.active { background: var(--accent); color: #1a0a12; border-color: var(--accent); }

.tab-badge {
  margin-left: 5px; font-size: 9.5px; padding: 2px 6px; border-radius: 8px; font-weight: 800;
  vertical-align: middle; letter-spacing: 0.3px; text-transform: uppercase;
}
.tab-badge.hidden { display: none; }
.tab-badge.live { background: var(--accent); color: white; animation: badge-pulse 1.4s infinite; }
.tab-badge.betting { background: var(--gold); color: #241c00; }
@keyframes badge-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.auth-area { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 14px; }

/* ---------------- Notifications ---------------- */
.notif-wrap { position: relative; }
.notif-bell { position: relative; font-size: 16px; padding: 8px 10px; }
.btn.notif-bell { clip-path: none; }
.notif-badge {
  position: absolute; top: -4px; right: -4px; background: var(--flag-red); color: white;
  font-size: 10px; font-weight: 800; border-radius: 10px; min-width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.notif-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; width: 320px; max-height: 400px; overflow-y: auto;
  background: var(--bg-panel); border: 1px solid var(--border); border-top: 3px solid var(--accent);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5); z-index: 50;
}
.notif-header { padding: 12px 14px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--border); font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.5px; }
.notif-list { padding: 4px; }
.notif-item { padding: 10px 10px; font-size: 13px; line-height: 1.4; margin-bottom: 2px; }
.notif-item.unread { background: rgba(255,255,255,0.04); }
.notif-item.won { border-left: 3px solid var(--accent-2); }
.notif-item.lost { border-left: 3px solid var(--flag-red); }
.notif-item.fan { border-left: 3px solid var(--gold); }
.notif-item.triggered { border-left: 3px solid #ff8c42; }
.notif-item.admin { border-left: 3px solid #8fb2ff; }
.notif-item .time { display: block; color: var(--text-dim); font-size: 11px; margin-top: 3px; }
.notif-empty { padding: 20px; text-align: center; color: var(--text-dim); font-size: 13px; }

/* ---------------- Colored bet status/payout ---------------- */
.status-won { color: var(--accent-2); font-weight: 700; }
.status-lost { color: var(--flag-red); font-weight: 700; }
.status-pending { color: var(--gold); font-weight: 700; }
.payout-positive { color: var(--accent-2); font-weight: 700; }
.payout-zero { color: var(--flag-red); }
.team-dot-inline { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.icon-img { width: 16px; height: 16px; vertical-align: -3px; object-fit: contain; }

/* ---------------- Leaderboard tab ---------------- */
.leaderboard-columns { grid-template-columns: repeat(3, 1fr); }
.leaderboard-columns > div, .standings-columns > div { min-width: 0; }
@media (max-width: 1000px) { .leaderboard-columns { grid-template-columns: 1fr; } }


.token-pill {
  background: linear-gradient(135deg, var(--bg-panel-2), var(--bg-panel)); border: 1px solid var(--gold);
  padding: 6px 12px; border-radius: 20px; font-weight: 700; font-size: 13px; color: var(--gold);
  font-family: var(--font-mono);
}
.btn {
  background: var(--accent); color: #1a0a12; border: none; padding: 9px 18px;
  cursor: pointer; font-weight: 700; font-size: 14px; font-family: var(--font-body);
  text-transform: uppercase; letter-spacing: 0.3px; clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 9px, 100% 100%, 0 100%);
}
.btn.secondary { background: var(--bg-panel-2); border: 1px solid var(--border); color: var(--text); }
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

/* ---------------- Layout ---------------- */
main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.race-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.race-header h1 { margin: 0 0 4px; font-size: 26px; }
.race-meta { color: var(--text-dim); font-size: 14px; font-family: var(--font-mono); }

.status-pill {
  display: inline-block; padding: 6px 16px; font-weight: 700; font-size: 13px;
  text-transform: uppercase; letter-spacing: 0.5px; background: var(--bg-panel-2); border: 1px solid var(--border);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}
.status-pill.betting { color: #1a1608; background: var(--gold); border-color: var(--gold); }
.status-pill.running { color: #06251f; background: var(--accent-2); border-color: var(--accent-2); animation: badge-pulse 1.4s infinite; }
.status-pill.finished { color: var(--text-dim); }
.status-pill.scheduled { color: #8fb2ff; border-color: #8fb2ff; }
.countdown { text-align: right; font-size: 24px; font-weight: 700; margin-top: 6px; font-family: var(--font-mono); color: var(--gold); }

.race-layout { display: grid; grid-template-columns: 1fr 280px; gap: 16px; }
.race-layout > * { min-width: 0; }
.track-wrap {
  position: relative; background: var(--bg-panel); border: 1px solid var(--border);
  padding: 10px; min-height: 420px;
}
#trackSvg { width: 100%; height: 420px; display: block; touch-action: none; }
#trackSvg.pannable { cursor: grab; }
#trackSvg.pannable:active { cursor: grabbing; }

.live-leaderboard { background: var(--bg-panel); border: 1px solid var(--border); border-top: 3px solid var(--accent); padding: 14px; max-height: 460px; overflow-y: auto; }
.live-leaderboard h3 { margin: 0 0 10px; font-size: 14px; color: var(--text); font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.5px; }
#liveLeaderboard { list-style: none; margin: 0; padding: 0; }
#liveLeaderboard li {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
#liveLeaderboard li .pos { width: 20px; color: var(--gold); font-weight: 700; font-family: var(--font-mono); }
#liveLeaderboard li .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
#liveLeaderboard li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#liveLeaderboard li .st { font-size: 11px; color: var(--text-dim); }

/* ---------------- Info box (tooltip) ---------------- */
.info-box {
  position: absolute; background: rgba(18,13,31,0.97); border: 1px solid var(--border); border-top: 2px solid var(--accent);
  padding: 12px 14px; font-size: 12.5px; width: 220px; pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5); z-index: 30;
}
.info-box.pinned { pointer-events: auto; }
.info-box h4 { margin: 0 0 6px; font-size: 14px; font-family: var(--font-body); font-weight: 700; }
.info-box-header { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.info-box-header h4 { margin: 0; }
.info-box .team-tag { display: inline-block; font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }
.info-box .stat-row { display: flex; justify-content: space-between; margin: 2px 0; font-family: var(--font-mono); font-size: 12px; }
.info-box .stat-row span:first-child { color: var(--text-dim); font-family: var(--font-body); }
.stat-high { color: var(--accent-2); font-weight: 700; }
.stat-mid { color: var(--gold); font-weight: 700; }
.stat-low { color: var(--flag-red); font-weight: 700; }
.stat-buff { color: var(--accent-2); font-weight: 800; font-size: 0.85em; }
.info-box .close-x { position: absolute; top: 6px; right: 8px; cursor: pointer; color: var(--text-dim); }

/* ---------------- Betting panel ---------------- */
.betting-panel { margin-top: 20px; background: var(--bg-panel); border: 1px solid var(--border); padding: 18px; }
.betting-panel h3 { margin: 0 0 14px; font-family: var(--font-display); font-size: 16px; font-weight: 400; }
.grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.grid-list > .grid-card { min-width: 0; }
.grid-card { background: var(--bg-panel-2); border: 1px solid var(--border); padding: 12px; min-width: 0; }
.grid-card .row1 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; min-width: 0; }
.grid-card .swatch { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.grid-card .dname { font-weight: 700; font-size: 14px; overflow-wrap: break-word; }
.grid-card .tname { color: var(--text-dim); font-size: 12px; overflow-wrap: break-word; }
.grid-card .odds-row { display: flex; gap: 8px; margin-top: 8px; }
.odds-btn {
  flex: 1; background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
  padding: 8px 6px; cursor: pointer; font-size: 12px; text-align: center; font-family: var(--font-body);
}
.odds-btn b { display: block; font-size: 15px; color: var(--accent-2); font-family: var(--font-mono); }
.odds-btn:hover { border-color: var(--accent-2); }
.odds-btn.selected { border-color: var(--accent); background: rgba(255,61,138,0.14); }

/* ---------------- Results panel ---------------- */
.results-panel { margin-top: 20px; background: var(--bg-panel); border: 1px solid var(--border); padding: 18px; }
.results-panel h3 { font-family: var(--font-display); font-size: 16px; font-weight: 400; }
#resultsList { list-style: none; margin: 0; padding: 0; columns: 2; }
#resultsList li { padding: 6px 4px; border-bottom: 1px solid var(--border); font-size: 14px; }
#resultsList li .pos-badge { display:inline-block; width:22px; font-weight:800; color: var(--gold); font-family: var(--font-mono); }
#resultsList li.dnf .pos-badge { color: var(--flag-red); }

/* ---------------- Standings tab ---------------- */
.standings-header { display: flex; align-items: center; justify-content: space-between; }
.standings-header h1 { font-family: var(--font-display); }
.standings-columns { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; margin-top: 10px; }
.std-table { width: 100%; border-collapse: collapse; background: var(--bg-panel); border: 1px solid var(--border); }
.std-table th, .std-table td { padding: 8px 10px; text-align: left; font-size: 13.5px; border-bottom: 1px solid var(--border); }
.std-table th { color: var(--bg); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; background: var(--gold); font-weight: 700; }
.std-table tr:hover td { background: rgba(255,255,255,0.03); }
select { background: var(--bg-panel-2); color: var(--text); border: 1px solid var(--border); padding: 8px 10px; font-family: var(--font-body); }

/* ---------------- Modal ---------------- */
.modal { position: fixed; inset: 0; background: rgba(10,6,20,0.75); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-card { background: var(--bg-panel); border: 1px solid var(--border); border-top: 3px solid var(--accent); padding: 24px; width: 320px; position: relative; }
.modal-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.modal-tabs button { flex: 1; background: var(--bg-panel-2); border: 1px solid var(--border); color: var(--text-dim); padding: 8px; cursor: pointer; font-weight: 700; font-family: var(--font-body); }
.modal-tabs button.active { color: var(--text); border-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; font-size: 14px; font-family: var(--font-body);
}
.auth-form button[type=submit] { background: var(--accent); color: #1a0a12; border: none; padding: 10px; font-weight: 700; cursor: pointer; text-transform: uppercase; letter-spacing: 0.3px; clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 9px, 100% 100%, 0 100%); }
.form-error { color: var(--flag-red); font-size: 12.5px; min-height: 16px; }
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: none; color: var(--text-dim); font-size: 20px; cursor: pointer; }

/* ---------------- Zoom controls ---------------- */
.zoom-controls { position: absolute; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 4px; z-index: 15; }
.zoom-controls button {
  width: 30px; height: 30px; background: rgba(29,23,48,0.9); border: 1px solid var(--border);
  color: var(--text); font-size: 16px; font-weight: 700; cursor: pointer; line-height: 1;
}
.zoom-controls button:hover { border-color: var(--accent-2); color: var(--accent-2); }

/* ---------------- Clickable name links ---------------- */
.entity-link { color: inherit; text-decoration: none; cursor: pointer; border-bottom: 1px dotted currentColor; }
.entity-link:hover { color: var(--accent-2); border-bottom-color: var(--accent-2); }
.fan-mark { color: var(--gold); font-size: 0.9em; }

/* ---------------- Entity (driver/team) profile modal ---------------- */
.entity-card { width: 420px; max-width: 92vw; max-height: 84vh; overflow-y: auto; }
.entity-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.entity-header .swatch-lg { width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; }
.entity-header h2 { margin: 0; font-size: 20px; font-family: var(--font-display); font-weight: 400; }
.entity-header .sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.driver-face { position: relative; width: 30px; height: 37px; flex-shrink: 0; }
.driver-face .face-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: contain; }
.driver-face-sm { width: 22px; height: 27px; }
.std-driver-cell { display: flex; align-items: center; gap: 8px; }
.entity-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 14px 0; }
.entity-stat { background: var(--bg-panel-2); border: 1px solid var(--border); padding: 8px 10px; }
.entity-stat .label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; }
.entity-stat .value { font-size: 16px; font-weight: 700; margin-top: 2px; font-family: var(--font-mono); }
.entity-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--accent); font-family: var(--font-display); margin: 16px 0 6px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg-panel-2); border: 1px solid var(--border); padding: 4px 10px; font-size: 12.5px; }
.chip.like { border-color: rgba(53,224,196,0.4); }
.chip.dislike { border-color: rgba(255,82,102,0.4); }
.info-list { list-style: none; margin: 0; padding: 0; }
.info-list li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.info-list li span:first-child { color: var(--text-dim); }
.roster-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.roster-face-name { display: flex; align-items: center; gap: 8px; }

/* ---------------- Fan system ---------------- */
.fan-btn {
  display: block; width: 100%; margin: 12px 0 4px; padding: 10px; cursor: pointer;
  background: var(--bg-panel-2); border: 1px solid var(--border); color: var(--text); font-weight: 700; font-size: 13.5px;
}
.fan-btn:hover { border-color: var(--gold); color: var(--gold); }
.fan-btn.active { background: rgba(255,210,63,0.12); border-color: var(--gold); color: var(--gold); }
.fan-login-hint { display: block; margin: 12px 0 4px; font-size: 12.5px; }
.value.fan-value { font-size: 15px; display: flex; align-items: center; gap: 4px; }
.fan-none { font-size: 14px; font-weight: 400; }

/* ---------------- Profile tab ---------------- */
.profile-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 16px 0 24px; }
.profile-summary .card { background: var(--bg-panel); border: 1px solid var(--border); padding: 14px; min-width: 0; }
.profile-summary .card .label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; overflow-wrap: break-word; }
.profile-summary .card .value { font-size: 22px; font-weight: 700; margin-top: 4px; overflow-wrap: break-word; font-family: var(--font-mono); }
.profile-summary .card .value.gold { color: var(--gold); }
.profile-summary .card .value.good { color: var(--accent-2); }
.profile-summary .card .value.bad { color: var(--flag-red); }

/* ---------------- Account settings ---------------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin: 12px 0 28px; }
.settings-card { background: var(--bg-panel); border: 1px solid var(--border); padding: 16px; }
.settings-card h3 { margin: 0 0 8px; font-size: 14px; font-family: var(--font-display); font-weight: 400; }
.settings-card input {
  display: block; width: 100%; margin: 6px 0; background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); padding: 9px 11px; font-size: 13.5px; font-family: var(--font-body);
}
.settings-card .btn { width: 100%; margin-top: 4px; }
.settings-card .form-error { margin-top: 6px; }


/* ---------------- Shop ---------------- */
.shop-grid, .inventory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 14px 0 28px; }
.item-card { background: var(--bg-panel); border: 1px solid var(--border); padding: 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.item-card .item-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.item-card .item-icon { font-size: 28px; line-height: 1; flex-shrink: 0; }
.item-card .item-name { font-weight: 700; font-size: 15px; overflow-wrap: break-word; }
.item-card .item-category { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; }
.item-card .item-desc { font-size: 12.5px; color: var(--text-dim); line-height: 1.4; flex: 1; overflow-wrap: break-word; }
.item-card .item-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.item-card .item-price { font-weight: 700; color: var(--gold); font-size: 14px; font-family: var(--font-mono); }
.item-card .item-qty { font-size: 12px; color: var(--text-dim); }

/* ---------------- Banana placement ---------------- */
.placement-banner {
  background: rgba(255,210,63,0.12); border: 1px solid var(--gold);
  padding: 12px 16px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 14px;
}
.hazard-marker { cursor: default; }
.hazard-marker text { font-size: 16px; text-anchor: middle; dominant-baseline: central; }
.placement-preview { opacity: 0.4; pointer-events: none; }
.placement-preview text { font-size: 18px; text-anchor: middle; dominant-baseline: central; }


/* track svg elements */
.track-line { fill: none; stroke: #3A2F5C; stroke-width: 14; stroke-linejoin: round; }
.track-line-inner { fill: none; stroke: var(--bg-input); stroke-width: 8; stroke-linejoin: round; }
.start-line { stroke: #ffffff; stroke-width: 3; opacity: 0.7; }
.car-dot { cursor: pointer; stroke: var(--bg); stroke-width: 1.5; }
.car-dot.dnf { opacity: 0.25; }
.car-dot-ring { fill: none; stroke: var(--gold); stroke-width: 2.5; opacity: 0; pointer-events: none; transition: opacity 0.1s; }
.car-dot-ring.active { opacity: 1; }
.car-label { font-size: 9px; fill: var(--bg); font-weight: 800; text-anchor: middle; pointer-events: none; }

@media (max-width: 860px) {
  .race-layout { grid-template-columns: 1fr; }
  .standings-columns { grid-template-columns: 1fr; }
}

/* ---------------- Toast notifications ---------------- */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column-reverse; gap: 8px;
  z-index: 300; max-width: 340px;
}
.toast {
  background: var(--bg-panel); border: 1px solid var(--border); padding: 12px 16px;
  font-size: 13.5px; line-height: 1.4; box-shadow: 0 10px 28px rgba(0,0,0,0.5);
  animation: toast-in 0.18s ease-out; transition: opacity 0.18s ease-in, transform 0.18s ease-in;
}
.toast.error { border-left: 3px solid var(--flag-red); }
.toast.success { border-left: 3px solid var(--accent-2); }
.toast.info { border-left: 3px solid var(--gold); }
.toast.fading { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.buy-row { display: flex; gap: 6px; }
.buy-qty-input {
  width: 56px; background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
  padding: 8px 6px; text-align: center; font-size: 13px; font-family: var(--font-mono);
}
.buy-row .btn { flex: 1; }

.item-passive { font-size: 12.5px; text-align: center; padding: 8px 0; }

/* ---------------- Badges ---------------- */
.badges-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin: 12px 0 24px; }
.badge-card { background: var(--bg-panel); border: 1px solid var(--border); padding: 12px; text-align: center; min-width: 0; }
.badge-card.locked { opacity: 0.55; }
.badge-card.earned { border-color: var(--gold); background: rgba(255,210,63,0.07); }
.badge-icon { font-size: 28px; margin-bottom: 4px; }
.badge-name { font-weight: 700; font-size: 13px; overflow-wrap: break-word; }
.badge-desc { font-size: 11px; color: var(--text-dim); margin: 4px 0 8px; line-height: 1.3; min-height: 28px; overflow-wrap: break-word; }
.badge-earned-tag { font-size: 11px; font-weight: 800; color: var(--gold); text-transform: uppercase; letter-spacing: 0.4px; }
.badge-progress-bar { background: var(--bg-input); height: 6px; overflow: hidden; }
.badge-progress-fill { background: var(--accent-2); height: 100%; }
.badge-progress-text { font-size: 10.5px; color: var(--text-dim); margin-top: 4px; font-family: var(--font-mono); }
.notif-item.badge { border-left: 3px solid var(--gold); }

.shop-header { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.shop-header h1 { font-family: var(--font-display); }
.shop-countdown { font-size: 13px; color: var(--text-dim); background: var(--bg-panel-2); border: 1px solid var(--border); padding: 6px 12px; }
.shop-countdown span { color: var(--gold); font-weight: 700; font-family: var(--font-mono); }

/* ---------------- Admin panel ---------------- */
.admin-layout { display: grid; grid-template-columns: 220px 1fr; gap: 20px; margin-top: 16px; }
.admin-sidebar { display: flex; flex-direction: column; gap: 6px; }
.admin-nav-btn {
  text-align: left; background: var(--bg-panel); border: 1px solid var(--border); color: var(--text-dim);
  padding: 10px 14px; cursor: pointer; font-size: 14px; font-weight: 600; font-family: var(--font-body);
}
.admin-nav-btn:hover { color: var(--text); }
.admin-nav-btn.active { background: var(--bg-panel-2); color: var(--text); border-color: var(--accent); }
.admin-content { background: var(--bg-panel); border: 1px solid var(--border); border-top: 3px solid var(--accent); padding: 20px; }
.admin-panel input, .admin-panel select {
  display: block; width: 100%; max-width: 360px; margin: 8px 0; background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; font-size: 14px; font-family: var(--font-body);
}
.admin-btn-row { display: flex; gap: 8px; margin-top: 8px; }
@media (max-width: 700px) { .admin-layout { grid-template-columns: 1fr; } }

.admin-driver-results { max-height: 160px; overflow-y: auto; margin: 4px 0; }
.admin-driver-result {
  padding: 8px 10px; border: 1px solid var(--border); margin-bottom: 4px;
  cursor: pointer; font-size: 13px; display: flex; justify-content: space-between;
}
.admin-driver-result:hover { border-color: var(--accent-2); }
.admin-driver-result.selected { border-color: var(--gold); background: rgba(255,210,63,0.1); }

.item-card { position: relative; }
.item-card.on-sale { border-color: var(--accent-2); }
.sale-badge {
  position: absolute; top: -8px; right: 10px; background: var(--accent-2); color: #04211a;
  font-size: 11px; font-weight: 800; padding: 3px 8px; clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 0 100%);
}
.item-price-strike { color: var(--text-dim); text-decoration: line-through; font-size: 12px; }
.item-price.sale { color: var(--accent-2); }



/* ==========================================================================
   Mobile
   Primary breakpoint at 700px (matches the existing .admin-layout rule) -
   below this, the tab bar becomes a hamburger dropdown and tables condense.
   A tighter 480px breakpoint handles very narrow phones specifically.
   ========================================================================== */

.nav-toggle {
  display: none; /* shown only under the mobile breakpoint below */
  background: transparent; border: 1px solid var(--border); color: var(--text);
  font-size: 18px; line-height: 1; padding: 6px 10px; cursor: pointer;
}

/* Username/logout duplicate for the mobile dropdown - always in the DOM,
   only ever visible under the 700px breakpoint (see below), where the
   header versions are hidden instead. */
.mobile-nav-user { display: none; }

/* A table's own natural content width (long team/player names, several
   numeric columns) can exceed a phone's viewport even after padding is
   trimmed - this makes that scroll within its own box instead of
   pushing the whole page wider. Harmless no-op on desktop where content
   already fits. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; min-width: 0; }
.table-scroll .std-table { min-width: 100%; }

@media (max-width: 700px) {
  main { padding: 14px 12px 40px; }
  h1 { font-size: 20px; }
  h2 { font-size: 16px; }

  /* ---- Topbar: brand + hamburger + a trimmed header-right (just the
     notif bell and token count - username/logout move into the dropdown
     below so the row doesn't have to cram four things into ~370px) ---- */
  .topbar { flex-wrap: wrap; justify-content: flex-start; align-items: center; gap: 10px; padding: 10px 12px; row-gap: 8px; max-width: 100vw; overflow-x: hidden; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; order: 3; flex-shrink: 0; }
  .header-right { order: 2; margin-left: 0; gap: 8px; min-width: 0; flex-shrink: 0; }
  .brand { order: 1; font-size: 17px; flex-shrink: 0; }
  .notif-wrap { min-width: 0; }
  .auth-area { min-width: 0; }
  .auth-username-link, .auth-logout-btn { display: none; }
  .token-pill { font-size: 12px; padding: 5px 9px; }

  .tabs {
    order: 10; flex-basis: 100%; width: 100%; max-width: 100%; min-width: 0;
    display: none; flex-direction: column; gap: 2px;
    background: var(--bg-panel-2); border: 1px solid var(--border);
    padding: 6px; margin-top: 2px;
    overflow-x: hidden;
  }
  .tabs.open { display: flex; }
  .tab-btn { width: 100%; text-align: left; padding: 12px 14px; clip-path: none; }

  .mobile-nav-user {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 10px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--border);
    min-width: 0;
  }
  .mobile-nav-username { color: var(--text); font-weight: 700; font-size: 14px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

  /* ---- Notification dropdown shouldn't run off the right edge ---- */
  .notif-dropdown {
    position: fixed; width: auto; left: 10px; right: 10px; top: 62px;
    max-width: none;
  }

  /* ---- Standings / leaderboard / bet history: condense horizontally.
     table-scroll (see base rules above) is the safety net; this trims
     padding/font and truncates long names so scrolling is rarely even
     needed. ---- */
  .standings-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .std-table th, .std-table td { padding: 7px 6px; font-size: 12.5px; }
  .std-table .col-hide-narrow { display: none; } /* Podiums/DNFs, bet Type/Odds - still visible on a driver/bet's own profile if needed */
  .std-table td { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ---- Shop: rotation timer moves under the title (left-aligned)
     instead of pinned to the far right, and cards go full-width so
     their footer (price + buy button) has room to breathe. ---- */
  .shop-header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .shop-grid, .inventory-grid { grid-template-columns: 1fr; gap: 10px; }
  .item-card { padding: 11px; gap: 6px; }
  .item-card .item-icon { font-size: 24px; }

  /* ---- Profile: stat cards and badge cards to a fixed 2-column grid,
     which fits reliably instead of the auto-fit minmax computation
     occasionally landing just past the edge of the viewport. ---- */
  .profile-summary { grid-template-columns: repeat(2, 1fr); }
  .badges-grid { grid-template-columns: repeat(2, 1fr); }

  /* ---- Modal shouldn't overflow narrow screens ---- */
  .modal-card { width: 92vw; max-width: 360px; padding: 18px; }

  /* ---- Buttons/inputs: comfortable tap targets ---- */
  .btn, select, .auth-form input { font-size: 14px; }
}

@media (max-width: 480px) {
  /* ---- Very narrow phones: trim standings further and shrink the brand/title chrome ---- */
  .std-table th, .std-table td { padding: 6px 4px; font-size: 11.5px; }
  .std-table td { max-width: 72px; }
  .brand { font-size: 15px; }
  .modal-card { padding: 14px; }
}

/* ---------------- News feed ---------------- */
.news-feed { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.news-item {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--bg-panel); border: 1px solid var(--border); padding: 12px 14px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
}
.news-icon { font-size: 22px; line-height: 1; flex-shrink: 0; margin-top: 2px; }
.news-body { flex: 1; min-width: 0; }
.news-headline { font-weight: 700; line-height: 1.35; overflow-wrap: break-word; font-size: 15px; }
.news-links { font-size: 12.5px; margin-top: 5px; display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.news-driver-chip { display: inline-flex; align-items: center; gap: 4px; }
.news-link-sep { color: var(--text-dim); }
.news-time { font-size: 11px; margin-top: 5px; font-family: var(--font-mono); color: var(--text-dim); }
.news-item.news-race_result { border-left: 4px solid var(--gold); }
.news-item.news-milestone { border-left: 4px solid var(--accent-2); }
.news-item.news-bet_win { border-left: 4px solid var(--accent-2); }
.news-item.news-season { border-left: 4px solid var(--accent); }
.news-item.news-flavor {
  border-left: 4px solid var(--text-dim); background: var(--bg-panel-2);
  transform: rotate(-0.3deg);
}
.news-item.news-flavor:nth-child(even) { transform: rotate(0.3deg); }
.news-item.news-race_result .news-headline,
.news-item.news-season .news-headline { font-size: 16.5px; }

@media (max-width: 700px) {
  .news-item { padding: 10px 12px; gap: 10px; min-width: 0; }
  .news-icon { font-size: 18px; }
}
