/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #faf9f7;
  --bg-elev: #ffffff;
  --fg: #1a1a1a;
  --fg-muted: #6f6b66;
  --line: #e7e3de;
  --accent: #1a1a1a;
  --pill-bg: rgba(0, 0, 0, 0.05);
  --pill-active-bg: #1a1a1a;
  --pill-active-fg: #faf9f7;
  --tile-bg: #ecE9e4;
  --nav-bg: rgba(250, 249, 247, 0.82);
  --lb-bg: #0b0b0c;
  --lb-fg: #f2f2f2;
  --lb-muted: #9a9a9a;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --gap: 4px;
  --row: 240px;
  --pad: clamp(16px, 4vw, 48px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111112;
    --bg-elev: #19191b;
    --fg: #ececea;
    --fg-muted: #9b9895;
    --line: #2a2a2d;
    --accent: #ececea;
    --pill-bg: rgba(255, 255, 255, 0.07);
    --pill-active-bg: #ececea;
    --pill-active-fg: #111112;
    --tile-bg: #1f1f22;
    --nav-bg: rgba(17, 17, 18, 0.8);
  }
}
:root[data-theme="dark"] {
  --bg: #111112;
  --bg-elev: #19191b;
  --fg: #ececea;
  --fg-muted: #9b9895;
  --line: #2a2a2d;
  --accent: #ececea;
  --pill-bg: rgba(255, 255, 255, 0.07);
  --pill-active-bg: #ececea;
  --pill-active-fg: #111112;
  --tile-bg: #1f1f22;
  --nav-bg: rgba(17, 17, 18, 0.8);
}
@media (max-width: 900px) { :root { --row: 180px; } }
@media (max-width: 560px) { :root { --row: 130px; --gap: 3px; } }

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.muted { color: var(--fg-muted); }
.meta { color: var(--fg-muted); font-size: 13px; }

/* ---------------------------------------------------------------- home */
.home-hero { padding: clamp(48px, 10vh, 120px) var(--pad) 24px; max-width: 1200px; margin: 0 auto; }
.home-title { font-family: var(--font-display); font-weight: 400; font-size: clamp(40px, 7vw, 72px); margin: 0 0 8px; letter-spacing: -0.01em; }
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 32px;
  padding: 16px var(--pad) 96px;
  max-width: 1200px;
  margin: 0 auto;
}
.card { display: block; }
.card-media { aspect-ratio: 4 / 3; overflow: hidden; border-radius: 6px; background: var(--tile-bg); }
.card-media img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1); }
.card:hover .card-media img { transform: scale(1.03); }
.card-body { padding: 14px 2px 0; }
.card-body h2 { font-family: var(--font-display); font-weight: 400; font-size: 28px; margin: 0 0 2px; }
.card-body p { margin: 0; }

/* ---------------------------------------------------------------- album hero */
.album-hero { padding: clamp(40px, 8vh, 96px) var(--pad) 40px; max-width: 1100px; margin: 0 auto; }
.back { display: inline-block; color: var(--fg-muted); font-size: 13px; margin-bottom: 28px; }
.back:hover { color: var(--fg); }
.album-title { font-family: var(--font-display); font-weight: 400; font-size: clamp(44px, 8vw, 88px); line-height: 1; margin: 0 0 12px; letter-spacing: -0.01em; }
.album-subtitle { font-size: 17px; color: var(--fg-muted); margin: 0 0 4px; }
.album-meta { font-size: 13px; color: var(--fg-muted); margin: 0; }

