:root {
  color-scheme: dark;
  --bg: #070707;
  --bg-soft: #101010;
  --surface: #171717;
  --surface-2: #242424;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f7f7f7;
  --muted: #a7adb4;
  --accent: #e50914;
  --accent-2: #2cc9a8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 5px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  min-height: 38px;
  padding: 0 14px;
}

button.secondary,
.nav button {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
  min-height: 38px;
  padding: 0 12px;
}

.app {
  min-height: 100vh;
}

.auth-view {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(7, 7, 7, 0.96), rgba(7, 7, 7, 0.78)),
    linear-gradient(135deg, rgba(229, 9, 20, 0.38), rgba(44, 201, 168, 0.18)),
    #070707;
}

.auth-card {
  display: grid;
  gap: 16px;
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 10, 10, 0.92);
  padding: 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

.auth-card h1 {
  font-size: 32px;
  line-height: 1;
}

.auth-error {
  min-height: 20px;
  color: #ff8a8a;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px 22px;
  min-height: 96px;
  padding: 12px 42px;
  background: rgba(7, 7, 7, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(14px);
}

.search-row {
  grid-column: 1 / -1;
}

.search-row input {
  width: min(720px, 100%);
}

.brand,
.nav,
.hero-actions,
.rail-header,
.library {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  font-size: 20px;
}

.mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 5px;
  background: var(--accent);
  font-weight: 900;
}

.nav {
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav button {
  white-space: nowrap;
}

.nav button.active {
  background: white;
  color: #050505;
}

.nav .settings-nav-button {
  background: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: white;
}

main {
  min-width: 0;
  padding-bottom: 56px;
}

.hero {
  display: grid;
  align-items: end;
  min-height: 430px;
  padding: 120px 42px 44px;
  background:
    linear-gradient(90deg, rgba(7, 7, 7, 0.96), rgba(7, 7, 7, 0.62), rgba(7, 7, 7, 0.9)),
    linear-gradient(135deg, rgba(229, 9, 20, 0.42), rgba(44, 201, 168, 0.22)),
    #121212;
}

.hero > div {
  max-width: 720px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(42px, 6vw, 72px);
  line-height: 0.95;
  margin: 8px 0 16px;
}

h2 {
  font-size: 22px;
}

p,
small,
.rail-header span {
  color: var(--muted);
}

.hero-actions {
  gap: 10px;
  margin-top: 22px;
}

.rail {
  margin-top: 30px;
  padding-left: 42px;
}

.rail-header {
  justify-content: space-between;
  gap: 16px;
  padding-right: 42px;
  margin-bottom: 12px;
}

.rail-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 190px;
  gap: 12px;
  overflow-x: auto;
  padding: 3px 42px 14px 0;
  scroll-snap-type: x proximity;
}

.channel-row {
  grid-auto-columns: 260px;
}

.poster-card,
.channel-card {
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  scroll-snap-align: start;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.poster-card:hover,
.channel-card:hover {
  border-color: rgba(255, 255, 255, 0.32);
  background: var(--surface-2);
  transform: translateY(-3px);
}

.poster-art {
  position: relative;
  display: grid;
  align-items: end;
  aspect-ratio: 2 / 3;
  padding: 10px;
  background:
    linear-gradient(160deg, rgba(229, 9, 20, 0.82), rgba(44, 201, 168, 0.2)),
    linear-gradient(35deg, #292929, #0d0d0d);
  background-position: center;
  background-size: cover;
}

.poster-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 180ms ease;
}

.poster-card.previewing .poster-preview {
  opacity: 1;
}

.poster-card.previewing .poster-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 45%, rgba(0, 0, 0, 0.82));
}

.poster-art span {
  position: relative;
  z-index: 1;
  width: max-content;
  max-width: 100%;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.58);
  color: white;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
  text-transform: uppercase;
}

.card-copy {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.card-copy strong,
.channel-card strong {
  overflow-wrap: anywhere;
}

.progress {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.channel-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 92px;
  padding: 12px;
}

.channel-logo {
  display: grid;
  place-items: center;
  width: 72px;
  height: 52px;
  border-radius: 5px;
  background: #0b0b0b;
  color: var(--accent-2);
  font-weight: 900;
}

.channel-logo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.tv-guide {
  width: min(1180px, calc(100vw - 84px));
  margin: 0 42px 18px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.035);
  overflow: hidden;
}

.guide-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.guide-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.guide-tabs button {
  min-height: 32px;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.08);
}

.guide-tabs button.active {
  background: white;
  color: #050505;
}

.guide-table {
  max-height: 560px;
  overflow: auto;
}

.guide-row {
  display: grid;
  grid-template-columns: 56px 70px minmax(180px, 1fr) minmax(150px, 220px) auto;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  cursor: pointer;
}

.guide-row:hover {
  background: rgba(255, 255, 255, 0.07);
}

.guide-number {
  color: var(--muted);
  font-weight: 800;
}

.guide-logo {
  display: grid;
  place-items: center;
  width: 64px;
  height: 42px;
  border-radius: 5px;
  background: #0b0b0b;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
}

