:root {
  --red: #E2192A;
  --red-dark: #9E0E1C;
  --gold: #F0A500;
  --bg: #0A0A0B;
  --surface: #111114;
  --surface2: #18181D;
  --surface3: #22222A;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.13);
  --text: #F0EEE8;
  --muted: #888;
  --essential: #E2192A;
  --recommended: #1D9E75;
  --optional: #5F5E70;
}

/* ── Light mode ── */
body.light {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface2: #EDEDF0;
  --surface3: #E0E0E5;
  --border: rgba(0,0,0,0.08);
  --border2: rgba(0,0,0,0.14);
  --text: #1A1A1A;
  --muted: #666;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

/* ── Loading overlay ── */
.loading-screen {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 40vh; gap: 16px;
  color: var(--muted); font-size: 14px;
}
.loading-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--surface3);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.load-error {
  text-align: center; color: var(--essential);
  padding: 40px 20px; font-size: 14px;
}

/* ── Header ── */
header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,11,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  transition: background 0.25s;
}
body.light header {
  background: rgba(245,245,247,0.92);
}
.logo {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 26px;
  letter-spacing: 0.04em;
  color: var(--red);
  flex-shrink: 0;
}
.logo span { color: var(--text); }
.header-stats {
  display: flex; gap: 12px; flex-wrap: wrap; flex: 1;
  align-items: center;
}
.stat-pill {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.stat-pill strong { color: var(--text); }
.progress-bar-wrap {
  min-width: 120px; max-width: 220px;
  padding: 10px 0;
  align-self: center;
  position: relative;
  cursor: default;
}
.progress-bar-track {
  height: 6px; background: var(--surface3); border-radius: 3px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--red-dark), var(--red));
  border-radius: 3px; transition: width 0.4s ease;
  min-width: 4px;
}

