/* ============================================================
   GIO GP — kid-friendly F1 broadcast look.
   Dark carbon UI, heavy italic display type, tire-compound and
   team colors as the accent language. Big touch targets.
   ============================================================ */

:root {
  --bg: #10131b;
  --bg2: #181d29;
  --panel: rgba(16, 19, 28, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f6fb;
  --dim: rgba(244, 246, 251, 0.62);
  --purple: #c77dff;
  --green: #34c759;
  --red: #ff3b30;
  --yellow: #ffd318;
  --radius: 18px;
  --font: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; border: none; color: inherit; background: none; }
button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; font-family: 'Cascadia Mono', Consolas, ui-monospace, monospace; }
.dim { color: var(--dim); }
.purple { color: var(--purple); }

/* F1-broadcast display style */
.f1, .game-title, .section-label, .panel-title, .hud-lap, .results-title, .btn-start {
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ================= START SCREEN ================= */

#screen-start {
  overflow-y: auto;
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(212, 0, 0, 0.22), transparent 60%),
    radial-gradient(1000px 500px at 90% 10%, rgba(255, 128, 0, 0.16), transparent 60%),
    radial-gradient(900px 600px at 50% 110%, rgba(63, 193, 245, 0.12), transparent 60%),
    repeating-linear-gradient(115deg, transparent 0 44px, rgba(255, 255, 255, 0.022) 44px 88px),
    var(--bg);
}

.start-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: clamp(18px, 4vh, 44px) 20px 56px;
  text-align: center;
}

