:root {
  --cream: #FFF6E8;
  --ink: #2F2440;
  --muted: #5A4A6A;
  --plum: #8A3A6A;
  --pink: #C8588A;
  --line: #F4E4D0;
  --card: rgba(255, 255, 255, 0.96);
  --grad: linear-gradient(100deg, #F59A45 0%, #F28AB3 55%, #9C7BE0 100%);
  --display: 'Fredoka', system-ui, sans-serif;
  --body: 'Karla', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { background: var(--cream); color-scheme: light; }
body {
  margin: 0; min-height: 100dvh; background: var(--cream); color: var(--ink);
  font-family: var(--body); font-weight: 500; font-size: 16px; line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--plum); }
:focus-visible { outline: 3px solid #9C7BE0; outline-offset: 2px; }
.hidden { display: none !important; }

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; position: relative; overflow-x: hidden; container-type: inline-size; padding-bottom: calc(28px + var(--safe-bottom)); }

/* ---------- shared pieces ---------- */
.display { font-family: var(--display); }
.wordmark { font-family: var(--display); font-weight: 700; color: var(--cream); text-shadow: 3px 3px 0 var(--pink); line-height: 0.92; }
.card { background: var(--card); border: 1.5px solid #fff; border-radius: 24px; box-shadow: 0 12px 26px rgba(200, 88, 138, 0.16); }
.pad { padding: 14px 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.mx { margin-left: 20px; margin-right: 20px; }
.h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 21px; }
.sub { color: var(--muted); font-size: 14px; }
.eyebrow { font-weight: 700; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: #B0467A; }

.btn-main {
  width: 100%; min-height: 56px; border: 2px solid rgba(255, 255, 255, 0.75); border-radius: 999px;
  background: var(--grad); color: #fff; text-shadow: 0 1px 2px rgba(122, 40, 90, 0.45);
  box-shadow: 0 10px 22px rgba(242, 138, 179, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.55), inset 0 -4px 0 rgba(110, 40, 100, 0.18);
  font-family: var(--display); font-weight: 600; font-size: 19px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 20px;
}
.btn-main:disabled { filter: grayscale(0.7); opacity: 0.6; box-shadow: none; }
.btn-main:active:not(:disabled) { transform: translateY(1px); }
.btn-soft {
  min-height: 52px; border: 2px solid #fff; border-radius: 999px; background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 18px rgba(180, 120, 160, 0.2), inset 0 -3px 0 #F6E9F0; font-family: var(--display); font-weight: 600; font-size: 17px; padding: 0 20px;
}
.btn-link { background: none; border: 0; padding: 8px; font-weight: 700; color: var(--plum); font-size: 15px; }
.round-btn {
  width: 44px; height: 44px; flex-shrink: 0; border: 2px solid #fff; border-radius: 50%; background: rgba(255, 246, 232, 0.92);
  box-shadow: 0 4px 12px rgba(58, 30, 76, 0.22); display: flex; align-items: center; justify-content: center; padding: 0;
}
.field {
  width: 100%; min-height: 50px; border: 1.5px solid #fff; border-radius: 18px; background: var(--card);
  box-shadow: 0 8px 18px rgba(181, 100, 42, 0.12), inset 0 2px 4px rgba(122, 90, 166, 0.08); padding: 12px 14px; font-size: 16px; color: var(--ink);
}
textarea.field { resize: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 10px; font-weight: 700; font-size: 12px; }
.pill-live { background: #9FE3C8; color: #1F4A3C; }
.pill-soon { background: #F4E4D0; color: #6B4A2A; }
.error { color: #A3264F; font-weight: 700; font-size: 14px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; background: #FFD48A; border: 3px solid var(--cream); box-shadow: 0 0 0 2.5px #B5642A;
  display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 600; font-size: 16px; flex-shrink: 0; color: var(--ink);
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; border-width: 2px; box-shadow: 0 0 0 2px #B5642A; }

/* ---------- banner (top image) ---------- */
.banner { position: relative; overflow: hidden; }
.banner > img.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.banner .top-row { position: absolute; left: 20px; right: 20px; top: calc(18px + var(--safe-top)); display: flex; align-items: center; gap: 12px; }
.banner-title { font-family: var(--display); font-weight: 700; font-size: 24px; color: var(--cream); text-shadow: 2px 2px 0 var(--pink); line-height: 1.05; }
.banner-sub { font-weight: 700; font-size: 13px; color: #3A1E4C; }

/* ---------- home ---------- */
.home-hero { height: calc(320px + var(--safe-top)); }
.home-hero .wordmark { position: absolute; left: 20px; top: calc(34px + var(--safe-top)); font-size: 42px; }
.home-hero .avatar { position: absolute; right: 16px; top: calc(30px + var(--safe-top)); width: 50px; height: 50px; font-size: 17px; }
.welcome { margin: -18px 20px 0; position: relative; }
.welcome .display { font-weight: 600; font-size: 21px; }
.action-grid { margin: 28px 20px 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.action {
  position: relative; height: 170px; border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 26px; padding: 14px;
  display: flex; flex-direction: column; justify-content: flex-end; text-align: left; gap: 2px;
}
.action > img { position: absolute; top: -30px; pointer-events: none; }
.action .t { font-family: var(--display); font-weight: 700; font-size: 21px; line-height: 1; }
.action-start { background: linear-gradient(160deg, #FFE4BC 0%, #FFC69C 50%, #F7A9B9 100%); box-shadow: 0 14px 26px rgba(245, 154, 69, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.75); color: #4A1E10; }
.action-start > img { right: -8px; width: 124px; height: 124px; }
.action-start .s { font-weight: 600; font-size: 13px; color: #7A3A2A; }
.action-start .go { position: absolute; right: 12px; bottom: 12px; width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, 0.8); box-shadow: 0 3px 8px rgba(122, 58, 42, 0.2); display: flex; align-items: center; justify-content: center; }
.action-join { background: linear-gradient(160deg, #DCEEFE 0%, #C9DAFB 45%, #CDB9F2 100%); box-shadow: 0 14px 26px rgba(122, 90, 166, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.75); gap: 8px; }
.action-join > img { right: -6px; width: 112px; height: 112px; }
.join-row { display: flex; gap: 6px; }
.join-row input {
  flex: 1; min-width: 0; height: 44px; border: 2px solid #fff; border-radius: 999px; background: rgba(255, 255, 255, 0.88);
  box-shadow: inset 0 2px 4px rgba(78, 53, 114, 0.14); font-family: var(--display); font-weight: 600; font-size: 18px; letter-spacing: 0.22em; text-align: center; text-transform: uppercase; padding: 0 4px;
}
.join-row input::placeholder { color: #9A8AAE; letter-spacing: 0.22em; }
.join-row button {
  width: 44px; height: 44px; flex-shrink: 0; border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 50%;
  background: linear-gradient(140deg, #9C7BE0, #6B4FA8); box-shadow: 0 6px 12px rgba(107, 79, 168, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.section-head { margin: 24px 20px 0; display: flex; justify-content: space-between; align-items: baseline; }
.modes { margin: 10px 20px 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mode {
  position: relative; border: 1.5px solid #fff; border-radius: 24px; padding: 12px 10px 14px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  background: linear-gradient(180deg, #FFFFFF 0%, var(--tint) 100%); box-shadow: 0 10px 22px var(--shadow);
}
.mode .pill { position: absolute; right: 10px; top: 10px; z-index: 1; }
.mode img { width: 88px; height: 88px; border-radius: 18px; display: block; }
.mode .t { font-family: var(--display); font-weight: 600; font-size: 17px; line-height: 1.1; margin-top: 4px; }
.mode .s { font-size: 13px; color: var(--muted); }
.mode.soon img { filter: saturate(0.75); opacity: 0.85; }
.rooms-list { margin: 10px 20px 0; }
.room-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; width: 100%; background: none; border: 0; text-align: left; border-bottom: 2px solid var(--line); }
.room-row:last-child { border-bottom: 0; }
.room-row .tile { width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,0.2); }

/* ---------- name sheet ---------- */
.sheet-wrap { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vv-height, 100dvh); background: rgba(47, 36, 64, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { width: 100%; max-width: 480px; background: var(--cream); border-radius: 28px 28px 0 0; padding: 22px 20px calc(22px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 12px; }

/* ---------- lobby ---------- */
.lobby-banner { height: calc(170px + var(--safe-top)); }
.code-card { margin: -46px 20px 0; position: relative; display: flex; align-items: center; gap: 14px; }
.code-big { font-family: var(--display); font-weight: 700; font-size: 38px; letter-spacing: 0.16em; color: var(--ink); line-height: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1.5px solid #fff; border-radius: 999px; padding: 4px 12px 4px 4px; box-shadow: 0 6px 14px rgba(122, 90, 166, 0.14); font-weight: 700; font-size: 14px; }
.chip .count { color: var(--muted); font-weight: 600; }
.chip.away { opacity: 0.55; box-shadow: none; border-style: dashed; border-color: #C9BBD6; }
.away-tag { font-size: 11px; background: #EEE7F5; color: var(--muted); border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.chip-x { border: 0; background: #F3EDF8; color: #8A3A6A; width: 26px; height: 26px; border-radius: 50%; font-size: 12px; font-weight: 800; margin-right: -6px; cursor: pointer; }
.chip.away .chip-x { opacity: 1; }
.host-tag { font-size: 11px; background: #FFE7B8; color: #8A4A1A; border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.preview { display: flex; gap: 12px; align-items: center; }
.preview img { width: 96px; height: 54px; object-fit: cover; border-radius: 10px; flex-shrink: 0; background: #3A2E4E; }
.my-song { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 2px solid var(--line); }
.my-song:last-child { border-bottom: 0; }
.my-song img { width: 64px; height: 36px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.my-song .title { flex: 1; min-width: 0; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.x-btn { width: 36px; height: 36px; border: 0; background: #FCE3EB; border-radius: 50%; color: #8A2A5A; font-weight: 700; flex-shrink: 0; }
.mystery { background: #EDE4FA; border: 2px solid #7A5AA6; border-radius: 16px; padding: 10px 14px; color: #4E3572; font-weight: 600; font-size: 14px; }

/* ---------- play ---------- */
.play-banner { height: calc(150px + var(--safe-top)); }
.sync-pill { background: rgba(255, 255, 255, 0.92); border: 1.5px solid #fff; box-shadow: 0 4px 10px rgba(62, 140, 116, 0.25); border-radius: 999px; padding: 4px 10px; font-weight: 700; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.sync-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #3E8C74; }
.sync-pill.off .dot { background: #E0913A; }
.sync-pill.idle .dot { background: #A99BB8; }
.player-card { margin: -40px 20px 0; position: relative; padding: 12px; display: flex; flex-direction: column; gap: 10px; border-radius: 26px; }
.player-box { position: relative; aspect-ratio: 16 / 9; border-radius: 16px; overflow: hidden; background: #3A2E4E; }
.player-box iframe, .player-box > div { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 16px; background: rgba(58, 46, 78, 0.88); color: #F3ECFB; z-index: 2; }
.overlay .count { font-family: var(--display); font-weight: 700; font-size: 64px; line-height: 1; color: #FFD48A; }
.song-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.song-title { font-family: var(--display); font-weight: 600; font-size: 18px; line-height: 1.15; }
.badge { background: #EDE4FA; border: 2px solid #7A5AA6; border-radius: 12px; padding: 5px 10px; font-weight: 700; font-size: 12px; color: #4E3572; text-align: center; line-height: 1.2; flex-shrink: 0; }
.transport { display: flex; justify-content: center; align-items: center; gap: 10px; }
.transport button { border: 0; background: none; padding: 0; transition: transform 0.12s; }
.transport button:active:not(:disabled) { transform: scale(0.94); }
.transport button:disabled { opacity: 0.45; filter: grayscale(0.6); }
.transport img { display: block; width: 100%; height: 100%; }
.t-sm { width: 62px; height: 62px; filter: drop-shadow(0 8px 10px rgba(62, 140, 116, 0.3)); }
.t-lg { width: 92px; height: 92px; filter: drop-shadow(0 8px 10px rgba(200, 88, 138, 0.42)); }
.t-lg.pulse { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.tap-hint { text-align: center; font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--pink); margin-top: -6px; min-height: 20px; }

.score-card { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 14px 30px rgba(242, 138, 179, 0.2); border-radius: 26px; }
.score-num { font-family: var(--display); font-weight: 700; font-size: 34px; color: var(--pink); line-height: 1; }
.score-num.unset { color: #C9BBD6; }
.slider { position: relative; height: 50px; touch-action: none; }
.slider .track { position: absolute; left: 0; right: 0; top: 18px; height: 14px; border-radius: 999px; background: linear-gradient(90deg, #9CCBF5, #C9B6F0 40%, #F7A9B9 70%, #FFD48A); box-shadow: inset 0 2px 4px rgba(58, 30, 76, 0.18), 0 1px 0 #fff; }
.slider input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.slider .knob { position: absolute; top: 0; width: 50px; height: 50px; margin-left: -25px; pointer-events: none; filter: drop-shadow(0 5px 6px rgba(58, 30, 76, 0.35)); transition: left 0.05s; }
.slider .knob img { width: 100%; height: 100%; display: block; }
.slider .knob.unset { visibility: hidden; }
.score-hint { text-align: center; font-weight: 700; font-size: 13px; color: #8A3A6A; }
.all-notes { padding: 4px 16px; }
.all-notes summary { cursor: pointer; font-weight: 600; font-size: 18px; padding: 12px 0; list-style-position: inside; }
.an-song { border-top: 2px solid var(--line); padding: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.an-head { display: flex; align-items: center; gap: 10px; }
.an-pos { width: 26px; height: 26px; border-radius: 50%; background: #FFD48A; display: grid; place-items: center; font-weight: 800; font-size: 13px; flex-shrink: 0; }
.an-title { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.an-title span { font-size: 12px; color: var(--muted); }
.an-row { display: flex; gap: 10px; align-items: flex-start; padding-left: 36px; }
.an-who { display: flex; flex-direction: column; font-size: 14px; }
.an-who span { color: var(--muted); font-size: 13px; }
.picked { background: #FFF6E8; border: 2px solid #F59A45; border-radius: 18px; padding: 12px; animation: picked-in 0.35s ease-out; }
@keyframes picked-in { from { transform: scale(0.96); opacity: 0.4; } to { transform: none; opacity: 1; } }
.auto-next { text-align: center; color: var(--muted); font-weight: 600; font-size: 14px; }
.auto-next .btn-link { padding: 0 4px; font-size: 14px; }
.tie-note { font-size: 13px; font-weight: 600; color: #8A3A6A; margin-top: 4px; }
.slider input:focus-visible ~ .knob { outline: 3px solid #9C7BE0; border-radius: 50%; }
.scale-labels { display: flex; justify-content: space-between; font-weight: 700; font-size: 12px; color: var(--muted); }
.lock-row { display: flex; align-items: center; gap: 12px; }
.rated { text-align: center; font-weight: 700; font-size: 12px; color: var(--muted); line-height: 1.1; flex-shrink: 0; }
.rated b { font-family: var(--display); font-size: 22px; color: var(--ink); }
.locked { background: #DDF3E6; border: 2px solid #5DA27E; border-radius: 18px; padding: 10px 14px; color: #2E6B45; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.host-bar { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }

/* ---------- reveal + final ---------- */
.results-banner { height: calc(250px + var(--safe-top)); }
.results-banner .center { position: absolute; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-top)); text-align: center; width: max-content; max-width: calc(100% - 40px);
  padding: 10px 22px 14px; border-radius: 22px; background: rgba(58, 30, 76, 0.55); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border: 1.5px solid rgba(255, 255, 255, 0.35); box-shadow: 0 10px 24px rgba(58, 30, 76, 0.25); }
.results-banner .big { font-family: var(--display); font-weight: 700; font-size: 38px; line-height: 1; color: var(--cream); text-shadow: 2px 2px 0 var(--pink); overflow-wrap: anywhere; }
.results-banner .eye { font-weight: 700; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: #FFE7B8; margin-bottom: 4px; }
.winner { margin: -22px 20px 0; position: relative; display: flex; align-items: center; gap: 12px; box-shadow: 0 16px 32px rgba(200, 88, 138, 0.28); border-radius: 26px; }
.score-ball { width: 66px; height: 66px; flex-shrink: 0; border-radius: 50%; background: linear-gradient(140deg, #FFB27A, #F28AB3 60%, #C88AE6); border: 2px solid #fff; box-shadow: 0 8px 16px rgba(200, 88, 138, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.5); display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; font-size: 24px; color: #3A1028; }
.rank-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 2px solid var(--line); }
.rank-row:last-child { border-bottom: 0; }
.rank { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; font-size: 15px; flex-shrink: 0; }
.rank-row .name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rank-row .name b { font-size: 15px; overflow-wrap: anywhere; }
.rank-row .name span { font-size: 12px; color: var(--muted); }
.rank-row .val { font-family: var(--display); font-weight: 600; font-size: 18px; }
.bubble { max-width: 300px; border-radius: 20px; padding: 10px 14px; border: 2px solid; }
.bubble .who { font-weight: 700; font-size: 12px; }
.bubble .what { font-size: 15px; overflow-wrap: anywhere; }
.bubble.l { align-self: flex-start; border-radius: 20px 20px 20px 6px; }
.bubble.r { align-self: flex-end; border-radius: 20px 20px 6px 20px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.facts .fact:last-child:nth-child(odd) { grid-column: 1 / -1; }
.fact { border-radius: 18px; padding: 10px 12px; border: 2px solid; }
.fact .k { font-weight: 700; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }
.fact .v { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.btn-row { display: flex; gap: 12px; }
.btn-row .btn-main { flex: 1; width: auto; }

.toast { position: fixed; left: 50%; top: calc(16px + var(--safe-top)); transform: translateX(-50%); background: var(--ink); color: var(--cream); padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 14px; z-index: 30; max-width: calc(100% - 32px); text-align: center; }
.waiting { text-align: center; color: var(--muted); font-weight: 600; font-size: 15px; }
.center-msg { padding: 80px 24px; text-align: center; }

/* ---------- song search ---------- */
.search-row { display: flex; gap: 8px; align-items: center; }
.search-row .field { flex: 1; min-width: 0; }
.search-row input[type=search]::-webkit-search-decoration { -webkit-appearance: none; }
.search-btn {
  width: 50px; height: 50px; flex-shrink: 0; border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 50%;
  background: linear-gradient(140deg, #F59A45, #F28AB3 60%, #9C7BE0); box-shadow: 0 6px 12px rgba(200, 88, 138, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.results { display: flex; flex-direction: column; gap: 8px; }
.result { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: #fff; border: 1.5px solid var(--line); border-radius: 16px; padding: 8px; }
.result:active:not(:disabled) { background: #FFF1F4; }
.result:disabled { opacity: 0.5; }
.result img { width: 96px; height: 54px; object-fit: cover; border-radius: 10px; flex-shrink: 0; background: #3A2E4E; }
.result .txt { display: flex; flex-direction: column; min-width: 0; }
.result .t { font-weight: 700; font-size: 14px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.result .c { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- one-speaker mode ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #F4E4D0; border-radius: 999px; padding: 4px; }
.seg button { min-height: 44px; border: 0; border-radius: 999px; background: transparent; font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--muted); }
.seg button[aria-checked="true"] { background: #fff; color: var(--ink); box-shadow: 0 4px 10px rgba(181, 100, 42, 0.18); }
.speaker-box { display: flex; align-items: center; gap: 14px; border-radius: 16px; padding: 18px 16px; background: linear-gradient(135deg, #FFE4BC, #F7A9B9 60%, #CDB9F2); }
.speaker-icon { width: 64px; height: 64px; flex-shrink: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.85); display: flex; align-items: center; justify-content: center; font-size: 32px; animation: pulse 1.4s ease-in-out infinite; }

/* ---------- TV / big screen ---------- */
.overlay { cursor: pointer; }
body.tv #app { max-width: 620px; zoom: 1.5; }
body.tv.tv-play-on #app { max-width: none; zoom: 1; padding-bottom: 0; }
.tv-play { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(0, 1fr); gap: 40px; align-items: center; min-height: 100vh; padding: 48px 56px; box-sizing: border-box;
  background: linear-gradient(180deg, rgba(255, 246, 232, 0) 0%, var(--cream) 60%), url(/img/rate-banner.webp) top center / 100% auto no-repeat, var(--cream); }
.tv-play .player-box { border-radius: 28px; box-shadow: 0 24px 60px rgba(122, 90, 166, 0.35); border: 4px solid #fff; }
.tv-play .overlay .count { font-size: 120px; }
.tv-play .overlay div { font-size: 22px; }
.tv-right { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.tv-title { font-family: var(--display); font-weight: 700; font-size: clamp(28px, 3.4vw, 56px); line-height: 1.05; overflow-wrap: anywhere; }
.tv-raters { display: flex; flex-wrap: wrap; gap: 10px; }
.tv-rater { display: inline-flex; align-items: center; gap: 8px; background: #fff; border-radius: 999px; padding: 6px 16px 6px 6px; font-weight: 700; font-size: 18px; box-shadow: 0 6px 14px rgba(122, 90, 166, 0.14); opacity: 0.6; }
.tv-rater.done { background: #DDF3E6; opacity: 1; }
.tv-hint { font-size: 18px; color: var(--muted); }
.tv-join-panel { display: flex; gap: 18px; align-items: center; }
.qr { width: 150px; height: 150px; flex-shrink: 0; background: #fff; border-radius: 14px; padding: 6px; box-sizing: border-box; }
.qr svg { width: 100%; height: 100%; display: block; }

/* ---------- rooms ---------- */
.rename { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rename .pen { font-size: 0.7em; opacity: 0.85; }
.room-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout wrappers (stack on phones, columns on wide screens) ---------- */
.lobby-grid { display: flex; flex-direction: column; gap: 14px; }
.play-grid { display: flex; flex-direction: column; }
.play-grid .col-b { margin-top: 14px; gap: 14px; }

@media (min-width: 900px) {
  #app { max-width: 1120px; }
}
@container (min-width: 860px) {
  .mx { margin-left: 40px; margin-right: 40px; }
  .home-hero { height: 400px; }
  .home-hero .wordmark { left: 48px; top: 56px; font-size: 72px; }
  .home-hero .avatar { right: 40px; top: 48px; }
  .welcome { margin: -40px 40px 0; padding: 20px 28px; }
  .welcome .display { font-size: 28px; }
  .action-grid { margin: 40px 40px 0; gap: 20px; }
  .action { height: 200px; padding: 22px; }
  .action .t { font-size: 28px; }
  .action-start > img { width: 150px; height: 150px; top: -40px; }
  .action-join > img { width: 136px; height: 136px; top: -40px; }
  .join-row { max-width: 360px; }
  .section-head { margin: 36px 40px 0; }
  .modes { margin: 12px 40px 0; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
  .rooms-list { margin: 12px 40px 0; }

  .lobby-banner { height: 240px; }
  .play-banner { height: 200px; }
  .banner .top-row { left: 40px; right: 40px; top: 28px; }
  .banner-title { font-size: 34px; }
  .code-card { margin: -60px 40px 0; padding: 18px 24px; }
  .code-big { font-size: 48px; }
  .lobby-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; align-items: start; }
  .lobby-grid .col-a, .lobby-grid .col-b { gap: 18px; }

  .play-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 28px; align-items: start; margin: 0 40px; }
  .play-grid .player-card { margin: -64px 0 0; padding: 16px; }
  .play-grid .song-title { font-size: 24px; }
  .play-grid .col-b { margin-top: 24px; }
  .play-grid .col-b .mx { margin-left: 0; margin-right: 0; }
  .speaker-box { padding: 32px 24px; }

  .results-banner { height: 320px !important; }
  .narrow { max-width: 760px; margin: 0 auto; }
  .narrow .mx { margin-left: 20px; margin-right: 20px; }
  .results-banner .big { font-size: 56px; }
  .results-banner .center { top: 80px; padding: 14px 32px 18px; }
}
.results-banner > img.bg { object-position: center 85%; }

/* ---------- avatars ---------- */
.avatar.pic { padding: 0; overflow: hidden; background: #FFD48A; }
.avatar.pic img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }
.av-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.av-opt { aspect-ratio: 1; border: 3px solid transparent; border-radius: 50%; padding: 0; background: none; overflow: hidden; transition: transform 0.12s; }
.av-opt img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }
.av-opt[aria-checked="true"] { border-color: var(--pink); transform: scale(1.08); box-shadow: 0 6px 14px rgba(200, 88, 138, 0.35); }
.home-hero .avatar.pic { width: 58px; height: 58px; }

/* ---------- play on TV via YouTube ---------- */
a.btn-main, a.btn-soft { text-decoration: none; display: flex; align-items: center; justify-content: center; }
.yt-tv-link { margin: 4px 20px 0; color: var(--ink); }
.speaker-box.yt-tv { align-items: flex-start; }
.speaker-box.yt-tv .btn-main { min-height: 50px; font-size: 17px; }

/* room rules + host handover (v18) */
.seg.seg-n { grid-template-columns: repeat(5, 1fr); }
.seg.seg-3 { grid-template-columns: repeat(3, 1fr); }
.rule-label { font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--ink); }
.rules-read { display: flex; flex-wrap: wrap; gap: 8px; }
.rules-read span { background: #FFF1DD; border: 1.5px solid #F4D2A6; border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 14px; color: #8A4A1A; }
.rules-read b { font-family: var(--display); }
#add-form.is-full #search-row { display: none; }
button.chip { font: inherit; font-weight: 700; color: inherit; cursor: pointer; }
button.chip:active { transform: scale(0.97); }
.chip-more { color: var(--plum); font-weight: 800; margin-left: -2px; }
.seat-count { align-self: center; font-size: 13px; font-weight: 700; color: var(--muted); padding: 0 4px; }
.host-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: #FFF6E8; border: 1.5px dashed #F4C58A; border-radius: 16px; padding: 6px 8px 6px 14px; font-weight: 600; font-size: 14px; color: #8A4A1A; margin-top: 12px; }
.host-bar.away { background: #FCE3EB; border-color: #E48AA9; color: #8A2A5A; padding: 10px 10px 10px 14px; }
.host-bar.away .btn-soft { min-height: 40px; padding: 0 14px; }
.host-pick { display: flex; align-items: center; gap: 10px; justify-content: flex-start; text-align: left; width: 100%; }
.btn-link.danger { color: #B0343A; }
/* time's up and you still owe a score (v19) */
#rate-area.nudge .score-card { box-shadow: 0 0 0 3px #F28AB3, 0 14px 30px rgba(242, 138, 179, 0.35); animation: nudge 0.9s ease-in-out 3; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@media (prefers-reduced-motion: reduce) { #rate-area.nudge .score-card { animation: none; } }
#reveal-now.confirm { background: #FCE3EB; border-color: #E48AA9; color: #8A2A5A; }
/* v20: privacy, reveal timing, round results, room history */
.sheet { max-height: calc(var(--vv-height, 100dvh) - 24px); overflow-y: auto; }
.rule-hint { font-size: 13px; color: var(--muted); }
.avatar.anon { background: #EDE4FA; color: #7A5AA6; font-size: 15px; box-shadow: 0 0 0 2px #B49CF0; }
.anon-name { color: var(--muted); }
.winner.small { margin: 0 20px; box-shadow: 0 10px 22px rgba(200, 88, 138, 0.2); }
.stack > .winner.small:first-child { margin-top: -22px; }
.score-ball.sm { width: 54px; height: 54px; font-size: 20px; }
.banner-title.plain { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: none; border: 0; padding: 0; text-align: left; cursor: default; font: inherit; font-family: var(--display); font-weight: 700; font-size: 24px; color: var(--cream); }

/* ---------- intro (before every song) ---------- */
.intro { margin-top: -22px; position: relative; padding: 0 20px; gap: 14px; }
.intro-card { display: flex; flex-direction: column; gap: 10px; }
.intro-who { display: flex; gap: 14px; align-items: center; }
.intro-title { font-weight: 700; font-size: 22px; line-height: 1.1; overflow-wrap: anywhere; }
.intro-sub { font-size: 15px; margin-top: 4px; }
.avatar.lg { width: 64px; height: 64px; font-size: 26px; border-width: 3px; }
.just-played { text-align: center; }
.talk-card { display: flex; gap: 12px; align-items: center; background: linear-gradient(160deg, #FFFFFF 0%, #EDE4FA 100%); }
.talk-card .btn-soft { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; color: #4E3572; }

/* ---------- dock: voice + chat ---------- */
body.has-dock #app { padding-bottom: calc(96px + var(--safe-bottom)); }
.dock {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-bottom)); z-index: 15;
  width: min(460px, calc(100% - 24px)); display: flex; gap: 8px; align-items: center; justify-content: flex-end; pointer-events: none;
}
.dock > * { pointer-events: auto; }
.dock-voice {
  flex: 1; min-width: 0; min-height: 52px; display: flex; align-items: center; gap: 6px; border: 2px solid #fff; border-radius: 999px;
  background: rgba(255, 255, 255, 0.96); box-shadow: 0 8px 20px rgba(122, 90, 166, 0.25); padding: 4px 6px 4px 4px; font-weight: 700; font-size: 14px; color: var(--ink);
}
button.dock-voice.join { justify-content: center; gap: 8px; font-family: var(--display); font-weight: 600; font-size: 17px; color: #4E3572; padding: 0 18px; }
.dock-mic { display: flex; align-items: center; gap: 6px; min-height: 42px; border: 0; border-radius: 999px; padding: 0 12px; font-weight: 700; font-size: 14px; background: #F4E4D0; color: var(--ink); white-space: nowrap; flex-shrink: 0; }
.dock-voice.on .dock-mic { background: #9FE3C8; color: #1F4A3C; }
.dock-voice.muted .dock-mic { background: #FCE3EB; color: #8A2A5A; }
.dock-voice.locked .dock-mic { background: #EDE4FA; color: #4E3572; }
.dock-voice.warn .dock-mic { background: #FFD48A; color: #6B4A2A; }
.dock-mic:disabled { cursor: default; }
.dock-peers { display: flex; align-items: center; flex: 1; min-width: 0; overflow: hidden; padding-left: 2px; }
.dock-peer { position: relative; margin-left: -6px; flex-shrink: 0; }
.dock-peer:first-child { margin-left: 0; }
.dock-peer .avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.dock-peer.connecting, .dock-peer.trouble { opacity: 0.45; }
.dock-peer.trouble .avatar { box-shadow: 0 0 0 2px #C8384A; }
.dock-peer.mic::after { content: ''; position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; background: #3FBF83; border: 2px solid #fff; }
.dock-alone { color: var(--muted); font-weight: 600; font-size: 13px; padding-left: 4px; white-space: nowrap; }
.dock-x { width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 14px; flex-shrink: 0; padding: 0; }
.dock-chat {
  position: relative; width: 52px; height: 52px; flex-shrink: 0; border: 2px solid #fff; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--grad); box-shadow: 0 8px 20px rgba(242, 138, 179, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.5);
}
.dock-chat.on { filter: saturate(0.6); }
.badge-n { position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; border-radius: 999px; background: #C8384A; color: #fff; border: 2px solid #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 5px; font-family: var(--body); }
.chat-peek {
  position: fixed; z-index: 16; right: max(12px, calc(50% - 230px)); bottom: calc(74px + var(--safe-bottom)); max-width: min(320px, calc(100% - 24px));
  background: var(--ink); color: var(--cream); border: 0; border-radius: 18px 18px 4px 18px; padding: 10px 14px; text-align: left; font-size: 14px; font-weight: 500;
  box-shadow: 0 10px 22px rgba(47, 36, 64, 0.3); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.chat-peek b { color: #FFD48A; margin-right: 4px; }

/* the panel's bottom edge follows the visible area, so the keyboard never covers the input */
.chat-panel {
  position: fixed; z-index: 18; left: 50%; top: calc(var(--vv-top, 0px) + var(--vv-height, 100dvh)); transform: translate(-50%, -100%);
  width: min(480px, 100%); height: min(70dvh, calc(var(--vv-height, 100dvh) - 24px)); display: flex; flex-direction: column;
  background: var(--cream); border: 2px solid #fff; border-bottom: 0; border-radius: 26px 26px 0 0; box-shadow: 0 -12px 30px rgba(47, 36, 64, 0.22);
  padding-bottom: var(--safe-bottom);
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px 20px; }
.chat-close { width: 38px; height: 38px; font-size: 15px; }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 14px 10px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.chat-empty { text-align: center; margin: auto 0; }
.chat-line { display: flex; gap: 8px; align-items: flex-end; max-width: 86%; }
.chat-line.mine { align-self: flex-end; }
.chat-bubble { background: #fff; border-radius: 18px 18px 18px 4px; padding: 7px 12px; box-shadow: 0 3px 8px rgba(180, 120, 160, 0.14); min-width: 0; }
.chat-line.mine .chat-bubble { background: #EDE4FA; border-radius: 18px 18px 4px 18px; }
.chat-who { font-weight: 700; font-size: 12px; color: #B0467A; }
.chat-body { overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-form { display: flex; gap: 8px; padding: 8px 12px 12px; }
.chat-form .field { min-height: 48px; border-radius: 999px; }
.chat-form .search-btn { width: 48px; height: 48px; }

/* ---------- feedback ---------- */
.dock-fb {
  width: 44px; height: 44px; flex-shrink: 0; border: 2px solid #fff; border-radius: 50%; padding: 0; color: #4E3572;
  background: rgba(255, 255, 255, 0.96); box-shadow: 0 8px 20px rgba(122, 90, 166, 0.25); display: flex; align-items: center; justify-content: center;
}
.fb-rate { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.fb-rate button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 72px; border: 2px solid #fff; border-radius: 18px;
  background: rgba(255, 255, 255, 0.92); box-shadow: 0 6px 14px rgba(180, 120, 160, 0.16); font-weight: 700; font-size: 13px; color: var(--muted); padding: 8px 4px;
}
.fb-rate .e { font-size: 28px; line-height: 1.1; }
.fb-rate button[aria-checked="true"] { background: #EDE4FA; border-color: #9C7BE0; color: #4E3572; }
.game-fb { display: flex; flex-direction: column; gap: 10px; background: linear-gradient(160deg, #FFFFFF 0%, #FFE7B8 100%); }
.game-fb.done { flex-direction: row; align-items: center; justify-content: space-between; font-weight: 700; }

/* ---------- take the songs with you ---------- */
.take-songs { display: flex; flex-direction: column; gap: 8px; }
.take-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 4px; }
.take-row .btn-soft { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--ink); flex: 1 1 220px; }

/* ---------- the shared YouTube player (floats over .player-box or the intro's ready box) ---------- */
.yt-stage { position: absolute; z-index: 4; border-radius: 16px; overflow: hidden; background: #3A2E4E; }
.yt-stage.tv { border-radius: 28px; }
.yt-stage.off { left: -10000px !important; top: 0 !important; width: 320px !important; height: 180px !important; }
.yt-stage #yt-frame, .yt-stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.yt-stage.blur iframe { filter: blur(16px) saturate(1.3); transform: scale(1.08); }
.yt-stage.tv .overlay .count { font-size: 120px; }
.yt-stage.tv .overlay div { font-size: 22px; }
.ready-card { display: flex; flex-direction: column; gap: 8px; background: linear-gradient(160deg, #FFFFFF 0%, #DCEEFE 100%); }
.ready-box { position: relative; aspect-ratio: 16 / 9; border-radius: 16px; background: #3A2E4E; display: flex; align-items: center; justify-content: center; }
.ready-box .sub { color: #F3ECFB; }
.ready-done { font-weight: 700; color: #1F4A3C; }
.ready-ask { font-weight: 800; font-size: 20px; color: #3A1E4C; display: flex; align-items: center; gap: 8px; }
.ready-arrow { display: inline-block; font-size: 26px; animation: ready-bob 1s ease-in-out infinite; }
@keyframes ready-bob { 0%, 100% { transform: translateY(-3px); } 50% { transform: translateY(5px); } }
.tap-badge { display: none; position: absolute; inset: 0; z-index: 2; pointer-events: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: #fff; font-size: 20px; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }
.yt-stage.blur .tap-badge { display: flex; }
.tap-ring { width: 84px; height: 84px; border-radius: 50%; background: linear-gradient(135deg, #FF8A3D, #E0457B 55%, #9B6BDF); display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7); animation: tap-pulse 1.4s ease-out infinite; }
.tap-play { font-size: 34px; margin-left: 6px; }
@keyframes tap-pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.75); transform: scale(1); } 60% { box-shadow: 0 0 0 26px rgba(255, 255, 255, 0); transform: scale(1.06); } 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); transform: scale(1); } }
.ready-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; font-weight: 600; font-size: 14px; color: var(--muted); }
.ready-list:empty { display: none; }
.rl-p { background: #F4E4D0; border-radius: 999px; padding: 3px 10px; }
.rl-p.ok { background: #9FE3C8; color: #1F4A3C; }
.tap-hint.loud { font-family: var(--display); font-weight: 700; font-size: 20px; color: #B0467A; animation: pulse-hint 1.2s ease-in-out infinite; }
@keyframes pulse-hint { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .tap-hint.loud, .tap-ring, .ready-arrow { animation: none; } }
