/* 不二推理館 劇本索引
   Layout: a dark dossier wall. Sticky toolbar with search + filters, a poster grid or a
   compact 卷宗 index list, and a dialog for each play. Single committed dark theme. */
:root {
  color-scheme: dark;
  --bg: #0c0a0b;
  --bg-2: #151113;
  --bg-3: #1f1a1c;
  --ink: #f4ede4;
  --ink-2: #c0b4ab;
  --ink-3: #8a7f79;
  --line: rgba(244, 237, 228, 0.1);
  --line-2: rgba(244, 237, 228, 0.2);
  --seal: #d8262c;
  --seal-2: #a9181f;
  --seal-soft: rgba(216, 38, 44, 0.16);
  --gold: #c8a46a;
  --font-display: 'Noto Serif TC', 'Songti TC', 'PMingLiU', 'Noto Serif CJK TC', serif;
  --font-body: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', 'Noto Sans CJK TC', sans-serif;
  --font-mono: 'DM Mono', 'Noto Sans TC', ui-monospace, 'SF Mono', Menlo, monospace;
  --radius: 6px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  --maxw: 1480px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --toolbar-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--toolbar-h) + 16px); }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
img { max-width: 100%; display: block; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--seal); outline-offset: 3px; }
[hidden]:not(.card) { display: none !important; }
/* Cards hide without !important so Flip can keep a leaving card on screen while it fades out. */
.card[hidden] { display: none; }

.skip {
  position: absolute; left: var(--gutter-l); top: -48px; z-index: 50;
  padding: 8px 14px; background: var(--seal); color: #fff; border-radius: var(--radius);
}
.skip:focus { top: 8px; }

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  z-index: 1;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: radial-gradient(120% 90% at 85% 0%, rgba(216, 38, 44, 0.14), transparent 55%), var(--bg);
}
.hero-bg {
  position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  opacity: 0.22;
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 25%, #000 75%, transparent 100%), linear-gradient(90deg, transparent, #000 30%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(180deg, transparent 0%, #000 25%, #000 75%, transparent 100%);
}
.hero-strip {
  position: absolute; left: 35%; right: -10%; display: flex; gap: 14px;
  width: max-content; will-change: transform;
  padding-right: 14px; /* one trailing gap, so the two copies are exactly half the width and the -50% loop has no seam */
  animation: drift 90s linear infinite;
}
.hero-bg.offscreen .hero-strip { animation-play-state: paused; }
.hero-bg.paused .hero-strip, .hero-bg.offscreen .hero-strip { will-change: auto;
}
.hero-strip img { width: 120px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 3px; filter: saturate(0.6) contrast(0.95); }
.hero-strip--a { top: -40px; }
.hero-strip--b { top: 170px; animation-duration: 120s; animation-direction: reverse; }
@keyframes drift { to { transform: translateX(-50%); } }

.hero-inner {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px 28px;
  padding-block: 28px 44px;
  align-items: start;
}
.brand { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; }
.brand-logo { width: 54px; height: 81px; object-fit: cover; border-radius: 3px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; letter-spacing: 0.08em; }
.brand-latin { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.3em; color: var(--ink-3); margin-top: 6px; }

