/* Mnemotheca — the field is Warburg's black cloth; each work is pinned to it
   with a small paper label carrying its number. */
:root {
  --cloth: #171615;      /* panel cloth */
  --cloth-2: #1f1d1b;    /* raised cloth (sheets) */
  --paper: #e8e2d4;      /* label paper */
  --ink: #d9d3c5;        /* text on cloth */
  --dim: #8a847a;        /* secondary text */
  --thread: #3a3631;     /* hairlines on cloth */
  --serif: "EB Garamond", "Iowan Old Style", Garamond, Georgia, serif;
  --ease: cubic-bezier(.2, .7, .1, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--cloth);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
  font-variant-numeric: oldstyle-nums;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
/* woven cloth grain */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 1;
  opacity: .22; mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 1px solid var(--paper); outline-offset: 4px; }
.smcp { font-variant-caps: all-small-caps; letter-spacing: .06em; }

/* ---------- loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; text-align: center;
  background: var(--cloth); transition: opacity .9s var(--ease), visibility .9s;
}
#loader.done { opacity: 0; visibility: hidden; }
.loader-name { margin: 0; font-size: clamp(40px, 8vw, 96px); font-style: italic; letter-spacing: -.01em; }
.loader-count { margin: .2em 0 0; color: var(--dim); font-variant-numeric: lining-nums tabular-nums; }

/* ---------- field ---------- */
#field {
  position: fixed; inset: 0; z-index: 0; overflow: hidden;
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
  outline: none;
}
#field.dragging { cursor: grabbing; }
#glcanvas { position: absolute; inset: 0; display: block; }
#world { position: absolute; inset: 0; }
/* in WebGL mode the canvas paints the images; the DOM keeps labels, hit areas and focus */
.gl .frame { background: transparent; box-shadow: none; }
.gl .frame img { visibility: hidden; }
/* labels fade out under the glass band at the window edges */
.gl #world {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 64px, #000 calc(100% - 64px), transparent), linear-gradient(transparent, #000 64px, #000 calc(100% - 64px), transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent, #000 64px, #000 calc(100% - 64px), transparent), linear-gradient(transparent, #000 64px, #000 calc(100% - 64px), transparent);
  mask-composite: intersect;
}

.tav {
  position: absolute; left: 0; top: 0; margin: 0;
  will-change: transform;
  transition: opacity .6s var(--ease), filter .6s var(--ease);
}
.tav.muted { opacity: .12; filter: grayscale(1); pointer-events: none; }
.frame {
  position: relative; display: block; width: 100%; height: 100%;
  background: #0c0b0b; overflow: hidden;
  box-shadow: 0 1px 0 rgba(0,0,0,.6), 0 18px 40px -18px rgba(0,0,0,.8);
}
.frame img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .8s var(--ease);
  pointer-events: none; -webkit-user-drag: none;
}
.frame img.in { opacity: 1; }

