/* =========================
   Media Center Themes
   ========================= */
:root,
:root[data-theme="cinema-noir"] {
  --bg: #0b0c10;
  --bg-elev: #141720;
  --bg-card: #191d28;
  --bg-glass: rgba(20, 23, 32, 0.85);
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.09);
  --accent: #e50914;
  --accent-2: #f5c518;
  --focus: #f5c518;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.55);
}

:root[data-theme="midnight-tv"] {
  --bg: #070d19;
  --bg-elev: #0f172a;
  --bg-card: #16223b;
  --bg-glass: rgba(15, 23, 42, 0.88);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.16);
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --focus: #38bdf8;
  --shadow: 0 18px 45px rgba(2, 6, 23, 0.65);
}

:root[data-theme="studio-light"] {
  --bg: #f3f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.9);
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(15, 23, 42, 0.1);
  --accent: #2563eb;
  --accent-2: #0ea5e9;
  --focus: #2563eb;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

:root[data-theme="emerald-lounge"] {
  --bg: #07130f;
  --bg-elev: #0d1f19;
  --bg-card: #122a22;
  --bg-glass: rgba(13, 31, 25, 0.88);
  --text: #ecfdf5;
  --muted: #86efac;
  --border: rgba(110, 231, 183, 0.14);
  --accent: #10b981;
  --accent-2: #34d399;
  --focus: #6ee7b7;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

/* Remote / Keyboard TV-friendly focus rings */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

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

/* =========================
   Buttons & Inputs
   ========================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 0.5rem 0.95rem;
  border-radius: 0.65rem;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-ghost {
  background: transparent;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 0.75rem 1.4rem;
  font-size: 1rem;
}

.btn-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 0.5rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
}

.btn-icon:hover {
  color: var(--text);
  background: var(--border);
}

input[type="text"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 0.55rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

/* =========================
   Auth Gate
   ========================= */
.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.auth-card {
  max-width: 440px;
  text-align: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

/* =========================
   Topbar & Anchor Tab Underline
   ========================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.6rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
}

.brand-mark.large {
  width: 3.5rem;
  height: 3.5rem;
  font-size: 1.4rem;
  margin: 0 auto 1rem;
}

.main-tabs ul {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}

.main-tabs ul::before {
  content: "";
  position: absolute;
  position-anchor: --active-tab;
  inset-block-start: calc(anchor(bottom) + 2px);
  inset-inline-start: anchor(left);
  inset-inline-end: anchor(right);
  block-size: 3px;
  border-radius: 999px;
  background: var(--accent);
}

@media (prefers-reduced-motion: no-preference) {
  .main-tabs ul::before {
    transition: inset 0.2s ease;
  }
}

.main-tabs li.active {
  anchor-name: --active-tab;
}

@supports not (position-anchor: auto) {
  .main-tabs ul::before {
    display: none;
  }
  .main-tabs li.active {
    border-bottom: 3px solid var(--accent);
  }
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  border-radius: 0.55rem;
  cursor: pointer;
}

.main-tabs li.active .tab-btn,
.tab-btn:hover {
  color: var(--text);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.logout-link {
  color: var(--muted);
  text-decoration: none;
}

.logout-link:hover {
  color: var(--accent);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  display: inline-block;
}

/* =========================
   Main View & View Transitions
   ========================= */
.main-view {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

@keyframes slide-to-left {
  to { transform: translateX(-18%); opacity: 0; }
}
@keyframes slide-from-right {
  from { transform: translateX(18%); opacity: 0; }
}
@keyframes slide-to-right {
  to { transform: translateX(18%); opacity: 0; }
}
@keyframes slide-from-left {
  from { transform: translateX(-18%); opacity: 0; }
}

::view-transition-group(root) {
  animation-duration: 0.28s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

html:active-view-transition-type(forward)::view-transition-old(root) {
  animation-name: slide-to-left;
}
html:active-view-transition-type(forward)::view-transition-new(root) {
  animation-name: slide-from-right;
}
html:active-view-transition-type(backward)::view-transition-old(root) {
  animation-name: slide-to-right;
}
html:active-view-transition-type(backward)::view-transition-new(root) {
  animation-name: slide-from-left;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(root) {
    animation: none !important;
  }
}

/* =========================
   Hero & Section Headers
   ========================= */
.hero-card {
  position: relative;
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1.5rem;
  align-items: center;
  background: linear-gradient(135deg, var(--bg-elev), var(--bg-card));
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow);
}

.hero-poster {
  width: 180px;
  height: 250px;
  object-fit: cover;
  border-radius: 0.85rem;
  background: var(--bg);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.25rem 0 1rem;
  flex-wrap: wrap;
}

.section-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.crumb-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.4rem;
}

.crumb-btn:hover,
.crumb-btn.current {
  color: var(--text);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* =========================
   Media & Folder Grids
   ========================= */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.15rem;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

.card:hover,
.card:focus-within {
  transform: translateY(-3px) scale(1.01);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.folder-card {
  padding: 1.15rem;
  gap: 0.65rem;
  min-height: 150px;
  justify-content: space-between;
}

.folder-icon-badge {
  width: 3rem;
  height: 3rem;
  border-radius: 0.85rem;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent-2);
  font-size: 1.5rem;
}

.folder-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.video-poster-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #05070a;
  overflow: hidden;
}

.video-poster-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 2.2rem;
  color: var(--muted);
}

.video-badges {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  display: flex;
  gap: 0.3rem;
}

.badge {
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 0.35rem;
}

.progress-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
}

.progress-fill {
  height: 100%;
  background: var(--accent);
}

.card-body {
  padding: 0.85rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.card-title {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-top: auto;
  padding-top: 0.35rem;
}

.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  border: 1px dashed var(--border);
  border-radius: 1rem;
  color: var(--muted);
}

/* =========================
   Player Overlay
   ========================= */
.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  color: #fff;
  display: flex;
  flex-direction: column;
}

