/* ============ APEX RACER 3D — UI styles ============ */
:root {
  --accent: #ff5722;
  --accent2: #ffc107;
  --bg-dark: rgba(10, 12, 24, 0.72);
  --text: #f4f6ff;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0a0c18;
  font-family: 'Segoe UI', 'Roboto', system-ui, sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

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

.hidden { display: none !important; }

.overlay {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: space-between;
  padding: max(3vh, env(safe-area-inset-top)) 4vw max(3vh, env(safe-area-inset-bottom));
  z-index: 20;
  /* portals embed the game in short iframes — if the menu is ever taller
     than the frame, scroll instead of clipping the buttons */
  overflow-y: auto;
}
.overlay > * { flex-shrink: 0; }

.glass {
  background: var(--bg-dark);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

/* ---------- Main menu ---------- */
.menu-top { text-align: center; pointer-events: none; }

.game-title {
  font-size: clamp(2.4rem, 7vw, 4.5rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  font-style: italic;
  background: linear-gradient(100deg,
    #ffffff 18%, #ffd9c4 36%, var(--accent2) 46%, #ffffff 60%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: title-shine 5.5s linear infinite;
  filter: drop-shadow(0 4px 20px rgba(255, 87, 34, 0.5)) drop-shadow(0 2px 0 #7a1f00);
}
.game-title span {
  background: linear-gradient(100deg,
    var(--accent) 25%, #ffab6b 48%, var(--accent) 70%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: title-shine 5.5s linear infinite;
}
@keyframes title-shine { to { background-position: -220% 0; } }

/* menu blocks glide in when the menu appears */
.menu-top { animation: menu-rise 0.5s ease-out both; }
.car-select { animation: menu-rise 0.55s ease-out 0.08s both; }
.track-select { animation: menu-rise 0.55s ease-out 0.16s both; }
#menu .menu-bottom { animation: menu-rise 0.55s ease-out 0.24s both; }
@keyframes menu-rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

.game-subtitle {
  margin-top: 4px;
  font-size: clamp(0.85rem, 2.2vw, 1.1rem);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  opacity: 0.85;
}

.car-select {
  display: flex; align-items: center; gap: clamp(8px, 3vw, 28px);
  width: 100%; max-width: 560px;
}

.car-info {
  flex: 1;
  padding: clamp(12px, 2.5vw, 22px) clamp(16px, 3vw, 28px);
  text-align: center;
}
.car-info h2 { font-size: clamp(1.2rem, 3.5vw, 1.7rem); font-style: italic; letter-spacing: 0.05em; }
#car-name::before {
  content: '';
  display: inline-block;
  width: 0.6em; height: 0.6em;
  border-radius: 50%;
  margin-right: 0.4em;
  background: var(--car-c, #fff);
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 10px var(--car-c, transparent);
}
.car-desc { font-size: 0.85rem; opacity: 0.75; margin: 4px 0 12px; min-height: 2.2em; }

.stat-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em;
  margin: 6px 0;
}
.stat-row span { width: 92px; text-align: right; opacity: 0.8; flex-shrink: 0; }
.stat-bar {
  flex: 1; height: 8px; border-radius: 4px;
  background: rgba(255, 255, 255, 0.12); overflow: hidden;
}
.stat-bar div {
  height: 100%; border-radius: 4px; width: 50%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.35s ease;
}

.arrow-btn {
  width: clamp(44px, 9vw, 58px); height: clamp(44px, 9vw, 58px);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--bg-dark);
  color: var(--text); font-size: 1.3rem;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  flex-shrink: 0;
}
.arrow-btn:hover, .arrow-btn:active { background: var(--accent); transform: scale(1.08); }

/* ---------- Track selector ---------- */
.track-select {
  display: flex; align-items: center; gap: clamp(8px, 2vw, 18px);
  width: 100%; max-width: 470px;
  margin-top: 10px;
}
.track-info {
  flex: 1; padding: 10px 18px; text-align: center; border-radius: 12px;
}
.track-info h3 { font-size: clamp(1rem, 2.8vw, 1.2rem); font-style: italic; letter-spacing: 0.04em; }
.track-info p { font-size: 0.75rem; opacity: 0.75; margin-top: 2px; }
#track-meta { color: var(--accent2); opacity: 0.95; font-variant-numeric: tabular-nums; }

.arrow-btn.mini {
  width: 38px; height: 38px; font-size: 1rem;
}

.champ-total {
  font-size: 0.85rem; letter-spacing: 0.06em;
  color: var(--accent2);
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
}

.result-points {
  font-size: 0.95rem; font-weight: 700; color: var(--accent2);
  letter-spacing: 0.04em;
}

.big-btn.champ {
  background: linear-gradient(135deg, #1565c0, #4a148c);
  box-shadow: 0 6px 24px rgba(74, 20, 140, 0.5);
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  padding: 12px 34px;
}
.big-btn.champ:hover, .big-btn.champ:active {
  box-shadow: 0 10px 32px rgba(74, 20, 140, 0.7);
}

.champ-standings { margin-top: 4px; }
.champ-standings h3 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em;
  opacity: 0.7; margin-bottom: 4px;
}
.champ-standings .result-row { padding: 4px 4px; font-size: 0.9rem; }
.champ-standings .final-pos {
  margin-top: 8px; font-size: 1.05rem; font-weight: 800;
  color: var(--accent2); font-style: italic;
}

.panel { max-height: 92vh; overflow-y: auto; }

/* ---------- Mode selector ---------- */
.mode-select {
  display: flex; gap: 6px;
  background: var(--bg-dark);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  padding: 4px;
}
.mode-btn {
  padding: 8px 16px;
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em;
  color: var(--text); background: transparent;
  border: none; border-radius: 9px;
  cursor: pointer; opacity: 0.65;
  transition: background 0.15s, opacity 0.15s;
}
.mode-btn:hover { opacity: 0.9; }
.mode-btn.active {
  background: linear-gradient(135deg, var(--accent), #d32f2f);
  opacity: 1;
}

/* ---------- Elimination banner ---------- */
#elim-banner {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  padding: 5px 18px; border-radius: 10px;
  background: rgba(10, 12, 24, 0.72);
  border: 1px solid rgba(255, 87, 34, 0.5);
  font-size: 0.95rem; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--accent2);
}
#elim-banner.urgent { color: #ff5252; animation: blink 0.5s steps(2) infinite; }

/* ---------- Rotate hint (touch devices in portrait only) ---------- */
#rotate-hint {
  display: none;
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 10, 20, 0.92);
  align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 800; text-align: center;
  padding: 10vw;
}
@media (orientation: portrait) {
  body.touch #rotate-hint { display: flex; }
}

.menu-bottom { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.menu-row { display: flex; gap: 12px; }

.big-btn {
  padding: 16px 58px;
  font-size: clamp(1.1rem, 3vw, 1.4rem);
  font-weight: 800; font-style: italic; letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fff; background: linear-gradient(135deg, var(--accent), #d32f2f);
  border: none; border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(255, 87, 34, 0.45);
  transition: transform 0.15s, box-shadow 0.15s;
}
.big-btn:hover, .big-btn:active { transform: translateY(-2px) scale(1.03); box-shadow: 0 10px 32px rgba(255, 87, 34, 0.65); }

.small-btn {
  padding: 10px 22px;
  font-size: 0.85rem; font-weight: 600; letter-spacing: 0.05em;
  color: var(--text); background: var(--bg-dark);
  border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.small-btn:hover, .small-btn:active { background: rgba(255, 255, 255, 0.15); }
.small-btn.wide { width: 100%; margin-top: 10px; }

.controls-hint { font-size: 0.72rem; opacity: 0.55; text-align: center; letter-spacing: 0.04em; }

#brand-logo {
  height: 40px;
  margin-top: 6px;
  opacity: 0.96;
  /* no plate: a soft violet glow + grounding shadow lifts it off the scene */
  filter:
    drop-shadow(0 0 12px rgba(124, 92, 246, 0.55))
    drop-shadow(0 0 3px rgba(56, 189, 248, 0.45))
    drop-shadow(0 2px 5px rgba(0, 0, 0, 0.8));
  transition: transform 0.2s;
}
#brand-logo:hover { transform: scale(1.06); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

.hud-top {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px;
}
.hud-box { padding: 6px 14px; text-align: center; border-radius: 10px; min-width: 74px; }
.hud-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.65; }
.hud-value { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }

#minimap {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px;
  width: 130px; height: 130px;
  opacity: 0.9;
}

.hud-speed {
  position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); right: 16px;
  padding: 10px 20px 12px; text-align: center; border-radius: 14px;
  min-width: 148px;
}
.speed-value { font-size: 2.2rem; font-weight: 900; font-style: italic; line-height: 1.1; font-variant-numeric: tabular-nums; }
.speed-value small { font-size: 0.85rem; font-weight: 500; opacity: 0.7; }
.gear-value { font-size: 0.95rem; font-weight: 700; color: var(--accent2); }

