:root {
  --orange: #ff6600;
  --orange-hot: #ff8533;
  --orange-dim: #cc5200;
  --black: #0a0a0a;
  --ink: #121212;
  --panel: #1a1a1a;
  --panel-2: #222;
  --white: #f5f5f5;
  --muted: #9a9a9a;
  --shadow: 0 8px 32px rgba(0,0,0,.55);
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Ubuntu, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--black);
  color: var(--white);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(255,102,0,.18), transparent 60%),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(255,102,0,.08), transparent 50%),
    var(--black);
}
.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 10px 10px 8px;
  gap: 8px;
  min-height: 0;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand h1 {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: .02em;
  line-height: 1.15;
  display: flex;
  flex-direction: column;
}
.brand h1 span {
  font-size: .68rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
}
.logo-link {
  display: block;
  line-height: 0;
  flex-shrink: 0;
  transition: transform .15s ease, filter .15s ease;
}
.logo-link:hover,
.logo-link:focus-visible {
  transform: scale(1.06);
  filter: drop-shadow(0 0 12px rgba(255,102,0,.55));
  outline: none;
}
.logo-link img {
  display: block;
  border-radius: 50%;
}
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.stat {
  font-size: .72rem;
  color: var(--muted);
  font-weight: 600;
  background: var(--panel);
  border: 1px solid rgba(255,102,0,.25);
  border-radius: 8px;
  padding: 5px 8px;
}
.stat strong {
  color: var(--orange);
  font-size: .9rem;
  margin-left: 2px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255,102,0,.35);
  border-radius: 10px;
  background: var(--panel);
  color: var(--white);
  font-size: 1.1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { border-color: var(--orange); background: #24180f; }
.icon-btn.muted { opacity: .55; }

.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050505;
  border: 1px solid rgba(255,102,0,.35);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow), inset 0 0 40px rgba(255,102,0,.06);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  max-height: min(72vh, 720px);
  object-fit: contain;
  background: #000;
  touch-action: none;
}
.touch-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .65rem;
  color: rgba(255,255,255,.35);
  pointer-events: none;
  white-space: nowrap;
}
.touch-pad {
  display: none;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
  flex-shrink: 0;
  padding: 0 2px;
}
.move-zone {
  height: 72px;
  border-radius: 14px;
  border: 1px dashed rgba(255,102,0,.4);
  background: rgba(255,102,0,.06);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .12em;
  touch-action: none;
}
.fire-btn {
  height: 72px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--orange-hot), var(--orange-dim));
  color: #111;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 4px 16px rgba(255,102,0,.35);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.fire-btn:active,
.fire-btn.held {
  transform: scale(.97);
  filter: brightness(1.1);
}
.fire-btn .btn-title { font-size: 1.15rem; letter-spacing: .08em; }
.fire-btn .btn-sub { font-size: .65rem; font-weight: 700; opacity: .75; }
.controls-hint {
  text-align: center;
  font-size: .68rem;
  color: #666;
  line-height: 1.4;
  flex-shrink: 0;
  padding-bottom: 4px;
}
.controls-hint b { color: var(--orange); }

