:root {
  --gold: #ffb13c;
  --accent: #ff8a3c;
  --ink: #0e1622;
  --panel: rgba(18, 26, 38, 0.84);
  --line: rgba(255, 255, 255, 0.12);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: #fff;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game { display: block; position: fixed; inset: 0; }

/* ---------------- HUD ---------------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
  z-index: 5;
}
.hud-left { text-shadow: 0 2px 10px rgba(0,0,0,0.55); }
#hud-dist {
  font-size: 40px; font-weight: 800; line-height: 1;
  letter-spacing: -1px; color: #fff;
  font-variant-numeric: tabular-nums;
}
#hud-level { font-size: 15px; font-weight: 800; margin-top: 3px; color: #ffd86b; text-shadow: 0 0 10px rgba(255,177,60,0.5); }
#hud-level.cleared { color: #6fdc8a; text-shadow: 0 0 10px rgba(80,210,120,0.6); }
#hud-best { font-size: 14px; opacity: 0.8; margin-top: 4px; font-weight: 600; }

/* Menu level banner */
#level-panel {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 0 0 14px; padding: 10px 14px; border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,177,60,0.16), rgba(255,138,60,0.10));
  border: 1px solid rgba(255,177,60,0.35); font-size: 16px; font-weight: 700;
}
#level-panel .lp-lbl { letter-spacing: 2px; font-size: 12px; opacity: 0.7; }
#level-panel .lp-mid { opacity: 0.6; font-size: 13px; }
#level-panel b { font-size: 20px; color: var(--gold); }
#level-panel #lp-num { color: #fff; }

/* Level-cleared banner (in game window) */
#level-toast {
  position: fixed; top: 36%; left: 50%; transform: translateX(-50%) scale(0.8);
  padding: 12px 22px; border-radius: 16px;
  background: linear-gradient(180deg, rgba(120,235,150,0.96), rgba(60,200,120,0.96));
  color: #06301a; font-size: 20px; font-weight: 900; white-space: nowrap;
  box-shadow: 0 8px 32px rgba(60,200,120,0.5), 0 0 0 2px rgba(255,255,255,0.4) inset;
  opacity: 0; pointer-events: none; z-index: 7;
}
#level-toast.show { animation: goalpop 2.6s cubic-bezier(.2,1.2,.3,1) forwards; }

.go-level { font-size: 15px; font-weight: 800; margin-bottom: 6px; }
.go-level.win { color: #6fdc8a; }
.go-level.miss { color: #ff9a6a; }
#hud-fx { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
#hud-fx span {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700; color: #fff;
  padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 24%, rgba(0,0,0,0.4));
  border: 1px solid var(--c);
  box-shadow: 0 0 10px color-mix(in srgb, var(--c) 50%, transparent);
}
.hud-right { display: flex; gap: 8px; align-items: center; }
#mute, #home {
  pointer-events: auto;
  background: rgba(0,0,0,0.3); border: 1px solid var(--line);
  color: #fff; font-size: 18px; width: 42px; height: 42px;
  border-radius: 12px; cursor: pointer; backdrop-filter: blur(6px);
}

#hud-combo {
  position: fixed; top: 94px; left: 50%; transform: translateX(-50%) scale(0.6);
  font-size: 30px; font-weight: 800; color: var(--gold);
  text-shadow: 0 0 18px rgba(255,177,60,0.85);
  opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none; z-index: 5;
}
#hud-combo.show { opacity: 1; transform: translateX(-50%) scale(1); }

#zone-toast {
  position: fixed; top: 30%; left: 50%; transform: translateX(-50%);
  font-size: 32px; font-weight: 800; letter-spacing: 1px;
  color: #fff; text-shadow: 0 0 22px rgba(255,138,60,0.9);
  opacity: 0; pointer-events: none; z-index: 5; white-space: nowrap; text-align: center;
}
#zone-toast.show { animation: zone 1.9s ease forwards; }
@keyframes zone {
  0% { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.9); }
  18% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.05); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-18px) scale(1); }
}

/* Aim phase instruction. */
#aim-hint {
  position: fixed; left: 50%; bottom: 14%; transform: translateX(-50%);
  font-size: 18px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
  color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,0.6);
  opacity: 0; pointer-events: none; z-index: 5; white-space: nowrap;
  transition: opacity .15s;
}
#aim-hint.show { opacity: 0.95; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.06); } }

/* Goal-completed banner (in the game window). */
#goal-toast {
  position: fixed; top: 42%; left: 50%; transform: translateX(-50%) scale(0.8);
  padding: 10px 18px; border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,216,107,0.95), rgba(255,177,60,0.95));
  color: #2a1402; font-size: 17px; font-weight: 800; white-space: nowrap;
  box-shadow: 0 8px 30px rgba(255,177,60,0.5), 0 0 0 2px rgba(255,255,255,0.4) inset;
  opacity: 0; pointer-events: none; z-index: 6;
}
#goal-toast b { font-weight: 900; }
#goal-toast span { color: #6a3a00; }
#goal-toast.show { animation: goalpop 4.8s cubic-bezier(.2,1.2,.3,1) forwards; }