.spine {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: var(--font-display);
  font-size: 0.9rem;
  letter-spacing: 0.3em;
  color: #fff;
  background: var(--seal);
  padding: 14px 7px;
  border-radius: 2px;
  align-self: stretch;
  min-height: 190px;
  box-shadow: 0 10px 30px rgba(216, 38, 44, 0.25);
}
.hero-main { min-width: 0; position: relative; }
.hero-eyebrow { font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.28em; color: var(--ink-3); margin: 6px 0 10px; }
.hero-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(3.4rem, 10vw, 7.5rem);
  line-height: 1;
  letter-spacing: 0.04em;
  display: flex;
  flex-wrap: wrap;
  text-wrap: balance;
}
.hero-title .mask { display: inline-block; overflow: hidden; padding-bottom: 0.08em; }
.hero-title .char { display: inline-block; }
.hero-sub {
  margin: 18px 0 0;
  max-width: 34em;
  color: var(--ink-2);
  font-size: 1rem;
}
.hero-sub .count { font-family: var(--font-mono); font-size: 1.25em; color: var(--ink); font-variant-numeric: tabular-nums; }
.hero-seal {
  position: absolute; right: 0; top: 0;
  width: clamp(96px, 14vw, 150px); height: auto;
  transform: rotate(-8deg);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.5));
  pointer-events: none;
}
.hero-stats {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: 8px 22px;
  margin-top: 8px;
  font-family: var(--font-mono); font-size: 0.78rem; letter-spacing: 0.06em; color: var(--ink-3);
}
.hero-stats b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: rgba(12, 10, 11, 0.82);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.toolbar-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  min-height: var(--toolbar-h);
  padding-block: 10px;
}
.search {
  flex: 1 1 260px;
  display: flex; align-items: center; gap: 10px;
  min-width: 0;
  padding: 0 14px;
  height: 44px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search:focus-within { border-color: var(--seal); box-shadow: 0 0 0 4px var(--seal-soft); }
.search svg { width: 18px; height: 18px; flex: none; color: var(--ink-3); }
.search input {
  flex: 1; min-width: 0; height: 100%;
  background: transparent; border: 0; outline: 0;
  font-size: 1rem;
}
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-clear { background: none; border: 0; color: var(--ink-3); padding: 5px; min-width: 28px; min-height: 28px; display: grid; place-items: center; border-radius: 50%; }
.search-kbd { display: none; font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-3); border: 1px solid var(--line-2); border-radius: 5px; padding: 1px 6px; line-height: 1.4; flex: none; }
@media (min-width: 900px) and (hover: hover) { .search-kbd { display: inline-block; } .search:focus-within .search-kbd { display: none; } }
.search-clear:hover { color: var(--ink); }

.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 999px; padding: 3px; }
.seg button {
  background: transparent; border: 0; color: var(--ink-2);
  padding: 8px 14px; min-height: 38px; border-radius: 999px;
  font-size: 0.88rem; letter-spacing: 0.04em;
  transition: background 0.25s var(--ease-out), color 0.2s;
}
.seg button[aria-selected="true"] { background: var(--ink); color: var(--bg); }