/* missing image: a blank paper slip with the title, as on an unfinished panel */
.frame.slip { background: var(--paper); color: #2a2723; display: grid; place-content: center; padding: 12%; text-align: center; }
.frame.slip span { font-style: italic; font-size: 15px; line-height: 1.25; }

.label {
  position: absolute; left: 0; top: 100%; margin-top: 8px;
  display: flex; gap: .55em; align-items: baseline; white-space: nowrap;
  font-size: 13px; line-height: 1.2; color: var(--dim);
  transition: color .3s;
}
.label b {
  font-weight: 400; color: #fff; font-variant-numeric: lining-nums tabular-nums; font-size: 13px;
}
.label i { font-style: italic; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; opacity: 0; transform: translateX(-4px); transition: opacity .35s var(--ease), transform .35s var(--ease); }
.tav:hover .label, .tav:focus-visible .label { color: var(--ink); }
.tav:hover .label i, .tav:focus-visible .label i { opacity: 1; transform: none; }
.tav:focus-visible { outline: none; }
.tav:focus-visible .frame { outline: 1px solid var(--paper); outline-offset: 5px; }

/* ---------- bars ---------- */
.bar {
  position: fixed; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 24px;
  padding: max(18px, env(safe-area-inset-top)) clamp(16px, 3vw, 36px) 18px;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.bar-top { top: 0; background: linear-gradient(var(--cloth) 10%, transparent); }
.bar-bottom { bottom: 0; align-items: flex-end; padding-top: 18px; padding-bottom: max(18px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(23,22,21,.85) 70%); }
.brand { font-size: 26px; font-style: italic; text-decoration: none; letter-spacing: -.005em; }
.nav { display: flex; gap: clamp(14px, 2.4vw, 30px); }
.nav button { color: var(--dim); font-size: 17px; transition: color .25s; position: relative; }
.nav button:hover, .nav button[aria-pressed="true"] { color: var(--ink); }
.nav button[aria-pressed="true"]::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 1px; height: 1px; background: currentColor;
}

.filters { display: flex; flex-wrap: wrap; gap: 4px 16px; max-width: 72vw; font-size: 15px; }
.filters button { color: var(--dim); transition: color .25s; }
.filters button sup { font-size: 10px; margin-left: 2px; font-variant-numeric: lining-nums; }
.filters button:hover { color: var(--ink); }
.filters button[aria-pressed="true"] { color: var(--paper); text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }

.sound { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 15px; }
.sound:hover, .sound[aria-pressed="true"] { color: var(--ink); }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 13px; }
.bars i { width: 2px; height: 3px; background: currentColor; }
.sound[aria-pressed="true"] .bars i { animation: bar 1.1s ease-in-out infinite alternate; }
.sound[aria-pressed="true"] .bars i:nth-child(2) { animation-delay: -.4s; animation-duration: .9s; }
.sound[aria-pressed="true"] .bars i:nth-child(3) { animation-delay: -.7s; animation-duration: 1.3s; }
.sound[aria-pressed="true"] .bars i:nth-child(4) { animation-delay: -.2s; animation-duration: 1s; }
@keyframes bar { from { height: 2px; } to { height: 13px; } }

.hint {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 15; margin: 0;
  padding: 6px 14px 5px; background: var(--paper); color: #23201c; font-size: 15px; font-style: italic;
  pointer-events: none; transition: opacity .8s var(--ease);
}
.hint.gone { opacity: 0; }

