:root {
  --ink: #2a2350;
  --ink-soft: rgba(42, 35, 80, 0.55);
  --card: rgba(255, 255, 255, 0.92);
  --card-line: rgba(124, 92, 255, 0.18);
  --accent: #7c5cff;
  --accent2: #ff4d8d;
  --btn-alt: #f1ecff;
  --shadow: 0 18px 50px rgba(60, 30, 140, 0.22);
}
body.dark {
  --ink: #f4f1ff;
  --ink-soft: rgba(244, 241, 255, 0.6);
  --card: rgba(26, 19, 58, 0.94);
  --card-line: rgba(185, 168, 255, 0.22);
  --btn-alt: rgba(255, 255, 255, 0.08);
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #f1ecff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}
body.dark { background: #141033; }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; cursor: crosshair; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#scoreBox { position: absolute; left: max(18px, env(safe-area-inset-left)); top: 14px; }
#score {
  font-size: clamp(34px, 7vmin, 64px); font-weight: 900; line-height: 1;
  letter-spacing: -1px; font-variant-numeric: tabular-nums;
  text-shadow: 0 3px 0 rgba(124, 92, 255, 0.18);
}
#score.bump { animation: bump .22s ease-out; }
@keyframes bump { 0% { transform: scale(1.25); color: var(--accent); } 100% { transform: scale(1); } }
#best { margin-top: 4px; font-size: clamp(12px, 2.2vmin, 16px); font-weight: 800; color: var(--ink-soft); letter-spacing: 1px; }
#rightBox { position: absolute; right: max(14px, env(safe-area-inset-right)); top: 14px; display: flex; align-items: center; gap: 12px; }
#lives { display: flex; gap: 6px; }
#lives svg { width: clamp(24px, 4.6vmin, 36px); height: auto; fill: #ff4d8d; filter: drop-shadow(0 3px 4px rgba(255, 77, 141, 0.35)); transition: transform .2s, opacity .2s; }
#lives svg.lost { fill: rgba(128, 118, 170, 0.28); filter: none; transform: scale(0.85); }
#lives svg.hit { animation: hit .45s ease-out; }
@keyframes hit { 0%,100% { transform: scale(0.85); } 30% { transform: scale(1.4) rotate(-12deg); } 60% { transform: scale(0.9) rotate(8deg); } }

.iconBtn {
  pointer-events: auto; width: clamp(42px, 7vmin, 54px); height: clamp(42px, 7vmin, 54px);
  border: none; border-radius: 16px; background: var(--card); box-shadow: 0 6px 18px rgba(60, 30, 140, 0.18);
  display: grid; place-items: center; cursor: pointer; transition: transform .12s;
}
.iconBtn:active { transform: scale(0.92); }
.iconBtn svg { width: 46%; fill: var(--accent); }
body.state-over #gear, body.state-dying #gear { visibility: hidden; }
body.state-ready #scoreBox #score, body.state-ready #lives { visibility: hidden; }

#powerBar { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); width: min(32vw, 260px); height: 10px; border-radius: 10px; background: rgba(124, 92, 255, 0.15); overflow: hidden; opacity: 0; transition: opacity .2s; }
#powerBar.on { opacity: 1; }
#powerFill { height: 100%; width: 100%; border-radius: 10px; background: #ffb020; }

/* ---------- Start ---------- */
#start { position: fixed; inset: 0; pointer-events: none; text-align: center; transition: opacity .35s, transform .35s; }
#start.gone { opacity: 0; transform: scale(1.08); visibility: hidden; transition: opacity .35s, transform .35s, visibility 0s .35s; }
body.cover #title { top: 50%; transform: translateY(-50%); font-size: 17vmin; animation: none; }
body.cover #hint { display: none; }
#title {
  position: absolute; left: 0; right: 0; top: 9vh; margin: 0;
  font-size: clamp(46px, 12vmin, 120px); font-weight: 900; line-height: .9; letter-spacing: -2px;
  animation: floaty 3s ease-in-out infinite;
}
#title span { display: block; }
#title .t1 { background: linear-gradient(90deg, #ff4d8d, #7c5cff 60%, #19c3ff); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 5px 0 rgba(124, 92, 255, 0.2)); }
#title .t2 { color: var(--ink); font-size: .62em; letter-spacing: .32em; margin-left: .32em; margin-top: .12em; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
#hint {
  position: absolute; left: 0; right: 0; bottom: 12vh; margin: 0;
  font-size: clamp(16px, 3.4vmin, 26px); font-weight: 900; letter-spacing: 3px; color: var(--accent);
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* ---------- Panels ---------- */
.panel { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(30, 20, 70, 0.28); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.panel.hidden, .hidden { display: none !important; }
.card {
  width: min(88vw, 400px); max-height: 92vh; overflow: hidden;
  padding: clamp(18px, 4vmin, 30px); border-radius: 30px; background: var(--card);
  border: 2px solid var(--card-line); box-shadow: var(--shadow); text-align: center;
  animation: pop .32s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.label { font-weight: 900; letter-spacing: 4px; font-size: 14px; color: var(--ink-soft); }
#finalScore { font-size: clamp(56px, 14vmin, 92px); font-weight: 900; line-height: 1; margin: 4px 0; background: linear-gradient(90deg, #ff4d8d, #7c5cff, #19c3ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
#newBest { display: inline-block; padding: 5px 14px; border-radius: 99px; background: #ffb020; color: #fff; font-weight: 900; letter-spacing: 2px; font-size: 14px; animation: wiggle 1s ease-in-out infinite; }
@keyframes wiggle { 0%,100% { transform: rotate(-3deg) scale(1); } 50% { transform: rotate(3deg) scale(1.08); } }
#finalBest { margin: 8px 0 18px; font-weight: 800; color: var(--ink-soft); letter-spacing: 1px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  border: none; border-radius: 20px; cursor: pointer; font: inherit; font-weight: 900; letter-spacing: 1.5px;
  transition: transform .12s, filter .12s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(0.95); }
.btn svg { width: 1.1em; height: 1.1em; fill: currentColor; }
.btn.big { padding: 18px; font-size: clamp(18px, 3.6vmin, 24px); color: #fff; background: linear-gradient(135deg, #ff4d8d, #7c5cff); box-shadow: 0 10px 24px rgba(124, 92, 255, 0.4), inset 0 -4px 0 rgba(0, 0, 0, 0.15); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.035); } }
.btn.alt { margin-top: 12px; padding: 13px; font-size: 16px; color: #ff4d8d; background: var(--btn-alt); }
.btn.alt small { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: #ff4d8d; color: #fff; letter-spacing: 1px; }
.btn.toggle { padding: 13px 8px; font-size: 15px; color: var(--ink); background: var(--btn-alt); }
.btn.toggle svg { fill: var(--accent); }
h2 { margin: 0 0 14px; font-size: 28px; font-weight: 900; letter-spacing: 4px; }
.row { display: flex; gap: 10px; }
#achTitle { margin: 18px 0 8px; font-size: 12px; font-weight: 900; letter-spacing: 3px; color: var(--ink-soft); }
#achGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.ach { border-radius: 14px; padding: 8px 4px 6px; background: var(--btn-alt); opacity: .45; }
.ach.on { opacity: 1; background: linear-gradient(135deg, rgba(255, 77, 141, .16), rgba(124, 92, 255, .2)); }
.ach i { display: block; font-style: normal; font-size: 22px; line-height: 1.1; color: var(--accent); }
.ach.on i { color: #ff4d8d; }
.ach b { display: block; font-size: 9px; letter-spacing: .5px; margin-top: 3px; line-height: 1.15; }

#toast {
  position: fixed; left: 50%; top: 74px; transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow);
  font-weight: 900; font-size: 14px; letter-spacing: 1px; white-space: nowrap; transition: all .3s;
  border: 2px solid var(--card-line);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast em { font-style: normal; color: #ff4d8d; }
