/* =====================================================
   弹弹play Web UI — Design System v3
   Inspired by Plex / Apple TV+
   Dark by default · Light via [data-theme="light"]
   Accent: Amber #E8A020
   ===================================================== */

/* ---------- DESIGN TOKENS ---------- */
:root {
  color-scheme: dark;
  /* Surfaces */
  --bg:         #0a0a0a;
  --surface-1:  #111113;
  --surface-2:  #161618;
  --surface-3:  #1e1e21;
  --surface-4:  #252528;
  /* Text */
  --text-1:     #f0f0f0;
  --text-2:     #a0a0a8;
  --text-3:     #505058;
  --text-4:     #303038;
  /* Borders */
  --border:     rgba(255,255,255,0.07);
  --border-md:  rgba(255,255,255,0.12);
  /* Accent */
  --accent:     #E8A020;
  --accent-h:   #F0B030;
  --accent-dim: rgba(232,160,32,0.12);
  --accent-txt: #0a0a0a;
  /* Semantic */
  --danger:     #e24b4a;
  --danger-dim: rgba(226,75,74,0.10);
  --success:    #1D9E75;
  --info:       #378ADD;
  /* Layout */
  --nav-h:      52px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  /* Legacy compat (remote-android.css) */
  --card-bg:        var(--surface-2);
  --border-color:   var(--border);
  --text-color:     var(--text-1);
  --text-secondary: var(--text-2);
  --bg-color:       var(--bg);
  /* Legacy compat (bangumi modal) */
  --surface-modal:  var(--surface-1);
  --surface-overlay: var(--surface-1);
  --surface-card:   var(--surface-2);
  --border-soft:    var(--border-md);
  --border-faint:   var(--border);
  --text-primary:   var(--text-1);
  --text-muted:     var(--text-3);
  --text-body:      var(--text-1);
  --text-on-dark:   #f0f0f0;
  --backdrop:       rgba(0,0,0,0.65);
  --label-overlay:  rgba(0,0,0,0.6);
  --label-overlay-strong: rgba(0,0,0,0.75);
  --hover-surface:  var(--surface-3);
  --image-placeholder: var(--surface-3);
  --status-watched:     var(--success);
  --status-not-watched: var(--text-4);
  --status-not-aired:   var(--text-4);
  --highlight-bg:     var(--accent-dim);
  --highlight-border: var(--accent);
  --close-color:  var(--text-3);
  --close-hover:  var(--text-1);
}

[data-theme="light"] {
  color-scheme: light;
  --bg:         #f3f2ef;
  --surface-1:  #ffffff;
  --surface-2:  #eeece8;
  --surface-3:  #e2dfda;
  --surface-4:  #d4d0ca;
  --text-1:     #16171a;
  --text-2:     #44474e;
  --text-3:     #5f636c;
  --text-4:     #686c74;
  --border:     rgba(28,25,20,0.12);
  --border-md:  rgba(28,25,20,0.22);
  --accent:     #995f06;
  --accent-h:   #ad6e08;
  --accent-dim: rgba(153,95,6,0.11);
  --accent-txt: #ffffff;
  --danger:     #d32f2f;
  --danger-dim: rgba(211,47,47,0.08);
  --success:    #1a7a58;
  --info:       #1565c0;
  --card-bg:        var(--surface-1);
  --border-color:   var(--border);
  --text-color:     var(--text-1);
  --text-secondary: var(--text-2);
  --bg-color:       var(--bg);
  --surface-modal:  var(--surface-1);
  --surface-overlay: var(--surface-1);
  --surface-card:   var(--surface-1);
  --border-soft:    var(--border-md);
  --border-faint:   var(--border);
  --text-primary:   var(--text-1);
  --text-muted:     var(--text-3);
  --text-body:      var(--text-1);
  --text-on-dark:   #ffffff;
  --backdrop:       rgba(0,0,0,0.45);
  --label-overlay:  rgba(0,0,0,0.5);
  --label-overlay-strong: rgba(0,0,0,0.65);
  --hover-surface:  var(--surface-2);
  --image-placeholder: var(--surface-3);
  --status-watched:     #1a7a58;
  --status-not-watched: #676b73;
  --status-not-aired:   #737780;
  --highlight-bg:     rgba(153,95,6,0.11);
  --highlight-border: #995f06;
  --close-color:  var(--text-3);
  --close-hover:  var(--text-1);
}

/* ---------- THEME TRANSITION ---------- */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) {
  z-index: 2;
  animation: theme-reveal 520ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes theme-reveal {
  from { clip-path: circle(0 at var(--theme-reveal-x) var(--theme-reveal-y)); }
  to { clip-path: circle(var(--theme-reveal-radius) at var(--theme-reveal-x) var(--theme-reveal-y)); }
}

html.theme-fallback-transition body,
html.theme-fallback-transition .app-nav,
html.theme-fallback-transition .idx-nav,
html.theme-fallback-transition .modal-content,
html.theme-fallback-transition .tool-item,
html.theme-fallback-transition .follow-card {
  transition: background-color 360ms ease, color 360ms ease, border-color 360ms ease, box-shadow 360ms ease !important;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none !important; }
}

/* ---------- RESET ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text-1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
               'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- SCROLLBAR ---------- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 3px; }

/* =====================================================
   NAV BAR
   ===================================================== */
.app-nav {
  height: var(--nav-h);
  background: var(--surface-1);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  text-decoration: none;
}

.nav-brand-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.nav-brand:hover .nav-brand-icon { background: var(--accent-h); }
.nav-brand-icon svg { display: block; }

.nav-brand-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  gap: 2px;
  margin-left: 24px;
}

.nav-link {
  font-size: 13px;
  color: var(--text-3);
  padding: 5px 10px;
  border-radius: var(--r-sm);
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.nav-link:hover  { color: var(--text-2); background: var(--surface-2); }
.nav-link.active { color: var(--text-1); }

.nav-spacer { flex: 1; }

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-icon-btn {
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-icon-btn:hover { background: var(--surface-2); color: var(--text-2); }
.nav-icon-btn svg  { display: block; }

.nav-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 0.5px solid var(--border-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
}

.nav-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-3);
  padding: 5px 8px;
  border-radius: var(--r-sm);
  transition: color 0.15s;
  border: none;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}

.nav-back:hover { color: var(--text-2); }

.nav-divider {
  width: 0.5px; height: 16px;
  background: var(--border);
  flex-shrink: 0;
}

.nav-page-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
}

/* ---------- THEME TOGGLE (injected by theme.js) ---------- */
.theme-toggle {
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  background: transparent;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  font-size: 14px;
}

.theme-toggle:hover { background: var(--surface-2); color: var(--accent); }

/* =====================================================
   PAGE LAYOUT
   ===================================================== */
.app-body {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 28px 60px;
}

/* =====================================================
   HERO SECTION
   ===================================================== */
.hero {
  position: relative;
  height: 280px;
  background: var(--surface-1);
  overflow: hidden;
}

.hero-art      { position: absolute; inset: 0; display: flex; }
.hero-art-main { flex: 1; background: var(--surface-2); }
.hero-art-strips { width: 42%; display: flex; flex-direction: column; }
.hero-art-strips > div:nth-child(1) { flex: 3; background: var(--surface-2); }
.hero-art-strips > div:nth-child(2) { flex: 2; background: var(--surface-1); }
.hero-art-strips > div:nth-child(3) { flex: 1; background: var(--bg); }

/* When a real cover image is available */
.hero-art-main img {
  width: 100%; height: 100%;
  object-fit: cover; object-position: center top;
  display: block;
}

.hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 32px 36px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-dim);
  border: 0.5px solid rgba(232,160,32,0.3);
  border-radius: 4px;
  padding: 3px 9px;
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  width: fit-content;
}

.hero-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  line-height: 1.2;
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.hero-meta-dot {
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--text-4);
  flex-shrink: 0;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* =====================================================
   BUTTONS
   ===================================================== */
.btn-primary {
  background: var(--accent);
  color: var(--accent-txt);
  border: none;
  border-radius: var(--r-md);
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary:hover { background: var(--accent-h); color: var(--accent-txt); }
.btn-primary svg   { display: block; }

.btn-ghost {
  background: var(--surface-3);
  color: var(--text-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 18px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-ghost:hover { background: var(--surface-4); color: var(--text-1); }

.btn-sm { padding: 6px 13px; font-size: 12px; border-radius: var(--r-sm); }

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 0.5px solid rgba(226,75,74,0.2);
  border-radius: var(--r-sm);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:hover { background: rgba(226,75,74,0.18); }

.btn-subtle {
  background: transparent;
  color: var(--text-3);
  border: 0.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-subtle:hover { background: var(--surface-2); color: var(--text-2); }

/* =====================================================
   CONTENT SHELVES (index)
   ===================================================== */
.shelves { padding: 24px 0 0; }
.shelf   { margin-bottom: 36px; }

.shelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.shelf-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.01em;
}

.shelf-more {
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  transition: color 0.15s;
  background: none;
  border: none;
}

.shelf-more:hover { color: var(--accent); }

/* Continue-watching row (wide cards) */
.continue-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.continue-card {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: flex;
  cursor: pointer;
  transition: border-color 0.15s;
  text-decoration: none;
}

.continue-card:hover { border-color: var(--border-md); }

.continue-thumb {
  width: 64px;
  flex-shrink: 0;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
}

.continue-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.continue-info {
  padding: 12px 14px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.continue-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.continue-ep    { font-size: 11px; color: var(--text-3); margin-bottom: 10px; }
.continue-prog-track { height: 2px; background: var(--surface-4); border-radius: 1px; overflow: hidden; margin-bottom: 5px; }
.continue-prog-fill  { height: 100%; background: var(--accent); border-radius: 1px; }
.continue-pct   { font-size: 10px; color: var(--text-4); }

/* Poster row */
.poster-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.poster-row-4 { grid-template-columns: repeat(4, 1fr); }
.poster-row-5 { grid-template-columns: repeat(5, 1fr); }

.poster-card { cursor: pointer; text-decoration: none; display: block; }

.poster-thumb {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  overflow: hidden;
  position: relative;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}

.poster-card:hover .poster-thumb { border-color: var(--border-md); }
.poster-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.poster-prog { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: rgba(255,255,255,0.08); }
.poster-prog-fill { height: 100%; background: var(--accent); }

.poster-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.poster-sub {
  font-size: 11px;
  color: var(--text-4);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =====================================================
   TOOL LIST (index footer)
   ===================================================== */
.tool-list {
  border: 0.5px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* .tool-row  AND  .tool-item are the same component */
.tool-row,
.tool-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface-1);
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.tool-row:last-child,
.tool-item:last-child { border-bottom: none; }

.tool-row:hover,
.tool-item:hover { background: var(--surface-2); }

.tool-row-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Icon cell — both naming conventions */
.tool-icon,
.tool-item__icon {
  width: 34px; height: 34px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
  font-size: 14px;
  margin-right: 14px;
}

[data-theme="light"] .tool-icon,
[data-theme="light"] .tool-item__icon { background: var(--surface-3); }

/* Body (name + desc wrapper) */
.tool-item__body { flex: 1; }

.tool-name,
.tool-item__name { font-size: 13px; font-weight: 600; color: var(--text-1); }

.tool-desc,
.tool-item__desc { font-size: 11px; color: var(--text-3); margin-top: 2px; }

.tool-arrow,
.tool-item__arrow { font-size: 12px; color: var(--text-4); flex-shrink: 0; }

/* Section label */
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-4);
  text-transform: uppercase;
  margin-bottom: 14px;
  margin-top: 32px;
}

/* =====================================================
   STATUS PILLS
   ===================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

.pill-dl  { background: rgba(55,138,221,0.10); color: var(--info);    border: 0.5px solid rgba(55,138,221,0.20); }
.pill-sd  { background: rgba(29,158,117,0.10); color: var(--success); border: 0.5px solid rgba(29,158,117,0.20); }
.pill-ps  { background: var(--surface-3);      color: var(--text-3);  border: 0.5px solid var(--border); }
.pill-err { background: var(--danger-dim);     color: var(--danger);  border: 0.5px solid rgba(226,75,74,0.20); }
.pill-wt  { background: var(--surface-3);      color: var(--text-4);  border: 0.5px solid var(--border); }

/* =====================================================
   PROGRESS BARS
   ===================================================== */
.prog-track { height: 2px; background: var(--surface-4); border-radius: 1px; overflow: hidden; }
.prog-fill  { height: 100%; border-radius: 1px; transition: width 0.3s; }
.prog-amber { background: var(--accent); }
.prog-green { background: var(--success); }
.prog-blue  { background: var(--info); }
.prog-muted { background: var(--surface-4); }

/* =====================================================
   LOADING
   ===================================================== */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
  font-size: 24px;
}

/* =====================================================
   FORM ELEMENTS
   ===================================================== */
.form-label {
  font-size: 11px;
  color: var(--text-3);
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
}

.form-input {
  width: 100%;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 13px;
  color: var(--text-1);
  font-size: 13px;
  transition: border-color 0.15s;
  outline: none;
}

.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-4); }

.form-select {
  width: 100%;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 13px;
  color: var(--text-1);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

/* =====================================================
   FILTER TABS (download page)
   ===================================================== */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--border);
  flex-wrap: wrap;
}

.filter-tabs { display: flex; gap: 2px; flex-wrap: wrap; }

.filter-tab {
  background: transparent;
  border: none;
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.filter-tab:hover  { background: var(--surface-2); color: var(--text-2); }
.filter-tab.active { background: var(--accent-dim); color: var(--accent); }

/* =====================================================
   DOWNLOAD TASK LIST
   ===================================================== */
.dl-page-layout {
  padding: 0 28px 60px;
  max-width: 1100px;
  margin: 0 auto;
}

.dl-table-head {
  display: grid;
  grid-template-columns: 1fr 110px 90px 56px;
  padding: 10px 0 8px;
  border-bottom: 0.5px solid var(--border);
  margin-top: 4px;
}

.dl-th {
  font-size: 10px;
  color: var(--text-4);
  letter-spacing: 0.07em;
  font-weight: 600;
}

.dl-th:last-child { text-align: right; }

.task-item {
  padding: 16px 0;
  border-bottom: 0.5px solid var(--border);
}

.task-item:last-child { border-bottom: none; }

.task-top {
  display: grid;
  grid-template-columns: 1fr 110px 90px 56px;
  align-items: flex-start;
  gap: 0;
  margin-bottom: 10px;
}

.task-name {
  font-size: 13px;
  color: var(--text-1);
  line-height: 1.5;
  padding-right: 16px;
  word-break: break-word;
}

.task-name.deleted { color: var(--text-3); }

.task-speed { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.task-size  { font-size: 12px; color: var(--text-3); }
.task-pct   { font-size: 12px; font-weight: 600; text-align: right; color: var(--accent); }
.task-pct.green  { color: var(--success); }
.task-pct.muted  { color: var(--text-4); }

.task-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
}

.task-actions { display: flex; gap: 6px; margin-left: auto; }

/* =====================================================
   EMPTY STATE
   ===================================================== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-4);
}

.empty-state i   { font-size: 48px; opacity: 0.25; display: block; margin-bottom: 16px; }
.empty-state p   { font-size: 14px; }

/* =====================================================
   FOOTER
   ===================================================== */
.app-footer {
  padding: 16px 28px;
  border-top: 0.5px solid var(--border);
  font-size: 12px;
  color: var(--text-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 40px;
}

.app-footer a { color: var(--text-3); transition: color 0.15s; }
.app-footer a:hover { color: var(--accent); }

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  margin-right: 6px;
}

/* =====================================================
   SEARCH BAR
   ===================================================== */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0 12px;
  transition: border-color 0.15s;
}

