/* SPIRALFLY — UI skin. The 3D canvas does the heavy lifting; this layer is a
   thin neon HUD over the top. Everything is non-interactive by default so it
   never eats a click meant for the game, except the overlay screens. */

:root {
  --bg: #05070f;
  --ink: #eaf6ff;
  --dim: #7e93ad;
  --accent: #4fc3ff;
  --font-display: 'Orbitron', system-ui, sans-serif;
  --font-ui: 'Rajdhani', system-ui, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

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

/* ---------------------------------------------------------------- HUD ----- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s ease;
  font-family: var(--font-ui);
}
#hud.visible { opacity: 1; }

#hud-top {
  position: absolute;
  top: clamp(14px, 3vh, 34px);
  left: 0; right: 0;
  padding: 0 clamp(16px, 4vw, 54px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

#hud-score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(34px, 7vw, 76px);
  line-height: 0.95;
  letter-spacing: 1px;
  text-shadow: 0 0 18px rgba(79, 195, 255, .55), 0 2px 0 rgba(0,0,0,.4);
  font-variant-numeric: tabular-nums;
}
#hud-distance {
  margin-top: 2px;
  font-size: clamp(13px, 2vw, 18px);
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--dim);
}

#hud-coins {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(18px, 2.6vw, 26px);
  color: #ffd34d;
  text-shadow: 0 0 16px rgba(255, 211, 77, .6);
}
.coin-icon { font-size: .85em; }
#hud-coins.ping { animation: coinPing .35s ease; }
@keyframes coinPing {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

#hud-combo {
  position: absolute;
  top: clamp(96px, 16vh, 150px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(16px, 2.4vw, 24px);
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 20px rgba(255,255,255,.7);
  opacity: 0;
  transition: opacity .2s ease;
}
#hud-combo.visible { opacity: 1; }
#hud-combo.bump { animation: comboBump .25s cubic-bezier(.3,1.6,.5,1); }
@keyframes comboBump {
  0% { transform: translateX(-50%) scale(1); }
  45% { transform: translateX(-50%) scale(1.28); }
  100% { transform: translateX(-50%) scale(1); }
}

#hud-speed {
  position: absolute;
  bottom: clamp(16px, 3.4vh, 36px);
  left: 50%;
  transform: translateX(-50%);
  width: min(46vw, 460px);
  text-align: center;
}
#hud-tier-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(13px, 1.7vw, 17px);
  letter-spacing: 7px;
  margin-bottom: 7px;
  color: var(--accent);
  text-shadow: 0 0 16px currentColor;
}
#hud-speed-bar {
  height: 5px;
  border-radius: 99px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
#hud-speed-fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0.02);
  background: var(--accent);
  box-shadow: 0 0 14px currentColor;
  transition: transform .12s linear, background .6s ease;
}

/* (Stage-bar "threaded a ring" feedback is driven by the Web Animations API in
   hud.js so it never forces a synchronous layout mid-run.) */
#hud-speed-bar { transform-origin: center; }
#hud-tier-name { display: inline-block; transform-origin: center; }

/* near-miss popups */
#popup-layer {
  position: absolute;
  left: 50%;
  bottom: 30vh;
  width: 0; height: 0;
}
.popup {
  position: absolute;
  left: var(--jx, 0px); bottom: 0;
  transform: translate(-50%, 0);
  opacity: 0;                 /* pooled + hidden at rest; WAAPI drives it */
  display: flex;
  align-items: baseline;
  gap: 10px;
  white-space: nowrap;
  will-change: transform, opacity;
}
.popup .pm-main {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 3px;
  color: #fff;
  text-shadow: 0 0 16px rgba(255,255,255,.7);
}
.popup .pm-pts { font-weight: 700; font-size: 20px; color: var(--accent); text-shadow: 0 0 14px currentColor; }
.popup .pm-combo { font-weight: 700; font-size: 16px; color: #ffd34d; }
@keyframes popUp {
  0% { opacity: 0; transform: translate(calc(-50% + var(--jx,0px)), 12px) scale(.8); }
  18% { opacity: 1; transform: translate(calc(-50% + var(--jx,0px)), 0) scale(1.05); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--jx,0px)), -70px) scale(.95); }
}

