:root {
  --bg: #0a0618; --bg2: #150a2c; --ink: #f4efff; --muted: #a79bc7;
  --cyan: #35f0ff; --pink: #ff2d9a; --amber: #ffb020; --purple: #b56bff; --red: #ff2d6f; --yellow: #ffe94a;
  --card: rgba(18, 10, 40, 0.96); --stroke: rgba(255, 255, 255, 0.12);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; }
[hidden] { display: none !important; }
a { color: var(--cyan); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 5px; }

#app { position: fixed; inset: 0; width: 100%; height: 100%; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* camera layer */
#cam-layer { position: absolute; inset: 0; z-index: 5; background: #000; overflow: hidden; }
#cam-layer.hide { visibility: hidden; }
#cam-box { position: absolute; inset: 0; }
#cam-box.mirror { transform: scaleX(-1); }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
#cam-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }

/* HUD */
#hud { position: absolute; inset: 0; z-index: 8; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; padding: calc(var(--sat) + 10px) calc(var(--sar) + 12px) calc(var(--sab) + 14px) calc(var(--sal) + 12px); }
.hud-top { display: flex; align-items: flex-start; justify-content: space-between; }
.hearts { display: flex; gap: 2px; font-size: 22px; line-height: 1; padding-top: 8px; min-width: 80px; }
.hearts span { color: var(--red); text-shadow: 0 0 10px rgba(255,45,111,0.8); transition: transform .2s, opacity .2s; }
.hearts span.off { color: rgba(255,255,255,0.18); text-shadow: none; transform: scale(.85); }
.hud-score { text-align: center; }
#hud-score { font-size: 42px; font-weight: 900; letter-spacing: 1px; line-height: 1; font-variant-numeric: tabular-nums; text-shadow: 0 0 18px rgba(53,240,255,0.55); }
.mult { margin-top: 2px; font-size: 14px; font-weight: 900; color: var(--amber); letter-spacing: 2px; opacity: 0; transform: scale(.8); transition: opacity .2s, transform .2s; text-shadow: 0 0 12px rgba(255,176,32,0.7); }
.mult.on { opacity: 1; transform: scale(1); }
.icon-btn { pointer-events: auto; width: 44px; height: 44px; border-radius: 13px; border: 1px solid var(--stroke); background: rgba(10,6,24,0.65); color: var(--ink); font-weight: 900; font-size: 15px; cursor: pointer; }
.banner { align-self: center; background: rgba(53,240,255,0.12); border: 1px solid rgba(53,240,255,0.45); color: var(--cyan); padding: 10px 18px; border-radius: 999px; font-weight: 800; letter-spacing: 3px; text-transform: uppercase; font-size: 12px; animation: pulse 1.6s ease-in-out infinite; }
.hud-bottom { display: flex; justify-content: center; }
.boost { width: min(58%, 250px); }
.boost-label { font-size: 10px; letter-spacing: 4px; color: var(--muted); text-align: center; margin-bottom: 4px; font-weight: 700; }
.boost-track { height: 8px; border-radius: 999px; background: rgba(255,255,255,0.1); overflow: hidden; border: 1px solid rgba(255,255,255,0.08); }
.boost-fill { height: 100%; width: 100%; transform-origin: left center; transform: scaleX(0.35); background: linear-gradient(90deg, var(--purple), var(--cyan)); }
.boost.active .boost-fill { background: linear-gradient(90deg, var(--amber), #fff); }
.boost.active .boost-label { color: var(--amber); }
.pip { position: absolute; right: calc(var(--sar) + 12px); bottom: calc(var(--sab) + 56px); width: 100px; height: 134px; border-radius: 14px; overflow: hidden; border: 1px solid var(--stroke); background: #000; box-shadow: 0 0 0 2px rgba(53,240,255,0.22), 0 10px 30px rgba(0,0,0,0.5); pointer-events: auto; }
#pip-canvas, #gauge-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.pip-status { position: absolute; top: 3px; right: 6px; font-size: 11px; color: #4dff88; text-shadow: 0 0 6px #4dff88; }
.pip-status.lost { color: var(--red); text-shadow: 0 0 6px var(--red); }
.debug { position: absolute; left: calc(var(--sal) + 12px); bottom: calc(var(--sab) + 56px); font: 11px/1.4 ui-monospace, Menlo, monospace; color: rgba(255,255,255,0.75); background: rgba(0,0,0,0.45); padding: 6px 8px; border-radius: 8px; white-space: pre; }

/* screens */
.screen { position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px); background: rgba(7,5,15,0.86); animation: fade .22s ease-out; }
.screen.transparent { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; justify-content: flex-end; }
.screen.transparent.center { justify-content: center; pointer-events: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: .75; } 50% { opacity: 1; } }
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 60% { transform: scale(.95); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

.card { width: min(100%, 420px); background: var(--card); border: 1px solid var(--stroke); border-radius: 22px; padding: 22px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.card.wide { width: min(100%, 520px); }
.card.scroll { max-height: calc(100vh - var(--sat) - var(--sab) - 32px); max-height: calc(100dvh - var(--sat) - var(--sab) - 32px); overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.card-title { font-size: 24px; font-weight: 900; text-align: center; letter-spacing: -0.2px; }
.card-title.left, .card-detail.left { text-align: left; }
.card-detail { color: var(--muted); font-size: 14px; line-height: 1.45; text-align: center; }
.card-eyebrow { font-size: 12px; letter-spacing: 5px; color: var(--pink); font-weight: 900; }
.big-score { font-size: 64px; font-weight: 900; line-height: 1; text-shadow: 0 0 24px rgba(53,240,255,0.6); font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; width: 100%; margin-top: 6px; }
.row.col { flex-direction: column; align-items: stretch; }
.btn { pointer-events: auto; appearance: none; border: none; border-radius: 14px; padding: 14px 22px; font-size: 16px; font-weight: 800; color: #0a0618; background: linear-gradient(90deg, var(--cyan), #7df9ff); cursor: pointer; letter-spacing: .3px; box-shadow: 0 8px 24px rgba(53,240,255,0.25); transition: transform .1s; }
.btn:active { transform: scale(.97); }
.btn.ghost { background: rgba(255,255,255,0.08); color: var(--ink); box-shadow: none; border: 1px solid var(--stroke); }
.btn.small { padding: 10px 16px; font-size: 14px; }
.error { color: #ffd27a; background: rgba(255,176,32,0.12); border: 1px solid rgba(255,176,32,0.5); padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.45; width: 100%; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.12); border-top-color: var(--cyan); animation: spin .9s linear infinite; }
.progress { width: 100%; height: 6px; border-radius: 999px; background: rgba(255,255,255,0.1); overflow: hidden; }
.progress-fill { height: 100%; width: 100%; transform-origin: left center; transform: scaleX(0); background: linear-gradient(90deg, var(--purple), var(--cyan)); transition: transform .15s linear; }

/* menu */
.menu-inner { width: min(100%, 440px); display: flex; flex-direction: column; align-items: center; }
.title { font-size: clamp(46px, 13vw, 88px); font-weight: 900; letter-spacing: -2px; line-height: .88; margin: 0; text-align: center; display: flex; flex-direction: column; }
.title span:first-child { background: linear-gradient(90deg, #ffe36b, #ff7a3d, #ff2d9a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.title span:last-child { color: var(--cyan); text-shadow: 0 0 28px rgba(53,240,255,0.55); }
.tagline { margin: 12px 0 22px; color: var(--muted); font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; font-size: 12px; }
.mode-cards { display: grid; gap: 12px; width: 100%; }
.mode-card { display: flex; gap: 14px; align-items: center; text-align: left; width: 100%; padding: 14px 16px; border-radius: 18px; border: 1px solid var(--stroke); background: var(--card); color: var(--ink); cursor: pointer; transition: transform .12s, border-color .12s, box-shadow .12s; }
.mode-card:hover { border-color: rgba(53,240,255,0.55); box-shadow: 0 0 0 3px rgba(53,240,255,0.12); }
.mode-card:active { transform: scale(.985); }
.mode-emoji { font-size: 38px; line-height: 1; }
.mode-title { font-weight: 900; font-size: 20px; }
.mode-desc { color: var(--muted); font-size: 13px; line-height: 1.4; margin-top: 2px; }
.menu-links { display: flex; flex-wrap: wrap; gap: 4px 18px; justify-content: center; margin-top: 14px; }
.link { background: none; border: none; color: var(--cyan); font-size: 14px; font-weight: 700; padding: 8px 2px; cursor: pointer; }
.privacy { color: var(--muted); font-size: 12px; margin: 12px 0 0; text-align: center; }
.best { margin-top: 10px; color: var(--amber); font-weight: 800; font-size: 12px; letter-spacing: 2px; text-transform: uppercase; }
.warning { margin-top: 12px; background: rgba(255,176,32,0.12); border: 1px solid rgba(255,176,32,0.5); color: #ffd27a; padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.45; }

/* calibration */
.calib-card { width: min(100%, 460px); background: var(--card); border: 1px solid var(--stroke); border-radius: 22px; padding: 14px 16px 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); pointer-events: auto; margin-bottom: calc(var(--sab) + 4px); }
.calib-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }
.calib-emoji { font-size: 44px; line-height: 1; }
.calib-emoji.big { font-size: 56px; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.18); }
.dots i.done { background: var(--cyan); }
.dots i.now { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.ring { position: relative; width: 64px; height: 64px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255,255,255,0.12); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--cyan); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 264; stroke-dashoffset: 264; }
.ring-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: var(--ink); text-align: center; line-height: 1.1; }
.hint { min-height: 18px; font-size: 13px; color: var(--yellow); text-align: center; font-weight: 600; }

/* countdown */
.countdown { font-size: clamp(90px, 28vw, 180px); font-weight: 900; line-height: 1; color: #fff; text-shadow: 0 0 40px rgba(53,240,255,0.8), 0 0 90px rgba(255,45,154,0.5); }
.countdown.pop { animation: pop .5s ease-out; }
.legend { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 420px; }
.legend span { background: rgba(10,6,24,0.7); border: 1px solid var(--stroke); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700; }
.legend span b { color: var(--cyan); }

/* stats / settings / how */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; margin: 6px 0; }
.stats div { background: rgba(255,255,255,0.06); border-radius: 12px; padding: 8px 6px; text-align: center; }
.stats b { display: block; font-size: 20px; font-weight: 900; }
.stats small { color: var(--muted); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; }
.settings-list { width: 100%; display: flex; flex-direction: column; gap: 4px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 4px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.setting label { font-size: 14px; font-weight: 600; }
.setting .val { color: var(--muted); font-size: 12px; min-width: 34px; text-align: right; }
.switch { width: 50px; height: 30px; border-radius: 999px; border: none; background: rgba(255,255,255,0.14); position: relative; cursor: pointer; transition: background .15s; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch[aria-pressed="true"] { background: var(--cyan); }
.switch[aria-pressed="true"]::after { transform: translateX(20px); }
.setting input[type="range"] { width: 140px; accent-color: var(--cyan); touch-action: pan-x; }
.setting select { background: rgba(255,255,255,0.08); color: var(--ink); border: 1px solid var(--stroke); border-radius: 10px; padding: 8px 10px; font-family: inherit; font-size: 14px; }
.how { font-size: 14px; line-height: 1.55; color: #d9d0f0; }
.how p { margin: 0 0 10px; }
.how b { color: var(--ink); }

.toast { position: absolute; left: 50%; bottom: calc(var(--sab) + 90px); transform: translate(-50%, 10px); z-index: 30; background: rgba(10,6,24,0.92); border: 1px solid var(--stroke); color: var(--ink); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: 90%; text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (orientation: landscape) and (max-height: 480px) {
  #hud-score { font-size: 30px; }
  .pip { width: 84px; height: 112px; bottom: calc(var(--sab) + 44px); }
  .card { padding: 14px 16px; gap: 6px; }
  .title { font-size: clamp(36px, 9vh, 60px); }
  .mode-card { padding: 8px 12px; }
  .mode-desc { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .screen, .countdown.pop { animation: none; }
}