.search-wrap:focus-within { border-color: var(--accent); }

.search-wrap svg { color: var(--text-4); flex-shrink: 0; }

.search-wrap input {
  background: transparent;
  border: none;
  outline: none;
  padding: 9px 0;
  font-size: 13px;
  color: var(--text-1);
  width: 200px;
}

.search-wrap input::placeholder { color: var(--text-4); }

/* =====================================================
   LOGIN PAGE
   ===================================================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 420px;
  max-width: 100%;
  padding: clamp(26px, 5vw, 42px);
  border: 1px solid var(--border-md);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface-1) 90%, transparent);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(20px) saturate(1.15);
  -webkit-backdrop-filter: blur(20px) saturate(1.15);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-brand-icon {
  width: 42px; height: 42px;
  background: var(--accent);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-brand-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.03em;
}

.login-heading {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 32px;
}

.login-field { margin-bottom: 14px; }

.login-submit {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: var(--r-md);
  padding: 12px;
  color: var(--accent-txt);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}

.login-submit:hover { background: var(--accent-h); }

.login-footer-note {
  font-size: 11px;
  color: var(--text-4);
  text-align: center;
  margin-top: 24px;
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 20px;
}

.login-remember input[type="checkbox"] {
  width: 14px; height: 14px;
  accent-color: var(--accent);
}

.login-error {
  background: var(--danger-dim);
  border: 0.5px solid rgba(226,75,74,0.25);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--danger);
  margin-top: 14px;
}

/* =====================================================
   BANGUMI — poster grid + modal
   ===================================================== */
.poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 16px;
}

.poster-item {
  position: relative;
  cursor: pointer;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  transition: border-color 0.15s;
  display: flex;
  flex-direction: column;
}

.poster-item:hover { border-color: var(--border-md); }

.poster-item img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  display: block;
  background: var(--surface-3);
}

.poster-info { padding: 9px 11px 11px; }

.poster-info h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
  margin-bottom: 3px;
}

.poster-info p { font-size: 11px; color: var(--text-3); }

.watched-info {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.group-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  margin: 28px 0 14px;
  letter-spacing: -0.01em;
  grid-column: 1 / -1;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  inset: 0;
  background: var(--backdrop);
  align-items: center;
  justify-content: center;
}

.modal[style*="display: block"] { display: flex !important; }

.modal-content {
  background: var(--surface-modal);
  border: 0.5px solid var(--border-md);
  width: 92%;
  max-width: 860px;
  max-height: 88vh;
  border-radius: var(--r-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 0.5px solid var(--border);
  padding: 20px 24px;
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-1);
  margin: 0 0 4px;
}

.modal-header small { font-size: 12px; color: var(--text-3); }

.season-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 24px 0;
}

.season-tab {
  appearance: none;
  border: 0.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.season-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.season-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-txt);
}

.close {
  color: var(--text-3);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s;
  background: none;
  border: none;
  padding: 0;
}

.close:hover { color: var(--text-1); }

/* Episode list */
.episode-list {
  list-style: none;
  padding: 8px 24px 20px;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.episode-item {
  border-bottom: 0.5px solid var(--border);
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  transition: background 0.15s;
}

.episode-item:last-child { border-bottom: none; }

.episode-item:hover { background: var(--surface-2); border-radius: var(--r-md); padding: 14px 10px; margin: 0 -10px; }

.episode-item.last-watched-episode {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  padding: 14px 10px 14px 12px;
  margin: 0 -10px;
}

.episode-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.episode-details {
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 0 12px;
}

.local-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.file-item-link {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  max-width: 200px;
  transition: border-color 0.15s;
  text-decoration: none;
}

.file-item-link:hover { border-color: var(--accent); }

.file-thumbnail {
  width: 80px;
  height: 46px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-3);
}

.file-item-info {
  font-size: 10px;
  color: var(--text-3);
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.file-item-info i { color: var(--accent); }

.status-icon { font-size: 13px; }
.status-icon.watched     { color: var(--status-watched); }
.status-icon.not-watched { color: var(--status-not-watched); }
.status-icon.not-aired   { color: var(--status-not-aired); }

.no-local-files {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 13px;
  padding: 8px 2px 0;
}

/* =====================================================
   FILE LIST
   ===================================================== */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.file-item {
  position: relative;
  cursor: pointer;
  appearance: none;
  width: 100%;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  overflow: hidden;
  transition: border-color 0.15s;
}

.file-item:hover { border-color: var(--border-md); }

.thumbnail {
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 9;
  position: relative;
  overflow: hidden;
}

.thumbnail img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbnail i   { color: var(--text-3); font-size: 2rem; }

.file-item h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
  padding: 8px 10px 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item p {
  font-size: 11px;
  color: var(--text-3);
  padding: 0 10px 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-extension {
  position: absolute;
  bottom: 5px;
  right: 5px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 9px;
  padding: 2px 5px;
  border-radius: 3px;
  text-transform: uppercase;
}

.file-description {
  position: absolute;
  top: 5px;
  left: 5px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
}

/* =====================================================
   QUICK NAV (bangumi sidebar)
   ===================================================== */
#quickNavContainer {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  z-index: 200;
}

#quickNav {
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-right: none;
  border-radius: var(--r-md) 0 0 var(--r-md);
  padding: 8px 0;
  max-height: 70vh;
  overflow-y: auto;
  transition: transform 0.25s;
}

#quickNav.collapsed { transform: translateX(100%); }

#quickNav a {
  display: block;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  transition: color 0.15s;
}

#quickNav a:hover { color: var(--accent); }

#quickNavToggle {
  width: 22px; height: 40px;
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-right: none;
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-3);
  font-size: 12px;
}

/* =====================================================
   REMOTE CONTROL PAGES
   ===================================================== */