@media (pointer: coarse), (max-width: 640px) {
  .touch-pad { display: grid; }
  .controls-hint { display: none; }
  .touch-hint { display: none; }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  backdrop-filter: blur(6px);
}
.overlay.hidden { display: none; }
.card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid rgba(255,102,0,.45);
  border-radius: var(--radius);
  padding: 22px 20px 18px;
  box-shadow: var(--shadow), 0 0 40px rgba(255,102,0,.12);
  text-align: center;
}
.logo-hero {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  margin: 0 auto 10px;
  filter: drop-shadow(0 8px 24px rgba(255,102,0,.4));
  display: block;
}
.card h2 {
  font-size: 1.35rem;
  font-weight: 900;
  margin-bottom: 8px;
  letter-spacing: .02em;
}
.dollar { color: var(--orange); }
.card p {
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.45;
  margin-bottom: 12px;
}
.how {
  text-align: left;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  font-size: .82rem;
  color: var(--white);
  line-height: 1.45;
}
.how li {
  padding: 7px 10px;
  margin-bottom: 6px;
  background: rgba(0,0,0,.28);
  border-radius: 8px;
  border-left: 3px solid var(--orange);
}
.how b { color: var(--orange); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 160px;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  font-weight: 900;
  font-size: 1rem;
  letter-spacing: .06em;
  cursor: pointer;
  padding: 0 22px;
  transition: transform .1s ease, filter .15s ease;
}
.btn.primary {
  background: linear-gradient(180deg, var(--orange-hot), var(--orange));
  color: #111;
  box-shadow: 0 4px 20px rgba(255,102,0,.4);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:active { transform: scale(.97); }
.fine {
  margin-top: 14px;
  font-size: .75rem;
  color: #666;
}
.fine a { color: var(--orange); text-decoration: none; font-weight: 700; }
.fine a:hover { text-decoration: underline; }
.end-score {
  font-size: 1.4rem !important;
  color: var(--white) !important;
  margin-bottom: 4px !important;
}
.end-score strong { color: var(--orange); font-size: 1.6rem; }
.end-wave { margin-bottom: 6px !important; }
.end-feel {
  color: var(--orange) !important;
  font-weight: 800 !important;
  font-size: 1rem !important;
  letter-spacing: .02em;
}

@media (max-height: 700px) {
  .logo-hero { width: 88px; height: 88px; }
  .card { padding: 16px 14px 14px; }
  .how li { padding: 5px 8px; margin-bottom: 4px; }
}

/* ---- Leaderboard / score submit (Quote Swap / Hodl style) ---- */
.score-submit {
  margin: 8px 0 14px;
  text-align: left;
}
.name-label {
  display: block;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--orange);
  font-weight: 700;
  margin-bottom: 6px;
}
.name-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}
.name-row input {
  flex: 1 1 140px;
  min-width: 0;
  appearance: none;
  border: 1px solid #444;
  border-radius: 999px;
  background: #151515;
  color: var(--white);
  padding: 10px 14px;
  font-size: .95rem;
  font-family: inherit;
  outline: none;
}
.name-row input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(255,102,0,.25);
}
.name-row .btn.primary {
  width: auto;
  flex: 0 0 auto;
  min-width: 0;
  padding: 10px 18px;
  font-size: .9rem;
}
.name-row .btn.primary:disabled {
  opacity: .55;
  cursor: not-allowed;
  filter: none;
}
.submit-status {
  margin-top: 8px !important;
  margin-bottom: 0 !important;
  font-size: .8rem !important;
  color: var(--muted) !important;
}
.submit-status.ok { color: #6dcc7a !important; }
.submit-status.err { color: #ff6b6b !important; }

.leaderboard {
  margin: 4px 0 16px;
  text-align: left;
  background: #121212;
  border: 1px solid #2a2a2a;
  border-radius: 14px;
  padding: 12px 14px;
  max-height: 220px;
  overflow-y: auto;
}
.leaderboard h3 {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--orange);
  margin-bottom: 8px;
}
.lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.lb-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 8px;
  align-items: center;
  font-size: .86rem;
  padding: 6px 8px;
  border-radius: 8px;
  background: #181818;
  color: #ddd;
}
.lb-list li .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-list li .lb-name {
  font-weight: 700;
  color: var(--white);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-list li .lb-score { color: var(--orange); font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-list li .lb-wave { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
.lb-list li.empty {
  display: block;
  text-align: center;
  color: var(--muted);
  background: transparent;
}
.again-below { display: block; width: 100%; margin-top: 10px; }
.leaderboard .lb-list, .leaderboard ol { max-height: 110px !important; overflow: auto; }
.card.endish {
  max-height: min(78vh, 560px);
  overflow: auto;
  padding-top: 14px;
  padding-bottom: 14px;
}
.card.endish .logo-hero { width: 72px; height: 72px; margin-bottom: 6px; }
.card.endish h2 { font-size: 1.15rem; margin: 4px 0; }
.card.endish p { margin: 4px 0; }

.leaderboard::-webkit-scrollbar { width: 10px; }
.leaderboard::-webkit-scrollbar-track { background: #2a2a2a; border-radius: 999px; }
.leaderboard::-webkit-scrollbar-thumb {
  background: var(--orange-dim);
  border-radius: 999px;
}
.leaderboard::-webkit-scrollbar-thumb:hover { background: var(--orange-hot); }

#startOverlay .start-leaderboard {
  margin: 0 0 12px;
  padding: 8px 10px;
  max-height: 140px;
  overflow-y: auto;
  border-radius: 12px;
}
#startOverlay .board-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
#startOverlay .board-heading h3 {
  margin: 0;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--orange);
}
#startOverlay .board-heading span {
  color: var(--muted);
  font-size: .68rem;
}
#startOverlay .start-leaderboard .lb-list {
  gap: 3px;
  max-height: none !important;
  overflow: visible;
}
#startOverlay .start-leaderboard .lb-list li {
  grid-template-columns: 22px minmax(0, 1fr) auto 40px;
  gap: 6px;
  padding: 5px 6px;
  font-size: .76rem;
}
#startOverlay .start-leaderboard .lb-list li .lb-wave {
  font-size: .68rem;
  text-align: right;
}
#startOverlay .start-leaderboard .lb-list li.empty {
  display: block;
  padding: 5px 2px;
}
