:root {
  --bg: #09090b;
  --surface: #111114;
  --surface-elev: #18181c;
  --surface-hover: #1f1f25;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f4f4f0;
  --text-dim: #a1a1aa;
  --text-muted: #71717a;
  --accent: #ff4d29;
  --accent-hover: #ff6242;
  --accent-soft: rgba(255, 77, 41, 0.14);
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mono-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 28px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  border-bottom: 1px solid var(--border);
}

.brand-wordmark {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-link {
  background: transparent;
  border: 0;
  padding: 6px 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  border-bottom: 2px solid transparent;
  transition: color 150ms var(--ease), border-color 150ms var(--ease);
}

.nav-link:hover {
  color: var(--text);
}

.nav-link.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.topbar-action {
  min-width: 100px;
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 40px;
  transition: background 150ms var(--ease), border-color 150ms var(--ease), opacity 150ms var(--ease);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
  min-height: 32px;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-elev);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface);
}

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 140ms var(--ease), background 140ms var(--ease);
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.inline-trigger {
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--accent);
  cursor: pointer;
  transition: color 140ms var(--ease);
}

.inline-trigger:hover {
  color: var(--accent-hover);
}

/* Main */
.main-viewport {
  flex: 1;
  padding-bottom: 84px;
}

/* Search Stage */
.search-stage {
  max-width: 760px;
  margin: 0 auto;
  padding: 72px 0 36px;
  text-align: center;
  transition: padding 200ms var(--ease);
}

