:root {
  --pos: #38e6ff; --neg: #ff3385; --well: #9a73ff; --ink: #e9ecff; --dim: #8b90b8;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #05060f; color: var(--ink); overflow: hidden; }
body { font-family: var(--sans); -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; touch-action: none; }
body.playing canvas { cursor: none; }
.hidden { display: none !important; }
.touch-only { display: none; }
body.touch .touch-only { display: inline; }
body.touch .mouse-only { display: none; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#clock { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); text-align: center; line-height: 1; }
#time { display: block; font: 700 clamp(30px, 6vmin, 54px) var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; color: #fff;
  text-shadow: 0 0 18px rgba(154, 115, 255, 0.8), 0 0 4px rgba(255, 255, 255, 0.6); }
#time.pop { animation: pop 0.5s ease-out; }
@keyframes pop { 0% { transform: scale(1.25); color: #fff6c8; } 100% { transform: scale(1); } }
#best { display: block; margin-top: 6px; font: 600 11px var(--sans); letter-spacing: 0.3em; color: var(--dim); }
#best.hot { color: #ffe27a; text-shadow: 0 0 10px rgba(255, 210, 90, 0.7); }
@media (orientation: landscape) and (min-aspect-ratio: 13/10) {
  #clock { left: max(28px, env(safe-area-inset-left)); top: 26px; transform: none; text-align: left; }
}
#tier { position: absolute; top: 26%; left: 0; right: 0; text-align: center; font: 600 13px var(--sans); letter-spacing: 0.5em; color: #cbbcff; opacity: 0; }
#tier.big { font-size: clamp(20px, 4.4vmin, 36px); font-weight: 800; color: #fff; text-shadow: 0 0 24px rgba(154, 115, 255, 0.9); }
#tier.on { animation: tier 2.4s ease-out forwards; }
@keyframes tier { 0% { opacity: 0; letter-spacing: 1em; } 15% { opacity: 1; letter-spacing: 0.5em; } 70% { opacity: 1; } 100% { opacity: 0; letter-spacing: 0.6em; } }
#banner { position: absolute; top: 62%; left: 0; right: 0; text-align: center; opacity: 0; --bc: #fff; }
#banner.on { animation: banner 2.2s ease-out forwards; }
#bannerName { display: block; font: 800 clamp(18px, 4vmin, 30px) var(--sans); letter-spacing: 0.35em; color: var(--bc, #fff); text-shadow: 0 0 20px currentColor; }
#bannerSub { display: block; margin-top: 6px; font: 500 12px var(--sans); letter-spacing: 0.25em; color: #c9cdf2; text-transform: uppercase; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.3); } 10% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
#pulse { position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(340px, 72vw); height: 26px;
  border: 1px solid rgba(154, 115, 255, 0.45); border-radius: 13px; background: rgba(10, 8, 30, 0.55); overflow: hidden; pointer-events: auto; cursor: pointer; }
#pulseFill { position: absolute; inset: 0; transform-origin: left; transform: scaleX(1); background: linear-gradient(90deg, #5a3dd8, #9a73ff 60%, #d9ccff); opacity: 0.55; transition: transform 0.15s; }
#pulse.ready { border-color: #fff; box-shadow: 0 0 18px rgba(190, 160, 255, 0.8); }
#pulse.ready #pulseFill { opacity: 0.9; animation: shimmer 1.2s ease-in-out infinite; }
@keyframes shimmer { 50% { filter: brightness(1.35); } }
#pulse.flash { animation: flash 0.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 40px #fff; } }
#pulse.deny { animation: deny 0.3s; }
@keyframes deny { 25% { transform: translateX(calc(-50% - 6px)); } 75% { transform: translateX(calc(-50% + 6px)); } }
#pulseLabel { position: relative; display: block; text-align: center; line-height: 24px; font: 700 10px var(--sans); letter-spacing: 0.22em; color: #fff; text-shadow: 0 1px 2px #000; }
#combo { position: absolute; right: 12px; top: 0; line-height: 24px; font: 800 12px var(--mono); color: #fff; text-shadow: 0 0 8px #fff; }
#combo.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 0% { transform: scale(1.6); } }
#hint { position: absolute; left: 0; right: 0; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 40px); text-align: center; font: 500 12px var(--sans); letter-spacing: 0.15em; color: #b8bce6; transition: opacity 1s; }
#hint.gone { opacity: 0; }

/* Corner buttons */
#corner { position: fixed; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; gap: 8px; z-index: 5; }
#corner button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(154, 115, 255, 0.35); background: rgba(10, 8, 30, 0.5); padding: 9px; cursor: pointer; }
#corner svg { width: 100%; height: 100%; fill: #d9d4ff; stroke: #d9d4ff; stroke-width: 0; }
#corner .wave, #corner .x { fill: none; stroke-width: 1.8; stroke-linecap: round; }
#corner .x { display: none; }
#btnMute.muted .wave { display: none; }
#btnMute.muted .x { display: inline; }
#btnPause { display: none; }
body.playing #btnPause { display: block; }

/* Overlays */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 4; }
#over, #pause { background: radial-gradient(ellipse at center, rgba(5, 6, 15, 0.35), rgba(5, 6, 15, 0.75)); }
.panel { width: min(460px, 100%); max-height: 100%; overflow-y: auto; text-align: center; padding: 26px 22px; border-radius: 18px;
  background: rgba(8, 8, 26, 0.62); border: 1px solid rgba(154, 115, 255, 0.28); box-shadow: 0 0 60px rgba(90, 60, 220, 0.25); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
h1 { margin: 0; font: 900 clamp(38px, 9vmin, 64px)/0.92 var(--sans); letter-spacing: 0.12em; color: #fff;
  text-shadow: -3px 0 0 rgba(255, 51, 133, 0.75), 3px 0 0 rgba(56, 230, 255, 0.75), 0 0 30px rgba(154, 115, 255, 0.8); }
h2 { margin: 10px 0 18px; font: 600 13px var(--sans); letter-spacing: 0.6em; color: #cbbcff; }
.rules { list-style: none; padding: 0; margin: 0 0 20px; text-align: left; font-size: 14px; line-height: 1.45; color: #d6d9f5; }
.rules li { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; }
.rules b { color: #fff; }
.dot { flex: 0 0 12px; width: 12px; height: 12px; margin-top: 4px; border-radius: 50%; }
.dot.well { background: var(--well); box-shadow: 0 0 10px var(--well); }
.dot.pos { background: var(--pos); box-shadow: 0 0 10px var(--pos); }
.dot.neg { background: var(--neg); box-shadow: 0 0 10px var(--neg); }
.dot.white { background: #fff; box-shadow: 0 0 10px #fff; }
button { font-family: var(--sans); -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.primary, .secondary, .ghost { display: block; width: 100%; margin: 10px 0 0; padding: 15px; border-radius: 12px; font-weight: 800; font-size: 16px; letter-spacing: 0.3em; cursor: pointer; color: #fff; }
.primary { border: 0; background: linear-gradient(90deg, #6b43ff, #b05cff 55%, #ff3d8b); box-shadow: 0 0 26px rgba(160, 90, 255, 0.55); }
.primary:hover, .primary:focus-visible { filter: brightness(1.15); outline: none; box-shadow: 0 0 36px rgba(190, 120, 255, 0.9); }
.secondary { border: 1px solid #38e6ff; background: rgba(56, 230, 255, 0.12); font-size: 13px; }
.ghost { border: 1px solid rgba(255, 255, 255, 0.18); background: transparent; font-size: 12px; padding: 11px; color: #b8bce6; }
.best { margin: 14px 0 0; font: 600 12px var(--mono); letter-spacing: 0.2em; color: #ffe27a; min-height: 1em; }
.small { margin: 10px 0 0; font-size: 11px; letter-spacing: 0.12em; color: var(--dim); }
.cause { margin: 0; font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase; color: #ff7aa8; }
.big { margin: 6px 0 0; font: 800 clamp(54px, 13vmin, 84px)/1 var(--mono); color: #fff; text-shadow: 0 0 26px rgba(154, 115, 255, 0.9); font-variant-numeric: tabular-nums; }
.big small { font-size: 0.35em; color: var(--dim); margin-left: 4px; }
.newbest { margin: 8px 0 0; font: 800 14px var(--sans); letter-spacing: 0.5em; color: #ffe27a; text-shadow: 0 0 14px rgba(255, 210, 90, 0.9); animation: shimmer 1s infinite; }
.rank { margin: 8px 0 14px; font: 700 15px var(--sans); letter-spacing: 0.45em; color: #cbbcff; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0 0 8px; }
.stats div { padding: 8px 2px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); }
.stats dt { font-size: 9px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim); }
.stats dd { margin: 4px 0 0; font: 700 15px var(--mono); color: #fff; }
.ptitle { font-size: 20px; color: #fff; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); padding: 10px 16px; border-radius: 10px; background: rgba(20, 16, 50, 0.92);
  font-size: 13px; color: #fff; opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 6; }
#toast.on { opacity: 1; }
@media (max-height: 560px) {
  .panel { padding: 14px 18px; }
  h1 { font-size: 34px; }
  h2 { margin: 6px 0 10px; }
  .rules { font-size: 12px; margin-bottom: 10px; }
  .rules li { margin: 4px 0; }
  .primary { padding: 11px; }
}
