:root {
  --gold: #ffcf4d;
  --gold-deep: #e0951f;
  --wood: #6b3f1d;
  --wood-dark: #3d2410;
  --cream: #fff4d6;
  --ink: #2a1a0c;
  --red: #d23b2b;
  --green: #6fae3a;
  --sky: #3fb6e8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden; position: fixed;
  background: #0b0805; color: var(--cream);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, Arial, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
/* Disable all zoom (pinch + double-tap) while still allowing menus to scroll vertically */
.screen, .modal, .modal * { touch-action: pan-y; }
#hud, #hud * { touch-action: none; }

#app { position: fixed; inset: 0; width: 100%; height: 100%; }

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

.layer { position: absolute; inset: 0; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { pointer-events: none; }
.hud-top {
  position: absolute; top: calc(10px + var(--safe-top)); left: 0; right: 0;
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
}
.hud-pill {
  display: flex; flex-direction: column; align-items: center; line-height: 1;
  background: rgba(43, 26, 12, 0.62); border: 2px solid rgba(255,207,77,0.55);
  border-radius: 14px; padding: 6px 14px; min-width: 78px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
  backdrop-filter: blur(2px);
}
.hud-pill span:last-child { font-size: 22px; font-weight: 800; color: var(--gold); text-shadow: 0 2px 0 #000; }
.hud-label { font-size: 10px; letter-spacing: 2px; color: var(--cream); opacity: 0.8; margin-bottom: 3px; }
#timePill { margin-left: auto; }
#coinPill { flex-direction: row; gap: 6px; align-items: center; padding: 6px 12px; }
#coinPill .coin-ico { width: 22px; height: 22px; object-fit: contain; }
#coinPill span { font-size: 18px; }

/* ---- power-up buttons ---- */
.powerups {
  position: absolute; left: 12px; bottom: calc(18px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 12px; pointer-events: none;
}
.pu-btn {
  position: relative; width: 66px; height: 66px; border-radius: 18px;
  background: rgba(43,26,12,0.55); border: 2px solid rgba(255,207,77,0.4);
  box-shadow: 0 4px 0 rgba(0,0,0,0.35); pointer-events: auto; cursor: pointer;
  padding: 0; transition: transform 0.08s, filter 0.2s, opacity 0.2s;
  opacity: 0.5; filter: grayscale(0.7);
}
.pu-btn img { width: 70%; height: 70%; object-fit: contain; margin-top: 2px; pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5)); }
.pu-btn:active { transform: translateY(3px) scale(0.96); }
.pu-btn.ready { opacity: 1; filter: grayscale(0); border-color: #ffe680;
  box-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 0 16px rgba(255,200,60,0.7);
  animation: puPulse 1s ease-in-out infinite; }
@keyframes puPulse { 0%,100% { box-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 0 12px rgba(255,200,60,0.5); } 50% { box-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 0 22px rgba(255,200,60,0.95); } }
.pu-btn.armed { border-color: #fff; animation: puPulse 0.4s ease-in-out infinite; }
.pu-label {
  position: absolute; bottom: -3px; left: 0; right: 0; text-align: center;
  font-size: 9px; font-weight: 800; letter-spacing: 1px; color: var(--cream);
  text-shadow: 0 1px 2px #000;
}
.pu-meter { position: absolute; left: 6px; right: 6px; bottom: 9px; height: 5px;
  background: rgba(0,0,0,0.5); border-radius: 3px; overflow: hidden; }
.pu-meter > div { width: 0%; height: 100%; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); transition: width 0.15s; }
#frenzyFill { background: linear-gradient(90deg, #ff7a2a, #ffd23c); }
.pu-count {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px;
  background: var(--red); color: #fff; border-radius: 10px; border: 2px solid #fff;
  font-size: 12px; font-weight: 800; line-height: 16px; text-align: center;
}
.spray-hint {
  position: absolute; top: 30%; left: 0; right: 0; text-align: center; pointer-events: none;
  font-size: 26px; font-weight: 900; color: #fff; letter-spacing: 2px;
  text-shadow: 0 2px 0 #000, 0 0 18px rgba(120,255,120,0.8);
  animation: blink 0.7s ease-in-out infinite;
}
.icon-btn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 50%;
  background: rgba(43,26,12,0.62); border: 2px solid rgba(255,207,77,0.55);
  color: var(--gold); font-weight: 900; font-size: 16px; letter-spacing: 2px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35); cursor: pointer;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.35); }

