* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #0b0b0d;
  --surface: #121215;
  --surface-2: #19191e;
  --surface-3: #212128;
  --border: #26262e;
  --text: #ececef;
  --muted: #8a8a96;
  --accent: #7aa7ff;
  --accent-soft: rgba(122, 167, 255, 0.14);
  --ok: #6bcb77;
  --err: #f07178;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 12px;
  --gap: 16px;
  --bar-h: 52px;
  --pad: clamp(12px, 1.6vw, 24px);
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font: 14px/1.5 var(--sans);
  color: var(--text);
  background: var(--bg);
}

a {
  color: inherit;
}

/* ───────── Top bar ───────── */

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: var(--bar-h);
  padding: 0 clamp(14px, 2.5vw, 28px);
  border-bottom: 1px solid var(--border);
  background: rgba(11, 11, 13, 0.85);
  backdrop-filter: blur(10px);
}

.bar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.bar__logo {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--err);
  box-shadow: 0 0 0 4px rgba(240, 113, 120, 0.18);
  flex: none;
}

.bar__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar__title span {
  font-weight: 500;
  color: var(--muted);
}

.bar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar__actions .btn {
  min-height: 34px;
  padding: 5px 12px;
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .bar__host {
    display: none;
  }
}

.bar__host {
  font: 0.78rem var(--mono);
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.bar__host:hover {
  color: var(--accent);
  border-color: var(--accent);
}

@media (max-width: 480px) {
  .bar__title span {
    display: none;
  }
}

/* ───────── Shell layout ───────── */

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  width: min(1920px, 100%);
  margin: 0 auto;
  padding: var(--gap) var(--pad) calc(32px + env(safe-area-inset-bottom));
  align-items: start;
}

.stage {
  display: grid;
  gap: 14px;
  min-width: 0;
}

/* ── Desktop: two columns. The player grows with the window but never taller
   than what fits on screen, so the title, servers and channel list stay in view. ── */
@media (min-width: 960px) {
  .shell {
    grid-template-columns: minmax(0, 1fr) clamp(320px, 26vw, 520px);
    gap: 20px;
  }

  .stage {
    /* fill the column; only shrink if the window is too short to also show the controls */
    --stage-w: min(100%, calc((100dvh - 215px) * 16 / 9));
    justify-items: center;
  }

  .stage > * {
    width: var(--stage-w);
  }

  .channels {
    position: sticky;
    top: calc(var(--bar-h) + var(--gap));
    height: calc(100dvh - var(--bar-h) - var(--gap) * 2);
  }
}

/* ── Tablet and phone: one column, player pinned under the top bar so you can
   keep browsing channels while it plays. ── */
@media (max-width: 959px) {
  .stage {
    display: contents;
  }

  .player {
    position: sticky;
    top: var(--bar-h);
    z-index: 10;
    margin-inline: calc(var(--pad) * -1);
    border-radius: 0;
    border-width: 1px 0;
    order: 0;
  }

  .player video {
    max-height: 46dvh;
  }

  .now {
    order: 1;
  }

  .servers-wrap {
    order: 2;
  }

  .msg--err {
    order: 3;
  }

  .stream-notes {
    order: 3;
  }

  .channels {
    order: 4;
  }

  .export {
    order: 5;
  }
}

@media (max-width: 959px) and (max-height: 520px) {
  /* landscape phones: no room to pin the player */
  .player {
    position: static;
  }

  .player video {
    max-height: 80dvh;
  }
}

@media (pointer: coarse) {
  .badge,
  .channel-btn {
    min-height: 48px;
  }

  .chip {
    min-height: 34px;
  }
}

/* ───────── Player ───────── */

.player {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #000;
}

video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(18, 18, 21, 0.92), rgba(0, 0, 0, 0.96));
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.overlay[hidden],
.overlay.is-off {
  opacity: 0;
  visibility: hidden;
}

