:root {
  --red: #e10600;
  --ink: #f4f5f7;
  --muted: #a3a8b3;
  --panel: rgba(14, 15, 21, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --purple: #b388ff;
  --green: #3ddc84;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0c10; color: var(--ink);
  font-family: "Titillium Web", system-ui, -apple-system, Segoe UI, sans-serif;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body.touch { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

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

#ui { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; padding: 16px; pointer-events: auto; background: rgba(6, 7, 10, 0.55);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.screen > * { margin: auto; } /* centred when it fits, scrollable when it doesn't */
.screen.active { display: flex; }
#menu.screen { background: linear-gradient(90deg, rgba(6,7,10,0.92) 0%, rgba(6,7,10,0.6) 45%, rgba(6,7,10,0.1) 100%); justify-content: flex-start; }

.menu-wrap { max-width: 460px; width: 100%; margin: auto auto auto clamp(0px, 6vw, 90px); }
.brand-stripe { width: 80px; height: 6px; background: var(--red); margin-bottom: 14px; transform: skewX(-20deg); }
.brand h1 { font-size: clamp(48px, 8vw, 84px); font-weight: 900; font-style: italic; letter-spacing: -1px; margin: 0; line-height: 0.95; }
.brand h1 span { color: var(--red); }
.brand .tag { color: var(--muted); margin: 8px 0 26px; letter-spacing: 0.5px; }

button { font-family: inherit; cursor: pointer; border: 0; color: var(--ink); }
.menu-buttons { display: flex; flex-direction: column; gap: 8px; }
.menu-buttons button, .col-buttons button {
  text-align: left; font-size: 19px; font-weight: 700; padding: 13px 18px; background: rgba(255,255,255,0.06);
  border-left: 4px solid transparent; transition: background .15s, border-color .15s, transform .15s; text-transform: uppercase; letter-spacing: 0.5px;
}
.menu-buttons button small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); text-transform: none; letter-spacing: 0; }
.menu-buttons button:hover, .menu-buttons button:focus-visible, .col-buttons button:hover { background: rgba(255,255,255,0.12); border-left-color: var(--red); transform: translateX(4px); outline: none; }
.menu-buttons button.primary { background: var(--red); }
.menu-buttons button.primary small { color: rgba(255,255,255,0.8); }
.menu-buttons button.primary:hover { background: #ff1a12; border-left-color: #fff; }

.track-card { margin-top: 26px; padding: 14px 16px; border: 1px solid var(--line); background: rgba(0,0,0,0.35); }
.track-card h3 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--red); }
.track-card ul { list-style: none; padding: 0; margin: 0 0 6px; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; color: var(--muted); }
.track-card b { color: var(--ink); }
.track-card p { margin: 0; font-size: 12px; color: var(--muted); }

