/* ─────────────────────────────────────────────────────────────
   Classic theme — clean & mobile-first.
   Color tokens live in palettes.css; layout lives here.
   ───────────────────────────────────────────────────────────── */

:root {
  /* Layout */
  --gap: 12px;
  --gap-lg: 16px;
  --maxw: 920px;
  --radius: 10px;
  --radius-sm: 8px;
  --radius-pill: 999px;

  /* Type scale (fluid) */
  --fs-12: clamp(11px, 2.6vw, 12px);
  --fs-14: clamp(12px, 3.2vw, 14px);
  --fs-16: clamp(14px, 3.6vw, 16px);
  --fs-h1: clamp(20px, 4.8vw, 24px);

  /* Posters */
  --poster-w: clamp(88px, 28vw, 110px);
  --poster-w-lg: 130px;
  --poster-h: calc(var(--poster-w) * 1.5);
  --poster-h-lg: calc(var(--poster-w-lg) * 1.5);

  --z-topbar: 10;
  --z-fab: 20;

  /* Fonts */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-sans);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
button { font: inherit; color: inherit; }
a { color: inherit; }

/* ── top bar ───────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: "tabs" "utils";
  gap: var(--gap);
  padding: 10px var(--gap);
  padding-top: calc(env(safe-area-inset-top) + 8px);
}
.tabs {
  grid-area: tabs;
  display: flex; gap: 6px; align-items: center;
  overflow: auto hidden; scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.tabs::-webkit-scrollbar { height: 6px; }
.tabs::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-pill); }
.tabs button {
  border: 1px solid transparent; background: transparent; color: var(--fg);
  padding: 8px 14px; border-radius: var(--radius-pill); cursor: pointer;
  white-space: nowrap; font-size: var(--fs-14);
  transition: background .15s, border-color .15s;
}
.tabs button:hover { background: var(--chip); }
.tabs button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-fg); }

.utilities {
  grid-area: utils;
  display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center;
}
.icon-btn {
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 8px; cursor: pointer;
  transition: background .15s, border-color .15s;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--chip); border-color: var(--accent); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { width: 18px; height: 18px; fill: currentColor; display: block; }

.search { position: relative; }
.search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg); color: var(--fg);
  font-size: var(--fs-14);
  transition: border-color .15s, box-shadow .15s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search .sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

@media (min-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas: "tabs view utils";
    gap: var(--gap-lg);
    padding: 10px var(--gap-lg);
  }
  .utilities { display: flex; gap: 10px; align-items: center; justify-self: end; }
  .search input { width: clamp(180px, 28vw, 360px); }
}

.view-toggle { display: none; }
@media (min-width: 820px) {
  .view-toggle {
    grid-area: view; justify-self: center;
    display: inline-flex; gap: 4px; background: var(--chip);
    border-radius: var(--radius-pill); padding: 4px;
  }
  .view-toggle button {
    border: 0; background: transparent; color: var(--fg);
    padding: 6px 12px; border-radius: var(--radius-pill); cursor: pointer; font-size: var(--fs-14);
  }
  .view-toggle [aria-pressed="true"] { background: var(--bg); border: 1px solid var(--border); }
}

/* ── layout ───────────────────────────────────────────────── */
main { margin: 0 auto; max-width: var(--maxw); padding: var(--gap-lg) var(--gap); }
@media (min-width: 820px) { main { padding: 24px var(--gap-lg); } }
.tab { display: none; }
.tab.active { display: block; animation: fade-in .2s ease-out both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }

.section-head {
  display: flex; flex-direction: column; align-items: flex-start;
  gap: 12px; margin: 0 0 16px 0;
}
.section-head h1 {
  margin: 0;
  font-size: var(--fs-h1);
  font-weight: 700;
  letter-spacing: -0.02em;
}
@media (min-width: 640px) {
  .section-head { flex-direction: row; align-items: center; justify-content: space-between; }
}

.sort-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; width: 100%; }
@media (min-width: 640px) { .sort-controls { width: auto; } }

.sort-pills {
  display: inline-flex; gap: 4px; background: var(--chip);
  border-radius: var(--radius-pill); padding: 4px; max-width: 100%;
  overflow: auto hidden;
}
.sort-pills button {
  border: 0; background: transparent; color: var(--fg);
  padding: 6px 12px; border-radius: var(--radius-pill); cursor: pointer;
  white-space: nowrap; font-size: var(--fs-14);
}
.sort-pills [aria-pressed="true"] { background: var(--bg); border: 1px solid var(--border); }
.sort-extra { display: flex; align-items: center; gap: 8px; }
.sort-extra.hidden { display: none; }
.sort-extra label { font-size: var(--fs-12); color: var(--muted); }
.sort-extra select {
  padding: 6px 10px; border-radius: var(--radius-pill); border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font-size: var(--fs-14);
}

