/* ============================================================
   THE VAULT — style
   dark cinema / editorial archive
   ============================================================ */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --nav-h: 64px;
  --bg: #0c0c0e;
  --bg-2: #121215;
  --ink: #e8e4da;          /* warm off-white */
  --ink-dim: #9b968b;
  --ink-faint: #57534b;
  --line: #26262b;
  --accent: #d8a648;       /* projector amber */
  --accent-dim: #8a6a2e;
  --scrim: rgba(12,12,14,.92);       /* translucent nav / sticky bars */
  --scrim-strong: rgba(12,12,14,.95);
  --backdrop: rgba(5,5,7,.86);       /* modal backdrop (deep scrim, no blur) */
  --panel: #101014;                  /* modal panel */
  --panel-line: #2c2c33;
  --on-accent: #0c0c0e;              /* text on amber fills */
  --on-accent-soft: rgba(12,12,14,.65);
  --ph-dash: #34343b;                /* placeholder dashes */
  --hover-line: #3d3d44;
  --vignette: rgba(0,0,0,.32);
  --serif: "Instrument Serif", "Times New Roman", serif;
  --display: "Anton", "Arial Narrow", sans-serif;
  --body: "Space Grotesk", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
}

/* ---------- light mode (day screening) ---------- */

[data-theme="light"] {
  --bg: #f3f0e9;
  --bg-2: #eae6db;
  --ink: #23201a;
  --ink-dim: #5a5548;
  --ink-faint: #8d8672;
  --line: #d9d4c6;
  --accent: #a8731f;       /* darker amber for contrast on paper */
  --accent-dim: #c19a4e;
  --scrim: rgba(243,240,233,.94);
  --scrim-strong: rgba(243,240,233,.97);
  --backdrop: rgba(35,30,18,.58);
  --panel: #fbfaf5;
  --panel-line: #d9d4c6;
  --on-accent: #ffffff;
  --on-accent-soft: rgba(255,255,255,.78);
  --ph-dash: #c9c3b4;
  --hover-line: #c9c3b4;
  --vignette: rgba(40,32,18,.14);
}

[data-theme="light"] .card:hover .frame {
  box-shadow: 0 22px 40px -18px rgba(35,25,10,.28), 0 0 0 1px rgba(168,115,31,.25);
}

[data-theme="light"] .modal-panel { box-shadow: 0 40px 90px -30px rgba(35,25,10,.35); }

[data-theme="light"] .grain { opacity: .03; }

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

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--accent); color: var(--on-accent); }

/* ---------- film grain + vignette ---------- */

.grain {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  pointer-events: none;
  z-index: 300; /* above the modal too: one uniform film layer over the site,
                   and never beneath a backdrop-filter it could force to re-run */
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 7s steps(10) infinite;
}

@keyframes grain {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -2%); }
  80% { transform: translate(3%, 3%); }
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 89;
  background: radial-gradient(ellipse at center, transparent 72%, var(--vignette) 100%);
}

/* ---------- top nav ---------- */

.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 2.5rem;
  padding: 0 clamp(1.2rem, 4vw, 3.5rem);
  height: 64px;
  background: var(--scrim);
  /* no backdrop-filter: a blur on a sticky bar re-renders every scroll
     frame (the animated grain sits beneath it, so the blur never stops
     re-running). The high-alpha scrim reads the same and scrolls smooth. */
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: .7rem;
  text-decoration: none;
  color: var(--ink);
}

.brand b {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: .14em;
}

.brand span {
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.nav-links { display: none; }

.nav-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: .5rem;
  border: 1px solid var(--line);
  height: 36px;
  box-sizing: border-box;
  padding: 0 .8rem;
  min-width: 210px;
  margin-left: auto;
  transition: border-color .25s;
}

.nav-search:focus-within { border-color: var(--accent-dim); }

.nav-search svg { flex: none; opacity: .5; }

.nav-search input {
  background: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-family: var(--body);
  font-size: .85rem;
  width: 100%;
}

.nav-search input::-webkit-search-cancel-button { display: none; }

.nav-search input::placeholder { color: var(--ink-faint); }

.search-clear {
  flex: none;
  background: none;
  border: 0;
  color: var(--ink-faint);
  font-size: 1.15rem;
  line-height: 1;
  padding: .15rem .35rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: color .2s;
}

.search-clear:hover { color: var(--ink); }

