:root {
  --bg: #050b18;
  --panel: rgba(9, 22, 42, 0.72);
  --cyan: #5fe3ff;
  --cyan-strong: #38c8f0;
  --gold: #ffd34d;
  --text: #eaf7ff;
  --muted: #8fb3cc;
  --red: #ff5d6c;
  --green: #39e58c;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  overflow: hidden;
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  position: relative;
  width: min(100vw, 520px);
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, #12345a 0%, #071226 55%, #040913 100%);
}

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

#app::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at 50% 45%, rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 0.55) 100%);
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: calc(14px + env(safe-area-inset-top)) 18px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 2;
}

.score-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--muted);
}

#score {
  font-size: 34px;
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 18px rgba(95, 227, 255, 0.35);
}

.sub-row {
  display: flex;
  gap: 8px;
  margin-top: 2px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#mult {
  color: var(--gold);
  font-weight: 800;
}

#combo {
  color: var(--cyan);
}

#chain {
  color: var(--gold);
  font-weight: 700;
}

#targetLabel {
  margin-top: 5px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#targetWrap {
  width: 150px;
  height: 4px;
  margin-top: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

#targetBar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #5fe3ff, #ffd34d);
  transition: width 0.12s linear;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hud-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.restart-btn {
  pointer-events: auto;
  height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(120, 200, 255, 0.25);
  background: rgba(10, 30, 55, 0.62);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.restart-btn:active {
  transform: scale(0.95);
  background: rgba(95, 227, 255, 0.18);
}

#throwLabel {
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
}

.icon-btn {
  pointer-events: auto;
  margin-top: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(120, 200, 255, 0.25);
  background: rgba(10, 30, 55, 0.62);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ---------- Toast ---------- */

#toast {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -8px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(5, 18, 36, 0.84);
  border: 1px solid rgba(95, 227, 255, 0.35);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  z-index: 3;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Bottom controls ---------- */

#bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 18px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
  pointer-events: none;
}

#hint {
  text-align: center;
  font-size: 11px;
  color: rgba(200, 230, 255, 0.72);
  min-height: 14px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}



#spinBar {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.spin-btn {
  flex: 1;
  height: 40px;
  border-radius: 14px;
  border: 1px solid rgba(120, 200, 255, 0.22);
  background: rgba(8, 24, 45, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.spin-btn:active {
  transform: scale(0.97);
}

.spin-btn.active {
  color: #04121f;
  background: linear-gradient(180deg, #8ef2ff, #38c8f0);
  border-color: transparent;
  box-shadow: 0 0 18px rgba(95, 227, 255, 0.35);
}

/* ---------- Overlay ---------- */

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(3, 9, 20, 0.56);
  backdrop-filter: blur(10px);
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.card {
  width: 100%;
  max-width: 360px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 22px 20px;
  border-radius: 26px;
  background: linear-gradient(160deg, rgba(18, 44, 78, 0.96), rgba(6, 18, 36, 0.97));
  border: 1px solid rgba(120, 200, 255, 0.22);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  text-align: center;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: #8ef2ff;
  background: rgba(95, 227, 255, 0.1);
  border: 1px solid rgba(95, 227, 255, 0.25);
}

.card h1 {
  margin: 12px 0 4px;
  font-size: 30px;
  letter-spacing: 0.04em;
}

.tagline {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 12px;
}

.how {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
  color: #cfe9ff;
}

.how b {
  display: inline-flex;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(95, 227, 255, 0.16);
  color: #8ef2ff;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  margin-right: 8px;
}

.primary {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #9af4ff, #37c8f0);
  color: #04121f;
  font-size: 16px;
  font-weight: 800;
  font-family: inherit;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(56, 200, 240, 0.35);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.primary:active {
  transform: translateY(1px) scale(0.99);
  box-shadow: 0 6px 18px rgba(56, 200, 240, 0.3);
}

.primary:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

.secondary {
  width: 100%;
  height: 44px;
  margin-top: 8px;
  border: 1px solid rgba(120, 200, 255, 0.25);
  border-radius: 14px;
  background: rgba(10, 30, 55, 0.6);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.04em;
}

.secondary:active {
  transform: scale(0.98);
  background: rgba(95, 227, 255, 0.12);
}

#levelSelect {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(3, 9, 20, 0.66);
  backdrop-filter: blur(10px);
  z-index: 7;
}

.level-card {
  max-width: 360px;
}

.level-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin: 12px 0 14px;
}

.level-btn {
  position: relative;
  min-height: 90px;
  padding: 11px 10px 9px;
  border-radius: 16px;
  border: 1px solid rgba(120, 200, 255, 0.28);
  background: rgba(10, 30, 56, 0.78);
  color: var(--text);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  overflow: hidden;
}

.level-btn b {
  display: block;
  margin: 2px 0 3px;
  font-size: 15px;
}

.level-num {
  display: block;
  color: #5fe3ff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.level-goal {
  display: block;
  color: #ffd34d;
  font-size: 11px;
  font-weight: 700;
}

.level-state {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.level-btn.cleared {
  border-color: rgba(57, 229, 140, 0.55);
  background: rgba(18, 58, 52, 0.72);
}

.level-btn.locked {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.6);
}

#towerOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(3, 9, 20, 0.66);
  backdrop-filter: blur(10px);
  z-index: 6;
}

