*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-hover: #252525;
  --bg-panel: #141414;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #e50914;
  --accent-hover: #f40612;
  --accent2: #ffc107;
  --border: #2a2a2a;
  --radius: 8px;
  --max-width: 1400px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

/* ========== HEADER ========== */

header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

header > .logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  margin-right: 16px;
}

.search-area {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  vertical-align: middle;
}

.search-area input[type="text"] {
  width: 320px;
  padding: 7px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.search-area input:focus { border-color: var(--accent); }

.search-area select {
  padding: 7px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

.search-area button {
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.search-area button:hover { background: var(--accent-hover); }

.view-toggle-btn {
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: color 0.15s;
}

.view-toggle-btn:hover { color: var(--text); }

.magnet-toggle {
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: color 0.15s;
}

.magnet-toggle:hover { color: var(--accent2); }
.magnet-toggle.active { color: var(--accent2); border-color: var(--accent2); }

.cache-status {
  float: right;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 8px;
}

/* Magnet bar (second row) */
.magnet-bar {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.magnet-input {
  flex: 1;
  max-width: 500px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.magnet-input:focus { border-color: var(--accent2); }

.magnet-btn {
  padding: 6px 14px;
  background: var(--accent2);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.magnet-btn:hover { opacity: 0.9; }

/* ========== MAIN ========== */

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 24px;
}

.hidden { display: none !important; }

.loading {
  text-align: center;
  padding: 80px 0;
  color: var(--text-muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

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

.errors {
  padding: 10px 14px;
  margin-bottom: 14px;
  background: rgba(229,9,20,0.12);
  border: 1px solid rgba(229,9,20,0.25);
  border-radius: var(--radius);
  color: #f66;
  font-size: 12px;
}

/* ========== HOME ========== */

.home-section { padding: 10px 0; }

.home-section h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.continue-watching { margin-bottom: 28px; }
.continue-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }

.continue-card {
  flex: 0 0 185px;
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: border-color 0.15s, transform 0.15s;
}

.continue-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.continue-poster { aspect-ratio: 16/9; background: var(--bg-hover); position: relative; overflow: hidden; }
.continue-poster img { width: 100%; height: 100%; object-fit: cover; }

.continue-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-muted); text-align: center; padding: 8px;
}

.continue-info { padding: 7px 9px 9px; }
.continue-title { font-size: 11px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 3px; }
.continue-meta { font-size: 10px; color: var(--text-muted); margin-bottom: 5px; }
.continue-bar { height: 2px; background: var(--border); border-radius: 1px; overflow: hidden; }
.continue-fill { height: 100%; background: var(--accent); border-radius: 1px; }

.recent-searches { margin-bottom: 28px; }
.recent-list { display: flex; flex-wrap: wrap; gap: 6px; }

.recent-chip {
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
}

.recent-chip:hover { background: var(--bg-hover); border-color: var(--accent); }
.recent-chip .chip-source { font-size: 9px; text-transform: uppercase; color: var(--text-muted); background: rgba(229,9,20,0.12); padding: 1px 4px; border-radius: 2px; }
.recent-chip .chip-remove { color: var(--text-muted); font-size: 13px; cursor: pointer; padding: 0 2px; }
.recent-chip .chip-remove:hover { color: var(--accent); }

/* ========== GALLERY (grid) ========== */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 14px;
}

.poster-card {
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
}

.poster-card:hover { transform: scale(1.03); box-shadow: 0 4px 18px rgba(0,0,0,0.45); }

.poster-card .poster-img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  background: var(--bg-card);
  display: block;
}

.poster-card .poster-placeholder {
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 10px;
  overflow: hidden;
}

.poster-card .poster-info { padding: 7px 9px 9px; background: var(--bg-card); }
.poster-card .poster-title { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poster-card .poster-meta { font-size: 10px; color: var(--text-muted); margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.poster-card .poster-badges { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 4px; }

.source-badge {
  font-size: 8px; text-transform: uppercase; padding: 1px 4px; border-radius: 2px;
  background: rgba(229,9,20,0.15); color: var(--accent); white-space: nowrap;
}

.source-badge.extra { background: rgba(255,255,255,0.08); color: var(--text-muted); }

.count-badge {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,0.82);
  color: var(--text);
  font-size: 9px; font-weight: 600; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 3px;
}

.watchlater-badge {
  position: absolute;
  top: 6px; left: 6px;
  background: rgba(0,0,0,0.82);
  color: var(--accent2);
  font-size: 12px; padding: 2px 5px; border-radius: 3px;
  cursor: pointer; z-index: 2;
  transition: background 0.15s;
}

.watchlater-badge:hover { background: rgba(0,0,0,0.95); }

/* ========== LIST VIEW ========== */

.list-view {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.list-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.list-card:hover { background: var(--bg-hover); border-color: var(--accent); }

.list-card .list-poster {
  width: 44px; height: 66px;
  border-radius: 3px;
  object-fit: cover;
  background: var(--bg-hover);
  flex-shrink: 0;
}

.list-card .list-poster-placeholder {
  width: 44px; height: 66px;
  border-radius: 3px;
  background: var(--bg-hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; color: var(--text-muted);
  flex-shrink: 0;
}

.list-card .list-info { flex: 1; min-width: 0; }
.list-card .list-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-card .list-meta { font-size: 10px; color: var(--text-muted); display: flex; gap: 6px; margin-top: 1px; }
.list-card .list-badges { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; }
.list-card .action-btn { flex-shrink: 0; }

/* ========== DETAIL ========== */

.detail { padding: 4px 0; }

.detail .backdrop {
  width: 100%; max-height: 360px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 18px;
  background: var(--bg-card);
}

.detail .detail-header { display: flex; gap: 20px; margin-bottom: 20px; }

.detail .detail-poster {
  width: 180px;
  border-radius: var(--radius);
  flex-shrink: 0;
}

.detail .detail-info { flex: 1; min-width: 0; }

.detail .detail-title { font-size: 1.6rem; font-weight: 700; margin-bottom: 4px; }

.detail .detail-meta {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 10px;
}

.detail .detail-actions {
  display: flex; gap: 6px; margin-bottom: 12px;
}

.detail .detail-overview {
  font-size: 13px; color: #bbb; line-height: 1.55; margin-bottom: 18px;
  max-width: 650px;
}

.detail .section-title {
  font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; color: var(--text);
}

.rating-badge { color: var(--accent2); font-weight: 600; }

/* ========== TORRENT LIST ========== */

.torrent-list { display: flex; flex-direction: column; gap: 4px; }

.torrent-row { border-radius: var(--radius); overflow: hidden; }

.torrent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
}

.torrent-item .torrent-source {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 5px; border-radius: 2px;
  background: rgba(229,9,20,0.12); color: var(--accent);
  white-space: nowrap; flex-shrink: 0;
}

.torrent-item .torrent-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}

.torrent-item .torrent-size { color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.torrent-item .torrent-seeds { font-weight: 600; white-space: nowrap; flex-shrink: 0; min-width: 55px; text-align: right; }

.seed-high { color: #4caf50; }
.seed-mid { color: #ff9800; }
.seed-low { color: #f44336; }

.torrent-item .play-btn, .action-btn {
  padding: 5px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.torrent-item .play-btn:hover, .action-btn:hover { background: var(--accent-hover); }

.action-btn.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
}

.action-btn.secondary:hover { border-color: var(--accent); color: var(--text); }

.torrent-files-btn { flex-shrink: 0; display: flex; align-items: center; gap: 3px; }

.files-arrow {
  font-size: 7px;
  display: inline-block;
  transition: transform 0.15s;
}

/* ========== FILE PANEL ========== */

.torrent-files-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 4px 8px 8px;
}

.torrent-files-loading,
.torrent-files-empty {
  color: var(--text-muted);
  font-size: 12px;
  padding: 10px 8px;
  text-align: center;
}

.torrent-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.torrent-file-item:last-child { border-bottom: none; }

.torrent-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.torrent-file-size { color: var(--text-muted); font-size: 11px; white-space: nowrap; flex-shrink: 0; }

.torrent-file-play {
  padding: 3px 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.torrent-file-play:hover { background: var(--accent-hover); }

/* ========== PLAYER ========== */

.player { padding: 4px 0; }

.player-wrapper {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  max-width: 1000px;
}

.player-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.torrent-status {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ========== SEASON / EPISODE ========== */

.season-bar {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}

.season-select {
  padding: 5px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

.episode-list { display: flex; flex-direction: column; gap: 4px; max-height: 480px; overflow-y: auto; }

.episode-item { display: flex; align-items: flex-start; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); }

.ep-label { font-size: 11px; font-weight: 700; color: var(--text-muted); min-width: 36px; padding-top: 5px; }

.ep-options { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.ep-torrent-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  flex-wrap: wrap;
}

.ep-torrent-row .torrent-source {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 1px 5px; border-radius: 2px;
  background: rgba(229,9,20,0.12); color: var(--accent);
  white-space: nowrap;
}

.ep-torrent-row .torrent-size { color: var(--text-muted); white-space: nowrap; }

.ep-torrent-row .play-btn {
  padding: 3px 10px;
  font-size: 10px;
}

.ep-torrent-row .action-btn.secondary {
  padding: 3px 8px;
  font-size: 10px;
}

.ep-torrent-row .torrent-files-panel {
  width: 100%;
  margin-top: 2px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px 6px;
}

.ep-torrent-row .torrent-files-panel {
  width: 100%;
  margin-top: 2px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px 6px;
}

/* ========== BACK ========== */

.back-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  margin-bottom: 12px;
  transition: color 0.15s, border-color 0.15s;
}

.back-btn:hover { color: var(--text); border-color: var(--accent); }

/* ========== TOAST ========== */

.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 8px 20px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  z-index: 200;
  transition: opacity 0.3s;
}

/* ========== PLACEHOLDER ========== */

.placeholder {
  text-align: center; padding: 90px 20px; color: var(--text-muted);
}

.placeholder h2 { font-size: 1.3rem; color: var(--text); margin-bottom: 6px; }
.placeholder p { font-size: 13px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state h2 { font-size: 1.1rem; color: var(--text); margin-bottom: 4px; }

/* ========== FOOTER ========== */

footer {
  text-align: center;
  padding: 16px 24px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 36px;
}

/* ========== RESPONSIVE ========== */

@media (max-width: 768px) {
  header { padding: 8px 12px; }
  header > .logo { font-size: 1.2rem; margin-right: 8px; }

  .search-area input[type="text"] { width: 140px; font-size: 12px; }
  .search-area select { font-size: 11px; }
  .search-area button { padding: 7px 10px; font-size: 11px; }

  .cache-status { display: none; }

  main { padding: 12px; }

  .gallery { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }

  .detail .detail-header { flex-direction: column; }
  .detail .detail-poster { width: 120px; }

  .torrent-item { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .torrent-item .torrent-name { width: 100%; order: 10; }
  .torrent-item .torrent-size { order: 11; }
  .torrent-item .torrent-seeds { order: 12; }
  .torrent-item .play-btn { order: 13; }
  .torrent-item .torrent-files-btn { order: 14; }

  .torrent-file-item { flex-wrap: wrap; gap: 4px; }
  .torrent-file-name { width: 100%; }
}

@media (max-width: 480px) {
  .search-area { flex-wrap: wrap; }
  .search-area input[type="text"] { width: 100%; }
  .list-card { flex-wrap: wrap; }
}