/* ── Controls row ── */
.controls-row {
  display: flex; gap: 6px; flex-wrap: wrap; width: 100%; align-items: center;
}
.filter-btn {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--muted); padding: 4px 12px; border-radius: 20px;
  font-size: 12px; cursor: pointer; font-family: inherit;
  transition: all 0.15s;
}
.filter-btn:hover { border-color: var(--red); color: var(--text); }
.filter-btn.active { background: var(--red); border-color: var(--red); color: #fff; }
.filter-sep {
  width: 1px; height: 18px; background: var(--border2);
  flex-shrink: 0; margin: 0 2px;
}
.cat-btn {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--muted); padding: 4px 10px; border-radius: 20px;
  font-size: 11px; cursor: pointer; font-family: inherit;
  transition: all 0.15s; display: flex; align-items: center; gap: 4px;
}
.cat-btn:hover { border-color: var(--red); color: var(--text); }
.cat-btn.active { border-color: var(--text); color: var(--text); }
.cat-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.cat-dot-movie  { background: #7BB8EF; }
.cat-dot-series { background: #F0A040; }
.cat-dot-short  { background: #999; }

.search-wrap {
  position: relative; margin-left: auto;
}
.search-input {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 4px 12px 4px 28px;
  border-radius: 20px;
  font-size: 12px;
  font-family: inherit;
  width: 170px;
  outline: none;
  transition: border-color 0.15s, width 0.2s;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: var(--red); width: 220px; }
.search-icon {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; color: var(--muted); pointer-events: none;
}

.header-actions {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.theme-toggle {
  background: none; border: 1px solid var(--border2);
  color: var(--muted); width: 28px; height: 28px;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; font-size: 14px; padding: 0;
}
.theme-toggle:hover { border-color: var(--red); color: var(--text); }

.sync-indicator {
  font-size: 11px; display: flex; align-items: center; gap: 5px;
  color: var(--muted); flex-shrink: 0;
}
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); transition: background 0.3s;
}
.sync-dot.syncing { background: var(--gold); animation: pulse 0.8s infinite; }
.sync-dot.ok      { background: var(--recommended); }
.sync-dot.error   { background: var(--essential); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── Main ── */
main { max-width: 860px; margin: 0 auto; padding: 28px 20px 60px; }

/* ── Era sections ── */
.era { margin-bottom: 32px; }
.era.empty { display: none; }
.era-label {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 13px; letter-spacing: 0.15em;
  color: var(--muted); text-transform: uppercase;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  user-select: none;
  transition: color 0.15s;
}
.era-label:hover { color: var(--text); }
.era-chevron {
  width: 10px; height: 10px;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.era-label.collapsed .era-chevron { transform: rotate(-90deg); }
.era-count {
  margin-left: auto;
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
  font-weight: 400;
}
.era-count .done { color: var(--text); }
.era-entries { overflow: hidden; }
.era-entries.collapsed { display: none; }

/* ── Entry cards ── */
.entry {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  margin-bottom: 3px;
}
.entry:hover { background: var(--surface2); border-color: var(--border); }
.entry.watched {
  background: var(--surface);
  border-color: var(--border);
  opacity: 0.65;
}
.entry.watched .entry-title { text-decoration: line-through; color: var(--muted); }
.entry.next-up {
  border-color: var(--gold) !important;
  background: rgba(240,165,0,0.05) !important;
  opacity: 1 !important;
}

/* ── Custom checkbox ── */
.cb-wrap { flex-shrink: 0; width: 20px; height: 20px; position: relative; }
.cb-wrap input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.cb-box {
  width: 20px; height: 20px; border-radius: 5px;
  border: 1.5px solid var(--border2);
  background: var(--surface3);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s; pointer-events: none;
}
.cb-wrap input:checked ~ .cb-box {
  background: var(--red); border-color: var(--red);
}
.cb-box svg { display: none; }
.cb-wrap input:checked ~ .cb-box svg { display: block; }

.entry-body { flex: 1; min-width: 0; }
.entry-title { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-sub { font-size: 12px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.entry-tags { display: flex; gap: 5px; flex-shrink: 0; align-items: center; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 400;
}
.tag-movie  { background: rgba(24,95,165,0.18); color: #7BB8EF; border: 1px solid rgba(24,95,165,0.3); }
.tag-series { background: rgba(180,100,0,0.18); color: #F0A040; border: 1px solid rgba(180,100,0,0.3); }
.tag-short  { background: rgba(80,80,80,0.18); color: #999; border: 1px solid rgba(80,80,80,0.3); }
body.light .tag-movie  { background: rgba(24,95,165,0.10); border-color: rgba(24,95,165,0.25); }
body.light .tag-series { background: rgba(180,100,0,0.10); border-color: rgba(180,100,0,0.25); }
body.light .tag-short  { background: rgba(80,80,80,0.10); border-color: rgba(80,80,80,0.25); }
.prio-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.prio-essential    { background: var(--essential); }
.prio-recommended  { background: var(--recommended); }
.prio-optional     { background: var(--optional); }

.next-badge {
  font-size: 10px; font-weight: 500; letter-spacing: 0.08em;
  background: var(--gold); color: #000; padding: 2px 7px; border-radius: 20px;
  text-transform: uppercase; flex-shrink: 0;
}

/* ── Legend ── */
.legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 24px;
  font-size: 12px; color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }

/* ── Episode panel ── */
.entry-wrap { margin-bottom: 3px; }
.entry-wrap .entry { margin-bottom: 0; }
.chevron {
  flex-shrink: 0; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s;
  color: var(--muted);
}
.chevron.open { transform: rotate(90deg); }
.ep-panel {
  max-height: 0; overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  margin: 0 14px;
  padding: 0 12px;
}
.ep-panel.open {
  max-height: 600px;
  padding: 10px 12px;
}
.ep-season-label {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.08em; margin-bottom: 6px; margin-top: 6px;
}
.ep-season-label:first-child { margin-top: 0; }
.ep-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.ep-item {
  width: 34px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 5px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  font-size: 12px; color: var(--muted);
  cursor: pointer; position: relative;
  transition: all 0.12s;
  user-select: none;
}
.ep-item:hover { border-color: var(--red); color: var(--text); }
.ep-item.watched {
  background: var(--red); border-color: var(--red);
  color: #fff; font-weight: 500;
}
.ep-item input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.ep-progress {
  font-size: 11px; color: var(--muted); margin-left: auto;
  flex-shrink: 0; white-space: nowrap;
}

/* ── Progress tooltip ── */
.progress-tooltip {
  position: absolute;
  top: calc(100% - 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 150;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
body.light .progress-tooltip {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.progress-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: var(--border2);
}
.progress-bar-wrap:hover .progress-tooltip { opacity: 1; }
.progress-tooltip-row {
  display: flex; gap: 8px; align-items: center;
}
.progress-tooltip-row + .progress-tooltip-row { margin-top: 4px; }
.progress-tooltip-label { color: var(--muted); }
.progress-tooltip-value { color: var(--text); font-weight: 500; }

/* ── Hidden by filter ── */
.entry.hidden { display: none; }
.entry-wrap.hidden .entry, .entry-wrap.hidden .ep-panel { display: none; }
.entry-wrap.hidden { display: none; }
