/* ============================================================
   DERBY DUSK — style.css
   Loaded after lib/ui/ui.css; this file owns the pop's look.
   Dark smoky orange / steel-blue stadium theme.
   ============================================================ */

:root {
  --bg: #0d1014;
  --bg-2: #141920;
  --surface: rgba(20, 25, 32, 0.82);
  --surface-2: rgba(30, 36, 45, 0.9);
  --text: #f2f4f7;
  --muted: #93a0ae;
  --accent: #ff6a00;
  --accent-2: #ffd166;
  --steel: #5d6b7a;
  --steel-dark: #2a323c;
  --danger: #ff3b30;
  --ok: #57e389;
  --radius: 14px;
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Space Grotesk', 'Inter', ui-sans-serif, system-ui, sans-serif;
  --hud-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(120% 80% at 50% 0%, #2a1a10 0%, rgba(42, 26, 16, 0) 60%),
    linear-gradient(180deg, #171b21 0%, var(--bg) 55%, #08090b 100%);
}

/* ------------------------------------------------------------
   #stage — fullscreen fixed 3D container
   ------------------------------------------------------------ */
#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  overflow: hidden;
  touch-action: none;
  background: #0a0c0f;
}

#stage canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

/* red impact vignette painted over the 3D view */
#stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 2;
}

/* ------------------------------------------------------------
   Damage flash keyframes
   ------------------------------------------------------------ */
@keyframes damageFlash {
  0%   { opacity: 0.72; }
  18%  { opacity: 0.34; }
  100% { opacity: 0; }
}

@keyframes damageFlashSoft {
  0%   { opacity: 0.3; }
  100% { opacity: 0; }
}

@keyframes hpPulse {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.7); }
}

.damage-flash::after,
#stage.damage-flash::after,
body.damage-flash::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  background:
    radial-gradient(120% 90% at 50% 50%, rgba(255, 40, 20, 0) 35%, rgba(255, 30, 10, 0.75) 100%);
  animation: damageFlash 460ms ease-out forwards;
}

.damage-flash-soft::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  background: radial-gradient(120% 90% at 50% 50%, rgba(255, 120, 0, 0) 45%, rgba(255, 106, 0, 0.4) 100%);
  animation: damageFlashSoft 380ms ease-out forwards;
}

/* ------------------------------------------------------------
   .hud — top bar over the game
   ------------------------------------------------------------ */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  pointer-events: none;
  font-family: var(--font);
}

.hud > * { pointer-events: auto; }

.hud-chip,
.hud .chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(38, 45, 55, 0.9), rgba(16, 20, 26, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: var(--hud-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.hud-chip b,
.hud .chip b {
  font-family: var(--display);
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.hud-chip .lbl {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.hud-left,
.hud-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.hud-right { align-items: flex-end; }

.hud-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* health bar */
#hp-bar {
  position: relative;
  width: min(46vw, 260px);
  height: 20px;
  border-radius: 999px;
  padding: 3px;
  background: linear-gradient(180deg, rgba(10, 12, 15, 0.95), rgba(24, 28, 34, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--hud-shadow), inset 0 2px 6px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

#hp-bar::before {
  content: 'HULL';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: rgba(255, 255, 255, 0.55);
  z-index: 2;
  pointer-events: none;
}

#hp-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff8a1f 0%, var(--accent) 55%, #ff4d00 100%);
  box-shadow: 0 0 14px rgba(255, 106, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: width 220ms cubic-bezier(0.22, 1, 0.36, 1), background 300ms linear;
}

#hp-fill.warn {
  background: linear-gradient(90deg, #ffd166 0%, #ff9a1f 100%);
}

#hp-fill.crit {
  background: linear-gradient(90deg, #ff5f52 0%, var(--danger) 100%);
  animation: hpPulse 700ms ease-in-out infinite;
}

#hp-fill.dead { width: 0% !important; animation: none; }

/* score / combo / alive / timer */
#score {
  font-family: var(--display);
  font-size: clamp(20px, 5vw, 30px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 18px rgba(255, 106, 0, 0.55);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

#combo {
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  color: var(--accent-2);
  text-shadow: 0 0 14px rgba(255, 209, 102, 0.6);
  opacity: 0;
  transform: translateY(-6px) scale(0.9);
  transition: opacity 180ms ease, transform 180ms cubic-bezier(0.22, 1.4, 0.36, 1);
}

#combo.on {
  opacity: 1;
  transform: translateY(0) scale(1);
}

#combo.bump { animation: comboBump 320ms cubic-bezier(0.22, 1.6, 0.36, 1); }

@keyframes comboBump {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.35) rotate(-3deg); }
  100% { transform: scale(1); }
}

#alive b { color: var(--ok); }
#timer b { color: var(--accent-2); }
#timer b.low { color: var(--danger); }

/* floating combo / score text spawned over the arena */
.float-text {
  position: absolute;
  z-index: 12;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(16px, 4vw, 26px);
  color: var(--accent-2);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85), 0 0 18px rgba(255, 106, 0, 0.7);
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: floatUp 900ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.float-text.big { font-size: clamp(22px, 6vw, 40px); color: #fff; }

@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  25%  { opacity: 1; transform: translate(-50%, -60%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(1); }
}

/* ------------------------------------------------------------
   #countdown — big centered numerals with pop animation
   ------------------------------------------------------------ */
#countdown {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 20;
  pointer-events: none;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(84px, 26vw, 220px);
  line-height: 0.9;
  letter-spacing: -0.03em;
  color: #fff;
  text-align: center;
  text-shadow:
    0 0 24px rgba(255, 106, 0, 0.85),
    0 0 70px rgba(255, 106, 0, 0.5),
    0 10px 40px rgba(0, 0, 0, 0.9);
  -webkit-text-stroke: 2px rgba(255, 209, 102, 0.35);
}

#countdown:empty { display: none; }

#countdown:not(:empty),
#countdown.pop {
  animation: countdownPop 950ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

#countdown.go {
  color: var(--accent-2);
  font-size: clamp(70px, 22vw, 190px);
  -webkit-text-stroke: 2px rgba(255, 106, 0, 0.6);
}

