:root {
  --ink: #f4efe4;
  --ink-dim: #b9b0a0;
  --gold: #f2c14e;
  --gold-deep: #c8901f;
  --bg: #0b1026;
  --panel: rgba(14, 18, 42, 0.82);
  --edge: rgba(242, 193, 78, 0.28);
  --bad: #e2604a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ---------------------------------------------------------------- hud */
.hud {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  pointer-events: none;
  flex-wrap: wrap;
  align-items: center;
}
.hud-top { top: 0; }

.pill {
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  backdrop-filter: blur(8px);
  white-space: nowrap;
  transition: transform 0.16s ease, border-color 0.16s ease;
}
.pill b { color: var(--ink); font-size: 15px; }
.pill .ico { color: var(--gold); }
.pill-score {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}
.pill-score b { color: var(--gold); font-size: 17px; }

.pill-btn {
  pointer-events: auto;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 8px 12px;
  color: var(--ink);
  font-family: inherit;
}
.pill-btn:hover { border-color: var(--gold); }
.pill-btn.off { opacity: 0.4; }

.pill.bump { transform: scale(1.12); border-color: var(--gold); }

/* ---------------------------------------------------------------- ammo pips */
.ammo {
  position: absolute;
  left: 16px;
  bottom: calc(22px + var(--safe-b));
  display: flex;
  flex-direction: column-reverse;
  gap: 7px;
  pointer-events: none;
}
.ammo i {
  display: block;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: radial-gradient(circle at 33% 30%, #6a7285, #23283a 70%);
  border: 1px solid rgba(242, 193, 78, 0.45);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
  transition: transform 0.18s ease, opacity 0.25s ease, background 0.25s ease;
}
.ammo i.spent {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.13);
  box-shadow: none;
  opacity: 0.5;
  transform: scale(0.62);
}

/* ---------------------------------------------------------------- combo */
.combo {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 4px 22px rgba(0, 0, 0, 0.7);
}
.combo.on {
  animation: comboPop 0.62s cubic-bezier(0.2, 1.5, 0.4, 1) forwards;
}
.combo b {
  display: block;
  font-size: clamp(54px, 13vw, 104px);
  line-height: 0.9;
  color: var(--gold);
  font-weight: 900;
}
.combo span {
  display: block;
  font-size: clamp(12px, 3vw, 18px);
  letter-spacing: 0.5em;
  color: var(--ink);
  padding-left: 0.5em;
}
@keyframes comboPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  22%  { opacity: 1; transform: translate(-50%, -50%) scale(1.14); }
  70%  { opacity: 1; transform: translate(-50%, -54%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -74%) scale(0.94); }
}

/* ---------------------------------------------------------------- score popups */
.popups { position: absolute; inset: 0; pointer-events: none; }
.pop {
  position: absolute;
  font-size: 20px;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85);
  animation: popRise 0.95s ease-out forwards;
  transform: translate(-50%, -50%);
}
@keyframes popRise {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  18%  { opacity: 1; transform: translate(-50%, -60%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(0.95); }
}

/* ---------------------------------------------------------------- hint */
.hint {
  position: absolute;
  left: 50%;
  bottom: calc(26px + var(--safe-b));
  transform: translateX(-50%);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 7px 16px;
  pointer-events: none;
  transition: opacity 0.3s ease;
  text-align: center;
  max-width: 88vw;
}
.hint.gone { opacity: 0; }

/* ---------------------------------------------------------------- result card */
.scrim {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 6, 18, 0.72);
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  padding: 18px;
}
.scrim.on { opacity: 1; pointer-events: auto; }

