@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=Noto+Sans+TC:wght@400;500;700&display=swap');

:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --text: #1f2a2e;
  --muted: #5d6a70;
  --primary: #0f766e;
  --accent: #c2410c;
  --border: #ded8cb;
  --good: #157f3b;
  --warn: #b45309;
  --bad: #b91c1c;
  --shadow: 0 10px 30px rgba(30, 41, 59, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
body {
  margin: 0;
  font-family: 'Noto Sans TC', 'PingFang TC', sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.9), rgba(244, 241, 234, 0.96)),
    var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  max-width: 100%;
}

.sidebar {
  border-right: 1px solid rgba(222, 216, 203, 0.8);
  background:
    radial-gradient(circle at 14% 10%, rgba(253, 230, 138, 0.72), transparent 28%),
    radial-gradient(circle at 94% 2%, rgba(153, 246, 228, 0.76), transparent 34%),
    linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(248, 243, 234, 0.9));
  backdrop-filter: blur(10px);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  z-index: 40;
  align-self: start;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
}

.brand {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 4px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
}

.nav-group {
  margin: 8px 0 18px;
}

.nav-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 10px 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  color: #253237;
  font-size: 14px;
}

.nav-link:hover {
  background: #f8f3ea;
  border-color: var(--border);
}

.nav-link.active {
  background: #ecfdf5;
  border-color: #86efac;
  color: #14532d;
  font-weight: 700;
}

.main {
  padding: 20px;
  min-width: 0;
  max-width: 100%;
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(222, 216, 203, 0.78);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.76);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 28px rgba(30, 41, 59, 0.06);
}


.sticky-page-head {
  position: sticky;
  top: 12px;
  z-index: 26;
  margin-bottom: 14px;
}

.sticky-page-head .topbar {
  position: static;
  margin-bottom: 10px;
}

.sticky-page-head .filter-card {
  margin-bottom: 0;
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(14px);
}

.anime-library-main {
  position: relative;
}

.anime-library-main > #anime-grid {
  scroll-margin-top: 240px;
}

.anime-library-head {
  position: sticky;
  top: 12px;
  z-index: 35;
  border-radius: 18px;
}

.anime-library-head::before {
  content: '';
  position: absolute;
  inset: -20px -20px -12px;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(244, 241, 234, 0.96), rgba(244, 241, 234, 0.72) 72%, rgba(244, 241, 234, 0));
}

.anime-library-head .topbar,
.anime-library-head .filter-card {
  box-shadow: 0 12px 30px rgba(30, 41, 59, 0.08);
}

.topbar-main {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.page-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 28px;
  font-weight: 700;
  margin-right: auto;
  min-width: 0;
}

.topbar-search {
  width: min(420px, 100%);
  min-width: 220px;
  flex: 1;
  background: rgba(255, 255, 255, 0.92);
}

.topbar-home .topbar-search {
  width: 100%;
  max-width: none;
  min-width: 0;
  flex: 0 0 auto;
}

.top-right-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  order: 99;
}

.mobile-more-menu {
  display: none;
  position: relative;
  margin-left: auto;
  order: 98;
}

.mobile-more-menu summary {
  list-style: none;
}

.mobile-more-menu summary::-webkit-details-marker {
  display: none;
}

.mobile-more-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  min-width: 156px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.98);
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.16);
}

.mobile-more-menu-panel .btn {
  width: 100%;
  justify-content: center;
  display: flex;
  margin-bottom: 6px;
}

.mobile-more-menu-panel .btn:last-child {
  margin-bottom: 0;
}

.topbar .btn,
.topbar .badge {
  white-space: nowrap;
}

.hero-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}