/* In-game goals panel (bottom-left) */
#goal-hud {
  position: fixed; left: max(12px, env(safe-area-inset-left));
  bottom: max(78px, calc(env(safe-area-inset-bottom) + 78px));
  z-index: 5; display: none; flex-direction: column; gap: 4px; pointer-events: none; max-width: 48vw;
}
#goal-hud.show { display: flex; }
.gh-row { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,0.7); }
.gh-row.done { opacity: 0.55; }
.gh-desc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.gh-bar { flex: 1; min-width: 36px; height: 4px; background: rgba(0,0,0,0.4); border-radius: 999px; overflow: hidden; }
.gh-bar > span { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.gh-row.done .gh-bar > span { background: #6fdc8a; }
/* Menu goal progress bar */
.g-prog { display: inline-block; width: 56px; height: 4px; margin-left: 6px; vertical-align: middle; background: rgba(255,255,255,0.14); border-radius: 999px; overflow: hidden; }
.g-prog > span { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
@keyframes goalpop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6) translateY(10px); }
  12% { opacity: 1; transform: translateX(-50%) scale(1.08) translateY(0); }
  22% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(1) translateY(-24px); }
}

/* ---------------- Overlays ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: radial-gradient(120% 100% at 50% 0%, rgba(10,16,26,0.35), rgba(6,10,18,0.8));
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }

.panel {
  width: min(440px, 100%);
  max-height: 94vh; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 20px 70px rgba(0,0,0,0.6);
  backdrop-filter: blur(14px);
}
.panel.small { width: min(360px, 100%); }

.title {
  font-size: 42px; font-weight: 900; margin: 4px 0 2px;
  letter-spacing: -1px; line-height: 1;
  background: linear-gradient(180deg, #fff, #ffd9a8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 6px 30px rgba(255,138,60,0.35);
}
.title span { color: var(--gold); -webkit-text-fill-color: var(--gold); }
.tagline { margin: 2px 0 16px; opacity: 0.78; font-size: 15px; font-weight: 600; }

.stats { display: flex; gap: 12px; justify-content: center; margin-bottom: 14px; }
.stats > div {
  flex: 1; background: rgba(255,255,255,0.05); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 8px;
}
.stats b { display: block; font-size: 22px; }
.stats small { opacity: 0.6; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }

#name {
  width: 100%; padding: 12px 14px; margin-bottom: 14px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--line);
  border-radius: 12px; color: #fff; font-size: 15px; text-align: center;
  font-family: inherit;
}
#name::placeholder { color: rgba(255,255,255,0.4); }
#name:focus { outline: none; border-color: var(--accent); }

.play {
  width: 100%; padding: 16px;
  font-size: 19px; font-weight: 800; letter-spacing: 0.5px;
  color: #2a1402; cursor: pointer;
  background: linear-gradient(180deg, #ffc07d, var(--accent));
  border: none; border-radius: 14px;
  box-shadow: 0 8px 24px rgba(255,138,60,0.4);
  font-family: inherit;
  transition: transform .08s;
}
.play:active { transform: scale(0.97); }

.col { text-align: left; }
.col h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.65; margin: 18px 0 8px; display: flex; justify-content: space-between; align-items: center; }

/* ---------------- Upgrade shop ---------------- */
.shop-col { margin-bottom: 2px; }
.shop-bal { color: var(--gold); font-weight: 800; letter-spacing: 0; }
.shop-bal.flash { animation: shake 0.35s ease; color: #ff5a6a; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }
.shop { display: flex; flex-direction: column; gap: 6px; }
.shop-item {
  display: flex; align-items: center; gap: 9px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line);
  border-left: 3px solid var(--c, var(--accent));
  border-radius: 10px; padding: 7px 10px; cursor: pointer; color: #fff;
  font-family: inherit; font-size: 13px; text-align: left;
  transition: transform .07s, background .1s;
}
.shop-item:active { transform: scale(0.98); }
.shop-item:hover { background: rgba(255,255,255,0.09); }
.shop-item.broke { opacity: 0.55; }
.shop-item.maxed { opacity: 0.8; cursor: default; }
.si-glyph { font-size: 18px; filter: drop-shadow(0 0 6px var(--c, var(--accent))); }
.si-main { flex: 1; display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.si-main b { font-weight: 700; }
.si-main small { opacity: 0.5; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
/* Level pips */
.si-pips { display: flex; gap: 2px; margin-top: 3px; }
.si-pip { width: 9px; height: 5px; border-radius: 2px; background: rgba(255,255,255,0.16); }
.si-pip.on { background: var(--accent); box-shadow: 0 0 5px var(--accent); }
.si-buy {
  font-size: 12px; font-weight: 800; color: var(--gold);
  background: rgba(255,177,60,0.12); border: 1px solid rgba(255,177,60,0.3);
  border-radius: 8px; padding: 4px 8px; white-space: nowrap;
}
.shop-item.broke .si-buy { color: #ff7a8a; background: rgba(255,90,106,0.1); border-color: rgba(255,90,106,0.3); }
.si-bulk {
  font-size: 11px; font-weight: 800; color: #cfe0ff; white-space: nowrap;
  background: rgba(255,255,255,0.08); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 7px; margin-left: 5px;
}
.si-bulk:hover { background: rgba(255,255,255,0.16); }

/* ---------------- Goals ---------------- */
.goals { display: flex; flex-direction: column; gap: 5px; }
.goal {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line);
  border-radius: 9px; padding: 6px 9px; font-size: 12.5px;
}
.goal.done { border-color: rgba(80,210,120,0.4); background: rgba(80,210,120,0.08); }
.goal .g-tick { color: rgba(255,255,255,0.4); font-weight: 800; }
.goal.done .g-tick { color: #6fdc8a; }
.goal .g-desc { flex: 1; }
.goal .g-rew { font-size: 11px; font-weight: 800; color: var(--gold); white-space: nowrap; }
.goal.done .g-rew { color: #6fdc8a; }
.shop-item.maxed .si-buy { color: #8fe39b; background: rgba(80,210,120,0.12); border-color: rgba(80,210,120,0.3); }

/* ---------------- Characters ---------------- */
.chars { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.char {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 9px; cursor: pointer; color: #fff;
  font-family: inherit; font-size: 13px; text-align: left;
}
.char.sel { border-color: var(--accent); background: rgba(255,138,60,0.12); }
.char.locked { opacity: 0.5; }
.char .cface { font-size: 20px; flex: none; }
.char .cmain { flex: 1; min-width: 0; line-height: 1.1; }
.char .cmain b { font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char .cmain small { font-size: 10px; opacity: 0.7; color: var(--gold); }
.char .ccost { font-size: 11px; opacity: 0.75; white-space: nowrap; }

/* ---------------- In-run inventory bar ---------------- */
#invbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom)); z-index: 6;
  display: none; gap: 10px;
}
#invbar.show { display: flex; }
.inv-btn {
  position: relative; width: 58px; height: 58px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(14,18,28,0.7); border: 2px solid var(--c);
  border-radius: 16px; cursor: pointer; color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 0 14px color-mix(in srgb, var(--c) 45%, transparent);
  backdrop-filter: blur(6px);
}
.inv-btn:active { transform: scale(0.92); }
.ib-glyph { font-size: 26px; filter: drop-shadow(0 0 6px var(--c)); }
.ib-key { position: absolute; top: 3px; left: 6px; font-size: 10px; font-weight: 700; opacity: 0.5; }
.ib-n {
  position: absolute; bottom: -6px; right: -6px;
  min-width: 20px; height: 20px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #2a1402;
  background: var(--c); border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.leaderboard { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.leaderboard li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.leaderboard .rk { width: 18px; opacity: 0.5; font-weight: 700; }
.leaderboard .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .ht { font-weight: 800; color: var(--gold); }
.leaderboard .lb-empty { opacity: 0.5; justify-content: center; font-style: italic; }

.hint { margin: 14px 0 0; font-size: 12px; opacity: 0.5; }

.privacy { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); text-align: center; }
.privacy p { margin: 0 0 8px; font-size: 11px; opacity: 0.45; line-height: 1.4; }
.privacy button {
  background: none; border: 1px solid var(--line); color: rgba(255,255,255,0.55);
  font-family: inherit; font-size: 11px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.privacy button:hover { color: #ff8a8a; border-color: rgba(255,90,90,0.4); }

/* ---------------- Game over ---------------- */
.tag {
  display: inline-block; font-size: 13px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; opacity: 0.7; margin-bottom: 8px;
}
.tag.best { color: var(--gold); opacity: 1; text-shadow: 0 0 18px rgba(255,177,60,0.7); animation: pop .4s ease; }
@keyframes pop { 0% { transform: scale(0.5); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.big {
  font-size: 64px; font-weight: 900; letter-spacing: -2px; line-height: 1;
  margin: 4px 0 12px;
  background: linear-gradient(180deg, #fff, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.go-row { display: flex; justify-content: space-between; font-size: 14px; opacity: 0.85; margin-bottom: 16px; padding: 0 4px; font-weight: 600; }
.go-row span:last-child { color: var(--gold); }

.copy-btn {
  width: 100%; margin-top: 10px; padding: 12px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.3px;
  color: #ffe3c2; cursor: pointer;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line); border-radius: 14px;
  font-family: inherit;
  transition: transform .08s, background .12s, color .12s, border-color .12s;
}
.copy-btn:active { transform: scale(0.97); }
.copy-btn:hover { background: rgba(255,255,255,0.1); }
.copy-btn.copied {
  color: #2a1402; border-color: transparent;
  background: linear-gradient(180deg, #ffd6a8, #ff9d4f);
}
