:root {
  --bg:        #0f0f13;
  --bg-card:   #1a1a24;
  --bg-hover:  #22223a;
  --accent:    #7b5ea7;
  --accent-hi: #9b7ec8;
  --text:      #e8e8f0;
  --text-muted:#8888aa;
  --border:    #2a2a3a;
  --radius:    8px;
  --navbar-h:  60px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ── Navbar ────────────────────────────────────────────────────────────────── */

.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 2rem;
  background: rgba(15,15,19,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.3rem;
  font-weight: 700;
  flex-shrink: 0;
}

.logo-icon { color: var(--accent); font-size: 1.5rem; }
.logo-text  { color: var(--text); }

.nav-links {
  display: flex;
  gap: .5rem;
}

.nav-link {
  color: var(--text-muted);
  font-size: .95rem;
  padding: .3rem .75rem;
  border-radius: 999px;
  transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); }

.nav-search { flex: 1; max-width: 400px; }

.search-input {
  width: 100%;
  padding: .45rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 2rem;
  color: var(--text);
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.nav-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.username {
  color: var(--text-muted);
  font-size: .9rem;
}

.nav-link { white-space: nowrap; }

/* Tablets in portrait (iPad 768–1000 px): the full bar only fits a little tighter. */
@media (max-width: 1000px) {
  .navbar { gap: 1rem; padding: 0 1rem; }
  .nav-links { gap: 0; }
  .nav-link { padding: .3rem .5rem; }
  .nav-search { min-width: 0; }
  .nav-user { gap: .5rem; }
  html:not(.is-phone) .username { display: none; }
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */

.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.3rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, color .15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hi); }
.btn-primary:disabled { opacity: .5; cursor: default; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: .4rem .8rem;
}
.btn-ghost:hover { color: var(--text); }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.3rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: #c0392b;
  color: #fff;
  transition: background .15s;
}
.btn-danger:hover { background: #e74c3c; }

.btn-xs {
  padding: .3rem .7rem;
  font-size: .8rem;
}

/* ── Main layout ───────────────────────────────────────────────────────────── */

.main-content {
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Sections & grid ───────────────────────────────────────────────────────── */

.section { margin-bottom: 3rem; }

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--text);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}

@media (min-width: 600px)  { .card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); } }
@media (min-width: 1000px) { .card-grid { grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); } }

/* ── Media card ────────────────────────────────────────────────────────────── */

.media-card {
  display: block;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform .2s, border-color .2s;
  cursor: pointer;
}
.media-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
}

.media-card__poster {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
}

.media-card__no-poster {
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  font-size: .85rem;
  color: var(--text-muted);
  text-align: center;
}

.media-card__info {
  padding: .6rem .75rem .75rem;
}

.media-card__title {
  font-size: .85rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.media-card__year {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ── Detail page ───────────────────────────────────────────────────────────── */

.detail-hero {
  position: relative;
  min-height: 420px;
  background-color: var(--bg-card);
  background-size: cover;
  background-position: center top;
  border-radius: var(--radius);
  overflow: hidden;
}

.detail-hero__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgba(15,15,19,.95) 40%, rgba(15,15,19,.6));
}

.detail-hero__content {
  position: relative;
  display: flex;
  gap: 2rem;
  padding: 2.5rem;
  align-items: flex-start;
}

.detail-poster {
  width: 180px;
  flex-shrink: 0;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
}

.detail-info { max-width: 600px; }

.detail-title {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: .75rem;
}

.detail-meta {
  display: flex;
  gap: 1rem;
  font-size: .9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.detail-overview {
  font-size: .95rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.detail-actions {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}

/* ── Auth pages ────────────────────────────────────────────────────────────── */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.auth-container {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 2.5rem;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
}

.auth-card h1 {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: .9rem;
  margin-bottom: 1.5rem;
  margin-top: -.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .85rem;
  color: var(--text-muted);
}

.auth-form input {
  padding: .6rem .9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--accent); }

.auth-form .btn-primary {
  margin-top: .5rem;
  width: 100%;
  justify-content: center;
  padding: .7rem;
}

.error-msg {
  background: rgba(180, 60, 60, .15);
  border: 1px solid rgba(180, 60, 60, .4);
  color: #e88;
  border-radius: var(--radius);
  padding: .6rem .9rem;
  font-size: .875rem;
  margin-bottom: 1rem;
}

/* ── Misc ──────────────────────────────────────────────────────────────────── */

.empty-state {
  color: var(--text-muted);
  font-size: .95rem;
  padding: 2rem 0;
}

.pagination {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  justify-content: center;
}

/* Stream status */
.stream-status { margin-top: 0.75rem; min-height: 1.5rem; }
.stream-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.stream-error {
  color: #e05c5c;
  font-size: 0.85rem;
}
.htmx-indicator {
  display: none;
  color: var(--text-muted, #888);
  font-size: 0.85rem;
  font-style: italic;
}
.htmx-request .htmx-indicator { display: inline; }

.stream-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; align-items: center; }
.btn-small { padding: 0.35rem 0.75rem; font-size: 0.8rem; border-radius: 4px; cursor: pointer; text-decoration: none; border: none; display: inline-block; }
.btn-primary.btn-small { background: var(--accent); color: #fff; }
.btn-secondary.btn-small { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-ghost.btn-small { background: transparent; color: var(--text, #e8e8f0); }

/* Video player */
.player-wrap { margin-top: 0.75rem; }

.player-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  max-width: 960px;
}

.player-ext-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

.player-ext-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.player-ext-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--bg-hover);
}
.player-ext-btn.active,
.player-ext-btn.casting {
  color: var(--accent);
  border-color: var(--accent);
}

.player-video {
  display: block;
  width: 100%;
  max-width: 960px;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 6px;
  outline: none;
}

/* Subscription button */
.btn-subscribed {
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
}
.btn-subscribed:hover {
  background: rgba(139,92,246,0.12);
}

/* ── Seasons / Episodes ────────────────────────────────────────────────────── */

.seasons-section {
  margin-top: 2.5rem;
}

.season-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .75rem;
  overflow: hidden;
}

.season-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .9rem 1.25rem;
  background: var(--bg-card);
  border: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background .15s;
}
.season-toggle:hover { background: var(--bg-hover); }

