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

:root {
  --bg: #0f1219;
  --panel: #1a1f2b;
  --panel-2: #232a3a;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --accent: #f5a623;
  --accent-2: #4f8cff;
  --green: #3ecf6e;
  --red: #ff5c6c;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}

a { color: var(--accent-2); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}

.brand { font-size: 20px; font-weight: 700; white-space: nowrap; }

.searchbox { flex: 1; max-width: 520px; }

.searchbox input {
  width: 100%;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid #333c50;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.searchbox input:focus { border-color: var(--accent); }

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.2); }
.btn.primary { background: var(--accent); color: #1a1200; font-weight: 600; }
.btn.ghost { background: transparent; border: 1px solid #333c50; }
.btn.danger { background: var(--red); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; padding: 14px 20px 0; }

.tab {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Layout ---------- */
main { padding: 20px; max-width: 1280px; margin: 0 auto; }

.hidden { display: none !important; }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 720px;
  margin: 30px auto;
  line-height: 1.7;
  position: relative;
}

.panel .close-x {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}
.panel h2 { margin-bottom: 12px; }
.panel ol { padding-left: 22px; margin: 10px 0; }

.setup-row { display: flex; gap: 8px; margin-top: 14px; }
.setup-row input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #333c50;
  background: var(--panel-2);
  color: var(--text);
}

.msg { margin-top: 10px; color: var(--accent); min-height: 20px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; line-height: 1.8; font-size: 16px; }

/* ---------- Grid & Cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
}

.card {
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: transform .15s;
}
.card:hover { transform: translateY(-4px); }

.poster {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: linear-gradient(160deg, #2a3145, #171c28);
}

.poster.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  color: var(--muted);
}

.card-body { padding: 10px 12px 12px; }
.card-title { font-size: 14px; font-weight: 600; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,.75);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}
.badge.tv { color: var(--accent); }
.badge.movie { color: var(--accent-2); }
.badge.anime { color: #ff79c6; }

.badge-count {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: #1a1200;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.card .add-btn, .card .watch-btn, .card .wl-add-btn {
  position: absolute;
  right: 8px;
  bottom: 78px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  font-size: 20px;
  cursor: pointer;
  background: var(--accent);
  color: #1a1200;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.card .watch-btn.watched { background: var(--green); color: #fff; }
.card .wl-add-btn {
  bottom: 124px;
  font-size: 16px;
  background: var(--panel-2);
  border: 1px solid #3a445c;
}

.progress {
  height: 5px;
  background: #2c3446;
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
}
.progress > div { height: 100%; background: var(--green); border-radius: 999px; }

/* ---------- Upcoming ---------- */
.up-item {
  display: flex;
  gap: 14px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  align-items: center;
}
.up-item img { width: 52px; border-radius: 8px; }
.up-date { margin-left: auto; text-align: right; }
.up-date .day { font-size: 18px; font-weight: 700; color: var(--accent); }
.up-date .rel { font-size: 12px; color: var(--muted); }

/* ---------- Modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 50;
  overflow-y: auto;
}

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  max-width: 680px;
  width: 100%;
  padding: 22px;
  position: relative;
}

.modal .close-x {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}

.modal-head { display: flex; gap: 16px; margin-bottom: 16px; }
.modal-head img { width: 110px; border-radius: 8px; align-self: flex-start; }
.modal-head h2 { font-size: 20px; margin-bottom: 6px; }
.modal-head .meta { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.modal-head .overview { font-size: 13.5px; line-height: 1.55; color: #c3c9d6; max-height: 120px; overflow-y: auto; }

.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.season {
  background: var(--panel-2);
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
}

.season-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
}
.season-head:hover { background: #2a3245; }
.season-head .s-name { font-weight: 600; }
.season-head .s-count { color: var(--muted); font-size: 13px; margin-left: auto; }

.ep-list { padding: 4px 14px 12px; }

.ep-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px solid #2c3446;
  font-size: 14px;
}
.ep-row:last-child { border-bottom: none; }
.ep-row input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--green); cursor: pointer; }
.ep-row .ep-num { color: var(--muted); min-width: 42px; font-size: 12.5px; }
.ep-row .ep-date { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.ep-row.future { opacity: .5; }

/* ---------- Filtro di sezione ---------- */
#section-filter-wrap { padding: 12px 20px 0; max-width: 1280px; margin: 0 auto; }

#section-filter {
  width: 100%;
  max-width: 380px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid #333c50;
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
#section-filter:focus { border-color: var(--accent-2); }

.sec-count {
  background: var(--panel-2);
  border: 1px solid #333c50;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12.5px;
  color: var(--muted);
  vertical-align: middle;
}

/* ---------- Correlati (saghe, sequel) ---------- */
.rel-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 10px;
}