#hud-rpm-bar {
  height: 6px; border-radius: 3px; overflow: hidden;
  background: rgba(255, 255, 255, 0.12); margin-bottom: 6px;
}
#hud-rpm-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #4caf50, var(--accent2), #f44336);
  transition: width 0.06s linear;
}

.icon-btn {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px;
  width: 42px; height: 42px; border-radius: 12px;
  color: var(--text); font-size: 0.9rem; font-weight: 800;
  border: 1px solid rgba(255, 255, 255, 0.18);
  cursor: pointer; pointer-events: auto;
}

/* ---------- Lap-time toast ---------- */
#lap-popup {
  position: absolute; top: 15%; left: 50%; transform: translateX(-50%);
  padding: 8px 22px; border-radius: 12px;
  background: rgba(10, 12, 24, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: clamp(1.05rem, 3vw, 1.5rem); font-weight: 800; font-style: italic;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#lap-popup.show { animation: lap-toast 2.6s ease-out both; }
@keyframes lap-toast {
  0% { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(1.15); }
  12% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  80% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(6px) scale(1); }
}
#lap-popup .delta-fast { color: #69f0ae; text-shadow: 0 0 12px rgba(105, 240, 174, 0.6); }
#lap-popup .delta-slow { color: #ff8a80; text-shadow: 0 0 12px rgba(255, 138, 128, 0.6); }

