:root {
  color-scheme: dark;
  --bg: #080c14;
  --surface: #0f1623;
  --surface-elevated: #151f30;
  --border: rgba(148, 163, 184, 0.16);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --live: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

.app-shell.is-fullscreen .topbar {
  background: rgba(8, 12, 20, 0.92);
}

.topbar {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

.topbar-left,
.topbar-controls,
.player-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

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

.status-dot.status-idle {
  background: var(--text-muted);
}

.status-dot.status-connecting {
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
}

.status-dot.status-live {
  background: var(--live);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.25);
  animation: pulse 1.8s infinite;
}

.status-dot.status-ended {
  background: var(--warn);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-muted);
}

.badge-live {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.badge-connecting {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

.badge-warn {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

.session-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.volume-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  font-size: 12px;
}

.volume-label {
  color: var(--text-muted);
}

.volume-control input[type="range"] {
  width: 90px;
  accent-color: var(--accent);
  cursor: pointer;
}

.volume-value {
  font-family: var(--mono);
  width: 36px;
  text-align: right;
  color: var(--text);
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 11px;
}

.btn-full {
  width: 100%;
  padding: 11px 16px;
  font-size: 14px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  font-size: 14px;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: var(--surface-elevated);
  border-color: var(--border);
  color: var(--text);
  padding: 9px 14px;
  font-size: 13px;
}

.btn-ghost:hover:not(:disabled) {
  border-color: rgba(148, 163, 184, 0.38);
}

.btn-ghost[aria-pressed="true"] {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.6);
  color: #bfdbfe;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

.count-pill {
  background: rgba(148, 163, 184, 0.2);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--mono);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

.stage-container {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: radial-gradient(circle at top, #131c2e 0%, #070a11 75%);
}

.room-frame-host {
  width: 100%;
  height: 100%;
}

.room-frame-host iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #000;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 12, 20, 0.84);
  backdrop-filter: blur(8px);
  overflow-y: auto;
  z-index: 10;
}

.overlay[hidden],
.events-drawer[hidden],
.player-controls[hidden],
[hidden] {
  display: none !important;
}

.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.join-card {
  max-width: 520px;
}

.state-card {
  max-width: 440px;
  text-align: center;
}

.state-card h2 {
  margin: 14px 0 8px;
  font-size: 22px;
}

.state-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #60a5fa;
  font-weight: 700;
  margin-bottom: 6px;
}

.card-header h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-muted);
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
}

.req {
  color: #f87171;
}

.field input,
.field select {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
}

.hint {
  margin: 2px 0 4px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.4;
}

.alert-error {
  background: rgba(239, 68, 68, 0.13);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

.notice {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  margin-bottom: 14px;
  background: rgba(245, 158, 11, 0.13);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

.events-drawer {
  width: 340px;
  max-width: 90vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex-shrink: 0;
}

.drawer-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h2 {
  margin: 0;
  font-size: 14px;
}

.drawer-sub {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
}

.state-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.state-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.state-label {
  font-size: 10.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.state-value {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-log {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-entry {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}

.event-entry-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.event-dir {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 4px;
}

.dir-in {
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
}

.dir-out {
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
}

.dir-sys {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.event-time {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
}

.event-payload {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 780px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .events-drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
  }
}

