:root {
  --spark: #7cf7ff; --bloom: #ff7ce0; --echo: #b49bff; --gold: #ffd35a;
  --panel: rgba(12, 8, 26, 0.82);
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #07040f; color: #fff;
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
body.no-webgl { background: radial-gradient(circle at 50% 45%, #3a1458, #07040f 70%); }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* HUD + bar stay in layout (visibility, not display) so the spiral center can be measured */
#hud, #bar { visibility: hidden; }
body.playing #hud, body.playing #bar { visibility: visible; }

#hud {
  position: fixed; top: calc(8px + var(--st)); left: 0; right: 0;
  display: flex; justify-content: center; gap: 6px; padding: 0 8px; flex-wrap: wrap;
}
.pill {
  font: inherit; font-weight: 650; font-size: 14px; color: #fff; background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 999px; padding: 5px 11px;
  text-shadow: 0 1px 3px #000; font-variant-numeric: tabular-nums;
}
button.pill { cursor: pointer; }
.pill.money { color: var(--gold); }

#warn, #hint {
  position: fixed; left: 0; right: 0; text-align: center; pointer-events: none; opacity: 0; transition: opacity .2s;
}
#warn {
  top: calc(52px + var(--st)); font-size: 22px; font-weight: 850; letter-spacing: .12em;
  color: var(--gold); text-shadow: 0 0 14px #f60, 0 0 3px #000;
}
#warn.on { opacity: 1; animation: blink .25s steps(2) infinite; }
@keyframes blink { 50% { opacity: .45; } }
#hint {
  bottom: calc(var(--barh, 128px) + 8px + var(--sb)); font-size: 13px; color: #fff;
  text-shadow: 0 1px 4px #000;
}
#hint.on { opacity: .9; }

#bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(8px + var(--sb));
  width: min(560px, calc(100% - 16px));
  display: grid; grid-template-columns: repeat(3, 1fr) 1.05fr; gap: 6px;
}
#bar button {
  font: inherit; color: #fff; background: var(--panel); border: 1.5px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px; min-height: 50px; padding: 5px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: transform .06s, background .15s;
}
#bar button:active:not(:disabled) { transform: scale(.95); }
#bar button:disabled { opacity: .38; }
#bar .name { font-weight: 750; font-size: 15px; line-height: 1.1; text-align: center; }
#bar .price { font-size: 12.5px; color: var(--gold); font-variant-numeric: tabular-nums; }
#bar .lvl { font-size: 11px; opacity: .8; }
#bar .up .name { font-size: 13.5px; font-weight: 650; }
#bar .up { min-height: 44px; }
#bar .spark { border-color: color-mix(in srgb, var(--spark) 55%, transparent); }
#bar .bloom { border-color: color-mix(in srgb, var(--bloom) 55%, transparent); }
#bar .echo { border-color: color-mix(in srgb, var(--echo) 55%, transparent); }
#bar .tw.sel.spark { background: var(--spark); color: #071016; }
#bar .tw.sel.bloom { background: var(--bloom); color: #1a0716; }
#bar .tw.sel.echo { background: var(--echo); color: #0e0820; }
#bar .tw.sel .price { color: inherit; }
#bar .blast {
  grid-column: 4; grid-row: 1 / span 2;
  border-color: #ff5ad1; background: linear-gradient(160deg, rgba(255, 90, 209, .35), rgba(90, 60, 255, .35)), var(--panel);
}
#bar .blast .name { font-size: 17px; letter-spacing: .03em; }

.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: calc(24px + var(--st)) 24px calc(24px + var(--sb)); text-align: center;
}
.screen[hidden] { display: none; }
#screen-title { background: radial-gradient(circle at 50% 50%, rgba(7, 4, 15, .25), rgba(7, 4, 15, .8) 75%); }
.screen.panel { background: rgba(7, 4, 15, 0.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
h1 {
  margin: 0; font-size: clamp(54px, 16vw, 104px); line-height: .9; letter-spacing: .06em; font-weight: 900;
  background: linear-gradient(90deg, var(--spark), var(--echo), var(--bloom), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, .7));
}
h2 { margin: 0; font-size: 34px; }
.tag { margin: 0; font-size: 17px; opacity: .9; text-shadow: 0 1px 4px #000; }
.how {
  list-style: none; margin: 4px 0; padding: 14px 18px; max-width: 420px; text-align: left;
  background: var(--panel); border-radius: 16px; display: grid; gap: 8px; font-size: 15px;
}
.c-spark { color: var(--spark); } .c-bloom { color: var(--bloom); } .c-echo { color: var(--echo); }
.btn {
  font: inherit; font-weight: 800; font-size: 20px; letter-spacing: .05em; color: #120a1f; cursor: pointer;
  background: linear-gradient(90deg, var(--spark), var(--bloom)); border: 0; border-radius: 999px;
  padding: 14px 44px; min-width: 200px; box-shadow: 0 4px 22px rgba(255, 124, 224, .35);
}
.btn.ghost { background: transparent; color: #fff; border: 1.5px solid rgba(255, 255, 255, .4); box-shadow: none; font-size: 17px; padding: 10px 30px; }
.btn:active { transform: scale(.97); }
.best { margin: 0; min-height: 1.3em; color: var(--gold); font-weight: 650; text-shadow: 0 1px 4px #000; }
#o-sub { margin: 0; font-size: 17px; }

@media (min-width: 900px) {
  #bar { width: 620px; }
  #bar button { min-height: 54px; }
}