.tower-card {
  max-width: 360px;
}

.stone-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0 8px;
}

.stone-btn {
  height: 52px;
  border-radius: 14px;
  border: 1px solid rgba(120, 200, 255, 0.3);
  background: rgba(95, 227, 255, 0.08);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}

.stone-btn .lvl {
  display: block;
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 1px;
}

.stone-btn.selected {
  border-color: var(--gold);
  background: rgba(255, 211, 77, 0.14);
  box-shadow: 0 0 16px rgba(255, 211, 77, 0.3);
}

.stone-btn.empty {
  border-style: dashed;
  opacity: 0.25;
  cursor: default;
}

.tower-atk {
  text-align: center;
  font-size: 12px;
  color: var(--gold);
  font-weight: 700;
  margin: 6px 0 10px;
}

.tower-tip {
  margin: 0 0 4px;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}

.rune-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.rune-btn {
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid rgba(120, 200, 255, 0.22);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.rune-btn.chosen {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(255, 211, 77, 0.1);
}

.ball-bar {
  display: flex;
  gap: 6px;
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: none;
  pointer-events: auto;
}

.ball-bar::-webkit-scrollbar {
  display: none;
}

.ball-chip {
  flex: 0 0 66px;
  min-width: 0;
  height: 38px;
  padding: 4px 4px;
  border-radius: 12px;
  border: 1px solid rgba(120, 200, 255, 0.22);
  background: rgba(8, 24, 45, 0.72);
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.ball-chip .ball-name {
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.ball-chip .ball-lv {
  font-size: 9px;
  color: var(--muted);
}

.ball-chip.selected {
  border-color: var(--gold);
  background: rgba(255, 211, 77, 0.14);
  box-shadow: 0 0 14px rgba(255, 211, 77, 0.25);
}

.ball-chip:disabled {
  opacity: 0.5;
  cursor: default;
}

.ball-chip.used {
  opacity: 0.32;
  text-decoration: line-through;
}

.ball-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0 8px;
}

.ball-card {
  padding: 9px 8px;
  border-radius: 14px;
  border: 1px solid rgba(120, 200, 255, 0.3);
  background: rgba(95, 227, 255, 0.07);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.ball-card b {
  display: block;
  font-size: 13px;
}

.ball-card .ball-meta {
  display: block;
  margin-top: 2px;
  font-size: 9px;
  color: var(--gold);
}

.ball-card .ball-desc {
  display: block;
  margin-top: 2px;
  font-size: 9px;
  color: var(--muted);
  line-height: 1.3;
}

.ball-card.selected {
  border-color: var(--gold);
  background: rgba(255, 211, 77, 0.13);
  box-shadow: 0 0 16px rgba(255, 211, 77, 0.26);
}

.ball-card:disabled {
  opacity: 0.45;
  cursor: default;
}

.footnote {
  margin: 12px 0 0;
  font-size: 10px;
  color: rgba(160, 200, 230, 0.55);
}

.result-stats {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rs-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--muted);
}

.rs-row b {
  color: var(--text);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.rs-throws {
  display: flex;
  gap: 6px;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 10px;
  color: rgba(160, 200, 230, 0.72);
  font-variant-numeric: tabular-nums;
}

.rs-stars {
  text-align: center;
  font-size: 30px;
  letter-spacing: 6px;
  color: var(--gold);
  line-height: 1;
  margin: 2px 0 6px;
  text-shadow: 0 0 18px rgba(255, 211, 77, 0.35);
}

.rs-hint {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.hidden {
  display: none !important;
}

#overlay.result .how {
  display: none;
}

@media (min-width: 521px) {
  #app {
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.6);
  }
}

/* =====================================================================
   UI V2 — Arctic Broadcast
   Design goals:
   - HUD readable in glances, controls in thumb zone
   - 44px+ touch targets, safe-area aware
   - one primary action per screen, calm secondary actions
   - no unnecessary motion; reduced-motion respected
   ===================================================================== */

:root {
  --bg-0: #030812;
  --bg-1: #07162b;
  --bg-2: #0c2240;
  --surface: rgba(10, 27, 50, 0.82);
  --surface-strong: rgba(14, 36, 66, 0.94);
  --surface-soft: rgba(255, 255, 255, 0.045);
  --stroke: rgba(151, 213, 255, 0.18);
  --stroke-strong: rgba(151, 213, 255, 0.34);
  --accent: #6fe7ff;
  --accent-deep: #2db8e4;
  --gold: #ffd15c;
  --green: #46e6a0;
  --red: #ff6577;
  --text: #f2faff;
  --muted: #9bbbd1;
  --dim: #6f8da5;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 26px;
  --shadow-card: 0 28px 70px rgba(0, 0, 0, 0.58), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  --shadow-cyan: 0 12px 32px rgba(56, 200, 240, 0.28);
  --font-ui: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --font-num: "DIN Alternate", "Bahnschrift", "SF Pro Display", "PingFang SC", sans-serif;
}

html,
body {
  background: var(--bg-0);
  font-family: var(--font-ui);
}

#app {
  background:
    radial-gradient(110% 70% at 50% -10%, rgba(58, 148, 220, 0.26) 0%, transparent 55%),
    radial-gradient(80% 50% at 50% 105%, rgba(25, 88, 130, 0.18) 0%, transparent 60%),
    linear-gradient(180deg, #061225 0%, #030812 60%, #02060d 100%);
}

#app::after {
  background:
    radial-gradient(ellipse at 50% 42%, transparent 24%, rgba(0, 0, 0, 0.5) 100%),
    linear-gradient(180deg, rgba(2, 7, 15, 0.28), transparent 18%, transparent 80%, rgba(2, 7, 15, 0.42));
}

