/* =====================================================================
   PODUTTY RACERS  -  team colours from podutty.co.uk
   ===================================================================== */
:root {
  --dark: #07090d;
  --panel: #10141c;
  --line: #232a38;
  --pink: #f9214e;
  --cyan: #02e6f9;
  --text: #f4fefe;
  --dim: #8b94a3;
  --green: #3fb950;
  --purple: #a66bff;
  --gold: #ffd23f;
  --heavy: "Arial Black", "Segoe UI Black", "Segoe UI", Roboto, system-ui, sans-serif;
  --plain: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--dark);
  color: var(--text);
  font-family: var(--heavy);
  font-weight: 900;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

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

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------------- screens ---------------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2vh, 18px);
  padding: max(12px, var(--sat)) max(12px, var(--sar)) max(12px, var(--sab)) max(12px, var(--sal));
  background: radial-gradient(ellipse at 50% 40%, rgba(7, 9, 13, 0.25), rgba(7, 9, 13, 0.78));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 10;
}
/* centred when it fits, scrollable when it doesn't */
.screen > * { flex-shrink: 0; }
.screen::before, .screen::after { content: ''; flex: 1 0 0; }
.screen.dim { background: rgba(7, 9, 13, 0.72); }

h2 {
  margin: 0;
  font-size: clamp(20px, 4vw, 38px);
  font-style: italic;
  letter-spacing: 0.01em;
  text-align: center;
  text-shadow: 0 3px 0 #000;
}
.step {
  display: inline-block;
  background: var(--pink);
  color: #fff;
  padding: 0 0.4em;
  margin-right: 0.3em;
  transform: skewX(-12deg);
  font-size: 0.8em;
}

/* ---------------- the logo (in the style of the team's) ---------------- */
.logo {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.12em 0.9em 0.3em;
  font-style: italic;
  line-height: 0.9;
  cursor: default;
}
.logo::before {
  content: '';
  position: absolute;
  inset: 0;
  background: #000;
  clip-path: polygon(4% 0, 100% 0, 95% 62%, 92% 100%, 0 100%, 3% 55%);
  box-shadow: 0 0 0 3px #000;
  z-index: -1;
}
.logo-a {
  font-size: clamp(46px, 11vw, 128px);
  letter-spacing: -0.03em;
  transform: skewX(-8deg);
  text-shadow: 0 0 30px rgba(2, 230, 249, 0.25);
}
.logo-b {
  margin-top: 0.35em;
  font-size: clamp(14px, 3vw, 34px);
  letter-spacing: 0.7em;
  margin-right: -0.7em;
  font-weight: 700;
  font-family: var(--plain);
}
.sw {
  position: absolute;
  left: 4%;
  height: 0.06em;
  font-size: clamp(46px, 11vw, 128px);
  pointer-events: none;
}
.sw1 { bottom: 30%; width: 82%; background: linear-gradient(90deg, var(--cyan), #fff 50%, var(--pink)); clip-path: polygon(0 100%, 100% 0, 100% 100%); }
.sw2 { bottom: 23.5%; left: 10%; width: 85%; background: var(--pink); clip-path: polygon(0 100%, 100% 0, 100% 40%); }
.tagline { font-family: var(--plain); font-style: italic; font-weight: 600; color: var(--dim); font-size: 12px; }

/* ---------------- buttons ---------------- */
.menu {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  justify-items: center;
}
.btn {
  min-width: 11em;
  padding: 0.55em 1.4em;
  font-size: clamp(15px, 2.4vw, 22px);
  font-style: italic;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--line);
  transform: skewX(-12deg);
  transition: transform 0.08s, border-color 0.1s, background 0.1s;
}
.btn > span { display: inline-block; transform: skewX(12deg); }
.btn:hover, .btn:focus-visible { border-color: var(--cyan); outline: none; }
.btn:active { transform: skewX(-12deg) scale(0.96); }
.btn.primary { background: var(--pink); border-color: var(--pink); box-shadow: 0 0 26px rgba(249, 33, 78, 0.45); }
.btn.primary:hover { border-color: #fff; }
.btn.ghost { background: rgba(7, 9, 13, 0.4); }
.row { display: flex; gap: 10px; justify-content: center; }
.row.wrap { flex-wrap: wrap; }
.row .btn { min-width: 8em; }

.round-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(7, 9, 13, 0.75);
  border: 2px solid var(--line);
  font-size: 15px;
  display: grid;
  place-items: center;
  padding: 0;
}
.sound-btn { margin-top: 4px; font-size: 20px; }
.round-btn.corner { position: absolute; top: max(10px, var(--sat)); right: max(10px, var(--sar)); font-size: 20px; margin: 0; }

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  border: 2px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(7, 9, 13, 0.6);
}
.seg button {
  background: transparent;
  border: 0;
  padding: 0.45em 1.1em;
  font-size: clamp(12px, 1.7vw, 16px);
  font-style: italic;
  color: var(--dim);
}
.seg button.on { background: var(--cyan); color: var(--dark); }
.seg.small button { font-size: 12px; padding: 0.35em 1em; }

