/* An 1910-plate look: aged cream paper, hatched sea, flat chromolithograph
   possessions, engraved type, and a ruled degree frame around the sheet. */

:root {
  --paper: #f6ecd0;
  --paper-2: #efe3c2;
  --paper-3: #fbf5e4;
  --sea: #cfe0dc;
  --sea-line: #bcd3cf;
  --land: #fbf6e8;
  --ink: #2a2620;
  --ink-2: #4b4436;
  --faint: #8b8067;
  --rule: #b9ab8b;
  --water-ink: #55707c;
  --warn: #a3602c;
  --panel-w: 21.5rem;
  --frame: 26px;
  --shadow: 0 1px 2px rgba(45, 38, 25, .10), 0 10px 30px rgba(45, 38, 25, .12);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.5 "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

#app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  height: 100dvh;
  transition: grid-template-columns .3s ease;
}
#app.panel-closed { grid-template-columns: 0 1fr; }
#app.panel-closed #panel { opacity: 0; pointer-events: none; }

/* ── panel ─────────────────────────────────────────────────────────────────── */
#panel {
  overflow: hidden auto;
  overscroll-behavior: contain;
  min-width: 0;
  background: var(--paper);
  border-right: 1px solid var(--ink);
  box-shadow: inset -3px 0 0 -2px var(--rule);
  padding: 1.25rem 1.15rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.05rem;
  transition: opacity .2s ease;
}
#masthead h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: .26em;
  text-transform: uppercase;
  font-weight: 500;
}
#masthead h1 span {
  display: block;
  font-size: .56rem;
  letter-spacing: .38em;
  color: var(--faint);
  font-style: italic;
  text-transform: uppercase;
  margin-top: .4rem;
}
#masthead .sub { margin: .7rem 0 0; font-size: .77rem; color: var(--ink-2); line-height: 1.6; }

.search { position: relative; }
#search {
  width: 100%;
  font: inherit;
  font-size: .85rem;
  padding: .48rem .6rem;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper-3);
  color: var(--ink);
}
#search:focus { outline: 1px solid var(--ink); outline-offset: 1px; }
#results {
  list-style: none;
  margin: .3rem 0 0;
  padding: 0;
  max-height: 15rem;
  overflow-y: auto;
  border: 1px solid var(--rule);
  background: var(--paper-3);
}
#results li { padding: .36rem .55rem; cursor: pointer; font-size: .8rem; border-bottom: 1px solid var(--paper-2); }
#results li:last-child { border-bottom: 0; }
#results li:hover { background: var(--paper-2); }
#results em { color: var(--faint); font-size: .73rem; }

#selection {
  position: relative;
  background: var(--paper-3);
  border: 1px solid var(--ink);
  padding: .75rem .85rem;
  box-shadow: 3px 3px 0 -1px var(--paper-2), 3px 3px 0 0 var(--rule);
}
#selection h2 { margin: 0 1.2rem .1rem 0; font-size: 1.02rem; font-weight: 500; letter-spacing: .02em; }
#selection p { margin: .3rem 0 0; font-size: .79rem; line-height: 1.55; }
#sel-terra { color: var(--ink-2); font-style: italic; }
#sel-meta { color: var(--faint); font-size: .71rem; letter-spacing: .05em; }
#deselect { position: absolute; top: .25rem; right: .3rem; border: 0; background: none; cursor: pointer; font-size: 1.05rem; line-height: 1; color: var(--faint); }

details > summary {
  cursor: pointer;
  font-size: .66rem;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--ink-2);
  border-bottom: 1px solid var(--ink);
  padding-bottom: .3rem;
  list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: " +"; }
details[open] > summary::after { content: " –"; }

