:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #646b78;
  --line: #e2e5ea;
  --accent: #1b2a55;
  --accent-ink: #ffffff;
  --accent-soft: #e6e9f2;
  --imdb: #f5c518;
  --rt: #fa320a;
  --good: #1f8a4c;
  --good-soft: #e3f3e9;
  --new: #c8102e;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1a1d23;
    --ink: #eef0f3;
    --muted: #9aa1ad;
    --line: #2a2e36;
    --accent-soft: #232a3d;
    --good: #4cc27c;
    --good-soft: #17301f;
    --new: #ff5a6e;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 150px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Header */
.top {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 16px 0;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: var(--accent);
}
.top-row { display: flex; align-items: center; gap: 10px; }
.home-link {
  color: inherit; text-decoration: none; font-size: 22px; line-height: 1;
  padding: 6px 8px 6px 0;
}
.top h1 { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; margin: 0; flex: 1; }
.top h1 small { display: block; font-size: 12.5px; font-weight: 500; opacity: .75; letter-spacing: 0; }
.add-btn {
  border: 1.5px solid rgba(255,255,255,.5); background: transparent; color: inherit;
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600;
}
.search {
  margin: 10px 0 8px; width: 100%; border: 0; border-radius: 10px;
  padding: 10px 12px; background: rgba(255,255,255,.16); color: inherit; font-size: 16px;
}
.search::placeholder { color: rgba(255,255,255,.7); }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 0; background: transparent; color: inherit; opacity: .72;
  padding: 9px 10px 11px; font-size: 15px; font-weight: 600; border-bottom: 3px solid transparent;
}
.tab[aria-selected="true"] { opacity: 1; border-bottom-color: var(--accent-ink); }
.tab .count { font-weight: 500; opacity: .8; margin-left: 3px; }