.select {
  position: relative; display: inline-flex; align-items: center;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 999px;
  height: 44px; padding: 0 14px 0 14px;
}
.select select {
  appearance: none; -webkit-appearance: none;
  background: transparent; border: 0; outline: 0; color: var(--ink-2);
  padding-right: 22px; font-size: 0.88rem; cursor: pointer;
}
.select svg { position: absolute; right: 12px; width: 14px; height: 14px; color: var(--ink-3); pointer-events: none; }
.select:focus-within { border-color: var(--seal); box-shadow: 0 0 0 4px var(--seal-soft); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 16px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 999px;
  color: var(--ink-2); font-size: 0.88rem; letter-spacing: 0.04em;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.btn:hover { border-color: var(--ink-3); color: var(--ink); }
.btn[aria-expanded="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn .badge {
  font-family: var(--font-mono); font-size: 0.72rem;
  background: var(--seal); color: #fff; border-radius: 999px;
  min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center;
}
.btn[aria-expanded="true"] .badge { background: var(--seal); }
.btn svg { width: 16px; height: 16px; }
.btn--ghost { background: transparent; border-color: transparent; height: 36px; padding: 0 10px; }
.btn--ghost:hover { border-color: var(--line-2); }

/* Filters panel: grid-rows trick for a smooth expand; it lives below the sticky bar so it scrolls away */
.filters-wrap { position: relative; z-index: 1; }
.filters { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.45s var(--ease-out); }
.filters.open { grid-template-rows: 1fr; }
.filters > .filters-inner { overflow: hidden; min-height: 0; visibility: hidden; transition: visibility 0s linear 0.45s; padding-inline: 6px; margin-inline: -6px; }
.filters.open > .filters-inner { border-bottom: 1px solid var(--line); visibility: visible; transition-delay: 0s; }
.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px 28px;
  padding-block: 18px 18px;
}
.filters fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.filters legend {
  font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.26em;
  color: var(--ink-3); margin-bottom: 8px; padding: 0;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 11px 0 11px;
  background: transparent; border: 1px solid var(--line-2); border-radius: 999px;
  color: var(--ink-2); font-size: 0.84rem;
  transition: border-color 0.2s, background 0.25s var(--ease-out), color 0.2s, transform 0.2s var(--ease-out);
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip:active { transform: scale(0.97); }
.chip[aria-pressed="true"], .chip--on { background: var(--seal); border-color: var(--seal); color: #fff; }
.chip[aria-pressed="true"] .chip-count { color: #fff; }
.chip[disabled] { opacity: 0.35; cursor: not-allowed; }
.chip-count { font-family: var(--font-mono); font-size: 0.75rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.chip--seal img { width: 22px; height: 22px; border-radius: 50%; }
.filters-foot { display: flex; justify-content: flex-end; padding-bottom: 14px; }

/* ---------- Results bar ---------- */
.results {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  padding-block: 18px 10px;
  font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: 0.06em; color: var(--ink-3);
}
.results b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.active-filters .chip { min-height: 28px; font-size: 0.76rem; padding: 0 9px; }
.active-filters .chip svg { width: 12px; height: 12px; }

/* ---------- Poster grid ---------- */
.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 26px 18px;
  padding-block: 10px 60px;
}
@media (min-width: 900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 32px 22px; } }
@media (min-width: 1400px) { .grid { grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); } }

.card { position: relative; min-width: 0; }
.grid.reveal-armed > .card:not([data-revealed]) { opacity: 0; }
.card-link { display: block; text-decoration: none; color: inherit; border-radius: var(--radius); }
.card-link:focus-visible { outline-offset: 6px; }
.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  max-width: 100%;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--bg-3);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  transition: transform 0.45s var(--ease-out), box-shadow 0.45s var(--ease-out);
  isolation: isolate; /* keeps the rounded corners clipping the scaled image in Safari without a compositor layer */
}
/* Child combinator: these rules are for the poster image only, never the seal images inside .poster > .seals. */
.poster > img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 0.6s var(--ease-out), opacity 0.4s;
  opacity: 0;
}
.poster > img.loaded { opacity: 1; }
.poster--missing > img, .poster--missing > img.loaded { object-fit: contain; padding: 18%; opacity: 0.45; filter: grayscale(1); }
.poster--missing::after {
  content: '海報待補';
  position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.3em; color: var(--ink-2);
}
.poster-shade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 45%, rgba(8, 6, 7, 0.92) 100%);
  opacity: 0; transition: opacity 0.35s;
}
.poster-excerpt {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 14px 12px 12px;
  font-size: 0.78rem; line-height: 1.55; color: var(--ink-2);
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
  content-visibility: hidden; /* shaped only on hover: saves ~2.7 MB of CJK font slices per cold load */
  opacity: 0; transform: translateY(10px);
  transition: opacity 0.35s var(--ease-out), transform 0.45s var(--ease-out), content-visibility 0.35s allow-discrete;
}
.seals {
  position: absolute; top: 8px; left: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.seal {
  width: 34px; height: 34px; border-radius: 50%;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6));
  transition: transform 0.3s var(--ease-out);
}
.card-body { padding: 10px 2px 0; }
.card-num { font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.2em; color: var(--ink-3); }
.card-title {
  margin: 2px 0 4px;
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.02rem; line-height: 1.3; letter-spacing: 0.02em;
  text-wrap: balance;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta {
  margin: 0; display: flex; flex-wrap: wrap; gap: 2px 10px;
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-2); letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.card-tags { margin: 4px 0 0; font-size: 0.78rem; color: var(--ink-3); letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (hover: hover) {
  .card:hover .poster { transform: translateY(-6px); box-shadow: 0 22px 44px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(216, 38, 44, 0.35); }
  .card:hover .poster > img { transform: scale(1.06); }
  .card:hover .poster-shade, .card:hover .poster-excerpt { opacity: 1; }
  .card:hover .poster-excerpt { transform: translateY(0); content-visibility: visible; }
  .card:hover .seal { transform: rotate(-10deg) scale(1.08); }
}

/* ---------- Index list ---------- */
.index { padding-block: 10px 60px; }
.index-head, .row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 150px 110px 120px;
  gap: 14px; align-items: center;
}
.index-head {
  padding: 8px 12px;
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.24em; color: var(--ink-3);
  border-bottom: 1px solid var(--line-2);
}
.row {
  padding: 12px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit;
  transition: background 0.2s;
}
.row:hover, .row:focus-visible { background: var(--bg-2); }
.row:hover .row-title { color: #fff; }
.row-num { font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.18em; color: var(--ink-3); }
.row-main { min-width: 0; display: flex; flex-direction: column; }
.row-title { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; line-height: 1.3; transition: color 0.2s; }
.row-genres { font-size: 0.78rem; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.row-seals { display: flex; gap: 4px; flex-wrap: wrap; }
.row-seals .seal { width: 26px; height: 26px; filter: none; }
.row-thumb {
  display: none;
}
@media (max-width: 760px) {
  .index-head { display: none; }
  .row { grid-template-columns: 56px minmax(0, 1fr); grid-template-rows: auto auto; gap: 2px 12px; padding: 12px 6px; }
  .row-num { grid-row: 1 / span 2; align-self: start; padding-top: 4px; }
  .row-meta { grid-column: 2; }
  .row-seals { grid-column: 2; margin-top: 4px; }
}

.empty {
  text-align: center; padding: 70px 0 90px;
  color: var(--ink-3); font-family: var(--font-display); font-size: 1.1rem;
}
.empty .btn { margin-top: 18px; }

/* ---------- Detail overlay (卷宗) ---------- */
.detail {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: 16px;
}
.detail-backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 4, 4, 0.8);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.detail-ghost {
  position: absolute; z-index: 3; pointer-events: none;
  object-fit: cover; border-radius: var(--radius);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.no-scroll { overflow: hidden; }
.detail-card {
  position: relative;
  width: min(1040px, 100%);
  max-height: min(92vh, 100%);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--bg-2);
  overflow: hidden;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.7);
  display: grid;
  grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr); /* clamps to max-height, so .detail-body scrolls instead of being clipped */
}
.detail-card:empty { display: none; }
.detail-poster {
  position: relative;
  background: var(--bg);
  display: grid; align-items: start;
  min-height: 0; overflow: hidden;
}
/* width/height attributes carry each poster's real size, so the box is reserved before the image arrives and nothing is cropped. */
.detail-poster img {
  display: block; width: 100%; height: auto; object-fit: cover;
  background-size: cover; background-position: center;
}
.detail-poster--missing img { object-fit: contain; padding: 22%; opacity: 0.4; filter: grayscale(1); }
.detail-body {
  min-width: 0;
  overflow-y: auto;
  padding: 28px 30px 30px;
  display: flex; flex-direction: column; gap: 16px;
}
.detail-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-num { font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.26em; color: var(--ink-3); }
.detail-title {
  margin: 4px 0 0;
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(1.6rem, 3.4vw, 2.3rem); line-height: 1.2; letter-spacing: 0.02em; text-wrap: balance;
}
.detail-close {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--ink-2);
  display: grid; place-items: center;
  transition: background 0.2s, color 0.2s, transform 0.3s var(--ease-out);
}
.detail-close:hover { background: var(--ink); color: var(--bg); transform: rotate(90deg); }
.detail-close svg { width: 16px; height: 16px; }
.detail-seals { display: flex; flex-wrap: wrap; gap: 10px; }
.detail-seals figure { margin: 0; display: flex; align-items: center; gap: 8px; }
.detail-seals .seal { width: 44px; height: 44px; filter: none; }
.detail-seals figcaption { font-size: 0.8rem; color: var(--ink-2); }
.facts {
  margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px;
  padding: 14px 16px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
}
.facts dt { font-family: var(--font-mono); font-size: 0.78rem; letter-spacing: 0.22em; color: var(--ink-3); padding-top: 3px; }
.facts dd { margin: 0; font-size: 0.95rem; }
.facts dd .muted { color: var(--ink-3); }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 0.78rem; padding: 3px 9px; border-radius: 999px; background: var(--seal-soft); color: #f0a7aa; border: 1px solid rgba(216, 38, 44, 0.3); }
.tag--plain { background: var(--bg-3); color: var(--ink-2); border-color: var(--line-2); }
.synopsis { font-size: 0.98rem; line-height: 1.85; color: var(--ink); }
.synopsis p { margin: 0 0 1em; text-wrap: pretty; }
.synopsis p:last-child { margin-bottom: 0; }
.synopsis-empty { color: var(--ink-3); font-style: normal; }
.detail-section h3 {
  margin: 0 0 8px; font-family: var(--font-mono); font-weight: 500;
  font-size: 0.78rem; letter-spacing: 0.26em; color: var(--ink-3);
}
.detail-section ul { margin: 0; padding-left: 1.2em; color: var(--ink-2); font-size: 0.92rem; }
.detail-section li + li { margin-top: 4px; }
.store-note { border-left: 3px solid var(--seal); padding: 10px 14px; background: var(--seal-soft); border-radius: 0 var(--radius) var(--radius) 0; }
.detail-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.detail-nav .btn { height: 40px; }
.detail-nav .btn svg { width: 14px; height: 14px; }
.detail-nav .btn span { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Phone dossier, also used on landscape phones and short windows where two columns would hide the close button. */
@media (max-width: 760px), (max-height: 500px) {
  .detail { padding: 0; }
  .detail-card { width: 100%; max-height: none; height: 100%; border-radius: 0; border: 0; overflow-y: auto; display: block; }
  .detail-card:empty { display: none; }
  .detail-poster { justify-items: center; }
  .detail-poster img { width: min(100%, calc(75vh * var(--ar, 0.6717))); max-height: 75vh; }
  .detail-nav .btn { flex: 1 1 0; min-width: 0; justify-content: center; }
  .detail-nav .btn span { max-width: none; }
  .detail-body { overflow: visible; padding: 20px var(--gutter-r) calc(24px + env(safe-area-inset-bottom, 0px)) var(--gutter-l); }
  .detail-close { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); z-index: 2; background: rgba(12, 10, 11, 0.75); }
}

