:root {
  --bg: #0b0b0f;
  --bg-2: #15151c;
  --bg-3: #1f1f29;
  --text: #ececf1;
  --muted: #9a9aab;
  --accent: #e5b443;
  --mega: #d9272e;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  background: rgba(11, 11, 15, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 16px 10px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid #ffffff10;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { margin: 0; font-size: 20px; letter-spacing: .02em; font-weight: 800; }
.logo span { color: var(--accent); }
.help-btn {
  background: none; border: 1px solid #ffffff30; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.help-btn[aria-expanded="true"] { background: var(--accent); color: #111; border-color: var(--accent); }
.search { position: relative; margin-top: 10px; }
.search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: var(--muted); }
.search input {
  width: 100%; padding: 9px 12px 9px 38px;
  background: var(--bg-3); border: 1px solid transparent; border-radius: var(--radius);
  font-size: 16px; /* avoids iOS zoom on focus */
}
.search input:focus { outline: none; border-color: var(--accent); }
.filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
.filters label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.filters span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.filters select {
  width: 100%; padding: 8px 6px; border-radius: 8px; text-overflow: ellipsis;
  background: var(--bg-3); border: 1px solid #ffffff14; font-size: 13px;
}

/* Help */
.help {
  margin: 12px 16px 0; padding: 14px 16px; border-radius: var(--radius);
  background: var(--bg-2); border: 1px solid #e5b44340;
}
.help h2 { margin: 0 0 6px; font-size: 16px; color: var(--accent); }
.help ul { margin: 0; padding-left: 18px; }
.help li { margin: 6px 0; color: #d4d4de; }

/* Grid */
main { padding: 8px 16px 24px; }
.count { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }
.card {
  display: block; text-align: left; padding: 0; border: 0; background: none; cursor: pointer;
  color: inherit; text-decoration: none;
  border-radius: var(--radius); -webkit-tap-highlight-color: transparent;
}
.poster {
  position: relative; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(160deg, #262633, #15151c);
  box-shadow: 0 4px 14px #0008;
}
.poster img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
.poster .ph { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; text-align: center; color: var(--muted); font-weight: 600; }
.badge {
  position: absolute; top: 6px; left: 6px; background: #000c; color: var(--accent);
  font-size: 12px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
}
.badge.off { left: auto; right: 6px; color: #ddd; background: #444c; }
.card h3 { margin: 7px 2px 0; font-size: 14px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card p { margin: 2px 2px 0; font-size: 12px; color: var(--muted); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (hover: hover) { .card:hover .poster img { transform: scale(1.04); } }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Modal / detail */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: #000b; }
.sheet {
  position: relative; width: 100%; max-height: 94vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-2); border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.close {
  position: absolute; top: 10px; right: 10px; z-index: 2; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: #000a; font-size: 16px; cursor: pointer;
}
.hero { position: relative; aspect-ratio: 16 / 9; background: #000 center / cover no-repeat; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, transparent 40%, var(--bg-2)); }
.hero.none { aspect-ratio: auto; height: 56px; }
.d-body { position: relative; padding: 0 16px 20px; margin-top: -48px; }
.d-head { display: flex; gap: 14px; align-items: flex-end; }
.d-head img, .d-head .noimg { width: 104px; flex: none; aspect-ratio: 2 / 3; border-radius: 8px; object-fit: cover; box-shadow: 0 6px 20px #000a; background: var(--bg-3); }
.d-head h2 { margin: 0; font-size: 21px; line-height: 1.2; }
.d-head .orig { margin: 3px 0 0; color: var(--muted); font-size: 13px; font-style: italic; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 14px 0 8px; color: #cfcfdb; font-size: 14px; }
.meta .rate { color: var(--accent); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.chips span { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--bg-3); color: #d8d8e4; }
.actions { display: grid; gap: 10px; margin: 16px 0; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px;
  padding: 12px 16px; border-radius: 12px; border: 0; cursor: pointer;
  font-size: 16px; font-weight: 700; text-decoration: none; color: #fff;
}
.btn-mega { background: var(--mega); }
.btn-mega:hover { background: #ef343b; }
.btn-mega small { font-weight: 500; opacity: .85; }
.btn-trailer { background: var(--bg-3); border: 1px solid #ffffff20; }
.btn-off { background: #2a2a33; color: var(--muted); cursor: default; }
.synopsis { margin: 0 0 14px; color: #dcdce6; }
.people { margin: 0; font-size: 14px; }
.people dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; margin-top: 10px; }
.people dd { margin: 2px 0 0; }
.trailer { position: relative; aspect-ratio: 16 / 9; margin: 0 0 16px; border-radius: 10px; overflow: hidden; background: #000; }
.trailer iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Footer */
.foot { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 16px 36px; border-top: 1px solid #ffffff10; text-align: center; }
.foot p { margin: 0; font-size: 12px; color: var(--muted); max-width: 420px; }
.tmdb svg { width: 96px; height: 32px; display: block; }

body.locked { overflow: hidden; }

/* Wider screens */
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters select { font-size: 15px; padding: 8px 10px; }
}
@media (min-width: 820px) {
  .top { padding-left: 24px; padding-right: 24px; display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 16px; }
  .top-row { display: contents; }
  .logo { grid-column: 1; grid-row: 1; align-self: center; }
  .search { grid-column: 2; grid-row: 1; margin: 0; max-width: 560px; }
  .help-btn { grid-column: 3; grid-row: 1; align-self: center; }
  .hero { aspect-ratio: auto; height: 340px; }
  .filters { grid-column: 1 / -1; grid-row: 2; margin: 0; grid-template-columns: repeat(3, minmax(0, 230px)); }
  main { padding: 8px 24px 32px; }
  .help { margin: 16px 24px 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 20px 16px; }
  .modal { align-items: center; padding: 24px; }
  .sheet { max-width: 860px; border-radius: 16px; max-height: 90vh; }
  .d-body { padding: 0 28px 28px; }
  .d-head img, .d-head .noimg { width: 160px; }
  .d-head h2 { font-size: 28px; }
  .actions { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