.theme-toggle {
  flex: none;
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  height: 36px;
  width: 36px;
  min-width: 36px;
  max-width: 36px;
  box-sizing: border-box;
  aspect-ratio: 1 / 1;
  border-radius: 0;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: color .2s, border-color .2s;
}

.theme-toggle:hover { color: var(--ink); border-color: var(--hover-line); }

.theme-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-icon svg { display: block; }
.theme-icon .icon-sun { display: none; }
.theme-icon .icon-moon { display: block; }
[data-theme="light"] .theme-icon .icon-sun { display: block; }
[data-theme="light"] .theme-icon .icon-moon { display: none; }

/* ---------- hero ---------- */

.hero {
  padding: clamp(4rem, 9vw, 8rem) clamp(1.2rem, 4vw, 3.5rem) 2.5rem;
  max-width: 1500px;
  margin: 0 auto;
  position: relative;
}

.hero-kicker {
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.4rem;
  display: flex;
  align-items: center;
  gap: .8rem;
}

.hero-kicker::before {
  content: "";
  width: 42px;
  height: 1px;
  background: var(--accent-dim);
}

.hero h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3rem, 9.5vw, 8.5rem);
  line-height: .96;
  letter-spacing: .015em;
  text-transform: uppercase;
}

.hero h1 em {
  font-family: var(--serif);
  font-style: italic;
  text-transform: none;
  color: var(--accent);
  letter-spacing: 0;
  padding: 0 .1em;
}

.hero-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  margin-top: 2.2rem;
  flex-wrap: wrap;
}

.hero-sub {
  max-width: 440px;
  color: var(--ink-dim);
  font-size: .95rem;
}

.hero-stats {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
}

.hero-stat {
  padding: .9rem 1.6rem;
  border-right: 1px solid var(--line);
}

.hero-stat:last-child { border-right: 0; }

.hero-stat b {
  display: block;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.9rem;
  letter-spacing: .04em;
}

.hero-stat span {
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---------- category tabs + sort bar (one sticky control bar) ---------- */

.sortbar-wrap {
  position: sticky;
  top: 64px;
  z-index: 80;
  background: var(--scrim-strong);
  border-bottom: 1px solid var(--line);
}

.catbar-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: stretch;
}

.catbar-wrap::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 24px;
  background: linear-gradient(to right, var(--scrim-strong), transparent);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity .2s;
}

.catbar-wrap.has-more-left::before {
  opacity: 1;
}

.catbar-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 28px;
  background: linear-gradient(to left, var(--scrim-strong), transparent);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity .2s;
}

.catbar-wrap.has-more-right::after {
  opacity: 1;
}

.catbar {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: .2rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.catbar::-webkit-scrollbar { display: none; }

.cat-btn {
  flex: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .16em;
  padding: .78rem .75rem .68rem;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: .45rem;
  touch-action: manipulation;
  transition: color .2s, border-color .2s;
}

.cat-btn .n {
  font-size: .56rem;
  color: var(--ink-faint);
  letter-spacing: .06em;
  transition: color .2s;
}

.cat-btn:hover { color: var(--ink); }

.cat-btn.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.cat-btn.active .n { color: var(--accent); }

.sortbar {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 clamp(1.2rem, 4vw, 3.5rem);
  display: flex;
  align-items: stretch;
  gap: .75rem;
}

/* ---------- sort: 3-dot kebab menu ---------- */

.sort-kebab {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
}

.kebab-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: .95rem;
  line-height: 1;
  padding: .38rem .62rem;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}

.kebab-btn:hover { color: var(--ink); border-color: var(--hover-line); }

.kebab-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  z-index: 150;
  min-width: 210px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  box-shadow: 0 24px 55px -22px rgba(0,0,0,.65);
  padding: .35rem;
  animation: kebabIn .16s ease both;
}

.kebab-menu[hidden],
.kebab-menu button[hidden] { display: none !important; }

@keyframes kebabIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

.menu-label {
  display: block;
  font-family: var(--mono);
  font-size: .55rem;
  letter-spacing: .22em;
  color: var(--ink-faint);
  padding: .4rem .55rem .3rem;
}

.kebab-menu button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: none;
  border: 0;
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .1em;
  padding: .55rem;
  cursor: pointer;
  text-align: left;
  transition: color .15s, background .15s;
}