#views, #layers, #legend { list-style: none; margin: .55rem 0 0; padding: 0; }
#views li button {
  width: 100%; text-align: left;
  font: inherit; font-size: .81rem;
  background: none; border: 0; cursor: pointer;
  padding: .26rem .25rem;
  color: var(--ink-2);
}
#views li button:hover { background: var(--paper-2); color: var(--ink); }
#layers li { font-size: .81rem; padding: .14rem 0; }
#layers label { display: flex; gap: .55rem; align-items: center; cursor: pointer; }

/* inked boxes, ticked with a cross, as on a printed reference */
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  margin: 0; flex: none;
  width: .95rem; height: .95rem;
  border: 1px solid var(--ink);
  background: var(--paper-3);
  box-shadow: 1px 1px 0 -0.5px var(--rule);
  display: grid; place-content: center;
  cursor: pointer;
  transition: background .12s ease;
}
input[type="checkbox"]::after {
  content: "✕";
  font-size: .74rem; line-height: 1; color: var(--ink);
  transform: scale(0) rotate(-12deg);
  transition: transform .14s cubic-bezier(.3, 1.4, .5, 1);
}
input[type="checkbox"]:checked { background: var(--paper-2); }
input[type="checkbox"]:checked::after { transform: scale(1) rotate(-6deg); }
input[type="checkbox"]:hover { background: var(--paper-2); }
input[type="checkbox"]:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
#layers label:has(:checked) { color: var(--ink); }
#layers label:has(:not(:checked)) { color: var(--faint); }
.hint { color: var(--faint); font-size: .71rem; font-style: italic; }

#legend li { display: grid; grid-template-columns: 1.5rem 1fr; gap: .5rem; padding: .26rem 0; font-size: .79rem; align-items: start; }
#legend i { display: block; height: .78rem; margin-top: .16rem; border: .5px solid var(--ink); }
#legend em { display: block; color: var(--faint); font-size: .71rem; font-style: italic; line-height: 1.4; }

.foot { font-size: .71rem; color: var(--ink-2); line-height: 1.55; margin: 0; }
.foot.dim { color: var(--faint); }
.foot.legal { font-size: .62rem; color: var(--faint); line-height: 1.5; letter-spacing: .01em; }
.foot.links { font-size: .72rem; color: var(--ink-2); }
.foot.byline { font-size: .62rem; color: var(--faint); letter-spacing: .04em; }
.foot.byline a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--rule); }
.foot.byline a:hover { color: var(--ink-2); border-bottom-color: var(--ink-2); }
#about-link, #sources-link {
  font: inherit; font-size: inherit;
  background: none; border: 0; padding: 0;
  color: inherit; cursor: pointer;
  border-bottom: 1px dotted var(--rule);
  white-space: nowrap;
}
#about-link:hover, #sources-link:hover { color: var(--ink); border-bottom-color: var(--ink); }

/* ── dialogs: about, sources ───────────────────────────────────────────────── */
dialog.plate {
  max-width: 36rem; width: calc(100vw - 2.5rem);
  max-height: 82dvh; overflow: auto;
  padding: 1.6rem 1.7rem 1.5rem;
  border: 1px solid var(--ink);
  background: var(--paper-3);
  color: var(--ink);
  box-shadow: 5px 5px 0 -1px var(--paper-2), 5px 5px 0 0 var(--rule);
}
dialog.plate::backdrop { background: rgba(42, 38, 32, .45); }
dialog.plate h2 {
  margin: 0 0 .9rem; font-size: .72rem; letter-spacing: .3em;
  text-transform: uppercase; font-weight: 500; color: var(--ink-2);
  border-bottom: 1px solid var(--rule); padding-bottom: .5rem;
}
dialog.plate h3 {
  margin: 1.1rem 0 .35rem; font-size: .64rem; letter-spacing: .22em;
  text-transform: uppercase; font-weight: 500; color: var(--faint);
}
dialog.plate p { margin: 0 0 .8rem; font-size: .82rem; line-height: 1.65; }
dialog.plate p:last-child { margin-bottom: 0; }
dialog.plate p.lede { color: var(--ink-2); font-style: italic; }
dialog.plate ul { margin: 0; padding: 0; list-style: none; }
dialog.plate li {
  font-size: .8rem; line-height: 1.6;
  padding: .3rem 0 .3rem .9rem; position: relative;
  border-bottom: 1px solid var(--paper-2);
}
dialog.plate li:last-child { border-bottom: 0; }
dialog.plate li::before { content: "—"; position: absolute; left: 0; color: var(--rule); }
dialog.plate a { color: inherit; border-bottom: 1px dotted var(--rule); text-decoration: none; }
dialog.plate a:hover { border-bottom-color: var(--ink); }
.dialog-close {
  position: absolute; top: .5rem; right: .6rem;
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 1.3rem; line-height: 1; color: var(--faint);
}
.dialog-close:hover { color: var(--ink); }

