:root {
  --bg: #0b0d12;
  --bg-elevated: #12151c;
  --bg-panel: #161a24;
  --border: #262b38;
  --text: #e8ebf2;
  --text-muted: #8b93a7;
  --accent: #5b8cff;
  --accent-hover: #7aa3ff;
  --danger: #ff5c7a;
  --success: #3dd68c;
  --warning: #f5c542;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

body {
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(91, 140, 255, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(61, 214, 140, 0.06), transparent);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.container {
  width: min(1100px, 100% - 2rem);
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  box-shadow: 0 0 24px rgba(91, 140, 255, 0.4);
}

.nav-links {
  display: flex;
  gap: 1rem;
  font-size: 0.95rem;
}

.hero {
  text-align: center;
  padding: 3rem 0 2.5rem;
}

.hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.hero p {
  margin: 0 auto 1.75rem;
  max-width: 36rem;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.7rem 1.25rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  text-decoration: none;
  color: inherit;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

.btn-secondary {
  background: var(--bg-panel);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: #3a4154;
  text-decoration: none;
  color: var(--text);
}

.btn-danger {
  background: rgba(255, 92, 122, 0.15);
  border-color: rgba(255, 92, 122, 0.4);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(255, 92, 122, 0.25);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

.card + .card {
  margin-top: 1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 2.5rem;
}

.feature {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}

.feature h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.feature p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Stream / watch layouts */

.page-title {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.page-sub {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
}

.layout {
  display: grid;
  gap: 1rem;
}

@media (min-width: 900px) {
  .layout-stream {
    grid-template-columns: 1fr 320px;
    align-items: start;
  }
}

.video-stage {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  min-height: 240px;
  box-shadow: var(--shadow);
}

.video-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-muted);
  padding: 1.5rem;
  text-align: center;
  pointer-events: none;
}

.video-placeholder.hidden,
.hidden {
  display: none !important;
}

.video-placeholder strong {
  color: var(--text);
  font-size: 1.05rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-top: 1rem;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.badge.live {
  color: var(--success);
  border-color: rgba(61, 214, 140, 0.35);
  background: rgba(61, 214, 140, 0.1);
}

.badge.live::before {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 1.4s ease-in-out infinite;
}

.badge.error {
  color: var(--danger);
  border-color: rgba(255, 92, 122, 0.35);
  background: rgba(255, 92, 122, 0.1);
}

.badge.error::before {
  background: var(--danger);
}

.badge.connecting {
  color: var(--warning);
  border-color: rgba(245, 197, 66, 0.35);
  background: rgba(245, 197, 66, 0.1);
}

.badge.connecting::before {
  background: var(--warning);
  animation: pulse 1s ease-in-out infinite;
}

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

.share-box {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.share-url {
  display: flex;
  gap: 0.5rem;
}

.share-url input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.55rem 0.75rem;
}

.share-url input:focus {
  outline: 2px solid rgba(91, 140, 255, 0.45);
  outline-offset: 1px;
}

.stats {
  display: grid;
  gap: 0.65rem;
  font-size: 0.9rem;
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}

.stat:last-child {
  border-bottom: none;
}

.stat span:last-child {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat span:first-child {
  color: var(--text-muted);
}

.log {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.log li {
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(38, 43, 56, 0.6);
}

.log li:last-child {
  border-bottom: none;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.form-row input[type="text"] {
  flex: 1;
  min-width: 12rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 0.65rem 0.85rem;
}

.form-row input:focus {
  outline: 2px solid rgba(91, 140, 255, 0.45);
  outline-offset: 1px;
}

.alert {
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
}

.alert.error {
  border-color: rgba(255, 92, 122, 0.4);
  background: rgba(255, 92, 122, 0.1);
  color: #ffb3c0;
}

.alert.info {
  border-color: rgba(91, 140, 255, 0.35);
  background: rgba(91, 140, 255, 0.1);
  color: #b8ceff;
}

.footer-note {
  margin-top: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.peer-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}

.peer-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  color: var(--text-muted);
}

.peer-list li:last-child {
  border-bottom: none;
}

.peer-list .state {
  color: var(--text);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.8rem;
}

/* Quality controls */

.card-hint {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.quality-grid {
  display: grid;
  gap: 0.75rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field span {
  font-weight: 600;
  color: var(--text-muted);
}

.field select,
.field input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 0.55rem 0.7rem;
}

.field select:focus,
.field input[type="text"]:focus {
  outline: 2px solid rgba(91, 140, 255, 0.45);
  outline-offset: 1px;
}

.join-form {
  display: grid;
  gap: 0.85rem;
}

.join-form .btn {
  justify-self: start;
}

/* Watcher cards (streamer) */

.watcher-list {
  display: grid;
  gap: 0.65rem;
}

.watcher-list .empty-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.watcher-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.watcher-card-main {
  min-width: 0;
  flex: 1;
}

.watcher-name {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
  word-break: break-word;
}

.watcher-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.watcher-ip {
  font-family: var(--mono);
  font-size: 0.75rem;
}

.watcher-geo {
  color: var(--text-muted);
}

.watcher-state {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: lowercase;
}

.watcher-state.state-ok {
  color: var(--success);
}

.watcher-state.state-bad {
  color: var(--danger);
}

.watcher-state.state-wait {
  color: var(--warning);
}

/* Video HUD (watcher) */

.video-hud {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e8ebf2;
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  backdrop-filter: blur(6px);
}

.video-hud .hud-sep {
  opacity: 0.45;
}

@media (min-width: 900px) {
  .layout-stream {
    grid-template-columns: 1fr 340px;
  }
}
