:root {
  color-scheme: dark;
  --bg: #0b0c11;
  --surface: #141722;
  --surface-2: #1c2130;
  --border: #272e40;
  --crimson: #e11d48;
  --crimson-bright: #f43f5e;
  --crimson-dark: #9f1239;
  --blue: #3b82f6;
  --gold: #f59e0b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --subtle: #64748b;
  --header-crop: 68px;
}

* {
  box-sizing:border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: #06070a;
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  max-width: 1180px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  padding-bottom: 92px;
}

@media (min-width: 768px) {
  .app-shell { padding-bottom: 40px; }
}

.hidden { display: none !important; }

/* Header & Search */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 12, 17, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(39, 46, 64, 0.7);
  padding: 12px 18px;
}

.header-inner { display: flex; flex-direction: column; gap: 10px; }

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  cursor: pointer;
}

.brand span { color: var(--crimson); }

.desktop-nav { display: none; gap: 6px; }
@media (min-width: 768px) { .desktop-nav { display: flex; } }

.dnav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.dnav-btn:hover { color: var(--text); background: var(--surface); }
.dnav-btn.active {
  background: rgba(225, 29, 72, 0.15);
  border-color: rgba(225, 29, 72, 0.5);
  color: #fff;
}

.search-wrap { position: relative; width: 100%; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 5px 6px 5px 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.search-box:focus-within {
  border-color: var(--crimson);
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.16);
}

.search-icon { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }

.search-box input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.95rem;
  padding: 6px 2px;
}

.search-box input::placeholder { color: var(--subtle); }

.kbd-hint {
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 6px;
}

@media (max-width: 640px) { .kbd-hint { display: none; } }

.clear-btn {
  background: var(--surface-2);
  color: var(--muted);
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

.search-submit {
  background: var(--crimson);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.search-submit:hover { background: var(--crimson-bright); }
.search-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* Local Zero-API Dropdown */
.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  display: none;
  z-index: 70;
  max-height: 430px;
  overflow-y: auto;
}

.suggestions.open { display: block; }

.sugg-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(39, 46, 64, 0.5);
}

.sugg-item:last-child { border-bottom: none; }
.sugg-item:hover, .sugg-item.active { background: var(--surface-2); }

.sugg-thumb {
  width: 34px;
  height: 50px;
  object-fit: cover;
  border-radius: 6px;
  background: #0d1117;
  flex-shrink: 0;
}

.sugg-meta { flex: 1; min-width: 0; }
.sugg-title {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sugg-sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }

.sugg-footer {
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #fda4af;
  background: rgba(225, 29, 72, 0.1);
  cursor: pointer;
  text-align: center;
}

.sugg-footer:hover { background: rgba(225, 29, 72, 0.2); }

/* Views & Sections */
.view { padding: 16px 18px 24px; }
.section { margin-bottom: 32px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.wrap-header { flex-wrap: wrap; }
.section-header h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.status-text { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.toolbar-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pills { display: flex; gap: 6px; }
.pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.pill.active, .pill:hover { background: var(--crimson); border-color: var(--crimson); color: #fff; }

.select-input {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.84rem;
}

.see-all-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.see-all-btn:hover { border-color: var(--crimson); color: var(--text); }

/* Recent Searches */
.recent-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  font-size: 0.8rem;
  color: var(--muted);
}

.recent-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
}
.recent-chip:hover { border-color: var(--crimson); }

/* Carousels & Grids */
.poster-carousel {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.poster-carousel::-webkit-scrollbar { display: none; }
.carousel-card { flex: 0 0 146px; scroll-snap-align: start; cursor: pointer; }
@media (min-width: 640px) { .carousel-card { flex: 0 0 166px; } }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px 14px;
}
@media (min-width: 640px) {
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(162px, 1fr)); }
}

.grid-card { cursor: pointer; }

.poster-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  margin-bottom: 8px;
  border: 1px solid rgba(39, 46, 64, 0.7);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.poster-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.22s ease;
}

.carousel-card:hover .poster-wrap img,
.grid-card:hover .poster-wrap img { transform: scale(1.04); }

.type-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(11, 12, 17, 0.85);
  color: #fda4af;
  border: 1px solid rgba(225, 29, 72, 0.45);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 6px;
}