.search-stage.compact {
  max-width: 100%;
  margin: 0;
  padding: 24px 0 22px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.search-stage.compact .stage-title {
  display: none;
}

.stage-title {
  margin: 0 0 24px;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 4.4vw, 3.4rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 6px 6px 16px;
  transition: border-color 150ms var(--ease);
}

.search-box:focus-within {
  border-color: var(--border-strong);
}

.search-icon {
  color: var(--text-muted);
  display: inline-flex;
  flex-shrink: 0;
}

.search-box input[type='text'] {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.98rem;
  padding: 10px 4px;
  outline: none;
}

.search-box input[type='text']::placeholder {
  color: var(--text-muted);
}

.search-subtext {
  margin: 12px 0 0;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.inline-alert {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 6px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  font-size: 0.88rem;
  text-align: left;
}

.recent-row {
  margin-top: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.search-stage.compact .recent-row {
  display: none;
}

.recent-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.recent-links {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.recent-link-btn {
  background: transparent;
  border: 0;
  padding: 2px 0;
  font-family: var(--font-body);
  font-size: 0.86rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: color 140ms var(--ease), border-color 140ms var(--ease);
}

.recent-link-btn:hover {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Search Results Grid */
.results-wrap {
  padding-top: 26px;
}

.results-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.results-bar h2 {
  margin: 0 0 2px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.meta-text {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.84rem;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  color: var(--text-dim);
}

.poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(186px, 1fr));
  gap: 24px 16px;
}

.poster-card {
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.poster-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 180ms var(--ease);
}

.poster-card:hover .poster-frame {
  border-color: var(--border-strong);
}

.poster-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 200ms var(--ease);
}

.poster-card:hover .poster-frame img {
  transform: scale(1.04);
}

.poster-fallback {
  width: 100%;
  height: 100%;
  padding: 16px;
  display: flex;
  align-items: flex-end;
  background: linear-gradient(155deg, #18181c 0%, #0d0d10 100%);
  color: var(--text-dim);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
}

.poster-title {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.poster-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.skeleton-frame {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.skeleton-line {
  height: 12px;
  border-radius: 3px;
  background: var(--surface);
  width: 80%;
}

.skeleton-line.short {
  width: 52%;
  height: 10px;
}

/* Series View & Cinematic Banner */
.view-series {
  padding-top: 20px;
}

.series-hero {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 24px;
}

.series-banner-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.28;
  filter: saturate(0.9);
  pointer-events: none;
}

.series-banner-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(9, 9, 11, 0.95) 0%, rgba(9, 9, 11, 0.78) 55%, rgba(9, 9, 11, 0.9) 100%),
    linear-gradient(to top, rgba(9, 9, 11, 0.98) 0%, transparent 65%);
  pointer-events: none;
}

.series-hero-content {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 136px minmax(0, 1fr);
  gap: 24px;
  padding: 26px;
  align-items: end;
}

.series-poster {
  width: 136px;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
}

.series-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.series-info {
  min-width: 0;
}

.series-info h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 2.8vw, 2.3rem);
  font-weight: 700;
  line-height: 1.12;
  text-wrap: balance;
}

.series-meta {
  font-size: 0.86rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.series-synopsis {
  margin: 12px 0 0;
  font-size: 0.9rem;
  color: var(--text-dim);
  max-width: 78ch;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.series-synopsis.expanded {
  -webkit-line-clamp: unset;
}

.series-links {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.ext-link {
  font-size: 0.84rem;
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

.ext-link:hover {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Extraction Results Panel */
.extraction-panel {
  margin-top: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.extraction-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.extraction-head h2 {
  margin: 0 0 2px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
}

.extraction-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.progress-track {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 180ms var(--ease);
}

.results-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}

.result-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.result-row:last-child {
  border-bottom: 0;
}

.result-ep {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  font-weight: 600;
}

.result-main {
  min-width: 0;
}

.result-file {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.state-ok {
  color: var(--ok);
  font-weight: 600;
}

.state-err {
  color: var(--err);
  font-weight: 600;
}

.result-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Episode Controls */
.episode-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.controls-left,
.controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 5px 12px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.active {
  background: var(--surface-elev);
  color: var(--text);
}

/* Episode Grid */
.episode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 16px;
}

.ep-cell {
  background: var(--bg);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  transition: background 120ms var(--ease);
}

.ep-cell:hover {
  background: var(--surface);
}

.ep-cell.selected {
  background: var(--accent-soft);
}

.ep-cell.unavailable {
  opacity: 0.48;
}

.ep-cell input[type='checkbox'] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.ep-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 34px;
}

.ep-cell.selected .ep-num {
  color: var(--text);
}

.ep-body {
  min-width: 0;
  flex: 1;
}

.ep-name {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  grid-column: 1 / -1;
  background: var(--bg);
  padding: 32px 20px;
  text-align: center;
  color: var(--text-dim);
}

/* Floating Selection Dock */
.selection-dock {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, calc(100% - 32px));
  z-index: 40;
}

.dock-inner {
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
}

.dock-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.dock-sep {
  color: var(--text-muted);
}

.dock-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Providers Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 60;
}

.modal-panel {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.modal-desc {
  margin: 0 0 18px;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.provider-list {
  border-top: 1px solid var(--border);
}

.provider-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.provider-row:last-child {
  border-bottom: 0;
  padding-bottom: 4px;
}

.provider-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.provider-name {
  font-weight: 600;
  font-size: 0.96rem;
}

.provider-domain {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.provider-meta {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.status-operational {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ok);
  white-space: nowrap;
}

/* Footer DMCA */
.footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.dmca-notice {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 82ch;
}

.dmca-notice strong {
  color: var(--text-dim);
  font-weight: 600;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}

.footer-link-btn {
  background: transparent;
  border: 0;
  padding: 0;
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  transition: color 140ms var(--ease);
}

.footer-link-btn:hover {
  color: var(--text);
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 70;
}

@media (max-width: 720px) {
  .app-shell {
    padding: 0 16px 32px;
  }
  .topbar {
    gap: 14px;
  }
  .topbar-action {
    min-width: auto;
  }
  .series-hero-content {
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 16px;
    padding: 18px;
  }
  .series-poster {
    width: 96px;
  }
  .result-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .ep-one-btn {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
