:root {
  color-scheme: light dark;
  --bg: #fafaf8;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --card: #ffffff;
  --border: #e2e1dc;
  --accent: #2f5d8a;
  --accent-fg: #ffffff;
  --accent-soft: #2f5d8a1f;
  --warn: #8a5a00;
  --bad: #b3261e;
  --desk: #d9d8d3;
  --paper: #ffffff;
  --guide: #2f5d8a;
  --bleed-mask: #d9d8d3b8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --fg: #ecebe6;
    --muted: #9c9b95;
    --card: #20201e;
    --border: #34332f;
    --accent: #8fb6dd;
    --accent-fg: #111;
    --accent-soft: #8fb6dd24;
    --warn: #e0b45c;
    --bad: #f2a29b;
    --desk: #2a2a28;
    --paper: #fbfbf9;
    --guide: #4f86c0;
    --bleed-mask: #2a2a28c4;
  }
}

@font-face {
  font-family: "Pho Sans";
  src: url("/fonts/NotoSans-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

* { box-sizing: border-box; }

/* An image that wasn't ready when shown fades in once it is (media.js
   fadeInIfLate). It keeps its own opacity after, e.g. a faded draft's. */
img.fade-in { transition: opacity 0.2s ease-out; }
img.fade-in:not(.shown) { opacity: 0; }
/* An image whose source isn't set yet (a thumbnail waiting to scroll into
   view, a URL still being read) would show as broken: keep it invisible,
   its space held, until it has one. */
img:not([src]), img[src=""] { visibility: hidden; }

/* Author `display` rules otherwise override the hidden attribute. */
[hidden] { display: none !important; }

/* Text isn't selectable, so clicks and drags on the interface don't
   highlight it, except where copying is useful: anything you type,
   a photo's details, error messages, and whatever is marked .selectable. */
body { user-select: none; -webkit-user-select: none; }
input, textarea, [contenteditable],
.photo-dialog-info h2, .photo-meta,
.status.error, .failures,
.selectable { user-select: text; -webkit-user-select: text; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
body.editing { overflow: hidden; }

a { color: var(--accent); }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }

input[type="text"], input[type="search"], select, textarea, .title-input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.status { min-height: 1.5em; margin: 8px 0; }
.status.error { color: var(--bad); }
.hint { margin: 6px 0; font-size: 13px; color: var(--muted); }
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 8px;
  list-style: none;
}

/* ---- Home hero --------------------------------------------------------------- */

/* A black banner in both themes. The logo (logo-mono.png) is logo.png with
   the background around the drawing removed, inside kept whole:
   `tools/silhouette.sh web/logo.png web/logo-mono.png`. */
/* Edge to edge across the top of the page, square corners. */
.hero {
  margin: 0 0 24px;
  background: radial-gradient(#262626, #000000);
  color: #f2f1ec;
  overflow: hidden;
}
/* The banner's contents, aligned with the page below (.home). */
.hero-inner {
  /* The drawing's width; how far the text column tucks in over its right
     side (its transparent edge, and the 20px it's nudged left); and the gap
     after the column. .hero-add lines its buttons up with the text. */
  --art-size: clamp(240px, 40vw, 540px);
  --art-tuck: 40px;
  --art-width: calc(var(--art-size) - var(--art-tuck));
  --art-gap: 0px;
  position: relative; /* the drawing is placed in its grid area */
  display: grid;
  grid-template-columns: var(--art-width) minmax(0, 1fr);
  grid-template-areas:
    "art text"
    "add add";
  column-gap: var(--art-gap);
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}
.hero h1 {
  margin: 0;
  font-size: clamp(44px, 6.4vw, 88px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.04em;
}
/* "Pho" in white on the dark banner, a big italic serif. */
.hero h1 .name {
  color: #fff;
  font-size: clamp(108px, 19.8vw, 270px); /* smaller on narrow screens, where 270px wouldn't fit */
  font-family: serif;
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.05em; /* scales with the text */
  position: relative;
  top: 0.07em; /* nudged down a little, in step with its size */
}
/* Out of the flow, so the text alone sets the banner's height: the drawing
   is sized by width and starts at the banner's top. Anything taller than
   the text runs over the add-photos strip, cut off at the banner's bottom. */
.hero img {
  grid-area: art;
  position: absolute;
  /* Nudged left (nearer the banner's edge) and down by fixed shares of the
     drawing's size (-36px and 40px at its largest, 540px), so it sits the
     same way however big the window makes it. */
  left: calc(var(--art-size) * -0.067);
  top: calc(var(--art-size) * 0.074);
  width: var(--art-size); /* see .hero-inner */
  height: auto;
  /* The artwork has empty black below the bowl (and some above the photos):
     show the middle 82%, so the hairline sits close under the bowl. */
  aspect-ratio: 1 / 0.82;
  object-fit: cover;
  object-position: center 33%;
  /* Drawn over the hairline below it; clicks pass through to the buttons. */
  z-index: 2;
  pointer-events: none;
}

.add-button { display: inline-flex; align-items: center; gap: 6px; }
.add-button .plus { font-size: 1.25em; font-weight: 600; line-height: 1; margin-top: -0.08em; }
.button-note {
  margin-left: 2px;
  font-size: 0.7em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
}

/* Full banner height: title and privacy note at the top, the add buttons
   at the very bottom. */
/* Above the artwork, so a long title can run over it. */
.hero-text { grid-area: text; padding: 0 0 30px; text-shadow: 5px 5px 20px black; display: flex; flex-direction: column; min-width: 0; align-self: center; position: relative; z-index: 3; }
/* Title, description and install button, stacked. */
.hero-head { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; }
.hero-head .install-row { margin-top: 12px; }
.hero-head .privacy-note { margin: 0; }
/* The add-photo buttons along the bottom, under a hairline that runs the
   banner's full width (the negative margins reach past its padding). */
.hero-add {
  grid-area: add;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* The hairline spans the whole window; content stays aligned. */
  margin-inline: calc((100% - 100vw) / 2);
  padding: 20px calc((100vw - 100%) / 2);
  /* Content starts where the title does, right of the drawing. */
  padding-left: calc((100vw - 100%) / 2 + var(--art-width) + var(--art-gap));
  background: #0000004a;
  border-top: 1px solid var(--bg); /* the page's own background showing through */
}
.hero-add-label {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #a8a7a1;
}

.hero h1 { cursor: default; white-space: nowrap; }
.install-box { display: flex; flex: none; }
/* Button and note side by side: the note shrinks to fit rather than wrap below. */
.install-row { display: flex; align-items: center; gap: 40px; align-self: stretch; }
.install-row .privacy-note { flex: 1 1 auto; min-width: 0; max-width: 30em; }
/* Controls on the dark banner. */
.hero .actions button {
  padding: 9px 16px;
  font-size: 15px;
  color: #f2f1ec;
  background: #ffffff14;
  border-color: #ffffff33;
}
.hero .actions button:hover:not(:disabled) { border-color: #8fb6dd; background: #ffffff1f; }
.install-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 8px;
}
.install-button:hover:not(:disabled) { filter: brightness(1.1); }
.install-button .icon { flex: none; margin-left: -2px; }
.privacy-note { margin: 0; max-width: 34em; font-size: 13px; color: #a8a7a1; }

.privacy-note strong { color: #f2f1ec; font-weight: 600; }
/* A phrase that wraps as a unit when it fits on a line: line breaks fall
   between phrases first (it still wraps inside if a line is too narrow). */
.phrase { display: inline-block; }

@media (max-width: 640px) {
  .install-row { flex-wrap: wrap; }
  .hero-inner { grid-template-columns: minmax(0, 1fr); grid-template-areas: "art" "text" "add"; padding: 20px 16px 0; --art-width: 0px; --art-gap: 0px; }
  .hero img { position: static; width: 100%; margin: -12px 0 8px; }
}

/* ---- Home ---------------------------------------------------------------- */

.home { max-width: 1200px; margin: 0 auto; padding: 0 16px 48px; }
.home-footer { margin-top: 48px; font-size: 13px; color: var(--muted); }
.home-footer a { color: inherit; }

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.app-header h1 { margin: 0; font-size: 22px; letter-spacing: 0.02em; }

.section-bar, .library-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}
/* One size for the home screen's section headings (Books, Library). */
.section-bar h2, .library-bar h2 { margin: 0; font-size: 30px; }

.section-actions { display: flex; flex-wrap: wrap; gap: 8px; }
/* A link that looks like a button. */
.button-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: inherit;
  text-decoration: none;
}
.button-link:hover { border-color: var(--accent); }

/* ---- Migrate ------------------------------------------------------------------ */

.migrate { max-width: 860px; margin: 0 auto; padding: 24px 16px 64px; }
.migrate h1 { margin: 12px 0 8px; font-size: 30px; }
.migrate-actions { margin: 16px 0; }
.migrate-review { margin-top: 24px; }
.migrate-pages { display: grid; gap: 10px; margin: 12px 0 20px; padding: 0; list-style: none; }
.migrate-page {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}
.migrate-thumb { width: 120px; height: auto; border-radius: 3px; background: #fff; }
.migrate-page-info { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.migrate-page-title { margin: 0; font-weight: 600; }
/* The screenshot's caption, enlarged so its small text is legible. */
.migrate-caption-image { width: 100%; max-width: 560px; background: #fff; border: 1px solid var(--border); border-radius: 4px; }
.migrate-caption { width: 100%; }
.migrate-page .remove { padding: 2px 9px; }
.migrate-make { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.migrate-make .field { flex: 1 1 260px; margin: 0; }
.books { margin-bottom: 32px; }

.book-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.book-grid > .empty { grid-column: 1 / -1; }

/* Cards fill their grid row, so every card in a row is the same height. */
.book-card { position: relative; min-width: 0; display: flex; }
.book-card > .book-link { flex: 1; min-width: 0; }
.book-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: inherit;
  text-decoration: none;
}
.book-link:hover { border-color: var(--accent); }
/* "New Book" tile: a dashed box as tall as the book cards beside it, with
   the icon and label centred together. */
.new-book { display: flex; }
.new-book-tile {
  flex: 1;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.new-book-tile .icon { width: 44px; height: 44px; stroke-width: 1.5; }
.new-book-tile:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.books-hint { align-self: center; color: var(--muted); font-size: 14px; list-style: none; }
.book-cover {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  margin-bottom: 8px;
}
.book-shape {
  display: block;
  overflow: hidden;
  border-radius: 3px;
  background: var(--border);
  box-shadow: 0 1px 3px #0003;
}
.book-shape img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Library --------------------------------------------------------------- */

.library {
  border: 2px dashed transparent;
  border-radius: 10px;
  padding: 8px;
  margin: -8px;
  transition: border-color 120ms, background 120ms;
}
.library.dropping { border-color: var(--accent); background: var(--accent-soft); }

.count { color: var(--muted); font-weight: normal; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }


/* The import box (import-toast.js): bottom centre, over everything. */
.import-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 50;
  transform: translateX(-50%);
  width: min(460px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  box-shadow: 0 10px 30px #0000003d;
  animation: import-toast-in 0.18s ease-out;
}
.import-toast.error { border-color: var(--bad); }
.import-toast-row { display: flex; align-items: center; gap: 10px; }
.import-toast-message { flex: 1; min-width: 0; margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.import-toast.error .import-toast-message { color: var(--bad); }
.import-toast progress { display: block; width: 100%; height: 8px; margin-top: 10px; }
.import-toast .dismiss { flex: none; padding: 0 7px; border: 0; background: none; color: inherit; font-size: 18px; line-height: 1.2; opacity: 0.7; }
.import-toast .dismiss:hover:not(:disabled) { opacity: 1; }
.import-toast .failures { max-height: 180px; overflow-y: auto; margin: 10px 0 0; }
@keyframes import-toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }
.failures { margin: 0 0 12px; padding-left: 20px; font-size: 13px; color: var(--bad); }
.storage { margin: 12px 0 0; font-size: 12px; color: var(--muted); }
.storage.warn { color: var(--warn); }

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.card {
  position: relative;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
/* In the editor: a photo can always be dragged to a slot; it invites a
   click only when there's a slot for it (.can-place, see refreshPlaceable). */
.card.placeable { cursor: grab; }
.library.can-place .card.placeable { cursor: pointer; }
.library.can-place .card.placeable:hover { border-color: var(--accent); }
.card.used { border-color: var(--accent-soft); }

.card img {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--border);
  border-radius: 4px;
  display: block;
}

.meta { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); min-width: 0; }
.meta .name { color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.usage {
  position: absolute;
  left: 10px;
  bottom: 10px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

/* A card's corner button: × (remove) or ⓘ (details), shown on hover. */
.remove, .card-info {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  padding: 0;
  line-height: 1;
  font-size: 16px;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 120ms;
}
.card:hover .remove, .book-card:hover .remove, .remove:focus-visible,
.card:hover .card-info, .card-info:focus-visible { opacity: 0.95; }
@media (hover: none) { .remove, .card-info { opacity: 0.85; } }
.card-info { display: grid; place-items: center; }
.card-info .icon { width: 70%; height: 70%; }

.library-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 8px; }
.library-filters input[type="search"] { flex: 1 1 200px; min-width: 0; }
.library-filters select { font-size: 13px; }
.segmented.scope { margin: 12px 0 0; }
/* Everything but the search, behind the Filters button. */
.filter-button { flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
/* A chevron: down while the panel is closed, up while it's open. */
.filter-button::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s, margin 0.15s;
}
.filter-button[aria-expanded="true"]::after { transform: rotate(-135deg); margin-top: 3px; }
/* Filters set: accent colour. Panel open: pressed in. */
.filter-button.active { border-color: var(--accent); background: var(--accent-soft); }
.filter-button[aria-expanded="true"] { box-shadow: inset 0 1px 3px #0003; background: var(--border); }
.filter-button.active[aria-expanded="true"] { background: var(--accent-soft); }
.filter-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px 12px;
  margin: 0 0 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}
.filter-panel .field { margin: 0; }
.filter-panel select { font-size: 13px; }
.filter-panel .check { font-size: 13px; }
.filter-tags { flex: 1 1 100%; }
/* The tag box at the panel's text size, not a form field's. */
.filter-tags .tag-input input { font-size: 13px; }
.segmented.tag-match { margin: 6px 0 0; max-width: 260px; }
.link-button { padding: 2px 4px; border: 0; background: none; color: var(--accent); font-size: 13px; }
.link-button:hover:not(:disabled) { text-decoration: underline; }
.add-shown { margin: 4px 0 8px; font-size: 13px; }

.library-group h3 { margin: 16px 0 8px; font-size: 13px; font-weight: 600; }
.library-group h3 .count { font-weight: normal; }
.library-group:first-child h3 { margin-top: 4px; }

.include {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity 120ms;
}
.include.on { opacity: 0.95; background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.include:disabled { opacity: 0.95; }
.card:hover .include, .include:focus-visible { opacity: 0.95; }
@media (hover: none) { .include { opacity: 0.85; } }

.library.compact { margin: 0; padding: 4px; }
.library.compact .library-filters { margin-top: 8px; }
.library.compact .filter-panel { flex-direction: column; align-items: stretch; }
.library.compact .library-group h3 { margin: 12px 0 6px; font-size: 12px; }
.library.compact .include { top: 5px; left: 5px; width: 20px; height: 20px; font-size: 12px; }
.library.compact .library-bar { flex-direction: column; align-items: stretch; }
.library.compact .library-bar h2 { font-size: 17px; } /* the editor's narrow side panel */
.library.compact .actions { flex-direction: column; }
.library.compact .grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.library.compact .card { padding: 3px; border-radius: 6px; }
.library.compact .card img { border-radius: 3px; }
.library.compact .remove, .library.compact .card-info { top: 5px; right: 5px; width: 20px; height: 20px; font-size: 13px; }
.library.compact .usage { left: 5px; bottom: 5px; }
.library.compact .empty { padding: 24px 8px; font-size: 13px; }

/* ---- Dialog ----------------------------------------------------------------- */

.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
}
.dialog::backdrop { background: #0006; }
.dialog:focus { outline: none; } /* focused itself on open, so no control is */
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.field input, .field select { color: var(--fg); font-size: 15px; }

.tag-dialog { width: min(480px, calc(100vw - 32px)); }
.tag-preview { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 14px; }
.tag-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 3px; background: var(--border); }
.tag-preview .more { font-size: 13px; color: var(--muted); padding: 0 6px; }
.tag-input {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
}
.tag-input:focus-within { border-color: var(--accent); }
.tag-input { position: relative; }
.tag-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px #0000002e;
}
.tag-suggestions li {
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 14px;
  color: var(--fg);
  cursor: pointer;
}
.tag-suggestions li:hover, .tag-suggestions li.active { background: var(--accent-soft); }
.tag-field { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
/* ⋮ at the end of the box, level with the first line: lists every tag in use. */
.tag-all {
  flex: none;
  display: grid;
  place-items: center;
  margin-top: 2px;
  padding: 3px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}
.tag-all:hover:not(:disabled) { color: var(--fg); background: var(--accent-soft); }
.tag-all[hidden] { display: none; }
/* A typed tag that doesn't exist (in a filter, which only takes real ones). */
.tag-input input[aria-invalid="true"] { color: var(--bad); }
.tag-input input { flex: 1 1 140px; min-width: 0; border: 0; padding: 4px; background: transparent; outline: none; }
.tag-chips { display: contents; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 2px 1px 8px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--fg);
  font-size: 13px;
}
.tag-chip button { padding: 0 6px; border: 0; background: transparent; font-size: 14px; line-height: 1.4; }
.card.openable { cursor: pointer; }
.card.openable:hover { border-color: var(--accent); }
.details { margin-top: 8px; font-size: 13px; }

/* At least a steady size, so the window doesn't change as photos load or
   as ← / → step through them; taller when a photo's details need it, up to
   the browser window (then the details scroll). The photo is fitted inside
   its box, which matches the details' height. */
.photo-dialog[open] {
  display: flex;
  flex-direction: column;
  width: min(860px, calc(100vw - 32px));
  min-height: min(640px, calc(100dvh - 32px));
  max-height: calc(100dvh - 32px);
  overflow: hidden; /* the details scroll, not the window */
}
.photo-dialog-body {
  /* As tall as the details (not a share of a fixed height), shrinking to
     fit the browser window, when the details scroll. */
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 20px;
}
.photo-dialog-preview { position: relative; background: #1d1d1d; border-radius: 6px; }
.photo-dialog-preview img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.photo-dialog-info { min-width: 0; overflow-y: auto; }
.photo-dialog-info h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 16px; font-size: 13px; }
.photo-meta dt { color: var(--muted); }
.photo-meta dd { margin: 0; overflow-wrap: anywhere; }
.save-note { font-size: 12px; color: var(--muted); margin-left: 6px; }

.smart-status { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.smart-info { margin-top: 14px; }
.smart-heading { margin: 10px 0 6px; font-size: 13px; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.suggestion { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 14px; font-size: 13px; }
.suggestion .plus { font-weight: 600; }
.suggestion:disabled { opacity: 0.4; }
.similar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.similar button { padding: 0; border-radius: 4px; overflow: hidden; }
.similar img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
@media (max-width: 640px) {
  /* Stacked: the photo in a fixed box, the details below it scrolling. */
  .photo-dialog-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: 45dvh minmax(0, 1fr); }
}

.meta .tags { color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Editor ------------------------------------------------------------------- */

.editor {
  display: grid;
  grid-template-columns: var(--sidebar-width, 360px) minmax(0, 1fr) 260px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "bar bar bar"
    "sidebar stage inspector"
    "sidebar strip inspector";
  height: 100vh;
  height: 100dvh;
}

.editor-bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.editor-bar .back { text-decoration: none; white-space: nowrap; }
.title-input { min-width: 0; width: 280px; font-weight: 600; border-color: transparent; background: transparent; }
.title-input:hover, .title-input:focus { border-color: var(--border); background: var(--bg); }
.print-button { font-size: 13px; padding: 4px 10px; color: var(--muted); white-space: nowrap; border-color: transparent; background: transparent; }
.print-button:hover:not(:disabled) { color: var(--fg); }
.print-button.has-issues { color: var(--warn); border-color: var(--warn); }
.print-dialog { width: min(560px, calc(100vw - 32px)); }
.print-dialog .row .field { min-width: 120px; }
.backup-dialog { width: min(480px, calc(100vw - 32px)); }
.backup-dialog h3 { margin: 18px 0 0; font-size: 15px; }
.backup-dialog p:first-of-type { margin-top: 0; }
.backup-actions { display: flex; gap: 8px; }
.backup-dialog progress { display: block; width: 100%; height: 14px; margin-top: 16px; }
.backup-dialog progress[hidden] { display: none; }
.export-dialog progress { width: 100%; height: 14px; margin-top: 8px; }
.export-file { margin: 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.spacer { flex: 1; }

.sidebar {
  grid-area: sidebar;
  overflow-y: auto;
  padding: 10px;
  border-right: 1px solid var(--border);
}
/* The library column's draggable right edge: a strip straddling its border
   that shows the accent colour on hover, focus and while dragging. */
.sidebar-resize {
  grid-area: sidebar;
  justify-self: end;
  z-index: 3;
  width: 8px;
  margin-right: -4px;
  cursor: col-resize;
  touch-action: none;
}
.sidebar-resize::after {
  content: "";
  display: block;
  width: 2px;
  height: 100%;
  margin: 0 auto;
  background: transparent;
  transition: background 0.15s;
}
.sidebar-resize:hover::after,
.sidebar-resize:focus-visible::after,
.editor.resizing .sidebar-resize::after { background: var(--accent); }
.sidebar-resize:focus-visible { outline: none; }
/* The resize cursor everywhere while dragging the column edge. */
.editor.resizing { cursor: col-resize; }

.stage { grid-area: stage; display: flex; flex-direction: column; min-height: 0; background: var(--desk); }
.stage-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
.stage-bar button { padding: 3px 10px; font-size: 13px; }
.spread-label { min-width: 110px; text-align: center; color: var(--muted); }

.canvas {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.editor-status { margin: 0; min-height: 1.6em; padding: 0 12px 4px; font-size: 13px; color: var(--muted); text-align: center; }
.editor-status.error { color: var(--bad); }

.inspector {
  grid-area: inspector;
  overflow-y: auto;
  padding: 10px 12px;
  border-left: 1px solid var(--border);
}
.panel { padding: 8px 0 14px; }
.panel h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.row .field { flex: 1; min-width: 70px; margin: 0; }
.row .field select { font-size: 13px; padding: 4px; }
.row button { font-size: 13px; }

.segmented { display: flex; margin-bottom: 10px; }
.segmented button { flex: 1; border-radius: 0; font-size: 13px; padding: 4px 8px; }
.segmented button:first-child { border-radius: 6px 0 0 6px; }
.segmented button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.segmented button.active { background: var(--accent-soft); border-color: var(--accent); position: relative; }

.layout-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.layout-option { padding: 4px; display: flex; align-items: center; justify-content: center; }
.layout-option.active { border-color: var(--accent); background: var(--accent-soft); }
.layout-icon {
  position: relative;
  display: block;
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--border);
}
.layout-icon .cell { position: absolute; background: #9aa6b2; border: 1px solid var(--paper); }
.layout-icon .cap { position: absolute; height: 1px; background: #9aa6b2; }

.caption-text { width: 100%; resize: vertical; margin-top: 4px; }

.spread-photos {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.spread-photo {
  position: relative;
  min-width: 0;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  cursor: grab;
}
.spread-photo:hover { border-color: var(--accent); }
.spread-photo.selected { border-color: var(--accent); background: var(--accent-soft); }
.spread-photo img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 2px; background: var(--border); }
.spread-photo.hidden-photo img { opacity: 0.45; filter: grayscale(0.6); }
.spread-photo .remove { top: 4px; right: 4px; width: 20px; height: 20px; font-size: 13px; }
.spread-photo:hover .remove { opacity: 0.95; }

.photo-name { margin: 0 0 6px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zoom { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.zoom input { flex: 1; }
.dpi-readout { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.dpi-readout.warn { color: var(--warn); }

.strip {
  grid-area: strip;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 10px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.strip-item {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border-color: transparent;
  background: transparent;
}
.strip-item.active { border-color: var(--accent); background: var(--accent-soft); }
.strip-item { position: relative; cursor: grab; }
.strip-item.dragging { opacity: 0.4; }
.strip-item.insert-before::before,
.strip-item.insert-after::after {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.strip-item.insert-before::before { left: -7px; }
.strip-item.insert-after::after { right: -7px; }
.strip-label { font-size: 11px; color: var(--muted); }
/* The space between two thumbnails. Its "+" button is wider than the gap
   (overlapping the thumbnails' edges a little) so it's easy to hit, and
   only shows on hover. */
.strip-gap { flex: none; position: relative; align-self: stretch; width: 0; margin-inline: -5px; } /* nets the strip's 10px gap */
.strip-insert {
  position: absolute;
  inset: 0 auto 0 -11px;
  z-index: 1;
  width: 22px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  opacity: 0;
  cursor: pointer;
}
.strip-insert:hover,
.strip-insert:focus-visible { opacity: 1; }
.strip-insert span {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  color: var(--accent-fg);
  background: var(--accent);
}
.strip-add { flex: none; align-self: stretch; min-width: 90px; font-size: 13px; border-style: dashed; }

@media (max-width: 900px) {
  body.editing { overflow: auto; }
  .editor {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 60vh auto auto auto;
    grid-template-areas: "bar" "stage" "strip" "inspector" "sidebar";
    height: auto;
  }
  .sidebar, .inspector { border: 0; border-top: 1px solid var(--border); }
  .sidebar-resize { display: none; }
  .editor-bar { flex-wrap: wrap; }
  .title-input { width: 100%; order: 5; }
}

/* ---- Spread rendering --------------------------------------------------------------- */

.spread-view { position: relative; flex: none; overflow: hidden; }
.spread-view > * { position: absolute; }
.spread-view.interactive { box-shadow: 0 2px 14px #0000002e; background: var(--desk); }

.page { background: var(--paper); }
.cover {
  z-index: 2;
  background: repeating-linear-gradient(135deg, #ecebe7, #ecebe7 8px, #e4e3df 8px, #e4e3df 16px);
}
.cover-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 13px;
  color: #8b8a85;
  pointer-events: none;
}
.spread-view.interactive .page.left { box-shadow: inset -12px 0 14px -14px #0005; }
.spread-view.interactive .page.right { box-shadow: inset 12px 0 14px -14px #0005; }

/* The old spread, while the next one's photos finish loading (briefly). */
.canvas.leaving { pointer-events: none; }
.slot { overflow: hidden; }
.slot img { position: absolute; max-width: none; pointer-events: none; user-select: none; }
.slot.empty { background: #e9e8e4; }
.slot.missing { background: repeating-linear-gradient(45deg, #eee, #eee 6px, #e2e2e2 6px, #e2e2e2 12px); }
.spread-view.interactive .slot { cursor: pointer; }
.spread-view.interactive .slot.filled.selected { cursor: grab; }
.spread-view.interactive .slot.filled.selected:active { cursor: grabbing; }
.spread-view.interactive .slot.empty {
  background: #ecebe7;
  outline: 1px dashed #a9a8a2;
  outline-offset: -1px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spread-view.interactive .slot.empty::after { content: "+"; font-size: 28px; color: #9c9b95; font-weight: 300; }
/* Rings are drawn by a pseudo-element above the photo; an outline on the
   slot itself can end up painted underneath the positioned <img>. */
.spread-view.interactive .slot.selected::before,
.spread-view.interactive .slot.drop-target::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.spread-view.interactive .slot.selected::before {
  box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 0 3px #ffffff80;
}
.spread-view.interactive .slot.drop-target::before {
  box-shadow: inset 0 0 0 3px var(--accent);
  background: var(--accent-soft);
}
.spread-view.interactive .page.selected { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.slot-note {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #6b6b66;
}

.dpi-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: #fff;
  pointer-events: none;
}
.dpi-badge.low { background: #8a5a00e6; }
.dpi-badge.poor { background: #b3261ee6; }
/* A draft: the screenshot's crop, faded, with a dashed outline and a label,
   so it can't be mistaken for a placed photo. */
/* The caption from the screenshot, enlarged so its small text is legible. */
.caption-hint { margin: 6px 0; }
.caption-hint img { display: block; width: 100%; image-rendering: auto; background: #fff; border: 1px solid var(--border); border-radius: 4px; }
.caption-hint figcaption { margin-top: 3px; font-size: 12px; color: var(--muted); }
.slot.draft img { opacity: 0.55; filter: saturate(0.6); }
.slot.draft::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.5px dashed #ffffffcc;
  pointer-events: none;
}
/* Matching progress, beside the spread navigation. */
.match-status { margin-left: 10px; font-size: 12px; color: var(--muted); }
.draft-matches { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.draft-candidates { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.draft-candidate { display: flex; flex-direction: column; gap: 2px; padding: 3px; font-size: 12px; }
.draft-candidate img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 3px; }
.draft-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: #fff;
  background: #3a3937d9;
  pointer-events: none;
}

.caption {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.25;
  white-space: pre-wrap;
  overflow: visible;
  /* Must match the font embedded in the PDF, with no kerning or ligatures
     (the PDF uses plain advance widths). */
  font-family: "Pho Sans", sans-serif;
  font-kerning: none;
  font-variant-ligatures: none;
  font-synthesis: none;
  pointer-events: none;
  z-index: 2;
}
.caption.dark { color: #1d1d1b; }
.caption.light { color: #fff; text-shadow: 0 1px 2px #0008; }
.caption.placeholder { opacity: 0.35; }
.caption.laid-out { display: block; }
.caption-line { position: absolute; white-space: pre; }
.hint.warn { color: var(--warn); }

.bleed-mask { background: var(--bleed-mask); pointer-events: none; z-index: 3; }
.trim-line { border: 1px solid #0000002a; pointer-events: none; z-index: 3; }
.safe-line { border: 1px dashed #2f5d8a40; pointer-events: none; z-index: 3; }
.gutter-line { border-left: 1px dashed #00000038; pointer-events: none; z-index: 3; }

/* ---- Sign-in popup ---------------------------------------------------------------------- */

.popup-message { max-width: 480px; margin: 20vh auto 0; padding: 0 16px; text-align: center; color: var(--muted); }

/* ---- Swapping photos and the right-click menu ---------------------------------- */

.spread-view.interactive .slot.swap-source::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  box-shadow: inset 0 0 0 3px #f08a4b;
  background: #f08a4b26;
}
.canvas.swapping .spread-view.interactive .slot,
.canvas.swapping .spread-view.interactive .slot.filled.selected { cursor: crosshair; }
.canvas.drag-swapping .spread-view.interactive .slot,
.canvas.drag-swapping .spread-view.interactive .slot.filled.selected { cursor: grabbing; }

/* Beside the pointer while dragging a photo: "Hold Shift to swap". */
.drag-hint {
  position: fixed;
  z-index: 50;
  transform: translate(14px, 18px);
  padding: 3px 8px;
  border-radius: 6px;
  background: #000000a6;
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}
.drag-hint.under-ghost { transform: translate(-50%, 0); }
.drag-hint[hidden] { display: none; }
.drag-ghost {
  position: fixed;
  z-index: 49;
  transform: translate(-50%, -50%) rotate(-3deg);
  object-fit: cover;
  border: 3px solid #fff;
  border-radius: 3px;
  box-shadow: 0 8px 24px #00000059;
  opacity: 0.9;
  pointer-events: none;
}
.drag-ghost[hidden] { display: none; }

.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 180px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px #0003;
}
.context-menu button {
  padding: 7px 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  font-size: 14px;
}
.context-menu button:hover,
.context-menu button:focus-visible { background: var(--accent-soft); outline: none; }