.score-tag {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(11, 12, 17, 0.85);
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.card-sub {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Popular Compact List */
.popular-list { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .popular-list { grid-template-columns: 1fr 1fr; } }

.popular-item {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 10px;
  border-radius: 14px;
  background: rgba(20, 23, 34, 0.65);
  border: 1px solid rgba(39, 46, 64, 0.7);
  cursor: pointer;
}
.popular-item:hover { border-color: rgba(225, 29, 72, 0.55); background: var(--surface); }

.popular-thumb {
  width: 72px;
  height: 102px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}

.popular-info { min-width: 0; flex: 1; }
.popular-info h3 {
  font-size: 0.96rem;
  font-weight: 600;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.genre-pills { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.genre-pill {
  background: var(--surface-2);
  color: #cbd5e1;
  font-size: 0.69rem;
  padding: 2px 8px;
  border-radius: 999px;
}

.load-more-wrap { text-align: center; margin-top: 20px; }
.load-more-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 22px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}
.load-more-btn:hover { border-color: var(--crimson); }

/* Detail & Unified Workspace */
.detail-view { min-height: 100vh; background: var(--bg); }
.detail-hero { position: relative; width: 100%; height: 360px; overflow: hidden; background: #000; }
@media (min-width: 768px) { .detail-hero { height: 430px; } }

.detail-backdrop { width: 100%; height: 100%; object-fit: cover; object-position: center 22%; display: block; }
.detail-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11,12,17,0.45) 0%, rgba(11,12,17,0.15) 35%, rgba(11,12,17,0.88) 78%, #0b0c11 100%);
}

.detail-top-actions {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  z-index: 5;
}

.circle-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(11, 12, 17, 0.65);
  backdrop-filter: blur(8px);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.circle-btn svg { width: 20px; height: 20px; }
.circle-btn.saved { background: var(--crimson); border-color: var(--crimson); }
.circle-btn.saved svg { fill: #fff; }

.detail-hero-text {
  position: absolute;
  bottom: 16px;
  left: 20px;
  right: 20px;
  text-align: center;
  z-index: 4;
}

.hero-badge {
  display: inline-block;
  background: rgba(225, 29, 72, 0.22);
  border: 1px solid rgba(225, 29, 72, 0.55);
  color: #fda4af;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 9px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.detail-hero-text h1 {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: 6px;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8);
}

.detail-genres { font-size: 0.9rem; color: #d1d5db; }
.detail-genres .dot { color: var(--crimson); margin: 0 6px; font-weight: 800; }

.detail-body { max-width: 920px; margin: 0 auto; padding: 12px 20px 40px; }

.stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.trailer-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 12px;
  background: rgba(225, 29, 72, 0.14);
  border: 1px solid rgba(225, 29, 72, 0.55);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.trailer-btn svg { width: 15px; height: 15px; }

.stat-item { display: flex; align-items: center; gap: 8px; }
.red-icon { width: 20px; height: 20px; color: var(--crimson); flex-shrink: 0; }
.stat-label { display: block; font-size: 0.72rem; color: var(--muted); }
.stat-value { font-size: 0.88rem; color: var(--text); font-weight: 700; }

.cta-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }

.cta-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
}
.cta-btn svg { width: 18px; height: 18px; }
.cta-btn:active { transform: scale(0.98); }
.cta-watch {
  background: linear-gradient(135deg, var(--crimson-bright), var(--crimson-dark));
  box-shadow: 0 8px 22px rgba(225, 29, 72, 0.32);
}
.cta-download {
  background: linear-gradient(135deg, var(--blue), #1d4ed8);
  box-shadow: 0 8px 22px rgba(59, 130, 246, 0.28);
}

.episode-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.ep-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--muted);
  flex: 1;
  min-width: 150px;
}
.ep-field select { flex: 1; min-width: 0; }
.anime-input { width: 90px; }

.workspace-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 20px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.mode-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 13px 12px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.mode-tab.active[id="tab-watch"] {
  color: #fff;
  border-bottom-color: var(--crimson);
  background: rgba(225, 29, 72, 0.1);
}
.mode-tab.active[id="tab-download"] {
  color: #fff;
  border-bottom-color: var(--blue);
  background: rgba(59, 130, 246, 0.1);
}

.workspace-pane { padding: 14px; }

.iframe-wrapper {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}
.iframe-wrapper iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.server-heading { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 8px; }
.server-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.server-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.server-btn.active {
  background: linear-gradient(135deg, var(--crimson-bright), var(--crimson-dark));
  border-color: transparent;
  color: #fff;
}

.player-notice { margin-top: 10px; font-size: 0.78rem; color: #fbbf24; }

.dl-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 12px;
  font-size: 0.84rem;
}

.toggle-check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text); }
.direct-link { margin-left: auto; color: #60a5fa; text-decoration: none; font-weight: 600; }
.direct-link:hover { text-decoration: underline; }

.download-shell {
  position: relative;
  width: 100%;
  height: 56vh;
  min-height: 400px;
  max-height: 620px;
  background: #090a0d;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.download-shell iframe {
  position: relative;
  top: calc(var(--header-crop) * -1);
  width: 100%;
  height: calc(100% + var(--header-crop));
  border: 0;
  display: block;
}

.dl-note { margin-top: 10px; font-size: 0.78rem; color: var(--muted); line-height: 1.45; }
.detail-overview { color: #cbd5e1; font-size: 0.94rem; line-height: 1.65; }

/* Mobile Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 1180px;
  background: rgba(14, 15, 22, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  z-index: 45;
}
@media (min-width: 768px) { .bottom-nav { display: none; } }

.nav-btn { background: transparent; border: none; color: var(--muted); display: flex; justify-content: center; cursor: pointer; }
.nav-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 62px;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
}
.nav-pill svg { width: 20px; height: 20px; }
.nav-btn.active .nav-pill {
  background: linear-gradient(135deg, var(--crimson-bright), var(--crimson-dark));
  color: #fff;
}
