/* Royal-blue editorial theme: serif display type on a saturated blue canvas,
   the CUT emblem in white line art, navy solid + white outline buttons. */

:root {
  --blue: #3150D9;
  --navy: #0B1040;
  --ink: #0A0C1C;
  --white: #FFFFFF;
  --line: rgba(255, 255, 255, 0.35);
  --muted: rgba(255, 255, 255, 0.78);
  --gold: #E4B85C;
  --paper: #FBFAF6;
  --rule: #D6DCF4;
  --margin-red: #E08A8A;
  --serif: "Cormorant Garamond", "EB Garamond", Garamond, "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Inter", "Segoe UI", system-ui, Arial, sans-serif;
  --gutter: clamp(1rem, 4.5vw, 4.5rem);
  /* One shared left/right edge for header, content and footer. */
  --edge: max(var(--gutter), calc((100% - 1560px) / 2 + var(--gutter)));
}

* { box-sizing: border-box; }

/* Elements styled with their own display (like .btn) must still disappear when hidden. */
[hidden] { display: none !important; }

.visually-hidden,
.js .file-pick input[type="file"] {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--blue);
  color: var(--white);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

::selection { background: var(--gold); color: var(--ink); }

a { color: inherit; }

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------------- */
/* Header: links split around a centred emblem                             */
/* ---------------------------------------------------------------------- */

.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 2rem;
  padding: 1.6rem var(--edge);
}

.nav {
  display: flex;
  align-items: center;
  gap: clamp(1.25rem, 3vw, 3rem);
  flex-wrap: wrap;
}

.nav-left { justify-self: start; }
.nav-right { justify-self: end; }

.nav a:not(.btn) {
  font-size: 1.02rem;
  font-weight: 500;
  text-decoration: none;
  text-underline-offset: 6px;
}

.nav a:not(.btn):hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
}

.emblem {
  width: 48px;
  height: 48px;
  color: var(--white);
  flex-shrink: 0;
}

.wordmark {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.32em;
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                  */
/* ---------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.95rem 2rem;
  font-family: var(--sans);
  font-size: 1.02rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  border: 1.5px solid transparent;
  border-radius: 0;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.btn-outline {
  background: transparent;
  color: var(--white);
  border-color: var(--white);
}

.btn-outline:hover {
  background: var(--white);
  color: var(--blue);
}

.btn-solid {
  background: var(--navy);
  color: var(--white);
  border-color: var(--navy);
}

.btn-solid:hover {
  background: var(--ink);
  border-color: var(--ink);
}

/* ---------------------------------------------------------------------- */
/* Flash messages                                                          */
/* ---------------------------------------------------------------------- */

.flashes {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0 var(--edge);
}

.flashes li {
  padding: 0.85rem 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-left: 3px solid var(--gold);
}

.flashes li + li { margin-top: 0.5rem; }

/* ---------------------------------------------------------------------- */
/* Home                                                                     */
/* ---------------------------------------------------------------------- */

.hero {
  flex: 1;
  min-height: min(760px, calc(100vh - 110px));
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  align-items: center;
  gap: 3rem;
  padding: 2rem var(--edge) 4rem;
}

.hero h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(3rem, 6.6vw, 6.8rem);
  line-height: 0.98;
  letter-spacing: -0.01em;
  margin: 0 0 1.25rem;
}

.lede {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.4rem, 2.2vw, 2rem);
  line-height: 1.25;
  color: var(--muted);
  margin: 0;
}

.upload-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-top: 2.75rem;
}

input[type="file"] {
  max-width: 100%;
  color: var(--white);
  font-family: var(--sans);
  font-size: 0.95rem;
}

input[type="file"]::file-selector-button {
  margin-right: 1rem;
  padding: 0.95rem 1.5rem;
  background: transparent;
  color: var(--white);
  border: 1.5px solid var(--white);
  border-radius: 0;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease;
}

input[type="file"]::file-selector-button:hover {
  background: var(--white);
  color: var(--blue);
}

.hero-emblem {
  justify-self: center;
}

.hero-emblem .emblem {
  width: clamp(240px, 30vw, 440px);
  height: auto;
}

.hero-emblem .emblem [stroke] { stroke-width: 1.4; }

/* Full-screen progress while a file uploads and is read */

.busy {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: rgba(49, 80, 217, 0.97);
}

.busy[hidden] { display: none; }

