/* ============================================================
   HOST PRODUCTION — host.css
   Dark theme, video-hero layout
   ============================================================ */

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

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface-2:   #21262d;
  --border:      rgba(255,255,255,0.08);
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #58a6ff;
  --live:        #3fb950;
  --error:       #f85149;
  --radius:      12px;
  --radius-lg:   18px;
  --font-ui:     'Syne', sans-serif;
  --font-mono:   'DM Mono', monospace;
}

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

/* ── OVERLAYS ─────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(13,17,23,0.92);
  backdrop-filter: blur(6px);
}

.overlay__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.overlay__label {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.overlay__sub {
  font-size: 14px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.overlay__icon {
  width: 52px;
  height: 52px;
  color: var(--error);
}

.overlay--error {
  background: rgba(13,17,23,0.96);
}

.btn-reload {
  margin-top: 8px;
  padding: 10px 28px;
  border: 1.5px solid var(--error);
  border-radius: var(--radius);
  background: transparent;
  color: var(--error);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-reload:hover {
  background: var(--error);
  color: #fff;
}

/* Spinner */
.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── STATE CONTROL ────────────────────────────────────────── */

/* connecting → show connecting overlay */
body.state-connecting #overlayConnecting { display: flex; }

/* error → show error overlay, video blocked */
body.state-error #overlayError   { display: flex; }
body.state-error #player         { pointer-events: none; filter: brightness(0.3); }

/* ready → both overlays hidden (default already hidden) */

/* ── LAYOUT ───────────────────────────────────────────────── */

.layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── TOP BAR ──────────────────────────────────────────────── */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.15s;
}
.topbar__brand:hover { opacity: 0.7; }

.topbar__role {
  color: var(--accent);
  margin-left: 6px;
  font-size: 11px;
  background: rgba(88,166,255,0.12);
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: 0.1em;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Status pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px;
  font-family: var(--font-mono);
}

.status-pill__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

/* dot colours per state */
body.state-connecting .status-pill__dot { background: var(--accent); animation: pulse-dot 1.2s ease-in-out infinite; }
body.state-ready      .status-pill__dot { background: var(--live); }
body.state-error      .status-pill__dot { background: var(--error); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* Icon buttons */
.btn-icon {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { background: var(--surface); border-color: rgba(255,255,255,0.18); }

.btn-logout:hover { border-color: var(--error); color: var(--error); }

/* ── CONTENT ──────────────────────────────────────────────── */

.content {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 0;
  overflow: hidden;
}

/* ── TRACK LIST ───────────────────────────────────────────── */

.tracklist-wrap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 24px;
}

.tracklist-wrap__label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 12px;
}

.tracklist {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.tracklist__loading,
.tracklist__error {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 0;
}

.tracklist__error { color: var(--error); }

.track-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.track-row:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.track-row--active {
  background: var(--accent-dim, rgba(88,166,255,0.1));
  border-color: rgba(88,166,255,0.3);
}

.track-row__art {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
}

.track-row__art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.track-row__art-placeholder {
  width: 100%;
  height: 100%;
  background: var(--surface-2);
}

.track-row__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.track-row__title {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-row__artist {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-row__end {
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.track-row__play {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.12s;
  flex-shrink: 0;
}

.track-row__pause {
  width: 14px;
  height: 14px;
  color: var(--accent);
  display: none;
  cursor: pointer;
  flex-shrink: 0;
}

.track-row:hover .track-row__play { opacity: 1; color: var(--accent); }

/* ── playing: EQ + pause button, no play triangle ── */
.track-row--playing .track-row__play  { display: none; }
.track-row--playing .track-row__pause { display: block; }
.track-row--playing .eq               { display: flex; }

/* ── paused: play triangle as resume, no EQ, no pause button ── */
.track-row--paused .track-row__play  { display: block; opacity: 1; color: var(--accent); }
.track-row--paused .track-row__pause { display: none; }
.track-row--paused .eq               { display: none; }

/* hide EQ on all other rows */
.track-row:not(.track-row--playing):not(.track-row--paused) .eq { display: none; }

/* ── EQ animation ─────────────────────────────────────────── */

.eq {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
}

.eq span {
  display: block;
  width: 3px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  animation: eq-bar 0.6s ease-in-out infinite alternate;
}

.eq span:nth-child(1) { animation-duration: 0.65s; animation-delay: 0.00s; }
.eq span:nth-child(2) { animation-duration: 0.45s; animation-delay: 0.13s; }
.eq span:nth-child(3) { animation-duration: 0.80s; animation-delay: 0.07s; }
.eq span:nth-child(4) { animation-duration: 0.55s; animation-delay: 0.20s; }
.eq span:nth-child(5) { animation-duration: 0.70s; animation-delay: 0.04s; }

@keyframes eq-bar {
  from { height: 3px;  opacity: 0.5; }
  to   { height: 16px; opacity: 1.0; }
}

/* ── SIDEBAR ──────────────────────────────────────────────── */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 16px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

/* ── QR PANEL ─────────────────────────────────────────────── */

.qr-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.qr-panel__label {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.qr-panel__canvas-wrap {
  background: #fff;
  padding: 10px;
  border-radius: 10px;
  line-height: 0; /* prevent extra whitespace */
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#qr {
  width: 200px;
  height: 200px;
  display: block;
  image-rendering: pixelated;
}

/* ── SESSION ID (dev-only) ───────────────────────────────── */

.session-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.session-info__label {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.session-info__id {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text);
  word-break: break-all;
}

/* Toggle dev-only elements — set to 'none' for prod */
.dev-only {
  display: none;
}

/* ── RESPONSIVE ───────────────────────────────────────────── */

@media (max-width: 768px) {
  .content {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .sidebar {
    flex-direction: row;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 12px;
    overflow-x: auto;
  }

  .qr-panel {
    flex-direction: row;
    gap: 10px;
    padding: 10px 14px;
  }

  .qr-panel__canvas-wrap {
    width: 120px;
    height: 120px;
  }

  #qr {
    width: 100px;
    height: 100px;
  }
}

/* ── NOW PLAYING ──────────────────────────────────────────── */

.now-playing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: center;
}

.now-playing__label {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.now-playing__art {
  width: 160px;
  height: 160px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  flex-shrink: 0;
}

.now-playing__art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.now-playing__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.now-playing__artist {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.btn-mute--active {
  border-color: var(--error);
  color: var(--error);
  background: rgba(248, 81, 73, 0.12);
}

.btn-mute--active:hover {
  background: var(--error);
  color: #fff;
}

.sync-quality {
  position: relative;
  z-index: 200;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #e3b341;
  background: rgba(227, 179, 65, 0.15);
  border: 1px solid rgba(227, 179, 65, 0.45);
  padding: 5px 14px;
  border-radius: 20px;
  white-space: nowrap;
}

.hidden { display: none; }
