/* Saltiva chart room — classical nautical chart theme.
   Vellum paper, iron-gall ink, portolan red and verdigris rhumb lines, gilt for cartouches. */
:root {
  --vellum: #e4d6b2;
  --vellum-hi: #efe4c6;
  --vellum-deep: #cbb685;
  --land: #d3bf8c;
  --ink: #2a1f16;
  --ink-soft: #5b4733;
  --ink-faint: rgba(42, 31, 22, 0.18);
  --rubric: #9b2c22;
  --verdigris: #2f6e62;
  --gilt: #a5803a;
  --sea-wash: #c9c7a4;
  --night: #1d2a2c;
  --display: 'IM Fell English', 'IM Fell DW Pica', Georgia, serif;
  --body: 'EB Garamond', Garamond, Georgia, serif;
  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.3rem;
  --step-2: 1.65rem;
  --step-3: 2.2rem;
  --step-4: 3.1rem;
  --nav-h: 56px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--vellum);
  color: var(--ink);
  font-family: var(--body);
  font-size: var(--step-0);
  line-height: 1.55;
  font-variant-numeric: oldstyle-nums proportional-nums;
  min-height: 100vh;
}

/* Paper grain + foxing + vignette: one fixed layer, drawn once, no animation. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  background:
    radial-gradient(ellipse at 20% 15%, rgba(140, 95, 40, 0.10), transparent 40%),
    radial-gradient(ellipse at 85% 80%, rgba(120, 80, 30, 0.12), transparent 45%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(70, 45, 15, 0.28) 100%),
    url('/img/grain.svg');
  mix-blend-mode: multiply;
}

a { color: var(--rubric); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--rubric); outline-offset: 2px; }

h1, h2, h3, h4 { font-family: var(--display); font-weight: 400; line-height: 1.15; margin: 0 0 0.5em; letter-spacing: 0.005em; }
h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }
p { margin: 0 0 1em; max-width: 72ch; }
small, .fine { font-size: var(--step--1); color: var(--ink-soft); }
.num { font-variant-numeric: lining-nums tabular-nums; }
em.latin { font-family: var(--display); font-style: italic; }

/* ---------- Top bar: a chart's neat line ---------- */
.neatline {
  position: sticky; top: 0; z-index: 500;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0 1.25rem;
  background: var(--vellum-hi);
  border-bottom: 1px solid var(--ink);
  box-shadow: 0 3px 0 -2px var(--ink);
}
.neatline .mark { display: flex; align-items: center; gap: 0.55rem; text-decoration: none; color: var(--ink); font-family: var(--display); font-size: 1.35rem; white-space: nowrap; }
.neatline .mark svg { width: 30px; height: 30px; }
.neatline nav { display: flex; gap: 0.15rem; overflow-x: auto; scrollbar-width: none; flex: 1; }
.neatline nav::-webkit-scrollbar { display: none; }
.neatline nav a {
  font-family: var(--display); font-size: 1.05rem; color: var(--ink-soft); text-decoration: none;
  padding: 0.35rem 0.7rem; white-space: nowrap; border-radius: 2px;
}
.neatline nav a:hover { color: var(--ink); background: rgba(42, 31, 22, 0.06); }
.neatline nav a[aria-current='page'] { color: var(--rubric); box-shadow: inset 0 -2px 0 var(--rubric); }
.neatline .who { font-size: var(--step--1); color: var(--ink-soft); white-space: nowrap; }
.neatline .who button { font: inherit; background: none; border: 0; color: var(--rubric); cursor: pointer; padding: 0 0 0 0.4rem; text-decoration: underline; }

/* ---------- Page body ---------- */
.folio { max-width: 1180px; margin: 0 auto; padding: 2.5rem 1.25rem 5rem; }
.folio.wide { max-width: 1480px; }
.lede { font-size: var(--step-1); color: var(--ink-soft); max-width: 62ch; }

/* Cartouche: the ornamental frame classical charts use for their title. The one bold device. */
.cartouche {
  position: relative;
  padding: 1.6rem 2rem 1.4rem;
  background: var(--vellum-hi);
  border: 1px solid var(--ink);
  outline: 4px double var(--gilt);
  outline-offset: 5px;
  margin: 10px;
}
.cartouche::before, .cartouche::after {
  content: '❦'; position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 1.4rem; color: var(--gilt); background: var(--vellum); padding: 0 2px; line-height: 1;
}
.cartouche::before { left: -19px; }
.cartouche::after { right: -19px; transform: translateY(-50%) scaleX(-1); }