@keyframes countdownPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.25) rotate(-8deg); filter: blur(8px); }
  22%  { opacity: 1; transform: translate(-50%, -50%) scale(1.18) rotate(2deg); filter: blur(0); }
  45%  { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  78%  { opacity: 1; transform: translate(-50%, -50%) scale(1.02); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.35); }
}

/* ------------------------------------------------------------
   .overlay > .panel — title + end screens
   ------------------------------------------------------------ */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: none;
  background:
    radial-gradient(90% 70% at 50% 45%, rgba(8, 10, 13, 0.25) 0%, rgba(6, 7, 9, 0.82) 100%);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: overlayIn 320ms ease-out both;
}

.overlay[hidden] { display: none !important; }

.overlay:not([hidden]) { pointer-events: auto; }

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay .panel {
  position: relative;
  width: min(520px, 100%);
  padding: clamp(22px, 5vw, 38px);
  border-radius: calc(var(--radius) + 6px);
  text-align: center;
  background:
    linear-gradient(180deg, rgba(34, 40, 49, 0.94) 0%, rgba(13, 16, 21, 0.96) 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.75),
    0 0 0 1px rgba(255, 106, 0, 0.14),
    0 0 60px rgba(255, 106, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: panelIn 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
  overflow: hidden;
}

.overlay .panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent) 30%, var(--accent-2) 70%, transparent);
  opacity: 0.9;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(22px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#ov-title {
  margin: 0 0 6px;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(34px, 10vw, 62px);
  line-height: 0.95;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff 10%, var(--accent-2) 55%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(255, 106, 0, 0.45));
}

#ov-title.win { animation: titleWin 700ms cubic-bezier(0.16, 1, 0.3, 1) both; }
#ov-title.lose { animation: titleLose 500ms ease-out both; }

@keyframes titleWin {
  0%   { transform: scale(0.6) rotate(-4deg); opacity: 0; letter-spacing: 0.2em; }
  60%  { transform: scale(1.08) rotate(1deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; letter-spacing: -0.02em; }
}

@keyframes titleLose {
  0%   { transform: translateY(-16px); opacity: 0; filter: blur(6px); }
  100% { transform: translateY(0); opacity: 1; filter: blur(0); }
}

#ov-sub {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: clamp(13px, 3.4vw, 15px);
  line-height: 1.5;
}

#ov-stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 22px;
}

#ov-stats .stat {
  min-width: 96px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#ov-stats .stat b {
  display: block;
  font-family: var(--display);
  font-size: 26px;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

#ov-stats .stat span {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.overlay .btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------
   Buttons (game-specific emphasis over ui.css)
   ------------------------------------------------------------ */
