:root {
  --bg: #12081a;
  --ink: #f7efe8;
  --muted: #b9a8c4;
  --panel: rgba(32, 18, 44, 0.92);
  --line: rgba(255, 220, 180, 0.14);
  --accent: #ff4d6d;
  --accent-2: #ffd166;
  --good: #62e0a4;
  --font: "Outfit", system-ui, sans-serif;
  --display: "Bebas Neue", Impact, sans-serif;
  --pad: max(1rem, env(safe-area-inset-left));
  --pad-r: max(1rem, env(safe-area-inset-right));
  --pad-b: max(1rem, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  padding-bottom: var(--pad-b);
}

.glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 60% 45% at 15% 10%, #6a1b9a66, transparent 60%),
    radial-gradient(ellipse 50% 40% at 90% 0%, #ff4d6d44, transparent 55%),
    linear-gradient(160deg, #0d0614, #1a0b24 50%, #12081a);
}

.top {
  width: min(1200px, calc(100% - var(--pad) - var(--pad-r)));
  margin: 0 auto;
  padding: 1.25rem 0 0.75rem;
}
.brand-link {
  display: inline-flex;
  text-decoration: none;
}
.brand-logo {
  display: block;
  width: min(200px, 58vw);
  height: auto;
}
.top h1 {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent-2);
}
.tag {
  color: var(--muted);
  margin: 0.55rem 0 0;
  font-size: 0.92rem;
  line-height: 1.35;
}

.panel, .stage {
  width: min(1200px, calc(100% - var(--pad) - var(--pad-r)));
  margin: 0 auto 1.5rem;
}
.hidden { display: none !important; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.card-form, .block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.1rem;
  backdrop-filter: blur(10px);
}
.card-form h2, .block h3 {
  margin: 0 0 0.8rem;
  font-size: 1.05rem;
}
label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  font-size: 0.86rem;
  color: var(--muted);
}
input, textarea, button {
  font: inherit;
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.28);
  color: var(--ink);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  font-size: 16px; /* prevents iOS zoom */
}
button {
  border: 0;
  border-radius: 12px;
  padding: 0.8rem 1rem;
  min-height: 44px;
  background: linear-gradient(135deg, var(--accent), #c9184a);
  color: white;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
button.secondary { background: #3b2454; }
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}
button.btn-lg {
  flex: 1;
  min-height: 48px;
  font-size: 1.05rem;
}
.note { color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.note a { color: var(--accent-2); }

.stage-bar {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.room-label {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.5rem, 6vw, 2rem);
  letter-spacing: 0.08em;
}
.muted { color: var(--muted); margin: 0.2rem 0 0; font-size: 0.88rem; }
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: #3b2454;
  color: var(--accent-2);
  border: 1px solid var(--line);
}
.role-badge.host {
  background: linear-gradient(135deg, var(--accent), #c9184a);
  color: #fff;
  border-color: transparent;
}
.bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  justify-content: flex-end;
}
.host-qr-panel {
  margin: 0 0 0.85rem;
}
.host-qr-card {
  display: grid;
  justify-items: center;
  gap: 0.45rem;
  text-align: center;
  padding: 1rem 1.1rem 1.15rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  color: #1a1024;
  border: 1px solid rgba(255, 220, 180, 0.35);
  max-width: 320px;
}
.host-qr-card h3 {
  margin: 0;
  font-family: var(--display);
  letter-spacing: 0.06em;
  font-size: 1.45rem;
  color: #1a1024;
}
.host-qr-card .muted {
  color: #5c4d6a;
  margin: 0;
}
.host-qr-card canvas {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  background: #fff;
}
.qr-code-label {
  margin: 0;
  font-size: 1.05rem;
  color: #1a1024;
}
.qr-link {
  margin: 0;
  font-size: 0.72rem;
  word-break: break-all;
  max-width: 100%;
}
.qr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  margin-top: 0.25rem;
}
.card-form.join-highlight {
  outline: 2px solid var(--accent-2);
  box-shadow: 0 0 0 6px rgba(255, 209, 102, 0.18);
}
.join-scan-tip {
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: rgba(255, 209, 102, 0.14);
  color: var(--accent-2);
  font-size: 0.9rem;
  font-weight: 600;
}
.btn-scan-qr {
  width: 100%;
  margin-bottom: 0.35rem;
}
.or-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.55rem;
  margin: 0.55rem 0 0.85rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.or-divider::before,
.or-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}
.scan-modal-card {
  width: min(440px, 100%);
}
.qr-reader {
  width: 100%;
  min-height: 240px;
  overflow: hidden;
  border-radius: 14px;
  background: #0a0610;
}
.qr-reader video {
  width: 100% !important;
  border-radius: 14px;
}
.scan-status {
  margin: 0.55rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
}
.room-notice {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid rgba(255, 209, 102, 0.35);
  color: var(--accent-2);
  font-size: 0.9rem;
}
.guest-hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.transport.host-only-dim .sliders,
.transport.host-only-dim .score-row {
  opacity: 0.55;
  pointer-events: none;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 4, 14, 0.72);
  backdrop-filter: blur(6px);
}
.modal.hidden { display: none !important; }
.modal-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.2rem;
}
.modal-card h3 { margin: 0 0 0.5rem; }
.modal-card p {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.4;
}
.modal-actions {
  display: grid;
  gap: 0.55rem;
}