/* ── stage: the sheet ──────────────────────────────────────────────────────── */
#stage {
  position: relative;
  overflow: hidden;
  background:
    repeating-linear-gradient(to bottom, var(--sea-line) 0 .5px, transparent .5px 4px),
    var(--sea);
}
#map { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
#app.loading #map { opacity: 0; }

/* Mid-gesture the two heaviest hairline layers step aside; they come back the
   moment the sheet settles. */
#map #scene.interacting #physical .river,
#map #scene.interacting #terra-src { display: none; }

/* ── map paint ─────────────────────────────────────────────────────────────── */
#map .world-bg { fill: none; }   /* the hatched sea comes from the stage behind */
#map .land { fill: var(--land); }
#map .polity { fill-opacity: 1; }
#map .coast { fill: none; stroke: #3b342a; stroke-linejoin: round; }
#map .lake { fill: var(--sea); stroke: #6f8f93; stroke-width: .5px; }
#map .river { fill: none; stroke: #7d9aa0; stroke-width: .7px; stroke-linejoin: round; stroke-linecap: round; }
#map .terra-border { fill: none; stroke: #6a6152; stroke-width: .6px; opacity: .8; }
#map .anti-border { fill: none; stroke: #2a2620; stroke-width: 1.5px; stroke-linejoin: round; }
#map .graticule { fill: none; stroke: #5d5648; stroke-width: .5px; opacity: .55; }
#map .parallel { fill: none; stroke: #4a4336; stroke-width: .7px; stroke-dasharray: 1 3; opacity: .85; }
#map .rail { fill: none; stroke: var(--ink); stroke-width: 1.6px; }
#map .rail-ties { fill: none; stroke: var(--paper-3); stroke-width: 1.3px; stroke-dasharray: 1.4 4; }
#map .liner { fill: none; stroke: #33302a; stroke-width: .9px; stroke-dasharray: 1 3.5; opacity: .85; }
#map .hidden { display: none; }

#map .marks circle.dot { fill: var(--ink); stroke: var(--land); stroke-width: .8; }
#map .marks circle.site { fill: var(--land); stroke: var(--ink); stroke-width: 1.1; }
#map .marks circle.seat { fill: var(--land); stroke: var(--ink); stroke-width: 2; }
#map .marks path.peak { fill: var(--ink); stroke: var(--land); stroke-width: .5; }
#map .marks .hit { fill: transparent; cursor: pointer; }
#map .marks .halo { fill: none; stroke: #a3602c; stroke-width: 1.5; opacity: 0; }
#map .marks .place.on .halo, #map .marks .place:hover .halo { opacity: 1; }

