/* Tarnwick Locks — an open ledger on a lilac desk.
   Desk #B8B2D4 · paper #F8F6FB · ink #16131F · second ink #4A4560 · moss green #2C6A3A (open, selected, links) · red #8E1F2B (errors).
   No gradients, no shadows. Closed = ink panel + the word "Closed". */

@view-transition { navigation: auto; }

:root {
  --desk: #B8B2D4;
  --paper: #F8F6FB;
  --ink: #16131F;
  --ink-2: #4A4560;
  --green: #2C6A3A;
  --red: #8E1F2B;
  --rule: #CFCBD8;
  --tint: #ECE9F3;
  --serif: 'Libre Caslon Text', Georgia, 'Times New Roman', serif;
  --sans: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pad: clamp(20px, 3.2vw, 48px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 400 1rem/1.55 var(--sans);
  font-variant-numeric: tabular-nums;
}
body.is-locked { overflow: hidden; }
img, svg { display: block; max-width: 100%; }
a { color: var(--green); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip { position: absolute; left: 12px; top: -60px; z-index: 30; background: var(--ink); color: var(--paper); padding: 10px 14px; }
.skip:focus { top: 12px; }

/* ---------- desk ---------- */
.desk { padding: 18px clamp(16px, 2.4vw, 32px) 28px; }
.top {
  max-width: 1440px; margin: 0 auto 16px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap;
}
.brand-line { margin: 0; display: flex; align-items: baseline; gap: 6px 14px; flex-wrap: wrap; }
.brand { font: 700 1.5rem/1.1 var(--serif); color: var(--ink); text-decoration: none; }
.sub { font-size: 0.9375rem; }
.menu-btn { display: none; }

/* ---------- ledger ---------- */
.ledger {
  max-width: 1440px; margin: 0 auto;
  display: grid; grid-template-columns: 1fr 1fr;
  position: relative;
}
.verso, .recto {
  background: var(--paper);
  border: 1px solid var(--ink);
  border-bottom: 4px double var(--ink);
  padding: 28px var(--pad) 24px;
  min-width: 0;
  position: relative;
  display: flex; flex-direction: column;
}
.verso { grid-column: 1; grid-row: 1; border-right: none; }
.recto { grid-column: 2; grid-row: 1; view-transition-name: recto; outline: none; }
/* the fold: a stitched line down the middle */
.ledger::after {
  content: ''; position: absolute; top: 18px; bottom: 22px; left: 50%;
  border-left: 2px dotted var(--ink-2);
}
.run {
  display: flex; justify-content: space-between; gap: 16px;
  margin: 0 0 28px; padding-bottom: 8px; border-bottom: 1px solid var(--ink);
  font: italic 400 0.9375rem/1.3 var(--serif);
}
.folio { margin: auto 0 0; padding-top: 40px; font: italic 400 1rem/1 var(--serif); color: var(--ink-2); }
.recto .folio { text-align: right; }

/* page head */
.ph { margin-bottom: 36px; }
h1 { font: 400 clamp(2.25rem, 1.5rem + 2.2vw, 3.25rem)/1.06 var(--serif); letter-spacing: -0.01em; margin: 0 0 14px; }
.lede { font-size: 1.125rem; line-height: 1.5; margin: 0; max-width: 34em; color: var(--ink-2); }
h2 { font: 700 1.375rem/1.2 var(--serif); margin: 0 0 14px; }
h3 { font: 400 1.5rem/1.2 var(--serif); margin: 0 0 12px; }
.sec { margin-top: 44px; }
.sec:first-of-type { margin-top: 0; }
.big { font: 400 1.625rem/1.3 var(--serif); margin: 0 0 18px; max-width: 26em; }
.small { font-size: 0.875rem; color: var(--ink-2); margin: 12px 0 0; max-width: 40em; }
p { max-width: 40em; }
.run, .idx-h, .folio { max-width: none; }

/* ---------- verso: contents + lock index ---------- */
.contents ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; column-gap: 28px; }
.ci {
  display: grid; grid-template-columns: 2.1em 1fr; column-gap: 6px; align-items: baseline;
  padding: 7px 0 8px; border-bottom: 1px solid var(--rule);
  color: var(--ink); text-decoration: none;
}
.fol { font: italic 400 0.9375rem/1 var(--serif); color: var(--ink-2); }
.ct { font-weight: 600; }
.cn { grid-column: 2; font-size: 0.8125rem; color: var(--ink-2); }
.ci:hover .ct { text-decoration: underline; text-underline-offset: 0.18em; }
.ci[aria-current="page"] .ct { color: var(--green); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.22em; }

.lockidx { margin-top: 32px; }
.idx-h { margin: 0 0 4px; padding-bottom: 8px; border-bottom: 1px solid var(--ink); font: italic 400 0.9375rem/1.3 var(--serif); }
.lockidx ol { list-style: none; margin: 0; padding: 0; }
.li {
  display: grid; grid-template-columns: 2.4em 1fr auto 6.6em; align-items: center; column-gap: 12px;
  padding: 6px 0 7px; border-bottom: 1px solid var(--rule);
  color: var(--ink); text-decoration: none;
}
.li-n { font: 400 1.5rem/1 var(--serif); }
.li-name { font-weight: 500; }
.li-fall { font-size: 0.875rem; color: var(--ink-2); }
.li:hover .li-name { text-decoration: underline; text-underline-offset: 0.18em; }
.li.is-cur .li-n, .li.is-cur .li-name { color: var(--green); }
.li.is-cur .li-name { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.22em; }

/* status marks — never colour alone */
.st { justify-self: start; display: inline-block; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.02em; padding: 2px 8px; border: 1px solid currentColor; line-height: 1.4; }
.st-open { color: var(--green); }
.st-restricted { color: var(--ink); font-style: italic; }
.st-closed { color: var(--paper); background: var(--ink); border-color: var(--ink); }

/* plates */
.plate { margin: 36px 0 0; }
.plate img { width: 100%; height: auto; max-height: 440px; object-fit: cover; border: 1px solid var(--ink); }
.plate figcaption { font-size: 0.875rem; margin-top: 8px; color: var(--ink-2); }
.plate-n { font: italic 400 0.9375rem/1 var(--serif); color: var(--ink); margin-right: 6px; }

/* ---------- recto pieces ---------- */
.kv { margin: 0; border-top: 1px solid var(--ink); }
.kv > div { display: grid; grid-template-columns: minmax(9em, 2fr) 3fr; column-gap: 18px; padding: 9px 0 10px; border-bottom: 1px solid var(--rule); }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; }