/* position gained / lost flash on the HUD box */
.hud-box.pos-up { animation: pos-up 0.9s ease-out; }
.hud-box.pos-down { animation: pos-down 0.9s ease-out; }
@keyframes pos-up {
  0% { background: rgba(76, 175, 80, 0.65); box-shadow: 0 0 22px rgba(76, 175, 80, 0.8); }
  100% { background: var(--bg-dark); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45); }
}
@keyframes pos-down {
  0% { background: rgba(244, 67, 54, 0.65); box-shadow: 0 0 22px rgba(244, 67, 54, 0.8); }
  100% { background: var(--bg-dark); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45); }
}

#wrong-way {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%);
  font-size: clamp(1.4rem, 5vw, 2.4rem); font-weight: 900; font-style: italic;
  color: #ff3d3d; text-transform: uppercase; letter-spacing: 0.12em;
  text-shadow: 0 0 18px rgba(255, 0, 0, 0.7);
  animation: blink 0.6s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.15; } }

/* ---------- Countdown ---------- */
#countdown {
  position: fixed; inset: 0; z-index: 15;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(6rem, 22vw, 13rem); font-weight: 900; font-style: italic;
  color: var(--accent2);
  text-shadow: 0 0 40px rgba(255, 193, 7, 0.8), 0 6px 0 rgba(0,0,0,0.4);
  pointer-events: none;
}
#countdown.go { color: #4caf50; text-shadow: 0 0 50px rgba(76, 175, 80, 0.9); }
#countdown span { animation: pop 0.9s ease-out; display: inline-block; }
@keyframes pop {
  0% { transform: scale(2.2); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  85% { opacity: 1; }
  100% { transform: scale(0.85); opacity: 0; }
}

/* ---------- Touch controls ---------- */
#touch-controls {
  position: fixed; inset: 0; z-index: 12; pointer-events: none;
}
.touch-left, .touch-right {
  position: absolute; bottom: max(18px, env(safe-area-inset-bottom));
  display: flex; gap: 14px;
}
.touch-left { left: 14px; }
.touch-right { right: 14px; flex-direction: row-reverse; }

