:root {
  color-scheme: dark;
  --pink: #ff3ca6;
  --cyan: #3cf0ff;
  --violet: #9b6bff;
  --gold: #ffd23c;
  --leaf: #57ff8f;
  --ink: #f0f0f5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Chakra Petch", system-ui, sans-serif;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html.in-shell .mute-btn,
html.in-shell .fs-btn,
html.in-shell .back-link {
  display: none;
}

.back-link {
  position: absolute;
  top: 1.25rem;
  left: 1.5rem;
  z-index: 6;
  color: #8f8fb0;
  text-decoration: none;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
  text-transform: uppercase;
}
.back-link:hover { color: var(--cyan); }

.arena {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 0.7rem;
  padding: 1rem;
}

.hudbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(86vw, 118vh);
  min-width: 300px;
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 0.95rem;
}
.hud-score { color: var(--leaf); text-shadow: 0 0 12px rgba(87, 255, 143, 0.55); }
.hud-score span { color: #eafff0; }
.hud-coins {
  color: var(--gold);
  font-size: 0.85rem;
  text-shadow: 0 0 10px rgba(255, 210, 60, 0.5);
}
.hud-coins span { color: #fff3cf; }
.hud-gems {
  color: var(--cyan);
  font-size: 0.85rem;
  text-shadow: 0 0 10px rgba(60, 240, 255, 0.5);
}
.hud-gems span { color: #e6fbff; }
.hud-best {
  color: #b6a6e0;
  font-size: 0.8rem;
  margin-left: auto;
  text-shadow: 0 0 6px rgba(5, 3, 12, 0.9), 0 0 14px rgba(5, 3, 12, 0.9);
}
.hud-best span { color: #e7dcff; }

.stage {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  line-height: 0;
  /* Reserve the canvas's final size up front so the stage doesn't grow when
     three.js boots (mirrors sizeRenderer() in script.js: w = min(86vw,120vh,
     1180px), h = 0.66·w). Keep the two in sync. */
  width: min(86vw, 120vh, 1180px);
  height: min(56.8vw, 79.2vh, 779px);
}
#mount { line-height: 0; }
#mount canvas { display: block; touch-action: none; cursor: pointer; }

/* ---------- milestone callouts ---------- */
.callout {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  letter-spacing: 0.1em;
  color: #fff;
  opacity: 0;
  line-height: 1.4;
}
.callout.show { animation: md-callout 1.4s ease-out forwards; }
@keyframes md-callout {
  0% { opacity: 0; transform: scale(0.6); }
  14% { opacity: 1; transform: scale(1.15); }
  26% { transform: scale(1); }
  76% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.05); }
}
.callout span {
  text-shadow:
    0 0 14px var(--leaf),
    0 0 34px rgba(87, 255, 143, 0.7),
    3px 3px 0 rgba(255, 60, 166, 0.5),
    -3px -3px 0 rgba(60, 240, 255, 0.5);
}

/* ---------- Pause ---------- */
.pause-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 4;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 19, 0.6);
  border: 2px solid rgba(155, 107, 255, 0.45);
  border-radius: 11px;
  color: #b6a6e0;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.pause-btn svg { width: 20px; height: 20px; }
.pause-btn:hover { border-color: var(--cyan); color: var(--cyan); box-shadow: 0 0 14px rgba(60, 240, 255, 0.4); }
.pause-btn:active { transform: scale(0.92); }

.pause-veil {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  text-align: center;
  line-height: 1.4;
  background: rgba(8, 5, 20, 0.74);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  cursor: pointer;
}
.pause-veil.show { opacity: 1; pointer-events: auto; }
.pause-veil .pv-title {
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: 2.2rem;
  letter-spacing: 0.14em;
  color: #eafcff;
  text-shadow: 0 0 18px rgba(60, 240, 255, 0.75), 0 0 40px rgba(155, 107, 255, 0.5);
}
.pause-veil .pv-sub { color: #b6a6e0; font-size: 0.85rem; letter-spacing: 0.04em; }
.pause-veil .pv-sub b { color: var(--cyan); }

/* ---------- Title / result overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 1.5rem;
  text-align: center;
  line-height: 1.4;
  background:
    radial-gradient(ellipse 90% 55% at 50% 8%, rgba(87, 255, 143, 0.12), transparent 60%),
    rgba(6, 5, 18, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.3s ease;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.overlay-logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.02em;
  font-family: "Audiowide", "Orbitron", sans-serif;
  font-weight: 400;
  line-height: 1;
}
.wm-max {
  font-size: clamp(2rem, 9vw, 3.4rem);
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #eafff0 0%, var(--leaf) 55%, #1f9e57 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 16px rgba(87, 255, 143, 0.55));
}
.wm-dash {
  font-size: clamp(1.1rem, 4.6vw, 1.7rem);
  letter-spacing: 0.5em;
  margin-left: 0.5em;
  color: #eafcff;
  text-shadow: 0 0 10px var(--cyan), 0 0 26px rgba(60, 240, 255, 0.7);
}
.overlay-tag {
  margin: 0.1rem 0;
  max-width: 92%;
  color: #c4c4e0;
  font-size: 0.86rem;
  line-height: 1.5;
}
.overlay-tag .c-car { color: #ff6a5a; }
.overlay-tag .c-log { color: #e0a95e; }
.overlay-tag .c-water { color: var(--cyan); }
.overlay-tag .c-coin { color: var(--gold); }
.overlay-tag .c-gloop { color: #c58bff; }
.overlay-tag .c-zap { color: #7df3ff; }
.overlay-tag .c-gem { color: #aef7ff; }
.overlay-best {
  margin: 0.3rem 0 0;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.03em;
}
.overlay-best:empty { display: none; }
.overlay-result {
  margin: 0;
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: 1.5rem;
  letter-spacing: 0.03em;
  background: linear-gradient(90deg, #57ff8f, #3cf0ff, #b06bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(87, 255, 143, 0.5));
}
.overlay-result:empty { display: none; }
.overlay-sub { margin: 0; color: #d8ccff; font-size: 0.95rem; min-height: 1.1em; }
.overlay-sub:empty { display: none; }
.overlay-hint { margin: 0.2rem 0 0; color: #8b86ae; font-size: 0.75rem; }

.overlay-btn {
  margin-top: 0.3rem;
  padding: 0.6rem 2.2rem;
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 0.95rem;
  text-transform: uppercase;
  color: #06210f;
  background: linear-gradient(90deg, #57ff8f, #3cf0ff);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(87, 255, 143, 0.5);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.overlay-btn:hover { transform: scale(1.05); box-shadow: 0 0 32px rgba(60, 240, 255, 0.7); }
.overlay-btn:active { transform: scale(0.98); }

/* Corner buttons (hidden inside the shell) */
.mute-btn,
.fs-btn {
  position: fixed;
  top: 14px;
  z-index: 80;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 19, 0.7);
  border: 2px solid rgba(155, 107, 255, 0.55);
  border-radius: 11px;
  color: var(--cyan);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.mute-btn { right: 14px; }
.fs-btn { right: 62px; color: var(--gold); border-color: rgba(255, 210, 60, 0.55); }
.mute-btn svg,
.fs-btn svg { width: 21px; height: 21px; filter: drop-shadow(0 0 5px currentColor); }
.mute-btn:hover { border-color: var(--cyan); box-shadow: 0 0 16px rgba(60, 240, 255, 0.5); }
.fs-btn:hover { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 210, 60, 0.5); }
.mute-btn:active,
.fs-btn:active { transform: scale(0.92); }
.mute-btn.muted { color: var(--pink); border-color: rgba(255, 60, 166, 0.6); }

@media (max-width: 640px) {
  .overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    overflow-y: auto;
    background:
      radial-gradient(ellipse 90% 45% at 50% 8%, rgba(87, 255, 143, 0.12), transparent 60%),
      rgba(6, 5, 18, 0.95);
  }
}

/* ---------- floating "+1 🪙" pops when a coin is scooped ---------- */
.coin-pop {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 210, 60, 0.8), 0 1px 0 rgba(0, 0, 0, 0.6);
  pointer-events: none;
  opacity: 0;
  line-height: 1;
}
.coin-pop.show { animation: coin-rise 0.85s ease-out forwards; }
@keyframes coin-rise {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -64%) scale(1.15); }
  30% { transform: translate(-50%, -76%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(0.95); }
}

/* ---------- watchdog fallback ---------- */
.load-fail {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  text-align: center;
  line-height: 1.4;
  background: rgba(6, 5, 18, 0.92);
}
.load-fail[hidden] { display: none; }
.load-fail .lf-title {
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: 1.6rem;
  letter-spacing: 0.14em;
  color: #ff6a5a;
  text-shadow: 0 0 18px rgba(255, 106, 90, 0.6);
}
.load-fail .lf-sub { color: #b6a6e0; font-size: 0.9rem; }
