/* The Red Book of Westmarch
   Layout: a full-bleed inked map with a manuscript-style chronicle at the
   right and a calendar rail along the foot.
   A deliberately single-theme design: vellum and iron-gall ink, with red
   rubrication as in the old books. Night falls on the map itself, not the page. */

:root {
  --vellum: #f0e4c6;
  --vellum-deep: #e2d0a4;
  --vellum-edge: #c9b27c;
  --sea: #e4dcc3;
  --ink: #2e2115;
  --ink-soft: #5e4a33;
  --ink-faint: #8a7555;
  --rubric: #9b2616;
  --gold: #a57a1c;
  --leaf: #4d5e2a;
  --shadow: rgba(46, 33, 21, 0.28);
  --panel-bg: #f5ecd5;

  --display: 'IM Fell English', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --caps: 'IM Fell English SC', 'IM Fell English', Georgia, serif;
  --body: 'EB Garamond', 'Iowan Old Style', Palatino, Georgia, serif;

  --panel-w: 360px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #d9c79c;
  color: var(--ink);
  font: 16px/1.45 var(--body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--rubric); outline-offset: 2px; }

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  padding-top: env(safe-area-inset-top, 0px);
}

/* ——— Stage & map ——— */
#stage { position: relative; overflow: hidden; min-width: 0; background: #d9c79c; }
#tiles { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; transform-origin: 0 0; }
.labels { pointer-events: none; }
.lbl { paint-order: stroke; stroke: rgba(240, 228, 198, 0.78); stroke-width: calc(var(--u, 1) * 3px); stroke-linejoin: round; }
.sheet-name { font-family: var(--display); fill: var(--ink); text-anchor: middle; }
.sheet-name.italic { font-style: italic; }
.sheet-name.caps { font-family: var(--caps); letter-spacing: calc(var(--u, 1) * 3px); fill: var(--rubric); }
.sheet-name.red { font-family: var(--caps); fill: var(--rubric); }
.sheet-name.water { fill: #2f4452; }
.forest-name.lbl { stroke-width: calc(var(--u, 1) * 3.5px); }
#map:active { cursor: grabbing; }

.paper-outer { fill: #d3bd8c; }
.paper { fill: var(--vellum); }
.paper-mottle { fill: var(--vellum); }
.sea { fill: var(--sea); }
.ripple-ink { fill: none; stroke: #4f5a5c; stroke-linejoin: round; }
.ripple-gap { fill: none; stroke: var(--sea); stroke-linejoin: round; }
.waves { fill: none; stroke: #6d7470; stroke-width: 0.7; opacity: 0.55; }
.coast { fill: none; stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; }
.island { fill: var(--vellum); stroke: var(--ink); stroke-width: 1.1; }
.lake { fill: var(--sea); }
.lake-shore { fill: none; stroke: var(--ink); stroke-width: 1; stroke-linejoin: round; }
.river { fill: none; stroke: #2f4452; stroke-linecap: round; stroke-linejoin: round; opacity: 0.9; }
.river-bank { fill: none; stroke: #2f4452; stroke-linecap: round; stroke-linejoin: round; }
.river-water { fill: none; stroke: var(--sea); stroke-linecap: round; stroke-linejoin: round; }
.road { fill: none; stroke: #8a4a2a; stroke-width: 0.9; stroke-dasharray: 4 2.5; opacity: 0.8; }
.tufts { fill: none; stroke: #45552f; stroke-width: 0.5; opacity: 0.9; }
.pools { fill: none; stroke: #2f4452; stroke-width: 0.8; opacity: 0.7; }
.tuft { fill: none; stroke: #6e6a3c; stroke-width: 0.45; opacity: 0.75; stroke-linecap: round; }
.tuft.sparse { opacity: 0.45; }
.ash { fill: none; stroke: #3b1f16; stroke-width: 1.1; stroke-linecap: round; opacity: 0.5; }
.mordor-tint { fill: #9a5a3a; opacity: 0.13; }
.mordor-hatch { opacity: 0.3; }
.hill { fill: var(--vellum); stroke: var(--ink-soft); stroke-width: 0.75; stroke-linecap: round; stroke-linejoin: round; }
.hill.faint { opacity: 0.45; fill: none; }
.hill.named { stroke-width: 1.1; stroke: var(--ink); }
.hill-shade { fill: none; stroke: var(--ink-soft); stroke-width: 0.5; opacity: 0.8; }
.tree .crown { fill: #e5d8b0; stroke: #34361b; stroke-width: 0.5; stroke-linejoin: round; }
.tree .shade { fill: #9f9a6b; stroke: none; }
.tree .trunk { fill: none; stroke: #34361b; stroke-width: 0.55; }
.tree.dark .crown { fill: #a3a06c; stroke: #2a2c14; }
.tree.dark .shade { fill: #666838; }
.tree.golden .crown { fill: #e0bb4c; stroke: #6d5212; }
.tree.golden .shade { fill: #b0861f; }
.tree.light .crown { fill: #d3d0a0; stroke: #454722; }
.tree.light .shade { fill: #a8a676; }
.peak { fill: var(--vellum); stroke: var(--ink); stroke-width: 0.8; stroke-linejoin: round; }
.peak.volcano { fill: #cdb892; stroke: #2a120c; stroke-width: 1.4; }
.peak-hatch { fill: none; stroke: #4a3a28; stroke-width: 0.45; stroke-linecap: round; }
.peak-ridge { fill: none; stroke: var(--ink); stroke-width: 0.45; opacity: 0.8; }
.lava { fill: none; stroke: #c2381c; stroke-width: 1.3; stroke-linecap: round; }
.smoke { fill: none; stroke: #3b2a24; stroke-width: 2; opacity: 0.45; stroke-linecap: round; }
.smoke.thin { stroke-width: 1; opacity: 0.35; }
.fire { fill: #d9481f; }
.washes { pointer-events: none; }

.region { font-family: var(--caps); fill: var(--ink-soft); text-anchor: middle; opacity: 0.66; }
.region.dark { fill: #5b1a10; opacity: 0.75; }
.region.faint { opacity: 0.42; }
.sea-name { font-family: var(--caps); fill: #4f5a5c; text-anchor: middle; opacity: 0.75; }
.sea-name.italic { font-family: var(--display); font-style: italic; }
.river-name { font-family: var(--display); font-style: italic; fill: #2f4452; opacity: 0.85; }
.range-name { font-family: var(--caps); fill: var(--ink); letter-spacing: 3px; opacity: 0.72; text-anchor: middle; }
.forest-name { font-family: var(--display); font-style: italic; fill: #1f220e; text-anchor: middle; paint-order: stroke; stroke: rgba(240, 228, 198, 0.85); stroke-width: 3.5px; }
.feature-labels, .regions { pointer-events: none; }

.frame-outer { fill: none; stroke: var(--ink); stroke-width: 3.2; }
.frame-mid { fill: none; stroke: var(--ink); stroke-width: 0.8; }
.frame-inner { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.frame-ticks { fill: none; stroke: var(--ink); stroke-width: 0.7; }
.corner { fill: var(--vellum); stroke: var(--ink); stroke-width: 1.2; }
.corner-dot { fill: var(--rubric); }
.rose-ring { fill: none; stroke: var(--ink); stroke-width: 1; }
.rose-ring.thin { stroke-width: 0.5; }
.rose-tick { stroke: var(--ink); stroke-width: 0.6; }
.rose-point.dark { fill: var(--ink); }
.rose-point.light { fill: var(--vellum); stroke: var(--ink); stroke-width: 0.6; }
.rose-n { font-family: var(--caps); font-size: 22px; fill: var(--rubric); text-anchor: middle; }
.scale-dark { fill: var(--ink); }
.scale-light { fill: var(--vellum); stroke: var(--ink); stroke-width: 0.6; }
.scale-num { font-family: var(--body); font-size: 10px; fill: var(--ink); text-anchor: middle; }
.scale-label { font-family: var(--caps); font-size: 14px; fill: var(--ink); text-anchor: middle; letter-spacing: 2px; }
.scale-sub { font-family: var(--display); font-style: italic; font-size: 10px; fill: var(--ink-soft); text-anchor: middle; }

.night { fill: #1d2a4a; opacity: var(--night, 0); pointer-events: none; transition: opacity 1.2s ease; }

/* Places — markers keep a steady on-screen size (see applyView). */
.place { cursor: pointer; }
.place .glyph { fill: var(--vellum); stroke: var(--ink); stroke-width: 1.1; }
.place.kind-city .glyph, .place.kind-fortress .glyph { fill: var(--rubric); stroke: #3b0d06; }
.place.kind-haven .glyph { fill: var(--vellum); stroke: #274b63; stroke-width: 1.2; }
.place.kind-ruin .glyph { fill: none; stroke-dasharray: 1.5 1; }
.place-label {
  font-family: var(--display); font-size: 11.5px; fill: var(--ink);
  paint-order: stroke; stroke: rgba(240, 228, 198, 0.9); stroke-width: 3px; stroke-linejoin: round;
}
.place.tier-1 .place-label { font-size: 13.5px; font-family: var(--caps); fill: var(--rubric); letter-spacing: 0.3px; }
.place .hit { fill: transparent; }
.place-label.clash { display: none; }
.lbl.clash { display: none; }
/* While a zoom is in motion the lettering steps aside (laying it out at every scale
   would stall the zoom) and fades back in when the zoom rests. */
#map.zooming text { display: none; }
#map text { animation: lettering-in 0.22s ease-out; }
@keyframes lettering-in { from { opacity: 0; } to { opacity: 1; } }
.place.on-sheet, .place.off { display: none; }
.traveller-label.clash { display: none; }
.place:hover .place-label, .place:focus .place-label { fill: var(--rubric); }
#map[data-zoom="1"] .place.tier-2 .place-label,
#map[data-zoom="1"] .place.tier-3,
#map[data-zoom="2"] .place.tier-3 .place-label { display: none; }
#map[data-zoom="1"] .place.tier-2 .place-glyph { opacity: 0.7; }

/* Routes */
.route path { fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.route-future path { stroke: var(--c); stroke-width: 1.2; stroke-dasharray: 1 4; opacity: 0.35; }
.route:not(.highlight) .route-future { display: none; }
.route-past path { stroke: var(--c); stroke-width: 2.6; opacity: 0.85; }
.route-past .mode-boat, .route-past .mode-drift { stroke-dasharray: 7 3; }
.route-past .mode-eagle { stroke-dasharray: 2 5; stroke-width: 1.8; }
.route-past .mode-underground, .route-past .mode-fall { stroke-dasharray: 1 3; stroke-width: 2.2; }
.route-past .mode-captive { stroke-dasharray: 4 2 1 2; }
.route-past .mode-horse, .route-past .mode-pony { stroke-width: 2.2; }
.route-past .mode-ent { stroke-dasharray: 10 3; }
.route.pending { display: none; }
.route.menace .route-past path { stroke: #1b1b1b; opacity: 0.55; stroke-dasharray: 3 3; }
.route.menace .route-future { display: none; }
.route.ghost .route-future { display: none; }
#map.following .route:not(.highlight) { opacity: 0.35; }
.route.highlight .route-past path { stroke-width: 3.6; opacity: 1; }
.route.highlight .route-future path { opacity: 0.7; stroke-width: 1.6; }

/* Travellers */
.traveller { cursor: pointer; transition: opacity 0.5s; }
.traveller.gone { opacity: 0; pointer-events: none; }
.traveller .dot { fill: var(--c); stroke: var(--vellum); stroke-width: 1.8; transition: cx 0.35s, cy 0.35s; }
.traveller.menace .dot { fill: #111; stroke: #6b1a10; stroke-width: 2; }
.traveller.ghost .dot { fill: #b8bcc0; stroke: #555; stroke-dasharray: 2 1; }
.traveller.lurker .dot { fill: #4f5b3a; stroke: #20261a; }
.traveller .ring-glow { fill: #e8b53a; opacity: 0.55; filter: url(#glow); transition: cx 0.35s, cy 0.35s; animation: ringpulse 2.8s ease-in-out infinite; }
@keyframes ringpulse { 50% { opacity: 0.2; } }
.traveller-label {
  font-family: var(--display); font-size: 13px; font-style: italic; fill: var(--ink);
  paint-order: stroke; stroke: rgba(245, 236, 213, 0.95); stroke-width: 3.5px; stroke-linejoin: round; pointer-events: none;
}
.traveller.menace .traveller-label { fill: #5b1a10; }
.traveller.followed .dot { stroke: var(--rubric); stroke-width: 2.6; }
.pulse { fill: none; stroke: var(--rubric); stroke-width: 2; vector-effect: non-scaling-stroke; animation: pulse 2.1s ease-out forwards; pointer-events: none; }
.pulse.w3 { stroke-width: 3; }
@keyframes pulse { from { r: 0; opacity: 0.9; } to { r: var(--r); opacity: 0; } }

/* ——— Overlays on the stage ——— */
.cartouche {
  position: absolute; top: 14px; left: 16px; max-width: calc(100% - 100px);
  padding: 10px 18px 11px; background: rgba(245, 236, 213, 0.9);
  border: 1px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 3px;
  box-shadow: 0 6px 18px var(--shadow); pointer-events: none;
}
.cartouche h1 { margin: 0; font: 400 26px/1.05 var(--display); color: var(--rubric); letter-spacing: 0.3px; text-wrap: balance; }
.cartouche .the, .cartouche .of { font-style: italic; font-size: 0.72em; color: var(--ink-soft); }
.cartouche .sub { margin: 3px 0 0; font: italic 14px/1.2 var(--display); color: var(--ink-soft); }

.map-controls { position: absolute; top: 14px; right: 16px; display: flex; flex-direction: column; gap: 6px; }
.map-controls button {
  width: 36px; height: 36px; border: 1px solid var(--ink); background: rgba(245, 236, 213, 0.92);
  font: 20px/1 var(--display); cursor: pointer; box-shadow: 0 2px 6px var(--shadow);
}
.map-controls button:hover { background: var(--vellum-deep); }

.event-card {
  position: absolute; left: 16px; bottom: 132px; width: min(440px, calc(100% - 32px));
  background: var(--panel-bg); border: 1px solid var(--ink); padding: 14px 18px 12px;
  box-shadow: 0 10px 30px var(--shadow); animation: cardin 0.6s ease-out;
}
.event-card::before { content: ''; position: absolute; inset: 4px; border: 0.5px solid var(--ink-faint); pointer-events: none; }
.event-card .ec-date { font: 13px var(--caps); color: var(--rubric); letter-spacing: 0.6px; }
.event-card h3 { margin: 2px 0 6px; font: 400 25px/1.1 var(--display); text-wrap: balance; }
.event-card.w3 h3 { color: var(--rubric); }
.event-card.w3 h3::first-letter { font-size: 1.25em; }
.event-card p { margin: 0; font-size: 16.5px; line-height: 1.45; }
.event-card .ec-ref { margin-top: 8px; font: italic 13px var(--display); color: var(--ink-faint); text-align: right; }
@keyframes cardin { from { opacity: 0; transform: translateY(12px); } }

.place-card {
  position: absolute; right: 64px; top: 14px; width: min(340px, calc(100% - 96px)); max-height: calc(100% - 170px); overflow: auto;
  background: var(--panel-bg); border: 1px solid var(--ink); padding: 14px 18px; box-shadow: 0 10px 30px var(--shadow);
  animation: cardin 0.35s ease-out;
}
.place-card .close { position: absolute; top: 4px; right: 8px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--ink-soft); }
.place-card .pc-region { font: 12px var(--caps); letter-spacing: 1px; color: var(--ink-faint); }
.place-card h3 { margin: 0; font: 400 26px/1.1 var(--display); color: var(--rubric); }
.place-card .pc-alt { font: italic 14px var(--display); color: var(--ink-soft); margin-top: 2px; }
.place-card p { margin: 8px 0 0; }
.place-card h4 { margin: 12px 0 4px; font: 13px var(--caps); letter-spacing: 1px; color: var(--ink-soft); font-weight: 400; }
.place-card ul { list-style: none; margin: 0; padding: 0; }
.place-card li button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 3px 0; cursor: pointer; }
.place-card li button span { font: 12.5px var(--caps); color: var(--rubric); margin-right: 4px; }
.place-card .pc-refs { margin-top: 4px; border-top: 1px solid rgba(46, 33, 21, 0.18); }
.place-card .pc-refs summary { cursor: pointer; list-style: none; }
.place-card .pc-refs summary::-webkit-details-marker { display: none; }
.place-card .pc-refs summary h4 { display: inline-block; }
.place-card .pc-refs summary h4::after { content: ' ▾'; font-size: 10px; }
.place-card .pc-refs:not([open]) summary h4::after { content: ' ▸'; }
.place-card .pc-src { font: italic 13.5px var(--display); color: var(--rubric); margin-bottom: 4px; }
.place-card .pc-facts li { position: relative; padding: 2px 0 2px 14px; font-size: 14.5px; line-height: 1.38; }
.place-card .pc-facts li::before { content: '❧'; position: absolute; left: 0; top: 2px; font-size: 11px; color: var(--ink-faint); }
.place-card .pc-approx, .place-card .pc-note { font: italic 12.5px var(--display); color: var(--ink-faint); margin-top: 4px; }
.place-card .pc-claims li { display: flex; gap: 6px; padding: 3px 0; font-size: 14px; line-height: 1.35; }
.place-card .pc-claims .mark { flex: none; width: 12px; color: #4f6a2a; font-weight: 600; }
.place-card .pc-claims .unmet .mark { color: var(--rubric); }
.place-card .pc-meta { font-size: 12.5px; color: var(--ink-soft); }
.place-card .pc-meta a { color: var(--rubric); }
.place-card li button:hover { text-decoration: underline; }

/* The Survey overlay */
.survey { display: none; pointer-events: none; }
#map.surveying .survey { display: inline; }
#map.surveying #routes, #map.surveying #travellers { opacity: 0.25; }
.ev-line { stroke: var(--rubric); stroke-width: 1.4; stroke-dasharray: 6 3; vector-effect: non-scaling-stroke; }
.ev-line.faint { opacity: 0.45; }
.ev-arrow { stroke: #2b4c7e; stroke-width: 1.3; vector-effect: non-scaling-stroke; opacity: 0.7; }
.ev-head { fill: #2b4c7e; }
.ev-derived .ev-line { stroke: #8a5a1c; }
.ev.unmet .ev-line { stroke: #d0301a; stroke-dasharray: 2 2; }
.ev.hot .ev-line, .ev.hot .ev-arrow { stroke-width: 3.2; opacity: 1; }
.ev.hot .survey-label { fill: var(--rubric); font-weight: 600; }
.lat-line { stroke: #274b63; stroke-width: 1; stroke-dasharray: 10 4 2 4; vector-effect: non-scaling-stroke; opacity: 0.8; }
.survey-label {
  font-family: var(--display); font-style: italic; font-size: calc(var(--u, 1) * 12px); fill: #5b1a10; text-anchor: middle;
  paint-order: stroke; stroke: rgba(240, 228, 198, 0.92); stroke-width: calc(var(--u, 1) * 3.5px);
}
.lat-label { text-anchor: start; fill: #274b63; font-size: calc(var(--u, 1) * 13px); }
.survey-btn { width: auto !important; padding: 0 8px; font: 13px var(--caps) !important; letter-spacing: 0.8px; }
.survey-btn[aria-pressed="true"] { background: var(--rubric) !important; color: var(--vellum); }
.survey-card {
  position: absolute; left: 16px; top: 104px; width: min(430px, calc(100% - 96px)); max-height: calc(100% - 250px); overflow: auto;
  background: var(--panel-bg); border: 1px solid var(--ink); padding: 14px 18px; box-shadow: 0 10px 30px var(--shadow); animation: cardin 0.35s ease-out;
}
.survey-card .close { position: absolute; top: 4px; right: 8px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--ink-soft); }
.survey-card .pc-region { font: 12px var(--caps); letter-spacing: 1px; color: var(--ink-faint); }
.survey-card h3 { margin: 0; font: 400 26px/1.1 var(--display); color: var(--rubric); }
.survey-card .sv-intro { font-size: 15px; margin: 8px 0 4px; }
.survey-card h4 { margin: 14px 0 4px; font: 13px var(--caps); letter-spacing: 1px; color: var(--ink-soft); font-weight: 400; border-bottom: 1px solid var(--ink-faint); padding-bottom: 3px; }
.survey-card ul { list-style: none; margin: 0; padding: 0; }
.survey-card li { display: grid; grid-template-columns: 18px 1fr; gap: 6px; padding: 6px 4px; cursor: pointer; border-bottom: 1px dotted rgba(138, 117, 85, 0.5); }
.survey-card li:hover { background: rgba(155, 38, 22, 0.06); }
.survey-card .mark { color: #3d7a45; font-weight: 600; }
.survey-card li.unmet .mark { color: #d0301a; }
.survey-card .sv-says { font-size: 15px; line-height: 1.35; }
.survey-card .sv-meta { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.survey-card .sv-meta a { color: var(--rubric); }

/* ——— Timeline ——— */
#timeline {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 22px calc(16px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(240, 228, 198, 0.97) 70%, rgba(240, 228, 198, 0));
}
.tl-row { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.play {
  width: 46px; height: 46px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--rubric);
  display: grid; place-items: center; cursor: pointer; flex: none; box-shadow: 0 3px 8px var(--shadow);
}
.play svg { width: 20px; height: 20px; fill: var(--vellum); }
.play .i-pause, .play.playing .i-play { display: none; }
.play.playing .i-pause { display: inline; }
.tl-date { flex: 1; min-width: 0; }
.tl-shire { font: 22px/1.1 var(--display); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-tale { font: italic 14px/1.2 var(--display); color: var(--ink-soft); }
.speed { display: flex; align-items: center; gap: 6px; font: 13px var(--caps); color: var(--ink-soft); letter-spacing: 0.5px; }
.speed select { font: 14px var(--body); background: var(--vellum); border: 1px solid var(--ink-faint); padding: 3px 4px; color: var(--ink); }

.track { position: relative; height: 40px; cursor: pointer; touch-action: none; }
.track-bar { position: absolute; left: 0; right: 0; top: 12px; height: 6px; background: var(--vellum-deep); border: 1px solid var(--ink-faint); }
.track-fill { position: absolute; left: 0; top: 12px; height: 6px; background: var(--rubric); opacity: 0.75; pointer-events: none; }
.track-ticks .tick { position: absolute; top: 7px; height: 16px; border-left: 1px solid var(--ink-faint); pointer-events: none; }
.track-ticks .tick span { position: absolute; top: 17px; left: 3px; font: 11px var(--caps); color: var(--ink-soft); white-space: nowrap; letter-spacing: 0.3px; }
.track-ticks .tick.yule { border-left: 2px solid var(--rubric); }
.track-ticks .tick.yule span { color: var(--rubric); top: -14px; }
.track-pips .pip {
  position: absolute; top: 9px; width: 7px; height: 12px; margin-left: -3.5px; padding: 0; border: 0;
  background: var(--ink); opacity: 0.55; cursor: pointer; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.track-pips .pip.w3 { background: var(--rubric); opacity: 0.95; width: 9px; margin-left: -4.5px; }
.track-pips .pip:hover { transform: scale(1.5); opacity: 1; }
.thumb {
  position: absolute; top: 5px; width: 20px; height: 20px; margin-left: -10px; border-radius: 50%;
  background: var(--vellum); border: 2px solid var(--rubric); box-shadow: 0 2px 6px var(--shadow); pointer-events: none;
}

/* ——— The Chronicle panel ——— */
#panel {
  position: relative; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel-bg); border-left: 1px solid var(--ink);
  box-shadow: -8px 0 24px var(--shadow); padding: 20px 22px 30px;
  display: flex; flex-direction: column; gap: 18px;
}
.panel-toggle { display: none; }
#panel h2 { margin: 0 0 8px; font: 400 15px var(--caps); letter-spacing: 1.6px; color: var(--rubric); border-bottom: 1px solid var(--ink-faint); padding-bottom: 4px; }
.today { text-align: center; padding: 8px 0 14px; border-bottom: 1px double var(--ink); }
.p-weekday { font: 14px var(--caps); letter-spacing: 1.4px; color: var(--ink-soft); }
.p-day { font: 40px/1.05 var(--display); color: var(--rubric); margin: 2px 0; }
.p-year { font: 16px var(--caps); letter-spacing: 1px; }
.p-tale { font: italic 14px var(--display); color: var(--ink-soft); margin-top: 4px; }

.company { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.company li button {
  width: 100%; display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center;
  border: 0; background: none; text-align: left; padding: 5px 6px; cursor: pointer; border-radius: 2px;
}
.company li button:hover { background: rgba(155, 38, 22, 0.07); }
.company li.following button { background: rgba(155, 38, 22, 0.12); }
.company .swatch { width: 12px; height: 12px; border-radius: 50%; background: var(--c); border: 1px solid var(--ink); }
.company .who { min-width: 0; display: flex; flex-direction: column; }
.company .who b { font-weight: 500; font-size: 16px; line-height: 1.15; }
.company .who i { font-size: 14px; color: var(--ink-soft); line-height: 1.25; }
.company .miles { font-size: 13px; color: var(--ink-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.company li.absent { opacity: 0.5; }

.chronicle { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.chronicle li button { display: grid; gap: 1px; width: 100%; text-align: left; border: 0; background: none; padding: 7px 6px 8px; cursor: pointer; border-bottom: 1px dotted var(--ink-faint); }
.chronicle li button:hover { background: rgba(155, 38, 22, 0.06); }
.chronicle .c-date { font: 12.5px var(--caps); color: var(--rubric); letter-spacing: 0.5px; }
.chronicle .c-title { font: 19px/1.15 var(--display); }
.chronicle .w3 .c-title { color: var(--rubric); }
.chronicle .c-text { font-size: 15px; line-height: 1.4; color: var(--ink); }
.chronicle .c-ref { font: italic 12.5px var(--display); color: var(--ink-faint); }
.chronicle li.today button { background: rgba(165, 122, 28, 0.1); }
.chronicle li:not(:first-child) .c-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chronicle .empty { font-style: italic; color: var(--ink-soft); }
.colophon { margin: auto 0 0; font: italic 13px/1.4 var(--display); color: var(--ink-faint); border-top: 1px solid var(--ink-faint); padding-top: 10px; }

/* ——— Intro ——— */
.intro {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(240, 228, 198, 0.9), rgba(120, 92, 52, 0.85));
  transition: opacity 0.7s;
}
.intro.gone { opacity: 0; pointer-events: none; }
.intro-page {
  max-width: 620px; text-align: center; padding: 34px 38px 28px; background: var(--panel-bg);
  border: 1px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 5px; box-shadow: 0 20px 60px rgba(40, 25, 10, 0.5);
}
.intro-eyebrow { margin: 0; font: 14px var(--caps); letter-spacing: 2px; color: var(--ink-soft); }
.intro-title { margin: 8px 0 14px; font: 400 58px/0.95 var(--display); color: var(--rubric); text-wrap: balance; }
.intro-title span { font-style: italic; font-size: 0.55em; color: var(--ink-soft); }
.intro-lede { margin: 0 auto; max-width: 52ch; font-size: 18px; line-height: 1.5; }
.intro-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 22px; }
.intro-actions button { padding: 10px 20px; border: 1px solid var(--ink); background: var(--vellum); cursor: pointer; font: 18px var(--display); }
.intro-actions button.primary { background: var(--rubric); color: var(--vellum); border-color: #4a1008; }
.intro-actions button:hover { filter: brightness(1.06); }
.intro-note { margin: 16px 0 0; font: italic 14px var(--display); color: var(--ink-faint); }

/* ——— Small screens: the chronicle becomes a bottom sheet ——— */
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #panel { max-height: 42vh; border-left: 0; border-top: 1px solid var(--ink); padding: 8px 16px 20px; transition: max-height 0.3s; }
  #panel.collapsed { max-height: 44px; overflow: hidden; }
  .panel-toggle { display: block; position: sticky; top: -8px; margin: -8px -16px 0; padding: 10px 16px; border: 0; background: var(--panel-bg); font: 15px var(--caps); letter-spacing: 1.5px; color: var(--rubric); text-align: left; z-index: 2; cursor: pointer; }
  .today { padding-top: 0; }
  .p-day { font-size: 30px; }
  .cartouche { padding: 7px 12px; }
  .cartouche h1 { font-size: 19px; }
  .cartouche .sub { display: none; }
  .intro-title { font-size: 42px; }
  .intro-page { padding: 24px 20px; }
  .tl-shire { font-size: 18px; }
  .speed span { display: none; }
  #timeline { padding: 8px 16px 12px; }
  .event-card { bottom: auto; top: 64px; padding: 10px 14px 8px; }
  .event-card h3 { font-size: 19px; margin-bottom: 3px; }
  .event-card p { font-size: 14px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .event-card .ec-ref { margin-top: 3px; }
  .track-ticks .tick:nth-child(even) span { display: none; }
  .track-ticks .tick span { font-size: 10px; }
  .survey-card { top: 64px; max-height: calc(100% - 200px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