.remote-page {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.player-card, .control-card {
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: var(--r-xl);
  padding: 20px;
  margin-bottom: 14px;
}

.player-card { text-align: center; }

.player-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

.status-playing  { background: rgba(55,138,221,0.12); color: var(--info); }
.status-paused   { background: rgba(232,160,32,0.12); color: var(--accent); }
.status-stopped  { background: var(--surface-3); color: var(--text-3); }

.media-title    { font-size: 16px; font-weight: 700; color: var(--text-1); margin-bottom: 4px; }
.media-subtitle { font-size: 12px; color: var(--text-3); margin-bottom: 14px; }

.time-display {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 6px;
}

.progress-bar-container {
  background: var(--surface-3);
  height: 5px;
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  touch-action: none;
}

.progress-bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.control-section { margin-bottom: 22px; }
.control-section:last-child { margin-bottom: 0; }

.control-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: var(--text-4);
  text-transform: uppercase;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.playback-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.ctrl-btn {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.ctrl-btn:active   { opacity: 0.7; }
.ctrl-btn:disabled { opacity: 0.3; cursor: default; }

.ctrl-btn-xl     { width: 64px; height: 64px; background: var(--accent); color: var(--accent-txt); font-size: 24px; }
.ctrl-btn-lg     { width: 48px; height: 48px; background: var(--surface-3); color: var(--text-2); font-size: 18px; }
.ctrl-btn-sm     { width: 40px; height: 40px; background: var(--surface-2); color: var(--text-3); font-size: 15px; }
.ctrl-btn-danger { background: var(--danger-dim); color: var(--danger); }

.volume-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.volume-row input[type="range"] { flex: 1; accent-color: var(--accent); }

.volume-val {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  min-width: 38px;
  text-align: right;
}

.speed-grid { display: flex; flex-wrap: wrap; gap: 6px; }

.speed-btn {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s;
}

.speed-btn:hover  { background: var(--surface-3); }
.speed-btn.active { background: var(--accent-dim); color: var(--accent); border-color: rgba(232,160,32,0.3); }

.seek-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.seek-btn {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 7px 12px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s;
}

.seek-btn:hover { background: var(--surface-3); }

.brightness-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brightness-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.brightness-val { font-size: 12px; color: var(--text-2); min-width: 38px; text-align: right; }

/* Danmu collapsible */
.danmu-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-4);
}

.danmu-content { overflow: hidden; max-height: 0; transition: max-height 0.3s ease; }
.danmu-content.open { max-height: 2000px; }

.danmu-group {
  padding: 12px 0;
  border-bottom: 0.5px solid var(--border);
}

.danmu-group:last-child { border-bottom: none; }
.danmu-group:first-child { margin-top: 14px; }

.danmu-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 8px;
}

.danmu-label label { font-size: 12px; color: var(--text-2); }
.danmu-val { color: var(--accent); font-weight: 700; font-size: 12px; }

.danmu-slider { accent-color: var(--accent); width: 100%; }

.danmu-checkbox-group {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.danmu-check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
}

.danmu-check-item input[type="checkbox"] { accent-color: var(--accent); }

/* Connection panel (android remote) */
.connection-panel {
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: var(--r-xl);
  padding: 16px;
  margin-bottom: 14px;
}

.connection-form { display: flex; gap: 8px; margin-bottom: 10px; }
.connection-form .form-input { flex: 1; min-width: 0; }

.connection-status {
  padding: 8px 12px;
  border-radius: var(--r-md);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-disconnected { background: var(--danger-dim); color: var(--danger); }
.status-connecting   { background: var(--accent-dim); color: var(--accent); }
.status-connected    { background: rgba(29,158,117,0.10); color: var(--success); }

/* Loading overlay */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-overlay.show { display: flex; }
.loading-spinner { color: var(--text-1); font-size: 2rem; }

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
  .app-nav      { padding: 0 16px; }
  .app-body     { padding: 0 16px 40px; }
  .nav-links    { display: none; }
  .hero         { height: 220px; }
  .hero-title   { font-size: 20px; }
  .hero-overlay { padding: 20px; }
  .poster-row-4 { grid-template-columns: repeat(2, 1fr); }
  .poster-row-5 { grid-template-columns: repeat(3, 1fr); }
  .continue-row { grid-template-columns: 1fr; }
  .dl-page-layout { padding: 0 16px 40px; }
  .dl-table-head  { display: none; }
  .task-top { grid-template-columns: 1fr auto; }
  .task-speed, .task-size { display: none; }
  .app-footer   { padding: 16px; }
  .login-page   { padding: 16px; }
  .poster-grid  { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

@media (max-width: 480px) {
  .poster-row-5 { grid-template-columns: repeat(2, 1fr); }
  .hero { height: 180px; }
  .hero-title { font-size: 17px; }
}

/* =====================================================
   BEM NAV ALIASES & EXTENSIONS
   (used by the rewritten HTML pages)
   ===================================================== */
.app-nav__inner {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 0;
}

.app-nav__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  text-decoration: none;
  color: var(--text-1);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition: color 0.15s;
}

.app-nav__brand i {
  color: var(--accent);
  font-size: 20px;
}

.app-nav__brand:hover { color: var(--accent); }

.app-nav__end {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.app-nav__user {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

.app-nav__logout {
  color: var(--text-4);
  font-size: 14px;
  text-decoration: none;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  transition: color 0.15s, background 0.15s;
}

.app-nav__logout:hover { color: var(--danger); background: var(--danger-dim); }

.app-nav__search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  transition: border-color 0.15s;
}

.app-nav__search:focus-within { border-color: var(--accent); }

.app-nav__search i { color: var(--text-4); font-size: 12px; }

.app-nav__search-toggle {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--text-4);
  background: transparent;
}

.app-nav__search-toggle:hover,
.app-nav__search-toggle:focus-visible { color: var(--accent); }

.app-nav__search-toggle i { color: currentColor; }

.app-nav__search input {
  background: transparent;
  border: none;
  outline: none;
  font-size: 12px;
  color: var(--text-1);
  width: 160px;
}

.app-nav__search input::placeholder { color: var(--text-4); }

/* Media library route navigation */
.app-nav--library .app-nav__inner {
  gap: clamp(14px, 1.8vw, 28px);
}

.library-nav__rail,
.library-nav__group {
  display: flex;
  align-items: center;
}

.library-nav__rail {
  flex: 1 1 auto;
  min-width: 0;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: none;
}

.library-nav__rail::-webkit-scrollbar { display: none; }

.library-nav__group {
  flex: 0 0 auto;
  gap: 2px;
}

.library-nav__home,
.library-nav__link {
  position: relative;
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  transition:
    color var(--motion-fast, 150ms) ease,
    background-color var(--motion-fast, 150ms) ease,
    border-color var(--motion-fast, 150ms) ease,
    transform var(--motion-fast, 150ms) ease;
}

.library-nav__home {
  border: 1px solid rgba(232,160,32,.28);
  background: rgba(232,160,32,.08);
  color: var(--accent);
}

.library-nav__home:hover,
.library-nav__home:focus-visible {
  border-color: rgba(232,160,32,.55);
  background: rgba(232,160,32,.15);
  transform: translateY(-1px);
}

.library-nav__link:hover,
.library-nav__link:focus-visible {
  color: var(--text-1);
  background: var(--surface-2);
}

.library-nav__link.is-active {
  color: var(--accent-txt);
  background: linear-gradient(135deg, #ffe49d, var(--accent));
  box-shadow: 0 7px 22px rgba(232,160,32,.2);
}

.library-nav__home:focus-visible,
.library-nav__link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.library-nav__group-label {
  flex: 0 0 auto;
  margin: 0 4px 0 2px;
  color: var(--text-4);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.library-nav__divider {
  width: 1px;
  height: 22px;
  flex: 0 0 auto;
  margin-inline: 2px;
  background: var(--border);
}

@media (max-width: 1180px) {
  .app-nav.app-nav--library {
    height: auto;
    padding: 0;
    align-items: stretch;
  }

  .app-nav--library .app-nav__inner {
    max-width: none;
    flex-wrap: wrap;
    gap: 0;
  }

  .app-nav--library .app-nav__brand {
    margin: 0 auto 0 clamp(14px, 3vw, 28px);
    min-height: 56px;
  }

  .app-nav--library .app-nav__end {
    margin-right: clamp(14px, 3vw, 28px);
  }

  .library-nav__rail {
    order: 3;
    flex-basis: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    padding: 7px clamp(14px, 3vw, 28px) 9px;
    border-top: 1px solid var(--border);
  }

  .library-nav__rail::-webkit-scrollbar { display: none; }

  .app-nav--library .library-nav__home {
    position: sticky;
    left: 0;
    z-index: 3;
    overflow: hidden;
    background: var(--surface-1);
    box-shadow: 10px 0 0 var(--surface-1);
  }
}

@media (max-width: 560px) {
  .app-nav--library .app-nav__brand span { max-width: 42vw; }
  .library-nav__rail { gap: 5px; }
  .library-nav__group-label { display: none; }
  .library-nav__home,
  .library-nav__link { min-height: 32px; padding: 6px 9px; font-size: 11px; }
  .library-nav__divider { margin-inline: 1px; }
}

/* Video page nav modifier */
.app-nav--video { background: var(--bg); border-bottom-color: var(--border); }

.app-nav__breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 20px;
  font-size: 12px;
  color: var(--text-3);
  overflow: hidden;
}

.app-nav__breadcrumb span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.app-nav__breadcrumb .active { color: var(--text-1); }
.app-nav__breadcrumb i { font-size: 9px; flex-shrink: 0; }

/* =====================================================
   APP MAIN WRAPPER
   ===================================================== */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 28px 60px;
}

/* =====================================================
   SHELF BEM ALIASES
   ===================================================== */
.shelf__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

.shelf__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.01em;
}

