:root {
  color-scheme: dark;
  --bg: #11100e;
  --surface: #191715;
  --surface-2: #24211e;
  --line: #38322d;
  --text: #f7f1e8;
  --muted: #b8aca0;
  --accent: #ff5f57;
  --accent-dark: #3b1212;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, rgba(255, 95, 87, 0.12), transparent 28%), linear-gradient(225deg, rgba(32, 201, 151, 0.10), transparent 24%), var(--bg);
  color: var(--text);
}
body.modal-open { overflow: hidden; }
button, input { font: inherit; }
button { cursor: pointer; }
.is-locked { display: none; }

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 22% 20%, rgba(255, 95, 87, 0.22), transparent 32%), #11100e;
}
.access-gate.is-open { display: none; }
.access-panel {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(25, 23, 21, 0.96);
  padding: 24px;
}
.access-panel label { display: grid; gap: 7px; color: var(--muted); }
.access-panel input, .access-panel button, .search-box input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  background: #0d0c0b;
  color: var(--text);
  padding: 12px 14px;
}
.access-panel button {
  background: var(--accent);
  color: #120d0a;
  font-weight: 900;
}
.access-panel small { color: var(--muted); }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 16, 14, 0.92);
  backdrop-filter: blur(18px);
}
.brand-lockup { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 1px solid color-mix(in srgb, var(--accent), white 30%);
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent), black 35%));
  color: #120d0a;
  font-weight: 900;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.35rem; line-height: 1.1; }
.brand-lockup p, .mini-panel span, .tagline { color: var(--muted); }
.search-box {
  display: grid;
  gap: 6px;
  width: min(420px, 42vw);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}
.search-box input:focus, .access-panel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 78%);
}

.main-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 22px;
  padding: 22px 24px 32px;
}
.rhythm-rail { position: sticky; top: 94px; align-self: start; display: grid; gap: 14px; }
.rhythm-buttons, .tag-board, .video-grid { display: grid; gap: 10px; }
.rhythm-button {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(25, 23, 21, 0.86);
  color: var(--text);
  padding: 12px;
  text-align: left;
}
.rhythm-button.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-dark), var(--surface) 38%);
}
.rhythm-swatch { width: 12px; height: 34px; border-radius: 4px; background: var(--button-accent); }
.rhythm-name { display: block; font-weight: 800; }
.rhythm-count { color: var(--muted); font-size: 0.84rem; }
.mini-panel, .tag-group, .empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(25, 23, 21, 0.76);
  padding: 14px;
}
.mini-panel { display: grid; gap: 4px; }

.watch-area { display: grid; gap: 18px; min-width: 0; }
.player-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  place-items: center;
  padding: 18px;
}
.player-modal.is-open { display: grid; }
.player-modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 5, 0.82);
  backdrop-filter: blur(10px);
}
.player-band {
  position: relative;
  z-index: 1;
  width: min(1180px, 100%);
  max-height: calc(100svh - 36px);
  overflow: auto;
  display: grid;
  grid-template-columns: minmax(320px, 1.35fr) minmax(280px, 0.65fr);
  gap: 18px;
  align-items: stretch;
  border: 1px solid color-mix(in srgb, var(--accent), var(--line) 62%);
  border-radius: var(--radius);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent-dark), #15120f 36%), #15120f 72%);
  padding: 14px;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-height: 36px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: var(--radius);
  background: rgba(13,12,11,0.86);
  color: var(--text);
  padding: 7px 10px;
  font-weight: 800;
}
.video-frame {
  overflow: hidden;
  border: 1px solid #000;
  border-radius: var(--radius);
  background: #050505;
  aspect-ratio: 16 / 9;
  position: relative;
}
.stream-frame video, #streamPlayer {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #060606;
}
.video-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  background: #050505;
}
.video-placeholder.hidden { display: none; }
.player-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 8px;
}
.eyebrow-row, .control-row, .filter-band, .segmented, .section-title-row, .card-footer, .card-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.eyebrow, .card-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid color-mix(in srgb, var(--accent), var(--line) 50%);
  border-radius: var(--radius);
  color: var(--text);
  background: color-mix(in srgb, var(--accent), transparent 82%);
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 700;
}
.eyebrow.muted, .card-chip.muted {
  border-color: var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
}
.player-copy h2 { overflow-wrap: anywhere; font-size: 1.8rem; line-height: 1.1; }
.tagline { line-height: 1.45; }
.icon-button, .text-button, .speed-button, .segment, .tag-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 11px;
}
.icon-button { width: 42px; padding: 0; font-size: 1.55rem; }
.text-button.active, .speed-button.active, .segment.active, .tag-button.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent), black 18%);
  color: #100c09;
  font-weight: 800;
}
.filter-band { justify-content: space-between; }
.segmented {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(13,12,11,0.64);
}
.segment { border-color: transparent; background: transparent; }
.tag-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tag-group { display: grid; gap: 10px; }
.tag-group h3 { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; }
.tag-strip { display: flex; flex-wrap: wrap; gap: 7px; }
.tag-button { min-height: 32px; padding: 6px 9px; font-size: 0.84rem; }
.section-title-row { justify-content: space-between; border-top: 1px solid var(--line); padding-top: 6px; }
.section-title-row h2 { font-size: 1.2rem; }
#resultCount { color: var(--muted); }
.video-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.video-card {
  display: flex;
  min-height: 260px;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  background: rgba(25, 23, 21, 0.88);
  color: var(--text);
  padding: 14px;
  text-align: left;
}
.card-media {
  display: block;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: calc(var(--radius) - 2px);
  background: #070706;
}
.card-media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.card-media.is-empty { display: none; }
.video-card:hover, .video-card.active {
  border-color: color-mix(in srgb, var(--accent), white 22%);
  border-left-color: var(--accent);
  transform: translateY(-1px);
}
.video-card.seen { opacity: 0.72; }
.video-card.pending { border-left-color: #67615b; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.video-number {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent), black 16%);
  color: #100c09;
  font-weight: 900;
}
.video-title { overflow-wrap: anywhere; font-size: 1rem; line-height: 1.28; }
.card-tags { align-items: flex-start; }
.card-chip { min-height: 24px; font-size: 0.72rem; padding: 4px 7px; }
.card-footer { justify-content: space-between; color: var(--muted); font-size: 0.82rem; }
.empty-state { grid-column: 1 / -1; color: var(--muted); }

