:root {
  color-scheme: dark;
  --bg: #111312;
  --panel: #1b211e;
  --panel-2: #242b27;
  --line: #38423c;
  --text: #edf3ef;
  --muted: #a9b8af;
  --accent: #4cc38a;
  --accent-2: #6ea8ff;
  --danger: #ff8a7a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.1;
}

#summary {
  margin-top: 8px;
  color: var(--muted);
}

button,
.copy,
.button-link,
.player-button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  min-height: 40px;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

button:hover,
.copy:hover,
.button-link:hover,
.player-button:hover {
  border-color: var(--accent);
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.status {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 8px;
  padding: 18px;
}

.status.error {
  border-color: var(--danger);
  color: var(--danger);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(0 0 0 / 72%);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  position: relative;
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
  box-shadow: 0 24px 70px rgb(0 0 0 / 45%);
}

.modal h2 {
  padding-right: 44px;
  font-size: 22px;
}

.modal p {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.metrics-panel {
  margin-top: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 18px;
}

.metrics-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.metrics-head h2 {
  font-size: 20px;
}

#metricsSummary {
  color: var(--muted);
  margin-top: 6px;
}

.metrics-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.monthly-bandwidth {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.monthly-bandwidth div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0f0e;
  padding: 14px;
}

.monthly-bandwidth span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.monthly-bandwidth strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

.legend-item {
  font-size: 12px;
  font-weight: 700;
}

.legend-item.cpu {
  color: var(--accent);
}

.legend-item.inbound {
  color: var(--accent-2);
}

.legend-item.outbound {
  color: #ffd45c;
}

#metricsChart {
  display: block;
  width: 100%;
  height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0f0e;
}

.card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.card h2 {
  font-size: 20px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.stream-title-link {
  color: var(--text);
  text-decoration: none;
}

.stream-title-link:hover {
  color: var(--accent);
}

.meta {
  color: var(--muted);
  margin-top: 6px;
  font-size: 14px;
}

.badge {
  border: 1px solid rgba(76, 195, 138, 0.45);
  color: var(--accent);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
}

.badge.offline {
  border-color: rgba(255, 138, 122, 0.45);
  color: var(--danger);
}

.preview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  gap: 10px;
  align-items: stretch;
}

.video-shell {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #050706;
}

.preview video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 180px;
  max-height: 360px;
  object-fit: contain;
  background: #050706;
}

.player-controls {
  display: grid;
  grid-template-columns: auto auto minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: rgba(13, 15, 14, 0.96);
}

.player-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.mute-toggle {
  gap: 8px;
}

.speaker-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  overflow: hidden;
  text-indent: -999px;
  position: relative;
}

.speaker-icon::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 5px;
  width: 6px;
  height: 8px;
  background: currentColor;
  clip-path: polygon(0 25%, 45% 25%, 100% 0, 100% 100%, 45% 75%, 0 75%);
}

.speaker-icon::after {
  content: "";
  position: absolute;
}

.is-muted .speaker-icon::after {
  left: 12px;
  top: 2px;
  width: 2px;
  height: 15px;
  background: var(--danger);
  transform: rotate(45deg);
}

.is-live-audio {
  border-color: rgba(76, 195, 138, 0.7);
  color: var(--accent);
}

.is-live-audio .speaker-icon::after {
  right: 0;
  top: 4px;
  width: 8px;
  height: 10px;
  border: 2px solid currentColor;
  border-left: 0;
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
}

.volume-control {
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr);
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}

.volume-control span {
  text-transform: uppercase;
}

.volume-range {
  width: 100%;
  accent-color: var(--accent);
}

.meter {
  position: relative;
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background:
    linear-gradient(to top, rgba(76, 195, 138, 0.16), rgba(255, 205, 86, 0.16) 72%, rgba(255, 138, 122, 0.2)),
    #0d0f0e;
}

.meter::before,
.meter::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid rgba(237, 243, 239, 0.18);
  z-index: 2;
}

.meter::before {
  bottom: 72%;
}

.meter::after {
  bottom: 90%;
}

.meter-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: linear-gradient(to top, var(--accent), #ffd45c 72%, var(--danger));
  transition: height 80ms linear;
}

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

.details div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

dd {
  margin: 6px 0 0;
  font-size: 16px;
}

.links {
  display: grid;
  gap: 8px;
}

.outputs-accordion {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.outputs-accordion summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  min-height: 34px;
  display: flex;
  align-items: center;
}

.outputs-accordion summary:hover {
  color: var(--accent);
}

.outputs-accordion-body {
  display: grid;
  gap: 8px;
  padding-top: 8px;
}

.link-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 74px;
  align-items: center;
  gap: 8px;
}

.protocol {
  color: var(--accent-2);
  font-weight: 700;
  font-size: 13px;
}

.featured-output-link {
  margin-bottom: 2px;
}

.featured-output-link .protocol,
.featured-output-link code {
  color: var(--accent);
}

.featured-output-link code {
  border-color: rgba(76, 195, 138, 0.45);
  background: rgba(76, 195, 138, 0.08);
}

code {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  background: #0d0f0e;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.stream-page {
  background:
    radial-gradient(circle at top left, rgba(76, 195, 138, 0.18), transparent 32rem),
    linear-gradient(135deg, #111312 0%, #171b19 48%, #101312 100%);
}

.watch-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 24px;
}

.watch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-link {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.watch-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.watch-player {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #050706;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.watch-player video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 520px;
  max-height: calc(100vh - 210px);
  object-fit: contain;
  background: #050706;
}

.watch-player video[hidden],
.watch-controls[hidden],
.watch-offline[hidden] {
  display: none;
}

.watch-controls {
  border-top-color: var(--line);
}

.watch-offline {
  min-height: 520px;
  aspect-ratio: 16 / 9;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.watch-offline h1 {
  font-size: clamp(28px, 4vw, 52px);
}

.watch-offline p,
.watch-status {
  color: var(--muted);
}

.watch-panel {
  border: 1px solid var(--line);
  background: rgba(27, 33, 30, 0.86);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(260px, auto) minmax(180px, 1fr);
  gap: 14px;
  align-items: center;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.watch-panel h1 {
  overflow-wrap: anywhere;
}

.watch-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}

.watch-stats div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: #0d0f0e;
}

.watch-stats dd {
  font-size: 22px;
  font-weight: 700;
}

.watch-status {
  text-align: right;
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding: 18px 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .metrics-head {
    flex-direction: column;
  }

  .metrics-legend {
    justify-content: flex-start;
  }

  .monthly-bandwidth {
    grid-template-columns: 1fr;
  }

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

  .link-row {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .preview {
    grid-template-columns: minmax(0, 1fr) 14px;
  }

  .player-controls {
    grid-template-columns: 1fr 1fr;
  }

  .volume-control {
    grid-column: 1 / -1;
  }

  .preview video,
  .meter {
    min-height: 170px;
  }

  .copy {
    grid-column: 2;
  }
}

@media (max-width: 860px) {
  .watch-shell {
    width: min(100% - 20px, 1180px);
    padding: 16px 0;
  }

  .watch-layout {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .watch-panel {
    grid-template-columns: 1fr;
  }

  .watch-status {
    text-align: left;
  }

  .watch-player video,
  .watch-offline {
    min-height: 220px;
  }
}
