:root {
  --bg0: #06051a;
  --bg1: #150c38;
  --p1: #4fe3ff;
  --p1g: #00b7ff;
  --p2: #ff5fd2;
  --p2g: #ff2fa8;
  --gold: #ffd86b;
  --text: #eef0ff;
  --muted: #9aa0c8;
  --glass: rgba(18, 16, 48, 0.72);
  --line: rgba(160, 170, 255, 0.18);
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Arial Black", "Segoe UI Black", "Helvetica Neue", Impact, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg0); color: var(--text); font-family: var(--font); -webkit-tap-highlight-color: transparent; }
body { touch-action: manipulation; }
/* The hidden attribute must win over display rules like .btn { display: inline-flex }. */
[hidden] { display: none !important; }
/* Korean: break between words, not between syllables. */
html:lang(ko) body { word-break: keep-all; overflow-wrap: break-word; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--p1); }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }

/* ---- menus -------------------------------------------------------------------------------- */
#ui { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; pointer-events: auto; overflow: hidden; overflow: clip;
  background: radial-gradient(1200px 700px at 20% 10%, rgba(79,227,255,0.14), transparent 60%), radial-gradient(1000px 700px at 85% 80%, rgba(255,95,210,0.16), transparent 60%), linear-gradient(160deg, var(--bg0), var(--bg1)); }
.screen.active { display: flex; }
.screen::before { content: ""; position: absolute; inset: -20%; background:
  radial-gradient(circle at 30% 40%, rgba(255,216,107,0.08), transparent 30%),
  radial-gradient(circle at 70% 30%, rgba(79,227,255,0.08), transparent 25%),
  radial-gradient(circle at 60% 75%, rgba(255,95,210,0.08), transparent 28%);
  animation: drift 18s ease-in-out infinite alternate; pointer-events: none; }
@keyframes drift { to { transform: translate(4%, -3%) rotate(8deg); } }

/* The title scrolls when the phone is too short; margin:auto centres it when it fits. */
.title-scroll { flex: 1; min-height: 0; display: flex; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; position: relative;
  padding: calc(max(12px, env(safe-area-inset-top)) + 44px) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.title-inner { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 28px; width: 100%; max-width: 1000px; min-width: 0; }
.logo { text-align: center; position: relative; min-width: 0; max-width: 100%; }
.logo-main { font-family: var(--display); font-style: italic; font-size: clamp(48px, 10vw, 112px); letter-spacing: 0.02em; line-height: 1; }
.logo-main .c1 { color: #dffaff; text-shadow: 0 0 8px var(--p1), 0 0 26px var(--p1g), 0 0 60px var(--p1g); }
.logo-main .c2 { color: #ffe3f6; text-shadow: 0 0 8px var(--p2), 0 0 26px var(--p2g), 0 0 60px var(--p2g); }
.logo-ko { margin-top: 6px; font-weight: 800; font-size: clamp(18px, 3vw, 26px); letter-spacing: 0.4em; color: #fff; text-shadow: 0 0 14px rgba(255,216,107,0.7); }
.tagline { margin: 10px 0 0; color: var(--muted); font-size: clamp(14px, 2vw, 17px); }
.menu { display: flex; flex-direction: column; gap: 12px; width: min(460px, 100%); position: relative; min-width: 0; }
.menu .big { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 16px 20px; border-radius: 16px; border: 1px solid var(--line);
  background: linear-gradient(120deg, rgba(79,227,255,0.16), rgba(40,30,110,0.5)); text-align: left; transition: transform .12s, box-shadow .12s, border-color .12s; }
.menu .big.duet { background: linear-gradient(120deg, rgba(79,227,255,0.18), rgba(255,95,210,0.22)); border-color: rgba(255,255,255,0.3); }
.menu .big b { font-size: 21px; }
.menu .big small { color: var(--muted); font-size: 13.5px; }
.menu .big:hover, .menu .big:focus-visible { transform: translateY(-2px); border-color: rgba(255,255,255,0.55); box-shadow: 0 0 22px rgba(79,227,255,0.35), 0 0 40px rgba(255,95,210,0.2); outline: none; }
.menu-row { display: flex; gap: 8px; }
.menu-row button { flex: 1; padding: 11px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); font-size: 14px; }
.menu-row button:hover { border-color: rgba(255,255,255,0.5); }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 4px 0 0; line-height: 1.5; }
.corner { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); display: flex; gap: 8px; z-index: 2; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass); font-size: 13px; text-decoration: none; color: var(--text); }