.busy-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
  width: min(100%, 30rem);
}

.busy .emblem {
  width: 120px;
  height: 120px;
  margin-bottom: 0.75rem;
}

.busy .emblem [stroke] { stroke-width: 2; }

.busy.is-uploading .emblem,
.busy.is-reading .emblem { animation: spin 8s linear infinite; }

.busy-title {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  font-weight: 600;
  line-height: 1.1;
}

.busy-bar {
  position: relative;
  width: min(100%, 22rem);
  height: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.25);
}

.busy-bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--white);
  transition: width 0.2s ease;
}

.busy.is-reading .busy-bar span {
  width: 35% !important;
  transition: none;
  animation: sweep 1.6s ease-in-out infinite;
}

.busy.is-failed .busy-bar { display: none; }

.busy-detail {
  margin: 0;
  min-height: 1.5em;
  color: var(--muted);
}

.busy-retry { margin-top: 0.75rem; }

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes sweep {
  from { left: -35%; }
  to { left: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .busy.is-uploading .emblem,
  .busy.is-reading .emblem,
  .busy.is-reading .busy-bar span { animation: none; }
  .busy.is-reading .busy-bar span { width: 100% !important; opacity: 0.5; }
}

button:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Instructions under the hero: four steps in a row. Each drawing follows the
   same ledger page from handwriting to typed data, and its ring fills with
   gold to show how far along you are (partials/step_art.html). */

.howto {
  padding: clamp(4rem, 8vw, 7.5rem) var(--edge);
  border-top: 1px solid var(--line);
}

.howto h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.75rem, 4.5vw, 4rem);
  line-height: 1;
  letter-spacing: -0.01em;
  margin: 0 0 clamp(2rem, 4.4vw, 4rem);
}

.howto ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: start;
  gap: 2.5rem 3rem;
}

.howto li {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  min-width: 0;
}

.step-copy { min-width: 0; }

.howto h3 {
  --title-size: clamp(1.75rem, 2.5vw, 2.25rem);
  --num-size: 30px;
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  font-family: var(--serif);
  font-weight: 600;
  font-size: var(--title-size);
  line-height: 1.1;
  margin: 0 0 0.625rem;
}

/* The step number: a solid gold node, like the emblem's. Centred on the
   title's first line, so it stays put when a translation wraps. */
.step-num {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--num-size);
  height: var(--num-size);
  margin-top: calc((var(--title-size) * 1.1 - var(--num-size)) / 2);
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  font-family: var(--sans);
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1;
}

.howto p {
  margin: 0;
  max-width: 38ch;
  font-size: clamp(1rem, 1.25vw, 1.125rem);
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.86);
  text-wrap: pretty;
}

/* White line art at one stroke weight. The track uses the hairline colour;
   gold marks progress and nothing else. */
.step-art {
  display: block;
  flex: none;
  width: clamp(5.5rem, 12vw, 10.5rem);
  height: auto;
  aspect-ratio: 1;
  color: var(--white);
}

.step-art .track { stroke: var(--line); }
.step-art .progress { stroke: var(--gold); }
.step-art .node { fill: var(--gold); }

/* ---------------------------------------------------------------------- */
/* Review page                                                              */
/* ---------------------------------------------------------------------- */

.review {
  padding: 1.5rem var(--edge) 5rem;
}

.review h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.6rem, 5vw, 4.6rem);
  line-height: 1;
  margin: 0 0 0.75rem;
}

.meta {
  margin: 0 0 2.25rem;
  color: var(--muted);
}

.meta .filename {
  color: var(--white);
  font-weight: 600;
  word-break: break-all;
}

/* The editable table sits on a sheet of "ledger paper". */

.sheet {
  max-height: 70vh;
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 12px 12px 0 var(--navy);
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 1rem;
  background: var(--navy);
  color: var(--white);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-align: left;
  text-transform: uppercase;
}

/* Headings read from the page are editable, like the cells. */
thead th:has(input) { padding: 0.45rem 0.5rem; }

thead th input[type="text"] {
  width: 100%;
  min-width: 6rem;
  padding: 0.55rem 0.5rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--white);
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

thead th input[type="text"]:focus {
  outline: none;
  border-color: var(--gold);
}

.table-title {
  display: block;
  width: min(100%, 36rem);
  margin: 0 0 0.9rem;
  padding: 0.3rem 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--white);
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 600;
}

.table-title::placeholder { color: var(--muted); }