/* tier change banner */
#tier-banner {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(40px, 9vw, 120px);
  letter-spacing: 8px;
  opacity: 0;
  pointer-events: none;
}
#tier-banner.flash { animation: bannerFlash 1.5s cubic-bezier(.15,.7,.3,1) forwards; }
@keyframes bannerFlash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); filter: blur(8px); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1); filter: blur(0); }
  60% { opacity: .9; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(.96); }
}

/* ------------------------------------------------------------ overlays ---- */
#overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#overlay.visible { display: flex; }

.screen {
  display: none;
  pointer-events: auto;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  animation: screenIn .4s cubic-bezier(.2,.8,.3,1);
}
.screen.visible { display: flex; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* a soft vignette behind overlays so text stays legible over the tunnel */
#title-screen, #death-screen, #skins-screen {
  background: radial-gradient(ellipse at center, rgba(5,7,15,.35) 0%, rgba(5,7,15,.78) 70%, rgba(5,7,15,.9) 100%);
}

/* logo */
.logo-wrap { margin: 8px 0 34px; }
.logo {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(48px, 13vw, 150px);
  letter-spacing: 6px;
  line-height: .92;
  color: #fff;
  text-shadow: 0 0 30px rgba(79,195,255,.6), 0 0 70px rgba(79,195,255,.35);
}
.logo span { color: var(--accent); text-shadow: 0 0 30px var(--accent), 0 0 80px var(--accent); }
.logo-sub {
  margin-top: 10px;
  font-size: clamp(13px, 2vw, 18px);
  letter-spacing: 8px;
  text-transform: uppercase;
  color: var(--dim);
}

.title-meta-row {
  position: absolute;
  top: 22px; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 clamp(16px, 4vw, 48px);
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 3px;
  font-size: clamp(13px, 1.8vw, 17px);
  color: var(--dim);
}
#title-coins { color: #ffd34d; }