.mobile-tabs {
  display: none;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 0.35rem 0;
  background: linear-gradient(180deg, #12081aee, #12081acc 70%, transparent);
  backdrop-filter: blur(8px);
}
.mobile-tabs .tab {
  flex: 1;
  background: #2a163d;
  border: 1px solid var(--line);
  color: var(--muted);
}
.mobile-tabs .tab.active {
  background: linear-gradient(135deg, var(--accent), #c9184a);
  color: #fff;
  border-color: transparent;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 260px;
  gap: 1rem;
}
.rail { display: grid; gap: 1rem; align-content: start; }
.row { display: flex; gap: 0.45rem; align-items: stretch; }
.row input { flex: 1; min-width: 0; }
.row button { flex-shrink: 0; }
.stack { display: grid; gap: 0.55rem; }
.list, .chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
  max-height: 240px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.list li, .chips li {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.7rem;
  font-size: 0.9rem;
}
.list li.mine {
  border-color: rgba(167, 139, 250, 0.55);
  background: rgba(124, 58, 237, 0.14);
}
.list li button {
  width: 100%;
  margin-top: 0.45rem;
}
.list .meta { color: var(--muted); font-size: 0.78rem; }
.chips {
  display: flex;
  flex-wrap: wrap;
  max-height: none;
}
.chips li.host-chip {
  background: linear-gradient(135deg, #ff4d6d55, #6a1b9a88);
  border-color: #ff4d6d66;
}

.lyrics-view {
  min-height: 280px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255,77,109,0.12), transparent 40%),
    rgba(0,0,0,0.35);
  padding: 1rem;
  display: grid;
  grid-template-rows: auto 1fr;
}
.yt-wrap {
  margin-bottom: 0.85rem;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #000;
  aspect-ratio: 16 / 9;
  max-height: 42vh;
}
.yt-wrap iframe,
#yt-player {
  width: 100%;
  height: 100%;
}
.now-card {
  margin-top: 0.85rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.9rem 1rem;
}
.now-meta {
  margin: 0;
  color: var(--accent-2);
  font-size: 0.92rem;
  line-height: 1.35;
}
.lyrics-sync {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.sync-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sync-btn {
  min-height: 36px;
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
}
#lyrics-offset {
  width: min(160px, 36vw);
  padding: 0;
}
#lyrics-offset-val {
  min-width: 3.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-2);
}
.sync-hint {
  margin: 0 0 0.65rem;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}
.lyrics-lines {
  overflow: auto;
  text-align: center;
  padding: 0.75rem 0.35rem 2.5rem;
  -webkit-overflow-scrolling: touch;
  max-height: min(42vh, 420px);
}
.lyrics-lines p {
  margin: 0.5rem 0;
  font-size: clamp(1.05rem, 4.2vw, 1.55rem);
  color: #7d6d8c;
  transition: color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
  line-height: 1.35;
}
.lyrics-lines p.active {
  color: #fff;
  transform: scale(1.04);
  text-shadow: 0 0 24px rgba(255, 77, 109, 0.45);
}
.lyrics-lines p.passed { color: #4f425c; }

.transport {
  margin-top: 0.85rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.9rem;
}
.controls, .sliders, .score-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-top: 0.65rem;
}
.transport .controls {
  position: relative;
  z-index: 6;
  pointer-events: auto;
}
.transport .controls button {
  pointer-events: auto;
  cursor: pointer;
}
.transport .controls button:disabled {
  cursor: not-allowed;
}
.sliders label {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  grid-template-columns: none;
}
.sliders input[type="range"] {
  width: 110px;
  min-height: 28px;
}
.check {
  flex-direction: row !important;
  align-items: center;
  color: var(--ink);
  margin-bottom: 0;
}
.check input { width: auto; }
.meter {
  flex: 1;
  min-width: 80px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
#meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--good));
}
#live-score { margin: 0; min-width: 4.5rem; font-weight: 700; }

.lyrics-view.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 40;
  border-radius: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(3rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
}
.lyrics-view.fullscreen .lyrics-lines {
  max-height: none;
}
.lyrics-view.fullscreen .lyrics-lines p {
  font-size: clamp(1.35rem, 5.5vw, 2.4rem);
}

@media (max-width: 980px) {
  .grid-2 { grid-template-columns: 1fr; }
  .mobile-tabs { display: flex; }
  .layout {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }
  .pane { display: none; }
  .pane.active { display: grid; }
  .main-stage.pane.active { display: block; }
  .list { max-height: 50vh; }
  .lyrics-view { min-height: 220px; }
  .sliders {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem 0.75rem;
  }
  .sliders label {
    width: 100%;
    justify-content: space-between;
  }
  .sliders input[type="range"] { width: min(140px, 42vw); }
  .transport {
    position: sticky;
    bottom: var(--pad-b);
    z-index: 15;
    box-shadow: 0 -12px 30px rgba(0,0,0,0.35);
  }
  .bar-actions button {
    padding: 0.65rem 0.75rem;
    font-size: 0.88rem;
  }
}

@media (max-width: 420px) {
  .row {
    flex-direction: column;
  }
  .row button { width: 100%; }
  .score-row {
    flex-direction: column;
    align-items: stretch;
  }
  .score-row button { width: 100%; }
}