/* ---- swarm meter (how close to game over) ---- */
.swarm-meter {
  position: absolute; top: calc(64px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; width: min(74%, 320px);
}
.swarm-label { font-size: 11px; font-weight: 800; letter-spacing: 2px; color: var(--cream);
  text-shadow: 0 1px 2px #000; opacity: 0.9; }
.swarm-track {
  flex: 1; height: 12px; border-radius: 7px; overflow: hidden;
  background: rgba(0,0,0,0.5); border: 2px solid rgba(0,0,0,0.45);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}
#swarmFill {
  width: 0%; height: 100%; border-radius: 5px;
  background: linear-gradient(90deg, #6fae3a, #e0b840);
  transition: width 0.25s ease, background 0.25s ease;
}
.swarm-meter.danger #swarmFill { animation: swarmPulse 0.5s ease-in-out infinite; }
@keyframes swarmPulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.5); } }

.combo-banner {
  position: absolute; top: 22%; left: 0; right: 0; text-align: center;
  font-size: 44px; font-weight: 900; color: var(--gold);
  text-shadow: 0 3px 0 #7a3b00, 0 0 18px rgba(255,180,40,0.7);
  opacity: 0; transform: scale(0.6) rotate(-6deg); pointer-events: none;
}
.combo-banner.pop { animation: comboPop 0.7s ease-out; }
@keyframes comboPop {
  0% { opacity: 0; transform: scale(0.4) rotate(-10deg); }
  25% { opacity: 1; transform: scale(1.15) rotate(4deg); }
  60% { opacity: 1; transform: scale(1) rotate(-2deg); }
  100% { opacity: 0; transform: scale(1.05) rotate(0deg); }
}

#dangerVignette {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 140px 40px rgba(150,0,0,0.0);
  transition: opacity 0.3s;
}

/* ---------- Screens ---------- */
.screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  text-align: center;
}
.modal-screen { background: rgba(10, 7, 4, 0.72); backdrop-filter: blur(4px); }