.season-name  { font-weight: 600; font-size: .95rem; flex: 1; }
.season-meta  { font-size: .82rem; color: var(--text-muted); }
.season-chevron {
  font-size: 1.3rem;
  color: var(--text-muted);
  transition: transform .2s;
  line-height: 1;
}
.season-item.open .season-chevron { transform: rotate(90deg); }

.season-episodes-wrap { background: var(--bg); }

.season-episodes { padding: .25rem 0; }

.episode-row {
  display: flex;
  gap: 1rem;
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  align-items: flex-start;
}
.episode-row:first-child { border-top: none; }
.episode-row:hover { background: var(--bg-hover); }

.episode-still {
  flex-shrink: 0;
  width: 120px;
}
.episode-still img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}
.episode-still__placeholder {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg-card);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 700;
}

.episode-info { flex: 1; min-width: 0; }

.episode-header {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: .3rem;
}
.episode-num     { font-size: .78rem; color: var(--accent); font-weight: 700; white-space: nowrap; }
.episode-title   { font-size: .9rem;  font-weight: 600; }
.episode-runtime { font-size: .78rem; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.episode-watched-badge {
  color: #4caf82;
  font-weight: 700;
  font-size: .85rem;
}
.episode-row--watched .episode-title { opacity: .55; }

.episode-overview {
  font-size: .82rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.episode-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

/* ── TV / Remote-control mode ───────────────────────────────────────────────
   Activated by JS when Tizen / Google TV / WebOS UA is detected,
   or when running as a fullscreen PWA.                                      */

.tv-mode {
  font-size: 20px;
}

/* Global focus ring — must be visible from 3 m away */
.tv-mode :focus {
  outline: 4px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius);
}
.tv-mode :focus-visible {
  outline: 4px solid var(--accent-hi);
  outline-offset: 3px;
}

/* Navbar */
.tv-mode .navbar {
  height: 72px;
  padding: 0 3rem;
  gap: 3rem;
}
.tv-mode .nav-logo  { font-size: 1.6rem; }
.tv-mode .nav-link  { font-size: 1.1rem; padding: 0.4rem 0.8rem; border-radius: var(--radius); }
.tv-mode .nav-link:focus { background: var(--bg-hover); }
.tv-mode .nav-search { flex: 0 1 360px; }
.tv-mode .search-input { font-size: 1rem; padding: 0.6rem 1rem; }

/* Main layout */
.tv-mode .main-content { padding: 2rem 3rem; }
.tv-mode .section { margin-bottom: 3rem; }
.tv-mode .section-title { font-size: 1.4rem; margin-bottom: 1.25rem; }

/* Card grid — fewer columns, bigger cards */
.tv-mode .card-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
}

/* Cards — always show title (no hover needed on TV) */
.tv-mode .media-card__info {
  display: block !important;
  padding: 0.6rem 0.5rem 0.5rem;
}
.tv-mode .media-card__title { font-size: 0.95rem; }
.tv-mode .media-card__year  { font-size: 0.8rem; }
.tv-mode .media-card:focus  {
  outline: 4px solid var(--accent);
  outline-offset: 0;
  border-radius: var(--radius);
  transform: scale(1.04);
  z-index: 2;
}

/* Detail page */
.tv-mode .detail-title    { font-size: 2.8rem; }
.tv-mode .detail-meta     { font-size: 1.1rem; gap: 1.25rem; }
.tv-mode .detail-overview { font-size: 1.05rem; line-height: 1.7; max-width: 700px; }
.tv-mode .detail-actions  { gap: 1.25rem; margin-top: 1.5rem; }

/* Buttons */
.tv-mode .btn-primary,
.tv-mode .btn-secondary {
  font-size: 1.1rem;
  padding: 0.9rem 2rem;
  border-radius: var(--radius);
}
.tv-mode .btn-play { font-size: 1.2rem; padding: 1rem 2.5rem; }
.tv-mode button:focus {
  outline: 4px solid var(--accent-hi);
  outline-offset: 3px;
}

/* Seasons / episodes in TV mode */
.tv-mode .season-toggle { font-size: 1.1rem; padding: 1rem 1.5rem; }
.tv-mode .episode-still { width: 160px; }
.tv-mode .episode-title { font-size: 1rem; }
.tv-mode .episode-overview { font-size: 0.9rem; }

/* Prevent tiny focus flashes on non-interactive elements */
.tv-mode div:focus,
.tv-mode section:focus { outline: none; }