.menu-lights {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
}
.menu-lights span {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #3a0d0d;
  box-shadow: inset 0 0 4px rgba(0,0,0,0.7);
  animation: menu-light 3.2s infinite;
}
.menu-lights span:nth-child(2) { animation-delay: 0.25s; }
.menu-lights span:nth-child(3) { animation-delay: 0.5s; }
.menu-lights span:nth-child(4) { animation-delay: 0.75s; }
.menu-lights span:nth-child(5) { animation-delay: 1s; }
@keyframes menu-light {
  0%, 8% { background: #3a0d0d; box-shadow: inset 0 0 4px rgba(0,0,0,0.7); }
  16%, 62% { background: var(--red); box-shadow: 0 0 14px rgba(255, 59, 48, 0.8); }
  70%, 100% { background: #3a0d0d; box-shadow: inset 0 0 4px rgba(0,0,0,0.7); }
}

.game-title {
  font-size: clamp(36px, 9vw, 84px); /* sized so "CHRISTIAN GP" fits on phones */
  line-height: 1;
  background: linear-gradient(180deg, #fff 30%, #aeb6c6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.45));
}

.game-sub {
  color: var(--dim);
  font-weight: 600;
  margin: 10px 0 26px;
  font-size: clamp(13px, 2.4vw, 16px);
}

.section-label {
  font-size: 14px;
  color: var(--dim);
  letter-spacing: 0.18em;
  margin: 26px 0 12px;
}

.team-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.team-card {
  --team: #fff;
  background: var(--bg2);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.team-card:hover { transform: translateY(-3px); }
.team-card.selected {
  border-color: var(--team);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--team) 35%, transparent), 0 10px 28px rgba(0, 0, 0, 0.45);
}
.team-car { width: 84px; height: 84px; }
.team-name { font-weight: 900; font-style: italic; text-transform: uppercase; font-size: 16px; }
.team-tag { font-size: 12px; color: var(--dim); }

.diff-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.diff-btn {
  background: var(--bg2);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.12s, border-color 0.12s;
}
.diff-btn:hover { transform: translateY(-3px); }
.diff-btn.selected { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 211, 24, 0.28); }
.diff-dot { width: 16px; height: 16px; border-radius: 50%; }
.diff-name { font-weight: 900; font-style: italic; text-transform: uppercase; font-size: 17px; }
.diff-blurb { font-size: 12px; color: var(--dim); }

.pb-chip {
  display: inline-block;
  margin-top: 20px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(199, 125, 255, 0.14);
  border: 1px solid rgba(199, 125, 255, 0.45);
  color: var(--purple);
  font-weight: 700;
  font-size: 14px;
}

.btn-start {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  padding: 20px 44px;
  font-size: clamp(20px, 4vw, 28px);
  border-radius: 999px;
  color: #04160a;
  background: linear-gradient(180deg, #4cd964, #2fb14e);
  box-shadow: 0 8px 0 #1d7534, 0 14px 30px rgba(52, 199, 89, 0.35);
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn-start:active { transform: translateY(6px); box-shadow: 0 2px 0 #1d7534; }
.go-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #04160a;
  box-shadow: 0 0 0 4px rgba(4, 22, 10, 0.25);
}

.howto {
  margin-top: 30px;
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--dim);
}
.howto b { color: var(--text); }

/* ================= RACE SCREEN ================= */

#screen-race { background: #43a047; }

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

.hud { position: absolute; z-index: 5; }

.hud-top-left {
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  min-width: 178px;
}
.hud-lap { font-size: 22px; margin-bottom: 6px; }
.hud-row { display: flex; justify-content: space-between; gap: 14px; font-size: 14px; }
.hud-key { color: var(--dim); font-weight: 800; font-size: 11px; letter-spacing: 0.1em; align-self: center; }

.sectors { display: flex; gap: 4px; margin-top: 8px; }
.sector-cell {
  flex: 1;
  text-align: center;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 3px 2px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--dim);
}
.sector-cell.done { background: rgba(52, 199, 89, 0.25); color: #b8f5c9; }
.sector-cell.best { background: rgba(199, 125, 255, 0.3); color: #eed6ff; }

.hud-top-center {
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  line-height: 0;
}

.hud-top-right {
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.btn-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  font-size: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.tire-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 12px;
}
.tire-dot {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 6px solid var(--yellow);
  background: #191b21;
}
.tire-chip-info { display: flex; flex-direction: column; font-size: 13px; font-weight: 800; }
.tire-chip-info .dim { font-weight: 600; font-size: 11px; }
.wear-bar {
  width: 92px; height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  margin-top: 4px;
  overflow: hidden;
}
.wear-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.wear-fill[data-tone="good"] { background: var(--green); }
.wear-fill[data-tone="warn"] { background: var(--yellow); }
.wear-fill[data-tone="bad"] { background: var(--red); }

.diff-chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--dim);
}

.hud-bottom-right {
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 16px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.speed-num { font-size: 34px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; display: inline-block; }
.speed-unit { color: var(--dim); font-weight: 700; font-size: 13px; }

.pit-chip, .box-hint {
  position: absolute;
  z-index: 6;
  top: calc(max(10px, env(safe-area-inset-top)) + 78px);
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 15px;
  white-space: nowrap;
}
.pit-chip { background: var(--yellow); color: #241c00; }
.wrong-way {
  position: absolute;
  z-index: 6;
  top: 32%;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 26px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-weight: 900;
  font-style: italic;
  font-size: clamp(16px, 3.4vw, 22px);
  white-space: nowrap;
  box-shadow: 0 8px 26px rgba(255, 59, 48, 0.45);
  animation: wrong-way-flash 0.6s infinite;
}
@keyframes wrong-way-flash { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .wrong-way { animation: none; } }
.box-hint { background: var(--panel); border: 2px solid var(--yellow); color: var(--yellow); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.05); } }

.engineer {
  position: absolute;
  z-index: 6;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(92vw, 560px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 6px solid var(--dim);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: clamp(14px, 2.6vw, 17px);
  font-weight: 700;
  animation: slide-up 0.25s ease-out;
}
.engineer[data-tone="go"] { border-left-color: var(--green); }
.engineer[data-tone="warn"] { border-left-color: var(--yellow); }
.engineer-tag { font-size: 11px; font-weight: 900; letter-spacing: 0.1em; color: var(--dim); white-space: nowrap; }
/* on touch devices the radio message rides above the pedal buttons */
.touch .engineer { bottom: calc(max(64px, env(safe-area-inset-bottom) + 58px) + clamp(78px, 12vw, 104px) + 14px); }
@keyframes slide-up { from { opacity: 0; transform: translate(-50%, 14px); } }

.rotate-hint {
  display: none;
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 700;
  pointer-events: none;
}
@media (orientation: portrait) and (max-width: 620px) {
  .rotate-hint { display: block; animation: fade-out 5s forwards; }
}
@keyframes fade-out { 0%, 70% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

/* ---------- touch controls ---------- */

.touch-controls {
  position: absolute;
  z-index: 7;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  padding: 0 max(14px, env(safe-area-inset-left)) max(64px, calc(env(safe-area-inset-bottom) + 58px)) max(14px, env(safe-area-inset-left));
  pointer-events: none;
}
.touch-steer, .touch-pedals { display: flex; gap: 14px; pointer-events: auto; }

.touch-btn {
  width: clamp(78px, 12vw, 104px);
  height: clamp(78px, 12vw, 104px);
  border-radius: 50%;
  background: rgba(16, 19, 28, 0.55);
  border: 3px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  font-size: 30px;
  font-weight: 900;
  touch-action: none;
  backdrop-filter: blur(2px);
}
.touch-btn.active { background: rgba(255, 255, 255, 0.35); transform: scale(0.94); }
.touch-btn.throttle { background: rgba(52, 199, 89, 0.45); border-color: #4cd964; font-size: 20px; font-style: italic; }
.touch-btn.throttle.active { background: rgba(52, 199, 89, 0.75); }
.touch-btn.brake { background: rgba(255, 59, 48, 0.4); border-color: #ff6259; font-size: 16px; font-style: italic; }
.touch-btn.brake.active { background: rgba(255, 59, 48, 0.7); }

/* ---------- start lights ---------- */

.overlay-lights {
  position: absolute;
  z-index: 8;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}
.lights-row {
  display: flex;
  gap: clamp(10px, 2.4vw, 20px);
  background: #14161d;
  border-radius: 18px;
  padding: clamp(12px, 2.4vw, 20px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
}
.light {
  width: clamp(34px, 7vw, 58px);
  height: clamp(34px, 7vw, 58px);
  border-radius: 50%;
  background: #3a0d0d;
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.8);
  transition: background 0.08s;
}
.light.on { background: var(--red); box-shadow: 0 0 26px rgba(255, 59, 48, 0.9); }

.go-flash {
  margin-top: 18px;
  font-size: clamp(48px, 11vw, 92px);
  font-weight: 900;
  font-style: italic;
  color: var(--green);
  text-shadow: 0 0 34px rgba(52, 199, 89, 0.8);
  animation: go-pop 0.35s ease-out;
}
@keyframes go-pop { from { transform: scale(2.2); opacity: 0; } }

/* ---------- overlays / panels ---------- */

.overlay {
  position: absolute;
  z-index: 9;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 12, 0.55);
  backdrop-filter: blur(3px);
  padding: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: clamp(18px, 3.5vw, 30px);
  text-align: center;
  max-width: 640px;
  width: 100%;
  max-height: 94vh;
  overflow-y: auto;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
}

.panel-title { font-size: clamp(24px, 5vw, 34px); margin-bottom: 8px; }
.pit-current { color: var(--dim); font-weight: 600; margin-bottom: 16px; font-size: 14px; }

.tire-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }

.tire-card {
  --tire: #fff;
  background: var(--bg2);
  border: 3px solid var(--line);
  border-radius: 16px;
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transition: transform 0.1s, border-color 0.1s;
}
.tire-card:hover { transform: translateY(-2px); }
.tire-card.selected { border-color: var(--tire); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tire) 40%, transparent); }
.tire-ring {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 7px solid var(--tire);
  background: #191b21;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 20px;
}
.tire-title { font-weight: 900; font-style: italic; text-transform: uppercase; font-size: 16px; }
.tire-blurb { font-size: 11.5px; color: var(--dim); min-height: 30px; }
.tire-pips { font-size: 11px; color: var(--dim); }
.tire-pips b { color: var(--tire); letter-spacing: 2px; margin-left: 4px; }

.btn-big {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 20px;
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  border-radius: 14px;
  color: #04160a;
  background: linear-gradient(180deg, #4cd964, #2fb14e);
  box-shadow: 0 6px 0 #1d7534;
}
.btn-big:disabled { filter: grayscale(1) brightness(0.6); cursor: not-allowed; box-shadow: none; }
.btn-big:not(:disabled):active { transform: translateY(4px); box-shadow: 0 2px 0 #1d7534; }

.btn-mid {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  font-size: 16px;
  font-weight: 800;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
}
.btn-mid:hover { background: rgba(255, 255, 255, 0.14); }

.pause-panel { max-width: 380px; }
.pause-panel .btn-big { margin-bottom: 6px; }

.service-panel { max-width: 420px; }
.crew { font-size: 40px; letter-spacing: 6px; animation: crew-bounce 0.5s infinite alternate; }
@keyframes crew-bounce { to { transform: translateY(-6px); } }
.service-tire { font-weight: 900; font-style: italic; text-transform: uppercase; font-size: 20px; margin: 12px 0 4px; }
.service-count { font-size: 74px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; line-height: 1; }
.service-bar { height: 14px; border-radius: 7px; background: rgba(255, 255, 255, 0.1); margin-top: 16px; overflow: hidden; }
.service-fill { height: 100%; background: linear-gradient(90deg, var(--yellow), var(--green)); border-radius: 7px; }

/* ================= RESULTS ================= */

#screen-results {
  overflow-y: auto;
  background:
    radial-gradient(900px 400px at 50% -8%, rgba(199, 125, 255, 0.18), transparent 60%),
    repeating-linear-gradient(115deg, transparent 0 44px, rgba(255, 255, 255, 0.022) 44px 88px),
    var(--bg);
}

.results-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(20px, 5vh, 48px) 20px 60px;
  text-align: center;
}

.results-title { font-size: clamp(30px, 7vw, 52px); font-weight: 900; font-style: italic; }

.results-cards {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-top: 22px;
}
.result-card {
  grid-column: span 3;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.result-card.small { grid-column: span 2; }
.result-key { font-size: 11px; font-weight: 900; letter-spacing: 0.14em; color: var(--dim); }
.result-val { font-size: clamp(20px, 4.5vw, 30px); font-weight: 900; font-style: italic; }
.result-card.small .result-val { font-size: clamp(16px, 3.5vw, 22px); }

.pb-badge {
  font-size: 11px;
  font-weight: 900;
  color: #241c00;
  background: var(--yellow);
  border-radius: 999px;
  padding: 3px 10px;
  animation: pulse-badge 0.9s infinite alternate;
}
@keyframes pulse-badge { to { transform: scale(1.08); } }

.strategy-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.strategy-chip {
  --tire: #fff;
  padding: 7px 14px;
  border-radius: 999px;
  border: 2px solid var(--tire);
  font-weight: 800;
  font-size: 13px;
}

.laps-scroll { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.laps-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.laps-table th {
  position: sticky; top: 0;
  background: var(--bg2);
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--dim);
  padding: 10px;
}
.laps-table td { padding: 9px 10px; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.laps-table .best-lap td { background: rgba(199, 125, 255, 0.14); color: #eed6ff; font-weight: 800; }
.mini-tire {
  --tire: #fff;
  display: inline-grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 4px solid var(--tire);
  background: #191b21;
  font-size: 11px;
  font-weight: 900;
}

.results-buttons { margin-top: 26px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.results-buttons .btn-mid { width: auto; padding: 13px 26px; }

/* ================= responsive ================= */

@media (max-width: 700px) {
  .team-cards, .diff-btns { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .team-card { padding: 10px 6px; }
  .team-car { width: 56px; height: 56px; }
  .team-name { font-size: 12px; }
  .team-tag { display: none; }
  .diff-blurb { display: none; }
  .hud-top-left { min-width: 148px; padding: 8px 10px; }
  .hud-lap { font-size: 17px; }
  .hud-row { font-size: 12px; }
  .hud-top-center { display: none; }        /* minimap hidden on phones */
  .speed-num { font-size: 24px; min-width: 52px; }
  .tire-chip { padding: 6px 9px; }
  .wear-bar { width: 64px; }
  .tire-cards { gap: 8px; }
  .tire-blurb { display: none; }
  .results-cards { grid-template-columns: repeat(6, 1fr); }
}

@media (max-height: 460px) {
  /* phone landscape: tuck HUD tighter so the track stays visible */
  .hud-top-center { display: none; }
  .hud-times .hud-row:nth-child(3) { display: none; }
  .diff-chip { display: none; }
  /* keep the speed readout clear of the GO/BRAKE pedals */
  .touch .hud-bottom-right { bottom: 158px; padding: 4px 12px; }
  .touch .speed-num { font-size: 22px; min-width: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  .menu-lights span, .crew, .box-hint, .pb-badge { animation: none; }
  * { transition-duration: 0.01s !important; }
}