.title-buttons { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.btn-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

.btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(15px, 2vw, 19px);
  letter-spacing: 3px;
  color: var(--ink);
  background: rgba(20, 32, 54, .55);
  border: 1px solid rgba(120, 170, 230, .35);
  border-radius: 12px;
  padding: 14px 26px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: transform .12s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.btn:hover {
  transform: translateY(-2px);
  background: rgba(34, 54, 88, .7);
  border-color: var(--accent);
  box-shadow: 0 6px 24px rgba(79,195,255,.25), 0 0 0 1px rgba(79,195,255,.3) inset;
}
.btn:active { transform: translateY(0); }
.btn-primary {
  color: #04121e;
  background: linear-gradient(180deg, #8fe3ff, var(--accent));
  border-color: transparent;
  box-shadow: 0 0 28px rgba(79,195,255,.5);
  padding: 18px 40px;
  font-size: clamp(17px, 2.4vw, 23px);
}
.btn-primary:hover { box-shadow: 0 0 40px rgba(79,195,255,.75); background: linear-gradient(180deg, #aeeaff, #66cdff); }
.btn kbd { background: rgba(0,0,0,.2); border-radius: 5px; padding: 1px 7px; font-family: inherit; }

.title-hint {
  margin-top: 30px;
  color: var(--dim);
  letter-spacing: 2px;
  font-size: clamp(12px, 1.7vw, 16px);
}
.title-hint kbd {
  font-family: var(--font-display);
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: .85em;
  color: var(--ink);
}

.title-foot {
  position: absolute;
  bottom: 22px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.mini-btn {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 13px;
  color: var(--dim);
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
.mini-btn:hover { color: var(--ink); border-color: var(--accent); }
.mini-btn.active { color: #04121e; background: var(--accent); border-color: var(--accent); }
#vol-slider { width: 130px; accent-color: var(--accent); cursor: pointer; }

/* death screen */
.newbest {
  display: none;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 5px;
  color: #04121e;
  background: linear-gradient(90deg, #ffe27a, #ffd34d);
  padding: 6px 18px;
  border-radius: 99px;
  margin-bottom: 14px;
  box-shadow: 0 0 26px rgba(255,211,77,.6);
  animation: badgePop .5s cubic-bezier(.2,1.6,.4,1);
}
.newbest.visible { display: inline-block; }
@keyframes badgePop { from { transform: scale(0); } to { transform: scale(1); } }

#death-title {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 6px;
  font-size: clamp(16px, 2.4vw, 22px);
  color: var(--dim);
}
.death-score {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(60px, 15vw, 150px);
  line-height: 1;
  margin: 8px 0;
  text-shadow: 0 0 36px rgba(79,195,255,.55);
  font-variant-numeric: tabular-nums;
}
.death-best { color: var(--dim); letter-spacing: 4px; font-weight: 700; font-size: clamp(14px,2vw,18px); }

.death-stats {
  display: flex;
  gap: clamp(18px, 5vw, 56px);
  margin: 30px 0;
  flex-wrap: wrap;
  justify-content: center;
}
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat span { font-family: var(--font-display); font-weight: 800; font-size: clamp(22px, 3.6vw, 34px); }
.stat label { font-size: 12px; letter-spacing: 3px; text-transform: uppercase; color: var(--dim); }

.leaderboard { margin-bottom: 26px; min-width: 260px; }
.leaderboard h3 { font-family: var(--font-display); letter-spacing: 4px; font-size: 13px; color: var(--dim); margin-bottom: 10px; }
.leaderboard ol { list-style: none; }
.leaderboard li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 15px;
}
.leaderboard li:nth-child(odd) { background: rgba(255,255,255,.04); }
.leaderboard li span { color: var(--dim); font-weight: 700; }
.leaderboard li b { font-family: var(--font-display); font-weight: 700; text-align: left; }
.leaderboard li em { color: var(--dim); font-style: normal; font-size: 12px; }
.leaderboard li.empty { display: block; text-align: center; color: var(--dim); }

/* skins */
.skins-head {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 28px;
}
.skins-head h2 { font-family: var(--font-display); font-weight: 800; letter-spacing: 8px; font-size: clamp(26px,5vw,46px); }
#skins-coins { font-family: var(--font-display); font-weight: 700; color: #ffd34d; letter-spacing: 2px; }

.skins-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  max-width: 720px;
  width: 100%;
  margin-bottom: 28px;
}
.skin-card {
  background: rgba(20, 32, 54, .5);
  border: 1px solid rgba(120,170,230,.22);
  border-radius: 14px;
  padding: 18px 12px 14px;
  cursor: pointer;
  transition: transform .12s ease, border-color .2s ease, box-shadow .2s ease;
}
.skin-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.skin-card.selected { border-color: var(--accent); box-shadow: 0 0 24px rgba(79,195,255,.4), inset 0 0 0 1px var(--accent); }
.skin-card.locked { opacity: .55; }
.skin-card.locked:hover { border-color: rgba(255,120,120,.5); }
.skin-swatch {
  height: 76px;
  display: grid;
  place-items: center;
  margin-bottom: 12px;
}
.skin-craft {
  width: 0; height: 0;
  border-left: 17px solid transparent;
  border-right: 17px solid transparent;
  border-bottom: 44px solid var(--b);
  filter: drop-shadow(0 0 16px var(--b));
  position: relative;
}
.skin-craft::after {
  content: '';
  position: absolute;
  left: -17px; top: 30px;
  width: 34px; height: 7px;
  background: var(--f);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--f);
}
.skin-name { font-family: var(--font-display); font-weight: 700; letter-spacing: 2px; font-size: 16px; }
.skin-meta { font-size: 12px; letter-spacing: 2px; color: var(--dim); margin-top: 4px; text-transform: uppercase; }
.skin-card.selected .skin-meta { color: var(--accent); }

@media (max-width: 560px) {
  .death-stats { gap: 14px; }
  .stat span { font-size: 24px; }
}