#map text {
  paint-order: stroke;
  stroke: var(--land);
  stroke-width: 2.4px;
  stroke-opacity: .75;
  stroke-linejoin: round;
  fill: var(--ink);
  font-size: 11.5px;
  cursor: pointer;
  user-select: none;
}
#map text .sub { font-size: 8.5px; font-style: italic; fill: var(--faint); pointer-events: none; }
#map text.polity { font-size: 17px; letter-spacing: .5em; text-transform: uppercase; font-style: normal; stroke-width: 3.4px; }
#map text.polity .sub { font-size: 9px; letter-spacing: .08em; text-transform: none; }
#map text.province { font-size: 10.5px; letter-spacing: .32em; text-transform: uppercase; fill: #3d3729; }
#map text.province .sub { letter-spacing: .02em; text-transform: none; }
#map text.water, #map text.ocean, #map text.ocean-note { fill: var(--water-ink); font-style: italic; }
#map text.ocean { font-size: 13px; letter-spacing: .62em; stroke: none; text-transform: uppercase; font-style: normal; }
#map text.ocean-note { font-size: 10.5px; letter-spacing: .12em; stroke: none; }
#map text.note { font-size: 9.5px; font-style: italic; fill: var(--faint); letter-spacing: .08em; }
#map text.site { font-size: 10px; font-style: italic; }
#map text.seat { font-size: 12.5px; font-weight: 600; }
#map text.on { fill: #8a4a12; }
#map .warn { fill: var(--warn); font-size: 8.5px; }

/* the ruled degree frame */
#map .frame-band { fill: var(--paper-3); }
#map .frame-rule { fill: none; stroke: var(--ink); }
#map .frame-tick { stroke: var(--ink); stroke-width: 1; }
#map .frame-label {
  font-size: 9px; fill: var(--ink); stroke: none; letter-spacing: .04em;
  font-style: normal; pointer-events: none; cursor: default;
}
#map .parallel-label { font-size: 9.5px; font-style: italic; fill: #4a4336; stroke: none; letter-spacing: .1em; pointer-events: none; }

/* ── chrome ────────────────────────────────────────────────────────────────── */
#controls {
  position: absolute; top: calc(var(--frame) + .6rem); right: calc(var(--frame) + .6rem);
  display: flex; flex-direction: column; gap: .25rem;
}
#controls button, #panel-toggle, #cartouche-toggle {
  width: 1.9rem; height: 1.9rem;
  font: inherit; font-size: .95rem; line-height: 1;
  background: var(--paper-3);
  border: 1px solid var(--ink); border-radius: 0;
  color: var(--ink); cursor: pointer;
  box-shadow: 2px 2px 0 -1px var(--rule);
}
#controls button:hover { background: var(--paper-2); }

#plate-no {
  position: absolute; top: calc(var(--frame) + .5rem); left: calc(var(--frame) + .7rem);
  font-size: .72rem; letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink-2);
}


#readout {
  position: absolute; left: calc(var(--frame) + .7rem); bottom: calc(var(--frame) + .7rem);
  display: flex; align-items: center; gap: .7rem;
  font-size: .66rem; color: var(--ink-2);
  background: var(--paper-3);
  border: 1px solid var(--ink);
  padding: .25rem .5rem;
  box-shadow: 2px 2px 0 -1px var(--rule);
  pointer-events: none;
}
#scalebar { display: flex; align-items: center; gap: .4rem; }
#scalebar i { display: block; height: .38rem; border: 1px solid var(--ink-2); border-top: 0; width: 4rem; }
#coords { font-variant-numeric: tabular-nums; color: var(--faint); }

#panel-toggle, #cartouche-toggle {
  position: absolute;
  width: auto; padding: 0 .6rem; height: 1.7rem;
  font-size: .64rem; letter-spacing: .16em; text-transform: uppercase;
}
/* a drawer tab on the sheet's left edge, so it never fights the plate number */
#panel-toggle {
  left: 0; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: .45rem;
  width: auto; min-width: 1.9rem;
  height: auto; padding: 1.15rem .5rem;
  font-size: .66rem; letter-spacing: .24em; line-height: 1.2;
  border-left: 0;
  box-shadow: 2px 2px 0 -1px var(--rule);
}
#panel-toggle span { writing-mode: vertical-rl; text-orientation: mixed; display: block; }
#panel-toggle::after { content: "‹"; font-size: .85rem; line-height: 1; color: var(--faint); }
#app.panel-closed #panel-toggle::after { content: "›"; }
#panel-toggle:hover { background: var(--paper-2); }
#panel-toggle:hover::after { color: var(--ink); }
#cartouche-toggle { right: calc(var(--frame) + .6rem); top: calc(var(--frame) + 7.2rem); }
#app.cartouche-closed #cartouche { display: none; }
#app.cartouche-closed #cartouche-toggle { color: var(--faint); }