.rel-card { flex: 0 0 112px; }
.rel-card[data-open], .rel-card[data-rel-search] { cursor: pointer; }
.rel-card.current { outline: 2px solid var(--accent); }
.rel-card .add-btn, .rel-card .wl-add-btn { width: 30px; height: 30px; font-size: 15px; }
.rel-card .add-btn { bottom: 62px; }
.rel-card .wl-add-btn { bottom: 98px; }
.rel-card .card-sub { font-size: 11px; }

.badge.lib {
  color: var(--green);
  font-size: 10px;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Watchlist ---------- */
.wl-head {
  font-size: 17px;
  margin: 22px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid #2c3446;
}
.wl-head:first-child { margin-top: 0; }

.empty-inline { color: var(--muted); font-size: 14px; padding: 8px 4px 20px; }

/* ---------- Dettagli extra nelle modal ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.chip {
  background: var(--panel-2);
  border: 1px solid #333c50;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  color: #c3c9d6;
}
.chip.score { color: var(--accent); border-color: var(--accent); font-weight: 700; }

.extra-label { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }

.providers {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.providers img { width: 32px; height: 32px; border-radius: 8px; }

.cast-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.cast-card {
  flex: 0 0 84px;
  text-align: center;
}
.cast-card img, .cast-card .cast-ph {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 50%;
  background: var(--panel-2);
}
.cast-card .cast-ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
}
.cast-name { font-size: 12px; font-weight: 600; margin-top: 5px; line-height: 1.25; }
.cast-role { font-size: 11px; color: var(--muted); line-height: 1.2; margin-top: 2px; }

.cast-card.clickable { cursor: pointer; }
.cast-card.clickable:hover img, .cast-card.clickable:hover .cast-ph {
  outline: 2px solid var(--accent);
}

/* ---------- Filmografia attore ---------- */
.modal-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
.modal-grid .add-btn, .modal-grid .wl-add-btn { width: 32px; height: 32px; font-size: 16px; }
.modal-grid .add-btn, .modal-grid .watch-btn { bottom: 66px; }
.modal-grid .wl-add-btn { bottom: 104px; }

.badge-count.soon {
  background: var(--green);
  color: #fff;
  font-size: 10px;
}

/* ---------- Da vedere (watch next) ---------- */
.wn-item { cursor: pointer; }
.wn-item:hover { background: var(--panel-2); }

.wn-more {
  background: var(--panel-2);
  border: 1px solid #3a445c;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  margin-left: 4px;
}

.wn-check {
  margin-left: auto;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #3a445c;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  transition: all .15s;
}
.wn-check:hover {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* ---------- Griglia episodi anime ---------- */
.ep-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px;
}

.ep-chip {
  min-width: 40px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid #333c50;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .1s;
}
.ep-chip:hover { filter: brightness(1.3); }
.ep-chip.watched {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* ---------- Statistiche ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid #2c3446;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-title {
  font-size: 14px;
  font-weight: 700;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid #2c3446;
}

.stat-nums {
  display: flex;
  justify-content: center;
  gap: 22px;
}
.stat-nums span {
  font-size: 26px;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.stat-nums label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}

.stat-big {
  font-size: 30px;
  font-weight: 800;
  padding: 6px 0;
}

.stats-row {
  background: var(--panel);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 10px;
  font-size: 14.5px;
}
.stats-row.muted { color: var(--muted); font-size: 13.5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid #3a445c;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .brand { font-size: 17px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(125px, 1fr)); gap: 12px; }
  .modal-head img { width: 80px; }
}