/* Section: chart-legend style, a ruled heading with a scale bar under it. */
.section { margin: 3.2rem 0 0; }
.section > h2 { display: flex; align-items: baseline; gap: 0.8rem; }
.section > h2::after { content: ''; flex: 1; height: 7px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink);
  background: repeating-linear-gradient(90deg, var(--ink) 0 22px, transparent 22px 44px); background-size: 44px 3px; background-repeat: repeat-x; background-position: 0 1px; opacity: 0.75; }

.grid { display: grid; gap: 1.2rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }

/* Soundings: figures set like depth soundings on a chart — numeral first, small italic gloss. */
.soundings { display: flex; flex-wrap: wrap; gap: 0.6rem 2.4rem; margin: 1.4rem 0; }
.sounding { min-width: 9rem; }
.sounding b { display: block; font-family: var(--display); font-weight: 400; font-size: var(--step-3); line-height: 1; font-variant-numeric: lining-nums; }
.sounding span { font-style: italic; color: var(--ink-soft); font-size: var(--step--1); }

/* Ledger: tables written as a ship's log. */
.ledger-wrap { overflow-x: auto; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); margin: 1rem 0; }
table.ledger { width: 100%; border-collapse: collapse; font-size: 0.97rem; }
.ledger th { font-family: var(--display); font-weight: 400; text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--ink); white-space: nowrap; position: sticky; top: 0; background: var(--vellum-hi); cursor: default; }
.ledger th[data-sort] { cursor: pointer; }
.ledger th[data-sort]:hover { color: var(--rubric); }
.ledger td { padding: 0.42rem 0.6rem; border-bottom: 1px dotted var(--ink-faint); vertical-align: top; }
.ledger td.r, .ledger th.r { text-align: right; font-variant-numeric: lining-nums tabular-nums; }
.ledger tr:hover td { background: rgba(165, 128, 58, 0.09); }
.ledger tr.clickable { cursor: pointer; }

.note { border-left: 3px solid var(--verdigris); padding: 0.4rem 0 0.4rem 1rem; margin: 1rem 0; color: var(--ink-soft); font-style: italic; max-width: 75ch; }
.warn { border-left-color: var(--rubric); }
.tag { display: inline-block; font-size: 0.8rem; padding: 0 0.45rem; border: 1px solid currentColor; border-radius: 2px; margin: 0 0.25rem 0.25rem 0; color: var(--ink-soft); max-width: 100%; overflow-wrap: anywhere; }
.tag.red { color: var(--rubric); }
.tag.green { color: var(--verdigris); }
.tag.gilt { color: var(--gilt); }
.src { font-size: 0.8rem; color: var(--ink-soft); }
.src a { color: var(--ink-soft); }

.plate { background: var(--vellum-hi); border: 1px solid rgba(42, 31, 22, 0.55); padding: 1.1rem 1.25rem; box-shadow: 2px 3px 0 rgba(42, 31, 22, 0.12); }
.plate h3 { margin-bottom: 0.3rem; }

/* Controls */
button.btn, a.btn, select.btn, input.field, textarea.field, select.field {
  font: inherit; font-size: 0.97rem; color: var(--ink); background: var(--vellum-hi);
  border: 1px solid var(--ink); border-radius: 2px; padding: 0.38rem 0.75rem;
}
button.btn, a.btn { cursor: pointer; text-decoration: none; display: inline-block; }
button.btn:hover, a.btn:hover { background: var(--ink); color: var(--vellum-hi); }
button.btn.primary { background: var(--rubric); border-color: var(--rubric); color: var(--vellum-hi); }
button.btn.primary:hover { background: var(--ink); border-color: var(--ink); }
.seg { display: inline-flex; border: 1px solid var(--ink); border-radius: 2px; overflow: hidden; }
.seg button { font: inherit; font-size: 0.92rem; border: 0; background: var(--vellum-hi); color: var(--ink); padding: 0.32rem 0.75rem; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--ink); }
.seg button[aria-pressed='true'] { background: var(--ink); color: var(--vellum-hi); }
input.field, textarea.field, select.field { width: 100%; }
textarea.field { min-height: 5rem; resize: vertical; }
label.lab { display: block; font-size: var(--step--1); color: var(--ink-soft); margin: 0.6rem 0 0.2rem; font-style: italic; }