.kebab-menu button:hover { color: var(--ink); background: var(--bg-2); }

.kebab-menu button.active { color: var(--accent); }

/* direction arrows show on the active row only */
.kebab-menu button .dir { opacity: 0; }
.kebab-menu button.active .dir { opacity: .85; }

/* ---------- shelves ---------- */

.shelf {
  max-width: 1500px;
  margin: 0 auto;
  padding: clamp(3rem, 6vw, 5.5rem) clamp(1.2rem, 4vw, 3.5rem) 0;
  scroll-margin-top: calc(var(--nav-h) + 48px);
}

.shelf-head {
  display: flex;
  align-items: baseline;
  gap: 1.4rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1.1rem;
  margin-bottom: 2.2rem;
}

.shelf-num {
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--accent);
  letter-spacing: .1em;
}

.shelf-head h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2rem, 4.5vw, 3.4rem);
  letter-spacing: .03em;
  text-transform: uppercase;
  line-height: 1;
}

.shelf-count {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--ink-faint);
  letter-spacing: .15em;
  align-self: center;
}

.shelf-note {
  margin-left: auto;
  max-width: 380px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.02rem;
  color: var(--ink-dim);
  text-align: right;
  display: none;
}

@media (min-width: 900px) { .shelf-note { display: block; } }

/* ---------- poster grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: clamp(1rem, 2.2vw, 1.8rem);
}

@media (min-width: 640px)  { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); } }

.card {
  position: relative;
  cursor: default;
}

.frame {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: var(--bg-2);
  border: 1px solid var(--line);
  transition: transform .35s cubic-bezier(.2,.7,.2,1), border-color .35s, box-shadow .35s;
}

@media (hover: hover) and (pointer: fine) {
  .card:hover .frame {
    transform: translateY(-7px);
    border-color: var(--accent-dim);
    box-shadow: 0 22px 40px -18px rgba(0,0,0,.85), 0 0 0 1px rgba(216,166,72,.25);
  }
}

.frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(.92) contrast(1.04);
  transition: transform .5s cubic-bezier(.2,.7,.2,1), filter .4s;
}

@media (hover: hover) and (pointer: fine) {
  .card:hover .frame img {
    transform: scale(1.045);
    filter: saturate(1.05) contrast(1.06);
  }
}

.frame::after {  /* bottom scrim for index chip */
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 34%;
  background: linear-gradient(transparent, rgba(0,0,0,.55));
  opacity: 0;
  transition: opacity .35s;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .card:hover .frame::after { opacity: 1; }
}

.idx {
  position: absolute;
  left: 10px;
  bottom: 8px;
  z-index: 2;
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .12em;
  color: #e8e4da;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .3s .05s, transform .3s .05s;
  text-shadow: 0 1px 6px rgba(0,0,0,.8);
}

@media (hover: hover) and (pointer: fine) {
  .card:hover .idx { opacity: .95; transform: translateY(0); }
}

.year-tag {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .12em;
  /* poster overlay: stays dark-chip/light-text in BOTH themes — var(--ink)
     would turn near-black in light mode on the dark chip (unreadable) */
  color: #e8e4da;
  background: rgba(10,10,12,.72);
  border: 1px solid rgba(255,255,255,.12);
  padding: .18rem .42rem;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .3s, transform .3s;
}

@media (hover: hover) and (pointer: fine) {
  .card:hover .year-tag { opacity: 1; transform: translateY(0); }
}

@media (hover: none) {
  .card {
    touch-action: manipulation;
  }
  .card:active .frame {
    transform: scale(0.975);
    border-color: var(--accent);
    transition: transform .12s cubic-bezier(.2,.8,.2,1);
  }
}

/* ---------- missing-poster placeholder ---------- */

.ph {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: .9rem;
  background:
    repeating-linear-gradient(45deg, transparent 0 12px, rgba(255,255,255,.012) 12px 24px),
    var(--bg-2);
  border: 1px dashed var(--ph-dash);
  margin: -1px;
}

.ph-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.25;
  color: var(--ink-dim);
}

.ph-file {
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .04em;
  color: var(--ink-faint);
  word-break: break-all;
  line-height: 1.5;
}

.ph-file b {
  color: var(--accent-dim);
  font-weight: 500;
}

/* ---------- card meta ---------- */

.meta {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  margin-top: .65rem;
}