.notes { margin: 0; padding-left: 1.2em; }
.notes li { margin: 0 0 8px; max-width: 40em; }

.lines { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--ink); }
.lines a {
  display: grid; grid-template-columns: 2.2em 1fr 6.6em; align-items: center; column-gap: 14px;
  padding: 10px 0 11px; border-bottom: 1px solid var(--rule); color: var(--ink); text-decoration: none;
}
.ll-n { font: 400 1.75rem/1 var(--serif); }
.ll-t { font-weight: 600; }
.ll-s { display: block; font-weight: 400; font-size: 0.9375rem; color: var(--ink-2); }
.lines a:hover .ll-t { color: var(--green); text-decoration: underline; text-underline-offset: 0.18em; }
.lines .st { justify-self: end; }

.tools { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--ink); }
.tools a { display: block; padding: 12px 0 13px; border-bottom: 1px solid var(--rule); color: var(--ink); text-decoration: none; }
.tool-t { display: block; font: 700 1.125rem/1.3 var(--serif); color: var(--green); }
.tool-x { display: block; color: var(--ink-2); }
.tools a:hover .tool-t { text-decoration: underline; text-underline-offset: 0.18em; }

/* drawings */
.drawing { margin: 0; }
.draw-box { overflow-x: auto; padding-top: 12px; padding-bottom: 12px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--rule); }
.drawing figcaption { font-size: 0.875rem; color: var(--ink-2); margin-top: 8px; max-width: 40em; }
.drawing svg { width: 100%; height: auto; }
svg .pond, svg .water { fill: var(--desk); }
svg .lvl { fill: none; stroke: var(--ink); stroke-width: 1.5; }
svg .ground { fill: none; stroke: var(--ink); stroke-width: 1.5; }
svg .wall { fill: none; stroke: var(--ink); stroke-width: 3; }
svg .cope { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 2 4; }
svg .gate { fill: var(--ink); }
svg .dim { fill: none; stroke: var(--ink-2); stroke-width: 1; }
svg .lbl { font: 400 13px var(--sans); fill: var(--ink); }
svg .num { font: 400 16px var(--serif); fill: var(--ink); }
svg .num.is-cur { fill: var(--green); font-weight: 700; }
svg .canal { stroke: var(--ink); stroke-width: 2; }
svg .lockmark { fill: var(--ink); }
svg .moor { fill: var(--green); }
.section .water { transform: translateY(var(--rise)); transition: transform var(--fill-dur, 2.8s) cubic-bezier(0.45, 0, 0.55, 1); }
.section.is-full .water { transform: translateY(0); }