/* ── indices ──────────────────────────────────────────────── */
.index { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.index a {
  font-size: var(--fs-14); padding: 6px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  text-decoration: none; color: var(--fg); background: var(--chip);
  transition: background .12s, border-color .12s;
}
.index a:hover { background: var(--accent-soft); border-color: var(--accent); }

.index.az { display: block; column-width: clamp(220px, 48vw, 280px); column-gap: 12px; column-fill: balance; }
.index-group {
  break-inside: avoid; display: block; border: 1px dashed var(--border);
  border-radius: var(--radius-sm); padding: 8px; margin: 0 0 8px;
}
.index-group h4 { margin: 0 0 8px 0; font-size: var(--fs-12); color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.index-row { display: flex; flex-direction: column; gap: 4px; }

.index.grid-index { display: block; column-gap: 12px; column-fill: balance; }
@media (min-width: 900px) { .index.grid-index { column-count: 3; } }
@media (min-width: 640px) and (max-width: 899.98px) { .index.grid-index { column-count: 2; } }
@media (max-width: 639.98px) { .index.grid-index { column-count: 1; } }
.index.grid-index .index-group { break-inside: auto; margin: 0; }
.index.grid-index .index-row a { display: block; margin: 0; overflow-wrap: anywhere; }

/* ── people directory ────────────────────────────────────── */
.people-split { display: grid; grid-template-columns: 1fr; gap: 12px; width: 100%; margin-bottom: 20px; }
.people-pane {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; background: var(--chip);
  display: flex; flex-direction: column; gap: 8px;
}
.people-search input {
  width: 100%; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font-size: var(--fs-14);
}
.people-search input:focus { outline: none; border-color: var(--accent); }
.people-list {
  overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg);
  max-height: 40vh;
}
.person-btn {
  appearance: none;
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 8px 12px;
  background: transparent;
  border: 0; border-bottom: 1px solid var(--border); border-radius: 0;
  text-align: left; cursor: pointer; font-size: var(--fs-14);
}
.person-btn:hover { background: var(--chip); }
.person-btn:last-child { border-bottom: 0; }
.person-btn[aria-current="true"] { background: var(--accent-soft); font-weight: 600; }
.person-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.person-badge {
  font-size: var(--fs-12); color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 2px 8px;
}
.people-empty { padding: 12px; color: var(--muted); }

.people-results { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.people-results h4 { margin: 0 0 10px 0; color: var(--muted); font-size: var(--fs-12); letter-spacing: .04em; text-transform: uppercase; }
.people-results .index-row a { background: var(--chip); }

@media (min-width: 900px) {
  .people-split { grid-template-columns: 280px 1fr; align-items: start; }
  .people-pane { height: 60vh; }
  .people-list { max-height: none; flex: 1; min-height: 0; overflow: auto; }
}

/* ── reviews ─────────────────────────────────────────────── */
.reviews { display: grid; gap: 14px; }
.review {
  scroll-margin-top: 90px;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto;
  gap: 12px; align-items: start;
  background: var(--bg);
  transition: border-color .15s, transform .15s;
}
.review:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

.review .poster {
  grid-column: 1 / -1; width: 100%; max-width: clamp(180px, 60vw, 280px);
  height: auto; aspect-ratio: 2/3; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border); justify-self: center;
}
.review .poster-credits {
  grid-column: 1; grid-row: 2; font-size: var(--fs-12); color: var(--muted); line-height: 1.4;
}
.poster-credits .entry { margin-top: 8px; }
.poster-credits .entry:first-child { margin-top: 0; }
.poster-credits .label {
  font-weight: 600; display: block; margin-bottom: 3px;
  color: var(--fg); letter-spacing: .04em; text-transform: uppercase; font-size: 10px;
}
.poster-credits .names { display: block; }
.poster-credits .names .name { display: block; }

.review .content { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.review .review-head { display: grid; grid-template-columns: 1fr auto; align-items: start; column-gap: 10px; }
.review .review-head h3 {
  margin: 0; font-size: var(--fs-16); line-height: 1.3; font-weight: 600; letter-spacing: -0.01em;
}
.review p.body { margin: 0; white-space: pre-line; font-size: var(--fs-14); line-height: 1.55; color: var(--fg); }
.review .title { color: var(--fg); text-decoration: none; }
.review .title:hover { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.review .meta { color: var(--muted); font-size: var(--fs-12); white-space: nowrap; }

@media (max-width: 719.98px) {
  /* A review is a single reading column on phones. Keeping credits and body in
     two equal columns makes long reviews unreadably narrow. */
  .review { grid-template-columns: 1fr; grid-template-rows: auto; }
  .review .poster { grid-column: 1; grid-row: auto; }
  .review .poster-credits { grid-column: 1; grid-row: auto; }
  .review .content { grid-column: 1; grid-row: auto; }
  .review .review-head { grid-template-columns: minmax(0, 1fr); row-gap: 4px; }
  .review .meta { white-space: normal; overflow-wrap: anywhere; }
}

@media (min-width: 720px) {
  :root { --poster-w: var(--poster-w-lg); --poster-h: var(--poster-h-lg); }
  .review {
    grid-template-columns: var(--poster-w) 1fr;
    grid-template-rows: var(--poster-h) auto;
    column-gap: 14px; row-gap: 8px; min-height: calc(var(--poster-h) + 28px);
  }
  .review .poster {
    grid-column: 1; grid-row: 1; width: var(--poster-w); height: var(--poster-h);
    aspect-ratio: auto; justify-self: auto; max-width: none;
  }
  .review .poster-credits { grid-column: 1; grid-row: 2; }
  .review .content { grid-column: 2; grid-row: 1 / 3; }
}

.review:not(:has(.poster)) {
  grid-template-columns: 1fr; grid-template-rows: auto auto; min-height: auto;
}
.review:not(:has(.poster)) .content { grid-column: 1; grid-row: 1; }
.review--empty { text-align: center; color: var(--muted); }

/* ── footer + FAB ────────────────────────────────────────── */
footer { margin: 36px 0 16px; text-align: center; color: var(--muted); font-size: var(--fs-12); }

.to-top {
  position: fixed; right: clamp(10px, 3vw, 20px); bottom: clamp(10px, 3vw, 20px);
  width: 44px; height: 44px; border-radius: var(--radius-pill); border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transform: translateY(8px);
  transition: opacity .2s, transform .2s, background .2s; z-index: var(--z-fab);
}
.to-top:hover { background: var(--chip); border-color: var(--accent); }
.to-top.show { opacity: 1; pointer-events: auto; transform: translateY(0); }