.meta h3 {
  font-size: .86rem;
  font-weight: 500;
  letter-spacing: .01em;
  color: var(--ink);
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}

.meta .yr {
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--ink-faint);
  flex: none;
}

/* category tint on hover, subtle per-shelf */
[data-cat="animated"]:hover .frame { border-color: #b98f3e; }
[data-cat="hollywood"]:hover .frame { border-color: #a8a29a; }
[data-cat="marvel"]:hover .frame   { border-color: #b3403a; }

/* ---------- swap guide / footer ---------- */

.swap {
  max-width: 1500px;
  margin: clamp(4rem, 8vw, 7rem) auto 0;
  padding: 3rem clamp(1.2rem, 4vw, 3.5rem) 3.5rem;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 900px) { .swap { grid-template-columns: 1fr 1.4fr; } }

.swap h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.6rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.swap ol {
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 1rem;
}

.swap li {
  counter-increment: step;
  display: flex;
  align-items: flex-start;
  gap: .9rem;
  color: var(--ink-dim);
  font-size: .88rem;
  line-height: 1.55;
}

.swap li::before {
  content: counter(step, decimal-leading-zero);
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--accent);
  padding-top: .15rem;
  flex: none;
}

.swap .step-content {
  flex: 1;
  min-width: 0;
}

.swap code {
  font-family: var(--mono);
  font-size: .78em;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: .1em .38em;
  border-radius: 2px;
  word-break: break-word;
}

.swap .hint {
  margin-top: 1.1rem;
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-faint);
}

footer {
  border-top: 1px solid var(--line);
  padding: 1.4rem clamp(1.2rem, 4vw, 3.5rem);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---------- search empty state ---------- */

.hidden { display: none !important; }

.empty {
  display: none;
  padding: 4rem 0;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--ink-dim);
}

.empty.show { display: block; }

/* reveal on load */
.card { animation: rise .6s both; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   franchise cards: filmstrip slices for multi-part, full poster
   for single films
   ============================================================ */

.card.franchise { cursor: pointer; }

/* --- single film + series (one poster, no filmstrip) --- */
.card.franchise.single .frame img.st,
.card.franchise.single .frame .ph.st,
.card.franchise.series .frame img.st,
.card.franchise.series .frame .ph.st {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* --- multi-part: N vertical slices, one per part --- */
.franchise.multi .frame .slice {
  position: absolute;
  top: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-2);
}

/* thin divider between slices, filmstrip feel */
.franchise.multi .slice + .slice { box-shadow: inset 1px 0 0 rgba(0,0,0,.55); }

.franchise.multi .slice img {
  position: absolute;
  top: 0;
  height: 100%;
  object-fit: cover;
  filter: saturate(.92) contrast(1.04);
  transition: transform .5s cubic-bezier(.2,.7,.2,1), filter .4s;
}

.card.franchise.multi:hover .slice img {
  transform: scale(1.04);
  filter: saturate(1.06) contrast(1.06);
}

.franchise.multi .slice .ph {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  padding: .35rem;
  border: none;
  border-left: 1px dashed var(--ph-dash);
  margin: 0;
  background:
    repeating-linear-gradient(45deg, transparent 0 12px, rgba(255,255,255,.012) 12px 24px),
    var(--bg-2);
}

.franchise.multi .slice .ph .ph-file {
  font-size: .5rem;
  line-height: 1.4;
}

@media (hover: hover) and (pointer: fine) {
  /* on hover, each slice lifts its poster slightly — keeps the
     strip intact but feels alive */
  .card.franchise.multi:hover .slice:nth-child(odd) img { transform: scale(1.06) translateY(-1%); }
  .card.franchise.multi:hover .slice:nth-child(even) img { transform: scale(1.06) translateY(1%); }
  .card.franchise:hover .parts-chip {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* count + parts chips */
.parts-chip {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 4;
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .14em;
  color: var(--on-accent);
  background: var(--accent);
  padding: .2rem .45rem;
  transition: opacity .3s, transform .3s;
}

.more-chip {
  position: absolute;
  right: 10px;
  bottom: 34px;
  z-index: 4;
  font-family: var(--mono);
  font-size: .62rem;
  /* poster overlay: fixed light text on dark chip, both themes */
  color: #e8e4da;
  background: rgba(10,10,12,.78);
  border: 1px solid rgba(255,255,255,.14);
  padding: .18rem .42rem;
}

/* ============================================================
   modal / detail view
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  /* no backdrop-filter here: a full-viewport blur re-renders on EVERY
     scroll frame of the panel body — the modal would judder. The deep
     scrim alone reads the same and stays smooth. */
}

.modal-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  box-shadow: 0 40px 90px -30px rgba(0,0,0,.9);
  animation: modalIn .28s cubic-bezier(.2,.7,.2,1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(18px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.35rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}

#modal-label { flex: 1; }

.modal-close {
  flex: none;
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .12em;
  padding: .4rem .7rem;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}

.modal-close:hover { color: var(--accent); border-color: var(--accent-dim); }

.modal-body {
  overflow-y: auto;
  padding: 1.2rem 1.4rem 1.6rem;
  overscroll-behavior: contain;   /* wheel stops here, never chains to the page */
  contain: paint;                 /* keep repaints inside the scroller */
  will-change: scroll-position;   /* own scrolling layer: compositor-driven wheel */
}

.part {
  display: grid;
  grid-template-columns: 104px 1fr;
  gap: 1.2rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}

.part:last-child { border-bottom: 0; }

.part-poster {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-2);
}

.part-poster img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .35s;
  will-change: transform; /* hover zoom runs on the GPU, not as a repaint */
}

.part:hover .part-poster img { transform: scale(1.05); }

.part-info h4 {
  font-size: 1.02rem;
  font-weight: 500;
  line-height: 1.3;
  display: flex;
  align-items: baseline;
  gap: .6rem;
}

.part-num {
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--accent);
  letter-spacing: .1em;
  flex: none;
}

.part-line {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin: .45rem 0 .6rem;
}

.part-line .yr { font-family: var(--mono); font-size: .7rem; color: var(--ink-faint); }

.rating {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  text-decoration: none;
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  padding: .16rem .5rem;
  transition: background .2s, color .2s;
}

.rating svg { opacity: .85; }

.rating i {
  font-style: normal;
  font-size: .6rem;
  color: var(--ink-faint);
  letter-spacing: .06em;
  transition: color .2s;
}

.rating:hover { background: var(--accent); color: var(--on-accent); }
.rating:hover i { color: var(--on-accent-soft); }

.part-info p {
  font-size: .88rem;
  line-height: 1.6;
  color: var(--ink-dim);
  max-width: 52ch;
}

/* modal placeholder poster */
.part-poster .ph {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  padding: .5rem;
  border: 1px dashed var(--ph-dash);
  background: var(--bg-2);
}

.part-poster .ph .ph-file { font-size: .55rem; }

/* ---------- series detail: brief + season rows ---------- */

.series-brief {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 1.3rem;
  padding: .2rem 0 1.1rem;
}

.series-poster {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-2);
}