.table-title:focus {
  outline: none;
  border-bottom-color: var(--gold);
}

tbody td {
  padding: 0.2rem 0.5rem;
  border-bottom: 1px solid var(--rule);
}

tbody td:first-child { border-right: 2px solid var(--margin-red); }

tbody tr:hover { background: #F1F3FC; }

/* The row being edited stays easy to find. */
tbody tr:focus-within { background: #E6EAFB; }
tbody tr:focus-within td:first-child { box-shadow: inset 4px 0 0 var(--blue); }

td input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.5rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.98rem;
}

td input[type="text"]:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--white);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 2.5rem;
}

/* ---------------------------------------------------------------------- */
/* Upload form                                                              */
/* ---------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: min(100%, 30rem);
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.optional {
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"] {
  padding: 0.7rem 0;
  border: 0;
  border-bottom: 1.5px solid var(--line);
  background: transparent;
  color: var(--white);
  font-family: var(--sans);
  font-size: 1.05rem;
}

.field input::placeholder { color: rgba(255, 255, 255, 0.55); }

.field-hint { font-size: 0.88rem; color: var(--muted); }

.field input:focus {
  outline: none;
  border-bottom-color: var(--gold);
}

.upload-form { flex-direction: column; align-items: flex-start; }

.pick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.file-pick { position: relative; display: inline-flex; }
.no-js .file-pick-btn { display: none; }
.file-pick:focus-within .file-pick-btn { outline: 2px solid var(--gold); outline-offset: 3px; }

.file-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.9rem;
  margin: 0;
  font-weight: 600;
  word-break: break-word;
}

.file-summary img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border: 2px solid var(--white);
}

.file-warning {
  flex-basis: 100%;
  font-weight: 400;
  color: var(--gold);
}

.tip {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
}

/* Recent documents on the home page */

.recent {
  padding: 3rem var(--edge) 0;
  border-top: 1px solid var(--line);
}

.recent h2,
.doc h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.8rem, 2.8vw, 2.5rem);
  line-height: 1;
  margin: 0 0 1.25rem;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.doc-list a {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  height: 100%;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line);
  text-decoration: none;
  transition: background-color 0.18s ease, border-color 0.18s ease;
}

.doc-list a:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--white); }

.doc-name {
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.15;
  word-break: break-word;
}

.doc-meta { font-size: 0.9rem; color: var(--muted); }

/* Phones: a Scan button within thumb reach (shown by app.js) */
.thumb-bar { display: none; }

/* Waiting screen: page thumbnails, tick as each is read */

.busy.is-counting .busy-bar span {
  width: 0;
  animation: none;
}

.busy-pages {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  max-height: 30vh;
  overflow: auto;
  margin: 0.25rem 0 0;
  padding: 0;
}

.busy-pages:empty { display: none; }

.busy-pages li {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 58px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.75rem;
  opacity: 0.55;
  transition: opacity 0.3s ease;
}

.busy-pages img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.busy-pages li.is-done { opacity: 1; border-color: var(--white); }

.busy-pages li.is-done::after {
  content: "✓";
  position: absolute;
  right: 2px;
  bottom: 2px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 600;
}

.busy-note {
  margin: 0;
  font-size: 0.92rem;
}

.busy-tip {
  margin: 0;
  min-height: 1.5em;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--muted);
}

/* Messages with an action (Undo, Change all) */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 60;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  width: max-content;
  max-width: calc(100% - 2rem);
  padding: 0.85rem 1.1rem;
  background: var(--navy);
  color: var(--white);
  border-left: 3px solid var(--gold);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.page-review .toast { bottom: calc(var(--actionbar-h, 5rem) + 1.5rem); }