button {
  font-family: var(--font-ui);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- HUD ---------- */

#hud {
  top: 0;
  padding: calc(10px + env(safe-area-inset-top)) 14px 0;
  display: block;
  z-index: 3;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.hud-left {
  min-width: 0;
  flex: 0 1 auto;
}

.score-label {
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.22em;
  color: rgba(180, 218, 240, 0.68);
  font-weight: 700;
}

.score-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

#score {
  font-family: var(--font-num);
  font-size: 38px;
  font-weight: 900;
  line-height: 0.92;
  letter-spacing: -0.03em;
  color: var(--text);
  text-shadow: 0 4px 24px rgba(95, 227, 255, 0.32);
  font-variant-numeric: tabular-nums;
}

.mult-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255, 209, 92, 0.36);
  background: rgba(255, 209, 92, 0.11);
  color: var(--gold);
  font-size: 10px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat-row {
  display: flex;
  gap: 5px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(5, 18, 35, 0.55);
  border: 1px solid rgba(151, 213, 255, 0.14);
  color: rgba(196, 228, 246, 0.8);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#mult,
#combo,
#chain {
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
}

#mult {
  color: var(--gold);
}

#chain {
  color: #ffd976;
}

.hud-right {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  text-align: right;
}

.resource-pill {
  max-width: 182px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(5, 18, 35, 0.52);
  border: 1px solid rgba(151, 213, 255, 0.16);
  color: rgba(215, 239, 252, 0.86);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.hud-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 0;
}

