/* Puntata — palette "salotto di sera": indaco profondo, luce di lampada albicocca */
:root {
  --bg: #1A1830;
  --surface: #24213F;
  --raised: #2F2B52;
  --line: #3B3663;
  --text: #EFEAF7;
  --muted: #A59FC0;
  --lamp: #FFB86B;
  --lamp-ink: #2A1A06;
  --lamp-soft: rgba(255, 184, 107, .16);
  --danger: #FF8A8A;
  --ok: #8FE3B0;

  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Helvetica Neue", Arial, system-ui, sans-serif;

  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;
  --tabbar-h: 64px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #F4F2FA;
    --surface: #FFFFFF;
    --raised: #ECE8F6;
    --line: #DAD4EA;
    --text: #1A1830;
    --muted: #625C80;
    --lamp: #D9750F;
    --lamp-ink: #FFFFFF;
    --lamp-soft: rgba(217, 117, 15, .13);
    --danger: #C23B3B;
    --ok: #1F8A4C;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 var(--font-body);
  padding-top: env(safe-area-inset-top, 0px);
  min-height: 100vh;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 18px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom, 0px));
}
.no-tabbar #app { padding-bottom: 40px; }

/* ---------- Tipografia ---------- */
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; margin: 0; }
h1 { font-size: 2.25rem; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0 18px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--raised); text-decoration: none;
  font-family: var(--font-display); font-weight: 700; text-transform: uppercase;
}
.section { margin: 26px 0 0; }
.section > h2 { margin-bottom: 12px; display: flex; align-items: baseline; gap: 8px; }
.section > h2 .count { font-family: var(--font-body); font-weight: 400; font-size: .95rem; color: var(--muted); }

/* ---------- Controlli ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; text-decoration: none;
  font-weight: 700;
}
.btn:hover { background: var(--raised); }
.btn.primary { background: var(--lamp); color: var(--lamp-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 700; font-size: .95rem; }
input[type=text], input[type=password], input[type=search], textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--surface);
}
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--muted); }

.segmented {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface); border-radius: 999px; border: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.segmented button {
  flex: 1 0 auto; min-height: 38px; padding: 0 14px; border: 0; border-radius: 999px;
  background: transparent; cursor: pointer; white-space: nowrap; color: var(--muted); font-weight: 700;
}
#status { display: grid; grid-template-columns: 1fr 1fr; border-radius: var(--r-lg); }
#status button { border-radius: var(--r-md); }
.segmented button[aria-pressed=true] { background: var(--raised); color: var(--text); }

.stars { display: inline-flex; gap: 2px; }
.stars button {
  width: 40px; height: 40px; border: 0; background: none; cursor: pointer; padding: 6px;
  color: var(--line);
}
.stars button.on { color: var(--lamp); }
.stars svg { width: 100%; height: 100%; fill: currentColor; }

/* ---------- Liste di titoli ---------- */
.rows { display: grid; gap: 2px; }
.row {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center;
  padding: 10px 0; text-decoration: none; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.poster {
  width: 100%; aspect-ratio: 2 / 3; border-radius: var(--r-sm);
  background: var(--raised) center / cover no-repeat; object-fit: cover;
}
.row .title { font-weight: 700; line-height: 1.25; }
.row .meta { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.bar { height: 4px; border-radius: 4px; background: var(--raised); margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--lamp); border-radius: 4px; }

.tick {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--lamp); background: transparent; color: var(--lamp);
  display: grid; place-items: center; cursor: pointer;
}
.tick svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 3; }
.tick:hover, .tick.done { background: var(--lamp); color: var(--lamp-ink); }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--raised); color: var(--muted); font-size: .8rem; font-weight: 700;
}

.poster-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 16px 12px;
}
.poster-grid a { text-decoration: none; }
.poster-grid .title { font-size: .9rem; font-weight: 700; margin-top: 6px; line-height: 1.25; }
.poster-grid .meta { font-size: .8rem; color: var(--muted); }

