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

:root {
  --bg:        #0a0a12;
  --bg-2:      #150c26;
  --surface:   #12121e;
  --surface-2: #191928;
  --border:    rgba(255,255,255,0.1);
  --text:      #ffffff;
  --text-muted: #d9d2ec;
  --accent:    #ec4899;
  --pink:      #ec4899;
  --purple:    #a855f7;
  --blue:      #2fd3ff;
  --live:      #34d399;
  --error:     #f85149;
  --gradient-primary:   linear-gradient(135deg, var(--pink) 0%, var(--purple) 100%);
  --gradient-secondary: linear-gradient(135deg, var(--blue) 0%, var(--purple) 100%);
  --radius:    14px;
  --radius-lg: 20px;
  --font-ui:   'Inter', Helvetica, Arial, Lucida, sans-serif;
  --font-body: 'Helvetica Neue', Helvetica, Arial, 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;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10,10,18,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 {
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 14px;
}

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

.overlay--error {
  background: rgba(10,10,18,0.96);
}

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

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

body.state-connecting #overlayConnecting,
body.state-loading #overlayConnecting {
  display: flex;
}

body.state-error #overlayError {
  display: flex;
}

.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: linear-gradient(to bottom, var(--bg-2) 0%, var(--bg) 420px);
}

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

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

.topbar__role {
  color: var(--pink);
  margin-left: 6px;
  font-size: 11px;
  background: rgba(236,72,153,0.14);
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: 0.1em;
}

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

.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-body);
}

.audio-track-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.audio-track-btn {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill, 999px);
  padding: 6px 16px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.audio-track-btn:hover {
  border-color: rgba(236,72,153,0.4);
  color: var(--text);
}

.audio-track-btn--active {
  background: rgba(236,72,153,0.14);
  border-color: rgba(236,72,153,0.55);
  color: var(--text);
  box-shadow: 0 0 0 1px rgba(236,72,153,0.35);
}

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

body.state-loading .status-pill__dot,
body.state-connecting .status-pill__dot {
  background: var(--blue);
  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; }
}

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

.content {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 280px;
  min-height: 0;
}

.video-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.video-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: 20px;
  min-height: 52vh;
}

#player {
  width: 100%;
  max-height: 64vh;
  border-radius: var(--radius-lg);
  background: #000;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.live-panel {
  padding: 20px 24px 28px;
  border-top: 1px solid var(--border);
}

.live-panel__header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.live-panel__label {
  color: var(--pink);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.live-panel__header::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.audio-monitor {
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.audio-monitor__label {
  flex: 1;
  color: var(--text-muted);
  font-size: 12px;
}

.content-card {
  padding: 14px 16px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-top: 3px solid var(--pink);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.12s, box-shadow 0.12s;
}

.content-card:hover {
  border-color: rgba(255,255,255,0.25);
  border-top-color: var(--pink);
  transform: translateY(-2px);
}

.content-card--active {
  border-color: rgba(236,72,153,0.55);
  background: rgba(236,72,153,0.12);
  box-shadow: 0 0 0 1px rgba(236,72,153,0.35);
}

.content-card__title {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 4px;
}

.content-card__lede {
  font-family: var(--font-body);
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.content-card--placeholder {
  border-top-color: var(--border);
  border-style: dashed;
  cursor: default;
}

.content-card--placeholder .content-card__title {
  color: var(--text-muted);
  font-weight: 500;
}

.content-card--placeholder:hover {
  transform: none;
}

.content-card__accent {
  color: var(--pink);
}

.btn-primary {
  border: 1px solid rgba(236,72,153,0.45);
  border-radius: var(--radius);
  background: rgba(236,72,153,0.14);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 800;
  padding: 10px 16px;
}

.btn-primary:hover {
  background: rgba(236,72,153,0.22);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
}

.metric-card__label {
  display: block;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric-card__value {
  display: block;
  min-height: 20px;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.metric-card__value--small {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

.sidebar {
  border-left: 1px solid var(--border);
  padding: 24px;
}

.qr-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  padding: 18px;
}

.qr-panel__label {
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.qr-panel__canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  background: #fff;
  border-radius: var(--radius);
  padding: 10px;
}

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

.qr-panel__alias {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
}

.qr-panel__alias-text {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.qr-panel__alias-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(236,72,153,0.4);
  border-radius: var(--radius);
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  width: 120px;
}

.qr-panel__alias-input:focus {
  outline: none;
  border-color: var(--pink);
}

.qr-panel__alias-edit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.qr-panel__alias-edit:hover {
  color: var(--pink);
}

.qr-panel__alias-edit svg {
  width: 14px;
  height: 14px;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--surface);
  border-color: rgba(255,255,255,0.25);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

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

  .sidebar {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }
}
