@font-face {
  font-family: 'Formula1';
  src: url('fonts/formula1-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Formula1';
  src: url('fonts/formula1-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --accent: #ff8000;
  --accent-dim: #cc6600;
  --bg: #111113;
  --surface: #1c1c1f;
  --surface-hover: #252528;
  --surface-raised: #2a2a2e;
  --border: #333336;
  --text: #eaeaec;
  --text-dim: #8a8a8e;
  --text-muted: #5a5a5e;
  --green: #2ecc71;
  --green-dim: rgba(46, 204, 113, 0.15);
  --red: #e74c3c;
  --gold: #f1c40f;
  --silver: #bdc3c7;
  --bronze: #e67e22;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .race-name, .nav-btn, .status, .login-box h1,
.standings-table .pos, .standings-table .total, .countdown {
  font-family: 'Formula1', 'Segoe UI', system-ui, sans-serif;
}

.hidden { display: none !important; }
.error { color: var(--red); margin-top: 8px; font-size: 14px; }

/* ===== Login ===== */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  background: linear-gradient(145deg, #0a0a0c 0%, #1a1a1f 50%, #0f0f12 100%);
}

.login-box {
  width: 100%;
  max-width: 380px;
  padding: 40px 28px;
  background: var(--surface);
  border-radius: 20px;
  text-align: center;
  border: 1px solid var(--border);
}
.login-box h1 {
  font-size: 2.4em;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--accent), #ffaa44);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle {
  color: var(--text-dim);
  margin: 4px 0 28px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 3px;
}
.login-box form { display: flex; flex-direction: column; gap: 14px; }

/* ===== Inputs ===== */
input, select {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* prevents iOS zoom */
  transition: border-color 0.2s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
input::placeholder { color: var(--text-muted); }

/* ===== Buttons ===== */
button {
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #000;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px; /* touch target */
}
button:hover { background: #ff9933; }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

button.small {
  padding: 8px 16px;
  font-size: 13px;
  background: var(--surface-raised);
  color: var(--text);
  font-weight: 500;
  min-height: 36px;
}
button.small:hover { background: var(--surface-hover); }

button.secondary {
  background: var(--surface-raised);
  color: var(--text);
}
button.secondary:hover { background: var(--surface-hover); }

/* ===== Header ===== */
header {
  background: var(--surface);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 {
  font-size: 1.3em;
  letter-spacing: 1px;
  color: var(--accent);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
#user-info {
  color: var(--text-dim);
  font-size: 13px;
}

/* ===== Bottom Nav (mobile) ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 0;
  padding-bottom: calc(6px + var(--safe-bottom));
  z-index: 100;
}
.nav-btn {
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  padding: 8px 12px;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 8px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: color 0.2s;
}
.nav-btn:hover { background: transparent; color: var(--text-dim); }
.nav-btn.active {
  color: var(--accent);
}
.nav-icon { font-size: 20px; line-height: 1; }

/* ===== Main ===== */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 12px 90px; /* bottom padding for bottom nav */
}

/* ===== Race Cards ===== */
.race-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}
.race-card:hover { background: var(--surface-hover); }
.race-card:active { background: var(--surface-raised); }
.race-card .round {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 2px;
}
.race-card .race-name {
  font-weight: 700;
  font-size: 1.05em;
  letter-spacing: 0.3px;
}
.race-card .race-date { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.race-card .race-quali { color: var(--accent); font-size: 12px; margin-top: 4px; font-weight: 600; }
.race-card .race-quali.past { color: var(--text-dim); font-weight: 400; }

.status {
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 20px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.status.open { background: var(--green); color: #000; }
.status.locked { background: var(--text-muted); color: var(--bg); }
.status.done { background: var(--gold); color: #000; }
.status.predicted {
  border: 2px solid var(--green);
  color: var(--green);
  background: var(--green-dim);
}

/* ===== Race Detail ===== */
#race-info { margin: 16px 0; }
#race-info h2 { margin-bottom: 4px; letter-spacing: 0.5px; }
#race-info .meta { color: var(--text-dim); margin-bottom: 8px; font-size: 14px; }
.countdown {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.15em;
  margin: 10px 0;
  letter-spacing: 0.5px;
}

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 15px;
}
.loading::before {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Prediction Form ===== */
.pred-form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin: 16px 0;
  border: 1px solid var(--border);
}
.pred-form h3 { margin-bottom: 16px; font-size: 1em; letter-spacing: 0.5px; }
.pred-form .field { margin-bottom: 14px; }
.pred-form label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 14px;
}
.pred-form .points {
  font-family: 'Formula1', sans-serif;
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
}
.pred-form select { width: 100%; }
.pred-form button { width: 100%; margin-top: 4px; }
.pred-form .saved { color: var(--green); margin-top: 10px; font-weight: 600; }

/* ===== Predictions Table ===== */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px -12px;
  padding: 0 12px;
}

.pred-table { width: 100%; border-collapse: collapse; min-width: 500px; }
.pred-table th, .pred-table td {
  padding: 10px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.pred-table th {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pred-table .correct { color: var(--green); font-weight: 700; }
.pred-table .wrong { color: var(--text-muted); }
.pred-table .pts {
  font-family: 'Formula1', sans-serif;
  color: var(--accent);
  font-weight: 700;
  text-align: right;
}

/* Result row */
.result-row { background: rgba(255, 128, 0, 0.08); }
.result-row td {
  font-weight: 700;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

/* ===== Standings ===== */
.standings-table { width: 100%; border-collapse: collapse; }
.standings-table th, .standings-table td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.standings-table th {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.standings-table .pos {
  width: 40px;
  font-weight: 700;
  font-size: 1.3em;
}
.standings-table .username { font-weight: 600; }
.standings-table .total {
  font-weight: 700;
  font-size: 1.3em;
  color: var(--accent);
  text-align: right;
}
.standings-me {
  background: rgba(255, 128, 0, 0.1);
  border-left: 3px solid var(--accent);
}
.standings-me td { font-weight: 700; }

/* ===== Admin ===== */
.admin-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.admin-section h3 { margin-bottom: 8px; font-size: 1em; }
.admin-section p { color: var(--text-dim); margin-bottom: 14px; font-size: 14px; }
#add-user-form { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.user-chip {
  display: inline-block;
  background: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  margin: 3px;
  font-size: 14px;
  border: 1px solid var(--border);
}
.user-chip.admin { border-color: var(--accent); color: var(--accent); }

/* ===== Results Admin ===== */
.result-form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin: 16px 0;
  border: 1px solid var(--border);
}
.result-form h3 { margin-bottom: 14px; color: var(--accent); font-size: 1em; }
.result-form .field { margin-bottom: 14px; }
.result-form label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 14px;
}
.result-form select { width: 100%; }
.result-actions { display: flex; gap: 8px; margin-top: 14px; }
.result-actions button { flex: 1; }

/* ===== Section headers ===== */
#tab-standings h2, #tab-admin h2 {
  margin-bottom: 16px;
  font-size: 1.2em;
  letter-spacing: 0.5px;
}
#predictions-list h3 { font-size: 1em; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  header h1 { font-size: 1.1em; }
  .race-card { padding: 14px; }
  .race-card .race-name { font-size: 0.95em; }
  .pred-table th, .pred-table td { padding: 8px 6px; font-size: 13px; }
  .result-actions { flex-direction: column; }
}

/* ===== Recap ===== */
#recap-list h2, #recap-header h2 { margin-bottom: 16px; font-size: 1.2em; letter-spacing: 0.5px; }

.recap-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}
.recap-card:hover { background: var(--surface-hover); }
.recap-card:active { background: var(--surface-raised); }
.recap-card .round { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 2px; }
.recap-card .race-name { font-weight: 700; font-size: 1.05em; letter-spacing: 0.3px; }
.recap-card .race-date { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

.session-tabs {
  display: flex;
  gap: 6px;
  margin: 12px 0 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.session-tab {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  min-height: 36px;
  transition: all 0.15s;
}
.session-tab:hover { background: var(--surface-hover); color: var(--text); }
.session-tab.active { background: var(--accent); color: #000; border-color: var(--accent); }

.recap-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.recap-section h3 {
  font-size: 0.95em;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.recap-section h3 .section-icon { font-size: 16px; }

/* Positions table */
.pos-table { width: 100%; border-collapse: collapse; }
.pos-table th, .pos-table td { padding: 8px 8px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.pos-table th { color: var(--text-muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.pos-table .pos-num { font-family: 'Formula1', sans-serif; font-weight: 700; width: 32px; }
.pos-table .pos-1 { color: var(--gold); }
.pos-table .pos-2 { color: var(--silver); }
.pos-table .pos-3 { color: var(--bronze); }
.pos-table .driver-name { font-weight: 600; }
.pos-table .driver-team { color: var(--text-muted); font-weight: 400; font-size: 11px; }
.pos-table .team-color { display: inline-block; width: 4px; height: 16px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }
.pos-table .gap { color: var(--text-dim); font-size: 12px; font-family: 'Formula1', sans-serif; }
.pos-table .laps-col { color: var(--text-dim); text-align: right; }
.pos-table .lap-time { font-family: 'Formula1', sans-serif; font-size: 12px; white-space: nowrap; }
.pos-table .dnf-row td { opacity: 0.5; }
.pos-table .dnf-badge { font-family: 'Formula1', sans-serif; font-size: 10px; font-weight: 700; color: var(--red); background: rgba(231, 76, 60, 0.15); padding: 2px 6px; border-radius: 4px; margin-left: 6px; vertical-align: middle; opacity: 1; }

/* Pit stops */
.pit-table { width: 100%; border-collapse: collapse; }
.pit-table th, .pit-table td { padding: 8px 8px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.pit-table th { color: var(--text-muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.pit-table td:nth-child(3), .pit-table td:nth-child(4) { font-family: 'Formula1', sans-serif; }
.pit-table .fast-pit { color: var(--green); font-weight: 700; }

/* Stints / tyre strategy */
.stint-driver { margin-bottom: 10px; }
.stint-driver-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.stint-bar { display: flex; gap: 2px; height: 24px; border-radius: 4px; overflow: hidden; }
.stint-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #000;
  min-width: 20px;
  border-radius: 3px;
}
.stint-segment.SOFT { background: #ff3333; }
.stint-segment.MEDIUM { background: #ffd700; }
.stint-segment.HARD { background: #e0e0e0; }
.stint-segment.INTERMEDIATE { background: #43b02a; }
.stint-segment.WET { background: #0072c6; color: #fff; }
.stint-segment.UNKNOWN { background: #888; }
.stint-legend {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.stint-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
}
.stint-legend-dot { width: 12px; height: 12px; border-radius: 3px; }

/* Race control feed */
.rc-feed { max-height: 300px; overflow-y: auto; }
.rc-item {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.rc-item:last-child { border-bottom: none; }
.rc-time { color: var(--text-muted); font-family: 'Formula1', sans-serif; font-size: 11px; min-width: 90px; flex-shrink: 0; white-space: nowrap; }
.rc-lap { color: var(--text-muted); font-size: 11px; font-weight: 600; min-width: 32px; flex-shrink: 0; }
.rc-flag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.rc-flag.GREEN { background: var(--green); color: #000; }
.rc-flag.YELLOW, .rc-flag.DOUBLE_YELLOW { background: #ffd700; color: #000; }
.rc-flag.RED { background: var(--red); color: #fff; }
.rc-flag.CHEQUERED { background: #fff; color: #000; }
.rc-flag.BLUE { background: #0072c6; color: #fff; }
.rc-flag.BLACK_AND_WHITE { background: linear-gradient(90deg, #000 50%, #fff 50%); color: var(--red); }
.rc-flag.CLEAR { background: var(--surface-raised); color: var(--text-dim); }
.rc-flag.VSC, .rc-flag.SC { background: #ffd700; color: #000; }
.rc-msg { color: var(--text); line-height: 1.4; }

/* Weather widget */
.weather-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.weather-item {
  text-align: center;
  padding: 12px 8px;
  background: var(--bg);
  border-radius: 10px;
}
.weather-value { font-family: 'Formula1', sans-serif; font-size: 1.3em; font-weight: 700; color: var(--accent); }
.weather-label { font-size: 11px; color: var(--text-dim); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

.recap-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.recap-no-data {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  padding: 8px 0;
}

/* Desktop: inline nav instead of bottom bar */
@media (min-width: 769px) {
  .bottom-nav {
    position: static;
    background: transparent;
    border: none;
    justify-content: flex-start;
    gap: 4px;
    padding: 0;
  }
  .nav-btn {
    flex-direction: row;
    font-size: 14px;
    gap: 6px;
    padding: 8px 16px;
  }
  .nav-btn.active {
    background: rgba(255, 128, 0, 0.1);
    border-radius: 8px;
  }
  .nav-icon { font-size: 16px; }
  main { padding-bottom: 40px; }
  #add-user-form { flex-direction: row; }
}