/* ---------- sheets (index, info) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto;
  background: rgba(23, 22, 21, .94); backdrop-filter: blur(6px);
  padding: 96px clamp(16px, 4vw, 48px) 120px;
  animation: sheet-in .5s var(--ease);
}
@keyframes sheet-in { from { opacity: 0; } }
#index-list { list-style: none; margin: 0 auto; padding: 0; max-width: 1100px; }
#index-list li { border-top: 1px solid var(--thread); }
#index-list li:last-child { border-bottom: 1px solid var(--thread); }
#index-list li[hidden] { display: none; }
.row {
  display: grid; grid-template-columns: 3.2em minmax(0, 1.4fr) minmax(0, 1fr) 6em 7em;
  gap: 18px; align-items: baseline; width: 100%; text-align: left; padding: 11px 0 9px;
  color: var(--dim); transition: color .2s, padding .3s var(--ease);
}
.row .t { color: var(--ink); font-style: italic; font-size: 21px; line-height: 1.2; }
.row .n { font-variant-numeric: lining-nums tabular-nums; font-size: 14px; }
.row .y { font-variant-numeric: lining-nums; }
.row:hover, .row:focus-visible { color: var(--ink); padding-left: 10px; }
#index-peek {
  position: fixed; z-index: 12; width: 260px; pointer-events: none; opacity: 0;
  transition: opacity .2s; left: 0; top: 0;
}
#index-peek.on { opacity: 1; }
#index-peek img { display: block; width: 100%; height: auto; max-height: 340px; object-fit: contain; box-shadow: 0 24px 60px -20px #000; }

.sheet-info { display: grid; place-items: center; cursor: zoom-out; }
.sheet-info .info-body { cursor: auto; }
#index { cursor: zoom-out; }
#index .row { cursor: pointer; }
.info-body { max-width: 34em; }
.info-body h1 { font-weight: 400; font-style: italic; font-size: clamp(44px, 7vw, 84px); line-height: 1; margin: 0 0 .3em; letter-spacing: -.01em; }
.info-body .lede { font-size: 24px; line-height: 1.35; color: var(--paper); }
.info-body p { margin: 0 0 1em; line-height: 1.6; }
.info-small { color: var(--dim); font-size: 14px; }
.info-links a { text-underline-offset: 4px; text-decoration-thickness: 1px; }

/* ---------- detail ---------- */
.detail {
  position: fixed; inset: 0; z-index: 30; display: grid; grid-template-columns: minmax(0, 1fr) 380px;
  background: #0f0e0d; animation: sheet-in .45s var(--ease);
}
.d-stage { position: relative; overflow: hidden; touch-action: pan-y; }
.d-track { position: absolute; inset: 0; display: flex; transition: transform .7s var(--ease); }
.d-slide { flex: 0 0 100%; display: grid; place-items: center; padding: clamp(24px, 5vw, 64px); }
.d-slide img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 30px 80px -30px #000; -webkit-user-drag: none; user-select: none; }
.d-slide .frame.slip { width: min(60%, 420px); aspect-ratio: 4/5; height: auto; }
.d-arrow { position: absolute; top: 50%; transform: translateY(-50%); font-size: 44px; line-height: 1; padding: 20px 18px; color: var(--dim); }
.d-arrow:hover { color: var(--paper); }
.d-prev { left: 4px; } .d-next { right: 4px; }
.d-arrow[hidden], .d-count[hidden] { display: none; }
.d-count { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center; margin: 0; color: var(--dim); font-size: 15px; font-variant-numeric: lining-nums tabular-nums; }
.d-card {
  position: relative; overflow-y: auto; background: var(--cloth-2); border-left: 1px solid var(--thread);
  padding: 72px 34px 34px; display: flex; flex-direction: column;
}
.d-close { position: absolute; top: 22px; right: 30px; color: var(--dim); font-size: 16px; }
.d-close:hover { color: var(--ink); }
.d-num { margin: 0 0 18px; }
.d-num { color: #fff; font-variant-numeric: lining-nums; font-size: 15px; }
.d-card h2 { font-weight: 400; font-style: italic; font-size: 34px; line-height: 1.1; margin: 0 0 .35em; overflow-wrap: anywhere; }
.d-author { margin: 0; font-size: 20px; color: var(--paper); }
.d-meta { margin: .2em 0 1.6em; color: var(--dim); font-size: 16px; }
.d-text { font-size: 18px; line-height: 1.6; color: var(--ink); max-width: 34em; }
.d-text p { margin: 0 0 1em; }
.d-walk { margin-top: auto; padding-top: 28px; display: flex; justify-content: space-between; gap: 12px; color: var(--dim); font-size: 15px; }
.d-walk button:hover { color: var(--ink); }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  body { font-size: 17px; }
  .brand { font-size: 22px; }
  .nav button { font-size: 16px; }
  .filters { flex-wrap: nowrap; overflow-x: auto; max-width: 74vw; scrollbar-width: none; font-size: 15px; padding-bottom: 2px; }
  .filters::-webkit-scrollbar { display: none; }
  .filters button { flex: none; }
  .sound-label { display: none; }
  .row { grid-template-columns: 2.4em minmax(0, 1fr) 4.5em; gap: 10px; }
  .row .a, .row .d { display: none; }
  .row .t { font-size: 19px; }
  #index-peek { display: none; }
  .detail { grid-template-columns: 1fr; grid-template-rows: 58vh auto; overflow-y: auto; }
  .d-card { border-left: 0; border-top: 1px solid var(--thread); padding: 26px 20px 40px; overflow: visible; }
  .d-close { position: fixed; top: 14px; right: 16px; z-index: 2; background: var(--cloth); padding: 4px 10px; }
  .d-card h2 { font-size: 28px; }
  .d-arrow { font-size: 34px; padding: 14px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
