:root {
  --bg: #0b0d1a;
  --ink: #f4f6ff;
  --muted: #8b91b8;
  --accent: #ff5fa2;
  --accent2: #5fd0ff;
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: clamp(10px, 4vw, 36px);
  pointer-events: none;
  z-index: 10;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  border-radius: 16px;
  background: rgba(18, 21, 40, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 78px;
}

.stat .label {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 700;
}

.stat .value {
  font-size: clamp(18px, 5vw, 26px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* ---------- Area progress bar ---------- */
#area-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: max(78px, calc(env(safe-area-inset-top) + 64px));
  width: min(70vw, 320px);
  height: 8px;
  border-radius: 999px;
  background: rgba(18, 21, 40, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: visible;
  z-index: 10;
}
#area-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width 0.3s ease;
}
#area-target {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 14px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 2px;
}

/* ---------- Icon buttons ---------- */
#fullscreen-btn, #mute-btn, #menu-btn {
  position: fixed;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(18, 21, 40, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  display: grid;
  place-items: center;
  transition: transform 0.1s ease, background 0.2s ease;
}
#fullscreen-btn, #mute-btn { bottom: max(16px, env(safe-area-inset-bottom)); }
#fullscreen-btn { right: max(16px, env(safe-area-inset-right)); }
#mute-btn { right: calc(max(16px, env(safe-area-inset-right)) + 58px); }
#menu-btn {
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
}
#fullscreen-btn:active, #mute-btn:active, #menu-btn:active { transform: scale(0.9); }
#fullscreen-btn:hover, #mute-btn:hover, #menu-btn:hover { background: rgba(28, 32, 58, 0.7); }
#mute-btn[data-muted="true"] { color: var(--muted); opacity: 0.6; }

/* ---------- Splash + Game Over ---------- */
#splash, #gameover {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(30, 22, 60, 0.55), rgba(11, 13, 26, 0.85));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.5s ease;
  pointer-events: none; /* taps fall through to the bubblewrap behind */
}
#splash.hidden, #gameover.hidden { opacity: 0; }
#splash .splash-card, #gameover .splash-card { pointer-events: auto; }
#splash.hidden .splash-card, #gameover.hidden .splash-card { pointer-events: none; }
/* Override only the gradient + size; using `background-image` (not the
   `background` shorthand) preserves the `background-clip: text` from the base
   rule, so the title stays clipped to the letters instead of filling the box. */
.splash-card h1.go-title {
  font-size: clamp(40px, 13vw, 76px);
  background-image: linear-gradient(135deg, #ff5f6d, #ffc371);
}

.splash-card {
  text-align: center;
  max-width: 420px;
  width: 100%;
}

.splash-card h1 {
  font-size: clamp(48px, 16vw, 92px);
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 30px rgba(255, 95, 162, 0.35));
}

.tagline { color: var(--muted); margin-top: 4px; font-size: 15px; }

.splash-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px 24px;
  margin: 24px 0;
}
.splash-stats div { display: flex; flex-direction: column; }
.splash-stats b { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.splash-stats span { font-size: 11px; color: var(--muted); letter-spacing: 0.05em; }

#start-btn, #restart-btn {
  margin-top: 8px;
  padding: 16px 40px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.04em;
  border: none;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #ff8a5f);
  box-shadow: 0 10px 30px rgba(255, 95, 162, 0.4);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}
#start-btn:hover, #restart-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 38px rgba(255, 95, 162, 0.55); }
#start-btn:active, #restart-btn:active { transform: translateY(0) scale(0.97); }

.hint { color: var(--muted); font-size: 13px; margin-top: 18px; }