.hero-main {
  border-radius: 18px;
  border: 1px solid #c4b5fd;
  padding: 22px;
  background:
    radial-gradient(circle at 90% 10%, rgba(255, 255, 255, 0.75), transparent 42%),
    linear-gradient(125deg, #0f766e, #115e59 50%, #134e4a);
  color: #ecfeff;
  box-shadow: 0 16px 40px rgba(15, 118, 110, 0.28);
}

.hero-main h2 {
  margin: 0 0 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 34px;
  line-height: 1.1;
}

.hero-main p {
  margin: 0 0 14px;
  color: rgba(236, 254, 255, 0.9);
}

.hero-sub {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-tile {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric-tile .v {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 26px;
  font-weight: 700;
}

.metric-tile .k {
  font-size: 12px;
  color: var(--muted);
}

.metric-sub {
  margin-top: 2px;
  font-size: 11px;
  color: #8a6b4f;
}

.hero-inline {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.hero-chip {
  font-size: 12px;
  border: 1px solid rgba(236, 254, 255, 0.45);
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(15, 23, 42, 0.2);
  color: #f0fdfa;
}

.recent-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.recent-scroll {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: calc((100% - 42px) / 4);
  grid-template-columns: none;
  gap: 14px;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scroll-snap-type: x proximity;
}

.recent-scroll .recent-card {
  scroll-snap-align: start;
}

.recent-scroll .recent-card h4,
.recent-scroll .recent-card .meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, #fff, #fffaf0);
  padding: 10px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.recent-card .meta {
  font-size: 12px;
  color: var(--muted);
}

.recent-card h4 {
  margin: 10px 0 6px;
  font-size: 16px;
  overflow-wrap: anywhere;
}


/* Anime library cards: align long titles/metas and equalize actions. */
#anime-grid {
  align-items: stretch;
}

#anime-grid .card {
  display: grid;
  grid-template-rows: auto minmax(2.8em, auto) minmax(2.6em, auto) auto;
  gap: 8px;
  height: 100%;
}

#anime-grid .card .cover {
  align-self: start;
}

#anime-grid .card h3 {
  display: -webkit-box;
  min-height: 0;
  max-height: 2.8em;
  margin: 0;
  overflow: hidden;
  color: #17252b;
  font-size: clamp(14px, 1vw, 16px);
  font-weight: 800;
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

#anime-grid .card .meta {
  display: -webkit-box;
  min-height: 2.6em;
  max-height: 2.6em;
  margin: 0;
  overflow: hidden;
  line-height: 1.3;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

#anime-grid .card .split-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-self: end;
  margin-top: 0;
}

#anime-grid .card .split-actions .btn {
  width: 100%;
  min-width: 0;
  padding-left: 8px;
  padding-right: 8px;
  text-align: center;
  white-space: nowrap;
}

#anime-grid .card .split-actions .btn-primary {
  grid-column: 1 / -1;
}

@media (max-width: 520px) {
  #anime-grid .card {
    grid-template-rows: auto minmax(2.7em, auto) minmax(2.5em, auto) auto;
    gap: 7px;
  }

  #anime-grid .card h3 {
    min-height: 0;
    max-height: 2.7em;
    font-size: clamp(12px, 3.4vw, 14px);
    line-height: 1.35;
  }

  #anime-grid .card .meta {
    min-height: 2.5em;
    max-height: 2.5em;
    font-size: 11px;
    line-height: 1.25;
  }

  #anime-grid .card .split-actions {
    gap: 6px;
  }
}

/* Dashboard all-anime cards: keep titles adaptive without breaking card alignment. */
#all-anime-grid {
  align-items: stretch;
}

#all-anime-grid .recent-card {
  display: grid;
  grid-template-rows: auto minmax(2.8em, auto) minmax(2.6em, auto) auto;
  gap: 8px;
  height: 100%;
}

#all-anime-grid .recent-card .cover {
  align-self: start;
}

#all-anime-grid .recent-card h4 {
  display: -webkit-box;
  min-height: 2.8em;
  max-height: 2.8em;
  margin: 0;
  overflow: hidden;
  color: #17252b;
  font-size: clamp(13px, 0.95vw, 15px);
  font-weight: 800;
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

#all-anime-grid .recent-card .meta {
  display: -webkit-box;
  min-height: 2.6em;
  max-height: 2.6em;
  margin: 0;
  overflow: hidden;
  line-height: 1.3;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

#all-anime-grid .recent-card .split-actions {
  align-self: end;
  margin-top: 0;
}

@media (max-width: 520px) {
  #all-anime-grid .recent-card {
    grid-template-rows: auto minmax(2.7em, auto) minmax(2.5em, auto) auto;
    gap: 7px;
  }

  #all-anime-grid .recent-card h4 {
    min-height: 2.7em;
    max-height: 2.7em;
    font-size: clamp(12px, 3.4vw, 14px);
    line-height: 1.35;
  }

  #all-anime-grid .recent-card .meta {
    min-height: 2.5em;
    max-height: 2.5em;
    font-size: 11px;
    line-height: 1.25;
  }
}

.home-recent,
.home-continue,
.home-all-anime {
  min-width: 0;
  max-width: 100%;
}

.home-recent {
  overflow: hidden;
}

.card-action-right {
  justify-content: flex-end;
}

.meta-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}

.meta-action .meta {
  margin: 0;
}

.split-actions {
  width: 100%;
  justify-content: space-between;
}

.timeline {
  border-left: 2px dashed #cbd5e1;
  padding-left: 12px;
}

.timeline-item {
  margin-bottom: 12px;
}

.timeline-item:last-child {
  margin-bottom: 0;
}

.timeline-item .t {
  font-size: 12px;
  color: var(--muted);
}

.timeline-item .m {
  font-size: 14px;
}