/* ---------- Footer / misc ---------- */
.footer {
  position: relative; z-index: 1;
  border-top: 1px solid var(--line);
  padding-block: 28px 40px;
  color: var(--ink-3); font-size: 0.82rem;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 24px;
}
.footer b { color: var(--ink-2); font-weight: 500; }
.footer .mono { font-family: var(--font-mono); letter-spacing: 0.08em; }
.to-top {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 15;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--ink); color: var(--bg); border: 0;
  display: grid; place-items: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  opacity: 0; transform: translateY(12px); pointer-events: none; visibility: hidden;
  transition: opacity 0.3s, transform 0.4s var(--ease-out), visibility 0s 0.3s;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; visibility: visible; transition-delay: 0s; }
.to-top svg { width: 18px; height: 18px; }
main { position: relative; z-index: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 640px) {
  .hero-inner { grid-template-columns: auto 1fr; gap: 16px; padding-block: 20px 30px; }
  .spine { min-height: 150px; font-size: 0.8rem; }
  .hero-seal { width: 80px; top: auto; bottom: -16px; right: -6px; }
  .hero-sub { font-size: 0.92rem; padding-right: 84px; }
  .toolbar-row { gap: 8px; padding-block: 8px; }
  .toolbar-row .search { height: 42px; flex-basis: 100%; }
  .toolbar-row .select { height: 40px; padding: 0 10px; flex: 1 1 0; min-width: 0; } /* basis 0: wrapping is decided before shrinking */
  .toolbar-row .select select { font-size: 0.82rem; padding-right: 18px; width: 100%; min-width: 0; text-overflow: ellipsis; }
  .toolbar-row .select svg { right: 8px; }
  .toolbar-row .seg button { padding: 8px 11px; }
  .toolbar-row .btn { padding: 0 13px; }
}