/* ── Admin dropdown menu ─────────────────────────────────────────────────── */
.admin-menu {
  position: relative;
  display: inline-block;
  /* Extend hover area downward so the cursor stays "inside" while crossing the gap */
  padding-bottom: 8px;
  margin-bottom: -8px;
}
.admin-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% - 8px); /* overlap the padding-bottom bridge */
  padding-top: 8px;       /* visual gap, still part of hover area */
  background: transparent;
  z-index: 100;
  width: max-content;
}
.admin-dropdown-inner {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  overflow: hidden;
}
.admin-menu.open .admin-dropdown { display: block; z-index: 50; }
/* The quick profile switch: a list of buttons styled like the admin menu's links. */
.profile-menu[hidden] { display: none; }
.nav-profile { display: inline-flex; align-items: center; }
.profile-list .admin-group { display: block; padding: .5rem 1rem .2rem; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.profile-list form { margin: 0; }
.profile-list button { display: block; width: 100%; padding: .6rem 1rem; background: none; border: 0; color: var(--text); text-align: left; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.profile-list button:hover, .profile-list button:focus-visible { background: var(--surface-3); color: var(--accent-hi); }
.admin-dropdown a {
  display: block;
  padding: .6rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-size: .9rem;
}
.admin-dropdown a:hover { background: var(--surface-3); color: var(--accent-hi); }

/* ── Source priority page ────────────────────────────────────────────────── */
.source-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.source-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  cursor: grab;
  user-select: none;
  transition: background .15s;
}
.source-item.dragging {
  opacity: .5;
  background: var(--surface-3);
}
.source-drag-handle { font-size: 1.2rem; color: var(--text-muted); cursor: grab; }
.source-icon { font-size: 1.4rem; }
.source-name { flex: 1; font-weight: 500; }
.source-toggle {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
  color: var(--text-muted);
  cursor: pointer;
}
.source-toggle input[type=checkbox] { accent-color: var(--accent); width: 1rem; height: 1rem; cursor: pointer; }

/* ── Admin sections (indexers page) ─────────────────────────────────────── */
.admin-section {
  margin-bottom: 2.5rem;
}
.admin-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 .35rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.indexer-cards {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin: .75rem 0 1rem;
}
.indexer-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  min-width: 220px;
  max-width: 340px;
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.indexer-card--builtin { opacity: .75; }
.indexer-card-name { font-weight: 600; font-size: .95rem; }
.indexer-card-meta { display: flex; gap: .4rem; flex-wrap: wrap; }
.indexer-card-url {
  font-size: .75rem;
  color: var(--text-muted);
  word-break: break-all;
}
.indexer-card-status { font-size: .8rem; display: flex; align-items: center; gap: .3rem; }
.indexer-card-actions { margin-top: auto; padding-top: .5rem; display: flex; gap: .4rem; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot--on  { background: #4ade80; }
.dot--off { background: var(--text-muted); }

.badge-builtin { background: rgba(255,255,255,.08); color: var(--text-muted); }
.badge-torznab { background: rgba(139,92,246,.2);  color: #a78bfa; }
.badge-newznab { background: rgba(59,130,246,.2);  color: #60a5fa; }
.badge-nntp    { background: rgba(20,184,166,.2);  color: #2dd4bf; }
.badge-ssl     { background: rgba(34,197,94,.15);  color: #4ade80; }

/* Add-form accordion */
.add-form-details { margin-top: .25rem; }
.add-form-details summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  user-select: none;
}
.add-form-details summary::-webkit-details-marker { display: none; }
.add-form {
  margin-top: .75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .3rem 1.25rem;
  margin-bottom: .75rem;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  justify-content: flex-end;
  font-size: .85rem;
  color: var(--text-muted);
}
/* Label, field and help each get a shared row, so fields line up whatever wraps above or below them. */
@supports (grid-template-rows: subgrid) {
  .form-grid label:not(.checkbox-label) {
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;
    align-content: start;
    margin-bottom: .6rem;
  }
}
.form-grid .checkbox-label {
  grid-column: 1 / -1;
  flex-wrap: wrap;
}
.form-grid .checkbox-label small.admin-sub { flex-basis: 100%; margin-left: 1.6rem; }
.tv-scale .form-grid { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
.tv-scale input.tv-locked:not([readonly]) { outline: 2px solid var(--accent); }
.form-grid input[type=text],
.form-grid input[type=url],
.form-grid input[type=password],
.form-grid input[type=number] {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .45rem .6rem;
  font-size: .9rem;
  width: 100%;
}
.form-grid .checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: .5rem;
  color: var(--text);
  cursor: pointer;
  margin-top: .5rem;
}
.flash--ok {
  background: rgba(34,197,94,.15);
  border: 1px solid rgba(34,197,94,.3);
  color: #4ade80;
  border-radius: var(--radius);
  padding: .6rem 1rem;
  margin-bottom: 1.25rem;
  font-size: .9rem;
}
.empty-note { color: var(--text-muted); font-size: .85rem; font-style: italic; }

/* Card actions, ratings and filters */
.media-card-wrap { position: relative; }
.media-card-wrap .media-card { display: block; height: 100%; }
.card-add {
  position: absolute; right: .4rem; bottom: .4rem; width: 1.6rem; height: 1.6rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-hi); color: #000; font-weight: 900; font-size: 1.1rem; line-height: 1;
  border: 0; border-radius: 4px; cursor: pointer;
}
.card-add:hover { background: var(--accent); }
.card-add--done { background: #2ecc71; }
.card-add--remove { background: #c0392b; color: #fff; }
.imdb { color: #f5c518; font-weight: 700; }
.filter-box { margin-bottom: 1rem; }
.filter-form { margin-top: .75rem; display: grid; gap: .75rem; }
.filter-genres { display: flex; flex-wrap: wrap; gap: .4rem .9rem; }
.filter-row { display: flex; flex-wrap: wrap; gap: .75rem; }
.filter-row input { display: block; width: 7rem; }

.section-head { display: flex; justify-content: space-between; align-items: center; position: relative; margin-bottom: 1rem; }
.section-head .section-title { margin-bottom: 0; }
.section-head .filter-box { margin: 0; }
.section-head .filter-box summary { list-style: none; cursor: pointer; }
.section-head .filter-form {
  position: absolute; right: 0; top: 100%; z-index: 20; width: min(34rem, 92vw);
  padding: 1rem; background: var(--bg2, #16161f); border: 1px solid var(--accent); border-radius: 8px;
}
a.card-add { text-decoration: none; }

.section-link { color: inherit; text-decoration: none; }
.section-link:hover { color: var(--accent-hi); }

.player-audio { max-width: 16rem; background: var(--bg2, #16161f); color: inherit; border: 1px solid var(--accent); border-radius: 4px; padding: .2rem; }

.stream-status:fullscreen, #stream-status:fullscreen { display: flex; align-items: center; justify-content: center; margin: 0; background: #000; }
:fullscreen > .player-wrap, .player-wrap:fullscreen { display: flex; flex-direction: column; width: 100%; max-width: none; height: 100%; margin: 0; background: #000; border-radius: 0; }
:fullscreen > .player-wrap .player-video, .player-wrap:fullscreen .player-video { flex: 1; min-height: 0; width: 100%; max-width: none; max-height: none; border-radius: 0; }

.line-banner { background: #b3261e; color: #fff; text-align: center; padding: .5rem 1rem; font-weight: 600; }
.line-banner[hidden] { display: none; }

.card-play { width: 100%; margin-top: .35rem; }

.poster-box, .episode-still { position: relative; }
.poster-progress { position: absolute; left: 0; bottom: 0; width: 100%; height: 5px; border: 0; display: block; appearance: none; background: rgba(0,0,0,.6); }
.poster-progress::-webkit-progress-bar { background: rgba(0,0,0,.6); }
.poster-progress::-webkit-progress-value { background: var(--accent); }
.poster-progress::-moz-progress-bar { background: var(--accent); }
.seen-mark { position: absolute; left: .4rem; top: .4rem; background: rgba(0,0,0,.7); color: #fff; border-radius: 50%; width: 1.5rem; height: 1.5rem; display: flex; align-items: center; justify-content: center; font-size: .85rem; }
/* A long press must open the menu, not select text or show the phone's own callout. */
.ctx-menu, .ctx-menu *, [data-media], [data-lib-add], [data-all], [data-season] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.ctx-menu { position: fixed; z-index: 1000; min-width: 11rem; background: var(--bg2, #16161f); border: 1px solid var(--accent); border-radius: 6px; padding: .25rem; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.ctx-menu button { display: block; width: 100%; padding: .45rem .7rem; background: none; border: 0; color: inherit; text-align: left; cursor: pointer; border-radius: 4px; }
.ctx-menu button:hover { background: var(--bg-hover); }

.media-card-wrap:has(.card-play) .media-card { height: auto; }
.media-card-wrap:has(.card-play) .media-card__info { padding-bottom: .55rem; }
.media-card-wrap:has(.card-play) { display: flex; flex-direction: column; }
.media-card-wrap:has(.card-play) .media-card { flex: 1; }

/* ── Phone layout ─────────────────────────────────────────────────────────── */
.tabbar { display: none; }
html.is-phone body { padding-bottom: calc(3.6rem + env(safe-area-inset-bottom)); }
html.is-phone input, html.is-phone select, html.is-phone textarea { font-size: 16px; }
html.is-phone .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; background: var(--bg2, #16161f); border-top: 1px solid rgba(255,255,255,.1); padding-bottom: env(safe-area-inset-bottom); }
html.is-phone .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .4rem 0; color: var(--text-muted); font-size: .68rem; text-decoration: none; }
html.is-phone .tabbar a span { font-size: 1.2rem; line-height: 1.2; }
html.is-phone .tabbar a:active { color: var(--accent); }
html.is-phone .tabbar a.active { border-radius: 12px; margin: 0 2px; }
html.is-phone .navbar { flex-wrap: wrap; gap: .4rem .6rem; padding: .5rem .75rem; height: auto; }
html.is-phone .nav-links, html.is-phone .username { display: none; }
html.is-phone .nav-logo { order: 1; }
html.is-phone .nav-user { order: 2; margin-left: auto; }
html.is-phone .nav-search { order: 3; flex: 1 0 100%; max-width: none; }
html.is-phone .search-input { width: 100%; }
html.is-phone .main-content { padding: .75rem; max-width: 100%; }
html.is-phone .section { margin-bottom: 1.5rem; }
html.is-phone .section-head { flex-wrap: wrap; gap: .5rem; }
html.is-phone .section-title { font-size: 1.05rem; }
html.is-phone .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
html.is-phone #new-episodes .card-grid, html.is-phone #continue .card-grid { display: flex; overflow-x: auto; scroll-snap-type: x proximity; margin: 0 -.75rem; padding: 0 .75rem .25rem; }
html.is-phone #new-episodes .media-card-wrap, html.is-phone #continue .media-card-wrap { flex: 0 0 38vw; scroll-snap-align: start; }
html.is-phone .media-card__title { font-size: .75rem; }
html.is-phone .media-card__year { font-size: .68rem; }
html.is-phone .media-card__info { padding: .35rem .4rem .45rem; }
html.is-phone .card-add { width: 2rem; height: 2rem; }
html.is-phone .card-play { padding: .45rem .2rem; font-size: .8rem; }
html.is-phone .filter-box { width: 100%; }
html.is-phone .filter-form { width: 100%; }
html.is-phone .detail-hero__content { flex-direction: column; align-items: center; text-align: center; padding: 1rem .75rem; gap: .75rem; }
html.is-phone .detail-poster { width: 42vw; max-width: 180px; }
html.is-phone .detail-info { width: 100%; }
html.is-phone .detail-title { font-size: 1.4rem; }
html.is-phone .detail-meta, html.is-phone .detail-actions { justify-content: center; }
html.is-phone .detail-overview { font-size: .88rem; text-align: left; }
html.is-phone .detail-actions .btn-play { width: 100%; padding: .75rem; }
html.is-phone .episode-row { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: .5rem .6rem; padding: .6rem .25rem; }
html.is-phone .episode-still { width: 100%; }
html.is-phone .episode-header { flex-wrap: wrap; gap: .2rem .4rem; }
html.is-phone .episode-overview { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .78rem; }
html.is-phone .episode-actions { grid-column: 1 / -1; width: 100%; }
html.is-phone .episode-actions .btn-play { width: 100%; padding: .55rem; }
html.is-phone .admin-page table { display: block; overflow-x: auto; }
html.is-phone .add-form { max-width: 100%; }
html.is-phone .ctx-menu button { padding: .7rem .8rem; font-size: 1rem; }
html.is-phone .media-card-wrap .card-add { width: 1.6rem; height: 1.6rem; font-size: .9rem; top: .3rem; right: .3rem; bottom: auto; left: auto; }
html.is-phone .media-card-wrap .card-add { width: 1.25rem; height: 1.25rem; font-size: .7rem; line-height: 1; padding: 0; top: .25rem; left: .25rem; right: auto; }
html.is-phone .seen-mark { left: auto; right: .25rem; top: .25rem; width: 1.25rem; height: 1.25rem; font-size: .7rem; }
html.is-phone .stream-status, html.is-phone .player-wrap, html.is-phone .player-topbar { min-width: 0; max-width: 100%; }
html.is-phone .player-video { max-width: 100%; }

/* ── Card marks: seen top left, library top right, add bottom right ───────── */
.media-card-wrap .card-add, html.is-phone .media-card-wrap .card-add { position: absolute; top: auto; left: auto; right: .3rem; bottom: .55rem; width: 1.4rem; height: 1.4rem; padding: 0; font-size: .9rem; line-height: 1; border: 0; border-radius: 4px; background: var(--accent); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.seen-mark, html.is-phone .seen-mark { left: .3rem; right: auto; top: .3rem; width: 1.4rem; height: 1.4rem; border-radius: 4px; background: #2e9e5b; font-size: .8rem; }
.lib-mark { position: absolute; top: .3rem; right: .3rem; width: 1.4rem; height: 1.4rem; border-radius: 4px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }

.player-wrap { position: relative; }
.player-overlay { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; width: min(22rem, 90%); padding: 1rem; background: rgba(10,10,15,.92); border: 1px solid var(--accent); border-radius: 8px; text-align: center; display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.player-overlay p { flex: 1 0 100%; margin: 0 0 .25rem; }

.device-row, .device-test-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.device-test-row > span:first-child { flex: 1 1 10rem; }
.diag-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-bottom: 2rem; }
.diag-table th, .diag-table td { padding: .35rem .5rem; border-bottom: 1px solid rgba(255,255,255,.08); text-align: left; }
html.is-phone .diag-table { display: block; overflow-x: auto; }

.pair-card { text-align: center; }
.pair-url { font-size: 1.2rem; word-break: break-all; }
.pair-code { font-size: 3rem; font-weight: 700; letter-spacing: .2em; margin: 1rem 0; }
.pair-note { opacity: .7; }
.profile-grid { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 2rem; }
.profile-item { display: flex; flex-direction: column; gap: .4rem; }
.profile-btn { width: 9rem; height: 9rem; border: 1px solid var(--accent); border-radius: 12px; background: var(--bg2, #16161f); color: inherit; font-size: 1.1rem; cursor: pointer; padding: .5rem; }
.profile-btn:hover, .profile-btn:focus { background: var(--accent); }

/* ── Shared look ──────────────────────────────────────────────────────────── */
:root { --bg2: var(--bg-card); --surface-2: var(--bg-card); --surface-3: var(--bg-hover); }
html:not(.is-phone):not(.tv-mode) { font-size: 18px; }

input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; max-width: 100%; padding: .55rem .7rem; font: inherit; font-size: .95rem;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select option { background: var(--bg-card); color: var(--text); }
.search-input { border-radius: 999px; background: var(--bg-card); }
.player-audio { width: auto; padding: .3rem .4rem; font-size: .85rem; }

.admin-page { max-width: 1000px; margin: 0 auto; }
.admin-title { font-size: 1.8rem; font-weight: 700; margin-bottom: 1.25rem; }
.admin-section-title { font-size: 1.15rem; font-weight: 700; margin: 2rem 0 .6rem; }
.admin-sub { color: var(--text-muted); font-size: .9rem; line-height: 1.5; margin-bottom: .75rem; }
.admin-sub a, .auth-card a { color: var(--accent-hi); }
.admin-sub a:hover { text-decoration: underline; }
.add-form { display: flex; flex-direction: column; align-items: flex-start; gap: .85rem; padding: 1.1rem 1.25rem; margin-bottom: 1rem;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); }
.add-form .form-grid { width: 100%; }
.add-form label { display: flex; flex-direction: column; gap: .3rem; width: 100%; font-size: .9rem; color: var(--text-muted); }
.add-form label.checkbox-label { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
.device-row, .device-test-row { padding: .7rem 1rem; margin-bottom: .5rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); font-size: .92rem; }
.diag-table { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.diag-table th { color: var(--text-muted); font-weight: 600; }
.profile-btn { border-color: var(--border); background: var(--bg-card); font-weight: 600; }
.profile-grid { justify-content: center; }
.empty-state { color: var(--text-muted); }

html.is-phone .add-form { padding: .9rem; }
.tv-mode .admin-page { max-width: none; }

.bridge-next { min-height: 12rem; }
.code-input { text-transform: uppercase; letter-spacing: .15em; }
.diag-detail { white-space: pre-wrap; word-break: break-word; font-size: .8rem; color: var(--text-muted); max-height: 16rem; overflow: auto; }

/* ── Phone player: controls overlay the video, black around it ────────────── */
html.is-phone .player-wrap { position: relative; background: #000; min-height: 12rem; display: flex; align-items: center; }
html.is-phone .player-video { width: 100%; border-radius: 0; background: #000; }
html.is-phone .player-topbar { position: absolute; top: 0; left: 0; right: 0; z-index: 4; margin: 0; flex-direction: column; align-items: stretch; gap: .4rem;
  padding: .5rem .6rem 1.4rem; background: linear-gradient(rgba(0,0,0,.8), rgba(0,0,0,.45) 60%, transparent); transition: opacity .25s; }
html.is-phone .player-topbar .stream-badge { align-self: flex-start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: none; padding: 0; font-size: .8rem; font-weight: 600; color: rgba(255,255,255,.85); }
html.is-phone .player-ext-bar { margin: 0; flex-wrap: nowrap; gap: .4rem; min-width: 0; }
html.is-phone .player-audio { flex: 1 1 0; min-width: 0; max-width: none; height: 2.5rem; padding: 0 .5rem; border-radius: 8px; font-size: .85rem;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22); color: #fff; }
html.is-phone .player-ext-btn { flex: none; width: 2.5rem; height: 2.5rem; border-radius: 8px; background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.22); color: #fff; }
html.is-phone .player-ext-btn svg { width: 1.2rem; height: 1.2rem; }
html.is-phone .player-ext-btn.ext-player { display: none; }
html.is-phone .player-center { position: absolute; left: 0; right: 0; bottom: 4.5rem; z-index: 4; display: flex; justify-content: center; gap: .8rem; transition: opacity .25s; }
html.is-phone .player-center .seek-btn { width: 3.4rem; height: 3.4rem; border-radius: 50%; font-size: .85rem; font-weight: 700;
  background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.35); color: #fff; backdrop-filter: blur(4px); }
html.is-phone .controls-hidden .player-topbar, html.is-phone .controls-hidden .player-center { opacity: 0; pointer-events: none; }
:fullscreen > .player-wrap.zoomed .player-video, .player-wrap.zoomed:fullscreen .player-video { object-fit: cover; }

.spinner { width: 3rem; height: 3rem; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--accent-hi); border-radius: 50%; animation: spin .9s linear infinite; }
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-overlay { position: fixed; inset: 0; z-index: 950; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; background: rgba(10,10,15,.75); color: #fff; }
.player-spinner { position: absolute; left: 50%; top: 50%; margin: -1.5rem 0 0 -1.5rem; z-index: 3; pointer-events: none; }

/* ── TV: laid out for 1920 pixels, never phones or tablets ────────── */
html.tv-scale { font-size: 24px; }
.tv-scale .card-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 18px; }
.tv-scale .detail-title { font-size: 4.6rem; }
.tv-scale .detail-poster { width: 300px; }
.tv-scale .episode-still { width: 240px; }
.tv-scale .main-content { max-width: none; padding: 2rem; }
.tv-scale .card-play { font-size: .8rem; padding: .4rem; }
.tv-scale .media-card-wrap .card-add { display: none; }
.tv-scale .media-card__poster { width: 100%; height: auto; aspect-ratio: 2 / 3; object-fit: cover; }

.release-mark { position: absolute; left: .3rem; bottom: .55rem; padding: .15rem .4rem; border-radius: 4px; background: #b3541e; color: #fff; font-size: .72rem; font-weight: 600; }
.release-mark--inline { position: static; }

img.logo-icon { width: 1.5em; height: 1.5em; vertical-align: middle; }
.tv-scale .auth-card { max-width: 900px; }
.tv-scale .auth-body { min-height: 100vh; }
.tv-mode .ctx-menu button { font-size: 20px; padding: .6rem .9rem; }
.tv-mode .ctx-menu button:focus { background: var(--accent); }
.tv-toast { position: fixed; left: 50%; bottom: 3rem; transform: translateX(-50%); z-index: 960; padding: .7rem 1.2rem; border-radius: var(--radius); background: rgba(0,0,0,.85); color: #fff; }

.tv-scale .detail-info { max-width: 1250px; }
.tv-scale .detail-overview { max-width: none; font-size: .85rem; }
.tv-scale .season-item, .tv-scale .season-toggle { width: 100%; }
.season-item:not(.open) .season-episodes { display: none; }
.tv-mode .season-toggle:focus { outline: 3px solid var(--accent-hi); outline-offset: -3px; border-radius: var(--radius); background: var(--bg-hover); color: var(--accent-hi); }
.tv-mode .season-toggle:focus .season-name, .tv-mode .season-toggle:focus .season-meta, .tv-mode .season-toggle:focus .season-chevron { color: var(--accent-hi); }
.tv-mode .btn-primary:focus, .tv-mode .btn-secondary:focus, .tv-mode .btn-play:focus, .tv-mode .card-play:focus { outline: none; box-shadow: 0 0 0 3px var(--bg), 0 0 0 7px #fff; transform: scale(1.03); }

.media-info { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0 0 1rem; font-size: .88rem; }
.media-info dt { color: var(--text-muted); }
.media-info dd { margin: 0; }
html.is-phone .media-info { text-align: left; font-size: .8rem; }
.tv-scale .media-info { font-size: .78rem; }

.person-link { color: var(--accent-hi); }
.person-link:hover, .person-link:focus { text-decoration: underline; }
.person-grid { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.5rem; }
.person-card { display: flex; flex-direction: column; align-items: center; width: 9rem; padding: .5rem; text-align: center; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); }
.person-card img { width: 6rem; height: 6rem; object-fit: cover; border-radius: 50%; margin-bottom: .4rem; }
.person-card__name { font-weight: 600; font-size: .85rem; }
.person-card__role { color: var(--text-muted); font-size: .75rem; }
.related-section { margin-top: 2rem; }
.tv-mode .person-link:focus { outline: 2px solid var(--accent-hi); border-radius: 3px; }
.tv-mode .person-link:focus { outline: none; padding: .05rem .3rem; border-radius: 4px; background: var(--accent); color: #fff; text-decoration: none; }

.tv-mode .filter-box :focus { outline: 3px solid #fff; outline-offset: 2px; border-radius: 4px; }
.tv-mode .filter-box label:has(:focus) { background: var(--accent); color: #fff; border-radius: 4px; }
.tv-mode .filter-box summary:focus { background: var(--accent); color: #fff; }
.tv-mode .filter-box input[type=checkbox]:focus { transform: scale(1.3); }
.tv-select { max-height: 50vh; overflow-y: auto; min-width: 8rem; }
.tv-mode .ctx-menu button:focus { color: #fff; }

/* ── Cast panel: remote controls over the player while the TV plays ─────── */
.cast-panel { position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; justify-content: center; gap: .8rem;
  padding: 1rem 1.2rem; background: rgba(8,8,14,.88); color: #fff; }
.cast-panel-name { font-weight: 600; font-size: 1rem; }
.cast-panel input[type=range] { width: 100%; accent-color: var(--accent-hi); height: 2rem; }
.cast-panel-times { font-variant-numeric: tabular-nums; font-size: .9rem; color: rgba(255,255,255,.8); }
.cast-panel-row { display: flex; gap: .6rem; }
.cast-panel .cast-panel-btn { width: auto; min-width: 3rem; height: 2.6rem; padding: 0 1rem; color: #fff; background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); }
.player-wrap { position: relative; }
.admin-ok { color: #6fcf8f; font-size: .9rem; }
.form-grid label small.admin-sub { display: block; margin-top: .2rem; font-size: .75rem; }
.settings-advanced { margin: 1.2rem 0; padding: .6rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); }
.settings-advanced > summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }

/* ── Admin: grouped menu and tabs on every admin page ───────────────────── */
.admin-dropdown .admin-group { display: block; padding: .55rem 1rem .2rem; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.admin-dropdown .admin-group:not(:first-child) { border-top: 1px solid var(--border); margin-top: .25rem; }
.admin-dropdown-inner { min-width: 13rem; }
.admin-tabs { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; margin-bottom: 1.2rem; padding-bottom: .8rem; border-bottom: 1px solid var(--border); }
.admin-tabs .admin-group { font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin: 0 .2rem 0 .6rem; }
.admin-tabs .admin-group:first-child { margin-left: 0; }
.admin-tabs a { padding: .35rem .75rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: .85rem; white-space: nowrap; }
.admin-tabs a:hover { border-color: var(--accent); }
html.is-phone .admin-tabs { flex-wrap: nowrap; overflow-x: auto; }

.pw-row { display: flex; gap: .4rem; }
.pw-row input { flex: 1; min-width: 0; font-family: monospace; }

.episode-date { color: var(--muted, #9a9aa5); font-size: .85rem; }

/* TV: the search field opens from a button (_openSearch). */
.search-toggle { display: none; }
html.tv-scale .search-toggle { display: inline-flex; }
html.tv-scale .nav-search:not(.open) form { display: none; }
html.tv-scale .nav-search.open .search-toggle { display: none; }
html.tv-scale .nav-search { flex: 0 1 360px; }

/* A long admin menu scrolls inside itself, so the page behind it stays put. */
.admin-dropdown-inner { max-height: calc(100vh - 6rem); overflow-y: auto; }

/* A playback error raised far from the status line at the top of the page. */
.stream-toast { position: fixed; left: 50%; bottom: 2rem; transform: translateX(-50%); z-index: 2000; max-width: min(90vw, 40rem);
  padding: .8rem 1.2rem; border-radius: var(--radius, 8px); background: var(--surface-2, #222); border: 1px solid #c0392b; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.5); }

/* Age limits on the profile page */
.profile-age { display: block; font-size: .8rem; opacity: .75; margin-top: .25rem; }
.profile-item input[type=password] { display: block; width: 9rem; margin-top: .4rem; }
.profile-age-form select { display: block; width: 9rem; margin-top: .25rem; }
.admin-page .form-error { color: #ff6b6b; }
.admin-page .hint { opacity: .7; font-size: .9rem; max-width: 40rem; }

/* The profile's verdict on a card */
.rate-mark { position: absolute; left: .35rem; bottom: .35rem; font-size: .9rem; line-height: 1; padding: .2rem .25rem; border-radius: 6px; background: rgba(0,0,0,.6); }

/* "Anpassa förslag" on För dig */
.taste-box { margin: 0 0 1rem; }
.taste-box .taste-label { margin: .75rem 0 .25rem; font-weight: 600; }
.taste-box .filter-row span { align-self: center; }

/* The CAM warning sits mid-screen wherever the play button was */
.release-warning { position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); }
.release-warning .player-overlay { position: static; transform: none; max-width: min(90vw, 36rem); }
.rec-preparing { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 3rem 1rem; text-align: center; }

/* Help */
.nav-help { font-weight: 700; min-width: 2.2em; text-align: center; border-radius: 50%; }
.help-page { max-width: 860px; }
.help-toc { display: flex; flex-direction: column; gap: .2em; margin: 1em 0 2em; padding: 1em 1.2em;
  background: var(--bg-card); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); }
.help-toc h2 { margin: 0 0 .4em; font-size: 1.1em; color: var(--accent-hi); }
.help-toc a { color: var(--text); padding: .35em .6em; border-radius: var(--radius); text-decoration: none; }
.help-toc a::before { content: "›"; color: var(--accent-hi); margin-right: .6em; font-weight: 700; }
.help-toc a:hover, .help-toc a:focus { background: var(--bg-hover); color: var(--accent-hi); }
.help-section { margin-bottom: 2em; line-height: 1.55; }
.help-section h2 { margin-bottom: .4em; }
.help-section li { margin: .3em 0; }
.help-section details { border-bottom: 1px solid rgba(255,255,255,.1); padding: .6em 0; }
.help-section summary { cursor: pointer; font-weight: 600; }

.bw-bar { display: inline-block; width: 80px; height: 8px; background: rgba(255,255,255,.12); border-radius: 4px; vertical-align: middle; overflow: hidden; }
.bw-bar span { display: block; height: 100%; background: var(--accent, #4a9eff); }
.bw-bar.bw-high span { background: #e5533d; }

/* ── Admin: client map ───────────────────────────────────────────────────── */
.cmap { height: 60vh; min-height: 320px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); }
.cmap-layout { display: grid; grid-template-columns: 1fr 18rem; gap: 1rem; }
.cmap-ranges { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 1rem; }
.cmap-places { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; }
.cmap-places small { color: var(--text-muted); }
.cmap-legend { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.cmap-dot-wrap, .cmap-group-wrap { background: none; border: 0; }
.cmap-dot { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--c); color: #111; font: 700 14px/1 system-ui, sans-serif; box-shadow: 0 0 0 3px #fff, 0 2px 6px rgba(0,0,0,.5); }
.cmap-ip { box-shadow: none; outline: 3px dashed #fff; outline-offset: 0; }
.cmap-home { border-radius: 6px; }
.cmap-group { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; border-radius: 50%;
  box-shadow: 0 2px 10px rgba(0,0,0,.55); }
.cmap-group b { display: flex; align-items: center; justify-content: center; width: 68%; height: 68%; border-radius: 50%;
  background: #1e1b2e; color: #fff; font: 700 15px/1 system-ui, sans-serif; border: 2px solid #fff; }
.cmap-dialog { width: min(1100px, 94vw); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); color: var(--text); }
.cmap-dialog::backdrop { background: rgba(0,0,0,.6); }
.cmap-dialog-head { display: flex; justify-content: space-between; align-items: center; padding: .6rem .9rem; }
.cmap-dialog .cmap { height: 70vh; border-radius: 0; border: 0; }
.leaflet-popup-content { color: #111; }
html.is-phone .cmap-layout { grid-template-columns: 1fr; }

/* Sett & gillat: films/series toggle, sort and filter */
.liked-head { flex-wrap: wrap; gap: .8rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg a { padding: .4rem 1.1rem; border-radius: 999px; color: var(--text); text-decoration: none; font-weight: 600; font-size: .9rem; }
.seg a:hover, .seg a:focus-visible { background: var(--border); }
.liked-tools { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; position: relative; }
.sort-form label { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--text-muted); }
.sort-form select { width: auto; }
.liked-count { color: var(--text-muted); font-size: .85rem; margin: -.4rem 0 .8rem; }

.season-seen { font-size: .8rem; font-weight: 600; color: var(--success, #34d399); white-space: nowrap; margin-left: .6rem; }
.season-seen.part { color: var(--text-muted); font-weight: 500; }
.liked-note { color: var(--text-muted); font-size: .85rem; margin: 0 0 .6rem; }

/* Loading view while a slow page is built */
.page-wait { position: fixed; inset: 0; z-index: 2000; background: var(--bg); padding: 1.5rem clamp(16px, 4vw, 3rem); overflow: hidden; animation: wait-in .2s ease-out; }
.wait-head { display: flex; align-items: center; gap: .8rem; font-size: 1.05rem; font-weight: 600; color: var(--text); margin-bottom: 1.4rem; }
.wait-ring { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: wait-spin .8s linear infinite; }
.wait-dots { display: inline-flex; gap: 4px; margin-left: -.4rem; align-self: flex-end; padding-bottom: .35rem; }
.wait-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: wait-dot 1.2s ease-in-out infinite; }
.wait-dots i:nth-child(2) { animation-delay: .15s; }
.wait-dots i:nth-child(3) { animation-delay: .3s; }
.wait-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1.2rem; }
.wait-card { opacity: 0; animation: wait-in .4s ease-out forwards; animation-delay: calc(var(--i) * 60ms); }
.wait-poster, .wait-line { border-radius: 8px; background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%); background-size: 300% 100%; animation: wait-shine 1.4s ease-in-out infinite; }
.wait-poster { aspect-ratio: 2 / 3; }
.wait-line { height: .8rem; margin-top: .6rem; width: 85%; }
.wait-line.short { width: 45%; }
@keyframes wait-spin { to { transform: rotate(360deg); } }
@keyframes wait-shine { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@keyframes wait-dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }
@keyframes wait-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .page-wait *, .page-wait { animation-duration: 0s !important; animation-iteration-count: 1 !important; } .wait-card { opacity: 1; } }

/* Alarm list */
.nav-admin { position: relative; }
.alarm-badge { position: absolute; top: -6px; right: -8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: .7rem; font-weight: 700; line-height: 18px; color: #fff; text-align: center; }
.alarm-badge-critical, .alarm-banner-critical { background: #dc2626; }
.alarm-badge-warning, .alarm-banner-warning { background: #d97706; }
.alarm-link-critical:not(.active) { color: #f87171 !important; border-color: #dc2626 !important; font-weight: 600; }
.alarm-link-warning:not(.active) { color: #fbbf24 !important; border-color: #d97706 !important; }
.alarm-banner { display: block; margin: -.4rem 0 1rem; padding: .6rem .9rem; border-radius: 8px; color: #fff; text-decoration: none; font-weight: 600; }
.alarm-banner[hidden] { display: none; }
.alarm-check { margin: 0 0 1rem; }
.alarm-list { list-style: none; padding: 0; margin: 0 0 1.5rem; display: grid; gap: .7rem; }
.alarm { border: 1px solid var(--border); border-left-width: 5px; border-radius: 8px; padding: .8rem 1rem; background: var(--surface-2); }
.alarm p { margin: .35rem 0 0; }
.alarm-critical { border-left-color: #dc2626; }
.alarm-warning { border-left-color: #d97706; }
.alarm-cleared { border-left-color: var(--border); opacity: .75; }
.alarm-head { display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.alarm-level { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: .1rem .45rem; border-radius: 4px; color: #fff; background: #d97706; }
.alarm-critical .alarm-level { background: #dc2626; }
.alarm-fix { color: var(--text); }
.alarm-when { color: var(--text-muted); font-size: .8rem; }
.alarm-ok { padding: 1rem; border-radius: 8px; background: var(--surface-2); color: #34d399; font-weight: 600; }
.alarm-account { border-left-color: #34d399; }
.alarm-account .alarm-head { justify-content: space-between; }

/* The one marking for "you are here" and "chosen" everywhere: filled accent, white text.
   Menus, tabs, toggles and range buttons all use it, so it reads the same across Nexarr. */
.nav-link.active, html.is-phone .tabbar a.active, .admin-dropdown a.active, .admin-tabs a.active,
.seg a.active, .cmap-ranges button.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.nav-link.active:hover, .admin-dropdown a.active:hover { color: #fff; }
html.is-phone .tabbar a.active span { color: #fff; }
.hidden-note { color: var(--text-muted); font-size: .85rem; margin: .4rem 0 0; }

/* Source priority: move buttons for touch and remote; long presses select nothing. */
.source-item { -webkit-user-select: none; user-select: none; }
.source-move { display: inline-flex; gap: .25rem; margin-left: auto; }
.source-move button { min-width: 40px; min-height: 40px; padding: 0; font-size: .9rem; }
.source-item:first-child [data-move="-1"], .source-item:last-child [data-move="1"] { visibility: hidden; }
.source-item.moved { background: var(--surface-3); transition: background .4s; }


/* ── Home screen app (iPhone/iPad): safe areas, back button, install tip ─────
   viewport-fit=cover lets the page run under the notch, the status bar
   (black-translucent) and the home indicator; env() is 0 everywhere else. */
.navbar { height: calc(var(--navbar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  padding-left: max(2rem, env(safe-area-inset-left)); padding-right: max(2rem, env(safe-area-inset-right)); }
html.is-phone .navbar { height: auto; padding: calc(.5rem + env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) .5rem max(.75rem, env(safe-area-inset-left)); }
.line-banner { padding-top: calc(.5rem + env(safe-area-inset-top)); }
.main-content { padding-left: max(2rem, env(safe-area-inset-left)); padding-right: max(2rem, env(safe-area-inset-right)); }
html.is-phone .main-content { padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); }
html.is-phone .tabbar { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.page-wait { padding-top: calc(1.5rem + env(safe-area-inset-top)); }
.stream-toast { bottom: calc(2rem + env(safe-area-inset-bottom)); }
html.is-phone .stream-toast, html.is-phone .tv-toast { bottom: calc(4.6rem + env(safe-area-inset-bottom)); }
/* Fullscreen player (iPad, Android): controls clear the notch and the home indicator. */
:fullscreen > .player-wrap .player-topbar, .player-wrap:fullscreen .player-topbar {
  padding-top: max(.5rem, env(safe-area-inset-top)); padding-left: max(.6rem, env(safe-area-inset-left)); padding-right: max(.6rem, env(safe-area-inset-right)); }
:fullscreen > .player-wrap .player-center, .player-wrap:fullscreen .player-center { bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
:fullscreen > .player-wrap .player-overlay, .player-wrap:fullscreen .player-overlay,
:fullscreen > .player-wrap .cast-panel, .player-wrap:fullscreen .cast-panel {
  padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
.load-overlay, .release-warning { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* Standalone app: iOS has no back button, so the top menu has one. */
.nav-back { font-size: 1.8rem; line-height: 1; padding: 0 .55rem .15rem; margin-right: .15rem; color: var(--text); }

/* One-time tip in Safari: add Nexarr to the home screen. */
.a2hs-tip { position: fixed; z-index: 950; left: max(.75rem, env(safe-area-inset-left)); right: max(.75rem, env(safe-area-inset-right));
  bottom: calc(1rem + env(safe-area-inset-bottom)); max-width: 30rem; margin: 0 auto; display: flex; align-items: center; gap: .6rem;
  padding: .7rem .6rem .7rem 1rem; background: var(--bg2, #16161f); border: 1px solid var(--accent); border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5); font-size: .9rem; }
html.is-phone .a2hs-tip { bottom: calc(4.4rem + env(safe-area-inset-bottom)); }
.a2hs-tip span { flex: 1; }
.a2hs-close { flex: none; width: 2.2rem; height: 2.2rem; border-radius: 50%; background: transparent; color: var(--text-muted); font-size: 1.4rem; line-height: 1; }