/* ---------- Dettaglio ---------- */
.hero {
  position: relative; margin: 0 -18px; padding: 0 18px;
  min-height: 210px; display: flex; align-items: flex-end;
  background: var(--surface) center 20% / cover no-repeat;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 20%, var(--bg) 96%);
}
.hero .back {
  position: absolute; top: 12px; left: 14px; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(20, 18, 40, .6); color: #fff; border: 0; cursor: pointer;
  display: grid; place-items: center;
}
.hero .back svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.4; }
.detail-head {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: end;
  margin-top: -70px;
}
.detail-head h1 { font-size: 1.9rem; }
.detail-head .meta { color: var(--muted); margin-top: 6px; font-size: .95rem; }
.overview { margin-top: 18px; max-width: 65ch; }
.overview.clamped { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.linkish { background: none; border: 0; padding: 0; color: var(--lamp); font-weight: 700; cursor: pointer; }
.saved-note { font-size: .85rem; color: var(--ok); min-height: 1.2em; }

/* ---------- Griglia episodi: l'elemento distintivo ---------- */
.season { padding: 16px 0; border-bottom: 1px solid var(--line); }
.season:last-child { border-bottom: 0; }
.season-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.season-head .count { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.ep-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px;
}
.ep {
  aspect-ratio: 1; min-width: 38px; border-radius: 8px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface);
  font: 700 .9rem/1 var(--font-display); color: var(--muted);
  display: grid; place-items: center;
  transition: background .15s, color .15s, transform .1s;
}
.ep:active { transform: scale(.92); }
.ep.on { background: var(--lamp); border-color: var(--lamp); color: var(--lamp-ink); }
.ep.next { border-color: var(--lamp); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--lamp); }
.ep:disabled { cursor: default; border-style: dashed; background: transparent; opacity: .55; }
.season-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.ep-list { margin-top: 14px; display: grid; gap: 2px; }
.ep-item { display: grid; grid-template-columns: 44px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.ep-item .name { font-weight: 700; }
.ep-item .meta { color: var(--muted); font-size: .85rem; }
.ep-item .ov { font-size: .92rem; margin-top: 4px; color: var(--muted); }
.ep-item .until { margin-top: 6px; }

/* ---------- Calendario ---------- */
.day { margin-top: 22px; }
.day h2 { font-size: 1.1rem; margin-bottom: 4px; }
.day h2 .muted { font-family: var(--font-body); font-weight: 400; font-size: .9rem; }

/* ---------- Statistiche ---------- */
.big-time { font-family: var(--font-display); font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.big-time .n { font-size: 3.6rem; }
.big-time .u { font-size: 1.4rem; color: var(--muted); margin: 0 10px 0 4px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 22px; }
.split .n { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; }
.chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 150px; margin-top: 8px; }
.chart .col { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.chart .b { background: var(--lamp); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .b.mv { background: var(--muted); }
.chart .b + .b { border-radius: 0; }
.chart-labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; font-size: .75rem; color: var(--muted); text-align: center; margin-top: 6px; }
.legend { display: flex; gap: 16px; font-size: .85rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* ---------- Varie ---------- */
.empty { padding: 28px 0; color: var(--muted); max-width: 46ch; }
.empty .btn { margin-top: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.user-row:last-child { border-bottom: 0; }
.loading { padding: 40px 0; color: var(--muted); }
.error-box { padding: 16px; border-radius: var(--r-md); background: var(--lamp-soft); margin-top: 16px; }

.login { min-height: 80vh; display: grid; align-content: center; max-width: 380px; margin: 0 auto; }
.login .mark { width: 64px; height: 64px; margin-bottom: 20px; }
.login h1 { font-size: 2.6rem; margin-bottom: 6px; }
.login p { margin: 0 0 26px; color: var(--muted); }

/* ---------- Barra in basso ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  padding: 6px 6px env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
#tabbar[hidden] { display: none; }
#tabbar a {
  display: grid; justify-items: center; gap: 2px; padding: 6px 0 8px;
  text-decoration: none; color: var(--muted); font-size: .68rem; font-weight: 700;
}
#tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
#tabbar a.active { color: var(--lamp); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom, 0px));
  max-width: min(92vw, 520px); padding: 12px 18px; border-radius: var(--r-md);
  background: var(--text); color: var(--bg); font-weight: 700;
}

@media (min-width: 700px) {
  #app { padding-left: 28px; padding-right: 28px; }
  .hero { margin: 0 -28px; padding: 0 28px; min-height: 280px; }
  .detail-head { grid-template-columns: 140px 1fr; }
  .detail-head h1 { font-size: 2.4rem; }
}

img.broken { visibility: hidden; }

/* ---------- Novità: percentuali ---------- */
.barrow { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.barrow .bar { flex: 1; margin-top: 0; display: flex; }
.bar > b { display: block; height: 100%; background: var(--lamp-soft); }
.pct { font: 700 .85rem/1 var(--font-display); color: var(--lamp); min-width: 3.2ch; text-align: right; }
.bar.thick { height: 8px; margin-top: 8px; }
.show-progress { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
.pct-big { font: 800 2.6rem/1 var(--font-display); color: var(--lamp); letter-spacing: -0.03em; }
.pct-big small { font-size: 1.2rem; margin-left: 2px; }
.ep.future { border-style: dashed; background: transparent; opacity: .7; }
.ep.future.on { opacity: 1; border-style: dashed; border-color: var(--lamp-ink); background: var(--lamp); }

/* ---------- Dashboard ---------- */
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.summary .split.four { grid-template-columns: repeat(2, 1fr); gap: 18px 20px; }
.summary .split a { text-decoration: none; }
@media (min-width: 640px) { .summary .split.four { grid-template-columns: repeat(4, 1fr); } }
.hscroll {
  display: grid; grid-auto-flow: column; grid-auto-columns: 116px; gap: 12px;
  overflow-x: auto; margin: 0 -18px; padding: 0 18px 6px; scroll-padding-inline: 18px; scroll-snap-type: x proximity; scrollbar-width: none;
}
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { scroll-snap-align: start; }
.hscroll .rec a, .hscroll a { text-decoration: none; }
.hscroll .title { font-size: .9rem; font-weight: 700; margin-top: 6px; line-height: 1.25; }
.hscroll .meta { font-size: .78rem; color: var(--muted); line-height: 1.3; margin-top: 2px; }
.hscroll.lists { grid-auto-columns: 148px; }
.hscroll > .loading, .hscroll > p { grid-column: 1 / -1; width: calc(100vw - 36px); max-width: 700px; }

/* ---------- Liste ---------- */
.list-card { display: block; text-decoration: none; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.list-card .covers {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px; aspect-ratio: 1; border-radius: var(--r-md); overflow: hidden;
  background: var(--raised);
}
.list-card .covers img, .list-card .covers span { width: 100%; height: 100%; object-fit: cover; background: var(--surface); }
.list-card.new .covers { display: grid; grid-template-columns: 1fr; place-items: center; border: 1.5px dashed var(--line); background: transparent; }
.list-card.new .covers span { background: none; display: grid; place-items: center; font: 300 3rem/1 var(--font-display); color: var(--lamp); }
.list-card .title { font-weight: 700; margin-top: 8px; line-height: 1.25; }
.list-card .meta { font-size: .82rem; color: var(--muted); }
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px 14px; }
.tile { position: relative; }
.tile .remove {
  display: none; position: absolute; top: -8px; right: -8px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: var(--danger); color: #fff; font: 700 1.2rem/1 var(--font-body); cursor: pointer;
}
.editing .tile .remove { display: grid; place-items: center; }
.linkish svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.4; vertical-align: -3px; }

/* ---------- Generi ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700;
}
.chip:hover { border-color: var(--lamp); }
.chip.on { background: var(--lamp-soft); border-color: var(--lamp); }
.chip svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.4; }
.browse-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* ---------- Finestre di dialogo ---------- */
.dlg-backdrop { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(10, 8, 24, .6); }
.dlg { width: min(440px, 100%); max-height: 85vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; }
.dlg > p { margin: 0 0 16px; }
.dlg input[type=text] { margin-bottom: 4px; }
.btn-row.end { justify-content: flex-end; }
.radios { border: 0; padding: 0; margin: 0 0 18px; }
.radios legend { font-weight: 700; font-size: .95rem; margin-bottom: 8px; }
.radios label { display: flex; align-items: center; gap: 10px; min-height: 40px; font-weight: 400; }
.radios input { width: 20px; height: 20px; accent-color: var(--lamp); }
.pick { display: grid; gap: 4px; }
.pick-row {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: transparent; cursor: pointer; text-align: left;
}
.pick-row .name { flex: 1; font-weight: 700; }
.pick-row .box { width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--line); display: grid; place-items: center; color: transparent; }
.pick-row .box svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 3; }
.pick-row[aria-pressed=true] { border-color: var(--lamp); }
.pick-row[aria-pressed=true] .box { background: var(--lamp); border-color: var(--lamp); color: var(--lamp-ink); }