.shelf__more {
  font-size: 12px;
  color: var(--text-3);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s;
}

.shelf__more:hover { color: var(--accent); }

/* =====================================================
   HERO BEM (index.html)
   ===================================================== */
.hero {
  position: relative;
  background: linear-gradient(135deg, var(--surface-1) 0%, var(--surface-2) 100%);
  overflow: hidden;
  margin-bottom: 36px;
  border-radius: var(--r-xl);
}

.hero__inner {
  position: relative;
  z-index: 2;
  padding: 52px 48px;
  max-width: 600px;
}

.hero__eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 12px;
}

.hero__title {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-1);
  line-height: 1.1;
  margin-bottom: 10px;
}

.hero__sub {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 28px;
}

.hero__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-hero-primary {
  background: var(--accent);
  color: var(--accent-txt);
  border: none;
  border-radius: var(--r-md);
  padding: 11px 24px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}

.btn-hero-primary:hover { background: var(--accent-h); color: var(--accent-txt); }

.btn-hero-secondary {
  background: var(--surface-3);
  color: var(--text-1);
  border: 0.5px solid var(--border-md);
  border-radius: var(--r-md);
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}

.btn-hero-secondary:hover { background: var(--surface-4); }

/* =====================================================
   DOWNLOAD PAGE — ADDITIONAL
   ===================================================== */
.dl-loading {
  padding: 60px 0;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
}

.dl-list { padding: 0; }

.dl-empty {
  padding: 80px 0;
  text-align: center;
  color: var(--text-4);
}

.dl-empty i { font-size: 48px; opacity: 0.2; display: block; margin-bottom: 16px; }

/* Accent button (download add task) */
.btn-accent {
  background: var(--accent);
  color: var(--accent-txt);
  border: none;
  border-radius: var(--r-md);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-accent:hover { background: var(--accent-h); }

.filter-bar__actions { display: flex; align-items: center; gap: 8px; }

.filter-tab__count {
  background: var(--surface-3);
  border-radius: 10px;
  padding: 0 6px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.filter-tab.active .filter-tab__count { background: var(--accent-dim); }

/* task-header / task-info reuse from download.html */
.task-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.task-status-wrapper { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.task-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.status-downloading, .status-starting, .status-hashing, .status-metadata {
  background: rgba(55,138,221,0.15); color: var(--info);
}
.status-paused, .status-stopping, .status-stopped {
  background: rgba(245,124,0,0.12); color: #f57c00;
}
.status-seeding { background: rgba(29,158,117,0.12); color: var(--success); }
.status-error   { background: var(--danger-dim); color: var(--danger); }
.status-waitingforstart { background: var(--surface-3); color: var(--text-3); }

.task-item.deleted { opacity: 0.7; }

.deleted-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text-3);
}

.task-info {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--text-2);
}

.task-info-item { display: flex; align-items: center; gap: 4px; }
.task-info-item i { width: 12px; text-align: center; font-size: 10px; }

.task-progress { margin-bottom: 6px; }

.task-files-toggle {
  cursor: pointer;
  font-size: 11px;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s;
}

.task-files-toggle:hover { color: var(--text-2); }

.task-files {
  margin-top: 8px;
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px;
}

.task-files-header { font-size: 11px; color: var(--text-3); margin-bottom: 6px; }

.task-file-item {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  margin-bottom: 4px;
  font-size: 11px;
}