.player-overlay[hidden] {
  display: none;
}

.player-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: rgba(12, 14, 18, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.player-title-wrap h2 {
  margin: 0;
  font-size: 1.05rem;
}

.player-controls-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.sub-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.sub-select-wrap select,
#playerSubSize {
  width: auto;
  background: #141821;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.resume-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: rgba(20, 24, 34, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.player-stage {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0.5rem;
}

.player-stage video {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 76px);
  outline: none;
}

video.sub-sm::cue { font-size: 0.85rem; }
video.sub-md::cue { font-size: 1.15rem; }
video.sub-lg::cue { font-size: 1.55rem; }

/* =========================
   Top-Layer Dialog Animations
   ========================= */
dialog {
  width: min(540px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  background: var(--bg-elev);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: scale(0.95);
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.22s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

dialog.dialog-wide {
  width: min(920px, calc(100vw - 2rem));
}

dialog[open] {
  opacity: 1;
  transform: scale(1);
  @starting-style {
    opacity: 0;
    transform: scale(0.95);
  }
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0);
  transition:
    display 0.22s allow-discrete,
    overlay 0.22s allow-discrete,
    background-color 0.22s ease-out;
}

dialog[open]::backdrop {
  background-color: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
  @starting-style {
    background-color: rgba(0, 0, 0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog {
    transform: none;
    transition-duration: 0.1s;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow-y: auto;
  max-height: 70vh;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.92rem;
  cursor: pointer;
}

.icon-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 0.45rem;
}

.icon-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem 0.35rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.75rem;
}

.icon-choice.selected {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 760px) {
  .meta-grid {
    grid-template-columns: 1fr;
  }
  .hero-card {
    grid-template-columns: 1fr;
  }
}

.meta-col {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.meta-col h3 {
  margin: 0.4rem 0 0.1rem;
  font-size: 0.95rem;
  color: var(--accent-2);
}

.search-bar,
.inline-actions {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.lang-input {
  width: 56px !important;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 210px;
  overflow-y: auto;
}

.search-item {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--bg);
}

.search-item img {
  width: 44px;
  height: 64px;
  object-fit: cover;
  border-radius: 0.35rem;
}

.search-item-info {
  flex: 1;
  min-width: 0;
  font-size: 0.84rem;
}

.subs-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.subs-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.6rem;
  border-radius: 0.45rem;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 0.85rem;
  padding: 1.5rem;
  text-align: center;
  background: var(--bg);
}

.drop-zone.dragover {
  border-color: var(--accent);
}

.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.theme-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
  padding: 1rem;
  border-radius: 0.75rem;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.theme-card.active {
  border-color: var(--accent);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--accent);
  padding: 0.7rem 1.1rem;
  border-radius: 0.7rem;
  box-shadow: var(--shadow);
  font-weight: 600;
}
