:root {
  --bg: #0b0f1a; --panel: #121a2b; --panel2: #18223a; --text: #f1f5f9; --muted: #8b97ad;
  --c0: #22d3ee; --c1: #f472b6; --c2: #a3e635; --c3: #fb923c; --gold: #ffe08a; --red: #fb7185;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#app { height: 100%; }
button { font: inherit; color: inherit; }
.screen { display: none; min-height: 100%; }
.screen.active { display: block; }
.hidden { display: none !important; }
.top { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--sat) + 12px) 16px 8px; }
.top h1 { font-size: 18px; margin: 0; }
.brand { font-weight: 900; font-size: 24px; letter-spacing: -0.5px; }
.brand span { background: linear-gradient(90deg, var(--c0), var(--c1)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--panel); color: var(--text); font-size: 22px; cursor: pointer; }
.btn { min-height: 48px; padding: 0 20px; border-radius: 14px; border: 0; background: linear-gradient(90deg, #6366f1, #22d3ee); color: #fff; font-weight: 800; font-size: 16px; cursor: pointer; }
.btn.ghost { background: var(--panel2); }
.btn.danger { background: #3b1e2a; color: var(--red); }
.btn:active { transform: scale(0.97); }

/* profile strip */
.profile { display: flex; gap: 14px; align-items: center; margin: 4px 16px 10px; padding: 12px 14px; background: var(--panel); border-radius: 16px; }
.profile .lvl { flex: 1; min-width: 0; }
.lvl-num { font-weight: 800; font-size: 15px; }
.profile .bar, .r-xp .bar { height: 8px; background: #0b0f1a; border-radius: 4px; overflow: hidden; margin: 6px 0 2px; }
.profile .bar i, .r-xp .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--c0), var(--c1)); transition: width .5s ease; }
.profile .xp { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.profile .stat { text-align: center; line-height: 1.1; }
.profile .stat b { display: block; font-size: 20px; }
.profile .stat span { font-size: 11px; color: var(--muted); }

/* difficulty + tabs */
.seg { display: flex; margin: 0 16px 10px; background: var(--panel); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; min-height: 44px; padding: 0 3px; border: 0; background: transparent; border-radius: 9px; color: var(--muted); font-weight: 700; font-size: 14px; cursor: pointer; }
.seg button.active { background: var(--panel2); color: var(--text); }
.tabs { display: flex; gap: 6px; margin: 0 16px 8px; }
.tabs button { flex: 1; min-height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-weight: 800; cursor: pointer; }
.tabs button.active { color: var(--text); box-shadow: inset 0 -3px 0 var(--c0); }
.tabpane { padding: 0 16px calc(var(--sab) + 24px); }
.songs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.song { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; background: var(--panel); border-radius: 16px; }
.song .info { flex: 1; min-width: 0; }
.song .title { font-weight: 800; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.song .best { font-size: 12px; margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.song .best span { color: var(--muted); }
.song .best b { color: var(--gold); font-variant-numeric: tabular-nums; }
.song .play { min-width: 64px; min-height: 44px; border-radius: 12px; border: 0; background: linear-gradient(90deg, #6366f1, #22d3ee); color: #fff; font-weight: 800; cursor: pointer; }
.song .del { width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; }
.add-file { display: flex; align-items: center; justify-content: center; min-height: 56px; border: 2px dashed #2b3650; border-radius: 16px; font-weight: 800; cursor: pointer; margin-bottom: 8px; }
.add-file input { display: none; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.4; margin: 8px 2px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.error { color: var(--red); font-size: 14px; margin: 8px 2px; }
.progress { margin: 8px 0; }
.progress .bar { height: 8px; background: var(--panel); border-radius: 4px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--c0); transition: width .2s; }
.progress span { font-size: 12px; color: var(--muted); }

/* settings */
.form { padding: 0 16px calc(var(--sab) + 24px); display: flex; flex-direction: column; gap: 16px; }
.row { background: var(--panel); border-radius: 16px; padding: 14px; }
.row label { display: flex; justify-content: space-between; font-weight: 700; }
.row label b { color: var(--c0); font-variant-numeric: tabular-nums; }
.row label small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.row input[type=range] { width: 100%; margin: 12px 0 4px; accent-color: var(--c0); }
.row.toggle { display: flex; justify-content: space-between; align-items: center; }
.row.toggle input { width: 26px; height: 26px; accent-color: var(--c0); }
.row .btn { margin-top: 10px; width: 100%; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--panel2); font-size: 22px; cursor: pointer; }
.stepper input { flex: 1; }

/* sync */
.sync { padding: 0 16px; text-align: center; }
.sync p { color: var(--muted); line-height: 1.5; }
.sync-pad { width: min(70vw, 300px); height: min(70vw, 300px); border-radius: 50%; border: 0; background: radial-gradient(circle at 40% 35%, #6366f1, #0b0f1a 75%); color: #fff; font-size: 32px; font-weight: 900; margin: 24px auto; display: block; cursor: pointer; box-shadow: 0 0 40px rgba(99,102,241,.35); }
.sync-pad:active { transform: scale(0.96); }
.sync-result { font-size: 18px; }
.sync-result b { color: var(--c0); }
.sync-result .btns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }

/* play */
.screen.play { position: fixed; inset: 0; display: none; flex-direction: column; background: var(--bg); }
.screen.play.active { display: flex; }
.progress-line { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: rgba(255,255,255,.08); z-index: 5; }
.progress-line i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--c0), var(--c1)); }
.yt-strip { position: relative; width: 100%; max-width: 480px; margin: 0 auto; aspect-ratio: 16/9; min-height: 200px; background: #000; flex: 0 0 auto; padding-top: var(--sat); }
.yt-strip iframe, .yt-strip #yt-player { width: 100%; height: 100%; display: block; }
.yt-wait { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font-weight: 800; color: #fff; text-shadow: 0 1px 4px #000; pointer-events: none; }
.playarea { position: relative; flex: 1; min-height: 0; width: 100%; max-width: 640px; margin: 0 auto; touch-action: none; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.pause-btn { position: absolute; top: calc(var(--sat) + 10px); left: 50%; transform: translateX(-50%); width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(255,255,255,.1); color: #fff; font-weight: 900; letter-spacing: 2px; cursor: pointer; }
.song-title { position: absolute; top: calc(var(--sat) + 58px); left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); pointer-events: none; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(11,15,26,.8); z-index: 10; }
.overlay .card { background: var(--panel); border-radius: 20px; padding: 24px; min-width: 240px; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.overlay h2 { margin: 0 0 6px; }
.spinner { width: 36px; height: 36px; border: 4px solid rgba(255,255,255,.15); border-top-color: var(--c0); border-radius: 50%; margin: 0 auto 6px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* results */
.results { padding: calc(var(--sat) + 28px) 20px calc(var(--sab) + 24px); text-align: center; max-width: 460px; margin: 0 auto; }
.r-title { color: var(--muted); font-weight: 700; }
.r-grade { font-size: 120px; font-weight: 900; line-height: 1; margin: 6px 0; color: var(--gold); text-shadow: 0 0 28px rgba(255,208,80,.45), 0 2px 0 rgba(0,0,0,.4); animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.r-grade.D, .r-grade.C { color: var(--muted); text-shadow: none; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.badges { display: flex; gap: 8px; justify-content: center; min-height: 26px; }
.badge { padding: 4px 10px; border-radius: 999px; background: #3b2f12; color: var(--gold); font-weight: 900; font-size: 12px; letter-spacing: 1px; }
.badge.fc { background: #10303a; color: var(--c0); }
.r-score { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; margin: 8px 0 14px; }
.r-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.r-grid div { background: var(--panel); border-radius: 14px; padding: 10px; }
.r-grid b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.r-grid span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.r-grid .p b { color: var(--gold); } .r-grid .g b { color: var(--c0); } .r-grid .go b { color: var(--c2); } .r-grid .m b { color: var(--red); }
.r-xp { margin: 16px 0; font-size: 14px; }
.r-xp #r-levelup { color: var(--gold); font-weight: 900; margin-left: 8px; }
.results .btns { display: flex; gap: 10px; }
.results .btns .btn { flex: 1; padding: 0 8px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 24px); transform: translateX(-50%); background: var(--panel2); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.4); }

kbd { display: inline-block; min-width: 22px; padding: 1px 6px; border-radius: 6px; background: var(--panel2); border: 1px solid #2b3650; border-bottom-width: 2px; font: 700 12px ui-monospace, "SF Mono", Menlo, monospace; color: var(--text); text-align: center; margin: 0 2px; }
.keys-only { display: none; }
@media (pointer: fine) { .keys-only { display: inline; } .r-keys { display: block; text-align: center; margin-top: 14px; } }

/* ---- Regular width (Duo inner, iPad, Mac): two panes with the seam in the middle, so the Duo hinge sits in the gutter.
   Floor is 640px (never 744: the Duo inner display is ~669pt wide). Compact (phones, Duo outer) keeps the single column. ---- */
.stage { display: contents; }
.stage-head, .stage-card, .stage-stats, .stage-keys, .keys-card { display: none; }

@media (min-width: 640px) {
  /* songs: side | main */
  #screen-songs.active { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 32px; align-content: start; max-width: 1280px; margin: 0 auto; padding: 0 20px; }
  #screen-songs .top { grid-column: 1 / -1; padding-left: 0; padding-right: 0; }
  #screen-songs .side { grid-column: 1; position: sticky; top: 0; align-self: start; }
  #screen-songs .main { grid-column: 2; min-width: 0; }
  .profile, .seg, .tabs, .tabpane { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
  .tabs { flex-direction: column; gap: 4px; }
  .tabs button { text-align: left; padding: 0 14px; border-radius: 12px; }
  .tabs button.active { box-shadow: none; background: var(--panel2); }
  .keys-card { display: block; background: var(--panel); border-radius: 16px; padding: 14px; margin-top: 12px; color: var(--muted); font-size: 13px; line-height: 1.6; }
  #screen-settings, #screen-sync { max-width: 640px; margin: 0 auto; }
  .results { max-width: 640px; }
  .r-grid { grid-template-columns: repeat(3, 1fr); }

  /* play: stage | lanes */
  .screen.play.active { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 28px; } /* 28 keeps both panes clear of the 669-pt Duo fold band (322–347) */
  .stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 0; overflow: hidden; padding: calc(var(--sat) + 16px) 0 calc(var(--sab) + 16px) 20px; }
  .stage-head { display: flex; align-items: center; gap: 12px; }
  .stage-title { min-width: 0; }
  .stage-title b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stage-title span { font-size: 13px; color: var(--muted); }
  .yt-strip { max-width: none; margin: 0; min-height: 0; padding-top: 0; border-radius: 14px; overflow: hidden; }
  .stage-card { display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; aspect-ratio: 16/9; border-radius: 14px; padding: 18px; background: radial-gradient(circle at 20% 15%, rgba(99,102,241,.55), transparent 55%), radial-gradient(circle at 85% 80%, rgba(34,211,238,.35), transparent 50%), var(--panel); position: relative; overflow: hidden; }
  .sc-kind { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }
  .sc-title { font-size: clamp(22px, 3.2vw, 40px); font-weight: 900; line-height: 1.05; }
  .sc-meta { font-size: 13px; color: var(--muted); }
  .sc-lanes { position: absolute; top: 0; right: 0; bottom: 0; width: 38%; display: flex; gap: 6px; padding: 14px; opacity: .55; }
  .sc-lanes i { flex: 1; border-radius: 999px; background: linear-gradient(180deg, transparent, var(--c0)); }
  .sc-lanes i:nth-child(2) { background: linear-gradient(180deg, transparent, var(--c1)); } .sc-lanes i:nth-child(3) { background: linear-gradient(180deg, transparent, var(--c2)); } .sc-lanes i:nth-child(4) { background: linear-gradient(180deg, transparent, var(--c3)); }
  .stage-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .stage-stats .st { background: var(--panel); border-radius: 14px; padding: 12px 14px; min-width: 0; }
  .stage-stats .st b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; font-weight: 900; }
  .stage-stats .st span { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
  .stage-stats .st.big { grid-column: 1 / -1; }
  .stage-stats .st.big b { font-size: 44px; }
  .stage-stats .st-mult.hot b { color: var(--gold); }
  .playarea { max-width: none; margin: 0; height: 100%; min-height: 0; }
  .pause-btn, .song-title { display: none; }
}
@media (min-width: 640px) and (pointer: fine) {
  .stage-keys { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-top: auto; }
  .stage-keys span { margin-right: 10px; }
}
/* Mac / large: the song list becomes a grid, the lanes get a fixed comfortable width, the stage grows */
@media (min-width: 1024px) {
  #screen-songs.active { grid-template-columns: 340px minmax(0, 1fr); column-gap: 40px; }
  .songs { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
  .song { align-self: start; }
  .screen.play.active { grid-template-columns: minmax(0, 960px) clamp(400px, 40vw, 600px); column-gap: 32px; justify-content: center; }
  .stage { padding: calc(var(--sat) + 24px) 0 calc(var(--sab) + 24px) 32px; width: 100%; gap: 18px; }
  .stage-title b { font-size: 20px; }
  .stage-stats .st b { font-size: 34px; }
  .stage-stats .st.big b { font-size: 64px; }
}
@media (min-width: 1600px) {
  .screen.play.active { grid-template-columns: minmax(0, 1100px) clamp(480px, 32vw, 640px); column-gap: 48px; }
}
/* Progressive: a browser that exposes the fold puts the seam exactly on it */
@media (horizontal-viewport-segments: 2) {
  .screen.play.active { grid-template-columns: env(viewport-segment-width 0 0) minmax(0, 1fr); column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0)); }
}

.r-sync { margin: 12px 0 4px; padding: 12px 14px; border-radius: 14px; background: rgba(250, 204, 21, 0.08); border: 1px solid rgba(250, 204, 21, 0.25); display: flex; flex-direction: column; gap: 10px; text-align: left; }
.r-sync p { margin: 0; font-size: 14px; line-height: 1.4; color: var(--muted, #cbd5e1); }
.r-sync .btn { width: 100%; }

/* ---- difficulty note · how-to-play row · footer ---- */
.diff-note { margin: -4px 18px 10px; font-size: 12px; color: var(--muted); min-height: 15px; }
.howto { display: flex; align-items: center; gap: 12px; width: calc(100% - 32px); margin: 0 16px 10px; padding: 10px 14px; min-height: 56px; border: 0; border-radius: 16px; background: linear-gradient(90deg, rgba(99,102,241,.35), rgba(34,211,238,.2)), var(--panel); color: var(--text); text-align: left; cursor: pointer; }
.howto-ic { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(90deg, #6366f1, #22d3ee); display: flex; align-items: center; justify-content: center; font-size: 14px; flex: 0 0 auto; }
.howto b { display: block; font-size: 15px; }
.howto small { display: block; font-size: 12px; color: var(--muted); }
.foot { padding: 12px 16px calc(var(--sab) + 24px); font-size: 12px; color: var(--muted); text-align: center; }
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--text); }
.ad { margin-top: 18px; min-height: 0; }

/* ---- intro (first launch) ---- */
.intro { max-width: 460px; margin: 0 auto; padding: calc(var(--sat) + 48px) 24px calc(var(--sab) + 24px); text-align: center; display: flex; flex-direction: column; gap: 14px; }
.brand.big { font-size: 40px; }
.intro-sub { margin: -8px 0 0; color: var(--muted); font-weight: 700; }
.intro-lanes { display: flex; gap: 10px; height: 120px; padding: 0 30px; }
.intro-lanes div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 10px; }
.intro-lanes i { display: block; width: 70%; height: 18px; border-radius: 9px; background: var(--c0); box-shadow: 0 0 14px var(--c0); animation: fall 1.6s ease-in infinite; }
.intro-lanes u { display: block; width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--c0); opacity: .7; }
.intro-lanes div:nth-child(2) i, .intro-lanes div:nth-child(2) u { background: var(--c1); border-color: var(--c1); box-shadow: 0 0 14px var(--c1); }
.intro-lanes div:nth-child(3) i, .intro-lanes div:nth-child(3) u { background: var(--c2); border-color: var(--c2); box-shadow: 0 0 14px var(--c2); }
.intro-lanes div:nth-child(4) i, .intro-lanes div:nth-child(4) u { background: var(--c3); border-color: var(--c3); box-shadow: 0 0 14px var(--c3); }
.intro-lanes u { background: transparent !important; box-shadow: none !important; }
.intro-lanes div:nth-child(2) i { animation-delay: .4s; } .intro-lanes div:nth-child(3) i { animation-delay: .8s; } .intro-lanes div:nth-child(4) i { animation-delay: 1.2s; }
@keyframes fall { from { transform: translateY(-70px); opacity: 0; } 20% { opacity: 1; } to { transform: translateY(0); opacity: 1; } }
.intro-steps { text-align: left; margin: 0; padding: 0 0 0 22px; display: flex; flex-direction: column; gap: 10px; line-height: 1.45; font-size: 15px; color: var(--muted); }
.intro-steps b { color: var(--text); }
.intro-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.intro-btns .btn { width: 100%; }
@media (prefers-reduced-motion: reduce) { .intro-lanes i { animation: none; } }
@media (min-width: 640px) {
  .howto { width: 100%; margin-left: 0; margin-right: 0; }
  .diff-note { margin-left: 2px; }
  .intro { max-width: 560px; padding-top: calc(var(--sat) + 72px); }
  .intro-btns { flex-direction: row; }
}

/* ---- privacy / terms pages ---- */
.doc { max-width: 640px; margin: 0 auto; padding: calc(var(--sat) + 24px) 20px calc(var(--sab) + 40px); line-height: 1.55; }
.doc h1 { font-size: 26px; margin: 12px 0 4px; }
.doc h2 { font-size: 17px; margin: 22px 0 6px; }
.doc p, .doc li { color: #cbd5e1; font-size: 15px; }
.doc a { color: var(--c0); }
.doc .back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; }
