:root {
  --bg: #07070f;
  --panel: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.09);
  --text: #ffffff;
  --dim: rgba(255, 255, 255, 0.56);
  --faint: rgba(255, 255, 255, 0.34);
  --pink: #ff4fa3;
  --violet: #6d28d9;
  --lime: #b7ff5a;
  --radius: 22px;
  --font: 'Inter', 'Noto Sans KR', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* Everything is laid out on a 1920x1080 stage and scaled to fit the screen,
   so a 720p Chromecast, a 4K TV and a laptop window all show the same picture. */
#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overflow: clip; /* a focused button must not scroll the scaled stage */
  background: var(--bg);
}

#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1920px;
  height: 1080px;
  margin: -540px 0 0 -960px;
  overflow: hidden;
  overflow: clip;
  transform-origin: center center;
  background: var(--bg);
}

.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.32;
  pointer-events: none;
}
.glow-a { width: 900px; height: 900px; left: -260px; top: -320px; background: var(--violet); }
.glow-b { width: 760px; height: 760px; right: -220px; bottom: -300px; background: var(--pink); opacity: 0.2; }

.eyebrow {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

/* Top bar */
.top {
  position: absolute;
  left: 72px;
  right: 72px;
  top: 48px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 2;
}
.brand { display: flex; align-items: center; gap: 18px; font-size: 32px; font-weight: 800; letter-spacing: -0.01em; }
.brand svg { width: 56px; height: 56px; }
.room {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 24px;
}
.room-label { color: var(--faint); font-weight: 700; }
.room-code { font-weight: 800; letter-spacing: 0.18em; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); }
.dot.on { background: var(--lime); box-shadow: 0 0 12px var(--lime); }

/* Screens */
.screen { position: absolute; inset: 0; display: none; }
#stage[data-screen='idle'] .idle,
#stage[data-screen='intro'] .intro,
#stage[data-screen='waiting'] .waiting,
#stage[data-screen='play'] .play { display: block; }
#stage[data-screen='idle'] .idle,
#stage[data-screen='intro'] .intro,
#stage[data-screen='waiting'] .waiting { display: flex; }

/* Idle */
.idle {
  align-items: center;
  justify-content: center;
  gap: 160px;
}
.idle-code { display: flex; flex-direction: column; gap: 28px; }
.code {
  font-size: 260px;
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: 0.08em;
  background: linear-gradient(120deg, #fff 20%, #ffb6d5 60%, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.idle-join { display: flex; flex-direction: column; align-items: center; gap: 24px; }
.guests { display: flex; gap: 16px; min-height: 64px; flex-wrap: wrap; max-width: 760px; }
.guests span {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px 10px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  font-size: 28px;
  font-weight: 800;
  animation: slidein 0.4s ease-out;
}
.guests span i { width: 40px; height: 40px; border-radius: 50%; background: var(--c); }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } }
.qr {
  width: 300px;
  height: 300px;
  padding: 20px;
  border-radius: var(--radius);
  background: #fff;
}
.qr.small { width: 132px; height: 132px; padding: 10px; border-radius: 14px; flex: none; }
.qr svg { width: 100%; height: 100%; display: block; }

/* Intro + waiting */
.intro, .waiting {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
  padding: 0 160px;
}
.intro-title { font-size: 104px; line-height: 1.02; font-weight: 900; letter-spacing: -0.02em; }
.intro-title.small { font-size: 64px; }
.intro-artist { font-size: 40px; color: var(--dim); font-weight: 600; }
.intro-singer {
  margin-top: 18px;
  padding: 14px 34px;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--pink), var(--violet));
  font-size: 36px;
  font-weight: 800;
}
.intro-singer:empty { display: none; }
.intro-count { margin-top: 26px; font-size: 120px; font-weight: 900; color: var(--pink); font-variant-numeric: tabular-nums; }
.spinner {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--pink);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Playing: stage layout (video left, queue right, lyrics below). Nothing is drawn over the video. */
.video-box {
  position: absolute;
  left: 72px;
  top: 150px;
  width: 1088px;
  height: 612px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
}
.video-box iframe, #yt { width: 100%; height: 100%; display: block; border: 0; }