#btn-start,
#btn-restart {
  min-width: 190px;
  padding: 16px 34px;
  border: none;
  border-radius: 999px;
  font-family: var(--display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  color: #14100c;
  background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent) 100%);
  box-shadow:
    0 10px 26px rgba(255, 106, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 140ms cubic-bezier(0.22, 1.4, 0.36, 1), box-shadow 160ms ease, filter 160ms ease;
}

#btn-start:hover,
#btn-restart:hover { transform: translateY(-2px) scale(1.03); filter: brightness(1.06); }

#btn-start:active,
#btn-restart:active { transform: translateY(1px) scale(0.98); box-shadow: 0 4px 12px rgba(255, 106, 0, 0.4); }

#btn-start:focus-visible,
#btn-restart:focus-visible {
  outline: 3px solid rgba(255, 209, 102, 0.85);
  outline-offset: 3px;
}

#btn-restart {
  color: #fff;
  background: linear-gradient(180deg, #ff8a2b 0%, #e2450a 100%);
}

.hint {
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  line-height: 1.6;
}

.hint kbd {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-family: var(--font);
  font-size: 11px;
  color: var(--text);
}

/* ------------------------------------------------------------
   #touch — bottom touch controls, 64px round buttons
   ------------------------------------------------------------ */
#touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 16px calc(18px + env(safe-area-inset-bottom));
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

#touch .pad {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  pointer-events: auto;
}

#touch .pad.right { flex-direction: row; align-items: flex-end; }

#touch button {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.16);
  background:
    radial-gradient(120% 120% at 30% 20%, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, rgba(52, 61, 73, 0.92) 0%, rgba(20, 25, 32, 0.94) 100%);
  color: var(--text);
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

#touch button:active,
#touch button.pressed {
  transform: scale(0.92);
  border-color: rgba(255, 209, 102, 0.85);
  background:
    radial-gradient(120% 120% at 30% 20%, rgba(255, 255, 255, 0.24) 0%, rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, rgba(255, 138, 43, 0.95) 0%, rgba(226, 69, 10, 0.95) 100%);
  color: #17110b;
  box-shadow: 0 0 26px rgba(255, 106, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

#touch button:focus-visible {
  outline: 3px solid rgba(255, 209, 102, 0.9);
  outline-offset: 3px;
}

#touch .t-go {
  width: 84px;
  height: 84px;
  font-size: 15px;
  letter-spacing: 0.12em;
  color: var(--accent-2);
  border-color: rgba(255, 106, 0, 0.55);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.55), 0 0 22px rgba(255, 106, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

#touch .t-brake {
  width: 64px;
  height: 64px;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: #ffb4a8;
  border-color: rgba(255, 80, 60, 0.45);
}

#touch .t-left, #touch .t-right { font-size: 26px; }

/* visible only where a real touch/pen pointer is present */
@media (pointer: coarse), (hover: none) {
  #touch { display: flex; }
}

@media (pointer: fine) and (hover: hover) {
  #touch { display: none !important; }
}

/* landscape phones: keep the HUD and pads out of the way */
@media (max-height: 460px) and (orientation: landscape) {
  #touch { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  #touch button { width: 56px; height: 56px; }
  #touch .t-go { width: 70px; height: 70px; }
  #countdown { top: 46%; font-size: clamp(64px, 18vh, 130px); }
  .hud { padding-top: 6px; }
  #hp-bar { width: min(34vw, 200px); height: 17px; }
}

@media (max-width: 380px) {
  .hud-chip { padding: 6px 10px; font-size: 12px; }
  #hp-bar { width: 52vw; }
}

/* ------------------------------------------------------------
   Small shared-utility overrides so the kit matches the theme
   ------------------------------------------------------------ */
.app { background: transparent; }

.card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
}

.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #14100c;
  border: none;
}

.title, .gradient-text {
  font-family: var(--display);
  background: linear-gradient(180deg, #fff, var(--accent-2) 60%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.muted { color: var(--muted); }

.toast {
  background: var(--surface-2);
  border: 1px solid rgba(255, 106, 0, 0.35);
  color: var(--text);
  border-radius: var(--radius);
}

/* pause/resume: freeze decorative motion while the pop is paused */
.paused .float-text,
.paused #countdown,
.paused #combo.bump,
.paused .damage-flash::after { animation-play-state: paused; }
