:root {
  --bg: #0d0820;
  --panel: #1a1238;
  --panel-2: #261b4f;
  --line: #3a2d6b;
  --text: #f4f0ff;
  --muted: #a99fd0;
  --pink: #ff3d8b;
  --cyan: #2de2e6;
  --gold: #ffd23f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.muted { color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--panel-2);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--pink); color: #fff; }
.btn.accent { background: var(--cyan); color: #062a2b; }

/* ---------- Main screen ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(90deg, #2a0f5c, #4a1260);
}
.brand { font-size: 1.35rem; font-weight: 800; letter-spacing: 0.02em; }
.brand span { color: var(--pink); }
.top-actions { display: flex; gap: 8px; }

.now-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #13304a;
}
.now-bar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  align-items: start;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  min-width: 0;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.panel h2 {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.display {
  margin-bottom: 12px;
  padding: 12px;
  text-align: center;
  background: #050310;
  border: 2px solid var(--line);
  border-radius: 12px;
}
#numDisplay {
  display: block;
  padding-left: 0.3em;
  color: var(--gold);
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-shadow: 0 0 12px rgba(255, 210, 63, 0.5);
}
#numHint {
  display: block;
  min-height: 1.3em;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button {
  padding: 14px 0;
  font-size: 1.4rem;
  font-weight: 700;
  background: var(--panel-2);
  border-bottom: 3px solid #0f0a24;
  border-radius: 12px;
}
.keypad button:active { transform: translateY(2px); border-bottom-width: 1px; }
.keypad .fn { color: var(--muted); font-size: 1rem; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.actions .btn { padding: 14px; font-size: 1.05rem; }

.queue { margin: 0; padding: 0; list-style: none; }
.queue li, .song {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.queue .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { color: var(--gold); font-family: ui-monospace, "Courier New", monospace; font-weight: 700; }
.icon {
  flex: none;
  width: 36px;
  height: 36px;
  color: var(--muted);
  background: var(--panel-2);
  border-radius: 8px;
}
.icon.reserve { color: var(--cyan); font-size: 1.2rem; }

.toggle { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px; color: var(--muted); }
.toggle input { width: 20px; height: 20px; margin: 0; accent-color: var(--pink); }

.book-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.book-head h2 { margin: 0; }
#search {
  flex: 1 1 220px;
  min-width: 0;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  background: #0b0719;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.empty { padding: 24px 8px; color: var(--muted); text-align: center; }
.empty p { max-width: 460px; margin: 0 auto 12px; }

.songs { margin: 12px 0 0; padding: 0; list-style: none; }
.song { cursor: pointer; border-radius: 8px; }
.song:hover { background: var(--panel-2); }
.song .meta { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.song .meta b, .song .meta small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song .meta small { color: var(--muted); }
.song .kind {
  padding: 2px 6px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.legal {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 24px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  background: #2b2160;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%);
}

/* ---------- Stage (singing screen) ---------- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  background: #000;
}
.stage-bg {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 30% 30%, #5b1a8a, transparent 50%),
    radial-gradient(circle at 70% 60%, #0f4c75, transparent 50%),
    radial-gradient(circle at 50% 90%, #8a1a4f, transparent 55%),
    #0b0618;
  animation: drift 18s ease-in-out infinite alternate;
}
@keyframes drift {
  to { transform: rotate(8deg) scale(1.15); }
}
@media (prefers-reduced-motion: reduce) {
  .stage-bg { animation: none; }
}
#video {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.stage.has-video #video { display: block; }
.stage.has-video .stage-bg { display: none; }

.stage-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  background: linear-gradient(rgba(0, 0, 0, 0.6), transparent);
}
.pill {
  padding: 2px 8px;
  color: #1a1200;
  font-family: ui-monospace, "Courier New", monospace;
  font-weight: 700;
  background: var(--gold);
  border-radius: 6px;
}

.countdown {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(18% + 7.5em);
  color: var(--gold);
  font-size: 1.6rem;
  letter-spacing: 0.4em;
  text-align: center;
}

.lyrics {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 22%;
  padding: 0 16px;
  text-align: center;
}
.line {
  min-height: 1.25em;
  margin: 0.15em 0;
  color: #fff;
  font-size: clamp(1.6rem, 5.5vw, 3.6rem);
  font-weight: 800;
  line-height: 1.25;
  white-space: pre-wrap;
  text-shadow:
    2px 2px 0 #1a0a3a, -2px -2px 0 #1a0a3a,
    2px -2px 0 #1a0a3a, -2px 2px 0 #1a0a3a,
    0 0 12px rgba(0, 0, 0, 0.8);
  opacity: 0.8;
  transition: opacity 0.3s;
}
.line.current { opacity: 1; }
.line span { transition: color 0.12s; }
.line span.sung { color: var(--cyan); }

.stage-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}
.progress { height: 4px; margin-bottom: 12px; overflow: hidden; background: rgba(255, 255, 255, 0.15); border-radius: 2px; }
#progressBar { width: 0; height: 100%; background: var(--pink); }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.controls .btn { background: rgba(38, 27, 79, 0.85); }
.controls .btn.primary { background: var(--pink); }
.key { display: inline-flex; align-items: center; gap: 6px; }
#keyLabel { min-width: 4.5em; text-align: center; }

.score {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  background: rgba(8, 4, 20, 0.85);
  cursor: pointer;
}
.score-label { color: var(--muted); font-size: 1.2rem; font-weight: 700; letter-spacing: 0.3em; }
.score-value {
  color: var(--gold);
  font-family: ui-monospace, "Courier New", monospace;
  font-size: clamp(6rem, 30vw, 12rem);
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 0 30px rgba(255, 210, 63, 0.6);
}
.score-msg { padding: 0 16px; font-size: 1.6rem; font-weight: 700; }
