: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: 1.5rem;
}

.nav-link {
  color: var(--text-muted);
  font-size: .95rem;
  transition: color .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;
}

/* ── 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:hover .admin-dropdown { display: block; }
.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(200px, 1fr));
  gap: .75rem;
  margin-bottom: .75rem;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .85rem;
  color: var(--text-muted);
}
.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; }

.player-wrap:fullscreen { display: flex; flex-direction: column; width: 100%; max-width: none; height: 100%; margin: 0; background: #000; border-radius: 0; }
.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; }
.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 .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 .player-topbar { flex-direction: column; align-items: stretch; gap: .35rem; }
html.is-phone .player-ext-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .2rem; }
html.is-phone .player-ext-btn { flex: none; min-height: 2.4rem; min-width: 2.4rem; }
html.is-phone .player-audio { flex: none; max-width: 11rem; min-height: 2.4rem; }
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-ext-bar { flex-wrap: wrap; overflow: visible; min-width: 0; max-width: 100%; }
html.is-phone .player-audio { max-width: 100%; min-width: 0; }
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 { 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; padding: .4rem; background: linear-gradient(rgba(0,0,0,.7), transparent); transition: opacity .25s; }
html.is-phone .controls-hidden .player-topbar { opacity: 0; pointer-events: none; }
html.is-phone .player-ext-bar { flex-wrap: nowrap; overflow-x: auto; }
html.is-phone .player-ext-btn, html.is-phone .player-audio { flex: none; background: rgba(0,0,0,.45); border-color: rgba(255,255,255,.3); color: #fff; }
html.is-phone .player-audio { max-width: 9rem; }