.hud-action {
  pointer-events: auto;
  height: 44px;
  min-width: 44px;
  padding: 0 10px;
  border-radius: 14px;
  border: 1px solid rgba(151, 213, 255, 0.2);
  background: linear-gradient(180deg, rgba(20, 46, 78, 0.86), rgba(7, 22, 42, 0.86));
  color: rgba(236, 249, 255, 0.92);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.hud-action-icon {
  font-size: 14px;
  line-height: 1;
  opacity: 0.9;
}

.hud-action:active {
  transform: scale(0.95);
  background: rgba(42, 103, 142, 0.9);
}

.hud-action.icon-btn {
  width: 44px;
  padding: 0;
  font-size: 15px;
  border-radius: 50%;
}

#throwLabel {
  color: rgba(222, 244, 255, 0.9);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(5, 18, 35, 0.54);
  border: 1px solid rgba(151, 213, 255, 0.14);
  white-space: nowrap;
}

.objective-card {
  margin-top: 6px;
  padding: 7px 10px 7px;
  border-radius: 15px;
  border: 1px solid rgba(151, 213, 255, 0.16);
  background: linear-gradient(180deg, rgba(10, 30, 55, 0.72), rgba(5, 17, 33, 0.62));
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(12px);
}

.objective-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#targetLabel {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.015em;
  color: rgba(230, 247, 255, 0.92);
  font-variant-numeric: tabular-nums;
}

#targetWrap {
  width: 100%;
  height: 5px;
  margin-top: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

#targetBar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #5fe3ff 0%, #b9f4ff 52%, #ffd15c 100%);
  box-shadow: 0 0 12px rgba(95, 227, 255, 0.45);
  transition: width 0.16s linear;
}

/* ---------- Bottom controls ---------- */

#bottom {
  bottom: 0;
  padding: 0 14px calc(10px + env(safe-area-inset-bottom));
  gap: 5px;
  z-index: 3;
}

#hint {
  position: absolute;
  left: 14px;
  bottom: calc(134px + env(safe-area-inset-bottom));
  max-width: 176px;
  margin: 0;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(4, 17, 33, 0.6);
  border: 1px solid rgba(151, 213, 255, 0.12);
  backdrop-filter: blur(8px);
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(205, 233, 248, 0.74);
  text-shadow: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  z-index: 4;
}

.bottom-dock {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px;
  border-radius: 21px;
  border: 1px solid rgba(151, 213, 255, 0.16);
  background: linear-gradient(180deg, rgba(12, 32, 58, 0.82), rgba(4, 15, 30, 0.9));
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(14px) saturate(1.1);
}

.ball-bar {
  gap: 6px;
  padding-bottom: 0;
  min-height: 44px;
  align-items: stretch;
}

.ball-chip {
  flex: 0 0 auto;
  min-width: 86px;
  height: 44px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid rgba(151, 213, 255, 0.18);
  background: linear-gradient(180deg, rgba(16, 39, 68, 0.9), rgba(6, 20, 38, 0.9));
  color: var(--text);
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.ball-chip .ball-name {
  font-size: 11px;
  font-weight: 800;
  color: rgba(240, 251, 255, 0.92);
}

.ball-chip .ball-lv {
  font-size: 10px;
  color: var(--muted);
  padding: 1px 4px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
}

.ball-chip.selected {
  border-color: rgba(255, 209, 92, 0.72);
  background: linear-gradient(180deg, rgba(74, 64, 31, 0.56), rgba(24, 27, 26, 0.9));
  box-shadow: 0 0 0 1px rgba(255, 209, 92, 0.16), 0 6px 18px rgba(255, 209, 92, 0.1);
}

.ball-chip.used {
  opacity: 0.34;
}

.ball-chip:active {
  transform: scale(0.97);
}

#spinBar {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 15px;
  background: rgba(2, 12, 25, 0.5);
  border: 1px solid rgba(151, 213, 255, 0.1);
}