@media (max-width: 1180px) {
  .video-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 920px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }
  .search-box { width: 100%; }
  .main-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 14px 16px 28px;
  }
  .rhythm-rail { position: static; }
  .rhythm-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .player-band { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  body {
    background: linear-gradient(180deg, color-mix(in srgb, var(--accent-dark), #11100e 58%), #11100e 420px);
  }
  .access-gate { padding: 14px; }
  .access-panel { padding: 18px; }
  .topbar {
    gap: 10px;
    padding: 10px 12px 8px;
  }
  .brand-lockup { gap: 10px; }
  .brand-mark { width: 42px; height: 42px; font-size: 0.88rem; }
  h1 { font-size: 1rem; }
  .brand-lockup p { font-size: 0.78rem; }
  .search-box { gap: 5px; font-size: 0.68rem; }
  .search-box input { min-height: 40px; padding: 9px 11px; }

  .main-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px 10px 22px;
  }
  .watch-area {
    display: contents;
  }
  .rhythm-rail { order: 1; }
  .filter-band { order: 3; }
  .tag-board { order: 4; }
  .section-title-row { order: 5; }
  .video-grid { order: 6; }

  .player-modal {
    place-items: stretch;
    padding: 0;
  }
  .player-band {
    width: 100%;
    max-height: 100svh;
    overflow: auto;
    align-content: start;
    gap: 8px;
    border-radius: 0;
    border: 0;
    margin: 0;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: #0a0908;
  }
  .modal-close {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    min-height: 34px;
    font-size: 0.8rem;
  }
  .video-frame {
    width: min(100%, calc((100svh - 128px) * 9 / 16));
    height: min(calc(100svh - 128px), calc(100vw * 16 / 9));
    max-height: none;
    min-height: 0;
    margin: 0 auto;
    aspect-ratio: 9 / 16;
  }
  .player-copy {
    gap: 8px;
    padding: 0;
    justify-content: start;
  }
  .player-copy .control-row {
    order: -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }
  .control-row .icon-button, .control-row .text-button, .control-row .speed-button {
    width: 100%;
    min-height: 32px;
    padding: 5px 6px;
    font-size: 0.82rem;
  }
  .control-row .speed-button {
    font-weight: 800;
    font-size: 0.85rem;
  }
  .eyebrow-row { gap: 6px; }
  .eyebrow { min-height: 24px; padding: 4px 7px; font-size: 0.7rem; }
  .player-copy h2 { font-size: 1.05rem; line-height: 1.2; }
  .tagline {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 0.84rem;
  }

  .rhythm-rail {
    gap: 8px;
    min-width: 0;
  }
  .rhythm-buttons {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    padding: 0 0 2px;
  }
  .rhythm-buttons::-webkit-scrollbar { display: none; }
  .rhythm-button {
    flex: 0 0 auto;
    width: 132px;
    min-height: 46px;
    grid-template-columns: 8px 1fr;
    padding: 9px;
    gap: 8px;
  }
  .rhythm-button > span:last-child { display: none; }
  .rhythm-swatch { width: 8px; height: 28px; }
  .rhythm-name { font-size: 0.88rem; }
  .rhythm-count { font-size: 0.68rem; }
  .mini-panel {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
  }

  .filter-band {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }
  .segmented {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 3px;
  }
  .segmented.compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .segment {
    min-height: 30px;
    padding: 5px 6px;
    font-size: 0.78rem;
  }

  .tag-board {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .tag-group { padding: 10px; gap: 8px; }
  .tag-group h3 { font-size: 0.72rem; }
  .tag-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tag-strip::-webkit-scrollbar { display: none; }
  .tag-button {
    flex: 0 0 auto;
    min-height: 34px;
    max-width: 78vw;
    white-space: nowrap;
  }

  .section-title-row {
    padding-top: 10px;
  }
  .section-title-row h2 { font-size: 1rem; }
  .video-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .video-card {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    min-height: 124px;
    gap: 8px 10px;
    padding: 11px;
    border-left-width: 4px;
  }
  .video-card .card-media {
    grid-row: 1 / span 4;
    aspect-ratio: 3 / 4;
    align-self: stretch;
    min-height: 102px;
  }
  .video-card .card-top,
  .video-card .video-title,
  .video-card .card-tags,
  .video-card .card-footer {
    grid-column: 2;
  }
  .video-card .card-top {
    align-items: center;
  }
  .video-number {
    width: 30px;
    height: 30px;
  }
  .video-title { font-size: 0.94rem; }
  .card-tags {
    max-height: 32px;
    overflow: hidden;
  }
  .card-footer { font-size: 0.76rem; }
}

@media (max-width: 380px) {
  .video-frame {
    width: min(100%, calc((100svh - 126px) * 9 / 16));
    height: min(calc(100svh - 126px), calc(100vw * 16 / 9));
  }
  .player-copy .control-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .control-row .icon-button, .control-row .text-button, .control-row .speed-button {
    min-height: 30px;
    font-size: 0.78rem;
  }
}