.toast button,
.link-button {
  padding: 0.35rem 0.2rem;
  border: 0;
  background: none;
  color: var(--gold);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

/* ---------------------------------------------------------------------- */
/* Review page additions                                                    */
/* ---------------------------------------------------------------------- */

.review-head { margin-bottom: 1.5rem; }

.summary {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.review-hint {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.notice {
  margin: 0 0 1.75rem;
  padding: 0.9rem 1.1rem;
  background: rgba(228, 184, 92, 0.18);
  border-left: 3px solid var(--gold);
}

.notice-why {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.doc-name-field { margin-bottom: 2rem; }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
  scroll-margin-top: 1rem;
}

.pager .btn { padding: 0.7rem 1.2rem; }

.pager select,
.viewer-select {
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--white);
  border-radius: 0;
  background: var(--blue);
  color: var(--white);
  font: inherit;
  font-weight: 600;
}

.paged .page:not(.is-current) { display: none; }

.page + .page { margin-top: 4rem; }
.paged .page + .page { margin-top: 0; }

.page-heading {
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(0, 1.5fr);
  gap: 2.25rem;
  align-items: start;
}

.page-grid.no-photo { grid-template-columns: minmax(0, 1fr); }

.page-tables { min-width: 0; }

/* The photo of the page, with zoom; it follows the table while scrolling. */

.viewer {
  position: sticky;
  top: 1rem;
  margin: 0;
}

.viewer-frame {
  /* Room for the zoom buttons above the Save bar. */
  height: max(280px, min(calc(100vh - 19rem), 900px));
  overflow: auto;
  background: var(--white);
  overscroll-behavior: contain;
}

.viewer-frame img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
}

.viewer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.viewer-approx {
  padding: 0.1rem 0.5rem;
  background: var(--gold);
  color: var(--ink);
  font-weight: 600;
}

.viewer-zoom { display: flex; gap: 0.3rem; margin-left: auto; }

.viewer-zoom button {
  min-width: 2.6rem;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid var(--white);
  background: transparent;
  color: var(--white);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.viewer-zoom button:hover { background: var(--white); color: var(--blue); }

.table-block + .table-block { margin-top: 3rem; }

.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-bottom: 0.9rem;
}

.table-tools .table-title { margin: 0; flex: 1 1 18rem; }

/* Cells the reader wasn't sure of (a "?" in them) */
td input.unsure {
  background: #FBE8B8;
  box-shadow: inset 3px 0 0 #D99A1E;
}

td input.unsure:focus { background: #FFF6DC; }

/* Cells holding the word in "Change every…" */
td input.is-match {
  background: #DCE3FF;
  box-shadow: inset 0 0 0 2px var(--blue);
}

/* Insert / delete row buttons, added by app.js */
th.row-tools { width: 1%; }

td.row-tools {
  width: 1%;
  padding: 0 0.25rem;
  white-space: nowrap;
  border-right: 0;
}

.row-tools button {
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid transparent;
  background: transparent;
  color: #6A7090;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.row-tools button:hover { border-color: var(--rule); color: var(--ink); }
.row-tools .row-del:hover { color: #B3261E; }

/* Running totals under columns of numbers */
tfoot td {
  position: sticky;
  bottom: 0;
  padding: 0.75rem 1rem;
  background: #EEF0FA;
  border-top: 2px solid var(--navy);
  font-weight: 600;
  color: var(--ink);
}

tfoot td.total-label {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #4A5070;
}

/* Save stays in reach at the bottom of long pages */
.actionbar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin: 2.5rem calc(-1 * var(--edge)) 0;
  padding: 1rem var(--edge);
  background: var(--blue);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 24px rgba(11, 16, 64, 0.25);
}

.actionbar-summary {
  margin: 0 auto 0 0;
  font-weight: 600;
}

/* "Change every…": a row above the Save bar's buttons, opened by app.js */
.find-bar {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1.5rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.find-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1 1 13rem;
  min-width: 0;
  max-width: 22rem;
}

.find-field input {
  width: 100%;
  padding: 0.5rem 0;
  border: 0;
  border-bottom: 1.5px solid var(--line);
  background: transparent;
  color: var(--white);
  font-family: var(--sans);
  font-size: 1.05rem;
}

.find-field input::placeholder { color: rgba(255, 255, 255, 0.55); }
.find-field input:focus { outline: none; border-bottom-color: var(--gold); }

.find-bar .btn { padding: 0.7rem 1.4rem; }
.find-bar .btn:disabled { opacity: 0.45; cursor: default; }
.find-bar .btn:disabled:hover { background: transparent; color: var(--white); }

.find-close {
  align-self: flex-start;
  margin-left: auto;
  width: 2.4rem;
  height: 2.4rem;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--white);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.find-close:hover { border-color: var(--white); }

.find-foot {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.5rem;
  font-size: 0.92rem;
}

.find-option { display: inline-flex; align-items: center; gap: 0.45rem; cursor: pointer; }
.find-option input { width: 1.05rem; height: 1.05rem; accent-color: var(--gold); }

.find-status { margin: 0 0 0 auto; font-weight: 600; }
.find-link { display: none; }
.find-status .link-button { padding: 0 0.2rem; }

.details {
  margin-top: 3rem;
  color: var(--muted);
}

.details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--white);
}

.details dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1.25rem;
  margin: 1rem 0;
}