.panel { background: var(--panel); border-top: 4px solid var(--red); width: min(640px, 100%); max-height: calc(100vh - 32px);
  overflow: auto; padding: 18px 22px 22px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.panel.wide { width: min(1080px, 100%); }
.panel.small { width: min(360px, 100%); }
.panel.center { text-align: center; }
.panel header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel h2 { margin: 0; font-size: 26px; font-weight: 900; font-style: italic; text-transform: uppercase; }
.panel .sub { color: var(--muted); font-size: 14px; }

button.ghost { background: transparent; border: 1px solid var(--line); padding: 8px 16px; font-weight: 600; text-transform: uppercase; font-size: 13px; }
button.ghost:hover { border-color: var(--ink); }
button.primary { background: var(--red); padding: 10px 24px; font-weight: 700; text-transform: uppercase; font-size: 15px; }
button.primary:hover { background: #ff1a12; }
.row-buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.col-buttons { display: flex; flex-direction: column; gap: 8px; }

.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.team { background: rgba(255,255,255,0.04); border-left: 5px solid var(--team); padding: 10px 12px 12px; }
.team h4 { margin: 0; font-size: 16px; font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; }
.team h4 small { color: var(--muted); font-weight: 400; font-size: 11px; }
.team .perf { height: 4px; background: rgba(255,255,255,0.08); margin: 6px 0 8px; }
.team .perf i { display: block; height: 100%; background: var(--team); }
.team .drivers { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.driver-btn { background: rgba(255,255,255,0.06); padding: 8px; text-align: left; border: 1px solid transparent; transition: border-color .15s, background .15s; }
.driver-btn:hover, .driver-btn:focus-visible { border-color: var(--team); background: rgba(255,255,255,0.12); outline: none; }
.driver-btn .num { font-size: 22px; font-weight: 900; font-style: italic; color: var(--team); line-height: 1; }
.driver-btn .nm { display: block; font-size: 13px; font-weight: 600; }

.settings { display: grid; gap: 10px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; background: rgba(255,255,255,0.04); flex-wrap: wrap; }
.setting label { font-weight: 600; }
.setting label small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.seg { display: flex; gap: 2px; }
.seg button { background: rgba(255,255,255,0.07); padding: 7px 12px; font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--red); }
.range { display: flex; align-items: center; gap: 10px; }
.range input { width: 180px; accent-color: var(--red); }
.range output { min-width: 42px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.controls-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; align-items: center; font-size: 15px; }
kbd { display: inline-block; min-width: 26px; padding: 2px 7px; border: 1px solid rgba(255,255,255,0.3); border-bottom-width: 3px;
  border-radius: 4px; font-family: inherit; font-weight: 700; font-size: 13px; text-align: center; background: rgba(255,255,255,0.06); }
.tips h4 { margin: 20px 0 6px; text-transform: uppercase; color: var(--red); letter-spacing: 1px; font-size: 13px; }
.tips ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }

.brief { color: var(--muted); line-height: 1.55; font-size: 15px; }
.brief b { color: var(--ink); }
.brief .car-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; background: rgba(255,255,255,0.06); border-left: 4px solid var(--team); color: var(--ink); font-weight: 700; margin-bottom: 10px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,0.04); white-space: nowrap; }
td.pos { font-weight: 900; font-style: italic; font-size: 16px; width: 36px; }
td.drv { font-weight: 700; }
td.drv i { display: inline-block; width: 4px; height: 16px; background: var(--team); margin-right: 8px; vertical-align: -3px; }
td.num { font-variant-numeric: tabular-nums; }
tr.me td { background: rgba(255,255,255,0.12); }
td.purple { color: var(--purple); font-weight: 700; }
td.dnf { color: #ff5252; font-weight: 700; }
td.pts { font-weight: 700; color: var(--green); }

.spinner { width: 38px; height: 38px; border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--red); border-radius: 50%;
  margin: 8px auto 14px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); background: rgba(200,30,30,0.9); padding: 10px 18px;
  font-weight: 700; letter-spacing: 0.5px; pointer-events: none; }
#hint:not(.hidden) { animation: hint-fade 1s ease 9s forwards; }
@keyframes hint-fade { to { opacity: 0; } }
#hint { position: fixed; right: 14px; bottom: 14px; font-size: 12px; color: rgba(255,255,255,0.7); background: rgba(12,13,18,0.6); padding: 6px 10px; pointer-events: none; }
#hint kbd { font-size: 11px; padding: 0 5px; min-width: 0; }
.hidden { display: none !important; }
body.touch #hint { display: none; }
.banner.tappable { pointer-events: auto; cursor: pointer; }

/* ---------------------------------------------------------------- touch controls */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#touch button, #touch .tc-drag { pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none; }
#touch button { font-family: inherit; color: #fff; font-weight: 700; letter-spacing: 0.5px; }
#touch .on { filter: brightness(1.6); transform: scale(0.96); }
.tc-buttons { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); display: flex; gap: 14px; }
.tc-buttons button { width: 88px; height: 88px; border-radius: 50%; font-size: 30px;
  background: rgba(20, 22, 30, 0.45); border: 2px solid rgba(255, 255, 255, 0.45); }