.card {
  width: min(360px, 92vw);
  background: linear-gradient(180deg, #171d3f, #101636);
  border: 1px solid var(--edge);
  border-radius: 20px;
  padding: 26px 24px 22px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  transform: translateY(14px) scale(0.97);
  transition: transform 0.3s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.scrim.on .card { transform: none; }

.stars { font-size: 34px; letter-spacing: 6px; margin-bottom: 6px; }
.stars span { color: rgba(255, 255, 255, 0.14); transition: color 0.3s ease, transform 0.3s ease; display: inline-block; }
.stars span.lit { color: var(--gold); text-shadow: 0 0 22px rgba(242, 193, 78, 0.55); transform: scale(1.12); }

.card h2 { margin: 4px 0 6px; font-size: 27px; letter-spacing: 0.02em; }
.card p { margin: 0 0 16px; color: var(--ink-dim); font-size: 14px; }

.res-score {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  padding: 11px 2px;
  margin-bottom: 18px;
  font-size: 13px;
  color: var(--ink-dim);
  letter-spacing: 0.1em;
}
.res-score b { font-size: 26px; color: var(--gold); font-variant-numeric: tabular-nums; }

.card-actions { display: flex; gap: 10px; }
.btn {
  flex: 1;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 13px 10px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.03em;
  color: #2a1d00;
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  box-shadow: 0 5px 0 #8f6512;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #8f6512; }
.btn-ghost {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--edge);
  box-shadow: none;
  flex: 0 0 38%;
}
.btn-ghost:active { transform: translateY(2px); box-shadow: none; }

/* ---------------------------------------------------------------- boot */
.boot {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  background: var(--bg);
  z-index: 20;
  transition: opacity 0.45s ease;
  text-align: center;
  padding: 20px;
}
.boot.gone { opacity: 0; pointer-events: none; }
.boot .crown { font-size: 54px; color: var(--gold); animation: bob 2.1s ease-in-out infinite; }
.boot h1 { margin: 2px 0 2px; font-size: 34px; letter-spacing: 0.16em; text-transform: uppercase; }
.boot p { margin: 0; color: var(--ink-dim); font-size: 13px; letter-spacing: 0.12em; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }

/* ---------------------------------------------------------------- debug */
.debug {
  position: absolute;
  right: 10px;
  bottom: calc(10px + var(--safe-b));
  font: 11px/1.5 ui-monospace, Menlo, Consolas, monospace;
  color: #7de08a;
  background: rgba(0, 0, 0, 0.62);
  border-radius: 8px;
  padding: 7px 10px;
  white-space: pre;
  pointer-events: none;
}

@media (max-width: 520px) {
  .pill { font-size: 11.5px; padding: 5px 10px; }
  .pill b { font-size: 13px; }
  .ammo i { width: 14px; height: 14px; }
  .hint { font-size: 11px; }
}

/* ---------------------------------------------------------------- arena picker */
.card-wide {
  width: min(560px, 94vw);
  padding: 22px 20px 18px;
}

.levels-sub {
  margin: 2px 0 14px;
  opacity: 0.7;
  font-size: 13px;
}

.level-grid {
  display: grid;
  /* Tiles stay legible from 4 across on a phone to 6 on a desktop. */
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px;
  max-height: min(52vh, 420px);
  overflow-y: auto;
  padding: 2px;
  margin-bottom: 16px;
  scrollbar-width: thin;
}

.lvl {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 5px 7px;
  min-height: 74px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.lvl:hover:not(:disabled) {
  background: rgba(242, 193, 78, 0.14);
  border-color: rgba(242, 193, 78, 0.5);
  transform: translateY(-2px);
}

.lvl:disabled {
  opacity: 0.34;
  cursor: default;
}

.lvl-n {
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
}

.lvl-name {
  font-size: 10px;
  line-height: 1.15;
  opacity: 0.72;
  text-align: center;
  /* Two lines then ellipsis — arena names run long. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lvl-stars {
  font-size: 10px;
  letter-spacing: 1px;
  color: #f2c14e;
  min-height: 12px;
}

.lvl-stars .off { opacity: 0.22; }

.lvl.current {
  border-color: rgba(242, 193, 78, 0.75);
  background: rgba(242, 193, 78, 0.1);
}
