:root {
  --ink: #2b211b;
  --muted: #6d5a49;
  --paper: rgba(246, 239, 225, 0.92);
  --paper-solid: #f6efe1;
  --line: rgba(120, 80, 50, 0.25);
  --red: #9b2d20;
  --gold: #b8892e;
  --shadow: 0 6px 24px rgba(40, 20, 10, 0.25);
  --page: #cbbfa6;
  --serif: 'Cormorant Garamond', 'Georgia', serif;
  --sans: 'Source Sans 3', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1e6d3; --muted: #c4ad92; --paper: rgba(38, 28, 22, 0.9); --paper-solid: #261c16; --line: rgba(230, 190, 140, 0.2);
    --red: #e0735f; --gold: #e2b85c; --page: #2a211b; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #f1e6d3; --muted: #c4ad92; --paper: rgba(38, 28, 22, 0.9); --paper-solid: #261c16; --line: rgba(230, 190, 140, 0.2);
  --red: #e0735f; --gold: #e2b85c; --page: #2a211b; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; margin: 0; height: 100%; overflow: hidden; background: var(--page); color: var(--ink); font: 15px/1.45 var(--sans); }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 4px 10px; }
button:hover { border-color: var(--red); }
select { background: var(--paper-solid); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; max-width: 100%; }
.panel { position: fixed; background: var(--paper); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.spqr { font: 700 26px/1 var(--serif); letter-spacing: 0.22em; color: var(--red); }
.row { display: flex; gap: 6px; align-items: center; }

#top { top: calc(12px + env(safe-area-inset-top, 0px)); left: calc(12px + env(safe-area-inset-left, 0px)); padding: 10px 14px 8px; width: min(460px, calc(100vw - 24px)); }
.brand { display: flex; align-items: baseline; gap: 10px; }
#sub { font: italic 500 16px var(--serif); color: var(--muted); }
#eras { display: flex; gap: 4px; margin: 8px 0 4px; flex-wrap: wrap; }
#eras button { flex: 1 1 0; min-width: 72px; padding: 4px 6px; text-align: left; line-height: 1.15; border-radius: 6px; }
#eras button b { display: block; font: 700 15px var(--serif); }
#eras button span { font-size: 11.5px; color: var(--muted); }
#eras button.on { background: var(--red); border-color: var(--red); color: #fbf3e6; }
#eras button.on span { color: #f3d9c9; }
.yearrow { display: flex; align-items: center; gap: 6px; }
.steprow { display: flex; align-items: center; gap: 6px; }
.steprow input { flex: 1; min-width: 0; }
button.step { width: 30px; height: 30px; flex: none; padding: 0; border-radius: 15px; font: 700 18px/1 var(--serif); }
#year { flex: 1; accent-color: var(--red); }
#yearOut { font: 700 17px var(--serif); min-width: 92px; text-align: right; }

#eraInfo { left: calc(12px + env(safe-area-inset-left, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); width: min(460px, calc(100vw - 24px)); padding: 10px 16px 12px; max-height: 38vh; overflow: auto; }
#eraInfo h2 { margin: 0; font: 700 22px var(--serif); color: var(--red); }
#eraMeta { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
#eraInfo p { margin: 4px 0 0; }
#eraInfo.folded p, #eraInfo.folded #eraMeta { display: none; }
.fold { float: right; border: none; font-size: 18px; padding: 0 6px; }

#tools { top: calc(12px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); padding: 10px 12px; width: 236px; display: flex; flex-direction: column; gap: 8px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { flex: 1; border: none; border-radius: 0; padding: 5px 4px; }
.seg button.on { background: var(--red); color: #fbf3e6; }
.time { display: flex; flex-direction: column; font-size: 12.5px; color: var(--muted); }
.time input { accent-color: var(--gold); }
#hora { font: italic 500 15px/1.25 var(--serif); }
#hora b { font-style: normal; color: var(--red); }
#tools .row select { flex: 1; min-width: 0; }
#menu { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 14px; }
#menu[hidden] { display: none; }

#info, #story { right: 12px; top: 250px; width: min(340px, calc(100vw - 24px)); padding: 12px 16px 14px; max-height: calc(100vh - 440px); min-height: 120px; overflow: auto; }
#info h3 { margin: 0 24px 0 0; font: 700 22px/1.1 var(--serif); color: var(--red); font-style: italic; }
#infoName { font: 600 15px var(--sans); margin-top: 2px; }
#infoDates { font-size: 12.5px; color: var(--muted); }
#info p { margin: 8px 0 10px; }
.close { position: absolute; top: 6px; right: 8px; border: none; font-size: 22px; line-height: 1; padding: 0 6px; }

#voice { left: max(484px, calc(50% - 280px)); bottom: 16px; width: min(560px, calc(100vw - 700px)); padding: 12px 18px; transition: opacity .6s; }
#voice blockquote { margin: 0; font: italic 500 19px/1.3 var(--serif); }
#voiceCit { font-size: 12.5px; color: var(--red); margin-top: 4px; font-weight: 600; }
#voice p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
#voice.fade { opacity: 0; }

#mini { position: fixed; right: calc(12px + env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); width: 180px; height: 156px; border-radius: 10px; border: 1px solid var(--line); box-shadow: var(--shadow); cursor: crosshair; background: #9c9468; }
#hint { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(30, 20, 14, 0.72); color: #f7ecd9; padding: 6px 12px; border-radius: 8px; font-size: 13px; max-width: min(520px, 60vw); text-align: center; pointer-events: none; transition: opacity 1s; }
#where { position: fixed; left: 50%; top: 74px; transform: translateX(-50%); color: #fff; text-shadow: 0 1px 3px #000, 0 0 8px rgba(0,0,0,.5); font: 500 15px var(--serif); letter-spacing: .02em; pointer-events: none; white-space: nowrap; }
#where b { font-weight: 600; font-variant: small-caps; letter-spacing: .06em; }
@media (max-width: 700px) { #where { top: auto; bottom: 64px; font-size: 13px; } }
#near { position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); color: #fff; text-shadow: 0 1px 3px #000; font: italic 600 18px var(--serif); pointer-events: none; }
#cross { position: fixed; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255, 255, 255, 0.7); display: none; pointer-events: none; }
body.walking #cross { display: block; }

#legend { right: 12px; bottom: 178px; padding: 8px 12px; font-size: 13px; width: 180px; }
#legend div { display: flex; align-items: center; gap: 6px; }
#legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
#legend .note { display: block; margin-top: 4px; font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.lbl.hill { font: italic 700 22px/1 var(--serif); color: #fff8e6; letter-spacing: .03em; text-shadow: 0 1px 3px #000, 0 0 10px rgba(0,0,0,.6); }
.lbl.hill.minor { font-size: 16px; opacity: .85; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); white-space: nowrap; pointer-events: none;
  font: 600 13px/1.1 var(--sans); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.9), 0 0 6px rgba(0,0,0,.5); padding: 2px 4px; }
.lbl.p1 { font: 700 16px/1.1 var(--serif); letter-spacing: .02em; }
.lbl i { display: block; font: italic 500 12px var(--serif); opacity: .9; }
.lbl.site { color: #ffd9a8; }
.lbl::after { content: ''; position: absolute; left: 50%; bottom: -5px; width: 1px; height: 5px; background: rgba(255,255,255,.7); }

#about { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 24px)); padding: 16px 20px; max-height: 80vh; overflow: auto; }
#about h3 { margin: 0 0 6px; font: 700 22px var(--serif); color: var(--red); }

#loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: #e9dfca; color: #5a4636; z-index: 10; transition: opacity .8s; }
#loading .spqr { font-size: 46px; }
#loading.done { opacity: 0; pointer-events: none; }

#printSheet { display: none; }
@media print {
  @page { size: A4 portrait; margin: 14mm; }
  html, body { background: #fff !important; overflow: visible; height: auto; }
  body > *:not(#printSheet) { display: none !important; }
  #printSheet { display: block; color: #000; font: 11pt/1.4 var(--sans); }
  #printSheet h1 { font: 700 22pt var(--serif); color: #9b2d20; margin: 0; letter-spacing: .1em; }
  #printSheet h2 { font: italic 600 14pt var(--serif); margin: 2mm 0 3mm; }
  #printSheet img { width: 100%; border: 0.3mm solid #999; }
  #printSheet h3 { font: 700 13pt var(--serif); margin: 4mm 0 1mm; color: #9b2d20; }
  #printSheet .meta, #printSheet .src { font-size: 8.5pt; color: #444; }
  #printSheet .url { font-size: 8pt; word-break: break-all; color: #333; margin-top: 3mm; }
}
@media (max-width: 1180px) {
  #voice { left: 50%; transform: translateX(-50%); bottom: auto; top: 150px; width: min(560px, calc(100vw - 24px)); }
}
@media (max-width: 760px) {
  #top { padding: 8px 10px 6px; }
  .spqr { font-size: 20px; }
  #sub { display: none; }
  #eras button { min-width: 56px; }
  #eras button span { display: none; }
  #tools { top: auto; bottom: 12px; right: 12px; width: 180px; padding: 8px; gap: 6px; }
  #mini { display: none; }
  #eraInfo { bottom: 12px; width: calc(100vw - 216px); max-height: 30vh; font-size: 13.5px; }
  #eraInfo.folded { width: auto; }
  #info { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; max-height: 50vh; z-index: 3; }
  #voice { bottom: auto; top: 140px; }
  #hint { top: 132px; max-width: calc(100vw - 24px); }
}
@media (max-width: 480px) {
  #eraInfo { display: none; }
  #tools { width: calc(100vw - 24px); }
}

/* stories: everyday life (round, ochre) and events (diamond, red, with the year), unlike building labels */
#stories { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.story { position: absolute; left: 0; top: 0; pointer-events: auto; border: none; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.story .mk { width: 26px; height: 26px; display: grid; place-items: center; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.story svg { width: 16px; height: 16px; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.story.life .mk { border-radius: 50%; background: var(--story-life); border: 2px solid #fff6dd; }
.story.life svg { stroke: #3a2a12; }
.story.event .mk { transform: rotate(45deg); border-radius: 4px; background: var(--story-event); border: 2px solid #ffe6d8; }
.story.event svg { transform: rotate(-45deg); stroke: #fff; }
.story .yr { margin-top: 5px; font: 700 11px var(--sans); color: #fff; background: var(--story-event); border-radius: 3px; padding: 0 4px; white-space: nowrap; }
.story:hover .mk, .story:focus-visible .mk { outline: 2px solid #fff; outline-offset: 2px; }
#story { border-top: 5px solid var(--story-life); }
#story.event { border-top-color: var(--story-event); }
#storyKind { font: 600 12px var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
#story h3 { margin: 2px 24px 0 0; font: 700 21px/1.15 var(--serif); }
#storySrc { font-size: 12px; color: var(--muted); margin: 6px 0 8px; }
.key { display: inline-block; width: 11px; height: 11px; margin-right: 6px; vertical-align: -1px; }
.key.life { border-radius: 50%; background: var(--story-life); }
.key.event { transform: rotate(45deg) scale(.85); background: var(--story-event); }
:root { --story-life: #e3ae3f; --story-event: #a8352a; }
.street { position: absolute; left: 0; top: 0; white-space: nowrap; pointer-events: none; font: italic 600 13.5px var(--serif); letter-spacing: .12em; color: #fff2d8; text-shadow: 0 0 3px rgba(40,25,10,.9), 0 1px 2px rgba(0,0,0,.8); }