.tc-buttons button.on { background: rgba(225, 6, 0, 0.6); border-color: #fff; }
.tc-drag { position: absolute; left: 0; bottom: 0; width: 45vw; height: 65vh; display: none; }
.tc-drag .tc-track { position: absolute; left: max(24px, env(safe-area-inset-left)); bottom: max(34px, env(safe-area-inset-bottom)); width: 190px; height: 56px;
  border-radius: 28px; background: rgba(20, 22, 30, 0.45); border: 2px solid rgba(255, 255, 255, 0.35); }
.tc-drag .tc-knob { position: absolute; left: 67px; top: 4px; width: 52px; height: 44px; border-radius: 22px; background: rgba(255, 255, 255, 0.85); }
.tc-drag span { position: absolute; left: max(24px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); font-size: 11px; color: rgba(255,255,255,0.6); }
#touch[data-steer="drag"] .tc-buttons { display: none; }
#touch[data-steer="drag"] .tc-drag { display: block; }
.tc-pedals { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 12px; }
.tc-gas { width: 92px; height: 128px; border-radius: 18px; background: rgba(61, 220, 132, 0.28); border: 2px solid rgba(61, 220, 132, 0.85); font-size: 16px; }
.tc-brake { width: 84px; height: 100px; border-radius: 18px; background: rgba(255, 82, 82, 0.28); border: 2px solid rgba(255, 82, 82, 0.85); font-size: 14px; }
.tc-boost { position: absolute; right: 22px; bottom: 142px; width: 50px; height: 50px; border-radius: 50%; font-size: 12px;
  background: rgba(0, 176, 255, 0.3); border: 2px solid rgba(64, 196, 255, 0.85); }
.tc-actions { position: absolute; right: max(10px, env(safe-area-inset-right)); top: var(--tc-top, 120px); display: flex; gap: 8px; }
.tc-actions button { width: 46px; height: 46px; border-radius: 12px; font-size: 13px; background: rgba(12, 13, 18, 0.7); border: 1px solid rgba(255, 255, 255, 0.3); }

#rotate { display: none; position: fixed; inset: 0; z-index: 50; background: #0b0c10; color: var(--ink); flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px; }
#rotate .rotate-icon { font-size: 64px; color: var(--red); animation: tilt 1.6s ease-in-out infinite; }
#rotate p { font-size: 18px; font-weight: 700; }
@keyframes tilt { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(90deg); } }
@media (orientation: portrait) and (pointer: coarse) { body.driving #rotate { display: flex; } }

/* short (landscape phone) screens */
@media (max-height: 540px) {
  .brand h1 { font-size: 44px; }
  .brand-stripe { margin-bottom: 8px; }
  .brand .tag { margin: 4px 0 12px; font-size: 13px; }
  .menu-buttons { gap: 6px; }
  .menu-buttons button { padding: 8px 14px; font-size: 15px; }
  .menu-buttons button small { display: none; }
  .track-card { display: none; }
  .panel { padding: 12px 16px 16px; }
  .panel h2 { font-size: 20px; }
  .panel header { margin-bottom: 8px; }
  td, th { padding: 4px 6px; }
  .setting { padding: 6px 10px; }
  .banner { bottom: auto; top: 40%; }
}

@media (max-width: 700px) {
  .menu-wrap { margin-left: 0; }
  .controls-grid { grid-template-columns: 1fr; gap: 4px; }
  .controls-grid > div:nth-child(odd) { margin-top: 8px; }
  #hint { display: none; }
}

/* Garage panel (qualifying / practice) */
#garage { position: fixed; right: 14px; top: 150px; width: min(330px, calc(100vw - 28px)); background: var(--panel); border-top: 4px solid var(--red);
  padding: 12px 14px; pointer-events: auto; box-shadow: 0 12px 40px rgba(0,0,0,0.5); z-index: 5; }