.bar-top { display: flex; align-items: center; gap: 14px; padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left)); position: relative; flex: none; }
.bar-top h2 { margin: 0; font-size: 20px; }
.back { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass); }
.panel-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 8px max(20px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); max-width: 900px; width: 100%; margin: 0 auto; position: relative; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); cursor: pointer; font-weight: 600; }
.btn.primary { background: linear-gradient(120deg, #1fb8ff, #ff4fc4); border-color: transparent; color: #fff; box-shadow: 0 0 18px rgba(255,79,196,0.35); }
.btn:disabled { opacity: 0.45; cursor: default; }

/* ---- song select ---------------------------------------------------------------------------- */
.select-body { flex: 1; display: grid; grid-template-columns: minmax(260px, 1fr) minmax(300px, 1.15fr); grid-template-rows: minmax(0, 1fr); gap: 16px; padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left)); min-height: 0; position: relative; }
.song-list { overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 10px; padding: 0 4px 18px 0; min-height: 0; }
.song { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 13px 15px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass); cursor: pointer; text-align: left; transition: border-color .1s, box-shadow .1s; }
.song:hover { border-color: rgba(255,255,255,0.4); }
.song.sel { border-color: #fff; box-shadow: 0 0 0 1px #fff inset, 0 0 22px rgba(79,227,255,0.35); background: linear-gradient(120deg, rgba(79,227,255,0.16), rgba(255,95,210,0.16)); }
.song .t { font-weight: 800; font-size: 17px; }
.song .a { color: var(--muted); font-size: 13px; }
.song .meta { grid-row: 1 / span 2; grid-column: 2; text-align: right; font-size: 12px; color: var(--muted); align-self: center; }
.song .stars { color: var(--gold); letter-spacing: 1px; font-size: 13px; }
.song .tag { display: inline-block; margin-top: 4px; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,0.08); color: var(--muted); }
.song.locked { opacity: 0.6; }

