/* ==========================================================================
   Turbo Kart Racers — page shell. The game itself draws into two canvases;
   CSS only handles layout, the boot screen and the touch pad.
   ========================================================================== */

:root {
  --gold: #ffd54a;
  --ink: #05070e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: #fff;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gl, #ui {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#gl { z-index: 1; }
#ui { z-index: 2; pointer-events: none; }

/* ------------------------------------------------------------ boot screen */
#loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 50% 20%, #17233f 0%, #070a13 55%, #04060c 100%);
  transition: opacity .5s ease, visibility .5s;
}
#loading.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.boot { text-align: center; }

.logo {
  font-family: Impact, "Arial Black", system-ui, sans-serif;
  font-size: clamp(42px, 9vw, 96px);
  line-height: .92;
  letter-spacing: .02em;
  background: linear-gradient(180deg, #fff7d0 0%, #ffcf3c 52%, #ff6a2c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 18px rgba(255, 140, 40, .35));
}
.logo span {
  display: block;
  font-size: clamp(20px, 4.2vw, 46px);
  background: linear-gradient(180deg, #eafcff 0%, #38c8ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 14px rgba(56, 200, 255, .3));
}

.bar {
  width: min(340px, 60vw);
  height: 6px;
  margin: 26px auto 12px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .14);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 40%;
  border-radius: 99px;
  background: linear-gradient(90deg, #4fd6ff, #ffd54a);
  animation: slide 1.15s ease-in-out infinite;
}
@keyframes slide {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}

.small { font-size: 13px; color: rgba(255, 255, 255, .5); margin: 0; }

.err { max-width: 520px; padding: 24px; text-align: center; }
.err h1 { font-size: 28px; margin: 0 0 12px; color: #ff8a7a; }
.err p { color: rgba(255, 255, 255, .75); line-height: 1.6; }
.err .retry {
  margin-top: 8px;
  padding: 12px 28px;
  font: 600 16px/1 "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--gold);
  border: 0;
  border-radius: 999px;
}

/* --------------------------------------------------- landscape prompt --
   A portrait phone gives a racing camera almost no horizontal view, so ask
   for landscape rather than shipping an unplayable framing. */
#rotate {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: none;
  place-items: center;
  background: #05070e;
  text-align: center;
}
#rotate p { margin: 14px 0 0; font-size: 20px; font-weight: 600; }
#rotate .small { font-size: 13px; color: rgba(255, 255, 255, .45); font-weight: 400; }
.phone {
  width: 54px;
  height: 92px;
  margin: 0 auto;
  border: 3px solid rgba(255, 255, 255, .8);
  border-radius: 10px;
  animation: rotatehint 1.8s ease-in-out infinite;
}
@keyframes rotatehint {
  0%, 30%   { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: grid; }
}

/* Zero-sized probe whose padding mirrors the safe-area insets; the HUD reads
   it with getComputedStyle so canvas-drawn UI can dodge a notch too. */
#safe-probe {
  position: fixed;
  top: 0; left: 0;
  width: 0; height: 0;
  visibility: hidden;
  pointer-events: none;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* -------------------------------------------------------- touch controls */
.touch-controls {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  pointer-events: none;
}
.touch-controls.visible { display: block; }

/* Steering: the entire left half is live. A floating knob means the thumb
   never has to find a fixed centre — the standard for mobile racers.
   Everything is inset by the safe area so a notch or the home indicator
   never sits on top of a control. */
.touch-steer {
  position: absolute;
  left: env(safe-area-inset-left, 0px);
  top: 20%;
  width: calc(50% - env(safe-area-inset-left, 0px));
  height: calc(80% - env(safe-area-inset-bottom, 0px));
  pointer-events: auto;
}
.touch-knob-base {
  position: absolute;
  width: 140px;
  height: 140px;
  margin: -70px 0 0 -70px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .18);
  background: radial-gradient(circle, rgba(255, 255, 255, .07), rgba(255, 255, 255, .02));
  opacity: 0;
  transition: opacity .12s ease;
  pointer-events: none;
}
.touch-knob-base.active { opacity: 1; }
.touch-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 62px; height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .5);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .45);
}
.touch-steer-hint {
  position: absolute;
  left: calc(4vw + env(safe-area-inset-left, 0px));
  bottom: 10%;
  color: rgba(255, 255, 255, .34);
  font-size: 13px;
  pointer-events: none;
  transition: opacity .3s;
}
.touch-steer-hint.hidden { opacity: 0; }

.touch-right {
  position: absolute;
  right: calc(2.5vw + env(safe-area-inset-right, 0px));
  bottom: calc(6vh + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: flex-end;
  gap: 14px;
  pointer-events: none;
}
.touch-btn {
  pointer-events: auto;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .26);
  background: rgba(10, 16, 28, .55);
  color: #fff;
  font: 600 15px/1 "PingFang SC", system-ui, sans-serif;
  backdrop-filter: blur(4px);
  /* Sizes are per-button below; nothing generic, so a later media query
     cannot silently shrink the primary action. */
  width: 84px; height: 84px;
}
.touch-btn.down { background: rgba(255, 213, 74, .38); border-color: var(--gold); }
/* Drift is the primary right-thumb action now that throttle is automatic. */
.touch-drift {
  width: 124px; height: 124px;
  font-size: 20px;
  border-color: rgba(120, 200, 255, .6);
  background: rgba(20, 44, 70, .55);
}
.touch-item  { width: 88px; height: 88px; border-color: rgba(255, 213, 74, .45); font-size: 16px; }
.touch-brake { width: 78px; height: 78px; font-size: 14px; }

/* Rocket start: the entire screen is the launch pad while the lights are on,
   and it disappears the moment the race starts so it never eats a steer or a
   drift. It sits above the other controls only during the countdown. */
.touch-launch {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
}
.touch-controls.countdown .touch-launch { display: block; pointer-events: auto; }

/* Landscape phones. Only the specific buttons are resized — never .touch-btn,
   which would clobber the per-button sizes above. */
@media (max-height: 560px) {
  .touch-right { gap: 11px; bottom: calc(4vh + env(safe-area-inset-bottom, 0px)); }
  .touch-drift { width: 108px; height: 108px; font-size: 18px; }
  .touch-item  { width: 76px; height: 76px; font-size: 14px; }
  .touch-brake { width: 68px; height: 68px; font-size: 13px; }
  .touch-knob-base { width: 124px; height: 124px; margin: -62px 0 0 -62px; }
  .touch-knob { width: 54px; height: 54px; margin: -27px 0 0 -27px; }
}
@media (max-height: 420px) {
  .touch-right { gap: 9px; }
  .touch-drift { width: 96px; height: 96px; font-size: 16px; }
  .touch-item  { width: 68px; height: 68px; font-size: 13px; }
  .touch-brake { width: 60px; height: 60px; font-size: 12px; }
}
