:root {
  --bg: #0D0D0F; --panel: #141418; --panel2: #1B1B22; --line: #2A2A38; --text: #E8E8F0; --muted: #9090A8; --dim: #606070;
  --amber: #FFBB00; --orange: #FF5500; --pink: #FF0066; --purple: #8833CC; --blue: #3D80FF; --green: #22C55E;
  --grad: linear-gradient(135deg, #FFBB00 0%, #FF5500 35%, #FF0066 65%, #3D80FF 100%);
  --btn: radial-gradient(ellipse 60% 120% at 32% 115%, rgba(232, 48, 140, .9), transparent 70%), radial-gradient(ellipse 50% 90% at 80% -10%, rgba(255, 150, 40, .55), transparent 70%), linear-gradient(100deg, #F0761E, #E9552C 55%, #EE6A1C);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 .22 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");   /* fine film grain over the gradient buttons */
  --gloss: linear-gradient(180deg, rgba(255, 255, 255, .3), rgba(255, 255, 255, .08) 46%, rgba(255, 255, 255, 0) 52%);
  --bokeh: radial-gradient(circle at 14% 72%, rgba(255, 255, 255, .32) 0 2px, transparent 3px), radial-gradient(circle at 27% 38%, rgba(255, 255, 255, .14) 0 7px, transparent 9px),
    radial-gradient(circle at 63% 64%, rgba(255, 255, 255, .12) 0 9px, transparent 11px), radial-gradient(circle at 78% 30%, rgba(255, 255, 255, .26) 0 2.5px, transparent 3.5px),
    radial-gradient(circle at 90% 70%, rgba(255, 255, 255, .1) 0 6px, transparent 8px), radial-gradient(circle at 46% 22%, rgba(255, 255, 255, .22) 0 1.5px, transparent 2.5px);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; -webkit-font-smoothing: antialiased; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; visibility: hidden; pointer-events: none; }
body[data-screen=editor] #scene { display: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.screen { position: fixed; inset: 0; display: none; }
body[data-screen=menu] #menu, body[data-screen=editor] #editor { display: flex; }
body[data-screen=editor] #game { visibility: hidden; }
body[data-screen=play] { cursor: default; }
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.small { font-size: 12px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- buttons, chips, panels ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: 14px;
  cursor: pointer; transition: .15s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.btn:hover { border-color: #44445a; background: #1d1d26; }
.btn:not(.grad) { background-image: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .015) 50%, transparent 52%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .09), 0 0 0 3px rgba(255, 255, 255, .03); }
/* glass buttons: a glossy top half, soft bokeh specks of light inside, an inner glow, and a faint glass frame round it */
.btn.grad { background: var(--gloss), var(--bokeh), var(--grain), var(--btn); border-color: rgba(255, 255, 255, .28); color: #fff; text-shadow: 0 1px 2px rgba(120, 20, 40, .45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 0 16px rgba(255, 255, 255, .16), 0 0 0 4px rgba(255, 255, 255, .055), 0 0 0 5px rgba(255, 255, 255, .04), 0 10px 28px -10px rgba(255, 60, 60, .75); }
.btn.grad:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; }
.btn.big { padding: 13px 26px; font-size: 16px; border-radius: 999px; }
.btn.sm { padding: 6px 13px; font-size: 13px; border-radius: 999px; }
.btn.icon { width: 38px; padding: 7px 0; font-size: 15px; }
kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius: 5px; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .12); color: var(--muted); }
.btn.grad kbd { color: #fff; background: rgba(0, 0, 0, .18); border-color: rgba(255, 255, 255, .28); }
.panel { background: rgba(20, 20, 24, .86); border: 1px solid var(--line); border-radius: 16px; backdrop-filter: blur(12px); }
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid rgba(61, 128, 255, .3); background: rgba(61, 128, 255, .12); color: #a8c4ff; }
.chip.green { border-color: rgba(34, 197, 94, .3); background: rgba(34, 197, 94, .1); color: #6ee7a0; }
.chip.amber { border-color: rgba(255, 187, 0, .3); background: rgba(255, 187, 0, .12); color: #ffd466; }
input[type=text], input[type=number], select { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 14px; outline: none; }
input:focus, select:focus { border-color: var(--blue); }
input[type=range] { accent-color: var(--pink); }
input[type=checkbox] { accent-color: var(--pink); width: 15px; height: 15px; vertical-align: -2px; }

/* ---------- menu ---------- */
#menu { flex-direction: column; padding: 22px 28px 14px; gap: 16px; background: linear-gradient(90deg, rgba(13, 13, 15, .15), rgba(13, 13, 15, .55)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top-right { display: flex; gap: 6px; }
.logo { display: flex; align-items: baseline; gap: 12px; }
.logo { font-family: 'Jost', var(--font); align-items: center; gap: 18px; }
.logo-name { font-size: 30px; font-weight: 500; letter-spacing: .38em; color: #F3F3F5; position: relative; }
/* the O of TON618 is the symbol (#ton-o in index.html) drawn over an invisible real "O", so letter spacing and widths
   stay exactly the font's. Placed for Jost Medium (500): the O's ink centre is .40em in and .35em above the baseline,
   and with line-height 1 the baseline is .845em below the box top; the symbol is 1.295em square (its ring = the O, r .37em) */
.o-mark { display: inline-block; position: relative; line-height: 1; -webkit-text-fill-color: transparent; }
.o-mark > svg { position: absolute; left: -.2475em; top: -.1525em; width: 1.295em; height: 1.295em; overflow: visible; pointer-events: none; }
.logo small { color: var(--muted); font-weight: 400; letter-spacing: .45em; text-transform: uppercase; font-size: 11px; }
.warn { padding: 14px 18px; border-color: rgba(255, 0, 102, .4); color: #ffb3cf; }
.warn code { font-family: var(--mono); }
.menu-body { flex: 1; display: grid; grid-template-columns: minmax(260px, 1fr) minmax(320px, 430px); gap: 22px; min-height: 0; }
.song-list { overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 2px 8px 2px 2px; }
.song-list::-webkit-scrollbar, .song-detail::-webkit-scrollbar { width: 8px; }
/* more songs below: a small bouncing arrow over the bottom of the list (the list scrolls under it) */
.song-list-wrap { position: relative; display: flex; flex-direction: column; min-height: 0; }
.song-list-wrap > .song-list { flex: 1; min-height: 0; }
.song-more { position: absolute; left: 0; right: 10px; bottom: 0; height: 34px; display: flex; align-items: flex-end; justify-content: center;
  pointer-events: none; opacity: 0; transition: opacity .25s; background: linear-gradient(rgba(13, 13, 15, 0), rgba(13, 13, 15, .85)); z-index: 2; border-radius: 0 0 12px 12px; }
.song-more.show { opacity: 1; }
.song-more svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 0 6px rgba(255, 0, 102, .8)); animation: moreBob 1.4s ease-in-out infinite; }
@keyframes moreBob { 50% { transform: translateY(3px); } }
.song-list::-webkit-scrollbar-thumb, .song-detail::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.song { display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px 18px 14px 0; border-radius: 14px; cursor: pointer; overflow: hidden; flex-shrink: 0;
  border: 1px solid var(--line); background: rgba(20, 20, 24, .8); transition: transform .15s, background .15s; }
.song:hover { background: rgba(29, 29, 38, .9); transform: translateX(3px); }
.song.sel { border-color: transparent; background: linear-gradient(var(--panel2), var(--panel2)) padding-box, var(--grad) border-box; transform: translateX(8px); }
.song { position: relative; box-shadow: 0 0 18px 4px rgba(0, 0, 0, .85); }
.song-title, .song-artist { text-shadow: 0 0 8px #000, 0 1px 3px #000; }   /* readable over the art */
.song-grade { filter: drop-shadow(0 0 6px #000); }   /* (not text-shadow: it would cover the S grade's gradient-clipped text) */
/* a masked strip of the song's banner art between the title and the grade */
.song-art { position: absolute; inset: 0; pointer-events: none; background: var(--banner, none) center 45% / cover no-repeat; opacity: .6; filter: grayscale(1) brightness(.75);
  -webkit-mask-image: linear-gradient(90deg, transparent 18%, #000 42%, #000 72%, transparent 92%); mask-image: linear-gradient(90deg, transparent 18%, #000 42%, #000 72%, transparent 92%);
  transition: opacity .25s, filter .25s; }
.song:hover .song-art { opacity: .75; filter: grayscale(.6) brightness(.85); }
.song.sel .song-art { opacity: 1; filter: none; }   /* only the selected song in colour */
.song > :not(.song-art) { position: relative; }
.song .stripe { width: 5px; align-self: stretch; background: var(--c); border-radius: 0 4px 4px 0; box-shadow: 0 0 16px var(--c); }
.song-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.song-title { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-artist { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-grade { font-weight: 900; font-style: italic; font-size: 24px; min-width: 34px; text-align: right; }
.g-S { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.g-A { color: #4ADE80; } .g-B { color: #4A8BFF; } .g-C { color: #A23DF0; } .g-D, .g-F { color: #FF1A4A; }
.song-detail { padding: 0 26px 24px; overflow: auto; }
.d-top { height: 130px; margin: 0 -26px 18px; position: relative; overflow: hidden; border-radius: 16px 16px 0 0;
  background: radial-gradient(circle at 75% 20%, color-mix(in srgb, var(--c) 55%, transparent), transparent 60%), radial-gradient(circle at 10% 100%, rgba(255, 0, 102, .35), transparent 60%), #101014; }
.d-top.has-banner { background: var(--banner) center / cover no-repeat, #101014; }
.d-top.has-banner::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 55%, rgba(20, 20, 24, .55)); }
.d-top.has-banner .d-ring { opacity: .35; z-index: 1; }
.d-ring { position: absolute; width: 170px; height: 170px; right: 28px; top: 22px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .15);
  border-top-color: var(--c); filter: drop-shadow(0 0 10px var(--c)); animation: spin 4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.song-detail h2 { margin: 0; font-size: 30px; font-weight: 900; line-height: 1.1; }
.song-detail .artist { color: var(--muted); margin-top: 6px; }
.best { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(13, 13, 15, .6); min-height: 62px; }
.best .g { font-size: 36px; font-weight: 900; font-style: italic; }
.best b { display: block; font-size: 18px; }
.best small { color: var(--muted); }
.lbl { display: block; margin: 18px 0 8px; font-size: 12px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim); }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 10px; border-radius: 999px; color: var(--muted); font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--gloss), var(--bokeh), var(--grain), var(--btn); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), inset 0 0 12px rgba(255, 255, 255, .14); }
.seg.diffs button { display: flex; flex-direction: column; align-items: center; gap: 1px; line-height: 1.2; }
.seg.diffs small { font-size: 10px; font-weight: 600; opacity: .65; }
.seg.sm { padding: 2px; border-radius: 999px; }
.seg.sm button { padding: 4px 12px; font-size: 12px; min-width: 76px; }
.mods { display: flex; gap: 8px; flex-wrap: wrap; }
.mod { border: 1px solid var(--line); background: transparent; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; }
.mod.on { color: #fff; border-color: transparent; background: linear-gradient(var(--panel2), var(--panel2)) padding-box, var(--grad) border-box; }
.actions { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
.hint { color: var(--dim); font-size: 12px; text-align: center; }
.empty { padding: 30px; color: var(--muted); text-align: center; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(8, 8, 10, .6); backdrop-filter: blur(6px); z-index: 20; padding: 16px; }
.overlay.show { display: flex; }
.modal { width: min(520px, 100%); padding: 28px; }
.modal h2 { margin: 0 0 18px; }
.center { text-align: center; }
.big-title { font-size: 48px; font-weight: 900; font-style: italic; margin: 0 0 22px !important; }
.col { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; align-items: center; }
.row.left { justify-content: flex-start; margin-top: 4px; }
/* results: a round "orb" echoing the game circle, set in Jost; everything scales with --d (the orb's diameter) */
/* behind it, an eclipse drawn in code on canvas.res-bg (drawResultsBg in game.js) - its black disc is exactly the orb */
#results { background: #04060D; backdrop-filter: none; }
.res-bg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; animation: tFade .8s both; }
.res-orb { --d: min(94vw, 90vh, 660px); width: var(--d); height: var(--d); border-radius: 50%; position: relative; z-index: 1; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-family: 'Jost', var(--font);
  background: radial-gradient(circle at 50% 38%, rgba(26, 24, 32, .95), rgba(10, 10, 13, .97) 68%);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .65), inset 0 0 70px rgba(0, 0, 0, .7); backdrop-filter: blur(10px);
  animation: orbIn .55s cubic-bezier(.2, .9, .25, 1.15) both; }
.res-ring { position: absolute; inset: -3px; border-radius: 50%; padding: 3px; pointer-events: none;
  background: conic-gradient(#FFBB00, #FF5500, #FF0066, #8833CC, #3D80FF, #FFBB00);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
  filter: drop-shadow(0 0 12px rgba(255, 0, 102, .45)); animation: spin 16s linear infinite; }
/* failed: the ring becomes a progress arc from the top - bright red as far as you got, dim for the rest */
.res-orb.failed .res-ring { animation: none; filter: drop-shadow(0 0 12px rgba(255, 26, 74, .45));
  background: conic-gradient(#FF1A4A 0 calc(var(--pr, 1) * 360deg), rgba(255, 26, 74, .16) 0); }
.res-in { width: 74%; display: flex; flex-direction: column; align-items: center; text-align: center; gap: calc(var(--d) * .012); }
.res-grade { font-size: calc(var(--d) * .2); font-weight: 500; line-height: .9; background: var(--grad);
  -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 0 26px rgba(255, 0, 102, .35)); }
.res-grade.pending { opacity: 0; transform: scale(1.8); }
.res-grade.reveal { animation: gradeIn .55s cubic-bezier(.2, .9, .25, 1.25) both; }
@keyframes gradeIn {
  0% { opacity: 0; transform: scale(2.2); filter: blur(10px) drop-shadow(0 0 0 rgba(255, 255, 255, 0)); }
  55% { opacity: 1; transform: scale(.94); filter: blur(0) drop-shadow(0 0 40px rgba(255, 255, 255, .7)); }
  100% { opacity: 1; transform: scale(1); }
}
.res-grade[data-g=F], .res-grade[data-g=D] { background: none; color: #FF1A4A; filter: drop-shadow(0 0 26px rgba(255, 26, 74, .45)); }
.res-title { font-size: calc(var(--d) * .046); font-weight: 500; letter-spacing: .02em; line-height: 1.15; }
.res-sub { font-size: calc(var(--d) * .019); color: var(--muted); letter-spacing: .32em; text-transform: uppercase; padding-left: .32em; }
.res-score { font-size: calc(var(--d) * .072); font-weight: 500; letter-spacing: .04em; padding-left: .04em; font-variant-numeric: tabular-nums;
  background: linear-gradient(90deg, #FFBB00, #FF6418 25%, #FF1A75 50%, #A23DF0 75%, #4A8BFF); -webkit-background-clip: text; background-clip: text; color: transparent;
  margin: calc(var(--d) * .006) 0 calc(var(--d) * .01); }
.res-grid { display: grid; grid-template-columns: repeat(3, 1fr); width: 92%; border-top: 1px solid rgba(255, 255, 255, .08); }
.stat { padding: calc(var(--d) * .016) 4px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.stat + .stat:not(:nth-child(3n+1)) { border-left: 1px solid rgba(255, 255, 255, .08); }
.stat span { display: block; font-size: calc(var(--d) * .016); color: var(--muted); text-transform: uppercase; letter-spacing: .24em; font-weight: 500; }
.stat b { display: block; font-size: calc(var(--d) * .042); font-weight: 400; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat.blue b { color: #7FB0FF; } .stat.green b { color: #4ADE80; } .stat.amber b { color: #FFCC33; } .stat.pink b { color: #FF4D7D; }
.res-note { color: var(--muted); font-size: max(11px, calc(var(--d) * .018)); line-height: 1.45; min-height: 1em; max-width: 92%; margin: calc(var(--d) * .006) 0; }
.res-orb .row { justify-content: center; margin-top: calc(var(--d) * .006); gap: 10px; }
.res-orb .btn { font-family: 'Jost', var(--font); font-weight: 500; letter-spacing: .06em; border-radius: 999px; padding: calc(var(--d) * .016) calc(var(--d) * .034); font-size: max(13px, calc(var(--d) * .024)); }
@keyframes orbIn { from { transform: scale(.82); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.logo-name, .logo small { white-space: nowrap; }
/* ---------- phones (portrait) ---------- */
@media (max-width: 700px) {
  #menu { padding: 14px 14px 0; gap: 12px; height: 100dvh; }
  /* logo: TON618 on the first line, COSMIC BEAT GAME under it */
  .logo { flex-direction: column; align-items: flex-start; gap: 5px; }
  .logo-name { font-size: 24px; letter-spacing: .32em; }
  .logo small { font-size: 9px; letter-spacing: .42em; }
  .top-right .btn { padding: 8px 12px; min-width: 40px; font-size: 16px; }
  .top-right .btn-t { display: none; }   /* icons only, so the header fits beside the logo */
  .hint { display: none; }
  /* song select: every song visible at once as a grid of square art tiles; the chosen song's details below,
     with the Play button pinned to the bottom of the screen */
  .menu-body { display: flex; flex-direction: column; gap: 12px; }
  /* two rows of tiles (10 songs) - more songs scroll, so the song's details never get pushed down */
  .song-list-wrap { flex: none; }
  .song-list { --tile: calc((100vw - 32px - 24px) / 5); flex: none; display: grid; grid-template-columns: repeat(5, 1fr); grid-auto-rows: var(--tile);
    gap: 8px; padding: 2px; overflow-y: auto; max-height: calc(var(--tile) * 2 + 10px); }
  .song-more { right: 0; height: 26px; }
  .song { aspect-ratio: 1; padding: 0; border-radius: 12px; justify-content: flex-end; align-items: flex-end; box-shadow: 0 0 10px 2px rgba(0, 0, 0, .8); }
  .song:hover, .song.sel { transform: none; }
  .song.sel { box-shadow: 0 0 14px rgba(255, 0, 102, .5); }
  .song .stripe, .song-main { display: none; }
  .song-art { -webkit-mask-image: none; mask-image: none; background-position: center; background-size: cover; opacity: .55; }
  .song.sel .song-art { opacity: 1; }
  .song-grade { position: absolute; right: 5px; bottom: 2px; font-size: 15px; min-width: 0; }
  .song-list { gap: 6px; }
  .song-detail { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 0; border-radius: 16px 16px 0 0; position: relative; }
  /* the song's art, faint, behind the title (fading out downwards) */
  .d-top { display: block; position: absolute; top: 0; left: 0; right: 0; height: 130px; margin: 0; border-radius: 16px 16px 0 0; opacity: .3; pointer-events: none;
    -webkit-mask-image: linear-gradient(#000 35%, transparent); mask-image: linear-gradient(#000 35%, transparent); }
  .d-top::after, .d-ring { display: none; }
  .song-detail > :not(.d-top) { position: relative; }
  .song-detail h2 { font-size: 22px; }
  .song-detail .artist { margin-top: 3px; }
  .chips { margin: 10px 0 12px; }
  .best { min-height: 0; padding: 8px 12px; }
  .best .g { font-size: 28px; }
  .lbl { margin: 11px 0 6px; }
  .seg.diffs button { padding: 6px 8px; }
  .mod { padding: 6px 11px; }
  .actions { position: sticky; bottom: 0; margin: 12px -14px 0; padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(rgba(20, 20, 24, 0), var(--panel) 22%); }
  .actions .btn.big { padding-top: 12px; padding-bottom: 12px; }
  /* results: a rounded card instead of the round orb, so everything fits on a tall narrow screen */
  .res-orb { --d: min(100vw, 600px); width: min(94vw, 520px); height: auto; border-radius: 28px; padding: calc(var(--d) * .07) 0 calc(var(--d) * .06); }
  .res-ring { border-radius: 30px; animation: none; }   /* spinning only suits the circle */
  .res-in { width: 88%; gap: calc(var(--d) * .016); }
  .res-orb .btn { font-size: 15px; padding: 11px 22px; }
}
/* ---------- tutorial ---------- */
#tutorial { z-index: 30; }
.tut-card { width: min(500px, 100%); text-align: center; padding: 26px 28px 22px; }
.tut-step { font-size: 11px; font-weight: 700; letter-spacing: .28em; text-transform: uppercase; color: var(--dim); }
.tut-art { width: 112px; height: 112px; margin: 12px auto 6px; }
.tut-art svg { width: 100%; height: 100%; display: block; }
.tut-card h2 { margin: 4px 0 10px; font-size: 24px; }
.tut-text { color: #C9C9D6; line-height: 1.6; font-size: 15px; margin: 0 0 4px; }
.tut-fb { margin: 12px 0 0; padding: 9px 12px; border-radius: 10px; background: rgba(34, 197, 94, .08); border: 1px solid rgba(34, 197, 94, .25); color: #9EF0BF; font-size: 14px; font-weight: 600; }
.tut-fb span { color: var(--muted); font-weight: 500; margin-left: 6px; }
.tut-card .row { justify-content: center; margin-top: 20px; }
.tut-card .row .btn { min-width: 120px; }
.tc-p { color: #7FB0FF; } .tc-g { color: #4ADE80; } .tc-o { color: #FFCC33; } .tc-m { color: #FF4D7D; } .tc-s { color: #4A8BFF; }
/* during a practice round: SKIP stays on screen (top centre, clear of the HUD) */
.tut-skip-play { display: none; position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 15; padding: 8px 16px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .22); background: rgba(10, 10, 14, .6); color: #D8D8E2; font: 600 13px var(--font); letter-spacing: .08em; cursor: pointer; backdrop-filter: blur(6px); }
.tut-skip-play:hover { background: rgba(30, 30, 40, .8); }
body.tut-on[data-screen=play] .tut-skip-play { display: block; }
@media (max-width: 700px) { .tut-card { padding: 20px 18px 16px; } .tut-art { width: 88px; height: 88px; } .tut-text { font-size: 14px; } .tut-card .row .btn { min-width: 0; flex: 1; } }
.set-row { display: grid; grid-template-columns: 140px 1fr 70px; gap: 12px; align-items: center; margin: 10px 0; }
.set-row b { font-family: var(--mono); font-size: 13px; text-align: right; }
.check { display: block; margin: 10px 0; font-size: 14px; cursor: pointer; }
#calibMsg { color: var(--amber); }
.loader { display: flex; align-items: center; gap: 14px; font-weight: 600; }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--pink); animation: spin .8s linear infinite; }
#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; transition: .25s; pointer-events: none; z-index: 50;
  background: var(--panel2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- TON618 title / loading screen ---------- */
body[data-screen=title] #title { display: block; }
/* the backdrop is a square picture (images/title-blackhole.webp) covering the screen; S = its side. Its glowing disc
   line sits 49.5% down it and its hot spot at (63%, 49.7%) - the flare blooms there and the title sits on the line */
/* --dx/--dy: the black disc's centre (48.65%, 49.6% of the picture; inner edge of its ring at r = 14.2% of S) - the title text sits inside it */
#title { --S: max(100vw, 100vh); --fy: calc(50% - .005 * var(--S)); --dx: calc(50% - .0135 * var(--S)); --dy: calc(50% - .004 * var(--S)); background: #050507; overflow: hidden; cursor: pointer; z-index: 30;
  font-family: 'Jost', var(--font); user-select: none; -webkit-user-select: none; }
.t-bg { position: absolute; left: 50%; top: 50%; width: var(--S); height: var(--S); transform: translate(-50%, -50%); pointer-events: none;
  background: url('../images/title-blackhole.webp') center / cover no-repeat; animation: tBg 3s .1s cubic-bezier(.2, .8, .2, 1) both; }
.t-bg::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 50%, transparent 35%, rgba(0, 0, 0, .55) 85%); }   /* soft vignette */
.t-stars { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; animation: tFade 3.5s .2s both; }
.t-flare { position: absolute; left: 63%; top: 49.7%; width: 170px; height: 170px; border-radius: 50%; pointer-events: none; z-index: 1;
  background: radial-gradient(circle, #fff 0, #FFF1CF 3%, rgba(255, 205, 120, .7) 8%, rgba(255, 170, 60, .2) 20%, transparent 55%);
  mix-blend-mode: screen; animation: tFlare 1.3s .1s cubic-bezier(.2, .8, .2, 1) both, tBreathe 3.4s 1.5s ease-in-out infinite; }
.t-flare::after { content: ''; position: absolute; left: 50%; top: 50%; width: 300px; height: 2px; transform: translate(-50%, -50%);
  background: linear-gradient(90deg, transparent, rgba(255, 200, 120, .5) 40%, #FFF1CF 50%, rgba(255, 200, 120, .5) 60%, transparent); filter: blur(.5px); }
/* the title is centred on the dark disc AT ITS OWN HEIGHT: up there the dark area is centred at 49.3% of the picture
   (lower down the flare on the right pulls it to ~47%), i.e. .0065S right of --dx; + .024em centres the letters' ink
   rather than their box (the T's crossbar reaches its edge, the 8 has space after it) */
.t-name { position: absolute; left: calc(var(--dx) + .0065 * var(--S)); bottom: calc(100% - var(--dy) + .022 * var(--S)); margin: 0; transform: translateX(calc(-50% + .024em)); white-space: nowrap;
  font-weight: 500; font-size: calc(.041 * var(--S)); line-height: 1; color: #F3F3F5; letter-spacing: .42em; padding-left: .42em;
  z-index: 2; text-shadow: 0 0 24px rgba(0, 0, 0, .9), 0 2px 6px rgba(0, 0, 0, .7); animation: tName 1.8s .7s cubic-bezier(.2, .8, .2, 1) backwards; }   /* backwards: once done, no filter is left on the title (keeps it crisp) */
.t-sub { position: absolute; left: var(--dx); top: calc(var(--dy) + .036 * var(--S)); transform: translateX(-50%); white-space: nowrap;
  font-weight: 500; font-size: max(10px, calc(.0118 * var(--S))); color: #D9D9DF; letter-spacing: .5em; padding-left: .5em; z-index: 2; text-shadow: 0 0 14px rgba(0, 0, 0, .95); animation: tFade 1.4s 1.6s both; }
.t-prompt { position: absolute; left: 50%; top: auto; bottom: max(11%, 48px); transform: translateX(-50%); white-space: nowrap; font-weight: 600; font-size: clamp(18px, calc(.023 * var(--S)), 28px);
  letter-spacing: .45em; padding-left: .45em; color: #D2D2DA; opacity: 0; transition: opacity .8s; z-index: 2; text-shadow: 0 0 8px #000, 0 0 18px #000; }
/* ready: fully opaque, glowing neon that pulses as it shifts through the game's colours */
.t-prompt.ready { opacity: 1; animation: tNeon 5s 1.2s linear infinite both; }
/* under the prompt: a reminder to turn sound on (fades in with the prompt) */
.t-sound { position: absolute; left: 50%; bottom: max(calc(11% - 40px), 14px); transform: translateX(-50%); display: flex; align-items: center; gap: 9px; white-space: nowrap;
  font-weight: 500; font-size: clamp(11px, calc(.012 * var(--S)), 14px); letter-spacing: .3em; padding-left: .3em; text-transform: uppercase; color: #C4C4CE;
  opacity: 0; transition: opacity 1s .4s; z-index: 2; text-shadow: 0 0 8px #000, 0 0 16px #000; }
.t-sound svg { width: 1.5em; height: 1.5em; fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 6px #000); }
.t-sound.ready { opacity: .9; }
#title.leaving .t-flare { animation: tFlash .75s cubic-bezier(.3, 0, .2, 1) forwards; }
#title.leaving { animation: tOut .8s .25s ease forwards; pointer-events: none; }
@keyframes tBg { from { opacity: 0; transform: translate(-50%, -50%) scale(1.06); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes tFlare { 0% { transform: translate(-50%, -50%) scale(0); opacity: 0; } 55% { transform: translate(-50%, -50%) scale(1.35); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes tBreathe { 50% { filter: brightness(1.3); } }
@keyframes tName { from { opacity: 0; letter-spacing: .9em; padding-left: .9em; filter: blur(8px); } to { opacity: 1; letter-spacing: .42em; padding-left: .42em; filter: none; } }
@keyframes tFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tNeon {
  0%, 100% { color: #FFE9A8; text-shadow: 0 0 4px #FFBB00, 0 0 12px #FFBB00, 0 0 26px rgba(255, 187, 0, .55); }
  10% { text-shadow: 0 0 2px #FFBB00, 0 0 6px rgba(255, 187, 0, .6), 0 0 12px rgba(255, 187, 0, .25); }
  20% { color: #FFC7A8; text-shadow: 0 0 4px #FF6418, 0 0 12px #FF6418, 0 0 26px rgba(255, 100, 24, .55); }
  30% { text-shadow: 0 0 2px #FF6418, 0 0 6px rgba(255, 100, 24, .6), 0 0 12px rgba(255, 100, 24, .25); }
  40% { color: #FFB3D2; text-shadow: 0 0 4px #FF1A75, 0 0 12px #FF1A75, 0 0 26px rgba(255, 26, 117, .55); }
  50% { text-shadow: 0 0 2px #FF1A75, 0 0 6px rgba(255, 26, 117, .6), 0 0 12px rgba(255, 26, 117, .25); }
  60% { color: #DDB8FF; text-shadow: 0 0 4px #A23DF0, 0 0 12px #A23DF0, 0 0 26px rgba(162, 61, 240, .55); }
  70% { text-shadow: 0 0 2px #A23DF0, 0 0 6px rgba(162, 61, 240, .6), 0 0 12px rgba(162, 61, 240, .25); }
  80% { color: #B8D2FF; text-shadow: 0 0 4px #4A8BFF, 0 0 12px #4A8BFF, 0 0 26px rgba(74, 139, 255, .55); }
  90% { text-shadow: 0 0 2px #4A8BFF, 0 0 6px rgba(74, 139, 255, .6), 0 0 12px rgba(74, 139, 255, .25); }
}
@keyframes tFlash { 0% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 35% { transform: translate(-50%, -50%) scale(3.5); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(14); opacity: 0; } }
@keyframes tOut { to { opacity: 0; } }

/* ---------- on-screen TAP + pause buttons (touch devices) ---------- */
.tap-btn, .pause-btn { display: none; position: fixed; z-index: 5; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; cursor: pointer; }
body.tapbtn[data-screen=play] .tap-btn, body.tapbtn[data-screen=play] .pause-btn { display: flex; }
.tap-btn { --c: #FF0066; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom)); width: min(460px, calc(100vw - 32px)); height: clamp(64px, 11vh, 96px);
  align-items: center; justify-content: center; border-radius: 999px; font-size: 26px; font-weight: 900; font-style: italic; letter-spacing: 6px; color: #fff;
  border: 2px solid transparent; background: linear-gradient(rgba(20, 20, 24, .88), rgba(20, 20, 24, .88)) padding-box, var(--grad) border-box;
  box-shadow: 0 0 30px -6px rgba(255, 0, 102, .55), inset 0 0 24px rgba(255, 255, 255, .04); }
.tap-btn.hit { animation: tapHit .28s ease-out; }
@keyframes tapHit {
  0% { transform: translateX(-50%) scale(.95); background: linear-gradient(var(--c), var(--c)) padding-box, var(--grad) border-box; box-shadow: 0 0 60px 4px var(--c); }
  100% { transform: translateX(-50%) scale(1); }
}
.pause-btn { top: 14px; left: 50%; transform: translateX(-50%); width: 42px; height: 42px; align-items: center; justify-content: center; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(20, 20, 24, .8); color: var(--text); font-size: 14px; }
select#setTap { width: 100%; }

/* ---------- editor ---------- */
#editor { flex-direction: column; background: var(--bg); }
.ed-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.ed-titles { display: flex; gap: 8px; flex: 1; min-width: 0; }
.ed-titles input { flex: 1; min-width: 80px; font-weight: 700; }
.ed-status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.ed-status b { color: var(--text); }
.ed-status .unsaved { color: var(--amber); } .ed-status .saved { color: var(--green); }
.ed-tools { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.grp { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.grp label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.grp .num { width: 84px; padding: 5px 8px; }
.grp select { padding: 5px 8px; }
.grp .time { font-size: 15px; color: var(--text); min-width: 150px; }
#edSpeed { width: 110px; }
#edOverview { height: 38px; width: 100%; display: block; border-bottom: 1px solid var(--line); cursor: pointer; flex-shrink: 0; }
#edTimeline { flex: 1; width: 100%; display: block; min-height: 160px; cursor: crosshair; touch-action: none; }
.ed-help { padding: 8px 16px; font-size: 12px; color: var(--dim); border-top: 1px solid var(--line); line-height: 1.9; }
.pop { position: absolute; right: 16px; top: 112px; width: 340px; padding: 20px; z-index: 5; box-shadow: 0 20px 50px rgba(0, 0, 0, .6); }
.pop h3 { margin: 0 0 14px; }
.pop label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.pop label.check { flex-direction: row; align-items: center; }