/* ── the title cartouche ───────────────────────────────────────────────────── */
#cartouche {
  position: absolute; right: calc(var(--frame) + 1.2rem); bottom: calc(var(--frame) + 1.2rem);
  width: 21rem; margin: 0; padding: .85rem 1rem 1rem;
  background: rgba(251, 245, 228, .93);
  border: 1px solid var(--ink);
  box-shadow: 3px 3px 0 -1px var(--paper-2), 3px 3px 0 0 var(--rule);
  text-align: center;
}
#cartouche h2 { margin: 0; font-size: 1.5rem; letter-spacing: .3em; font-weight: 500; text-indent: .3em; }
#cartouche .rubric { margin: .2rem 0 0; font-size: .7rem; letter-spacing: .1em; }
#cartouche .rubric span { font-style: italic; letter-spacing: 0; text-transform: none; }
#cartouche .date { margin: .1rem 0 .55rem; font-size: .72rem; font-style: italic; color: var(--ink-2); }
#cartouche .ref-head { margin: 0 0 .35rem; font-size: .62rem; letter-spacing: .3em; text-transform: uppercase; border-top: 1px solid var(--rule); padding-top: .4rem; }

#cartouche-legend {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: .1rem .7rem;
  text-align: left;
}
#cartouche-legend li { display: grid; grid-template-columns: 1.1rem 1fr; gap: .35rem; align-items: center; font-size: .66rem; line-height: 1.35; }
#cartouche-legend i { display: block; height: .62rem; border: .5px solid var(--ink); }
#cartouche-legend em { display: none; }

.routes-key { list-style: none; margin: .5rem 0 0; padding: .4rem 0 0; border-top: 1px solid var(--rule); text-align: left; }
.routes-key li { display: grid; grid-template-columns: 2.6rem 1fr; gap: .4rem; align-items: center; font-size: .62rem; font-style: italic; color: var(--ink-2); line-height: 1.5; }
.routes-key i { display: block; height: 0; border-top: 1px solid var(--ink); }
.routes-key i.k-rail { border-top-style: solid; border-top-width: 1.5px; }
.routes-key i.k-liner { border-top-style: dotted; }
.routes-key .warn { color: var(--warn); font-style: normal; text-align: center; }

#tooltip {
  position: absolute; pointer-events: none;
  background: #2a2620ee; color: #f6ecd0;
  font-size: .7rem; padding: .25rem .45rem;
  transform: translate(-50%, -170%);
  white-space: nowrap; z-index: 5;
}
#tooltip em { color: #cfc4a6; font-style: italic; }