.counter { font-size: clamp(12px, 1.8vw, 17px); color: var(--dim); letter-spacing: 0.04em; text-align: center; }
.counter b { color: var(--cyan); font-size: 1.35em; margin-left: 0.25em; }
.counter .src { display: block; font-family: var(--plain); font-weight: 600; font-size: 11px; letter-spacing: 0; margin-top: 2px; }

/* ---------------- cards (drivers, cars, tracks) ---------------- */
.cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(8px, 1.4vw, 16px);
  max-width: 1160px;
}
.card {
  position: relative;
  width: clamp(132px, 21vw, 230px);
  padding: 10px 10px 12px;
  background: rgba(16, 20, 28, 0.92);
  border: 2px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  transition: transform 0.1s, border-color 0.1s;
}
.card:hover, .card:focus-visible { transform: translateY(-3px); border-color: var(--cyan); outline: none; }
.card:active { transform: scale(0.97); }
.card.sel { border-color: var(--pink); box-shadow: 0 0 22px rgba(249, 33, 78, 0.35); }
.card canvas { width: 100%; height: clamp(64px, 15vh, 140px); display: block; }
.card .name { font-size: clamp(16px, 2.3vw, 24px); font-style: italic; }
.card .meta { font-family: var(--plain); font-weight: 700; font-size: 12px; color: var(--dim); }
.card .blurb { font-family: var(--plain); font-weight: 600; font-size: 12px; color: var(--text); opacity: 0.85; min-height: 2.4em; }
.card .tag {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--line);
  color: var(--text);
}
.card .tag.hyper { background: var(--pink); }
.card .tag.lvl { background: var(--cyan); color: var(--dark); }
.card .rec { font-family: var(--mono); font-weight: 700; font-size: 12px; color: var(--cyan); }
.card .rec span { color: var(--dim); font-family: var(--plain); }
.cards.drivers .card { width: clamp(120px, 20vw, 200px); }
.cards.drivers .card .name { font-size: clamp(20px, 3vw, 30px); }

.stats { width: 100%; display: grid; gap: 3px; }
.stat { display: grid; grid-template-columns: 4.2em 1fr; align-items: center; gap: 6px; font-family: var(--plain); font-weight: 700; font-size: 10px; color: var(--dim); text-align: left; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--pink)); border-radius: 3px; }

.card.locked canvas, .card.locked .stats, .card.locked .blurb { opacity: 0.35; filter: grayscale(0.8); }
.lock {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  font-size: 12px;
  background: rgba(7, 9, 13, 0.9);
  border: 2px solid var(--pink);
  border-radius: 8px;
  padding: 6px;
}

