: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-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 {
  font-size: 2.5rem;
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 50%;
  line-height: 1;
  user-select: none;
  flex: 0 0 auto;
}
.reader-arrow:hover { background: rgba(255,255,255,0.1); 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 { width: 100%; height: 100%; 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-position { font-size: 0.85rem; }
.reader-history { font-size: 0.85rem; margin: 0.25rem 0; }

@media (max-width: 820px) {
  .page-spread { flex-direction: column; height: auto; width: 100%; }
  .page-frame, .page-frame-spread { max-width: 92vw; width: 92vw; height: auto; margin: 0 auto; }
  .gutter { display: none; }
  .reader { flex-direction: column; }
}

/* 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 { width: 100%; 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 {
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
}

/* 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 { 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 {
  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; }
.version-thumb img { width: 100%; 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-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; }

/* 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; }