.spin-btn {
  flex: 1;
  height: 44px;
  border-radius: 11px;
  border: 0;
  background: transparent;
  color: rgba(181, 214, 233, 0.78);
  font-size: 12px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  letter-spacing: 0.03em;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.spin-glyph {
  font-size: 15px;
  line-height: 1;
  opacity: 0.82;
}

.spin-btn.active {
  color: #04121f;
  background: linear-gradient(180deg, #a8f6ff, #42c9ec);
  box-shadow: 0 4px 18px rgba(95, 227, 255, 0.3);
}

.spin-btn.active .spin-glyph {
  opacity: 1;
}

/* ---------- Modal foundations ---------- */

#overlay,
#towerOverlay,
#levelSelect {
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(30, 93, 140, 0.12), transparent 60%),
    rgba(2, 8, 17, 0.68);
  backdrop-filter: blur(15px) saturate(1.15);
}

#overlay {
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  z-index: 8;
}

#levelSelect {
  z-index: 10;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}

#towerOverlay {
  z-index: 9;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
}

.card {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: calc(100dvh - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: 24px 20px 18px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(23, 54, 90, 0.96), rgba(6, 19, 38, 0.98) 45%, rgba(4, 13, 27, 0.99)),
    var(--surface-strong);
  border: 1px solid rgba(173, 224, 255, 0.24);
  box-shadow: var(--shadow-card);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  text-align: center;
}

.card::-webkit-scrollbar {
  display: none;
}

.card::before {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(174, 238, 255, 0.8), transparent);
  pointer-events: none;
}

.card h1 {
  margin: 10px 0 5px;
  font-size: 34px;
  line-height: 1.08;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #f6fcff;
  text-shadow: 0 3px 24px rgba(95, 227, 255, 0.16);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.17em;
  font-weight: 800;
  color: #9ff1ff;
  background: rgba(95, 227, 255, 0.09);
  border: 1px solid rgba(95, 227, 255, 0.26);
}

.tagline {
  margin: 0 0 16px;
  color: rgba(186, 218, 236, 0.78);
  font-size: 11px;
  line-height: 1.45;
}

/* ---------- Menu ---------- */

.menu-card {
  padding: 26px 20px 18px;
}

.menu-hero {
  padding: 2px 0 4px;
}

.brand-kicker {
  font-size: 8px;
  line-height: 1;
  letter-spacing: 0.24em;
  font-weight: 800;
  color: rgba(112, 232, 255, 0.62);
}

.menu-hero h1 {
  margin: 8px 0 5px;
  font-size: 39px;
  letter-spacing: 0.015em;
}

.menu-hero .tagline {
  margin: 0 0 14px;
  font-size: 11px;
}

.menu-progress {
  margin: 0 0 12px;
  padding: 8px 10px 9px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(151, 213, 255, 0.12);
  text-align: left;
}

.menu-progress-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 9px;
  letter-spacing: 0.06em;
  color: rgba(183, 216, 235, 0.72);
}

.menu-progress-top b {
  font-family: var(--font-num);
  font-size: 12px;
  color: rgba(239, 251, 255, 0.92);
  font-variant-numeric: tabular-nums;
}

.menu-progress-track,
.level-progress-track {
  height: 4px;
  margin-top: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

#menuProgressBar,
#levelProgressBar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4ee3ff, #b8f7ff 60%, #ffd15c);
  box-shadow: 0 0 10px rgba(95, 227, 255, 0.38);
  transition: width 0.35s ease;
}

.how {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  margin: 0 0 14px;
  padding: 7px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(151, 213, 255, 0.1);
  text-align: left;
}

.how > div {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  min-height: 27px;
  padding: 4px 5px;
  font-size: 10.5px;
  line-height: 1.35;
  color: rgba(207, 235, 249, 0.82);
}