.num-pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 22px; }
.num-btn {
  font: 400 1.125rem/1 var(--serif); color: var(--ink); background: var(--paper);
  border: 1px solid var(--ink); min-width: 44px; min-height: 44px; padding: 0 8px; cursor: pointer;
}
.num-btn:hover { background: var(--tint); }
.num-btn[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: var(--paper); }
.section-fig { margin-bottom: 22px; }
.section-fig figcaption { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 0.9375rem; color: var(--ink); }

/* tables */
.tbl-box { overflow-x: auto; padding-top: 8px; border-top: 1px solid var(--ink); }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px 10px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.tbl thead th { font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); padding-top: 4px; }
.tbl tbody th { font-weight: 500; }
.tbl.moor tbody th { min-width: 9em; }
.tbl.moor td { white-space: normal; }
.tbl.moor td.nw { white-space: nowrap; }
.tbl td { white-space: nowrap; }
.tbl td.wrap { white-space: normal; }
.tbl .nw { white-space: nowrap; }
.tbl .num { text-align: right; padding-right: 0; }
.tbl tfoot th, .tbl tfoot td { font-weight: 700; border-bottom: 1px solid var(--ink); }
.t-n { font: 400 1.125rem/1 var(--serif); display: inline-block; min-width: 1.6em; }
.was { color: var(--ink-2); }
.tbl tr.is-now th, .tbl tr.is-now td { background: var(--tint); }
.tbl tr.is-no th, .tbl tr.is-no td { color: var(--red); }
.tbl tr.is-cur th .t-n { color: var(--green); }
.tag { font-size: 0.8125rem; font-weight: 600; color: var(--green); margin-left: 4px; }

/* forms */
.calc, .filters { display: grid; gap: 18px 24px; margin: 0 0 36px; padding: 20px 0 24px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--rule); }
.calc { grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); align-items: start; }
.calc .actions, .calc fieldset { grid-column: 1 / -1; }
.filters { grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); align-items: start; margin-bottom: 18px; }
.field { margin: 0; padding: 0; border: none; min-width: 0; }
fieldset.field { display: grid; gap: 6px; }
.field > label, .field > legend, .field .label { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
.hint { margin: -2px 0 6px; font-size: 0.875rem; color: var(--ink-2); }
.input-row { display: flex; align-items: center; gap: 8px; }
input[type="number"], input[type="text"], input[type="search"], select {
  font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid var(--ink); border-radius: 0; padding: 9px 10px; min-height: 44px;
  width: 100%; max-width: 15rem;
}
select { appearance: none; padding-right: 30px; background-image: none; }
.field:has(select) { position: relative; }
.field:has(select)::after { content: ''; position: absolute; right: 12px; bottom: 19px; width: 7px; height: 7px; border-right: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); transform: rotate(45deg); pointer-events: none; }
.filters .field:has(select)::after, .calc .field:has(select)::after { right: auto; left: calc(min(100%, 15rem) - 20px); }
input[aria-invalid="true"] { border-color: var(--red); border-width: 2px; }
.unit { color: var(--ink-2); }
::placeholder { color: var(--ink-2); opacity: 1; }
.radio { display: flex; align-items: center; gap: 10px; min-height: 36px; cursor: pointer; }
.radio input { width: 18px; height: 18px; margin: 0; accent-color: var(--green); }
.err { margin: 6px 0 0; font-size: 0.9375rem; font-weight: 600; color: var(--red); }
.actions { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }

.btn {
  font: 600 0.9375rem/1 var(--sans); color: var(--ink); background: var(--paper);
  border: 1px solid var(--ink); min-height: 44px; padding: 0 18px; cursor: pointer;
}
.btn:hover { background: var(--tint); }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-ink:hover { background: var(--ink-2); }
.toggle {
  font: 600 0.9375rem/1 var(--sans); color: var(--ink); background: var(--paper);
  border: 1px solid var(--ink); min-height: 44px; padding: 0 16px; cursor: pointer; width: 100%; max-width: 15rem; text-align: left;
}
.toggle[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: var(--paper); }

.count { font-weight: 600; margin: 0 0 10px; }
.empty { padding: 18px 0 20px; border-top: 1px solid var(--ink); }
.empty p { margin: 0 0 12px; }

.result { margin-top: 0; }
.warn { margin: 0 0 18px; padding: 12px 0 12px 1.2em; border-top: 2px solid var(--red); color: var(--red); font-weight: 600; }
.warn li { margin-bottom: 4px; }
.out-list { margin: 0 0 18px; padding: 0; list-style: none; border-top: 1px solid var(--ink); }
.out-list li { padding: 10px 0 11px; border-bottom: 1px solid var(--rule); }

