:root {
  --gt-yellow: #ffd84a;
  --gt-orange: #ff8a1f;
  --gt-blue: #2f6fd6;
  --gt-cyan: #7fd7ff;
  --gt-white: #f4f4f4;
  --gt-red: #e6382c;
  --shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  --font: "Arial Narrow", "Helvetica Neue", Arial, "Liberation Sans Narrow", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  font-family: var(--font);
  color: var(--gt-white);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { font-style: italic; font-weight: 700; text-shadow: var(--shadow); letter-spacing: 0.02em; }

.hud-top-left { position: absolute; top: 18px; left: 22px; }
.hud-top-right { position: absolute; top: 18px; right: 22px; text-align: right; }
.hud-bottom-left { position: absolute; bottom: 22px; left: 22px; }
.hud-bottom-right { position: absolute; bottom: 22px; right: 22px; text-align: right; }

.course {
  font-size: clamp(18px, 3.2vw, 30px);
  color: var(--gt-yellow);
  text-transform: uppercase;
}
.course-sub { font-size: clamp(11px, 1.6vw, 15px); color: var(--gt-cyan); }

.label { font-size: clamp(10px, 1.5vw, 14px); color: var(--gt-cyan); text-transform: uppercase; }
.score { font-size: clamp(26px, 4.4vw, 44px); color: var(--gt-white); font-variant-numeric: tabular-nums; line-height: 1; }
.combo { font-size: clamp(14px, 2.4vw, 22px); color: var(--gt-orange); min-height: 1.3em; }

.speed-row { display: flex; align-items: baseline; gap: 8px; }
.speed { font-size: clamp(44px, 8vw, 84px); line-height: 0.9; color: var(--gt-white); font-variant-numeric: tabular-nums; }
.unit { font-size: clamp(14px, 2.2vw, 22px); color: var(--gt-yellow); }
.gear-row { margin-top: 4px; }
.gear { font-size: clamp(16px, 2.6vw, 26px); color: var(--gt-yellow); }

.stat { margin-top: 4px; font-size: clamp(14px, 2.2vw, 22px); display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.value { color: var(--gt-white); font-variant-numeric: tabular-nums; }
.bar {
  display: inline-block;
  width: clamp(110px, 18vw, 200px);
  height: 12px;
  border: 2px solid #000;
  background: #222;
  box-shadow: 0 0 0 1px #777 inset;
  transform: skewX(-12deg);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #35d05a, #ffd84a 60%, #e6382c);
  transition: width 0.15s ease-out;
}

.popup {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  font-size: clamp(24px, 5vw, 54px);
  color: var(--gt-yellow);
  opacity: 0;
  text-transform: uppercase;
  white-space: nowrap;
}
.popup.show { animation: pop 0.9s ease-out forwards; }
.popup.bad { color: var(--gt-red); }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  40% { transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

.banner {
  position: absolute;
  left: 0; right: 0;
  top: 11%;
  text-align: center;
  font-size: clamp(16px, 3vw, 30px);
  color: var(--gt-white);
  background: linear-gradient(90deg, transparent, rgba(47,111,214,0.75) 30%, rgba(47,111,214,0.75) 70%, transparent);
  padding: 4px 0;
  opacity: 0;
  text-transform: uppercase;
}
.banner.show { animation: banner 2.4s ease-in-out forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translateX(-30%); }
  18% { opacity: 1; transform: translateX(0); }
  78% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(30%); }
}

/* ---------- Controles de toque ---------- */
.touch-only { display: none; }
body.touch .touch-only { display: flex; }
#touch { z-index: 5; }
.tbtn {
  position: absolute;
  bottom: 22px;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.55);
  background: rgba(255,255,255,0.12);
  color: var(--gt-white);
  font: 700 22px var(--font);
  font-style: italic;
  text-shadow: var(--shadow);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(2px);
}
.tbtn.on { background: rgba(255,216,74,0.5); border-color: var(--gt-yellow); }
.t-left { left: 18px; }
.t-right { left: 116px; }
.t-brake { right: 128px; font-size: 16px; }
.t-gas { right: 18px; width: 98px; height: 98px; bottom: 16px; font-size: 12px; letter-spacing: 0.02em; background: rgba(53,208,90,0.18); }
.t-gas.on { background: rgba(53,208,90,0.55); border-color: #35d05a; }
.t-drift { right: 40px; bottom: 126px; width: 80px; height: 80px; font-size: 15px; background: rgba(255,80,190,0.16); }
.t-drift.on { background: rgba(255,80,190,0.55); border-color: #ff4fb8; }
/* Em telas de toque o HUD inferior sobe para não ficar embaixo dos botões. */
body.touch .hud-bottom-left { bottom: 128px; }
body.touch .hud-bottom-right { bottom: 216px; }
/* Paisagem baixa (celular deitado): DRIFT vai para a esquerda do FREIO e o HUD desce. */
@media (orientation: landscape) and (max-height: 520px) {
  .t-drift { right: 226px; bottom: 22px; width: 86px; height: 86px; }
  body.touch .hud-bottom-right { bottom: 128px; }
}
body.touch .hud-bottom-left { left: 14px; }
body.touch .hud-bottom-right { right: 14px; }

/* ---------- Telas ---------- */
.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  background: radial-gradient(ellipse at center, rgba(30,10,50,0.55), rgba(0,0,0,0.85));
}
.title-box { text-align: center; padding: 24px; max-width: 760px; width: 100%; }

.title-kicker { font-size: clamp(11px, 1.6vw, 15px); letter-spacing: 0.4em; color: var(--gt-cyan); text-shadow: var(--shadow); }

h1.title {
  margin: 8px 0 4px;
  font-size: clamp(54px, 13vw, 128px);
  line-height: 0.88;
  font-style: italic;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff 0%, #ffd1f2 30%, #ff4fb8 52%, #7a1fa0 53%, #45c8ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(3px 3px 0 #000) drop-shadow(0 0 14px rgba(255,80,190,0.45));
}
h1.title.small { font-size: clamp(40px, 9vw, 86px); }

.title-sub { font-size: clamp(13px, 2.2vw, 20px); letter-spacing: 0.3em; color: var(--gt-yellow); text-shadow: var(--shadow); font-weight: 700; }

.rules { margin: 22px auto 10px; font-size: clamp(14px, 2vw, 18px); text-shadow: var(--shadow); line-height: 1.5; }
.rules p { margin: 0; }
.rules b { color: var(--gt-yellow); }

.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; font-size: clamp(12px, 1.8vw, 15px); text-shadow: var(--shadow); margin-top: 10px; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 5px;
  margin-right: 3px;
  border: 1px solid #aaa;
  border-bottom-width: 3px;
  border-radius: 3px;
  background: #222;
  font-family: inherit;
  font-size: 0.9em;
  text-shadow: none;
}

.press { margin-top: 28px; font-size: clamp(14px, 2.2vw, 20px); font-weight: 700; font-style: italic; color: var(--gt-white); text-shadow: var(--shadow); letter-spacing: 0.1em; }
.blink { animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

.best { margin-top: 10px; font-size: clamp(12px, 1.8vw, 15px); color: var(--gt-cyan); text-shadow: var(--shadow); }

.results { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 32px; margin: 18px auto 0; max-width: 420px; text-shadow: var(--shadow); }
.result { display: flex; justify-content: space-between; font-size: clamp(16px, 2.6vw, 24px); font-weight: 700; font-style: italic; }

.loading { font-size: 20px; letter-spacing: 0.3em; color: var(--gt-cyan); text-shadow: var(--shadow); }