#garage.hidden { display: none; }
.g-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.g-head b { font-size: 16px; font-weight: 900; font-style: italic; letter-spacing: 0.5px; }
.g-head span { font-size: 12px; color: var(--muted); }
.g-tyres { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.g-tyres button { display: flex; align-items: center; gap: 8px; padding: 7px 8px; background: rgba(255,255,255,0.06); border: 1px solid transparent; text-align: left; font-size: 13px; font-weight: 700; }
.g-tyres button small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.g-tyres button.on { border-color: #fff; background: rgba(255,255,255,0.14); }
.g-tyres button:disabled { opacity: 0.35; cursor: default; }
.tyre-dot { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 4px solid var(--c); background: #111; color: #fff; font-size: 10px; font-weight: 900;
  display: inline-flex; align-items: center; justify-content: center; }
.g-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.g-actions button { padding: 9px 8px; font-weight: 700; text-transform: uppercase; font-size: 13px; }
.g-actions button small { display: block; text-transform: none; font-weight: 400; font-size: 10.5px; opacity: 0.8; }
.g-actions button.primary { background: var(--red); }
.g-actions button:disabled { opacity: 0.35; cursor: default; }
.g-wait { font-size: 13px; color: #ffd54f; margin-top: 8px; min-height: 0; }
.g-wait:empty { display: none; }
.g-foot { margin-top: 8px; font-size: 11px; color: var(--muted); }
.g-foot kbd { font-size: 10px; padding: 0 4px; min-width: 0; }
body.touch .g-foot { display: none; }
.tyre-pick { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.tyre-pick button { flex: 1 1 220px; display: flex; gap: 10px; align-items: center; text-align: left; padding: 10px 12px; background: rgba(255,255,255,0.06);
  border: 2px solid transparent; font-size: 15px; font-weight: 700; }
.tyre-pick button small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.tyre-pick button.on { border-color: #fff; background: rgba(255,255,255,0.12); }
.team .pace { font-size: 11px; color: var(--muted); margin-left: 6px; }
@media (max-height: 520px) { #garage { top: auto; bottom: 10px; right: 10px; } }

/* Live commentary caption */
#commentary { position: fixed; right: 14px; top: 172px; width: min(330px, calc(100vw - 28px)); background: rgba(12, 13, 18, 0.82);
  border-left: 3px solid var(--red); padding: 8px 12px 10px; pointer-events: none; z-index: 4; transition: opacity .4s; }
#commentary.hidden { display: none; }
#commentary.idle { opacity: 0.35; }
#commentary .c-tag { display: flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 700; letter-spacing: 1px; color: var(--muted); }
#commentary .c-tag i { width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: c-live 1.2s infinite; }
@keyframes c-live { 50% { opacity: 0.25; } }
#commentary p { margin: 4px 0 0; font-size: 14px; line-height: 1.35; font-weight: 600; }
#commentary.urgent p { color: #ffd54f; }
body.touch #commentary { top: auto; bottom: 150px; right: 50%; transform: translateX(50%); width: min(420px, 70vw); }
@media (max-height: 520px) { #commentary { top: auto; bottom: 10px; } }

/* Menu footnote: unofficial / fictional */
.disclaimer { grid-column: 1 / -1; margin-top: 14px; font-size: 12px; line-height: 1.45; color: rgba(255, 255, 255, .55); max-width: 70ch; }
.disclaimer a { color: rgba(255, 255, 255, .75); }

/* Menu: account, likes and the fastest-laps board */
.menu-side { position: absolute; top: 18px; right: clamp(12px, 3vw, 40px); width: min(340px, 34vw); display: grid; gap: 12px; justify-items: end; z-index: 2; }
.mz-acct { justify-self: end; }
.mz-board { width: 100%; }
.mz-board.bx-board { background: rgba(14, 15, 22, .88); backdrop-filter: blur(6px); }
.mz-like { margin-top: 14px; }
.mz-like.bx-like button { background: rgba(255, 255, 255, .1); }
@media (max-width: 900px) {
  .menu-side { position: static; width: auto; justify-items: stretch; margin: 16px; }
  #menu { flex-direction: column; }
}
