:root {
  --ink: #1b1b1f;
  --muted: #6b6b74;
  --border: #dcdce2;
  --bg: #fafafa;
  --accent: #b5432b;
  --accent-ink: #ffffff;
  --canvas: #17171b;
  --frame-bg: #f2f1ec;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
.site-title { font-weight: 700; font-size: 1.1rem; color: var(--ink); }
.site-nav { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.staff-badge {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
}
.private-badge {
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  vertical-align: middle;
}
.restricted-badge {
  color: var(--accent);
  border-color: var(--accent);
}
.link-button {
  background: none; border: none; padding: 0; color: var(--accent);
  cursor: pointer; font: inherit; text-decoration: underline;
}

.site-main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
.reader-body .site-main { max-width: none; padding: 1rem; }

.breadcrumb { font-size: 0.9rem; margin-bottom: 1rem; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { background: #fff3e0; border: 1px solid #ffcc80; padding: 0.5rem 0.75rem; border-radius: 4px; margin-bottom: 0.4rem; }

/* Title / issue lists */
.title-grid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.title-card { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.title-card-link { display: block; }
.title-cover { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: var(--frame-bg); }
.title-card-name { display: block; font-weight: 600; font-size: 1.05rem; padding: 0.85rem 1rem 0.15rem; }
.title-card > p { margin: 0; padding: 0 1rem 0.85rem; }
.title-card:not(:has(.title-cover)) .title-card-name { padding-top: 1rem; }

.issue-list { list-style: none; padding: 0; }
.issue-row { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.issue-row-link { display: flex; align-items: center; gap: 0.65rem; font-weight: 600; }
.issue-row-text { display: flex; flex-direction: column; gap: 0.15rem; }
.issue-credits { font-weight: 400; font-size: 0.8rem; }
.issue-cover { width: 40px; aspect-ratio: 2/3; object-fit: cover; border-radius: 3px; background: var(--frame-bg); flex-shrink: 0; }
.issue-actions a { margin-left: 0.25rem; }
.credits { font-size: 0.9rem; margin-top: -0.5rem; }

/* Reader */
.reader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--canvas);
  border-radius: 10px;
  padding: 1rem;
  min-height: 70vh;
}
.reader-arrow {
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  user-select: none;
  flex: 0 0 auto;
  transition: background 0.15s;
}
.reader-arrow svg { width: 1.15rem; height: 1.15rem; display: block; }
.reader-arrow:hover { background: rgba(255, 255, 255, 0.2); text-decoration: none; }
.reader-arrow.is-disabled { opacity: 0.2; pointer-events: none; }

.page-spread {
  display: flex;
  align-items: stretch;
  justify-content: center;
  height: 82vh;
  max-width: 100%;
}
.page-frame {
  position: relative;
  height: 100%;
  aspect-ratio: 2652 / 4096;
  background: var(--frame-bg);
  border: 1px solid #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  max-width: 44vw;
}
.page-frame-spread { aspect-ratio: 5304 / 4096; max-width: 90vw; }
.page-frame img {
  /* 1px oversize + matching negative margin, cropped by the frame's own
     overflow:hidden -- with vh-derived percentage sizing, this box's
     height often lands on a fractional device pixel, and the GPU has to
     round that to a whole pixel when rasterizing. Whichever edge loses
     the fractional row would otherwise expose the frame's own
     background behind it as a hairline (invisible against light pages,
     glaring as a bright line against art that's dark to the edge) --
     the 1px overscan guarantees full coverage regardless of which way
     that rounding goes, at a cost far below one visible pixel. */
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  margin: -1px;
  object-fit: contain;
  display: block;
}
.page-frame-blank { width: 100%; height: 100%; }
.page-frame-empty { color: #999; font-size: 0.85rem; }
.page-frame-restricted {
  color: var(--accent);
  font-size: 0.85rem;
  text-align: center;
  padding: 0 1rem;
}
.gutter { width: 4px; background: #000; height: 100%; opacity: 0.35; }

.page-number-tag {
  position: absolute;
  bottom: 0.5rem;
  background: rgba(23, 23, 27, 0.72);
  color: #fff;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  line-height: 1.2;
  pointer-events: none;
}
.page-number-tag-left { left: 0.5rem; }
.page-number-tag-right { right: 0.5rem; }

.reader-footer { text-align: center; margin-top: 0.75rem; }
.page-caption { font-style: italic; margin: 0.25rem 0; }
.reader-transcripts {
  display: flex; justify-content: center; align-items: flex-start;
  gap: 0.75rem; max-width: 900px; margin: 0.4rem auto 0;
}
.transcript-slot { flex: 1 1 0; min-width: 0; }
.transcript-toggle {
  text-align: left; border: 1px solid var(--border); border-radius: 6px;
  padding: 0.5rem 0.75rem; background: #fff; font-size: 0.9rem;
}
.transcript-toggle summary { cursor: pointer; font-weight: 600; }
.transcript-toggle summary:hover { color: var(--accent); }
.transcript-text { margin: 0.5rem 0 0; }
.reader-position { font-size: 0.85rem; }
.reader-history {
  display: flex; justify-content: center; gap: 0.75rem;
  max-width: 900px; margin: 0.25rem auto; font-size: 0.85rem;
}
.history-slot { flex: 1 1 0; min-width: 0; }
.reader-credits { font-size: 0.8rem; margin: 0.25rem 0; }

.reader-page-position { display: none; }

/* Small or short screens (phones either way up): slimmer site chrome, so
   the page itself gets as much of the screen as possible. */
@media (max-width: 700px), (max-height: 500px) {
  .site-header { padding: 0.5rem 0.75rem; }
  .site-title { font-size: 1rem; }
  .site-nav { gap: 0.5rem; font-size: 0.85rem; }
  .reader-body .site-main { padding: 0.5rem; }
  .reader-body .breadcrumb,
  .reader-body .tag-switcher { font-size: 0.8rem; margin: 0 0 0.4rem; }
}

/* Phones (portrait): one page at a time -- the half of the opening named by
   .reader-view[data-focus], which reader.js flips on swipe/tap/arrow --
   sized to fit the screen, with the arrows and "Page N of M" in a row
   underneath. Spreads still show whole, at full width. Keep the width in
   sync with SINGLE_PAGE_QUERY in reader.js. */
@media (max-width: 700px) {
  .reader {
    --chrome: 10.5rem; /* header + breadcrumb + paddings + arrow row */
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "page page page" "prev position next";
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    min-height: 0;
    border-radius: 6px;
  }
  .page-spread { grid-area: page; height: auto; width: 100%; }
  .reader-arrow-prev { grid-area: prev; }
  .reader-arrow-next { grid-area: next; }
  .reader-arrow { width: 2.75rem; height: 2.75rem; }
  .reader-page-position {
    display: block; grid-area: position; margin: 0; text-align: center;
    font-size: 0.85rem; font-variant-numeric: tabular-nums; color: #a9a9b3;
  }
  .gutter { display: none; }
  .page-frame {
    height: auto;
    max-width: none;
    margin: 0 auto;
    /* As wide as the canvas allows, unless that would make the page taller
       than the screen minus the surrounding chrome. */
    width: min(100%, calc((100vh - var(--chrome)) * 2652 / 4096));
    width: min(100%, calc((100dvh - var(--chrome)) * 2652 / 4096));
  }
  .page-frame-spread { width: 100%; }

  .reader-view[data-focus="left"] .side-right,
  .reader-view[data-focus="right"] .side-left { display: none; }

  .reader-position { display: none; }
  .reader-footer { margin-top: 0.5rem; }
  .reader-transcripts, .reader-history { gap: 0; }
}

/* Contact sheet */
.contact-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.75rem; }
.contact-tile { display: block; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #fff; position: relative; }
.contact-tile img {
  /* 1px overscan, cropped by .contact-tile's own overflow:hidden -- see
     .page-frame img for why (same fractional-device-pixel rounding). */
  width: calc(100% + 2px);
  margin: -1px;
  display: block;
  aspect-ratio: 2652/4096;
  object-fit: contain;
  background: var(--frame-bg);
}
.contact-tile.is-spread { grid-column: span 2; }
.contact-tile.is-spread img { aspect-ratio: 5304/4096; }
.contact-tile-number { display: block; text-align: center; font-size: 0.75rem; padding: 0.2rem; color: var(--muted); }
.contact-tile-empty { aspect-ratio: 2652/4096; background: var(--frame-bg); }
.contact-tile.is-spread .contact-tile-empty { aspect-ratio: 5304/4096; }
.contact-tile-restricted, .contact-tile-missing {
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
}
.contact-tile-missing { color: var(--muted); }

/* Staff: manage pages */
.manage-toolbar { margin-bottom: 1rem; }
.manage-page-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.manage-tile {
  border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem; background: #fff;
  position: relative; cursor: grab;
}
.manage-tile.dragging { opacity: 0.4; }
.manage-tile.drag-over { outline: 2px dashed var(--accent); }
.manage-tile-handle { position: absolute; top: 0.35rem; right: 0.5rem; color: var(--muted); font-size: 0.9rem; }
.manage-tile-dropzone {
  position: relative; aspect-ratio: 2652/4096; background: var(--frame-bg);
  border-radius: 4px; overflow: hidden;
}
.manage-tile-dropzone img { width: 100%; height: 100%; object-fit: contain; display: block; }
.manage-tile-overlay {
  position: absolute; inset: 0; background: rgba(181,67,43,0.85); color: #fff;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 0.8rem; padding: 0.5rem; opacity: 0; pointer-events: none; transition: opacity 0.1s;
}
.manage-tile-dropzone.drag-active .manage-tile-overlay,
.manage-tile-dropzone.is-uploading .manage-tile-overlay { opacity: 1; }
.manage-tile-meta { margin-top: 0.4rem; font-size: 0.8rem; display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.manage-tile-number { font-weight: 600; width: 100%; }
.restricted-toggle-form { display: contents; }
.restricted-toggle { display: inline-flex; align-items: center; gap: 0.2rem; cursor: pointer; color: var(--muted); }
.insert-after-btn, button.danger, .version-activate-btn, .transcript-form button {
  font: inherit; padding: 0.2rem 0.5rem; border-radius: 4px; border: 1px solid var(--border); background: #fff; cursor: pointer;
}
button.danger { color: #b5432b; border-color: #e0a598; }
.delete-page-form { display: inline; }

/* Compare */
.version-strip { margin-bottom: 1.5rem; }
.version-strip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.75rem; }
.version-thumb {
  border: 1px solid var(--border); border-radius: 6px; padding: 0.35rem; background: #fff;
  text-align: center; font-size: 0.75rem;
}
.version-thumb.is-a { border-color: #2c6e9e; box-shadow: 0 0 0 1px #2c6e9e; }
.version-thumb.is-b { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.version-thumb.is-a.is-b { box-shadow: 0 0 0 1px #2c6e9e, 0 0 0 3px var(--accent); }
.version-thumb.is-spread { grid-column: span 2; }
.version-thumb-image { position: relative; overflow: hidden; }
.version-thumb img {
  /* 1px overscan, cropped by .version-thumb-image's own overflow:hidden --
     see .page-frame img for why (same fractional-device-pixel rounding). */
  width: calc(100% + 2px);
  margin: -1px;
  aspect-ratio: 2652/4096;
  object-fit: contain;
  background: var(--frame-bg);
  display: block;
  border-radius: 3px;
}
.version-thumb.is-spread img { aspect-ratio: 5304/4096; }
.version-active-badge {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: #fff; border-radius: 50%;
  font-size: 0.7rem; line-height: 1; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.version-thumb-meta { color: var(--muted); margin: 0.3rem 0; }
.version-thumb-picks { display: flex; justify-content: center; gap: 0.75rem; }
.version-pick { display: flex; align-items: center; gap: 0.2rem; cursor: pointer; }
.version-pick-a { color: #2c6e9e; }
.version-pick-b { color: var(--accent); }
.version-activate-btn, .version-delete-btn { display: block; margin: 0.4rem auto 0; font-size: 0.7rem; padding: 0.1rem 0.4rem; }
.compare-nav { display: flex; justify-content: space-between; align-items: center; margin: 0.5rem 0 1rem; }
.compare-upload-dropzone {
  border: 2px dashed var(--border); border-radius: 8px; padding: 1.25rem;
  text-align: center; color: var(--muted); font-size: 0.9rem; cursor: pointer;
  margin-bottom: 1.5rem; transition: border-color 0.1s, background 0.1s, color 0.1s;
}
.compare-upload-dropzone.drag-active,
.compare-upload-dropzone:hover {
  border-color: var(--accent); color: var(--accent); background: rgba(181, 67, 43, 0.05);
}
.compare-upload-dropzone.is-uploading {
  border-style: solid; border-color: var(--accent); color: var(--accent);
  background: rgba(181, 67, 43, 0.05); cursor: progress;
}
.manage-tile-dropzone.is-uploading { cursor: progress; }
.replace-active-toggle {
  display: inline-flex; align-items: center; gap: 0.4em; font-size: 0.9rem; color: var(--muted);
  cursor: pointer;
}
.compare-upload-dropzone + .compare-page-options {
  display: flex; flex-direction: column; gap: 0.3rem; margin: -1rem 0 1.5rem;
}
.redacted-section { margin-top: 0.5rem; }
.redacted-row { display: flex; gap: 0.75rem; align-items: flex-start; margin-top: 0.3rem; }
.redacted-preview img { display: block; max-height: 140px; max-width: 120px; border: 1px solid var(--border); }
.redacted-controls { flex: 1; display: flex; flex-direction: column; gap: 0.4rem; align-items: flex-start; }
.compare-upload-dropzone.redacted-dropzone { margin: 0; padding: 0.75rem; font-size: 0.85rem; align-self: stretch; }
.manage-tile-redaction { font-size: 0.8rem; }
/* Spinner in front of the status text while an upload is in flight. */
.is-uploading [data-upload-status]::before {
  content: ""; display: inline-block; width: 0.9em; height: 0.9em; margin-right: 0.5em;
  vertical-align: -0.1em; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: upload-spin 0.8s linear infinite;
}
@keyframes upload-spin { to { transform: rotate(360deg); } }
.compare-grid { display: flex; gap: 1rem; flex-wrap: wrap; }
.compare-pane { flex: 1 1 320px; }
.compare-pane .page-frame { height: 70vh; max-width: 100%; }
.compare-pane.is-spread { flex-basis: 600px; }
.compare-pane.is-spread .page-frame { aspect-ratio: 5304/4096; }
.transcript-form { margin-top: 0.5rem; }
.transcript-label { display: block; font-size: 0.85rem; color: var(--muted); }
.transcript-label textarea {
  display: block; width: 100%; box-sizing: border-box; margin-top: 0.3rem;
  font: inherit; font-size: 0.9rem; padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; resize: vertical;
}
.transcript-form button { margin-top: 0.4rem; }
.transcript-label + .transcript-label { margin-top: 0.5rem; }

/* Tags */
.tag-switcher { margin: 0.5rem 0 1rem; }
.tag-switcher a.is-current { color: var(--ink); font-weight: 600; text-decoration: none; }
.version-thumb-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: center; margin: 0.3rem 0; min-height: 1.4rem; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  background: var(--frame-bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.1rem 0.5rem; font-size: 0.7rem; color: var(--ink);
}
.tag-chip-remove {
  font: inherit; border: none; background: none; cursor: pointer; color: var(--muted);
  padding: 0; line-height: 1;
}
.tag-chip-remove:hover { color: var(--accent); }
.tag-add-input, .tag-add-form input {
  font: inherit; font-size: 0.75rem; width: 100%; box-sizing: border-box;
  padding: 0.15rem 0.4rem; margin: 0.2rem 0; border: 1px solid var(--border); border-radius: 4px;
}

/* Auth */
.auth-form-wrap { max-width: 320px; margin: 2rem auto; }
.auth-form { display: flex; flex-direction: column; gap: 0.75rem; }
.auth-form input { padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; }
.auth-form button { padding: 0.5rem; background: var(--accent); color: #fff; border: none; border-radius: 4px; cursor: pointer; }