.series-poster img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.series-poster .ph {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  padding: .5rem;
  border: 1px dashed var(--ph-dash);
  background: var(--bg-2);
}

.series-poster .ph .ph-file { font-size: .55rem; }

.series-info h4 { font-size: 1.14rem; font-weight: 500; line-height: 1.3; }

.series-info .part-line { margin: .55rem 0 .7rem; }

.series-info p {
  font-size: .88rem;
  line-height: 1.6;
  color: var(--ink-dim);
  max-width: 52ch;
}

.seasons-label {
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .24em;
  color: var(--accent);
  padding: .9rem 0 .15rem;
  border-top: 1px solid var(--line);
}

.season-row {
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: .8rem 0;
  border-bottom: 1px solid var(--line);
}

.season-row:last-child { border-bottom: 0; }

.season-num {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--accent);
  letter-spacing: .1em;
  width: 2.5rem;
  flex: none;
}

.season-name {
  font-size: .96rem;
  font-weight: 500;
  flex: 1;
}

.season-row .yr { font-family: var(--mono); font-size: .7rem; color: var(--ink-faint); flex: none; }

.season-row .rating { flex: none; }

@media (max-width: 560px) {
  .series-brief { grid-template-columns: 92px 1fr; gap: .9rem; }
  .series-info h4 { font-size: 1rem; }
  .season-row { gap: .6rem; }
  .season-name { font-size: .88rem; }
}

@media (max-width: 560px) {
  .part { grid-template-columns: 84px 1fr; gap: .9rem; }
  .modal-head h3 { font-size: 1.1rem; }
}

