:root {
  --bg: #0b0b0d; --bg2: #16161a; --bg3: #222228; --fg: #f2f2f4; --mut: #9a9aa3; --accent: #f0b429; --red: #ff6b5e;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior-y: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: var(--fg); }
.hidden { display: none !important; }
.muted { color: var(--mut); }
.error { color: var(--red); min-height: 1.4em; }
.pad { padding: 0 16px; }

/* logo */
.logo { display: flex; align-items: center; font-weight: 800; letter-spacing: .32em; font-size: 17px; }
.logo .eye { width: 22px; height: 15px; margin-right: 10px; background: var(--accent); border-radius: 50% 0; transform: rotate(45deg) scale(.8); position: relative; }
.logo .eye::after { content: ""; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 50%; background: var(--bg); }
.logo.big { font-size: 30px; justify-content: center; margin-bottom: 18px; }
.logo.big .eye { width: 40px; height: 27px; margin-right: 18px; }
.logo.big .eye::after { width: 12px; height: 12px; margin: -6px 0 0 -6px; }

/* connexion */
#login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; text-align: center; }
#login form { display: flex; flex-direction: column; gap: 12px; max-width: 340px; width: 100%; margin: 12px auto 0; }
#login input, .field { background: var(--bg2); border: 1px solid var(--bg3); border-radius: 12px; padding: 14px 16px; font-size: 17px; outline: none; }
#login input:focus { border-color: var(--accent); }

/* boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 12px;
  background: var(--bg3); font-weight: 600; font-size: 16px; }
.btn.primary { background: var(--accent); color: #111; }
.btn.wide { width: 100%; }
.btn:active { transform: scale(.98); opacity: .85; }
.btn[disabled] { opacity: .5; }
.icon-btn { width: 40px; height: 40px; border-radius: 20px; font-size: 22px; line-height: 40px; text-align: center; }

/* en-tête */
#top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: calc(var(--st) + 8px) calc(var(--sr) + 10px) 8px calc(var(--sl) + 16px);
  background: linear-gradient(var(--bg) 60%, rgba(11,11,13,0)); }
#top .logo { flex: none; }
#sync { flex: 1; min-width: 0; font-size: 12px; color: var(--mut); }
#sync span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sync i { display: block; height: 3px; border-radius: 2px; background: var(--bg3); margin-top: 3px; overflow: hidden; }
#sync b { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
#btn-settings { margin-left: auto; }

main { padding-bottom: calc(var(--sb) + 76px); padding-left: var(--sl); padding-right: var(--sr); }

/* barre d'onglets */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: rgba(16,16,19,.92);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); border-top: 1px solid #ffffff12; padding-bottom: var(--sb); }
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 0 6px; font-size: 11px; color: var(--mut); }
#tabs .ti { font-size: 21px; line-height: 24px; }
#tabs button.on { color: var(--accent); }

/* accueil */
.hero { position: relative; margin: 0 16px 8px; border-radius: 16px; overflow: hidden; aspect-ratio: 16 / 10; background: var(--bg2); }
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(11,11,13,.95) 8%, rgba(11,11,13,0) 62%); }
.hero .hx { position: absolute; left: 16px; right: 16px; bottom: 14px; z-index: 1; }
.hero h2 { margin: 0 0 2px; font-size: 24px; line-height: 1.15; }
.hero .meta { font-size: 13px; }
.row { margin-top: 18px; }
.row h3 { display: flex; align-items: baseline; gap: 8px; margin: 0 16px 8px; font-size: 18px; }
.row h3 small { font-size: 13px; font-weight: 400; color: var(--mut); }
.track { display: flex; gap: 10px; overflow-x: auto; padding: 0 16px 4px; scroll-snap-type: x proximity; scroll-padding-left: 16px; scrollbar-width: none; }
.track::-webkit-scrollbar { display: none; }
.track .card { flex: none; width: 28vw; max-width: 150px; scroll-snap-align: start; }

/* jaquettes */
.card { position: relative; display: block; text-align: left; }
.card .pic { position: relative; aspect-ratio: 2 / 3; border-radius: 9px; overflow: hidden; background: var(--bg2); }
.card .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 10px; text-align: center;
  font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.card .cap { font-size: 12px; color: var(--mut); margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .badge { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.72); color: var(--accent); font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 6px; }
.card .seen { position: absolute; left: 6px; top: 6px; width: 20px; height: 20px; border-radius: 10px; background: var(--accent); color: #111;
  font-size: 12px; font-weight: 800; text-align: center; line-height: 20px; }
.card:active .pic { opacity: .75; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 10px; padding: 8px 16px 0; }
.grid .card .pic, .track .card .pic { content-visibility: auto; contain-intrinsic-size: 150px 225px; }

/* filtres */
#filters { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 10px; scrollbar-width: none; }
#filters::-webkit-scrollbar { display: none; }
.chip { position: relative; flex: none; display: inline-flex; align-items: center; height: 34px; padding: 0 12px; border-radius: 17px;
  background: var(--bg2); border: 1px solid var(--bg3); font-size: 14px; white-space: nowrap; }
