:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f5efe6;
  --muted: rgba(245, 239, 230, 0.55);
  --accent: #e8b84a;
  --accent-dim: rgba(232, 184, 74, 0.2);
  --danger: #e85d5d;
  --success: #5de88a;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-logo-link {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
  line-height: 0;
}

.site-logo-link:hover { text-decoration: none; opacity: 0.92; }

.site-logo {
  display: block;
  width: auto;
  height: clamp(2.25rem, 7vw, 2.75rem);
  max-width: min(7.5rem, 36vw);
  object-fit: contain;
  object-position: left center;
}

.page-header {
  margin-bottom: 1rem;
}

.container {
  width: min(960px, 100% - 2rem);
  margin: 0 auto;
  padding: 2rem 0;
}

.brand {
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

h1 {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0.35rem 0 0.5rem;
}

.subtitle { color: var(--muted); max-width: 42ch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.field { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }
.field[hidden] { display: none !important; }
.field label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

input[type="text"], input[type="url"], select {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}

input:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.2rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); color: #1a1200; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-outline {
  background: transparent;
  border-color: rgba(245, 239, 230, 0.25);
}
.btn-outline:hover {
  border-color: var(--accent);
  background: rgba(232, 184, 74, 0.08);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-vote {
  min-width: 3rem;
  min-height: 3rem;
  padding: 0;
  border-radius: 8px;
  font-size: 1.25rem;
  font-weight: 800;
  background: var(--accent-dim);
  border-color: rgba(232, 184, 74, 0.35);
  color: var(--accent);
}

.btn-vote:active { transform: scale(0.96); }
.btn-vote:disabled { opacity: 0.3; }

.error {
  color: var(--danger);
  background: rgba(232, 93, 93, 0.1);
  border: 1px solid rgba(232, 93, 93, 0.3);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.success-box {
  margin-top: 1.25rem;
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid rgba(93, 232, 138, 0.25);
  background: rgba(93, 232, 138, 0.06);
}

.room-code {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin: 0.5rem 0 1rem;
}

.link-row { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1rem; }

/* ── Vote page ── */
.vote-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left));
  padding-top: max(0.75rem, env(safe-area-inset-top));
}

.vote-header .site-logo-link { margin-bottom: 0.65rem; }

.vote-header h1 { font-size: 1.25rem; margin: 0.2rem 0; }

.votes-left {
  font-size: 0.85rem;
  color: var(--muted);
}

.votes-left strong { color: var(--accent); font-size: 1.1rem; }

.top-three {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.top-three-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
}

.top-three-item .rank {
  width: 1.4rem;
  font-weight: 800;
  color: var(--accent);
}

.track-list { padding: 0.75rem 1rem 5rem; }

.track-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.track-row.voted { background: rgba(232, 184, 74, 0.04); }
.track-row.played { opacity: 0.35; }

.track-art {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-2);
}

.track-info h3 { font-size: 0.95rem; font-weight: 600; }
.track-info p { font-size: 0.8rem; color: var(--muted); }
.vote-count { font-size: 0.75rem; color: var(--accent); font-variant-numeric: tabular-nums; margin-top: 0.15rem; }

/* ── Stage page ── */
.stage-body {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}

.stage-header-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.stage-header-brand .site-logo {
  height: clamp(2rem, 5vw, 2.5rem);
  max-width: min(6.5rem, 28vw);
}

.stage-room { font-size: clamp(0.85rem, 2.5vw, 1.1rem); font-weight: 700; letter-spacing: 0.15em; color: var(--accent); white-space: nowrap; }

.stage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  min-height: 0;
}

@media (max-width: 900px) {
  .stage-grid { grid-template-columns: 1fr; }
}

.now-playing-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.now-art {
  width: min(280px, 100%);
  aspect-ratio: 1;
  border-radius: 12px;
  object-fit: cover;
  background: var(--surface-2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.now-title { font-size: clamp(1.4rem, 3vw, 2rem); font-weight: 800; }
.now-artist { font-size: 1.1rem; color: var(--muted); }

.progress-wrap { margin-top: 0.5rem; }
.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.5s linear;
}
.progress-time {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
  font-variant-numeric: tabular-nums;
}

.queue-panel h2 {
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
}

.queue-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: calc(100vh - 12rem); overflow-y: auto; }

.queue-row {
  display: grid;
  grid-template-columns: 2rem 40px 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid transparent;
  transition: border-color 0.2s, transform 0.2s;
}

.queue-row.leader { border-color: var(--accent); background: var(--accent-dim); }
.queue-row.overtake { animation: pulse-rank 0.6s ease; }

@keyframes pulse-rank {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); border-color: var(--accent); }
}

.queue-rank { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.queue-votes { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); min-width: 2rem; text-align: right; }

.qr-panel {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  z-index: 10;
}

.qr-panel p { font-size: 0.72rem; color: var(--muted); margin-top: 0.5rem; letter-spacing: 0.06em; text-transform: uppercase; }
#qr-code canvas, #qr-code img { display: block; margin: 0 auto; }

.stage-auth {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.auth-status { font-size: 0.8rem; color: var(--muted); }
.auth-status.ok { color: var(--success); }

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.toast.show { opacity: 1; }

.operator-panel {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  max-width: 18rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  z-index: 10;
  font-size: 0.82rem;
}

.operator-panel summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}

.operator-panel summary::-webkit-details-marker { display: none; }

.operator-hint {
  color: var(--muted);
  font-size: 0.75rem;
  margin: 0.6rem 0;
  line-height: 1.35;
}

.operator-stat {
  margin-bottom: 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.operator-stat strong { color: var(--text); }

.operator-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.operator-actions .btn { width: 100%; font-size: 0.78rem; padding: 0.45rem 0.6rem; }

.operator-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.operator-row label { color: var(--muted); font-size: 0.75rem; }

.operator-row input {
  width: 3.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.35rem 0.45rem;
  font-size: 0.82rem;
}

.admin-panel { margin-top: 1rem; }

.admin-stats { margin-bottom: 1.25rem; }

.admin-stat-list {
  list-style: none;
  margin-top: 0.75rem;
  display: grid;
  gap: 0.5rem;
}

.admin-stat-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.88rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.45rem;
}

.admin-stat-list strong {
  color: var(--text);
  text-align: right;
}

.admin-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.admin-actions .btn { width: 100%; }