.overlay__text {
  margin: 0;
  max-width: 28rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.overlay[data-kind="error"] .overlay__text {
  color: var(--err);
}

.overlay[data-kind="loading"] .overlay__text {
  color: var(--text);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner[hidden] {
  display: none;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.5s;
  }
}

/* ───────── Now playing ───────── */

.now {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 18px;
}

.now__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.timing {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
}

.timing[hidden] {
  display: none;
}

.timing__item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
}

.timing__label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.timing__value {
  margin: 0;
  font: 0.82rem/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
}

.label {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.count {
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ───────── Servers (segmented) ───────── */

.servers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

@media (min-width: 640px) {
  .servers {
    grid-template-columns: repeat(6, 1fr);
  }
}

.badge {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #34343f;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.badge:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--accent);
}

.badge--active {
  background: var(--accent-soft);
  border-color: rgba(122, 167, 255, 0.45);
  color: var(--accent);
}

.badge--fail {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: rgba(240, 113, 120, 0.7);
}

.badge--fail.badge--active {
  color: var(--err);
  background: rgba(240, 113, 120, 0.08);
  border-color: rgba(240, 113, 120, 0.4);
}

.badge__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--surface-3);
}

.badge--ok .badge__dot {
  background: var(--ok);
}

.badge--fail .badge__dot {
  background: var(--err);
}

.badge--running {
  cursor: progress;
  color: var(--text);
}

.badge--running .badge__dot {
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

/* ───────── Messages / notes ───────── */

.msg--err {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(240, 113, 120, 0.35);
  border-radius: 8px;
  background: rgba(240, 113, 120, 0.07);
  font-size: 0.88rem;
  color: var(--err);
}

.msg--err[hidden] {
  display: none;
}

.stream-notes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 28px;
}

.stream-notes[hidden] {
  display: none;
}

.stream-notes li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 0.85rem;
}

.stream-notes__label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.stream-notes__text--warn {
  color: var(--err);
}

/* ───────── Export ───────── */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.export[hidden] {
  display: none;
}

.export summary {
  padding: 14px 16px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.export summary::-webkit-details-marker {
  display: none;
}

.export summary::after {
  content: "＋";
  color: var(--muted);
  font-weight: 400;
}

.export[open] summary::after {
  content: "－";
}

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

.exports {
  list-style: none;
  margin: 0;
  padding: 2px 16px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 16px 20px;
}

.export__meta {
  display: grid;
  gap: 1px;
  margin-bottom: 6px;
}

.export__name {
  font-size: 0.86rem;
  font-weight: 600;
}

.export__hint {
  font-size: 0.76rem;
  color: var(--muted);
}

.pill {
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(107, 203, 119, 0.14);
  color: var(--ok);
  font-size: 0.66rem;
  font-style: normal;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.export__row {
  display: flex;
  gap: 8px;
}

@media (max-width: 540px) {
  .export__row {
    flex-direction: column;
  }

  .export__row button {
    width: 100%;
  }
}

/* ───────── Inputs / buttons ───────── */

input[type="number"],
input[type="search"],
.export__row input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.export__row input {
  font: 0.78rem/1.4 var(--mono);
}

input::placeholder {
  color: var(--muted);
}

input:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled),
.btn:hover {
  background: var(--surface-3);
  border-color: #3a3a46;
}

.btn--accent {
  background: var(--accent-soft);
  border-color: rgba(122, 167, 255, 0.45);
  color: var(--accent);
  font-weight: 600;
}

.btn--accent:hover {
  background: rgba(122, 167, 255, 0.22);
  border-color: var(--accent);
}

button.ok {
  color: var(--ok);
  border-color: rgba(107, 203, 119, 0.45);
}

button.err {
  color: var(--err);
  border-color: rgba(240, 113, 120, 0.45);
}

/* ───────── Channels panel ───────── */

.channels {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.channels__head {
  display: grid;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.channels__top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.channels__top .label {
  margin: 0;
}

.goto {
  display: flex;
  align-items: center;
  gap: 8px;
}

.goto__label {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.goto input {
  width: 84px;
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 0.85rem;
}

.search {
  order: -1;
  position: relative;
}

.search input {
  padding: 13px 40px 13px 40px;
  border-radius: 10px;
  font-size: 0.95rem;
  background: var(--bg);
  border-color: #34343f;
}

.search input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 11px;
  height: 11px;
  margin-top: -7px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  pointer-events: none;
}

.search::after {
  content: "";
  position: absolute;
  left: 24px;
  top: 50%;
  width: 6px;
  height: 2px;
  margin-top: 5px;
  background: var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}

.search__key {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  font: 0.72rem/1.6 var(--mono);
  pointer-events: none;
}

.search input:not(:placeholder-shown) ~ .search__key,
.search input:focus ~ .search__key {
  display: none;
}

mark {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(122, 167, 255, 0.5);
}

.channels__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  max-height: min(60dvh, 520px);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  grid-auto-rows: min-content;
  gap: 2px;
}

.channels__list > .channels__empty {
  grid-column: 1 / -1;
}

@media (min-width: 960px) {
  .channels__list {
    max-height: none;
  }
}

.channel-btn {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: left;
  white-space: normal;
  line-height: 1.3;
}

.channel-btn:hover {
  background: var(--surface-2);
}

.channel-btn--active {
  background: var(--accent-soft);
  color: var(--accent);
}

.channel-btn--active:hover {
  background: var(--accent-soft);
}

.channel-btn__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.channel-btn__id {
  font: 0.72rem var(--mono);
  color: var(--muted);
  white-space: nowrap;
}

.channels__empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.channels__foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.channels__foot > * {
  flex: 1;
}

/* ───────── Panel tabs ───────── */

.channels__tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 10px 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tab--active {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--accent);
}

.panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.panel[hidden] {
  display: none;
}

/* ───────── Events panel ───────── */

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

.events__hint {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
}

.events__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
  max-height: min(60dvh, 520px);
}