.modal {
  width: min(86vw, 380px);
  background: linear-gradient(#5a3417, #3d2410);
  border: 3px solid var(--gold); border-radius: 22px;
  padding: 22px 20px 24px; display: flex; flex-direction: column; gap: 12px; align-items: center;
  box-shadow: 0 10px 0 rgba(0,0,0,0.4), inset 0 0 0 2px rgba(0,0,0,0.25);
}
.modal h2 {
  font-size: 30px; color: var(--gold); text-shadow: 0 3px 0 #000, 0 0 12px rgba(255,180,40,0.4);
  letter-spacing: 1px; text-transform: uppercase;
}

.btn {
  pointer-events: auto; width: 100%; max-width: 300px;
  padding: 15px 18px; border-radius: 16px; border: none; cursor: pointer;
  font-size: 19px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
  color: var(--cream); background: linear-gradient(#7a4a22, #5a3417);
  border: 2px solid rgba(255,207,77,0.5);
  box-shadow: 0 5px 0 rgba(0,0,0,0.4); transition: transform 0.05s, box-shadow 0.05s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,0.4); }
.btn-primary {
  color: var(--ink); background: linear-gradient(var(--gold), var(--gold-deep));
  border-color: #fff0b8; font-size: 22px;
  box-shadow: 0 6px 0 #8a5400, 0 0 18px rgba(255,180,40,0.35);
}
.btn.danger { background: linear-gradient(#b5402f, #8a2c1f); border-color: #ff9b8a; }

.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: 100%; align-items: center; }
.title-spacer { flex: 1; }
.title-best {
  margin-top: 18px; font-size: 16px; color: var(--cream); opacity: 0.85;
  background: rgba(0,0,0,0.35); padding: 6px 16px; border-radius: 12px;
}
.title-best span { color: var(--gold); font-weight: 800; }

.how-list { text-align: left; align-self: stretch; padding-left: 18px; display: flex; flex-direction: column; gap: 9px; }
.how-list li { font-size: 15px; line-height: 1.35; color: var(--cream); }
.how-list b { color: var(--gold); }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; font-size: 16px; padding: 4px 2px;
}
.toggle {
  pointer-events: auto; min-width: 78px; padding: 8px 12px; border-radius: 12px;
  border: 2px solid rgba(255,207,77,0.5); font-weight: 800; font-size: 14px; cursor: pointer;
  color: var(--ink); background: linear-gradient(var(--gold), var(--gold-deep));
}
.toggle[data-on="false"] { color: var(--cream); background: linear-gradient(#5a5048, #3a332d); border-color: rgba(255,255,255,0.2); }

/* ---------- Game over ---------- */
.go-stats { display: flex; gap: 10px; width: 100%; justify-content: center; margin: 4px 0; }
.go-stat {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  background: rgba(0,0,0,0.3); border-radius: 14px; padding: 10px 6px;
}
.go-num { font-size: 26px; font-weight: 900; color: var(--gold); text-shadow: 0 2px 0 #000; }
.go-cap { font-size: 10px; letter-spacing: 1.5px; opacity: 0.8; margin-top: 4px; }
.go-best { font-size: 15px; opacity: 0.85; }
.go-best span { color: var(--gold); font-weight: 800; }
.go-coins { display: flex; align-items: center; gap: 6px; justify-content: center; font-size: 16px; font-weight: 800; color: var(--gold); }
.go-coins .coin-ico { width: 20px; height: 20px; }
.new-best {
  font-size: 26px; font-weight: 900; color: #fff;
  text-shadow: 0 0 14px var(--gold), 0 2px 0 #000;
  animation: bestPulse 0.7s ease-in-out infinite alternate;
}
@keyframes bestPulse { from { transform: scale(1); } to { transform: scale(1.12); } }

/* ---------- Loading ---------- */
#loading { background: linear-gradient(#241608, #0b0805); }
.loader-logo {
  font-size: 38px; font-weight: 900; letter-spacing: 2px; color: var(--gold);
  text-shadow: 0 4px 0 #7a3b00, 0 0 20px rgba(255,180,40,0.5); margin-bottom: 28px;
  transform: rotate(-3deg);
}
.loader-bar { width: 70%; max-width: 280px; height: 16px; background: rgba(0,0,0,0.5); border-radius: 10px; border: 2px solid rgba(255,207,77,0.4); overflow: hidden; }
#loaderFill { width: 0%; height: 100%; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); transition: width 0.2s; }
.loader-tip { margin-top: 16px; font-size: 14px; opacity: 0.75; font-style: italic; }

/* ---------- Skip hint ---------- */
.skip-hint {
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: calc(40px + var(--safe-bottom));
  font-size: 14px; letter-spacing: 2px; text-transform: uppercase; color: rgba(255,255,255,0.7);
  pointer-events: none; animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.9; } }

.fade-in { animation: fadeIn 0.35s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Title topbar (coins + streak) ---------- */
.title-topbar {
  position: absolute; top: calc(12px + var(--safe-top)); left: 0; right: 0;
  display: flex; justify-content: space-between; padding: 0 14px;
}
.title-coins, .title-streak {
  display: flex; align-items: center; gap: 6px;
  background: rgba(43,26,12,0.6); border: 2px solid rgba(255,207,77,0.5);
  border-radius: 14px; padding: 6px 12px; font-weight: 800; color: var(--gold);
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
}
.title-coins .coin-ico { width: 22px; height: 22px; object-fit: contain; }
.title-streak { color: var(--cream); font-size: 14px; }

/* ---------- Menu icon buttons ---------- */
.menu-row { display: flex; gap: 12px; width: 100%; max-width: 300px; }
.btn-icon {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 24px; padding: 12px 6px; max-width: none;
}
.btn-icon span { font-size: 12px; letter-spacing: 0.5px; }

.modal-wide { width: min(92vw, 420px); max-height: 88vh; overflow-y: auto; }

/* ---------- Mode cards ---------- */
.mode-card {
  width: 100%; text-align: left; cursor: pointer; pointer-events: auto;
  background: linear-gradient(#7a4a22, #5a3417); border: 2px solid rgba(255,207,77,0.5);
  border-radius: 16px; padding: 14px 16px; color: var(--cream);
  box-shadow: 0 4px 0 rgba(0,0,0,0.35); transition: transform 0.06s;
}
.mode-card:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.35); }
.mode-name { font-size: 21px; font-weight: 900; color: var(--gold); text-transform: uppercase; }
.mode-tag { font-size: 12px; background: var(--red); color: #fff; padding: 2px 7px; border-radius: 8px; vertical-align: middle; margin-left: 6px; }
.mode-desc { font-size: 13px; opacity: 0.85; margin: 4px 0 6px; line-height: 1.3; }
.mode-best { font-size: 13px; color: var(--gold); font-weight: 700; }

/* ---------- Shop ---------- */
.shop-coins, .ach-progress {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  font-size: 20px; font-weight: 800; color: var(--gold);
}
.shop-coins .coin-ico { width: 24px; height: 24px; }
.shop-list { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.shop-item {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: rgba(0,0,0,0.28); border: 2px solid rgba(255,207,77,0.3);
  border-radius: 14px; padding: 10px 12px;
}
.shop-item.equipped { border-color: var(--green); }
.shop-racket {
  width: 52px; height: 52px; flex-shrink: 0; display: grid; place-items: center;
  background: rgba(255,255,255,0.06); border-radius: 12px;
}
.shop-racket img { width: 80%; height: 80%; object-fit: contain; }
.shop-info { flex: 1; min-width: 0; }
.shop-rname { font-size: 16px; font-weight: 800; color: var(--cream); }
.shop-rdesc { font-size: 12px; opacity: 0.8; line-height: 1.25; }
.shop-action { flex-shrink: 0; }
.shop-buy, .shop-equip {
  pointer-events: auto; border: none; cursor: pointer; border-radius: 12px;
  font-weight: 800; font-size: 13px; padding: 9px 12px; white-space: nowrap;
}
.shop-buy { background: linear-gradient(var(--gold), var(--gold-deep)); color: var(--ink); display: flex; align-items: center; gap: 4px; }
.shop-buy img { width: 16px; height: 16px; }
.shop-buy:disabled { background: #5a5048; color: #aaa; cursor: default; }
.shop-equip { background: linear-gradient(#7a4a22, #5a3417); color: var(--cream); border: 2px solid rgba(255,207,77,0.5); }
.shop-equip.is-equipped { background: var(--green); color: #163; border-color: #bfe; }

/* ---------- Achievements grid ---------- */
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.ach-item {
  display: flex; gap: 10px; align-items: center; text-align: left;
  background: rgba(0,0,0,0.28); border: 2px solid rgba(255,255,255,0.12);
  border-radius: 12px; padding: 9px 10px;
}
.ach-item.unlocked { border-color: var(--gold); background: rgba(255,200,60,0.12); }
.ach-item.locked { opacity: 0.55; filter: grayscale(0.7); }
.ach-ico { font-size: 26px; flex-shrink: 0; }
.ach-name { font-size: 13px; font-weight: 800; color: var(--cream); }
.ach-desc { font-size: 11px; opacity: 0.8; line-height: 1.2; }

/* ---------- High scores ---------- */
.hs-list { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.hs-row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.28); border-radius: 10px; padding: 8px 12px;
}
.hs-row.top { background: rgba(255,200,60,0.15); border: 1px solid rgba(255,207,77,0.5); }
.hs-rank { font-size: 15px; font-weight: 900; color: var(--gold); width: 26px; flex-shrink: 0; }
.hs-name { flex: 1; font-size: 15px; font-weight: 800; color: var(--cream); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hs-mode { font-size: 10px; letter-spacing: 1px; text-transform: uppercase; opacity: 0.7; }
.hs-score { font-size: 16px; font-weight: 900; color: var(--gold); min-width: 64px; text-align: right; }
.hs-empty { opacity: 0.75; font-style: italic; padding: 16px 0; }

/* ---------- Name entry (game over) ---------- */
.name-entry {
  width: 100%; background: rgba(255,200,60,0.12); border: 2px solid var(--gold);
  border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.name-prompt { font-size: 14px; font-weight: 800; color: var(--gold); text-align: center; }
.name-row { display: flex; gap: 8px; }
#goNameInput {
  flex: 1; min-width: 0; padding: 12px 12px; border-radius: 12px; border: 2px solid rgba(255,207,77,0.5);
  background: rgba(0,0,0,0.35); color: var(--cream); font-size: 16px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 1px; outline: none;
}
#goNameInput::placeholder { color: rgba(255,244,214,0.4); }
.name-row .btn { width: auto; flex-shrink: 0; padding: 12px 18px; font-size: 16px; }
.name-saved { text-align: center; font-weight: 800; color: var(--green); padding: 6px 0; }

/* ---------- Achievement toast ---------- */
#achToasts {
  position: absolute; top: calc(70px + var(--safe-top)); left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; z-index: 50;
}
.ach-toast {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(#5a3417, #3d2410); border: 2px solid var(--gold);
  border-radius: 14px; padding: 10px 16px; box-shadow: 0 6px 16px rgba(0,0,0,0.5);
  animation: toastIn 0.4s ease both;
}
.ach-toast .ach-ico { font-size: 28px; }
.ach-toast .t-title { font-size: 11px; letter-spacing: 1px; color: var(--gold); font-weight: 800; }
.ach-toast .t-name { font-size: 15px; font-weight: 800; color: var(--cream); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