/* ---------- Luxury reveal card ---------- */
#reveal {
  --rarity: #9fb4d8;
  position: fixed;
  left: 50%;
  top: max(96px, calc(env(safe-area-inset-top) + 82px));
  transform: translate(-50%, -18px);
  z-index: 16;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 12px;
  max-width: min(92vw, 380px);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(28, 24, 50, 0.92), rgba(16, 14, 30, 0.92));
  border: 1px solid color-mix(in srgb, var(--rarity) 60%, transparent);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45),
              0 0 0 1px color-mix(in srgb, var(--rarity) 25%, transparent),
              0 0 34px -6px var(--rarity);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
}
#reveal.show { animation: revealPop 2.2s cubic-bezier(0.2, 0.9, 0.25, 1) forwards; }
@keyframes revealPop {
  0%   { opacity: 0; transform: translate(-50%, -18px) scale(0.9); }
  10%  { opacity: 1; transform: translate(-50%, 0) scale(1.02); }
  16%  { transform: translate(-50%, 0) scale(1); }
  85%  { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(0.98); }
}
.reveal-icon {
  font-size: 34px;
  line-height: 1;
  filter: drop-shadow(0 2px 10px color-mix(in srgb, var(--rarity) 70%, transparent));
}
.reveal-body { display: flex; flex-direction: column; min-width: 0; }
.reveal-name {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reveal-cat {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.reveal-tier {
  position: absolute;
  top: -9px;
  left: 14px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
  padding: 2px 8px;
  border-radius: 999px;
  color: #15121f;
  background: var(--rarity);
  box-shadow: 0 2px 10px -2px var(--rarity);
}
.reveal-bonus {
  margin-left: auto;
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--rarity);
  white-space: nowrap;
}
#reveal[data-tier="legendary"] { animation-duration: 2.6s; }
#reveal[data-tier="legendary"].show .reveal-icon { animation: luxSpin 2.6s ease; }
@keyframes luxSpin {
  0% { transform: scale(0.6) rotate(-12deg); }
  14% { transform: scale(1.25) rotate(6deg); }
  30% { transform: scale(1) rotate(0); }
}

/* ---------- Pause + collection drawer ---------- */
#pause {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 35%, rgba(30, 22, 60, 0.78), rgba(11, 13, 26, 0.94));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#pause.hidden { display: none; }
.pause-card {
  width: min(560px, 100%);
  max-height: min(82vh, 720px);
  display: flex;
  flex-direction: column;
  padding: 22px;
  border-radius: 22px;
  background: rgba(16, 18, 36, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
.pause-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.pause-head h2 {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, #ffd166, #ff9d6f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.collection-count {
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent2);
}
.pause-sub { margin-top: 6px; font-size: 12px; color: var(--muted); }
.collection-grid {
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  overflow-y: auto;
  padding-right: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;                       /* Firefox */
  scrollbar-color: var(--accent) transparent;
}
.collection-grid::-webkit-scrollbar { width: 8px; }
.collection-grid::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
}
.collection-grid::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  border: 2px solid transparent;
  background-clip: padding-box;
}
.collection-grid::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--accent2), var(--accent));
  background-clip: padding-box;
}
.lux {
  --c: #9fb4d8;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  box-shadow: inset 0 0 18px -8px var(--c);
}
.lux[data-tier="common"]    { --c: #9fb4d8; }
.lux[data-tier="rare"]      { --c: #5fd0ff; }
.lux[data-tier="epic"]      { --c: #c887ff; }
.lux[data-tier="legendary"] { --c: #ffd166; }
.lux.locked {
  border-color: rgba(255, 255, 255, 0.07);
  box-shadow: none;
  opacity: 0.5;
  filter: grayscale(0.6);
}
.lux-icon { font-size: 26px; line-height: 1; }
.lux-name {
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  color: var(--ink);
}
.lux.locked .lux-name { color: var(--muted); }
.lux-x {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 10px;
  font-weight: 800;
  color: var(--c);
}
.pause-actions { display: flex; flex-direction: column; gap: 10px; }
#resume-btn {
  padding: 14px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  border: none;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #ff8a5f);
  box-shadow: 0 10px 28px rgba(255, 95, 162, 0.4);
  cursor: pointer;
  transition: transform 0.12s ease;
}
#resume-btn:active { transform: scale(0.97); }

/* ---------- Ghost (secondary) buttons ---------- */
.ghost-btn {
  display: inline-block;
  margin-top: 12px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(255, 255, 255, 0.28); }
.pause-actions .ghost-btn { margin-top: 0; }

/* ---------- Clear toast ---------- */
#clear-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  font-size: clamp(28px, 9vw, 56px);
  font-weight: 900;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0;
  pointer-events: none;
  z-index: 15;
  filter: drop-shadow(0 4px 20px rgba(95, 208, 255, 0.5));
}
#clear-toast.show {
  animation: toastPop 1.4s ease forwards;
}
@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  35% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}