.how b {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(95, 227, 255, 0.12);
  border: 1px solid rgba(95, 227, 255, 0.2);
  color: #9ff1ff;
  font-size: 9px;
  line-height: 1;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.primary {
  height: 56px;
  border: 0;
  border-radius: 17px;
  background: linear-gradient(180deg, #b1f8ff 0%, #62e1ff 35%, #30bfe6 100%);
  color: #03121e;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(48, 185, 230, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.primary:active {
  transform: translateY(1px) scale(0.99);
  filter: brightness(0.96);
  box-shadow: 0 6px 16px rgba(48, 185, 230, 0.26);
}

.primary:disabled {
  opacity: 0.42;
  box-shadow: none;
  filter: grayscale(0.25);
}

.secondary {
  height: 48px;
  margin-top: 0;
  border: 1px solid rgba(151, 213, 255, 0.2);
  border-radius: 15px;
  background: rgba(8, 25, 47, 0.74);
  color: rgba(229, 247, 255, 0.9);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.secondary:active {
  transform: scale(0.985);
  background: rgba(95, 227, 255, 0.11);
  border-color: rgba(151, 213, 255, 0.3);
}

.footnote {
  margin: 12px 0 0;
  font-size: 10px;
  line-height: 1.4;
  color: rgba(143, 179, 204, 0.6);
}

/* Result mode: keep one clear primary action, trim the menu. */
#overlay.result .how,
#overlay.result .menu-progress,
#overlay.result .menu-hero .tagline,
#overlay.result .brand-kicker {
  display: none;
}

#overlay.result .menu-hero h1 {
  margin: 6px 0 8px;
  font-size: 32px;
}

#overlay.result .card {
  padding-top: 28px;
}

/* ---------- Level select ---------- */

.level-card {
  max-width: 390px;
  padding: 22px 18px 16px;
}

.level-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.level-progress-text {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 9px;
  color: rgba(183, 216, 235, 0.65);
}

.level-progress-text b {
  font-family: var(--font-num);
  color: rgba(239, 251, 255, 0.92);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.level-card h1 {
  font-size: 30px;
  margin-top: 10px;
}

.level-progress-track {
  margin: 0 0 12px;
}

.level-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 12px;
}