/* stoppage calendar */
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr)); gap: 24px 28px; margin-top: 14px; }
.month { border-collapse: collapse; width: 100%; }
.month caption { text-align: left; font: 700 1.0625rem/1.3 var(--serif); padding-bottom: 6px; }
.month th { font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); padding: 4px 0 6px; text-align: center; }
.month td { padding: 1px; text-align: center; }
.day {
  width: 100%; min-width: 30px; min-height: 32px; font: 400 0.875rem/1 var(--sans); color: var(--ink);
  background: var(--paper); border: 1px solid transparent; cursor: pointer; padding: 0;
}
.day:hover { border-color: var(--ink); }
.day.is-closed { background: var(--ink); color: var(--paper); }
.day.is-today { font-weight: 700; text-decoration: underline; text-underline-offset: 0.2em; }
.day[aria-pressed="true"] { outline: 2px solid var(--green); outline-offset: 0; border-color: var(--paper); }

/* questions */
.faq { padding-top: 8px; border-top: 1px solid var(--ink); }
.faq details { border-bottom: 1px solid var(--rule); }
.faq summary { cursor: pointer; padding: 13px 0 14px; font: 700 1.0625rem/1.35 var(--serif); list-style: none; display: flex; justify-content: space-between; gap: 16px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: '+'; font: 400 1.25rem/1 var(--sans); color: var(--green); }
.faq details[open] summary::after { content: '−'; }
.faq details p { margin: 0 0 16px; }

/* footer */
.foot { max-width: 1440px; margin: 16px auto 0; display: flex; justify-content: space-between; gap: 6px 24px; flex-wrap: wrap; font-size: 0.9375rem; }
.foot p { margin: 0; }
.foot a { color: var(--ink); }

/* index sheet (narrow screens) */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(22, 19, 31, 0.5); display: flex; justify-content: flex-start; }
.sheet[hidden] { display: none; }
.sheet-panel { background: var(--paper); width: min(26rem, 92vw); height: 100%; overflow-y: auto; padding: 18px 22px 28px; border-right: 1px solid var(--ink); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--ink); }
.sheet-head h2 { margin: 0; }
.sheet-list { list-style: none; margin: 0; padding: 0; }

/* ---------- one page at a time ---------- */
@media (max-width: 1180px) {
  .ledger { grid-template-columns: minmax(0, 1fr); max-width: 780px; }
  .ledger::after { display: none; }
  .verso, .recto { grid-column: 1; }
  .recto { grid-row: 1; }
  .verso { grid-row: 2; border-right: 1px solid var(--ink); border-top: none; }
  .menu-btn {
    display: inline-flex; align-items: center; font: 600 0.9375rem/1 var(--sans); color: var(--paper); background: var(--ink);
    border: 1px solid var(--ink); min-height: 44px; padding: 0 18px; cursor: pointer;
  }
  .top, .foot { max-width: 780px; }
  .top { flex-wrap: nowrap; align-items: center; }
  .brand-line { min-width: 0; }
  .menu-btn { flex: none; }
}
@media (max-width: 560px) {
  .contents ol { grid-template-columns: 1fr; }
  .kv > div { grid-template-columns: 1fr; row-gap: 2px; }
  .lines a { grid-template-columns: 2em 1fr; }
  .lines .st { grid-column: 2; justify-self: start; margin-top: 6px; }
  .li { grid-template-columns: 2.2em 1fr 6.6em; }
  .li-fall { display: none; }
  .big { font-size: 1.375rem; }
  .draw-box svg { min-width: 540px; }
  .tbl-box .tbl { min-width: 520px; }
  .tbl-box.wide .tbl { min-width: 640px; }
  .run span + span { text-align: right; }
  /* will it fit: one lock per block, so the verdict stays on screen */
  .tbl-box .tbl.tbl-stack { min-width: 0; }
  .tbl-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tbl-stack tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 12px; padding: 10px 0 11px; border-bottom: 1px solid var(--rule); }
  .tbl-stack th, .tbl-stack td { border: 0; padding: 0; }
  .tbl-stack tbody th { grid-column: 1 / -1; padding-bottom: 6px; }
  .tbl-stack td[data-k]::before { content: attr(data-k); display: block; font-size: 0.8125rem; color: var(--ink-2); }
  .tbl-stack td[data-k]::after { content: " m"; }
  .tbl-stack td.fit-r { grid-column: 1 / -1; padding-top: 6px; font-weight: 600; }
}

/* ---------- motion 1: page turn (cross-document view transition, 300 ms) ---------- */
::view-transition-old(root), ::view-transition-new(root) { animation: none; }
::view-transition-group(recto) { animation-duration: 0s; }
::view-transition-old(recto) { animation: none; }
::view-transition-new(recto) { animation: turn 300ms var(--ease) both; }
@keyframes turn { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  .section .water { transition: none; }
}
