*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3e;
  --accent: #5b73ff;
  --accent-hover: #7389ff;
  --text: #e2e4f0;
  --muted: #7a7d94;
  --danger: #e05555;
  --green: #3ecf8e;
  --radius: 8px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── landing ─────────────────────────────────────── */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 1.5rem;
  padding: 2rem;
  text-align: center;
}

.landing h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.landing p {
  color: var(--muted);
  max-width: 380px;
}

.landing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  padding: 1.5rem 1.75rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.landing-card h2 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.1rem;
}

.landing-divider {
  color: var(--muted);
  font-size: 0.82rem;
}

.form-error {
  color: var(--danger);
  font-size: 0.82rem;
  min-height: 1.1em;
}

/* ── buttons ─────────────────────────────────────── */

.room-name-input {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}
.room-name-input:focus { border-color: var(--accent); }

.quality-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
}
.quality-select:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.4rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #cc3c3c; }

.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-green { background: var(--green); color: #0a2e20; }
.btn-green:hover { background: #52e0a4; }

/* ── room page layout ────────────────────────────── */

.room {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar .room-id {
  font-size: 0.8rem;
  color: var(--muted);
  margin-left: auto;
}

/* main area */
.room-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── status screen (shown while waiting) ─────────── */

.status-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 1rem;
  text-align: center;
  padding: 2rem;
}

.status-screen .status { color: var(--muted); font-size: 0.95rem; }

/* ── sharer UI ───────────────────────────────────── */

#sharer-ui {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.sharer-grid {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.preview-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

.preview-wrap video {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.sharer-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
}

.sharer-sidebar label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.link-group {
  display: flex;
  gap: 0.5rem;
}

.link-group input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.7rem;
  color: var(--text);
  font-size: 0.8rem;
  min-width: 0;
}

.viewer-count-badge {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--green);
}

/* ── network tower ───────────────────────────── */

.network-tower {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  cursor: help;
}
.network-tower .bar {
  width: 4px;
  background: var(--muted);
  border-radius: 1px;
  transition: background 0.3s;
}
.network-tower .bar1 { height: 6px; }
.network-tower .bar2 { height: 10px; }
.network-tower .bar3 { height: 14px; }

.network-tower.good .bar { background: var(--green); box-shadow: 0 0 5px var(--green); }
.network-tower.degraded .bar1, .network-tower.degraded .bar2 { background: #f0a500; box-shadow: 0 0 5px #f0a500; }
.network-tower.poor .bar1 { background: var(--danger); box-shadow: 0 0 6px var(--danger); animation: pulse 1s infinite; }

/* viewer: bottom-right corner */
.video-container .network-tower {
  position: absolute;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 10;
}

/* ── stats and full screen ───────────────────────────── */
.stats-overlay {
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  background: rgba(0, 0, 0, 0.6);
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius);
  font-family: monospace;
  font-size: 0.85rem;
  color: #0f0;
  z-index: 10;
  pointer-events: none;
}
.icon-btn {
  background: rgba(0,0,0,0.5);
  border: none;
  color: white;
  border-radius: var(--radius);
  padding: 0.5rem;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(0,0,0,0.8); }

#fullscreen-btn {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 10;
}
.stats-text {
  font-family: monospace;
  color: var(--text);
  font-size: 0.85rem;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── viewer UI ───────────────────────────────────── */

.video-container {
  display: none;
  flex: 1;
  background: #000;
  position: relative;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.video-container.active {
  display: flex;
}

.video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.audio-controls {
  position: absolute;
  bottom: 1.5rem;
  left: 1.5rem;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0,0,0,0.5);
  border-radius: var(--radius);
  padding: 0.35rem 0.6rem;
  backdrop-filter: blur(6px);
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}
.volume-slider::-webkit-slider-thumb:hover { background: var(--accent); }
.volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}

/* viewer waiting */
#viewer-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 1rem;
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