.level-btn {
  position: relative;
  min-height: 92px;
  padding: 10px 10px 9px;
  border-radius: 17px;
  border: 1px solid rgba(151, 213, 255, 0.17);
  background:
    linear-gradient(160deg, rgba(18, 45, 77, 0.9), rgba(7, 22, 42, 0.92));
  color: var(--text);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.level-btn::after {
  content: "";
  position: absolute;
  right: -18px;
  bottom: -24px;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 1px solid rgba(151, 213, 255, 0.08);
  pointer-events: none;
}

.level-btn b {
  display: block;
  margin: 2px 0 3px;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.level-num {
  display: block;
  color: rgba(111, 231, 255, 0.92);
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  line-height: 1;
}

.level-goal {
  display: block;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.level-state {
  display: block;
  margin-top: 4px;
  color: rgba(163, 199, 220, 0.65);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.level-btn.cleared {
  border-color: rgba(70, 230, 160, 0.42);
  background: linear-gradient(160deg, rgba(20, 67, 61, 0.82), rgba(6, 27, 31, 0.94));
}

.level-btn.cleared .level-state {
  color: rgba(133, 238, 190, 0.9);
}

.level-btn.current {
  border-color: rgba(111, 231, 255, 0.6);
  background: linear-gradient(160deg, rgba(21, 70, 103, 0.9), rgba(6, 24, 46, 0.96));
  box-shadow: 0 0 0 1px rgba(111, 231, 255, 0.1), 0 8px 24px rgba(0, 0, 0, 0.22);
}

.level-btn.current .level-state {
  color: rgba(180, 245, 255, 0.95);
}

.level-btn.locked {
  opacity: 0.58;
  cursor: not-allowed;
  filter: saturate(0.55);
}

.level-btn:not(.locked):active {
  transform: scale(0.975);
}

.level-btn.locked::after {
  border-color: rgba(151, 213, 255, 0.03);
}

.level-card .secondary {
  margin-top: 2px;
}

/* ---------- Tower / choice cards ---------- */

.tower-card {
  max-width: 380px;
}

.tower-card h1 {
  font-size: 29px;
}

.ball-grid {
  gap: 8px;
  margin: 12px 0 8px;
}

.ball-card {
  padding: 10px 9px;
  border-radius: 15px;
  border: 1px solid rgba(151, 213, 255, 0.2);
  background: linear-gradient(160deg, rgba(18, 45, 77, 0.9), rgba(7, 22, 42, 0.92));
  text-align: left;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.ball-card:active {
  transform: scale(0.98);
}

.ball-card b {
  font-size: 12px;
  line-height: 1.3;
}

.ball-card .ball-meta {
  font-size: 9px;
}

.ball-card .ball-desc {
  font-size: 9px;
  line-height: 1.4;
}

.tower-tip {
  font-size: 9px;
  line-height: 1.4;
}

.tower-atk {
  font-size: 11px;
  padding: 7px 8px;
  border-radius: 11px;
  background: rgba(255, 209, 92, 0.07);
  border: 1px solid rgba(255, 209, 92, 0.15);
}

/* ---------- Result ---------- */

.result-stats {
  gap: 7px;
  padding: 13px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(151, 213, 255, 0.1);
}

.rs-row {
  min-height: 22px;
  font-size: 10px;
}

.rs-row b {
  font-family: var(--font-num);
  font-size: 17px;
}

.rs-stars {
  font-size: 30px;
}

/* ---------- Toast ---------- */

#toast {
  left: 14px;
  right: auto;
  top: auto;
  bottom: calc(172px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: min(250px, calc(100% - 28px));
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid rgba(151, 213, 255, 0.22);
  background: linear-gradient(180deg, rgba(14, 39, 67, 0.9), rgba(5, 18, 35, 0.9));
  color: rgba(240, 251, 255, 0.94);
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0.01em;
  text-align: left;
  white-space: normal;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  z-index: 6;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Motion ---------- */

@keyframes ui-rise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes ui-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

#overlay.show .card,
#levelSelect:not(.hidden) .card,
#towerOverlay:not(.hidden) .card {
  animation: ui-rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

#overlay.show,
#levelSelect:not(.hidden),
#towerOverlay:not(.hidden) {
  animation: ui-fade 0.2s ease;
}

#toast.show {
  animation: toast-in 0.18s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Responsive / ergonomics ---------- */

@media (max-width: 360px) {
  #hud {
    padding-left: 10px;
    padding-right: 10px;
  }

  #bottom {
    padding-left: 10px;
    padding-right: 10px;
  }

  #score {
    font-size: 32px;
  }

  .hud-action {
    height: 44px;
    padding: 0 8px;
  }

  .hud-action.icon-btn {
    width: 44px;
  }

  .card {
    padding-left: 16px;
    padding-right: 16px;
  }

  .level-card {
    padding-left: 14px;
    padding-right: 14px;
  }

  .level-btn {
    min-height: 86px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .level-btn b {
    font-size: 13px;
  }

  .how {
    gap: 4px;
  }

  .how > div {
    font-size: 9px;
  }
}

@media (max-height: 720px) {
  .card {
    padding-top: 18px;
    padding-bottom: 14px;
  }

  .menu-hero h1 {
    font-size: 32px;
    margin-top: 5px;
  }

  .menu-hero .tagline {
    margin-bottom: 9px;
  }

  .how {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 6px;
  }

  .how > div {
    min-height: 24px;
    padding: 3px 4px;
  }

  .level-btn {
    min-height: 78px;
    padding-top: 8px;
    padding-bottom: 7px;
  }

  .level-card h1 {
    font-size: 26px;
    margin: 7px 0 4px;
  }

  .level-card .tagline {
    margin-bottom: 8px;
  }

  .primary {
    height: 52px;
  }

  .secondary {
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

/* Keyboard / large screen affordances */
@media (hover: hover) {
  .hud-action:hover,
  .secondary:hover {
    border-color: rgba(151, 213, 255, 0.34);
    background-color: rgba(32, 70, 105, 0.7);
  }

  .level-btn:not(.locked):hover {
    transform: translateY(-1px);
    border-color: rgba(151, 213, 255, 0.36);
  }

  .ball-card:hover {
    border-color: rgba(255, 209, 92, 0.34);
  }
}