.chip.on { background: #f0b4291f; border-color: var(--accent); color: var(--accent); }
.chip select { position: absolute; inset: 0; opacity: 0; width: 100%; }
.chip::after { content: "▾"; margin-left: 6px; font-size: 11px; opacity: .7; }
.chip.reset::after { content: ""; margin: 0; }

/* panneaux (fiche, saga, réglages) */
.layer { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: slide .22s ease-out; padding-bottom: calc(var(--sb) + 30px); }
@keyframes slide { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.layer .close { position: fixed; z-index: 3; top: calc(var(--st) + 10px); right: calc(var(--sr) + 12px); width: 38px; height: 38px; border-radius: 19px;
  background: rgba(0,0,0,.6); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); font-size: 20px; line-height: 38px; text-align: center; }
.layer .back { position: fixed; z-index: 3; top: calc(var(--st) + 10px); left: calc(var(--sl) + 12px); height: 38px; padding: 0 14px; border-radius: 19px;
  background: rgba(0,0,0,.6); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); font-size: 15px; }
.d-bd { position: relative; width: 100%; aspect-ratio: 16 / 10; background: var(--bg2) center / cover no-repeat; }
.d-bd.none { aspect-ratio: auto; height: calc(var(--st) + 140px); }
.d-bd::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, var(--bg) 2%, rgba(11,11,13,0) 55%); }
.d-head { display: flex; gap: 14px; margin-top: -70px; position: relative; z-index: 1; padding: 0 16px; align-items: flex-end; }
.d-head .card { width: 96px; flex: none; }
.d-head h1 { font-size: 23px; line-height: 1.15; margin: 0 0 4px; }
.d-tag { font-style: italic; color: var(--mut); font-size: 14px; }
.meta { color: var(--mut); font-size: 14px; }
.meta .star { color: var(--accent); }
.d-body { padding: 14px 16px 0; }
.d-genres { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 12px; }
.d-genres span { font-size: 12px; padding: 3px 9px; border-radius: 10px; background: var(--bg2); color: #cfcfd6; }
.d-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.d-actions .primary { grid-column: 1 / -1; min-height: 52px; font-size: 17px; }
.d-overview { margin: 0 0 12px; color: #dcdce2; }
.d-credits { font-size: 14px; color: var(--mut); margin-bottom: 6px; }
.d-credits b { color: #d8d8de; font-weight: 600; }
.d-file { font-size: 12px; color: #6d6d75; margin-top: 18px; word-break: break-all; }
.d-sub { font-size: 18px; margin: 22px 0 10px; }
.people { display: flex; gap: 12px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.people::-webkit-scrollbar { display: none; }
.person { flex: none; width: 74px; text-align: center; font-size: 11px; }
.person .ph { width: 64px; height: 64px; border-radius: 32px; margin: 0 auto 5px; background: var(--bg2) center / cover; display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--mut); }
.person .r { color: var(--mut); }
.eps { display: flex; flex-direction: column; gap: 8px; }
.ep { display: flex; gap: 12px; align-items: center; text-align: left; background: var(--bg2); border-radius: 12px; padding: 8px; }
.ep .still { width: 112px; flex: none; aspect-ratio: 16 / 9; border-radius: 8px; background: var(--bg3) center / cover; position: relative; }
.ep .still::after { content: "▶"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; text-shadow: 0 1px 6px #000; }
.ep .t { font-weight: 600; font-size: 14px; }
.ep .s { font-size: 12px; color: var(--mut); }
.ep.seen .t::before { content: "✓ "; color: var(--accent); }
.seasons { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 10px; }

/* page saga */
.s-head { padding: calc(var(--st) + 64px) 16px 6px; }
.s-head h1 { margin: 0 0 4px; font-size: 26px; }

/* feuille d'actions (versions, lecture) */
.sheet-bg { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 560px; margin: 0 auto; background: var(--bg2); border-radius: 18px 18px 0 0; padding: 18px 16px calc(var(--sb) + 16px);
  animation: up .2s ease-out; max-height: 85vh; overflow-y: auto; }
@keyframes up { from { transform: translateY(40px); } }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet p { margin: 0 0 14px; color: var(--mut); font-size: 14px; }
.sheet .list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.sheet .item { text-align: left; background: var(--bg3); border-radius: 12px; padding: 12px 14px; }
.sheet .item small { display: block; color: var(--mut); font-size: 12px; margin-top: 2px; word-break: break-all; }
.sheet .btns { display: flex; flex-direction: column; gap: 8px; }
.sheet textarea { width: 100%; height: 160px; background: var(--bg); color: var(--fg); border: 1px solid var(--bg3); border-radius: 10px; padding: 10px; font-size: 12px; }

/* réglages */
.set { padding: calc(var(--st) + 64px) 16px 0; max-width: 640px; margin: 0 auto; }
.set h1 { margin: 0 0 16px; }
.set .box { background: var(--bg2); border-radius: 14px; padding: 6px 14px; margin-bottom: 14px; }
.set .line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #ffffff0d; font-size: 15px; }
.set .line:last-child { border-bottom: 0; }
.set .line span:last-child { color: var(--mut); text-align: right; }
.set .ok { color: #7bd88f !important; }
.set .ko { color: var(--red) !important; }
.set .btns { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.set p { color: var(--mut); font-size: 14px; }

.empty { padding: 40px 24px; text-align: center; color: var(--mut); }

#toast { position: fixed; left: 50%; bottom: calc(var(--sb) + 84px); transform: translateX(-50%); z-index: 100; max-width: calc(100% - 32px);
  background: #2a2a31; color: var(--fg); padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 30px #0008; text-align: center; }

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .hero { aspect-ratio: 21 / 9; }
  .d-bd { aspect-ratio: 21 / 8; }
  .d-body, .d-head { max-width: 900px; }
}