/* ── narrow ────────────────────────────────────────────────────────────────── */
@media (max-width: 880px) {
  :root { --frame: 18px; }
  #app, #app.panel-closed { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  #stage { grid-row: 1; }
  #panel {
    position: absolute; z-index: 10;
    left: 0; right: 0; bottom: 0;
    max-height: 76dvh;
    border-right: 0;
    border-top: 1px solid var(--ink);
    box-shadow: 0 -6px 24px rgba(45, 38, 25, .18);
    padding: .5rem 1rem calc(2rem + env(safe-area-inset-bottom));
    transition: transform .28s ease, opacity .2s ease;
    touch-action: pan-y;
  }
  /* a paper tab to grab the sheet by */
  #panel::before {
    content: ""; flex: none;
    width: 2.6rem; height: 3px;
    margin: .1rem auto .5rem;
    background: var(--rule);
    position: sticky; top: 0;
  }
  #app.panel-closed #panel { transform: translateY(calc(100% + 2rem)); }

  /* room for a thumb */
  #controls { gap: .4rem; }
  #controls button { width: 2.4rem; height: 2.4rem; font-size: 1.15rem; }
  #panel-toggle, #cartouche-toggle { height: 2.1rem; font-size: .68rem; padding: 0 .8rem; }
  #search { font-size: 16px; padding: .6rem; }           /* 16px keeps iOS from zooming */
  #results li { padding: .6rem .6rem; font-size: .86rem; }
  #views li button { padding: .55rem .3rem; font-size: .88rem; }
  #layers li { padding: .34rem 0; font-size: .88rem; }
  #layers label { gap: .7rem; }
  input[type="checkbox"] { width: 1.25rem; height: 1.25rem; }
  input[type="checkbox"]::after { font-size: .95rem; }
  #legend li { padding: .4rem 0; font-size: .84rem; }
  details > summary { padding: .3rem 0 .4rem; font-size: .7rem; }
  #selection { padding: .9rem 1rem; }
  #deselect { font-size: 1.5rem; top: .3rem; right: .5rem; padding: .2rem .4rem; }
  @media (pointer: coarse) { #map .marks .hit { r: 17px; } }
  /* back to a plain button up top — a vertical tab makes no sense on a sheet */
  #panel-toggle {
    left: calc(var(--frame) + .6rem); top: calc(var(--frame) + .6rem);
    transform: none; flex-direction: row; gap: .4rem;
    min-width: 0; height: 2.1rem; padding: 0 .8rem;
    border-left: 1px solid var(--ink); letter-spacing: .16em;
  }
  #panel-toggle span { writing-mode: horizontal-tb; }
  #panel-toggle::after { content: none; }
  #cartouche-toggle { left: calc(var(--frame) + .6rem); right: auto; top: calc(var(--frame) + 3.1rem); }
  #app:not(.panel-closed) #panel-toggle { opacity: .5; }
  #plate-no { display: none; }
  #readout { bottom: calc(var(--frame) + .5rem); left: calc(var(--frame) + .5rem); }
  #app:not(.panel-closed) #readout { display: none; }
  #scalebar i { width: 3rem; }

  #cartouche { right: auto; left: 50%; transform: translateX(-50%); bottom: calc(var(--frame) + 2.6rem); width: min(19rem, calc(100vw - 2.5rem)); padding: .5rem .6rem .6rem; }
  #app.cartouche-closed #cartouche, #app:not(.panel-closed) #cartouche { display: none; }
  #cartouche h2 { font-size: 1.05rem; letter-spacing: .22em; }
  #cartouche .rubric { font-size: .6rem; }
  #cartouche .date { font-size: .62rem; margin-bottom: .4rem; }
  #cartouche .ref-head { font-size: .55rem; }
  #cartouche-legend li { font-size: .58rem; grid-template-columns: .9rem 1fr; }
  .routes-key li { font-size: .55rem; grid-template-columns: 2.2rem 1fr; }
  #map .parallel-label { font-size: 8.5px; }

  #map text { font-size: 10.5px; }
  #map text .sub { font-size: 8px; }
  #map text.polity { font-size: 12.5px; letter-spacing: .3em; }
  #map text.polity .sub { font-size: 8.5px; }
  #map text.province { font-size: 9px; letter-spacing: .2em; }
  #map text.ocean { font-size: 10px; letter-spacing: .35em; }
  #map text.ocean-note { font-size: 9px; }
  #map text.seat { font-size: 11px; }
  #map .frame-label { font-size: 8px; }
}
@media (max-width: 880px) and (orientation: landscape) {
  #panel { max-height: 90dvh; width: 23rem; right: auto; }
}