/* ---------------- panels and tables ---------------- */
.panel {
  width: min(780px, 100%);
  background: rgba(16, 20, 28, 0.94);
  border: 2px solid var(--line);
  border-top: 4px solid var(--pink);
  border-radius: 14px;
  padding: clamp(12px, 2.4vw, 24px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.sub { font-family: var(--plain); font-weight: 700; color: var(--dim); font-size: 14px; text-align: center; }
.table { width: 100%; display: grid; gap: 6px; }
.trow {
  display: grid;
  grid-template-columns: 2.2em 2.6em 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  background: #0b0e14;
  border-left: 5px solid var(--line);
  transform: skewX(-8deg);
}
.trow > * { transform: skewX(8deg); }
.trow.me { background: rgba(249, 33, 78, 0.16); }
.trow .p { font-size: 20px; font-style: italic; }
.trow canvas { width: 2.6em; height: 2.2em; }
.trow .who { min-width: 0; }
.trow .who b { display: block; font-size: 17px; font-style: italic; }
.trow .who span { display: block; font-family: var(--plain); font-weight: 600; font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow .t { text-align: right; font-family: var(--mono); font-weight: 700; font-size: 16px; }
.trow .t span { display: block; font-size: 12px; color: var(--dim); }
.trow .t.none { color: var(--dim); font-family: var(--plain); font-style: italic; font-size: 13px; }

.badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.badge { color: #fff; padding: 0.35em 0.9em; border-radius: 6px; font-size: clamp(12px, 1.7vw, 15px); font-style: italic; transform: skewX(-10deg); }
.badge.purple { background: var(--purple); box-shadow: 0 0 20px rgba(166, 107, 255, 0.5); }
.badge.green { background: var(--green); }
.badge.gold { background: var(--gold); color: var(--dark); }
.badge.dark { background: var(--line); color: var(--dim); }

.stats.team { grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }
.dstat { background: #0b0e14; border-radius: 8px; padding: 6px; text-align: center; border-bottom: 3px solid var(--line); }
.dstat b { display: block; font-style: italic; font-size: 15px; }
.dstat span { display: block; font-family: var(--plain); font-weight: 700; font-size: 11px; color: var(--dim); }

.howto { max-width: 820px; }
.how-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.how-grid div { font-family: var(--plain); font-weight: 600; font-size: 14px; line-height: 1.35; background: #0b0e14; border-radius: 10px; padding: 10px 12px; border-left: 4px solid var(--cyan); }
.how-grid b { font-family: var(--heavy); font-weight: 900; }
.small-print { margin: 0; font-family: var(--plain); font-weight: 600; font-size: 12px; color: var(--dim); text-align: center; }
.t-pink { color: var(--pink); } .t-cyan { color: var(--cyan); } .t-purple { color: var(--purple); } .t-green { color: var(--green); }

/* ---------------- race HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-left { position: absolute; left: max(12px, var(--sal)); top: max(8px, var(--sat)); }
#hud-pos { font-size: clamp(34px, 6.5vw, 66px); font-style: italic; line-height: 1; text-shadow: 0 3px 0 #000, 0 0 14px rgba(0, 0, 0, 0.6); }
#hud-pos small { font-size: 0.45em; color: var(--text); opacity: 0.75; }
#hud-lap { display: inline-block; margin-top: 4px; padding: 2px 10px; font-size: clamp(13px, 1.9vw, 19px); font-style: italic; background: var(--pink); transform: skewX(-12deg); }
.hud-mid { position: absolute; top: max(8px, var(--sat)); left: 50%; transform: translateX(-50%); text-align: center; }
#hud-time { font-family: var(--mono); font-weight: 800; font-size: clamp(20px, 3.4vw, 34px); padding: 2px 12px; background: rgba(7, 9, 13, 0.78); border-radius: 6px; border-bottom: 3px solid var(--cyan); }
#hud-best { margin-top: 3px; font-size: clamp(11px, 1.5vw, 14px); text-shadow: 0 2px 0 #000; }
#hud-delta { margin-top: 4px; font-family: var(--mono); font-weight: 800; font-size: clamp(18px, 2.8vw, 28px); text-shadow: 0 2px 0 #000; opacity: 0; transition: opacity 0.3s; }
#hud-delta.show { opacity: 1; }
.c-purple { color: var(--purple); } .c-green { color: #5cf07a; } .c-red { color: #ff5a6e; } .c-white { color: #fff; } .c-cyan { color: var(--cyan); } .c-gold { color: var(--gold); } .c-pink { color: var(--pink); }
.hud-right { position: absolute; right: max(12px, var(--sar)); top: max(8px, var(--sat)); display: flex; gap: 8px; align-items: flex-start; }
#minimap { width: clamp(92px, 14vw, 150px); height: auto; aspect-ratio: 13 / 9; background: rgba(7, 9, 13, 0.55); border: 1px solid var(--line); border-radius: 8px; }
#hud-bottom { position: absolute; bottom: max(8px, var(--sab)); left: 50%; transform: translateX(-50%); text-align: center; white-space: nowrap; }
#hud-items { font-size: clamp(18px, 2.6vw, 26px); min-height: 1.2em; letter-spacing: 2px; text-shadow: 0 2px 0 #000; }
#hud-items .oil { display: inline-block; font-size: 0.65em; padding: 0 0.4em; margin-left: 6px; background: #222; border: 2px solid #a66bff; border-radius: 6px; vertical-align: middle; }
#hud-speed { font-size: clamp(22px, 3.6vw, 38px); font-style: italic; line-height: 1; text-shadow: 0 3px 0 #000; }
#hud-speed small { font-size: 0.4em; margin-left: 4px; opacity: 0.8; }
#hud-keys { margin-top: 2px; font-family: var(--plain); font-weight: 600; font-size: 11px; color: rgba(255, 255, 255, 0.7); text-shadow: 0 1px 0 #000; }
body.touch .keys-only { display: none; }
body:not(.touch) .touch-only { display: none; }

#lights {
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: clamp(6px, 1.4vw, 12px);
  padding: 10px 14px;
  background: var(--panel);
  border: 3px solid #000;
  border-radius: 12px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.4);
}
#lights.show { display: flex; }
#lights i { width: clamp(26px, 5vw, 46px); aspect-ratio: 1; border-radius: 50%; background: #2a0d12; box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.6); }
#lights i.on { background: #ff1a3c; box-shadow: 0 0 18px #ff1a3c, inset 0 -3px 6px rgba(0, 0, 0, 0.3); }
#lights.go i { background: var(--green); box-shadow: 0 0 18px var(--green); }

#banner, #sub-banner {
  position: absolute;
  left: 50%;
  white-space: nowrap;
  font-style: italic;
  text-align: center;
  opacity: 0;
  pointer-events: none;
}
#banner { top: 38%; font-size: clamp(30px, 6.4vw, 70px); text-shadow: 0 4px 0 #000, 0 0 30px rgba(0, 0, 0, 0.6); transform: translate(-50%, -50%) skewX(-10deg); }
#sub-banner { top: calc(38% + clamp(36px, 7vw, 74px)); font-size: clamp(14px, 2.3vw, 23px); text-shadow: 0 2px 0 #000; transform: translate(-50%, -50%); }
#banner.show { animation: pop 1.5s ease-out forwards; }
#sub-banner.show { animation: fadeup 1.8s ease-out forwards; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) skewX(-10deg) scale(2.2); }
  12% { opacity: 1; transform: translate(-50%, -50%) skewX(-10deg) scale(0.92); }
  20% { transform: translate(-50%, -50%) skewX(-10deg) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) skewX(-10deg) scale(1); }
}
@keyframes fadeup {
  0% { opacity: 0; } 10% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; }
}

/* ---------------- touch buttons ---------------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
body:not(.touch) #touch { display: none; }
.tpad { position: absolute; bottom: max(14px, var(--sab)); display: flex; gap: clamp(8px, 2vmin, 16px); align-items: flex-end; }
.tpad.left { left: max(14px, var(--sal)); }
.tpad.right { right: max(14px, var(--sar)); }
.tbtn {
  pointer-events: auto;
  width: clamp(64px, 14vmin, 108px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(16, 20, 28, 0.5);
  border: 3px solid rgba(244, 254, 254, 0.35);
  font-size: clamp(22px, 5vmin, 36px);
  line-height: 1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.tbtn small { display: block; font-size: clamp(8px, 1.6vmin, 11px); font-family: var(--plain); font-weight: 700; opacity: 0.8; margin-top: 2px; }
.tpad.left .tbtn { border-radius: 24px; width: clamp(72px, 16vmin, 124px); }
#t-brake { font-size: clamp(12px, 2.6vmin, 17px); font-style: italic; }
.tbtn.turbo { background: rgba(249, 33, 78, 0.55); border-color: var(--pink); }
.tbtn.turbo small { font-size: clamp(11px, 2.4vmin, 15px); font-family: var(--heavy); }
.tbtn.turbo.empty { opacity: 0.4; }
.tbtn.small { width: clamp(52px, 11vmin, 80px); font-size: clamp(12px, 2.6vmin, 16px); background: rgba(80, 40, 120, 0.7); border-color: var(--purple); align-self: flex-start; }
.tbtn.down { background: rgba(2, 230, 249, 0.38); border-color: var(--cyan); transform: scale(0.95); }
@media (orientation: portrait) {
  .tpad.right { flex-direction: column-reverse; align-items: flex-end; }
  .tbtn.small { align-self: auto; }
}

/* ---------------- odds and ends ---------------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--panel);
  border: 2px solid var(--cyan);
  border-radius: 10px;
  font-size: 15px;
  font-style: italic;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 20;
  text-align: center;
}
#toast.show { opacity: 1; }

#rotate-hint {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(10px, var(--sab));
  text-align: center;
  font-family: var(--plain);
  font-weight: 700;
  font-size: 13px;
  color: var(--cyan);
  z-index: 11;
  pointer-events: none;
}
@media (orientation: portrait) and (max-width: 700px) {
  body.touch.menus #rotate-hint { display: block; }
}

/* short screens (phones on their side) */
/* sideways screens: all six cars in one row, so nothing scrolls off */
@media (orientation: landscape) {
  .cards.cars { flex-wrap: nowrap; width: 100%; max-width: 1260px; }
  .cards.cars .card { flex: 1 1 0; min-width: 0; max-width: 200px; }
}
@media (max-height: 520px) {
  .screen { gap: 8px; }
  .menu { grid-template-columns: 1fr 1fr; }
  .btn { min-width: 9.5em; padding: 0.45em 1em; }
  .logo-a, .sw { font-size: clamp(40px, 9vw, 80px); }
  .card { padding: 6px 8px 8px; gap: 2px; }
  .card canvas { height: clamp(46px, 13vh, 80px); }
  .card .blurb { display: none; }
  .cards { gap: 8px; }
  .cards.cars .card { width: clamp(108px, 14.8vw, 190px); }
  .cards.cars .card .name { font-size: clamp(13px, 1.9vw, 18px); }
  .card canvas { height: clamp(40px, 12vh, 76px); }
  .lock { font-size: 10px; padding: 4px; bottom: 6px; }
  h2 { font-size: clamp(18px, 3.4vw, 30px); }
  .panel { padding: 10px 14px; gap: 6px; }
  .trow { padding: 2px 10px; }
  .trow .who b { font-size: 15px; }
  .how-grid div { font-size: 12px; padding: 6px 10px; }
}
/* narrow phones held upright */
@media (max-width: 560px) {
  .hud-right { flex-direction: column-reverse; align-items: flex-end; }
  #minimap { width: 88px; }
  #banner { font-size: clamp(26px, 9vw, 44px); }
  #sub-banner { white-space: normal; width: 92vw; }
  body.touch #hud-bottom { bottom: calc(max(14px, var(--sab)) + 84px); }
}
@media (max-width: 420px) {
  .cards.cars .card, .cards.tracks .card { width: calc(50% - 6px); }
  .cards.drivers .card { width: calc(50% - 6px); }
  .stats.team { grid-template-columns: repeat(2, 1fr); }
}