/* Pause control for the drifting poster strips (WCAG 2.2.2): the strips are decorative, so pausing costs nothing. */
.hero-bg.paused .hero-strip { animation-play-state: paused; }
.motion-toggle {
  position: absolute; right: 0; bottom: 0; z-index: 2;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(12, 10, 11, 0.55); color: var(--ink-3); border: 1px solid var(--line-2);
  display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(6px);
}
.motion-toggle:hover { color: var(--ink); border-color: var(--ink-3); }
.motion-toggle svg { width: 14px; height: 14px; grid-area: 1 / 1; }
.motion-toggle .icon-play, .motion-toggle.paused .icon-pause { display: none; }
.motion-toggle.paused .icon-play { display: block; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .motion-toggle { display: none; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; transition-delay: 0s !important; }
  .hero-strip { animation: none; }
}

/* Phones: always two poster columns so the wall still reads as a wall at 320–480px. */
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 12px; }
}

@media (min-width: 900px) {
  .filters-grid fieldset:nth-child(2) { grid-column: span 2; }
}

@media (max-width: 380px) {
  .toolbar-row .btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .toolbar-row .btn { padding: 0 12px; }
}

/* Printing the list for the counter: dark ink on white, no chrome. */
@media print {
  :root { color-scheme: light; }
  body { background: #fff !important; color: #000 !important; }
  body::before, .hero-bg, .hero-seal, .motion-toggle, .toolbar, .filters-wrap, .to-top, .skip, .poster-excerpt, .poster-shade { display: none !important; }
  body:not(.no-scroll) .detail { display: none !important; }
  body.no-scroll > :not(.detail) { display: none !important; }
  body.no-scroll .detail { position: static; padding: 0; }
  body.no-scroll .detail-backdrop, body.no-scroll .detail-close, body.no-scroll .detail-nav, body.no-scroll .detail-ghost { display: none !important; }
  body.no-scroll .detail-card { display: block; max-height: none; height: auto; overflow: visible; background: #fff; color: #000; border: 0; box-shadow: none; opacity: 1 !important; transform: none !important; }
  body.no-scroll .detail-body { overflow: visible; }
  body.no-scroll .detail-poster img { width: 50%; max-height: none; }
  body.no-scroll .facts, body.no-scroll .store-note { background: #fff; }
  body.no-scroll .synopsis, body.no-scroll .facts dd, body.no-scroll .detail-title { color: #000 !important; }
  .hero { min-height: 0; padding-block: 0 12px; }
  .card-title, .row-title, .hero-title, .brand-name, .results b { color: #000 !important; }
  .card-meta, .card-tags, .card-num, .row-meta, .row-genres, .row-num, .hero-sub, .footer { color: #333 !important; }
  .poster { box-shadow: none; }
  .card, .row { break-inside: avoid; }
  .grid > .card { opacity: 1 !important; transform: none !important; }
}