.guide-logo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.guide-main,
.guide-status {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.guide-main strong {
  overflow-wrap: anywhere;
}

.guide-status span {
  width: max-content;
  border-radius: 999px;
  background: rgba(44, 201, 168, 0.15);
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  padding: 3px 8px;
}

.library-form,
.user-form,
.metadata-settings-form,
.remote-access-form {
  display: grid;
  grid-template-columns: 1fr 2fr 180px auto;
  gap: 10px;
  margin: 16px 0;
}

.user-form {
  grid-template-columns: 1fr 1fr 140px auto;
}

.metadata-settings-form {
  grid-template-columns: minmax(240px, 1fr) auto auto;
  align-items: center;
}

.remote-access-form {
  grid-template-columns: minmax(220px, 1fr) 180px auto;
  margin: 0;
}

.metadata-settings-form div {
  display: grid;
  gap: 4px;
}

.danger {
  color: #ffb3b3;
}

.settings-dialog {
  width: min(1080px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
  overflow: hidden;
}

.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

#closeSettings {
  width: 38px;
  padding: 0;
}

.settings-layout {
  display: grid;
  grid-template-columns: 190px 1fr;
  min-height: 560px;
}

.settings-nav {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
}

.settings-nav button {
  justify-content: start;
  text-align: left;
  background: transparent;
  color: var(--text);
}

.settings-nav button.active {
  background: white;
  color: #050505;
}

.settings-content {
  max-height: calc(100vh - 120px);
  overflow: auto;
  padding: 16px;
}

.settings-panel {
  display: none;
  gap: 14px;
}

.settings-panel.active {
  display: grid;
}

.settings-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
}

.settings-card > div:first-child {
  display: grid;
  gap: 4px;
}

.install-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.remote-access-options {
  display: grid;
  gap: 12px;
}

.remote-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
}

.remote-card > div:first-child {
  display: grid;
  gap: 4px;
}

.remote-card ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.remote-card code {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.42);
  color: var(--text);
  padding: 9px 10px;
}

.library-list {
  display: grid;
  gap: 8px;
}

.user-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.user-row {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 10px;
}

.library {
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 12px;
}

.library div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.library small {
  overflow-wrap: anywhere;
}

.empty {
  display: grid;
  align-content: center;
  min-height: 120px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  padding: 18px;
}

.hidden {
  display: none;
}

dialog {
  width: min(1120px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #030303;
  color: var(--text);
  padding: 0;
}

#detailsDialog {
  width: min(1180px, calc(100vw - 28px));
}

.details-backdrop {
  min-height: 250px;
  background:
    linear-gradient(90deg, rgba(3, 3, 3, 0.96), rgba(3, 3, 3, 0.62)),
    #101010;
  background-position: center;
  background-size: cover;
}

.details-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
}

#closeDetails {
  width: 38px;
  padding: 0;
  background: rgba(255, 255, 255, 0.12);
}

.details-body {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  padding: 18px;
}

.details-poster {
  min-height: 330px;
  border-radius: 6px;
  background:
    linear-gradient(160deg, rgba(229, 9, 20, 0.82), rgba(44, 201, 168, 0.2)),
    #181818;
  background-position: center;
  background-size: cover;
}

.details-copy {
  display: grid;
  gap: 16px;
}

.metadata-search-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.metadata-search-results {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.metadata-result {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px;
}

.metadata-result div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.chip-row,
.external-row,
.details-actions,
.cast-row,
.recommendation-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.recommendation-row:has(.season-block) {
  display: grid;
  gap: 14px;
}

.chip-row span,
.external-row span,
.external-row a {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 5px 10px;
  font-size: 13px;
  text-decoration: none;
}

.external-row a {
  background: rgba(229, 9, 20, 0.24);
}

.cast-card,
.recommendation-card {
  display: grid;
  gap: 6px;
  width: 120px;
}

.cast-photo,
.recommendation-poster {
  width: 120px;
  height: 160px;
  border-radius: 6px;
  background: #151515;
  background-position: center;
  background-size: cover;
}

.cast-card strong,
.recommendation-card strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.cast-card small,
.recommendation-card small {
  font-size: 12px;
}

.season-block {
  display: grid;
  gap: 8px;
  width: 100%;
}

.season-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.episode-list {
  display: grid;
  gap: 8px;
}

.episode-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px;
}

.episode-thumb {
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  background: #151515;
  background-position: center;
  background-size: cover;
}

.episode-row div:nth-child(2) {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.episode-row strong,
.episode-row small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.84);
}

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

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

#closePlayer {
  width: 38px;
  padding: 0;
  background: rgba(255, 255, 255, 0.12);
}

.player-shell {
  position: relative;
}

video {
  display: block;
  width: 100%;
  max-height: 72vh;
  background: #000;
}

.trickplay-preview {
  position: absolute;
  bottom: 54px;
  z-index: 3;
  display: grid;
  gap: 6px;
  width: 180px;
  pointer-events: none;
  transform: translateY(-4px);
}

.trickplay-preview.hidden {
  display: none;
}

.trickplay-preview img {
  width: 180px;
  aspect-ratio: 16 / 9;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 5px;
  background: #050505;
  object-fit: cover;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.58);
}

.trickplay-preview span {
  justify-self: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  color: white;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 8px;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 12px;
    padding: 14px 18px;
  }

  .search-row {
    grid-column: auto;
  }

  .search-row input {
    width: 100%;
  }

  .hero {
    min-height: 360px;
    padding: 90px 18px 34px;
  }

  .rail {
    padding-left: 18px;
  }

  .rail-header {
    padding-right: 18px;
  }

  .rail-row {
    grid-auto-columns: 158px;
    padding-right: 18px;
  }

  .channel-row {
    grid-auto-columns: 230px;
  }

  .tv-guide {
    width: calc(100vw - 36px);
    margin-right: 18px;
  }

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

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

  .guide-status,
  .guide-row button {
    display: none;
  }

  .library-form,
  .user-form,
  .metadata-settings-form,
  .remote-access-form {
    grid-template-columns: 1fr;
  }

  .settings-dialog {
    width: calc(100vw - 18px);
    max-height: calc(100vh - 18px);
  }

  .settings-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .settings-nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .settings-content {
    max-height: calc(100vh - 220px);
  }

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

  .install-actions {
    flex-direction: column;
  }

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

  .details-poster {
    min-height: 260px;
  }

  .episode-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .episode-row button {
    width: 100%;
  }
}