/* ============================================================
   phone / small screens
   ============================================================ */

body { -webkit-tap-highlight-color: transparent; }
body.modal-open {
  overflow: hidden;
  touch-action: none;
}
.modal-close-esc { display: inline; }

@media (max-width: 640px), (prefers-reduced-motion: reduce) {
  .grain { animation: none; opacity: .03; }
}

@media (max-width: 640px) {
  :root {
    --nav-h: 56px;
  }

  /* nav: safe area, brand + search + icon toggle */
  .nav {
    height: calc(var(--nav-h) + var(--safe-top));
    padding-top: var(--safe-top);
    padding-left: max(.85rem, var(--safe-left));
    padding-right: max(.85rem, var(--safe-right));
    gap: .6rem;
  }
  .brand { gap: .5rem; }
  .brand span { display: none; }
  .brand b { font-size: 1.05rem; letter-spacing: .1em; }

  .nav-search {
    flex: 1;
    min-width: 0;
    height: 36px;
    padding: 0 .65rem;
    gap: .45rem;
    box-sizing: border-box;
    display: flex;
    align-items: center;
  }
  /* Crucial: 16px font-size prevents iOS Safari from zooming into the viewport */
  .nav-search input {
    font-size: 16px;
    padding: 0;
    line-height: normal;
  }
  .search-clear {
    padding: 0 .2rem;
    font-size: 1.15rem;
    line-height: 1;
  }

  /* sortbar sticky and tabs */
  .sortbar-wrap {
    top: calc(var(--nav-h) + var(--safe-top));
  }
  .sortbar {
    padding-left: max(.85rem, var(--safe-left));
    padding-right: max(.85rem, var(--safe-right));
    gap: .4rem;
  }

  .catbar {
    gap: .2rem;
    padding-right: .5rem;
  }
  .cat-btn {
    padding: .72rem .62rem .62rem;
    font-size: .64rem;
    letter-spacing: .12em;
    gap: .35rem;
    min-height: 42px;
  }
  .cat-btn .n {
    font-size: .54rem;
  }

  .kebab-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 1.15rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
  }
  .kebab-menu {
    min-width: 200px;
    top: calc(100% + 6px);
    right: 0;
    padding: .45rem;
    border-radius: 0;
  }
  .kebab-menu button {
    padding: .75rem .7rem; /* comfortable 44px touch targets */
    font-size: .66rem;
  }

  /* hero: small counter tile at the right side like desktop */
  .hero {
    padding: clamp(2rem, 6vw, 3rem) max(.9rem, var(--safe-left)) 1.6rem max(.9rem, var(--safe-right));
  }
  .hero-kicker {
    font-size: .6rem;
    letter-spacing: .24em;
    margin-bottom: .8rem;
  }
  .hero-kicker::before {
    width: 28px;
  }
  .hero h1 {
    font-size: clamp(2.3rem, 11.5vw, 3.8rem);
    line-height: .98;
  }
  .hero-row {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.4rem;
    flex-wrap: nowrap;
  }
  .hero-sub {
    font-size: .84rem;
    line-height: 1.5;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 440px;
  }
  .hero-stats {
    width: auto;
    flex: 0 0 auto;
    border: 1px solid var(--line);
    align-self: flex-end;
  }
  .hero-stat {
    padding: .5rem .85rem;
    text-align: left;
  }
  .hero-stat b {
    font-size: 1.45rem;
    line-height: 1;
    letter-spacing: .04em;
  }
  .hero-stat span {
    font-size: .52rem;
    letter-spacing: .15em;
    display: block;
    margin-top: .15rem;
  }

  /* shelves and header */
  .shelf {
    padding: 2.2rem max(.9rem, var(--safe-left)) 0 max(.9rem, var(--safe-right));
    scroll-margin-top: calc(var(--nav-h) + var(--safe-top) + 48px);
  }
  .shelf-head {
    flex-wrap: wrap;
    align-items: baseline;
    gap: .3rem .8rem;
    padding-bottom: .75rem;
    margin-bottom: 1.2rem;
  }
  .shelf-head h2 {
    font-size: clamp(1.6rem, 7vw, 2.2rem);
  }
  .shelf-count {
    width: 100%;
    font-size: .62rem;
    letter-spacing: .12em;
    margin-top: .15rem;
  }
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .85rem;
  }

  .meta {
    margin-top: .5rem;
    gap: .4rem;
  }
  .meta h3 {
    font-size: .82rem;
    line-height: 1.25;
  }
  .meta .yr {
    font-size: .64rem;
  }

  .parts-chip {
    top: 7px;
    left: 7px;
    font-size: .54rem;
    padding: .18rem .38rem;
    border-radius: 2px;
  }
  .more-chip {
    right: 7px;
    bottom: 28px;
    font-size: .56rem;
    padding: .15rem .35rem;
    border-radius: 2px;
  }
  .year-tag {
    top: 7px;
    right: 7px;
    font-size: .56rem;
    padding: .15rem .35rem;
    border-radius: 2px;
  }
  .idx {
    left: 7px;
    bottom: 6px;
    font-size: .58rem;
  }

  /* empty state */
  .empty {
    font-size: 1.05rem;
    padding: 2.5rem 1rem;
  }

  /* modal centered at the middle of the screen like desktop */
  .modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(.75rem, 3.5vw, 1.2rem);
  }
  .modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--backdrop);
    touch-action: none;
  }
  .modal-panel {
    position: relative;
    width: min(760px, 100%);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 0;
    box-shadow: 0 35px 80px -25px rgba(0,0,0,.9);
    animation: modalIn .25s cubic-bezier(.2,.7,.2,1);
  }

  .modal-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .85rem 1.1rem;
    border-bottom: 1px solid var(--line);
  }
  .modal-head h3 {
    font-family: var(--display);
    font-weight: 400;
    font-size: 1.15rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    flex: 1;
    min-width: 0;
    line-height: 1.2;
  }
  .modal-close {
    flex: none;
    background: none;
    border: 1px solid var(--line);
    color: var(--ink-dim);
    font-family: var(--mono);
    font-size: .62rem;
    letter-spacing: .12em;
    padding: .38rem .65rem;
    cursor: pointer;
    border-radius: 0;
    transition: color .2s, border-color .2s;
  }
  .modal-close:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
  }
  .modal-close-esc {
    display: none;
  }

  .modal-body {
    overflow-y: auto;
    padding: .6rem 1.1rem 1.4rem;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .part {
    grid-template-columns: 74px 1fr;
    gap: .85rem;
    padding: .85rem 0;
  }
  .part-info h4 {
    font-size: .92rem;
    gap: .45rem;
    line-height: 1.3;
  }
  .part-num {
    font-size: .62rem;
  }
  .part-line {
    flex-wrap: wrap;
    gap: .55rem;
    margin: .35rem 0 .45rem;
  }
  .rating {
    font-size: .72rem;
    padding: .16rem .45rem;
    touch-action: manipulation;
  }
  .rating i {
    font-size: .56rem;
  }
  .part-info p {
    font-size: .82rem;
    line-height: 1.55;
  }

  .series-brief {
    grid-template-columns: 88px 1fr;
    gap: .9rem;
    padding-bottom: .9rem;
  }
  .series-info h4 {
    font-size: 1rem;
  }
  .season-row {
    flex-wrap: wrap;
    gap: .5rem .8rem;
    padding: .75rem 0;
  }
  .season-name {
    font-size: .88rem;
    min-width: 110px;
  }
  .season-row .rating {
    margin-left: auto;
  }

  /* swap guide */
  .swap {
    padding: 2.2rem max(.9rem, var(--safe-left)) 2.6rem max(.9rem, var(--safe-right));
    gap: 1.4rem;
    margin-top: 3rem;
  }
  .swap h2 {
    font-size: 1.35rem;
  }
  .swap li {
    font-size: .84rem;
    gap: .8rem;
  }

  footer {
    padding: 1.4rem max(.9rem, var(--safe-left)) max(1.8rem, var(--safe-bottom)) max(.9rem, var(--safe-right));
    flex-direction: column;
    gap: .5rem;
    text-align: center;
    font-size: .58rem;
  }
}

/* very narrow phones (< 380px) */
@media (max-width: 380px) {
  .brand b { font-size: .92rem; letter-spacing: .08em; }
  .nav-search { padding: .32rem .45rem; }
  .grid { gap: .65rem; }
  .part { grid-template-columns: 66px 1fr; gap: .7rem; }
  .series-brief { grid-template-columns: 78px 1fr; gap: .75rem; }
}