/* ---------------------------------------------------------------- chapter nav */
.chapter-nav {
  position: sticky; top: 0; z-index: 20;
  background: var(--nav-bg);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.chapter-nav-inner {
  display: flex; align-items: center; gap: 16px;
  padding: 10px var(--pad);
  max-width: 1400px; margin: 0 auto;
}
.chapter-nav-title { font-family: var(--font-display); font-size: 20px; white-space: nowrap; opacity: 0; transition: opacity 0.25s; }
.chapter-nav.scrolled .chapter-nav-title { opacity: 1; }
.chapter-pills { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; -webkit-overflow-scrolling: touch; }
.chapter-pills::-webkit-scrollbar { display: none; }
.pill {
  flex: none;
  padding: 6px 12px; border-radius: 999px;
  background: var(--pill-bg); font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.pill:hover { background: var(--line); }
.pill.active { background: var(--pill-active-bg); color: var(--pill-active-fg); }
.nav-tools { display: flex; gap: 6px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 999px;
  font-size: 15px; font-weight: 500; line-height: 1;
  background: var(--pill-bg);
}
.icon-btn:hover { background: var(--line); }

/* ---------------------------------------------------------------- gallery */
.gallery { padding: 8px 0 80px; }
.chapter { padding-top: 48px; scroll-margin-top: 56px; }
.chapter-heading { padding: 0 var(--pad); margin: 0 0 8px; }
.chapter-heading h2 { font-family: var(--font-display); font-weight: 400; font-size: clamp(32px, 4.5vw, 48px); margin: 0; line-height: 1.1; }
.chapter-heading .meta { margin: 2px 0 0; }
.day { padding-top: 28px; scroll-margin-top: 56px; }
.day-heading { padding: 0 var(--pad); margin: 0 0 10px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.day-heading h3 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
.day-heading .places { color: var(--fg-muted); font-size: 13px; }
.day-heading .count { color: var(--fg-muted); font-size: 12px; margin-left: auto; }

/* justified grid using flex-grow = aspect ratio */
.grid { display: flex; flex-wrap: wrap; gap: var(--gap); padding: 0 var(--gap); }
.grid::after { content: ""; flex-grow: 1000000; }
.tile {
  position: relative; display: block; overflow: hidden;
  background: var(--tile-bg);
  height: var(--row);
  flex-grow: calc(var(--ar) * 100);
  width: calc(var(--row) * var(--ar));
  border-radius: 2px;
}
.tile img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.2, 0.7, 0.2, 1); }
.tile img.loaded { opacity: 1; }
.tile:hover img { transform: scale(1.025); }
.tile-live { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.tile.playing .tile-live { opacity: 1; }
.tile.playing .badge.live { background: rgba(255, 255, 255, 0.85); color: #000; }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.badge {
  position: absolute; top: 8px; left: 8px;
  padding: 3px 7px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  /* no backdrop-filter here: hundreds of blurred layers stall the compositor */
}
.badge.dur { left: auto; right: 8px; top: auto; bottom: 8px; letter-spacing: 0; font-weight: 500; font-size: 11px; }
.badge.live { display: none; }
.badge.live::before { content: "◎ "; }
.tile:hover .badge.live, .tile:focus-visible .badge.live, .tile.playing .badge.live { display: block; }

.album-footer { padding: 24px var(--pad) 64px; color: var(--fg-muted); font-size: 13px; text-align: center; }

/* ---------------------------------------------------------------- lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: var(--lb-bg); color: var(--lb-fg);
  user-select: none; -webkit-user-select: none;
  touch-action: pan-y;
}
.lightbox[hidden] { display: none; }
.lb-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.lb-img, .lb-video {
  max-width: 100vw; max-height: 100vh;
  max-width: 100dvw; max-height: 100dvh;
  object-fit: contain;
  transition: opacity 0.18s ease;
}
.lb-video { position: absolute; inset: 0; margin: auto; }
.lb-video.live-overlay { inset: auto; margin: 0; object-fit: cover; max-width: none; max-height: none; }
.lb-arrow {
  position: absolute; top: 0; bottom: 0; width: 18vw; max-width: 140px; min-width: 56px;
  color: transparent; font-size: 48px; font-weight: 300;
  transition: color 0.2s;
}
.lb-prev { left: 0; text-align: left; padding-left: 20px; }
.lb-next { right: 0; text-align: right; padding-right: 20px; }
.lightbox:hover .lb-arrow, .lb-arrow:focus-visible { color: rgba(255, 255, 255, 0.55); }
.lb-arrow:hover { color: #fff !important; }
@media (hover: none) { .lb-arrow { color: transparent !important; } }

.lb-play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 84px; height: 84px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 30px; padding-left: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: transform 0.15s, background 0.15s;
}
.lb-play:hover { background: rgba(0, 0, 0, 0.75); transform: translate(-50%, -50%) scale(1.06); }
.lb-top, .lb-bottom {
  position: absolute; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  transition: opacity 0.25s;
}
.lb-top { top: 0; background: linear-gradient(rgba(0, 0, 0, 0.5), transparent); }
.lb-bottom { bottom: 0; flex-direction: column; align-items: flex-start; gap: 2px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55)); pointer-events: none; }
.lightbox.chrome-hidden .lb-top, .lightbox.chrome-hidden .lb-bottom { opacity: 0; }
.lb-counter { font-size: 13px; color: var(--lb-muted); font-variant-numeric: tabular-nums; }
.lb-actions { display: flex; gap: 8px; }
.lb-actions .icon-btn { background: rgba(255, 255, 255, 0.12); color: #fff; }
.lb-actions .icon-btn:hover { background: rgba(255, 255, 255, 0.24); }
.lb-live { width: auto; padding: 0 12px; font-size: 11px; letter-spacing: 0.1em; }
.lb-live.playing { background: #fff !important; color: #000; }
.lb-caption { font-size: 16px; }
.lb-caption:empty { display: none; }
.lb-meta { font-size: 13px; color: var(--lb-muted); }
.lb-info { position: absolute; right: 18px; top: 64px; background: rgba(20, 20, 22, 0.92); color: var(--lb-fg);
  border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 10px; padding: 14px 16px; font-size: 13px; line-height: 1.7;
  min-width: 220px; max-width: min(360px, calc(100vw - 36px)); }
.lb-info[hidden] { display: none; }
.lb-info b { color: var(--lb-muted); font-weight: 500; display: inline-block; width: 64px; }
.lb-info a { color: var(--lb-fg); text-decoration: underline; text-underline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}