.side {
  position: absolute;
  left: 1208px;
  right: 72px;
  top: 150px;
  height: 612px;
  display: flex;
  flex-direction: column;
  gap: 34px;
}
.now { display: flex; flex-direction: column; gap: 8px; }
.now-singer { font-size: 56px; font-weight: 900; letter-spacing: -0.01em; color: var(--pink); margin-top: 6px; }
.now-singer:empty { display: none; }
.now-title { font-size: 40px; font-weight: 800; line-height: 1.1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.now-artist { font-size: 28px; color: var(--dim); font-weight: 600; }
.next { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 16px; }
.next-list { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.next-list li { display: flex; align-items: center; gap: 18px; }
.next-list img { width: 112px; height: 63px; border-radius: 10px; object-fit: cover; background: #111; flex: none; }
.next-meta { min-width: 0; }
.next-title { font-size: 26px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.next-singer { font-size: 22px; color: var(--dim); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.next-empty { font-size: 26px; color: var(--faint); font-weight: 600; }
/* Member songs: the lineup takes the queue's place (who sings which member, "Idol" when nobody). */
.lineup { list-style: none; display: none; flex-direction: column; gap: 6px; flex: 1; min-height: 0; overflow: hidden; }
.lineup li { display: flex; align-items: center; gap: 16px; font-size: 26px; font-weight: 700; padding: 6px 16px; border-radius: 14px; transition: background 0.2s; }
.lineup li i { width: 24px; height: 24px; border-radius: 50%; background: var(--c); flex: none; }
.lineup li span { color: rgba(255, 255, 255, 0.4); font-weight: 600; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.lineup li.on { background: rgba(255, 255, 255, 0.08); }
.lineup li.on span { color: var(--c); font-weight: 800; }
#stage[data-cast='members'] .lineup { display: flex; }
#stage[data-cast='members'] .next { display: none; }
#stage[data-cast='members'] .now-singer { display: none; }
#stage[data-cast='members'] .side { gap: 20px; }
.side-join {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.side-join-title { font-size: 26px; font-weight: 800; }
.side-join-code { font-size: 22px; color: var(--dim); font-weight: 700; letter-spacing: 0.16em; margin-top: 4px; }

.lyrics {
  position: absolute;
  left: 72px;
  right: 72px;
  top: 790px;
  height: 236px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}
.lyric-original { font-size: 30px; font-weight: 700; color: var(--faint); min-height: 38px; }
.lyric-current {
  font-size: 68px;
  line-height: 1.12;
  font-weight: 900;
  letter-spacing: -0.01em;
  max-width: 100%;
}
.lyric-next { font-size: 40px; font-weight: 700; color: var(--faint); min-height: 50px; }
.lyric-singer, .lyric-ko { display: none; }
#stage[data-cast='members'] .lyrics { gap: 6px; }
#stage[data-cast='members'] .lyric-original { display: none; }
#stage[data-cast='members'] .lyric-singer {
  display: block;
  min-height: 38px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--c, var(--pink));
}
#stage[data-cast='members'] .lyric-ko { display: block; min-height: 38px; font-size: 30px; font-weight: 600; color: rgba(255, 255, 255, 0.5); }
#stage[data-cast='members'] .lyric-next { font-size: 34px; color: rgba(255, 255, 255, 0.3); min-height: 42px; }
#stage[data-cast='members'] .lyric-current { font-size: 72px; line-height: 1.1; }
.w {
  --p: 0;
  display: inline;
  background-image: linear-gradient(90deg, var(--pink) 0, var(--pink) calc(var(--p) * 100%), #fff calc(var(--p) * 100%), #fff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
/* Member songs: the line fills in her color. */
#stage[data-cast='members'] .w {
  background-image: linear-gradient(90deg, var(--c, var(--pink)) 0, var(--c, var(--pink)) calc(var(--p) * 100%), rgba(255, 255, 255, 0.5) calc(var(--p) * 100%), rgba(255, 255, 255, 0.5) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.w.done { --p: 1; }

.lead-in { position: absolute; top: 28px; display: none; gap: 14px; }
.lead-in.on { display: flex; }
.lead-in i { width: 18px; height: 18px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); }
.lead-in i.lit { background: var(--pink); box-shadow: 0 0 14px var(--pink); }

.progress { position: absolute; left: 72px; right: 72px; bottom: 30px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--violet), var(--pink)); }

/* Lyrics layout: small video in the corner, lyrics take the screen */
#stage[data-layout='lyrics'] .video-box { left: auto; right: 72px; top: 150px; width: 384px; height: 216px; }
#stage[data-layout='lyrics'] .side { left: 72px; right: auto; width: 1000px; top: 150px; height: 216px; flex-direction: row; gap: 56px; }
#stage[data-layout='lyrics'] .side .next { display: none; }
#stage[data-layout='lyrics'] .side-join { display: none; }
#stage[data-layout='lyrics'] .lyrics { top: 420px; height: 560px; gap: 28px; }
#stage[data-layout='lyrics'] .lyric-original { font-size: 40px; min-height: 50px; }
#stage[data-layout='lyrics'] .lyric-current { font-size: 104px; }
#stage[data-layout='lyrics'] .lyric-next { font-size: 58px; min-height: 70px; }
#stage[data-layout='lyrics'] .lead-in { top: 40px; }
#stage[data-layout='lyrics'][data-cast='members'] .side { width: 1360px; gap: 40px; }
#stage[data-layout='lyrics'][data-cast='members'] .now { width: 420px; flex: none; }
#stage[data-layout='lyrics'] .lineup { flex-direction: row; flex-wrap: wrap; align-content: flex-start; gap: 10px; }
#stage[data-layout='lyrics'] .lineup li { font-size: 24px; padding: 8px 14px; gap: 10px; }
#stage[data-layout='lyrics'] .lineup li span { margin-left: 6px; max-width: 180px; }
#stage[data-layout='lyrics'][data-cast='members'] .lyric-singer { font-size: 40px; min-height: 50px; }
#stage[data-layout='lyrics'][data-cast='members'] .lyric-current { font-size: 104px; }
#stage[data-layout='lyrics'][data-cast='members'] .lyric-ko { font-size: 40px; min-height: 50px; }
#stage[data-layout='lyrics'][data-cast='members'] .lyric-next { font-size: 52px; min-height: 64px; }

.start {
  position: absolute;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  display: none;
  padding: 22px 54px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--pink), var(--violet));
  color: #fff;
  font: 800 30px var(--font);
  cursor: pointer;
}
.start.on { display: block; }
.start:focus-visible { outline: 4px solid #fff; outline-offset: 6px; }

.toast {
  position: absolute;
  left: 50%;
  top: 50px;
  transform: translateX(-50%) translateY(-10px);
  padding: 16px 30px;
  border-radius: 999px;
  background: rgba(20, 20, 32, 0.92);
  border: 1px solid var(--line);
  font-size: 26px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 5;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