.details dt { font-weight: 600; }
.details dd { margin: 0; }
.details .filename { word-break: break-all; }

.straightened { margin: 0; max-width: 520px; }

.straightened figcaption {
  margin-bottom: 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.straightened img {
  display: block;
  width: 100%;
  padding: 0.6rem;
  background: var(--white);
}

/* ---------------------------------------------------------------------- */
/* Document page                                                            */
/* ---------------------------------------------------------------------- */

.doc { padding: 1.5rem var(--edge) 4rem; }

.doc h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.6rem, 5vw, 4.6rem);
  line-height: 1;
  margin: 0 0 0.6rem;
  word-break: break-word;
}

.saved-badge {
  display: inline-block;
  margin: 0 0 1rem;
  padding: 0.3rem 0.8rem;
  background: var(--gold);
  color: var(--ink);
  font-weight: 600;
}

.doc .meta { margin-bottom: 1.75rem; }

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.more-downloads { margin: 1.25rem 0 0.4rem; }
.more-downloads a { font-weight: 600; text-underline-offset: 4px; }

.doc-note {
  max-width: 44rem;
  margin: 0 0 3rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.page-list {
  list-style: none;
  margin: 0 0 3.5rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem 1.5rem;
}

.page-list li {
  display: flex;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.page-list img,
.page-list-blank {
  flex-shrink: 0;
  width: 72px;
  height: 96px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.15);
}

.page-list div { display: flex; flex-direction: column; gap: 0.15rem; }
.page-list-table { font-size: 0.92rem; color: var(--muted); }

.add-page {
  padding-top: 3rem;
  border-top: 1px solid var(--line);
}

.add-page > p { margin: 0 0 0.5rem; color: var(--muted); }
.add-page .upload-form { margin-top: 1.25rem; }


/* ---------------------------------------------------------------------- */
/* Accounts                                                                 */
/* ---------------------------------------------------------------------- */

.account {
  display: flex;
  align-items: center;
  gap: 0.25rem 0.9rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  font-size: 0.92rem;
}

.account-email {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.account form { margin: 0; }
.account .link-button { color: var(--white); }

.framed-note {
  margin: 0 var(--edge) 1rem;
  padding: 0.85rem 1.1rem;
  background: rgba(228, 184, 92, 0.18);
  border-left: 3px solid var(--gold);
}

.framed-note a { font-weight: 600; }

.auth-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 2.75rem 0 1rem;
}

.auth {
  width: min(100%, 34rem + 2 * var(--edge));
  padding: 2rem var(--edge) 5rem;
}

.auth h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.6rem, 5vw, 4rem);
  line-height: 1;
  margin: 0 0 0.75rem;
}

.auth-lede { margin: 0 0 2.25rem; color: var(--muted); }

.auth-form {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.5rem;
}

.auth-form .field { width: 100%; }
.auth-switch { margin: 2rem 0 0; }
.auth-switch a { font-weight: 600; text-underline-offset: 4px; }

.see-all { margin: 1.25rem 0 0; }
.see-all a { font-weight: 600; text-underline-offset: 4px; }


/* Column tools in the headings, page deletion, delete buttons */

.js .rows-form[data-mode="tables"] thead th { white-space: nowrap; }
.js .rows-form[data-mode="tables"] thead th input[type="text"] { display: inline-block; width: calc(100% - 4.4rem); vertical-align: middle; }

.col-tools { display: inline-flex; gap: 0.1rem; vertical-align: middle; }

.col-tools button {
  width: 2rem;
  height: 2rem;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.col-tools button:hover { border-color: rgba(255, 255, 255, 0.5); color: var(--white); }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
}

.delete-page {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.92rem;
  color: var(--muted);
  cursor: pointer;
}