.timeline-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-panel {
  display: grid;
  gap: 10px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-name {
  width: 100px;
  color: var(--muted);
  font-size: 13px;
}

.status-bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.status-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.status-bar.good > span { background: linear-gradient(90deg, #34d399, #10b981); }
.status-bar.warn > span { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.status-bar.bad > span { background: linear-gradient(90deg, #f87171, #ef4444); }

.auto-report-box {
  border: 1px dashed #94a3b8;
  border-radius: 12px;
  padding: 10px 12px;
  background: #f8fafc;
}

.auto-report-box .title {
  font-weight: 700;
  font-size: 13px;
}

.auto-report-box .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.badge {
  font-size: 12px;
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
}

.btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  background: #fff;
  color: #21343a;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  min-height: 38px;
}

.btn:hover { box-shadow: var(--shadow); }

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

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
}

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

.btn-ghost {
  background: transparent;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }


#all-anime-grid,
#anime-grid {
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}

@media (min-width: 1440px) {
  #all-anime-grid,
  #anime-grid {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  }
}

@media (max-width: 900px) {
  #all-anime-grid,
  #anime-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

@media (max-width: 520px) {
  #all-anime-grid,
  #anime-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 360px) {
  #all-anime-grid,
  #anime-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card h3 {
  margin: 0 0 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
}

.card p {
  margin: 6px 0;
  color: #3f4f55;
  font-size: 14px;
}

.stat {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 30px;
  font-weight: 700;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
}

.input, .select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  min-height: 42px;
}

.filter-card {
  margin-bottom: 14px;
}

.filter-row {
  align-items: stretch;
}

.filter-row .input {
  flex: 1 1 260px;
}

.filter-select-sm { max-width: 180px; }
.filter-select-md { max-width: 200px; }

.filter-summary {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.source-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.source-status strong {
  display: block;
  margin-bottom: 4px;
}

.source-status p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.source-status.ok { border-color: #86efac; background: rgba(240, 253, 244, 0.88); }
.source-status.warn { border-color: #fde68a; background: rgba(255, 251, 235, 0.9); }
.source-status.error { border-color: #fecaca; background: rgba(254, 242, 242, 0.92); }
.source-status.loading { border-color: #bfdbfe; background: rgba(239, 246, 255, 0.9); }

.empty-state {
  display: none;
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  background: #f8fafc;
  color: var(--muted);
}

.empty-state.show {
  display: block;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.spacer { flex: 1; }
.row .spacer { min-width: 0; }

.cover {
  border-radius: 10px;
  border: 1px solid var(--border);
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  object-position: center top;
  background: #f2f0ea;
}


.anime-detail-layout {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.anime-detail-cover .cover {
  max-width: 132px;
}

.anime-detail-info {
  min-width: 0;
}

.anime-detail-info h3 {
  margin-top: 0;
}

@media (max-width: 520px) {
  .anime-detail-layout {
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 12px;
  }

  .anime-detail-cover .cover {
    max-width: 96px;
  }
}

.episode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}

.episode-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  background: #fff;
  min-width: 0;
}

.episode-item.has-watch-status {
  display: grid;
  gap: 5px;
  align-content: center;
}

.episode-item-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.episode-watch-status,
.episode-webdav-status {
  justify-self: center;
  max-width: 100%;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.episode-status-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}

.episode-webdav-status.ready {
  background: #dcfce7;
  color: #15803d;
}

.episode-webdav-status.pending {
  background: #fff7ed;
  color: #c2410c;
}

.episode-item.unavailable {
  border-color: #fed7aa;
  background: #fff7ed;
}


.episode-item.seen .episode-watch-status {
  background: #f1f5f9;
  color: #475569;
}

.episode-item.current {
  border-color: #0f766e;
  background: #ecfdf5;
}

.episode-item.current .episode-watch-status {
  background: #0f766e;
  color: #ecfeff;
}

.episode-item.done {
  border-color: #16a34a;
  background: #f0fdf4;
}

.episode-item.done .episode-watch-status {
  background: #16a34a;
  color: #f0fdf4;
}

.episode-item:hover { border-color: #94a3b8; }
.episode-item.active { background: #ecfeff; border-color: #22d3ee; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.table-wrap.compact-scroll {
  max-height: 320px;
}

.table-wrap.compact-scroll table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
}


.settings-sections {
  display: grid;
  gap: 12px;
}

.settings-panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.62);
}

.settings-panel h4 {
  margin: 0 0 10px;
  font-size: 15px;
}

.settings-panel .meta {
  margin: -4px 0 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}


.admin-main {
  scroll-behavior: smooth;
}

.admin-workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.admin-menu {
  position: sticky;
  top: 92px;
  z-index: 18;
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid rgba(222, 216, 203, 0.82);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.admin-menu-title {
  padding: 0 6px 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.admin-menu-link {
  display: block;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  color: #334155;
  font-size: 14px;
}

.admin-menu-link:hover,
.admin-menu-link.active {
  border-color: #99f6e4;
  background: #ecfdf5;
  color: #0f766e;
  font-weight: 800;
}

.admin-content {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.admin-section {
  scroll-margin-top: 96px;
}

.admin-section[hidden],
#admin-overview[hidden] {
  display: none !important;
}

.admin-section.is-active {
  animation: adminSectionIn 0.18s ease-out;
}

@keyframes adminSectionIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

#admin-login-security {
  display: grid;
  gap: 14px;
}

.admin-mobile-list {
  display: none;
  gap: 10px;
}

.table-pager {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.table-pager .meta {
  min-width: 130px;
  margin: 0;
  text-align: center;
}

.table-pager .btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.admin-mobile-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.admin-mobile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.admin-mobile-title {
  font-weight: 700;
}

.admin-mobile-meta {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 10px 12px; border-bottom: 1px solid #eee6d8; text-align: left; font-size: 13px; }
th { background: #faf7f0; color: #475569; }

.history-mobile-list {
  display: none;
  gap: 10px;
}

.history-mobile-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.history-mobile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-mobile-title {
  font-size: 15px;
  font-weight: 700;
}

.history-mobile-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.history-mobile-meta {
  margin-top: 4px;
  font-size: 13px;
  color: #334155;
}

.tag {
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border: 1px solid transparent;
}

.tag.good { background: #ecfdf3; color: var(--good); border-color: #86efac; }

.stream-rate-badge {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.tag.warn { background: #fff7ed; color: var(--warn); border-color: #fdba74; }
.tag.bad { background: #fef2f2; color: var(--bad); border-color: #fca5a5; }


.watch-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 14px;
  align-items: start;
}

.watch-player-card,
.watch-episode-panel {
  min-width: 0;
}

.watch-control-row {
  margin-top: 12px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 2px;
}

.watch-control-row .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.watch-control-row .btn[disabled] {
  cursor: default;
  opacity: 0.78;
}

.watch-control-row .btn[aria-pressed] {
  cursor: pointer;
}

.watch-episode-panel {
  position: sticky;
  top: 14px;
  height: var(--watch-player-height, auto);
  max-height: calc(100vh - 28px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.watch-episode-list {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.watch-episode-group {
  min-width: 0;
}

.watch-episode-group-title {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.watch-episode-group-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.watch-episode-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 5px 6px;
  background: #fff;
  color: var(--text);
  text-align: center;
  text-decoration: none;
}

.watch-episode-link:hover {
  border-color: #60a5fa;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.12);
}

.watch-episode-link.current {
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  border-color: #0f766e;
  color: #ecfeff;
}

.watch-episode-link.unavailable:not(.current) {
  opacity: 0.58;
  background: #f8fafc;
}

.watch-episode-no {
  width: 100%;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.watch-episode-meta {
  color: inherit;
  font-size: 11px;
  opacity: 0.78;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-box {
  position: relative;
  min-height: 260px;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  border: 1px solid #111827;
  background: #020617;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: #e5e7eb;
}

.player-box.is-clickable {
  cursor: pointer;
}

.player-box.is-loading {
  cursor: wait;
}

.watch-video {
  width: 100%;
  height: 100%;
  min-height: 260px;
  display: block;
  background: #020617;
}

.player-status {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.78);
  color: #f8fafc;
  padding: 10px 12px;
  font-size: 13px;
  backdrop-filter: blur(8px);
}

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

.player-status.loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(248, 250, 252, 0.35);
  border-top-color: #f8fafc;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}

.player-status.hide {
  display: none;
}

.progress {
  width: 100%;
  accent-color: var(--primary);
}

.watch-shell {
  display: grid;
  gap: 14px;
}

.watch-card {
  overflow: hidden;
}

.episode-shortcuts {
  justify-content: space-between;
}


.watchlist-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.watchlist-cover {
  display: block;
  min-width: 0;
}

.watchlist-cover .cover {
  border-radius: 12px;
}

.watchlist-body {
  min-width: 0;
}

.watchlist-body h3 {
  margin-top: 0;
}

.watchlist-progress {
  display: grid;
  gap: 5px;
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

/* Watchlist cards: align long titles/metas and use two-row actions. */
#watchlist-grid {
  align-items: stretch;
}

.watchlist-card {
  height: 100%;
}

.watchlist-body {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 6px;
  height: 100%;
}

.watchlist-body h3 {
  display: -webkit-box;
  min-height: 2.8em;
  max-height: 2.8em;
  margin: 0;
  overflow: hidden;
  color: #17252b;
  font-size: clamp(14px, 1vw, 16px);
  font-weight: 800;
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.watchlist-progress {
  align-self: start;
  min-height: 0;
  max-height: none;
  overflow: visible;
}

.watchlist-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-self: end;
  margin-top: 0;
}

.watchlist-actions .btn {
  width: 100%;
  min-width: 0;
  padding-left: 8px;
  padding-right: 8px;
  text-align: center;
  white-space: nowrap;
}

.watchlist-actions .btn-primary,
.watchlist-actions > span:last-child {
  grid-column: 1 / -1;
}

@media (max-width: 520px) {
  .watchlist-body {
    grid-template-rows: auto auto auto;
    gap: 5px;
  }

  .watchlist-body h3 {
    min-height: 2.7em;
    max-height: 2.7em;
    font-size: clamp(12px, 3.4vw, 14px);
    line-height: 1.35;
  }

  .watchlist-progress {
    min-height: 0;
    max-height: none;
  }

  .watchlist-actions {
    gap: 6px;
  }
}

.btn.is-loading {
  opacity: 0.78;
  cursor: wait;
}

.btn.is-loading::after {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: spin .8s linear infinite;
}

.btn.is-added {
  background: #ecfdf5;
  border-color: #86efac;
  color: #166534;
}

.watchlist-added-pulse {
  animation: addedPulse .7s ease;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes addedPulse {
  0% { transform: scale(1); box-shadow: var(--shadow); }
  45% { transform: scale(1.015); box-shadow: 0 18px 42px rgba(15, 118, 110, 0.2); }
  100% { transform: scale(1); box-shadow: var(--shadow); }
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(480px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 32px;
  margin: 0 0 4px;
}

.login-sub {
  color: var(--muted);
  margin: 0 0 16px;
}

.login-hint {
  margin: -4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.verify-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(8px);
}

.verify-modal.show {
  display: grid;
}

.verify-card {
  width: min(420px, 100%);
  border: 1px solid rgba(222, 216, 203, 0.9);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 22px 54px rgba(15, 23, 42, 0.28);
  padding: 18px;
}

.verify-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.verify-card p {
  margin: 8px 0;
  color: #334155;
}

.verify-error {
  min-height: 18px;
  font-size: 12px;
  color: var(--bad) !important;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #0f172a;
  color: #f8fafc;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.35);
  opacity: 0;
  transform: translateY(10px);
  transition: all .2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-layout { grid-template-columns: minmax(0, 1fr); }
  .recent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .recent-scroll { grid-auto-columns: calc((100% - 14px) / 2); }
}

@media (max-width: 820px) {
  .anime-library-head {
    top: 76px;
    z-index: 45;
  }

  .anime-library-head::before {
    inset: -12px -12px -10px;
  }

  .anime-library-head .filter-card {
    max-height: calc(100vh - 112px);
    overflow: auto;
  }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid rgba(222, 216, 203, 0.78);
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
  }
  .brand {
    font-size: 18px;
    margin-bottom: 2px;
  }
  .brand-sub {
    display: none;
  }
  .nav-group {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .nav-group::after {
    content: '';
    position: sticky;
    right: -12px;
    flex: 0 0 24px;
    align-self: stretch;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(255, 253, 248, 0), rgba(255, 253, 248, 0.96));
  }
  .nav-group::-webkit-scrollbar {
    display: none;
  }
  .nav-title {
    display: none;
  }
  .nav-link {
    margin-bottom: 0;
    flex: 0 0 auto;
    padding: 8px 12px;
    font-size: 13px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 999px;
  }
  .nav-link.active {
    border-color: #86efac;
  }
  .main {
    padding: 12px;
  }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .watch-layout {
    grid-template-columns: 1fr;
  }
  .watch-episode-panel {
    position: static;
    height: auto;
    max-height: none;
  }
  .watch-episode-list {
    max-height: none;
  }
  .watch-episode-group-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .watch-control-row {
    flex-wrap: wrap;
  }
  .source-status {
    align-items: flex-start;
    flex-direction: column;
  }
  .recent-grid { grid-template-columns: 1fr; }
  .recent-scroll {
    grid-auto-columns: 100%;
    width: 100%;
  }
  .hero-sub { grid-template-columns: 1fr; }
  .hero-main h2 { font-size: 28px; }
  .topbar {
    top: 76px;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 12px;
    max-width: 100%;
  }

  .sticky-page-head {
    top: 76px;
  }
  .sticky-page-head .topbar {
    top: auto;
  }
  .topbar-row {
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar-main {
    gap: 6px;
    width: 100%;
    max-width: 100%;
  }
  .topbar .page-title {
    order: 1;
    width: auto;
    min-width: 0;
    margin-right: 0;
    font-size: 21px;
  }
  .topbar-search {
    width: 100%;
    min-width: 0;
    order: 3;
  }
  .topbar .badge {
    order: 3;
    width: 100%;
    white-space: nowrap;
    overflow: auto;
    text-overflow: ellipsis;
  }
  .top-right-actions {
    display: none;
  }
  .top-right-actions::-webkit-scrollbar {
    display: none;
  }
  .top-right-actions .btn {
    flex: 0 0 auto;
    text-align: center;
    padding: 8px 10px;
    font-size: 12px;
    border-radius: 8px;
    white-space: nowrap;
  }
  .mobile-more-menu {
    display: block;
  }
  .mobile-more-menu > summary.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
  }
  .topbar > .btn:not(.top-right-actions .btn),
  .topbar > .badge {
    order: 4;
    width: 100%;
  }
  .timeline-row {
    align-items: flex-start;
    flex-direction: column;
  }
  .card {
    padding: 12px;
    border-radius: 12px;
  }
  .card h3 {
    font-size: 16px;
  }
  .card p {
    font-size: 13px;
  }
  .btn {
    padding: 8px 12px;
    font-size: 12px;
  }
  .row > .btn,
  .row > .select {
    flex: 1 1 calc(50% - 6px);
    min-width: 112px;
  }
  .input, .select, textarea {
    font-size: 16px;
  }
  .split-actions .btn {
    min-width: 0;
  }
  th, td {
    padding: 8px 10px;
    font-size: 12px;
  }
  .player-box {
    min-height: 0;
    height: auto;
    font-size: 15px;
  }
  .watch-card {
    position: sticky;
    top: 86px;
    z-index: 20;
  }
  .filter-row .input,
  .filter-row .select {
    flex: 1 1 100%;
    max-width: none;
  }
  .filter-summary {
    margin-top: 8px;
  }
  .admin-table {
    display: none;
  }

.admin-main {
  scroll-behavior: smooth;
}

.admin-workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.admin-menu {
  position: sticky;
  top: 92px;
  z-index: 18;
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid rgba(222, 216, 203, 0.82);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.admin-menu-title {
  padding: 0 6px 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.admin-menu-link {
  display: block;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  color: #334155;
  font-size: 14px;
}

.admin-menu-link:hover,
.admin-menu-link.active {
  border-color: #99f6e4;
  background: #ecfdf5;
  color: #0f766e;
  font-weight: 800;
}

.admin-content {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.admin-section {
  scroll-margin-top: 96px;
}

#admin-login-security {
  display: grid;
  gap: 14px;
}

.admin-mobile-list {
    display: grid;
  }
  .home-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px !important;
    max-width: 100%;
  }
  .home-metrics .metric-tile {
    padding: 10px;
    border-radius: 12px;
  }
  .home-metrics .metric-tile .v {
    font-size: 20px;
  }
  .home-metrics .metric-tile .k {
    font-size: 11px;
  }
  .home-layout {
    gap: 10px;
    max-width: 100%;
  }
  .home-continue .timeline-row {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .home-continue .timeline-row > div {
    min-width: 0;
    flex: 1;
  }
  .home-continue .timeline-item .m {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .home-continue .timeline-item .btn {
    flex: 0 0 auto;
  }
  .home-note {
    display: none;
  }
  .history-table {
    display: none;
  }
  .history-mobile-list {
    display: grid;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 10px;
    border-radius: 14px;
  }
  .recent-scroll {
    grid-auto-columns: 86%;
  }
  .recent-card {
    padding: 9px;
  }
  .recent-card h4 {
    font-size: 15px;
  }
  .main {
    padding: 10px;
  }
  .topbar .page-title {
    font-size: 19px;
  }
  .top-right-actions {
    display: none;
  }
  .top-right-actions .btn {
    padding: 7px 10px;
    font-size: 12px;
  }
  .row > .btn,
  .row > .select {
    flex: 1 1 100%;
  }
  .split-actions .btn {
    flex: 1 1 calc(50% - 6px);
  }
  .home-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .home-metrics .metric-tile:last-child {
    grid-column: 1 / -1;
  }
  .home-metrics .metric-tile .v {
    font-size: 18px;
  }
  .home-continue .timeline-item .m {
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
  }

  .watchlist-card {
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 10px;
  }
  .watchlist-progress {
    font-size: 12px;
  }
  .history-mobile-item {
    padding: 10px;
  }
  .history-mobile-title {
    font-size: 14px;
  }
  .badge {
    font-size: 11px;
  }
  .episode-grid {
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  }
  .episode-shortcuts .btn {
    flex: 1 1 calc(33.333% - 7px);
    min-width: 0;
  }
  .stat {
    font-size: 26px;
  }
  .toast {
    right: 12px;
    left: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    text-align: center;
  }
}

.btn.disabled, .btn[aria-disabled="true"] { opacity: 0.48; pointer-events: none; }


.watch-control-row.row > .btn,
.watch-control-row.row > .select {
  flex: 0 0 auto;
  min-width: auto;
}

@media (max-width: 520px) {
  .watch-control-row.row > .btn {
    flex: 1 1 calc(50% - 6px);
    min-width: 128px;
  }
  .watch-episode-group-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .admin-workspace {
    grid-template-columns: 1fr;
  }
  .admin-menu {
    position: sticky;
    top: 76px;
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    border-radius: 14px;
  }
  .admin-menu-title {
    display: none;
  }
  .admin-menu-link {
    flex: 0 0 auto;
    font-size: 13px;
  }
  .admin-section {
    scroll-margin-top: 136px;
  }
}

@media (max-width: 520px) {
  .anime-library-head {
    top: 68px;
  }

  .anime-library-head .filter-card {
    max-height: calc(100vh - 98px);
  }
}


/* Fixed chrome: keep sidebar and anime-library search outside content scrolling. */
@media (min-width: 821px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 70;
    width: 260px;
    height: 100vh;
    max-height: 100vh;
  }

  .main {
    grid-column: 2;
  }

  .anime-library-main {
    padding-top: 228px;
  }

  .anime-library-head {
    position: fixed;
    top: 20px;
    left: 280px;
    right: 20px;
    z-index: 60;
    margin-bottom: 0;
  }

  .anime-library-head::before {
    inset: -20px -20px -14px;
  }
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    z-index: 70;
    width: 100%;
    height: auto;
    max-height: none;
  }

  .main {
    padding-top: 70px;
  }

  .anime-library-main {
    padding-top: 332px;
  }

  .anime-library-head {
    position: fixed;
    top: 58px;
    left: 12px;
    right: 12px;
    z-index: 55;
    margin-bottom: 0;
  }

  .anime-library-head .filter-card {
    max-height: 190px;
    overflow: auto;
  }
}

@media (max-width: 520px) {
  .main {
    padding-top: 64px;
  }

  .anime-library-main {
    padding-top: 374px;
  }

  .anime-library-head {
    top: 54px;
    left: 10px;
    right: 10px;
  }

  .anime-library-head .filter-card {
    max-height: 220px;
  }
}

/* Watchlist compact content spacing: prevent progress text from being pushed away. */
.watchlist-body {
  align-content: start;
  gap: 4px;
}

.watchlist-body h3 {
  min-height: 0;
  margin: 0;
}

.watchlist-progress {
  gap: 3px;
  margin: 0 0 6px;
  line-height: 1.25;
}

.watchlist-actions {
  align-self: start;
}

@media (max-width: 520px) {
  .watchlist-body {
    gap: 4px;
  }

  .watchlist-body h3 {
    min-height: 0;
  }

  .watchlist-progress {
    gap: 2px;
    margin-bottom: 6px;
    line-height: 1.22;
  }
}

/* Mobile WebUI refinement layer: keep chrome compact, avoid overlap, and improve touch layout. */
@media (max-width: 820px) {
  :root {
    --mobile-nav-height: 58px;
  }

  body {
    background:
      linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(244, 241, 234, 0.98)),
      var(--bg);
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    min-height: var(--mobile-nav-height);
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  }

  .brand {
    display: none;
  }

  .nav-group {
    gap: 8px;
    padding: 0 2px 2px;
  }

  .nav-link {
    min-height: 38px;
    padding: 8px 13px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
  }

  .main {
    padding: calc(var(--mobile-nav-height) + 12px) 12px 18px;
  }

  .topbar,
  .sticky-page-head {
    top: calc(var(--mobile-nav-height) + 8px);
  }

  .topbar {
    position: sticky;
    padding: 10px;
    border-radius: 15px;
    gap: 8px;
  }

  .topbar-row {
    gap: 8px;
  }

  .topbar .page-title,
  .page-title {
    font-size: 20px;
    line-height: 1.15;
  }

  .topbar-search,
  .filter-row .input,
  .filter-row .select {
    min-width: 0;
    max-width: none !important;
  }

  .mobile-more-menu-panel {
    position: fixed;
    top: calc(var(--mobile-nav-height) + 58px);
    right: 12px;
    left: auto;
    width: min(220px, calc(100vw - 24px));
  }

  .btn,
  .input,
  .select,
  textarea {
    min-height: 42px;
  }

  .row {
    gap: 8px;
  }

  .row > .btn,
  .row > .select,
  .row > .input {
    min-width: 0;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
  }

  .table-wrap table {
    min-width: 720px;
  }

  .compact-scroll {
    max-height: 62vh;
    overflow: auto;
  }

  .source-status {
    padding: 10px;
  }

  .anime-library-main {
    padding-top: calc(var(--mobile-nav-height) + 12px);
  }

  .anime-library-head {
    position: sticky;
    top: calc(var(--mobile-nav-height) + 8px);
    left: auto;
    right: auto;
    z-index: 55;
    margin-bottom: 12px;
  }

  .anime-library-head::before {
    inset: -10px -12px -8px;
  }

  .anime-library-head .filter-card {
    max-height: none;
    overflow: visible;
  }

  .filter-card {
    padding: 10px;
  }

  .filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .filter-row .input:first-child {
    grid-column: 1 / -1;
  }

  .filter-row .btn {
    width: 100%;
  }

  #all-anime-grid,
  #anime-grid {
    gap: 10px;
  }

  .recent-scroll {
    scroll-snap-type: x proximity;
  }

  .recent-card,
  #anime-grid .card,
  #all-anime-grid .recent-card {
    scroll-snap-align: start;
  }

  .watch-layout {
    gap: 12px;
  }

  .watch-player-card {
    padding: 10px;
  }

  .player-box {
    min-height: 210px;
    border-radius: 12px;
  }

  .watch-video {
    min-height: 210px;
  }

  .watch-episode-panel {
    max-height: none;
  }

  .watch-episode-list {
    max-height: 52vh;
  }

  .watch-control-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .watch-control-row.row > .btn {
    min-width: 0;
    width: 100%;
  }

  .admin-main {
    padding-top: calc(var(--mobile-nav-height) + 12px);
  }

  .admin-workspace {
    gap: 10px;
  }

  .admin-menu {
    top: calc(var(--mobile-nav-height) + 8px);
    margin: 0 -2px;
    padding: 8px;
    gap: 6px;
    scrollbar-width: none;
  }

  .admin-menu::-webkit-scrollbar {
    display: none;
  }

  .admin-menu-link {
    padding: 8px 10px;
  }

  .admin-content {
    gap: 10px;
  }

  .admin-section {
    scroll-margin-top: 128px;
  }

  .verify-card {
    width: min(520px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    overflow: auto;
  }
}

@media (max-width: 520px) {
  :root {
    --mobile-nav-height: 54px;
  }

  .sidebar {
    padding-left: 8px;
    padding-right: 8px;
  }

  .nav-link {
    min-height: 36px;
    padding: 7px 11px;
    font-size: 12px;
  }

  .main,
  .admin-main,
  .anime-library-main {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    padding: 9px;
  }

  .topbar .page-title,
  .page-title {
    font-size: 18px;
  }

  .mobile-more-menu-panel {
    top: calc(var(--mobile-nav-height) + 54px);
    right: 10px;
  }

  .filter-row {
    grid-template-columns: 1fr;
  }

  #all-anime-grid,
  #anime-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  #anime-grid .card,
  #all-anime-grid .recent-card,
  .recent-card {
    padding: 9px;
    border-radius: 12px;
  }

  #anime-grid .card h3,
  #all-anime-grid .recent-card h4 {
    font-size: 13px;
    line-height: 1.25;
    min-height: 2.5em;
  }

  #anime-grid .card .meta,
  #all-anime-grid .recent-card .meta {
    font-size: 11px;
    min-height: 2.6em;
  }

  .split-actions {
    gap: 6px;
  }

  .split-actions .btn {
    min-height: 36px;
    padding: 7px 8px;
  }

  .home-metrics {
    gap: 8px;
  }

  .home-layout {
    gap: 10px;
  }

  .recent-scroll {
    grid-auto-columns: 78%;
  }

  .anime-detail-layout {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .anime-detail-cover .cover {
    max-width: 82px;
  }

  .episode-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .episode-item {
    padding: 7px 5px;
    font-size: 12px;
  }

  .player-box,
  .watch-video {
    min-height: 188px;
  }

  .player-status {
    left: 10px;
    right: 10px;
    bottom: 10px;
    font-size: 12px;
    padding: 8px 10px;
  }

  .watch-episode-group-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .watch-episode-link {
    min-height: 36px;
    padding: 5px 4px;
  }

  .watch-episode-no {
    font-size: 12px;
  }

  .watch-episode-meta {
    font-size: 10px;
  }

  .watchlist-card {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .watchlist-card .cover {
    border-radius: 9px;
  }

  .admin-menu {
    top: calc(var(--mobile-nav-height) + 8px);
  }

  .admin-overview,
  #admin-overview {
    gap: 8px;
  }
}

@media (max-width: 360px) {
  #all-anime-grid,
  #anime-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .watch-control-row {
    grid-template-columns: 1fr;
  }

  .recent-scroll {
    grid-auto-columns: 88%;
  }
}
