/* Cache — 12-column grid, 8px baseline, one red. */

:root {
  --cols: 12;
  --gut: 16px;
  --mod: 8px;               /* horizontal spacing module */
  --base: 24px;             /* the baseline: one constant, repeating forever */
  --margin: 24px;
  --ink: #111;
  --paper: #fff;
  --grey: #888;
  --line: #e4e4e4;
  --red: #e0250e;
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 13px/16px var(--sans);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit; color: inherit; background: none; border: 0;
  padding: 0; cursor: pointer;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---- header on the grid ---- */
#hdr {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 0 var(--gut);
  height: calc(var(--base) * 2);   /* border included: content below starts on the grid */
  padding: 0 var(--margin);
  border-bottom: 1px solid var(--ink);
  position: sticky; top: 0; background: var(--paper); z-index: 20;
  align-items: center;
}
.hdr-cell.title { grid-column: 1 / span 4; font-weight: 700; }
.hdr-cell.title .sub { font-weight: 400; color: var(--grey); margin-left: 12px; }
.hdr-cell.right { grid-column: 11 / span 2; text-align: right; }
.hdr-cell.right button { margin-left: 16px; }
/* the g: an italic serif superscript leading the wordmark */
#gridBtn {
  font-family: "Hoefler Text", Didot, Georgia, serif;
  font-style: italic;
  font-weight: 400;
  font-size: 14px;
  line-height: 1;
  color: var(--grey);
  position: relative;
  top: -0.45em;
  margin-right: 3px;
}
#gridBtn:hover, #gridBtn.on { color: var(--red); }

/* the grid itself: 12 columns, 8px baseline, red, over everything */
#gridOverlay {
  position: fixed; inset: 0; z-index: 60; pointer-events: none;
  padding: 0 var(--margin);
}
#gridOverlay .cols {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 0 var(--gut);
}
#gridOverlay .col {
  background: rgba(224, 37, 14, 0.05);
  border-left: 1px solid rgba(224, 37, 14, .35);
  border-right: 1px solid rgba(224, 37, 14, .35);
}
/* baselines belong to the document, not the viewport: drawn on the containers,
   scrolling with their content (background-attachment: local) */
body.grid .idx-list,
body.grid .idx-stage,
body.grid #plate .plate {
  background-image: repeating-linear-gradient(
    to bottom, rgba(224, 37, 14, .28) 0 1px, transparent 1px var(--base));
  background-position: 0 -1px; /* row borders draw one pixel above the 24k line */
  background-attachment: local;
}
#hdr nav button { color: var(--grey); }
#hdr nav button:hover { color: var(--red); }

@media (max-width: 900px) {
  #hdr { grid-template-columns: repeat(4, 1fr); }
  .hdr-cell.title { grid-column: 1 / span 1; }
  .hdr-cell.right { grid-column: 2 / span 3; }
  #gridBtn { display: none; }  /* the grid is a desktop instrument */
}

main { min-height: 80vh; }

/* ---- index view: catalog left, stage centre ---- */
.v-index {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 0 var(--gut);
  padding: 0 var(--margin);
  height: calc(100dvh - 48px);
  overflow: hidden;
}
.idx-list {
  grid-column: 1 / span 5;
  overflow-y: auto;
  height: calc(100dvh - 48px);
  padding: var(--base) 0 calc(var(--base) * 4);
  scrollbar-width: none;
  scroll-snap-type: y mandatory;   /* the scroll itself obeys the grid */
}
.idx-list tr { scroll-snap-align: start; }
.idx-list::-webkit-scrollbar { display: none; }
.idx-list table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }

.v-index.cursor .idx-list tr { cursor: pointer; }
.idx-list tr:hover td { color: var(--red); }
.idx-list td { padding: 10px 16px 0 0; line-height: 13px; vertical-align: baseline; border-bottom: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }  /* a row is one baseline, always */
.idx-list td.no { color: var(--grey); width: 48px; font-variant-numeric: tabular-nums; }
.idx-list td.title { width: 45%; }
.idx-list td.year { color: var(--grey); text-align: right; padding-right: 0; width: 72px; }
.idx-list .unt { color: var(--grey); }
.idx-list tr:focus { outline: none; }