.task-file-header { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.task-file-name { color: var(--text-1); word-break: break-all; }
.task-file-progress-text { color: var(--accent); font-weight: 600; white-space: nowrap; }
.task-file-path { color: var(--text-4); font-size: 10px; word-break: break-all; }

/* =====================================================
   REMOTE CONTROL (remote-pc.html)
   ===================================================== */
.remote-shelf { max-width: 600px; }

.remote-card {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.player-status {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

.status-playing { background: rgba(55,138,221,0.15); color: var(--info); }
.status-paused  { background: rgba(245,124,0,0.12); color: #f57c00; }
.status-stopped { background: var(--surface-3); color: var(--text-3); }

.current-media { margin-top: 4px; margin-bottom: 12px; }
.media-title { font-size: 15px; font-weight: 700; color: var(--text-1); margin-bottom: 4px; }
.media-subtitle { font-size: 12px; color: var(--text-3); }

.progress-section {}
.time-display {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 6px;
}

.progress-bar-container {
  background: var(--surface-4);
  height: 5px;
  border-radius: 3px;
  cursor: pointer;
  position: relative;
}

.progress-bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.control-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.playback-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.control-btn {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  touch-action: manipulation;
}

.control-btn:active { transform: scale(0.9); }

.control-btn-large  { width: 68px; height: 68px; font-size: 26px; }
.control-btn-small  { width: 50px; height: 50px; font-size: 18px; }

.btn-primary-control  { background: var(--accent); color: var(--accent-txt); }
.btn-secondary-control { background: var(--surface-4); color: var(--text-1); }
.btn-danger-control   { background: var(--danger-dim); color: var(--danger); }

.btn-primary-control:hover  { background: var(--accent-h); }
.btn-secondary-control:hover { background: var(--surface-3); }
.btn-danger-control:hover   { background: rgba(226,75,74,0.2); }

.volume-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.volume-slider { flex: 1; accent-color: var(--accent); }
.volume-value { min-width: 40px; text-align: right; font-size: 12px; font-weight: 600; color: var(--text-2); }

.seek-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* =====================================================
   VIDEO PAGE LAYOUT
   ===================================================== */
.video-page { background: var(--bg); }
.video-layout { padding: var(--nav-h) 0 0; }

/* =====================================================
   LOGIN PAGE BODY
   ===================================================== */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-brand i {
  font-size: 40px;
  color: var(--accent);
  display: block;
  margin-bottom: 16px;
}

.login-form { margin-top: 20px; }

.login-field {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.login-field:focus-within { border-color: var(--accent); }

.login-field__icon {
  padding: 0 12px;
  color: var(--text-3);
  font-size: 14px;
  flex-shrink: 0;
}

.login-field__input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 12px 12px 12px 0;
  font-size: 14px;
  color: var(--text-1);
}

.login-field__input::placeholder { color: var(--text-4); }

.login-password-toggle {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  border-radius: var(--r-md);
}

.login-password-toggle:hover { color: var(--text-1); background: var(--surface-3); }

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  margin-bottom: 20px;
}

.login-error {
  background: var(--danger-dim);
  color: var(--danger);
  border: 0.5px solid rgba(226,75,74,0.2);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* =====================================================
   RESPONSIVE ADDITIONS
   ===================================================== */
@media (max-width: 768px) {
  .app-main { padding: 16px 16px 40px; }
  .app-nav__search { display: none; }
  .library-page .app-nav__search {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    display: flex;
    justify-content: center;
    padding: 0;
  }
  .library-page .app-nav__search input { display: none; }
  .library-page .app-nav__search.is-open {
    position: fixed;
    z-index: 120;
    top: 9px;
    left: 10px;
    right: 10px;
    width: auto;
    height: 46px;
    padding: 4px 12px;
    justify-content: flex-start;
    border-color: var(--accent);
    box-shadow: 0 12px 36px rgba(0,0,0,.34);
  }
  .library-page .app-nav__search.is-open input {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    font-size: 16px;
  }
  .app-nav__user { display: none; }
  .hero__inner { padding: 32px 24px; }
  .hero__title { font-size: 24px; }
  .remote-shelf { max-width: 100%; }
  .control-btn-large { width: 60px; height: 60px; font-size: 22px; }
  .control-btn-small { width: 46px; height: 46px; font-size: 16px; }
}

@media (max-width: 480px) {
  .app-nav__breadcrumb { display: none; }
  .hero__inner { padding: 24px 16px; }
  .hero__title { font-size: 20px; }
}

/* =====================================================
   PRODUCT SYSTEM V4 — shared layout, feedback and states
   ===================================================== */
:root {
  --content-max: 1440px;
  --content-reading: 760px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --shadow-sm: 0 6px 20px rgba(0,0,0,0.16);
  --shadow-md: 0 18px 52px rgba(0,0,0,0.28);
  --focus-ring: 0 0 0 3px rgba(232,160,32,0.28);
  --motion-fast: 140ms;
  --motion-base: 220ms;
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] {
  --shadow-sm: 0 6px 22px rgba(31,26,18,0.08);
  --shadow-md: 0 20px 56px rgba(31,26,18,0.14);
}

body {
  background-image:
    radial-gradient(circle at 8% -10%, rgba(232,160,32,0.08), transparent 30rem),
    radial-gradient(circle at 96% 8%, rgba(55,138,221,0.06), transparent 26rem);
  background-attachment: fixed;
}

[data-theme="light"] body {
  background-image:
    radial-gradient(circle at 8% -10%, rgba(153,95,6,0.12), transparent 31rem),
    radial-gradient(circle at 96% 8%, rgba(69,103,142,0.08), transparent 28rem);
}

::selection { background: rgba(232,160,32,0.32); color: var(--text-1); }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

button:disabled,
.btn:disabled,
[aria-disabled="true"] {
  cursor: not-allowed !important;
  opacity: 0.48;
}

button:not(:disabled):active,
.btn:not(:disabled):active,
.btn-accent:not(:disabled):active,
.btn-ghost:not(:disabled):active {
  transform: translateY(1px) scale(0.985);
}

.app-nav {
  height: 60px;
  background: rgba(17,17,19,0.82);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 1px 0 var(--border), 0 12px 40px rgba(0,0,0,0.1);
}

[data-theme="light"] .app-nav { background: rgba(255,255,255,0.86); }

.app-nav__inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

.app-nav__brand i {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #111;
  font-size: 14px;
  background: linear-gradient(145deg, #ffd76f, var(--accent) 62%, #ff8b24);
  box-shadow: 0 8px 24px rgba(232,160,32,0.22);
}

.app-main {
  width: 100%;
  max-width: var(--content-max);
  padding: 34px clamp(20px, 3vw, 48px) 72px;
}

.shelf__header {
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 24px;
}

.shelf__title {
  font-size: clamp(20px, 2vw, 28px);
  line-height: 1.2;
  letter-spacing: -0.035em;
}

.page-heading { min-width: 0; }

.page-heading__eyebrow {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.page-heading__description {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.55;
  margin-top: 7px;
  max-width: 62ch;
}

.shelf__more {
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  white-space: nowrap;
}

.shelf__more:hover {
  border-color: var(--border-md);
  background: var(--surface-2);
  transform: translateY(-1px);
}

.poster-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 16px; }

.poster-item,
.file-item,
.remote-card,
.task-item {
  transition:
    transform var(--motion-base) var(--ease-out),
    border-color var(--motion-fast) ease,
    box-shadow var(--motion-base) ease,
    background-color var(--motion-fast) ease;
}

.poster-item:hover,
.file-item:hover {
  transform: translateY(-4px);
  border-color: rgba(232,160,32,0.42);
  box-shadow: var(--shadow-sm);
}

.poster-item:focus-visible,
.file-item:focus-visible { box-shadow: var(--focus-ring), var(--shadow-sm); }

.poster-item img,
.thumbnail img {
  transition: opacity var(--motion-base) ease, transform 420ms var(--ease-out);
}

.poster-item:hover img,
.file-item:hover .thumbnail img { transform: scale(1.025); }

.poster-info { padding: 11px 12px 13px; }
.poster-info h3 { font-size: 13px; line-height: 1.45; }
.poster-info p { font-size: 11px; }

.group-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  margin: 36px 0 4px;
  scroll-margin-top: 84px;
}

.group-name::after {
  content: '';
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, var(--border-md), transparent 70%);
}

.file-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.file-item h3 { font-size: 13px; padding: 10px 12px 4px; }
.file-item p { padding: 0 12px 12px; }

.filter-bar {
  padding: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  position: sticky;
  top: 72px;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.filter-tab { min-height: 36px; padding: 7px 12px; }
.filter-tab.active { background: var(--accent); color: var(--accent-txt); }
.filter-tab.active .filter-tab__count { color: inherit; background: rgba(0,0,0,0.12); }

.btn-accent,
.btn-ghost {
  min-height: 38px;
  justify-content: center;
  transition: transform var(--motion-fast), background-color var(--motion-fast), border-color var(--motion-fast), opacity var(--motion-fast);
}

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: var(--r-md);
  padding: 8px 14px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.btn-ghost:hover { background: var(--surface-3); color: var(--text-1); }

.dl-loading,
.dl-empty,
.state-panel {
  min-height: 300px;
  padding: 60px 24px;
  border: 1px dashed var(--border-md);
  border-radius: var(--r-xl);
  background: linear-gradient(145deg, var(--surface-1), color-mix(in srgb, var(--surface-2) 72%, transparent));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-3);
}

.state-panel__icon,
.dl-empty > i {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 22px;
  opacity: 1;
  margin: 0 0 16px;
}

.state-panel__title,
.dl-empty p { color: var(--text-1); font-size: 16px; font-weight: 700; margin: 0; }
.state-panel__description,
.dl-empty small { color: var(--text-3); font-size: 13px; max-width: 48ch; margin-top: 7px; }
.state-panel__actions { display: flex; gap: 8px; margin-top: 18px; }
.state-panel--error .state-panel__icon { color: var(--danger); background: var(--danger-dim); }

.task-item {
  padding: 18px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-1);
}

.task-item:hover { border-color: var(--border-md); box-shadow: var(--shadow-sm); }

.list-load-more {
  display: flex;
  justify-content: center;
  padding: 18px 0 6px;
}

.remote-shelf { max-width: 900px; }
.remote-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr); gap: 16px; }
.remote-card { border: 1px solid var(--border); box-shadow: 0 1px 0 rgba(255,255,255,0.02); }
.remote-card--status { background: linear-gradient(145deg, var(--surface-2), var(--surface-1)); }
.remote-card__hint { color: var(--text-3); font-size: 12px; margin-top: 8px; }