@media (min-width: 960px) {
  .events__list {
    max-height: none;
  }
}

.events__empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.event-section {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}

.event-section summary {
  padding: 10px 12px;
  font-size: 0.86rem;
  font-weight: 650;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-section summary::after,
.event-cat summary::after {
  flex: none;
}

.event-section summary::-webkit-details-marker {
  display: none;
}

.event-section summary::after {
  content: "＋";
  color: var(--muted);
  font-weight: 400;
}

.event-section[open] summary::after {
  content: "－";
}

.event-section summary:hover {
  color: var(--accent);
}

.event-day {
  padding: 0 6px 6px;
}

.event-day__title {
  padding: 8px 6px 4px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.event-cat {
  border-top: 1px solid var(--border);
}

.event-cat summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.event-cat summary::-webkit-details-marker {
  display: none;
}

.event-cat summary::after {
  content: "▸";
  color: var(--muted);
  font-size: 0.7rem;
}

.event-cat[open] summary::after {
  content: "▾";
}

.event-cat summary:hover {
  color: var(--accent);
}

.event-cat__body {
  display: grid;
  gap: 2px;
  padding: 2px 4px 8px;
}

.event {
  display: grid;
  gap: 5px;
  padding: 8px;
  border-radius: 8px;
}

.event:hover {
  background: var(--surface-3);
}

.event__main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.event__time {
  flex: none;
  font: 0.74rem var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.event__title {
  font-size: 0.84rem;
  line-height: 1.35;
  word-break: break-word;
  min-width: 0;
}

.event__ctx {
  flex: none;
  margin-left: auto;
  font-size: 0.66rem;
  color: var(--muted);
  white-space: nowrap;
}

.event__channels {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.event__none {
  font-size: 0.72rem;
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 26px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 0.73rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.chip--play {
  border-color: rgba(122, 167, 255, 0.35);
}

.chip--play:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.chip--active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.chip--ext {
  color: var(--muted);
}

.chip--ext:hover {
  color: var(--text);
  border-color: #3a3a46;
}
