:root {
  --lime: #d8fd71;
  --lime-deep: #b5e04a;
  --ink: #0b1020;
  --panel: rgba(12, 17, 32, 0.82);
  --panel-solid: #121a30;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f7fb;
  --muted: #a9b3c9;
  --red: #ff4d5e;
  --gold: #f5c542;
  --radius: 18px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font-family: var(--font); overflow: hidden; }
body { -webkit-tap-highlight-color: transparent; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
kbd { font: 700 0.75em var(--font); padding: 1px 6px; border-radius: 6px; background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.2); }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
body.playing #stage canvas { cursor: crosshair; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; z-index: 30; }
.loading { background: radial-gradient(circle at 50% 40%, #1a2a52, var(--ink) 70%); z-index: 60; gap: 18px; align-content: center; transition: opacity .5s; }
.loading.done { opacity: 0; pointer-events: none; }
.loading p { margin: 0; color: var(--muted); letter-spacing: .04em; }
.loader-ball { width: 54px; height: 54px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #cfd3da 60%, #8a8f99); position: relative; animation: bounce 0.9s cubic-bezier(.3,.0,.5,1) infinite alternate; box-shadow: 0 18px 30px rgba(0,0,0,.4); }
.loader-ball::after { content: ""; position: absolute; inset: 30% 30%; background: #111; clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%); }
@keyframes bounce { from { transform: translateY(-26px) rotate(0); } to { transform: translateY(10px) rotate(160deg); } }

.fatal { background: var(--ink); z-index: 70; padding: 20px; }

/* ---------- panels & buttons ---------- */
.panel { background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 26px 22px; width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; box-shadow: 0 30px 80px rgba(0,0,0,.5); touch-action: pan-y; }
.panel.wide { width: min(640px, calc(100vw - 32px)); }
.panel h2 { margin: 0 0 14px; font-size: 26px; font-weight: 900; font-style: italic; letter-spacing: -.01em; text-transform: uppercase; }
.panel h3 { margin: 18px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--lime); }
.muted { color: var(--muted); font-size: 14px; }
.eyebrow { display: inline-block; font-size: 12px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; color: var(--lime); }

.btn { appearance: none; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--text); font-weight: 700; font-size: 15px; padding: 12px 18px; min-height: 46px; border-radius: 999px; cursor: pointer; transition: transform .12s, background .15s, border-color .15s; }
.btn:hover { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.28); }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .icon-btn:focus-visible, .chip-btn:focus-visible, .curve-btns button:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }
.btn.primary { background: var(--lime); color: #10120c; border-color: transparent; }
.btn.primary:hover { background: #e6ff9b; }
.btn.big { font-size: 19px; padding: 15px 28px; min-height: 56px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.row .btn { flex: 1 1 auto; }

.icon-btn { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(10px); cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn .ico-off { display: none; }
.icon-btn.muted .ico-on { display: none; }
.icon-btn.muted .ico-off { display: block; }
.top-actions { position: fixed; top: calc(14px + var(--safe-t)); right: calc(14px + var(--safe-r)); display: flex; gap: 8px; z-index: 45; }

/* ---------- start.ng profile card ---------- */
.startng-card { position: fixed; top: calc(14px + var(--safe-t)); left: calc(14px + var(--safe-l)); display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 999px; background: #292a23; color: #fffefa; z-index: 45; max-width: calc(100vw - 150px); box-shadow: 0 8px 24px rgba(0,0,0,.35); border: 1px solid rgba(216,253,113,.25); }
.startng-card img { width: 44px; height: 44px; border-radius: 50%; background: var(--lime); object-fit: cover; flex: none; }
.startng-card .who { min-width: 0; }
.startng-card b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.startng-card span { display: block; font-size: 12px; opacity: .72; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-btn { margin-left: 4px; border: 0; border-radius: 999px; padding: 8px 14px; min-height: 36px; background: var(--lime); color: #10120c; font-weight: 800; cursor: pointer; flex: none; }

/* ---------- menu ---------- */
.menu { background: linear-gradient(180deg, rgba(5,8,18,.15) 0%, rgba(5,8,18,.35) 45%, rgba(5,8,18,.88) 100%); align-items: end; padding: 90px 16px calc(28px + var(--safe-b)); overflow: auto; touch-action: pan-y; }
.menu-inner { width: min(560px, 100%); text-align: center; animation: rise .6s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.brand h1 { margin: 6px 0 6px; font-size: clamp(46px, 11vw, 92px); line-height: .86; font-weight: 900; font-style: italic; letter-spacing: -.035em; text-shadow: 0 6px 40px rgba(0,0,0,.6); }
.brand h1 em { color: var(--lime); font-style: italic; }
.brand h1 sup { font-size: .32em; vertical-align: top; margin-left: 6px; background: var(--lime); color: #10120c; padding: 2px 8px; border-radius: 8px; font-style: normal; letter-spacing: 0; position: relative; top: .35em; }
.tagline { margin: 10px 0 16px; color: #dfe5f2; font-size: 16px; text-shadow: 0 2px 10px rgba(0,0,0,.7); }
.best { display: inline-block; padding: 8px 16px; border-radius: 999px; background: rgba(0,0,0,.4); border: 1px solid var(--line); font-size: 14px; color: #e9eef9; margin-bottom: 16px; }
.best b { color: var(--gold); }
.menu-buttons { display: grid; gap: 10px; }
.menu-buttons .row { margin-top: 0; }
.controls-hint { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(4,6,14,.55); padding: 16px; overflow: auto; touch-action: pan-y; animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; } }
.howto { padding-left: 20px; margin: 0; display: grid; gap: 10px; line-height: 1.45; font-size: 15px; }
.perfect { color: var(--lime); font-weight: 800; }
.redzone { color: var(--red); font-weight: 800; }
.modal.over .panel { text-align: center; }
.scoring { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 14px; }
.scoring li { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding: 4px 0; }
.scoring b { color: var(--lime); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-weight: 600; min-height: 52px; }
.setting input[type=range] { width: 50%; accent-color: var(--lime); }
.setting select { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; }
.switch { appearance: none; width: 50px; height: 28px; border-radius: 999px; background: rgba(255,255,255,.18); position: relative; cursor: pointer; transition: background .15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch:checked { background: var(--lime-deep); }
.switch:checked::after { transform: translateX(22px); }
.switch:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

/* leaderboard */
.board-body { min-height: 120px; }
.board-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.board-table th { text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 6px 8px; font-weight: 700; }
.board-table th:nth-child(2), .board-table td:nth-child(2) { text-align: left; }
.board-table td { padding: 10px 8px; text-align: right; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.board-table td:first-child { font-weight: 900; width: 44px; text-align: center; }
.board-table tr.me td { background: rgba(216,253,113,.14); }
.board-table tr.me td:first-child { box-shadow: inset 3px 0 0 var(--lime); }
.board-table .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.board-table .you { margin-left: 6px; font-size: 11px; background: var(--lime); color: #10120c; border-radius: 6px; padding: 1px 6px; font-weight: 800; }
.board-msg { text-align: center; color: var(--muted); padding: 30px 10px; line-height: 1.5; }
.board-scroll { overflow-x: auto; }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.2); border-top-color: var(--lime); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* game over */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 0 10px; }
.stats div { background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; }
.stats small { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.stats b { display: block; font-size: 26px; font-weight: 900; margin-top: 4px; font-variant-numeric: tabular-nums; }
.best-line { margin: 6px 0; color: var(--gold); font-weight: 700; min-height: 1.2em; }
.save-status { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; font-size: 14px; color: #dfe5f2; padding: 8px; border-radius: 12px; background: rgba(255,255,255,.04); }
.save-status.ok { color: var(--lime); }
.save-status.err { color: #ffb3bb; }
.save-status .spinner { margin: 0; width: 18px; height: 18px; border-width: 2px; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
.hud > * { pointer-events: auto; }
.hud-top { position: absolute; top: calc(14px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; pointer-events: none; }
.round-chip, .score-chip, .shot-dots { background: var(--panel); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 14px; padding: 7px 14px; height: 52px; display: flex; flex-direction: column; justify-content: center; }
.round-chip span, .round-chip small { white-space: nowrap; }
.round-chip span { font-weight: 900; font-style: italic; text-transform: uppercase; font-size: 16px; line-height: 1; }
.round-chip small, .score-chip small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 3px; }
.score-chip { align-items: flex-end; min-width: 92px; }
.score-chip small { margin: 0 0 2px; }
.score-chip b { font-size: 24px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.score-chip b.bump { animation: bump .5s ease-out; }
@keyframes bump { 30% { transform: scale(1.3); color: var(--lime); } }
.shot-dots { flex-direction: row; align-items: center; gap: 7px; }
.shot-dots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.45); display: grid; place-items: center; font-style: normal; font-size: 11px; font-weight: 900; }
.shot-dots i.cur { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(216,253,113,.25); animation: pulse 1.2s infinite; }
.shot-dots i.goal { background: var(--lime); border-color: var(--lime); color: #10120c; }
.shot-dots i.fail { background: var(--red); border-color: var(--red); color: #fff; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(216,253,113,.05); } }
.hud-target { position: absolute; top: calc(74px + var(--safe-t)); left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #e7ecf7; background: rgba(0,0,0,.35); padding: 4px 12px; border-radius: 999px; pointer-events: none; white-space: nowrap; }
.hud-hint { position: absolute; bottom: calc(18px + var(--safe-b)); left: 50%; transform: translateX(-50%); font-size: 13px; color: #e7ecf7; background: rgba(0,0,0,.42); padding: 7px 14px; border-radius: 999px; white-space: nowrap; pointer-events: none; transition: opacity .3s; }

.power { position: absolute; right: calc(22px + var(--safe-r)); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.power span { font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.power-track { width: 22px; height: 210px; border-radius: 999px; background: rgba(8,12,24,.75); border: 2px solid rgba(255,255,255,.25); position: relative; overflow: hidden; }
.power-perfect { position: absolute; left: 0; right: 0; bottom: 68%; height: 18%; background: rgba(216,253,113,.35); border-top: 2px solid var(--lime); border-bottom: 2px solid var(--lime); }
.power-over { position: absolute; left: 0; right: 0; top: 0; height: 10%; background: rgba(255,77,94,.35); }
.power-fill { position: absolute; left: 3px; right: 3px; bottom: 3px; height: 0; border-radius: 999px; background: linear-gradient(0deg, #6ee7ff, #ffffff); box-shadow: 0 0 14px rgba(255,255,255,.6); }
.power-fill.perfect { background: linear-gradient(0deg, var(--lime-deep), var(--lime)); }
.power-fill.over { background: linear-gradient(0deg, #ff9a5e, var(--red)); }

.curve { position: absolute; left: calc(16px + var(--safe-l)); bottom: calc(16px + var(--safe-b)); background: var(--panel); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px 10px; }
.curve > span { display: block; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px 4px; }
.curve-btns { display: flex; gap: 4px; }
.curve-btns button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.06); cursor: pointer; font-size: 16px; font-weight: 900; }
.curve-btns button.on { background: var(--lime); color: #10120c; border-color: transparent; }

.shoot-btn { position: absolute; right: calc(18px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); width: 104px; height: 104px; border-radius: 50%; border: 3px solid rgba(255,255,255,.85); background: radial-gradient(circle at 40% 35%, #f0ffbf, var(--lime) 55%, var(--lime-deep)); color: #10120c; display: none; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.shoot-btn span { font-weight: 900; font-size: 20px; letter-spacing: .04em; }
.shoot-btn small { font-size: 10px; font-weight: 700; max-width: 76px; line-height: 1.1; text-align: center; }
.shoot-btn.charging { transform: scale(.94); box-shadow: 0 0 0 8px rgba(216,253,113,.3); }
.shoot-btn:disabled { filter: grayscale(.8) brightness(.7); }
body.touch .shoot-btn { display: flex; }
body.touch .power { right: calc(57px + var(--safe-r)); top: auto; bottom: calc(136px + var(--safe-b)); transform: none; }
body.touch .power-track { height: 150px; }
body.touch .curve .keys { display: none; }

/* banner */
.banner { position: fixed; left: 50%; top: 11%; transform: translateX(-50%); text-align: center; z-index: 25; pointer-events: none; width: min(92vw, 720px); }
.banner h2 { margin: 0; white-space: nowrap; font-size: clamp(38px, 9vw, 84px); font-weight: 900; font-style: italic; letter-spacing: -.03em; line-height: .95; text-transform: uppercase; color: #fff; text-shadow: 0 6px 0 rgba(0,0,0,.25), 0 10px 40px rgba(0,0,0,.6); animation: slam .45s cubic-bezier(.2,1.6,.4,1) both; }
.banner.goal h2 { color: var(--lime); }
.banner.fail h2 { color: #fff; }
.banner.info h2 { font-size: clamp(32px, 7vw, 60px); }
.banner p { margin: 4px 0 0; font-size: 17px; font-weight: 700; text-shadow: 0 2px 10px rgba(0,0,0,.8); animation: rise .4s .1s both; }
.banner ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.banner li { background: rgba(0,0,0,.55); border: 1px solid rgba(216,253,113,.4); color: #f2ffd0; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; animation: rise .35s both; }
.banner li b { color: var(--lime); margin-left: 4px; }
@keyframes slam { from { opacity: 0; transform: scale(1.8); } to { opacity: 1; transform: none; } }

.replay-badge { position: fixed; top: calc(80px + var(--safe-t)); right: calc(14px + var(--safe-r)); z-index: 26; background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.2); color: #fff; border-radius: 10px; padding: 8px 12px; font-weight: 900; letter-spacing: .1em; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 8px; min-height: 44px; }
.replay-badge i { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
.replay-badge small { font-weight: 600; letter-spacing: 0; opacity: .7; }
@keyframes blink { 50% { opacity: .2; } }

body.replaying .power, body.replaying .curve, body.replaying .shoot-btn, body.replaying .hud-hint { visibility: hidden; }

.toast { position: fixed; left: 50%; bottom: calc(140px + var(--safe-b)); transform: translateX(-50%); z-index: 80; background: var(--panel-solid); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: rise .25s both; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .hud-top { top: calc(80px + var(--safe-t)); gap: 6px; }
  .round-chip, .score-chip, .shot-dots { height: 46px; padding: 6px 10px; border-radius: 12px; }
  .round-chip span { font-size: 14px; }
  .score-chip { min-width: 70px; }
  .score-chip b { font-size: 20px; }
  .shot-dots { gap: 5px; }
  .shot-dots i { width: 15px; height: 15px; }
  .hud-target { top: calc(132px + var(--safe-t)); font-size: 11px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .banner { top: 24%; }
  .banner p { font-size: 15px; }
  .hud-hint { top: calc(166px + var(--safe-t)); bottom: auto; font-size: 12px; white-space: normal; text-align: center; width: max-content; max-width: 86vw; }
  .curve-btns button { width: 40px; height: 44px; }
  .replay-badge { top: calc(130px + var(--safe-t)); }
}
@media (max-width: 420px) {
  .startng-card b { font-size: 14px; }
  .curve { padding: 6px; }
  .curve-btns button { width: 34px; }
  .shoot-btn { width: 92px; height: 92px; }
  body.touch .power { right: calc(51px + var(--safe-r)); bottom: calc(122px + var(--safe-b)); }
  body.touch .power-track { height: 120px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .hud-top { top: calc(10px + var(--safe-t)); left: auto; right: 74px; transform: none; }
  .hud-target { display: none; }
  .banner { top: 6%; }
  .banner h2 { font-size: 48px; }
  .menu { align-items: center; padding-top: 70px; }
  .brand h1 { font-size: 44px; }
  .hud-hint { bottom: calc(10px + var(--safe-b)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
body.reduced-motion *, body.reduced-motion *::before, body.reduced-motion *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