.app-footer {
  width: 100%;
  max-width: var(--content-max);
  margin: 40px auto 0;
  padding-inline: clamp(20px, 3vw, 48px);
}

.app-page-enter { animation: app-page-enter var(--motion-base) var(--ease-out) both; }

@keyframes app-page-enter {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

.app-toast-region {
  position: fixed;
  z-index: 2200;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(390px, calc(100vw - 32px));
  pointer-events: none;
}

.app-toast {
  min-height: 52px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 11px;
  padding: 12px 12px 12px 15px;
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: var(--shadow-md);
  color: var(--text-1);
  font-size: 13px;
  pointer-events: auto;
  animation: toast-in var(--motion-base) var(--ease-out) both;
}

.app-toast--success > i { color: var(--success); }
.app-toast--warning > i { color: #f2b544; }
.app-toast--error > i { color: var(--danger); }
.app-toast--info > i { color: var(--info); }
.app-toast__close { width: 30px; height: 30px; border: 0; border-radius: 50%; background: transparent; color: var(--text-3); }
.app-toast__close:hover { background: var(--surface-3); color: var(--text-1); }
.app-toast.is-leaving { animation: toast-out 180ms ease both; }

@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }

.app-confirm {
  position: fixed;
  z-index: 2300;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.62);
  opacity: 0;
  transition: opacity 150ms ease;
}

.app-confirm.is-visible { opacity: 1; }
.app-confirm.is-leaving { opacity: 0; }

.app-confirm__dialog {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--border-md);
  border-radius: 20px;
  background: var(--surface-1);
  box-shadow: var(--shadow-md);
  transform: translateY(10px) scale(.98);
  transition: transform var(--motion-base) var(--ease-out);
}

.app-confirm.is-visible .app-confirm__dialog { transform: translateY(0) scale(1); }
.app-confirm__icon { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 15px; color: var(--danger); background: var(--danger-dim); margin-bottom: 18px; }
.app-confirm h2 { color: var(--text-1); font-size: 19px; letter-spacing: -.02em; margin: 0; }
.app-confirm p { color: var(--text-2); font-size: 13px; line-height: 1.65; margin: 9px 0 22px; }
.app-confirm__actions { display: flex; justify-content: flex-end; gap: 8px; }
.app-confirm__primary.is-danger { background: var(--danger); color: #fff; }
.app-confirm__primary.is-danger:hover { background: #ef5f5d; }

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-3);
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent);
  animation: skeleton-shimmer 1.45s ease-in-out infinite;
}

@keyframes skeleton-shimmer { to { transform: translateX(100%); } }

@media (max-width: 900px) {
  .remote-grid { grid-template-columns: 1fr; }
  .filter-bar { position: static; }
}

@media (max-width: 768px) {
  .app-nav { height: 56px; padding-inline: 14px; }
  .app-nav__brand span { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-main { padding: 24px 16px 48px; }
  .shelf__header { align-items: flex-start; margin-bottom: 20px; }
  .shelf__title { font-size: 22px; }
  .page-heading__description { font-size: 12px; }
  .shelf__more { min-height: 34px; padding: 7px 10px; }
  .poster-grid { grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 16px 12px; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .filter-bar__actions { width: 100%; }
  .filter-bar__actions > * { flex: 1; }
  .filter-tabs { flex-wrap: nowrap; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .filter-tabs::-webkit-scrollbar { display: none; }
  .task-item { padding: 15px; }
  .task-info { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
  .task-actions { flex-wrap: wrap; margin-left: 0; margin-top: 10px; }
  .app-footer { margin-top: 24px; padding: 18px 16px; }
}

@media (max-width: 480px) {
  .shelf__header { flex-direction: column; gap: 12px; }
  .shelf__more { align-self: flex-start; }
  .poster-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .file-grid { grid-template-columns: 1fr; }
  .file-item { display: grid; grid-template-columns: 112px minmax(0,1fr); }
  .file-item .thumbnail { grid-row: 1 / span 2; aspect-ratio: 16 / 11; }
  .file-item h3 { align-self: end; }
  .filter-bar { padding: 10px; }
  .modal-content { width: calc(100% - 16px); max-height: calc(100dvh - 24px); }
  .modal-header { padding: 16px; }
  .episode-list { padding-inline: 16px; }
  .season-tabs { padding-inline: 16px; overflow-x: auto; flex-wrap: nowrap; }
}

/* =====================================================
   MEDIA LIBRARY - clear shelves and route navigation
   ===================================================== */
.library-page { background-color: var(--bg); }

.library-page .app-nav {
  height: 72px;
  background: color-mix(in srgb, var(--surface-1) 97%, var(--bg));
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.library-page .app-nav__inner,
.library-page .app-main,
.library-page .app-footer {
  max-width: 1920px;
}

.library-page .app-nav__inner { gap: 16px; }

.library-page .app-nav__brand {
  min-height: 42px;
  padding-right: 18px;
  border-right: 1px solid var(--border);
}

.library-page .library-nav__rail {
  gap: 10px;
  overflow-x: auto;
}

.library-page .library-nav__home {
  min-height: 40px;
  padding: 0 13px;
  border-radius: 11px;
  border-color: color-mix(in srgb, var(--accent) 34%, var(--border));
  background: var(--accent-dim);
}

.library-page .library-nav__group {
  min-height: 42px;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
}

.library-page .library-nav__group-label {
  margin: 0;
  padding: 0 7px;
  color: var(--text-3);
  font-size: 9px;
  letter-spacing: .08em;
}

.library-page .library-nav__divider { display: none; }

.library-page .library-nav__link {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 9px;
  color: var(--text-2);
  font-size: 12px;
}

.library-page .library-nav__link:hover,
.library-page .library-nav__link:focus-visible {
  background: var(--surface-3);
}

.library-page .library-nav__link.is-active {
  color: var(--accent-txt);
  background: var(--accent);
  box-shadow: none;
}

.library-page .app-nav__search {
  min-height: 38px;
  border-radius: 11px;
  background: var(--surface-2);
}

.library-page .app-nav__search input { width: clamp(120px, 10vw, 190px); }

.library-page .app-main {
  padding: 30px clamp(18px, 2.2vw, 42px) 72px;
}

.library-page .shelf__header {
  align-items: center;
  gap: 28px;
  margin-bottom: 22px;
  padding: 22px 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-1);
}

.library-page .page-heading__description { max-width: 70ch; }

.library-summary {
  flex: 0 0 auto;
  min-width: 104px;
  display: grid;
  justify-items: end;
  gap: 3px;
  margin-left: auto;
  padding-left: 24px;
  border-left: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.library-summary strong {
  color: var(--text-1);
  font-size: clamp(24px, 2vw, 32px);
  line-height: 1;
  letter-spacing: -.04em;
}

.library-summary span {
  color: var(--text-3);
  font-size: 11px;
  white-space: nowrap;
}

.library-page .poster-grid { display: block; }

.poster-group {
  display: block;
  margin-bottom: 18px;
  padding: clamp(18px, 1.8vw, 26px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-1);
  scroll-margin-top: 88px;
}

.poster-group:last-child { margin-bottom: 0; }

.poster-group__header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.poster-group .group-name {
  display: block;
  min-width: 0;
  margin: 0;
  color: var(--text-1);
  font-size: clamp(18px, 1.35vw, 22px);
  line-height: 1.25;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.poster-group .group-name::after { display: none; }

.poster-group__count {
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--text-3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.poster-group__grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
  align-items: start;
  gap: 20px 16px;
}

.library-page .poster-item {
  min-width: 0;
  border-radius: 14px;
  border-color: var(--border);
  background: var(--surface-2);
  box-shadow: none;
}

.library-page .poster-item::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text-1) 3%, transparent);
  pointer-events: none;
}

.library-page .poster-item:hover,
.library-page .poster-item:focus-visible {
  z-index: 2;
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--accent) 52%, var(--border));
  box-shadow: var(--shadow-sm);
}

.library-page .poster-info {
  min-height: 78px;
  padding: 12px 13px 14px;
}

.library-page .poster-info h3 {
  font-size: 13px;
  line-height: 1.45;
}

.library-page .watched-info {
  z-index: 2;
  top: 8px;
  left: 8px;
  padding: 4px 7px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  background: rgba(10,10,12,.76);
  font-variant-numeric: tabular-nums;
}

.poster-progress {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) var(--watch-progress), rgba(255,255,255,.08) var(--watch-progress));
}