/* ---------- Map pages ---------- */
.chart-page { height: calc(100vh - var(--nav-h)); height: calc(100dvh - var(--nav-h)); position: relative; overflow: hidden; }
.chart-page .map { position: absolute; inset: 0; background: var(--vellum); }
.maplibregl-canvas { outline: none; }
.maplibregl-ctrl-attrib { background: rgba(239, 228, 198, 0.7) !important; font-family: var(--body); }
.maplibregl-ctrl-group { background: var(--vellum-hi) !important; border: 1px solid var(--ink) !important; border-radius: 2px !important; box-shadow: none !important; }

.chart-tools { position: absolute; top: 14px; left: 14px; z-index: 20; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; max-width: calc(100% - 28px); }
.chart-legend { position: absolute; left: 14px; bottom: 14px; z-index: 20; background: rgba(239, 228, 198, 0.94); border: 1px solid var(--ink); padding: 0.6rem 0.8rem; font-size: 0.88rem; max-width: 300px; }
.chart-legend .row { display: flex; align-items: center; gap: 0.5rem; }
.chart-legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1.5px solid var(--ink); }

/* Logbook side panel */
.logbook {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(460px, 100%); z-index: 30;
  background: var(--vellum-hi); border-left: 1px solid var(--ink); box-shadow: -6px 0 0 -5px var(--ink), -14px 0 30px rgba(42, 31, 22, 0.18);
  overflow-y: auto; padding: 1.2rem 1.3rem 3rem;
  transform: translateX(105%); transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.logbook.open { transform: none; }
.logbook .close { position: sticky; top: 0; float: right; font-size: 1.6rem; line-height: 1; background: var(--vellum-hi); border: 0; cursor: pointer; color: var(--ink); padding: 0 0.2rem; }
.logbook h2 { font-size: var(--step-2); margin-right: 2rem; }
.logbook dl { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: 0.25rem 0.8rem; margin: 0.8rem 0; font-size: 0.95rem; }
.logbook dt { font-style: italic; color: var(--ink-soft); }
.logbook dd { margin: 0; overflow-wrap: anywhere; }
.voyage { border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); padding: 0.7rem 0; margin: 1rem 0; }
.voyage ol { list-style: none; padding: 0; margin: 0.5rem 0 0; position: relative; }
.voyage ol::before { content: ''; position: absolute; left: 6px; top: 8px; bottom: 8px; border-left: 2px dashed var(--rubric); }
.voyage li { position: relative; padding: 0.1rem 0 0.35rem 1.6rem; }
.voyage li::before { content: ''; position: absolute; left: 1px; top: 0.55rem; width: 12px; height: 12px; border-radius: 50%; background: var(--vellum-hi); border: 2px solid var(--rubric); }
.voyage li.end::before { background: var(--rubric); }
.log-entry { border-bottom: 1px dotted var(--ink-faint); padding: 0.45rem 0; font-size: 0.94rem; }
.log-entry .meta { color: var(--ink-soft); font-style: italic; font-size: 0.85rem; }

.list-panel { position: absolute; top: 60px; left: 14px; bottom: 120px; width: 330px; z-index: 19; background: rgba(239, 228, 198, 0.95); border: 1px solid var(--ink); display: flex; flex-direction: column; }
.list-panel .head { padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--ink); }
.list-panel .items { overflow-y: auto; flex: 1; }
.list-panel .item { padding: 0.45rem 0.7rem; border-bottom: 1px dotted var(--ink-faint); cursor: pointer; font-size: 0.93rem; line-height: 1.3; }
.list-panel .item:hover { background: rgba(165, 128, 58, 0.14); }
.list-panel .item small { display: block; }
.list-panel.hidden { display: none; }