.delete-page input { width: 1.1rem; height: 1.1rem; accent-color: #E5484D; }

.page.is-deleted .page-grid { opacity: 0.3; pointer-events: none; }
.page.is-deleted .page-heading { text-decoration: line-through; }
.page.is-deleted .delete-page { color: var(--white); font-weight: 600; }

.delete-link { margin: 0 0 3rem; }
.delete-link a { color: var(--muted); text-underline-offset: 4px; }
.delete-link a:hover { color: var(--white); }

.btn-danger {
  background: #B3261E;
  color: var(--white);
  border-color: #B3261E;
}

.btn-danger:hover { background: #8C1D17; border-color: #8C1D17; }

/* Language choice in the footer */
.languages {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin-left: auto;
}

.languages span[aria-current] { font-weight: 600; text-decoration: underline; text-underline-offset: 5px; }
.languages a { color: var(--muted); text-decoration: none; }
.languages a:hover { color: var(--white); text-decoration: underline; }

/* ---------------------------------------------------------------------- */
/* Footer                                                                   */
/* ---------------------------------------------------------------------- */

.site-footer {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem var(--edge);
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}

.site-footer p { margin: 0; }

.crest {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--white);
  overflow: hidden;
  background: var(--white);
}

.crest img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------------------------------------------------------------------- */
/* Smaller screens                                                          */
/* ---------------------------------------------------------------------- */

@media (max-width: 900px) {
  .site-header {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 1rem;
  }
  .brand { order: -1; }
  .nav-left, .nav-right { justify-self: center; justify-content: center; }

  .hero { grid-template-columns: 1fr; text-align: center; }
  .hero-emblem { order: -1; }
  .hero-emblem .emblem { width: 180px; }
  .upload-form { justify-content: center; }

  .howto ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .upload-form { align-items: center; }
  .field { text-align: left; }
  .pick { justify-content: center; }

  .page-grid { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
  .viewer { position: static; }
  .viewer-frame { height: 32vh; }
}

@media (max-width: 600px) {
  /* Steps stack, each drawing small beside its text */
  .howto ol { grid-template-columns: 1fr; gap: 1.75rem; }
  .howto li { flex-direction: row; align-items: flex-start; gap: 1.25rem; }
  .step-art { width: 5.5rem; }
  .howto h3 { --title-size: 1.75rem; --num-size: 26px; gap: 0.625rem; }
  .step-num { font-size: 0.8rem; }
  .pick, .pick .btn, .file-pick { width: 100%; }
  .sheet { box-shadow: 6px 6px 0 var(--navy); max-height: 65vh; }

  /* Bigger targets for thumbs, and 16px text so phones don't zoom on focus. */
  .btn { min-height: 48px; }
  input[type="text"], select { font-size: 16px !important; }
  td input[type="text"] { padding: 0.75rem 0.5rem; }
  .row-tools button { width: 2.75rem; height: 2.75rem; }
  .col-tools button { width: 2.5rem; height: 2.5rem; }
  .js .rows-form[data-mode="tables"] thead th input[type="text"] { width: calc(100% - 5.4rem); }
  .viewer-zoom button { min-width: 3rem; min-height: 2.75rem; }
  .nav a:not(.btn) { padding: 0.5rem 0; }

  .page-home .thumb-bar {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    z-index: 20;
    display: flex;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
  .page-home .thumb-bar[hidden] { display: none !important; }

  /* One slim row of buttons; the counts are already at the top of the page. */
  .actionbar { flex-wrap: nowrap; gap: 0.5rem; padding-top: 0.6rem; padding-bottom: 0.6rem; }
  .actionbar .btn { flex: 1 1 0; padding: 0.7rem 0.4rem; font-size: 0.95rem; }
  .actionbar-summary { display: none; }
  .actionbar.is-finding { flex-wrap: wrap; }
  #find-open { display: none; }
  .find-link { display: inline-block; }
  .find-bar { position: relative; gap: 0.6rem 1rem; }
  .find-field { flex: 1 1 9rem; max-width: none; }
  .find-field:first-of-type { flex-basis: 100%; padding-right: 3rem; }
  .find-bar .btn { flex: 0 0 auto; }
  .find-close { position: absolute; top: 0; right: 0; margin: 0; }
  .find-status { margin-left: 0; flex: 1 1 auto; }
  .page-review .toast { bottom: calc(var(--actionbar-h, 4rem) + 1.5rem); }
  .page-home .site-footer { padding-bottom: 6rem; }

  .site-footer { flex-wrap: wrap; }
  .account { justify-content: center; }
  .account-email { max-width: 12rem; }
  .auth-cta .btn, .auth-form .btn { width: 100%; }
  .languages { margin-left: 0; flex-basis: 100%; }
  .doc-actions .btn { flex: 1 1 auto; }
}