.setup { overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 12px; min-height: 0; padding-bottom: 0; }
.setup > .keys-hint { padding-bottom: 12px; }
.setup { scroll-padding-bottom: 84px; }
.swap .ico { display: none; }
.bms-more { display: none; }
.diff-jump { display: inline-flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0; max-width: 40%; padding: 6px 10px; font-size: 13px; line-height: 1.25; text-align: left; }
.diff-jump .dj-lines { display: flex; flex-direction: column; min-width: 0; }
.diff-jump .dj-lines span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dj-line { display: flex; align-items: center; gap: 4px; }
.dj-p { font-weight: 800; font-size: 11px; opacity: 0.8; }
.dj-dot { display: none; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dj-dot.p1 { background: var(--p1); } .dj-dot.p2 { background: var(--p2); }
.seat.flash { animation: seatflash 0.9s ease-out; }
@keyframes seatflash { 0% { box-shadow: 0 0 0 3px #fff, 0 0 26px rgba(255,255,255,0.6); } 100% { box-shadow: 0 0 0 0 transparent; } }
.diff-jump .dj-arrow { flex: none; opacity: 0.8; }
.setup .actions .btn.primary { flex: 1 1 auto; min-width: 96px; }
.song { flex: none; }
.song-head { padding: 14px 16px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); }
.song-head h3 { margin: 0 0 4px; font-size: 22px; }
.song-head p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat { padding: 12px 14px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 9px; }
.seat.s0 { border-color: rgba(79,227,255,0.55); box-shadow: 0 0 18px rgba(0,183,255,0.18) inset; }
.seat.s1 { border-color: rgba(255,95,210,0.55); box-shadow: 0 0 18px rgba(255,47,168,0.18) inset; }
.seat .who { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.seat.s0 .who b { color: var(--p1); } .seat.s1 .who b { color: var(--p2); }
.seat .inst { font-size: 20px; font-weight: 800; }
.seat label { font-size: 12px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips button { padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); font-size: 13px; }
.chips button.on { background: #fff; color: #120c30; border-color: #fff; font-weight: 800; }
.seat.s0 .chips button.on { background: var(--p1); border-color: var(--p1); }
.seat.s1 .chips button.on { background: var(--p2); border-color: var(--p2); }
.diff-hint { font-size: 12px; color: var(--muted); min-height: 1.2em; }
.seat input[type=range] { width: 100%; accent-color: #fff; }
.seat.s0 input[type=range] { accent-color: var(--p1); }
.seat.s1 input[type=range] { accent-color: var(--p2); }
.song.bms-slot { border-style: dashed; }
.song-sep { font-size: 12px; color: var(--muted); margin: 8px 2px 0; letter-spacing: 0.08em; }
/* A solid bar with a shadow fade: nothing see-through that could swallow taps meant for chips. */
.setup .actions { display: flex; gap: 10px; flex-wrap: nowrap; align-items: stretch; position: sticky; bottom: 0; z-index: 3; padding: 8px 8px max(6px, env(safe-area-inset-bottom)); margin: 0 -8px; border-radius: 14px 14px 0 0; background: rgba(18,11,48,0.96); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.setup .actions .btn.primary { flex: 1; padding: 15px; font-size: 18px; }
.keys-hint { font-size: 12.5px; color: var(--muted); line-height: 1.6; }

/* ---- HUD -------------------------------------------------------------------------------------- */
#hud { position: fixed; left: 0; right: 0; top: 0; display: grid; grid-template-columns: 1fr minmax(160px, 30vw) 1fr; align-items: center; gap: 10px; padding: max(8px, env(safe-area-inset-top)) calc(max(12px, env(safe-area-inset-right)) + 52px) 6px max(12px, env(safe-area-inset-left)); pointer-events: none; }
#hud[hidden] { display: none; }
.hud-seat { display: flex; align-items: baseline; gap: 10px; font-weight: 800; text-shadow: 0 0 10px rgba(0,0,0,0.8); min-width: 0; }
.hud-seat { flex-direction: column; gap: 0; }
.hud-seat.right { align-items: flex-end; }
.hud-seat .who { min-width: 0; max-width: 100%; white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; line-height: 1.25; }
.hud-seat.right .who { text-align: right; }
.hud-seat.right { justify-content: flex-end; }
.hud-seat .who { font-size: 13px; color: var(--muted); }
.hud-seat .score { font-family: var(--display); font-size: 20px; font-variant-numeric: tabular-nums; }
#hud-0 .score { color: #dffaff; text-shadow: 0 0 10px var(--p1g); }
#hud-1 .score { color: #ffe3f6; text-shadow: 0 0 10px var(--p2g); }
.hud-mid { text-align: center; }
.hud-mid .hud-title { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-mid .bar { height: 4px; border-radius: 3px; background: rgba(255,255,255,0.12); margin-top: 4px; overflow: hidden; }
.hud-mid .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--p1), #fff, var(--p2)); }
.icon-btn { position: fixed; top: max(8px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); width: 42px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass); pointer-events: auto; font-size: 14px; }

/* ---- overlays ----------------------------------------------------------------------------------- */
.overlay { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: rgba(6,5,26,0.8); backdrop-filter: blur(6px); z-index: 20; }
.overlay[hidden] { display: none; }
.overlay .btn { min-width: 200px; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--p1); border-right-color: var(--p2); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.lbar { width: min(320px, 70vw); height: 6px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
.lbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--p1), var(--p2)); transition: width .15s; }
#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); padding: 10px 16px; border-radius: 12px; background: rgba(20,16,50,0.92); border: 1px solid var(--line); z-index: 30; font-size: 14px; max-width: 90vw; }

/* ---- results ------------------------------------------------------------------------------------ */
#scr-results { background: rgba(6,5,26,0.86); backdrop-filter: blur(8px); }
.results { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: max(16px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 14px; align-items: center; position: relative; }
.results h2 { margin: 6px 0 0; font-size: 24px; }
.res-song { color: var(--muted); margin-top: -8px; }
.res-team { display: flex; gap: 18px; align-items: center; padding: 12px 20px; border-radius: 16px; background: linear-gradient(120deg, rgba(79,227,255,0.14), rgba(255,95,210,0.14)); border: 1px solid rgba(255,255,255,0.25); }
.res-team .big { font-family: var(--display); font-size: 34px; font-variant-numeric: tabular-nums; }
.res-team .lbl { font-size: 12px; color: var(--muted); }
.res-seats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(290px, 100%), 1fr)); gap: 14px; width: min(980px, 100%); align-items: start; }
.res-seat { padding: 14px 16px; border-radius: 16px; background: var(--glass); border: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.res-seat.s0 { border-color: rgba(79,227,255,0.5); } .res-seat.s1 { border-color: rgba(255,95,210,0.5); }
.res-seat .head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; }
.res-seat .head b { font-size: 16px; }
.rank { grid-row: span 2; font-family: var(--display); font-style: italic; font-size: 64px; line-height: 1; min-width: 1.4em; text-align: center; }
.rank.P, .rank.S\+ { color: #fff6d0; text-shadow: 0 0 10px #ffd24a, 0 0 30px #ff9f2e, 0 0 60px #ff6ad5; }
.rank.S { color: #fff3c0; text-shadow: 0 0 12px #ffc93c, 0 0 30px #ff9f2e; }
.rank.A { color: #d8fff0; text-shadow: 0 0 12px #3dffa0; }
.rank.B { color: #d8e6ff; text-shadow: 0 0 12px #5b8cff; }
.rank.C, .rank.D { color: #ddd; }
.res-score { font-family: var(--display); font-size: 30px; font-variant-numeric: tabular-nums; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 900; padding: 3px 8px; border-radius: 6px; background: linear-gradient(90deg, #ffd86b, #ff7ad9); color: #1a0b25; letter-spacing: 0.05em; }
.counts { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.counts div { padding: 6px 2px; border-radius: 10px; background: rgba(255,255,255,0.05); }
.counts b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.counts span { font-size: 10.5px; font-weight: 900; letter-spacing: 0.04em; }
.c-p span { color: #ffd86b; } .c-g span { color: #4dffae; } .c-o span { color: #8fb0ff; } .c-m span { color: #ff8a8a; }
.c-p small { display: block; font-size: 10px; color: #fff3c0; }
.stats-row { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); flex-wrap: wrap; gap: 6px; }
.stats-row b { color: var(--text); }
.histo { grid-column: 1 / -1; width: 100%; height: 70px; }
.res-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.suggest { font-size: 13px; color: var(--muted); grid-column: 1 / -1; }
.suggest button { margin: 6px 0 0 6px; padding: 9px 16px; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.1); font-weight: 700; }

/* ---- sharing, challenges, party relay ------------------------------------------------------------ */
.btn.share { border-color: rgba(255,255,255,0.45); background: linear-gradient(120deg, rgba(79,227,255,0.24), rgba(255,95,210,0.24)); }
.res-challenge { padding: 8px 18px; border-radius: 12px; border: 1px solid rgba(255,216,107,0.45); background: rgba(255,216,107,0.07); color: #fff3c0; font-weight: 800; text-align: center; }
.res-challenge.ok { border-color: rgba(255,216,107,0.85); background: linear-gradient(90deg, rgba(255,216,107,0.22), rgba(255,122,217,0.22)); box-shadow: 0 0 22px rgba(255,201,60,0.3); }
.challenge-line { margin-top: 8px; color: #fff3c0; font-weight: 800; font-size: 14px; }
.online-box .invite { align-self: center; }
.relay-note { margin: 0; padding: 10px 14px; border-radius: 12px; border: 1px solid rgba(79,227,255,0.5); background: rgba(79,227,255,0.08); font-weight: 700; }
.relay { width: min(980px, 100%); display: flex; flex-direction: column; gap: 8px; }
.relay:empty { display: none; }
.relay-head { font-weight: 800; font-size: 15px; text-align: center; }
.relay-guest { margin: 0; text-align: center; }
.relay-games { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 8px; }
.relay-game { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); text-align: left; min-width: 0; }
.relay-game b { font-size: 15px; }
.relay-game small { font-size: 12px; color: var(--muted); }
.relay-game:hover { border-color: rgba(255,255,255,0.5); }
.relay-game:disabled { opacity: 0.5; cursor: default; }
.relay-banner { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 40; width: min(580px, calc(100vw - 24px)); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 14px; padding: 12px 16px; border-radius: 16px; background: rgba(20,14,56,0.97); border: 1px solid rgba(255,255,255,0.35); box-shadow: 0 0 30px rgba(79,227,255,0.3), 0 0 50px rgba(255,95,210,0.2); }
.rb-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 230px; min-width: 0; }
.rb-text span { color: var(--muted); font-size: 13px; }
.rb-act { display: flex; gap: 8px; }
.rb-act .btn { padding: 9px 14px; }

/* ---- settings, calibration, BMS, online --------------------------------------------------------- */
.set-row { display: grid; grid-template-columns: 1fr minmax(160px, 260px) 64px; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-row small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.set-row output { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
/* key bindings */
.keys-set { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.keys-set h3 { margin: 0; font-size: 18px; }
.keys-set p { margin: 0; }
.key-row { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.key-name { font-size: 14px; }
.key-lanes { display: flex; flex-wrap: wrap; gap: 6px; }
.keycap { min-width: 52px; min-height: 40px; padding: 6px 10px; border-radius: 9px; border: 1px solid rgba(255,255,255,0.25); border-bottom-width: 3px; background: rgba(255,255,255,0.07); font-weight: 800; font-size: 14px; }
.key-lanes.p1 .keycap:not(.add) { border-color: rgba(79,227,255,0.6); }
.key-lanes.p2 .keycap:not(.add) { border-color: rgba(255,95,210,0.6); }
.keycap.scratch { border-color: rgba(255,90,110,0.8) !important; }
.keycap.clash { border-color: #ffb07a !important; background: rgba(255,120,60,0.18); }
.keycap.multi i { font-style: normal; margin-left: 6px; color: var(--muted); font-weight: 400; }
.keycap.add { border-style: dashed; color: var(--muted); font-weight: 600; }
.keycap.listening { background: #fff; color: #120c30; border-color: #fff; animation: blink 0.8s ease-in-out infinite alternate; }
@keyframes blink { to { box-shadow: 0 0 18px rgba(255,255,255,0.7); } }
.key-actions { display: flex; gap: 8px; }
@media (max-width: 560px) { .key-row { grid-template-columns: 1fr; gap: 6px; } }
.calib { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.calib > * { flex-shrink: 0; }
.calib-pad { width: 220px; height: 220px; border-radius: 50%; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; position: relative; background: var(--glass); cursor: pointer; }
#calib-dot { position: absolute; inset: 30%; border-radius: 50%; background: radial-gradient(circle, #fff, var(--p1) 40%, transparent 70%); opacity: 0; }
#calib-count { font-family: var(--display); font-size: 44px; position: relative; }
.bms-drop { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 16px; border-radius: 14px; border: 2px dashed var(--line); margin: 10px 0 16px; }
.bms-drop.over { border-color: var(--p1); background: rgba(79,227,255,0.08); }
.bms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.bms-card { padding: 12px 14px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.bms-card b { font-size: 16px; }
.bms-card .muted { font-size: 12.5px; line-height: 1.45; }
.bms-card .state { font-size: 11px; font-weight: 800; }
.bms-card .state.ok { color: #4dffae; } .bms-card .state.no { color: #ffb07a; }
#track-status:empty { display: none; }
.track-bar { flex: 1 0 100%; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.08); overflow: hidden; }
.track-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--p1), var(--p2)); transition: width 0.2s; }
.track-bar[hidden] { display: none; }
.bpm-fix { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 4px; }
.bpm-fix[hidden] { display: none; }
.bpm-fix label { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; }
.bpm-fix input { width: 92px; font: inherit; color: var(--text); background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.bpm-fix .btn { padding: 6px 12px; font-size: 13px; }
.bpm-fix small { flex: 1 0 100%; font-size: 12px; line-height: 1.45; }
.import-sep { margin-top: 28px; }
.online-box { display: flex; flex-direction: column; gap: 14px; max-width: 560px; margin: 0 auto; }
.online-box input { font: inherit; color: var(--text); background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.code-big { font-family: var(--display); font-size: 44px; letter-spacing: 0.18em; text-align: center; text-shadow: 0 0 20px var(--p1g); }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1 1 0; min-width: 0; width: 0; text-transform: uppercase; letter-spacing: 0.2em; }
.join-row .btn { flex: none; white-space: nowrap; }
.room-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.room-ctl { display: flex; flex-direction: column; gap: 8px; }
.room-act { display: flex; gap: 10px; margin-top: 4px; }
.room-act .btn.primary { flex: 1; }
.room-songs .song:disabled { opacity: 1; cursor: default; }
.online-box.room .code-big { font-size: 36px; }
@media (max-height: 540px) and (orientation: landscape) and (min-width: 600px) {
  .online-box.room { max-width: 920px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 18px; align-items: start; }
  .online-box.room > :not(.room-side) { grid-column: 2; }
  .online-box.room .room-side { grid-row: 1 / span 4; }
  .online-box.room .seats { grid-template-columns: 1fr 1fr; }
  .online-box.room .code-big { font-size: 28px; }
}

@media (max-width: 599px), (max-width: 760px) and (orientation: portrait) {
  /* One column that scrolls as a whole; the start bar is pinned to the bottom of the screen. */
  .select-body { display: block; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(92px + env(safe-area-inset-bottom)); scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .song-list { overflow: visible; padding: 0; margin-bottom: 16px; min-height: auto; gap: 8px; }
  .song { padding: 10px 13px; }
  #song-list .bms-slot, #song-list .song-sep { display: none; }
  .bms-more { display: block; text-align: left; padding: 10px 13px; border-radius: 12px; border: 1px dashed var(--line); background: transparent; color: var(--muted); font-size: 13px; }
  .setup { overflow: visible; min-height: auto; scroll-margin-top: 8px; }
  .setup .actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; margin: 0; border-radius: 0; padding: 10px max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); background: rgba(10,8,32,0.96); border-top: 1px solid var(--line); flex-wrap: nowrap; pointer-events: auto; }
  .setup .actions .btn { padding: 11px 10px; white-space: nowrap; }
  .setup .actions .btn.primary { padding: 13px; font-size: 17px; flex: 1 1 auto; min-width: 96px; }
  .diff-jump { max-width: 42%; font-size: 12.5px; }
}
@media (max-width: 400px) {
  .dj-p { display: none; }
  .dj-dot { display: inline-block; }
  /* Narrow phones: the swap button shrinks to its icon so Start keeps its room. */
  .swap .lbl { display: none; }
  .swap .ico { display: inline; font-size: 18px; }
  .setup .actions { gap: 8px; }
}
@media (max-width: 760px) {
  .rank { font-size: 52px; }
  .seats { grid-template-columns: 1fr; }
  .set-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 54px; }
  .set-row input[type=range] { min-width: 0; width: 100%; }
  #hud { grid-template-columns: 1fr 1fr; padding-right: calc(max(12px, env(safe-area-inset-right)) + 48px); }
  .hud-mid { display: none; }
  .hud-seat { flex-direction: column; gap: 0; }
  .hud-seat.right { align-items: flex-end; }
  .hud-seat .who { font-size: 11px; max-width: 100%; white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.25; }
  .hud-seat.right .who { text-align: right; }
  .hud-seat .score { font-size: 17px; }
}
/* Phones on their side: logo left, menu right, both shrinking to fit the width. */
@media (max-height: 540px) and (orientation: landscape) {
  .title-scroll { padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .title-inner { flex-direction: row; justify-content: center; gap: clamp(14px, 4vw, 40px); }
  .logo { flex: 0 1 auto; }
  .logo-main { font-size: clamp(30px, min(8.5vw, 17vh), 96px); }
  .logo-ko { font-size: clamp(14px, 4.5vh, 22px); }
  .tagline { font-size: 13px; }
  .menu { flex: 0 1 430px; width: auto; gap: 8px; }
  .menu .big { padding: 8px 14px; }
  .menu .big b { font-size: 17px; }
  .menu .big small { font-size: 12px; }
  .menu-row button { padding: 9px 4px; font-size: 13px; }
  .hint { font-size: 11.5px; }
  .corner { top: auto; right: auto; bottom: max(10px, env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); }
  .calib-pad { width: 150px; height: 150px; }
  .bar-top { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 6px; }
  .song { padding: 9px 12px; }
  .song-head { padding: 10px 12px; }
  .song-head h3 { font-size: 18px; }
}
@media (max-height: 540px) and (orientation: landscape) {
  .res-seats { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
  .results { gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .results h2 { margin: 0; font-size: 20px; }
  .res-song { margin-top: -6px; font-size: 13px; }
  .res-team { padding: 6px 16px; gap: 14px; }
  .res-team > div { display: flex; align-items: baseline; gap: 8px; }
  .res-team .big { font-size: 24px; }
  /* calibration: pad on the left, text and buttons on the right */
  .calib { display: grid; grid-template-columns: 150px minmax(0, 340px); justify-content: center; align-content: start; align-items: center; column-gap: 28px; row-gap: 10px; text-align: left; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .calib > p { margin: 0; }
  .calib-pad { grid-column: 1; grid-row: 1 / span 4; }
  .calib > :not(.calib-pad) { grid-column: 2; justify-self: start; }
}
@media (min-width: 600px) and (max-width: 760px) and (max-height: 540px) and (orientation: landscape) {
  .song-head p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden; }
  .seat { gap: 6px; padding: 10px 12px; }
  .seat .inst { font-size: 16px; }
  .setup .actions .btn { padding: 9px 10px; white-space: nowrap; }
  .setup .actions .btn.primary { padding: 10px; font-size: 16px; }
  .swap .lbl { display: none; }
  .swap .ico { display: inline; font-size: 18px; }
}
/* Results on phones: the buttons come right after the title, so they're on screen without scrolling. */
@media (max-width: 760px), (max-height: 540px) and (orientation: landscape) {
  .results > h2 { order: -3; }
  .results > .res-song, .results > .res-challenge { order: -2; }
  .results > .res-actions, .results > .relay { order: -1; }
  .res-actions .btn { padding: 9px 14px; }
}
@media (max-width: 340px) {
  .set-row { grid-template-columns: minmax(0, 1fr) 54px; }
  .set-row > div:first-child { grid-column: 1 / -1; }
}
@media (max-height: 380px) and (orientation: landscape) {
  .menu .big small { display: none; }
}
/* 280-300px phones (folded Galaxy Fold): give the difficulty summary room for "Beginner". */
@media (max-width: 300px) {
  .setup .actions { gap: 6px; }
  .setup .actions .btn.primary { min-width: 0; padding: 13px 8px; }
  .diff-jump { max-width: 50%; padding: 6px 8px; gap: 4px; }
}
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch-only { display: block; }
  .key-only { display: none; }
  body.kbd .key-only { display: block; }
}