.idx-stage {
  grid-column: 6 / span 7;
  height: calc(100dvh - 48px);
  padding: var(--base) 0 0;
  overflow: hidden;
}
.stage-frame { cursor: pointer; display: flow-root; }  /* contain the image margin, no collapse */
.stage-frame img { display: block; object-fit: cover; }  /* left edge on the column, not centered */
.stage-cap { padding-top: 10px; line-height: 13px; height: calc(var(--base) * 2); overflow: hidden; }
.stage-cap .no { color: var(--red); margin-right: 12px; font-variant-numeric: tabular-nums; }
.stage-cap .t { font-weight: 700; margin-right: 8px; }
.stage-cap .a { margin-right: 8px; }
.stage-cap .y { color: var(--grey); }
.stage-cap .th { display: block; color: var(--grey); font-size: 11px; margin-top: 4px; }
@media (max-width: 900px) {
  .v-index { grid-template-columns: repeat(4, 1fr); }
  .idx-list td { padding: 6px 8px 6px 0; }
  .idx-list td.title { width: 40%; }
  .idx-list { grid-column: 1 / -1; height: calc((100dvh - 48px) * .4); }
  .v-index.cursor .idx-list { height: calc(100dvh - 48px); }
  .idx-stage { grid-column: 1 / -1; height: calc((100dvh - 48px) * .6); }
}

/* ---- plate (overlay geometry lives under #plate below) ---- */
.plate {
  height: calc(100dvh - 48px);
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 0 var(--gut);
  padding: calc(var(--mod) * 4) var(--margin);
  align-items: center;
}
.plate .pimg { grid-column: 3 / span 8; text-align: center; align-self: center; }
.plate .pimg img { max-width: 100%; max-height: calc(100dvh - 49px - 128px); cursor: pointer; }
.plate .pcap { grid-column: 1 / span 2; align-self: center; }
.plate .pcap .no { color: var(--red); display: block; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.plate .pcap .t { display: block; font-weight: 700; }
.plate .pcap .a { display: block; }
.plate .pcap .y, .plate .pcap .th { display: block; color: var(--grey); }
.plate .pcap .th { margin-top: 8px; font-size: 11px; }
@media (max-width: 900px) {
  .plate {
    display: flex; flex-direction: column;
    justify-content: center; align-items: stretch;
    gap: 16px; padding: 16px var(--margin);
  }
  .plate .pimg { order: 1; }
  .plate .pimg img { max-height: 65vh; }
  .plate .pcap { order: 2; align-self: flex-start; }
  .plate .pcap .no { margin-bottom: 4px; }
}

/* ---- board view: hand-rolled pan/zoom canvas fills it ---- */
.v-board {
  position: relative;
  height: calc(100dvh - 48px);
  overflow: hidden;
  color: var(--grey);
  display: flow-root;
  text-align: center;
  line-height: calc(100dvh - 48px);
}
.v-board > div { line-height: 16px; text-align: left; }
.bd-view {
  position: absolute; inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none; /* pointer events handle pan/pinch themselves */
}
.bd-view.dragging { cursor: grabbing; }
.bd-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.bd-item { position: absolute; cursor: pointer; }
.bd-item img { display: block; width: 100%; }
.bd-cap {
  margin-top: 8px;
  font: 12px/16px -apple-system, system-ui, sans-serif;
  color: var(--grey);
  white-space: pre-line;
  text-align: left;
  width: max-content; max-width: 120%;
}

/* ---- cursor-mode preview + mode toggle ---- */
.v-index.cursor .idx-list { grid-column: 1 / -1; }
.v-index.cursor .idx-list td.title { width: 34%; }
.v-index.cursor .idx-list td.year { text-align: left; }
#hoverThumb {
  position: fixed; pointer-events: none; z-index: 30;
  max-width: 256px; max-height: 256px; display: none;
  box-shadow: 0 2px 16px rgba(0,0,0,.25);
}

/* ---- plate overlay (opened from the board) ---- */
#plate {
  position: fixed; inset: 0; z-index: 45;
  background: var(--paper);
}
#plate[hidden] { display: none; }
#plate .plate { height: 100dvh; }
#plClose { position: absolute; top: 16px; right: var(--margin); font-size: 22px; }
#plate .pimg img { max-height: calc(100dvh - 128px); }

/* ---- lightbox ---- */
#lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(255,255,255,.97);
  display: flex; align-items: center; justify-content: center;
}
#lightbox[hidden] { display: none; }
#lbImg { max-width: calc(100vw - 128px); max-height: calc(100dvh - 128px); }
#lbCap { position: absolute; left: var(--margin); bottom: 24px; max-width: 40ch; }
#lbCap .t { font-weight: 700; }
#lbCap .a { display: block; }
#lbCap .y { color: var(--grey); }
#lbClose { position: absolute; top: 16px; right: var(--margin); font-size: 22px; }
#lbPrev, #lbNext { position: absolute; top: 50%; transform: translateY(-50%); font-size: 18px; padding: 16px; }
#lbPrev { left: 8px; } #lbNext { right: 8px; }
@media (max-width: 900px) {
  #lbImg { max-width: calc(100vw - 32px); max-height: calc(100dvh - 176px); }
  #lbCap { left: 16px; bottom: 20px; right: 132px; max-width: none; }
  #lbPrev, #lbNext { top: auto; bottom: 8px; transform: none; font-size: 22px; }
  #lbPrev { left: auto; right: 68px; }
  #lbNext { right: 8px; }
}

.hide { display: none; }