.touch-btn {
  width: clamp(62px, 15vw, 84px); height: clamp(62px, 15vw, 84px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(20, 24, 46, 0.5);
  color: rgba(255, 255, 255, 0.85); font-size: 1.5rem;
  pointer-events: auto;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.touch-btn:active { background: rgba(255, 255, 255, 0.28); }
.touch-btn.gas { border-color: rgba(76, 175, 80, 0.7); color: #7ee283; }
.touch-btn.brake { border-color: rgba(244, 67, 54, 0.7); color: #ff8a80; }

/* Move speedometer up so touch pedals don't cover it */
body.touch .hud-speed { bottom: 130px; }
body.touch #minimap { width: 96px; height: 96px; }

/* ---------- Panels (pause / results) ---------- */
.panel {
  padding: 32px 44px; text-align: center;
  display: flex; flex-direction: column; gap: 14px;
  min-width: min(86vw, 380px);
}
.panel h2 { font-style: italic; font-size: 1.8rem; letter-spacing: 0.08em; margin-bottom: 6px; }
.panel h2.win {
  color: var(--accent2);
  text-shadow: 0 0 24px rgba(255, 193, 7, 0.65), 0 2px 0 rgba(0, 0, 0, 0.4);
  animation: win-pop 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
@keyframes win-pop {
  from { opacity: 0; transform: scale(0.4) rotate(-4deg); }
  to { opacity: 1; transform: none; }
}
.overlay:has(.panel) { justify-content: center; }

.result-row {
  display: flex; justify-content: space-between; gap: 24px;
  padding: 8px 4px; font-size: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-variant-numeric: tabular-nums;
}
.result-row .pos { font-weight: 800; color: var(--accent2); }
.result-row.player { background: rgba(255, 87, 34, 0.18); border-radius: 8px; }

/* ---------- Loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  background: #0a0c18;
  display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 54px; height: 54px;
  border: 5px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Small screens / landscape phones ---------- */
@media (max-height: 480px) {
  .game-title { font-size: 2rem; }
  .game-subtitle { display: none; }
  .car-info { padding: 8px 16px; }
  .car-desc { display: none; }
  .big-btn { padding: 10px 40px; }
  .controls-hint { display: none; }
  .hud-box { min-width: 60px; padding: 4px 8px; }
  .hud-value { font-size: 0.9rem; }
  #track-desc { display: none; }
  .track-info { padding: 6px 12px; }
  .stat-row { margin: 3px 0; }
  /* the menu is taller than a landscape phone: it scrolls (see .overlay);
     flex-start keeps the top reachable, margin:auto re-centres panels */
  #menu { justify-content: flex-start; }
  .overlay:has(.panel) { justify-content: flex-start; }
  .panel { margin: auto; }
}

/* ---------- Short embeds (portal iframes ~600-880px tall) ---------- */
@media (min-height: 481px) and (max-height: 880px) {
  .overlay { padding-top: 1.5vh; padding-bottom: 1.5vh; }
  .game-title { font-size: clamp(2rem, 4.5vw, 3rem); }
  .game-subtitle { margin-top: 2px; }
  .car-info { padding: 10px 20px; }
  .stat-row { margin: 3px 0; }
  .track-info { padding: 6px 14px; }
  .menu-bottom { gap: 8px; }
  .big-btn { padding: 12px 48px; }
  #brand-logo { height: 32px; }
}

@media (max-height: 640px) {
  .track-select { margin-top: 4px; }
  #track-desc { display: none; }
}