.poster-rank {
  position: absolute;
  z-index: 3;
  top: 8px;
  right: 8px;
  min-width: 34px;
  height: 27px;
  display: grid;
  place-items: center;
  padding-inline: 7px;
  border-radius: 9px;
  color: var(--accent-txt);
  background: var(--accent);
  font-size: 10px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.library-page #quickNavContainer { right: 12px; z-index: 120; }

.library-page #quickNav {
  width: max-content;
  max-width: 180px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  box-shadow: var(--shadow-sm);
  transform: none;
  transition: max-width 180ms ease, padding 180ms ease, opacity 140ms ease, border-color 140ms ease;
}

.library-page #quickNav.collapsed {
  width: 0;
  max-width: 0;
  padding-inline: 0;
  opacity: 0;
  overflow: hidden;
  border-color: transparent;
  transform: none;
  pointer-events: none;
}

.library-page #quickNav a {
  padding: 7px 9px;
  border-radius: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-page #quickNav a:hover,
.library-page #quickNav a:focus-visible {
  color: var(--accent);
  background: var(--surface-2);
}

.library-page #quickNavToggle {
  width: 30px;
  height: 44px;
  margin-left: 5px;
  border: 1px solid var(--border);
  border-radius: 9px;
}

/* Recent files stay in a uniform media grid. */
[data-library-view="recent-files"] .file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  grid-auto-flow: row;
  gap: 18px;
}

[data-library-view="recent-files"] .file-item {
  min-width: 0;
  height: auto;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: var(--surface-2);
}

[data-library-view="recent-files"] .file-item .thumbnail {
  flex: 0 0 auto;
  aspect-ratio: 16 / 9;
}

[data-library-view="recent-files"] .file-item h3 {
  padding: 11px 13px 4px;
  font-size: 13px;
}

[data-library-view="recent-files"] .file-item p { padding: 0 13px 3px; }
[data-library-view="recent-files"] .file-item p:last-child { padding-bottom: 12px; }

[data-library-view="recent-files"] .file-item--directory .thumbnail,
[data-library-view="recent-files"] .file-item--shortcut .thumbnail {
  background: var(--surface-3);
}

/* Light mode keeps the same hierarchy without dark-only translucent surfaces. */
[data-theme="light"] .library-page .app-nav {
  background: rgba(255,255,255,.94);
  box-shadow: 0 1px 0 var(--border), 0 14px 38px rgba(42,34,22,.07);
}

[data-theme="light"] .library-page .library-nav__group,
[data-theme="light"] .library-page .app-nav__search {
  background: #ebe8e2;
}

[data-theme="light"] .library-page .shelf__header,
[data-theme="light"] .poster-group,
[data-theme="light"] .library-page #quickNav {
  box-shadow: 0 12px 36px rgba(42,34,22,.055);
}

[data-theme="light"] .library-page .poster-item,
[data-theme="light"] [data-library-view="recent-files"] .file-item {
  background: #f5f3ef;
}

[data-theme="light"] .library-page .poster-item:hover,
[data-theme="light"] .library-page .poster-item:focus-visible,
[data-theme="light"] [data-library-view="recent-files"] .file-item:hover,
[data-theme="light"] [data-library-view="recent-files"] .file-item:focus-visible {
  background: #ffffff;
  box-shadow: 0 16px 36px rgba(42,34,22,.12);
}

[data-theme="light"] .library-page #quickNavToggle,
[data-theme="light"] .theme-toggle {
  color: var(--text-2);
  background: rgba(255,255,255,.72);
  border-color: var(--border);
}

[data-theme="light"] .library-page #quickNavToggle:hover,
[data-theme="light"] .theme-toggle:hover {
  color: var(--accent);
  background: #ffffff;
}

@media (max-width: 1480px) {
  .library-page .library-nav__group-label { display: none; }
  .library-page .app-nav__inner { gap: 10px; }
  .library-page .library-nav__rail { gap: 6px; }
  .library-page .library-nav__link { padding-inline: 8px; }
}

@media (max-width: 1180px) {
  .library-page .app-nav { height: auto; }
  .library-page .app-nav__inner { max-width: none; gap: 0; }
  .library-page .app-nav__brand { border-right: 0; }
  .library-page .library-nav__rail {
    gap: 7px;
    padding: 8px clamp(14px, 3vw, 28px) 10px;
  }
  .library-page .library-nav__home {
    background: var(--surface-1);
    box-shadow: -18px 0 0 var(--surface-1), 10px 0 0 var(--surface-1);
  }
  .library-page .library-nav__group { border: 0; background: transparent; padding: 0; }
  .poster-group__grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

@media (max-width: 900px) {
  .library-page #quickNavContainer { display: none; }
  .library-page .shelf__header { padding: 20px; }
  .poster-group { padding: 18px; }
  .poster-group__grid { grid-template-columns: repeat(auto-fill, minmax(142px, 1fr)); gap: 16px 12px; }
  [data-library-view="recent-files"] .file-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
}

@media (max-width: 680px) {
  .library-page .app-main { padding: 20px 14px 48px; }
  .library-page .shelf__header {
    align-items: flex-end;
    gap: 14px;
    padding: 16px;
    border-radius: 14px;
  }
  .library-summary { min-width: 72px; padding-left: 12px; }
  .library-summary strong { font-size: 22px; }
  .library-summary span { font-size: 9px; }
  .poster-group {
    margin-bottom: 14px;
    padding: 14px;
    border-radius: 14px;
  }
  .poster-group__header { margin-bottom: 14px; padding-bottom: 11px; }
  .poster-group .group-name { font-size: 18px; }
  .poster-group__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 10px; }
  .library-page .poster-info { min-height: 72px; padding: 10px 11px 12px; }
  [data-library-view="recent-files"] .file-grid { grid-template-columns: 1fr; }
  [data-library-view="recent-files"] .file-item { display: block; }
}

@media (max-width: 420px) {
  .library-page .poster-info h3 { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