/* Ocean names on the chart, set in italic Fell like a 17th-century engraver would. */
.sea-label { font-family: var(--display); font-style: italic; color: rgba(42, 31, 22, 0.55); font-size: 15px; letter-spacing: 0.25em; pointer-events: none; white-space: nowrap; text-shadow: 0 0 3px var(--vellum); }
.sea-label.big { font-size: 20px; letter-spacing: 0.4em; }

/* Compass rose: draws itself once when a chart opens. */
.rose { position: absolute; right: 18px; bottom: 26px; width: 150px; height: 150px; z-index: 10; pointer-events: none; opacity: 0.85; }
.rose path, .rose circle, .rose line { stroke-dasharray: 600; stroke-dashoffset: 600; animation: ink 2.4s ease-out forwards; }
.rose .fill { animation: fillin 1.2s 1.6s ease-out forwards; opacity: 0; }
@keyframes ink { to { stroke-dashoffset: 0; } }
@keyframes fillin { to { opacity: 1; } }

.popup-card { font-family: var(--body); font-size: 0.92rem; }
.maplibregl-popup-content { background: var(--vellum-hi) !important; border: 1px solid var(--ink); border-radius: 2px !important; box-shadow: 3px 3px 0 rgba(42, 31, 22, 0.2) !important; padding: 0.55rem 0.8rem !important; }
.maplibregl-popup-tip { border-top-color: var(--ink) !important; border-bottom-color: var(--ink) !important; }

.loading { position: absolute; inset: 0; display: grid; place-items: center; z-index: 50; background: var(--vellum); font-family: var(--display); font-style: italic; font-size: 1.3rem; color: var(--ink-soft); transition: opacity 0.6s; }
.loading.done { opacity: 0; pointer-events: none; }

.prose h3 { margin-top: 1.6em; }
.prose ul { max-width: 72ch; padding-left: 1.2rem; }
.prose li { margin-bottom: 0.3em; }
.prose table { border-collapse: collapse; margin: 1rem 0; font-size: 0.95rem; display: block; overflow-x: auto; }
.prose th, .prose td { border-bottom: 1px dotted var(--ink-faint); padding: 0.35rem 0.6rem; text-align: left; vertical-align: top; }
.prose th { font-family: var(--display); font-weight: 400; border-bottom: 1px solid var(--ink); }
.prose blockquote { border-left: 3px solid var(--verdigris); margin: 1rem 0; padding: 0.2rem 1rem; color: var(--ink-soft); }
.prose code { font-size: 0.9em; background: rgba(42, 31, 22, 0.06); padding: 0 0.25em; }

.toc { position: sticky; top: calc(var(--nav-h) + 1rem); align-self: start; font-size: 0.93rem; max-height: calc(100vh - var(--nav-h) - 2rem); overflow-y: auto; }
.toc a { display: block; color: var(--ink-soft); text-decoration: none; padding: 0.15rem 0; }
.toc a:hover { color: var(--rubric); }
.with-toc { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 2.5rem; }

@media (max-width: 860px) {
  :root { --step-4: 2.3rem; --step-3: 1.8rem; }
  .with-toc { grid-template-columns: 1fr; }
  .toc { position: static; display: none; }
  .list-panel { top: auto; bottom: 0; left: 0; right: 0; width: auto; height: 38vh; }
  .chart-legend { display: none; }
  .rose { width: 90px; height: 90px; bottom: 40vh; }
  .neatline .who { display: none; }
  .logbook dl { grid-template-columns: 6.5rem minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.maplibregl-popup.hover-pop { pointer-events: none; }

/* Fact lists from the research data: label column at the top level, stacked when nested deeper. */
dl.facts { display: grid; grid-template-columns: 14rem minmax(0, 1fr); gap: 0.2rem 1rem; margin: 0.3rem 0; }
dl.facts.sub { grid-template-columns: 11rem minmax(0, 1fr); }
dl.facts.stack { display: block; }
dl.facts dt { font-style: italic; color: var(--ink-soft); }
dl.facts.stack dt { margin-top: 0.35rem; }
dl.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
dl.facts ul { padding-left: 1.1rem; margin: 0.2rem 0; }
@media (max-width: 860px) { dl.facts, dl.facts.sub { display: block; } dl.facts dt { margin-top: 0.35rem; } }