/* List */
main { padding: 4px 34px 32px 12px; max-width: 760px; margin: 0 auto; }
.letter {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + var(--head, 150px));
  z-index: 5;
  background: var(--bg);
  font-size: 30px; font-weight: 800; letter-spacing: -0.03em;
  color: var(--accent); padding: 10px 4px 2px; margin: 0;
}
@media (prefers-color-scheme: dark) { .letter { color: var(--ink); } }
.film {
  background: var(--surface);
  border-radius: 14px;
  margin: 8px 0;
  overflow: hidden;
  border: 1px solid var(--line);
}
.film.is-watched .film-body, .film.is-watched .ratings { opacity: .6; }
.film-body {
  display: flex; gap: 12px; align-items: flex-start; width: 100%;
  border: 0; background: none; text-align: left; padding: 12px 12px 4px;
}
.thumb {
  position: relative; flex: none; width: 66px; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden;
  background: linear-gradient(160deg, hsl(var(--h) 55% 46%), hsl(calc(var(--h) + 25) 60% 24%));
  display: grid; place-items: center; color: rgba(255,255,255,.92);
  font-size: 22px; font-weight: 800; letter-spacing: -0.02em;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.film-text { flex: 1; min-width: 0; }
.film-title { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
.badge-new {
  display: inline-block; vertical-align: 2px; margin-left: 6px;
  font-size: 11px; font-weight: 750; color: #fff; background: var(--new);
  padding: 2px 6px; border-radius: 5px;
}
.meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.desc { margin: 6px 0 0; font-size: 14.5px; line-height: 1.4; color: var(--ink); }
.film-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px 12px 90px; }
.ratings { display: flex; gap: 6px; flex-wrap: wrap; }
.r {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 650; padding: 3px 7px; border-radius: 6px;
  background: var(--accent-soft);
}
.r-imdb b { background: var(--imdb); color: #000; padding: 0 4px; border-radius: 3px; font-size: 11px; font-weight: 800; }
.r-rt b { color: var(--rt); font-size: 13px; }
.r.na { color: var(--muted); font-weight: 500; }
.actions { display: flex; gap: 6px; flex: none; }
.act {
  width: 42px; height: 38px; border-radius: 10px; border: 1.5px solid var(--line);
  background: transparent; display: grid; place-items: center; color: var(--muted);
}
.act svg { width: 20px; height: 20px; }
.act[aria-pressed="true"].watch { background: var(--accent); border-color: var(--accent); color: #fff; }
.act[aria-pressed="true"].seen { background: var(--good); border-color: var(--good); color: #fff; }
@media (prefers-color-scheme: dark) {
  .act[aria-pressed="true"].watch { background: #3b5bdb; border-color: #3b5bdb; }
}
.details { padding: 0 14px 14px 90px; display: none; }
.film.open .details { display: block; }
.details p { margin: 0; max-width: 62ch; }
.details .cast { color: var(--muted); font-size: 14px; }
.details .cast strong { color: var(--ink); font-weight: 600; }
.links { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.links a, .links button {
  font-size: 14px; font-weight: 600; color: var(--accent); text-decoration: none;
  border: 1.5px solid var(--line); border-radius: 999px; padding: 6px 12px; background: transparent;
}
@media (prefers-color-scheme: dark) { .links a, .links button { color: var(--ink); } }
.links .danger { color: var(--new); }
.posters { text-align: center; padding: 20px 12px 0; }
.posters .btn { font-size: 15px; }
.posters p { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.note { color: var(--muted); font-size: 13px; text-align: center; padding: 16px 12px 0; max-width: 60ch; margin: 0 auto; }

/* Alphabet scrubber */
.alpha {
  position: fixed; right: 2px; z-index: 15;
  top: calc(env(safe-area-inset-top, 0px) + var(--head, 150px) + 8px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  display: flex; flex-direction: column; justify-content: center;
  width: 26px; touch-action: none; user-select: none; -webkit-user-select: none;
}
.alpha span {
  display: block; text-align: center; font-size: 11px; font-weight: 700;
  color: var(--accent); line-height: 1; padding: 2px 0; flex: 0 1 auto;
}
@media (prefers-color-scheme: dark) { .alpha span { color: var(--muted); } }
.alpha-pop {
  position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%);
  width: 84px; height: 84px; border-radius: 20px; background: var(--accent); color: #fff;
  font-size: 44px; font-weight: 800; display: grid; place-items: center;
  z-index: 40; pointer-events: none; opacity: 0; transition: opacity .15s;
}
.alpha-pop.show { opacity: .92; }

/* Add dialog */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(94vw, 480px);
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg { padding: 18px; }
.dlg h2 { margin: 0 0 12px; font-size: 20px; }
.dlg label { display: block; font-size: 14px; font-weight: 600; margin: 10px 0 4px; }
.dlg input, .dlg textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 10px;
  background: var(--bg); font-size: 16px;
}
.dlg textarea { min-height: 70px; resize: vertical; }
.dlg .row { display: flex; gap: 10px; }
.dlg .row > div { flex: 1; }
.dlg .check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-top: 12px; }
.dlg .check input { width: auto; }
.dlg .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn { border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 650; background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: #fff; }

/* Home page */
.home { max-width: 520px; margin: 0 auto; padding: 32px 18px; }
.home h1 { font-size: 34px; letter-spacing: -0.03em; margin: 8px 0 4px; }
.home p { color: var(--muted); margin: 0 0 24px; }
.airline {
  display: block; text-decoration: none; color: #fff; border-radius: 18px;
  padding: 22px 20px; margin-bottom: 14px; position: relative;
}
.airline strong { display: block; font-size: 24px; letter-spacing: -0.02em; }
.airline span { opacity: .8; font-size: 14px; }
.airline.nz { background: #111; }
.airline.ba { background: #1b2a55; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.poster-bar { font-size: 12.5px; opacity: .8; padding: 0 0 8px; }
.poster-bar[hidden] { display: none; }
