:root {
  --gap: 12px;
  --top: calc(var(--gap) + env(safe-area-inset-top));
  --right: calc(var(--gap) + env(safe-area-inset-right));
  --bottom: calc(var(--gap) + env(safe-area-inset-bottom));
  --left: calc(var(--gap) + env(safe-area-inset-left));
}

html, body { margin: 0; height: 100%; overflow: hidden; }
html.page, html.page body { height: auto; overflow: auto; background: #fff; }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: #1d1d1f; background: #dce9f2; min-width: 320px; }

#map { position: fixed; inset: 0; }

.panel {
  position: fixed; z-index: 2; box-sizing: border-box;
  background: #fff; border-radius: 12px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
}
.panel:empty { display: none; }

#timeline { left: var(--left); right: var(--right); bottom: var(--bottom); padding: 10px 14px; }
#error {
  top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 3;
  width: min(360px, calc(100% - 2 * var(--gap))); padding: 16px 20px; text-align: center; font-weight: 600;
}

#error.soft { pointer-events: none; }
.err-retry { display: block; margin: 10px auto 0; min-height: 44px; padding: 0 20px; border: 0; border-radius: 10px; background: #2b6c9e; color: #fff; font: 600 15px system-ui, sans-serif; cursor: pointer; pointer-events: auto; }
.err-retry:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }

.maplibregl-ctrl-top-right { top: env(safe-area-inset-top); right: env(safe-area-inset-right); }
.maplibregl-ctrl-top-right .maplibregl-ctrl { margin: var(--gap) var(--gap) 0 0; }
.maplibregl-ctrl-group { border-radius: 12px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16) !important; overflow: hidden; }
.maplibregl-ctrl-group button { width: 44px; height: 44px; }

/* Timeline. Row 1: the names of the events (when there are some). Row 2: play button, year box with its step buttons,
   the name of what is on. Row 3: slider. Row 4: era labels, or a note. */
#timeline { display: grid; grid-template-columns: 52px minmax(0, 326px) minmax(0, 1fr); gap: 4px 12px; align-items: center; max-width: 900px; margin: 0 auto; }
.tl-play, .tl-steps, .tl-ons { grid-row: 2; }
.tl-play { width: 52px; height: 52px; border-radius: 50%; border: 0; background: #2b6c9e; color: #fff; font-size: 18px; cursor: pointer; }
.tl-steps { display: flex; align-items: center; gap: 4px; min-width: 0; } /* one year back, the year box, one year forward */
.tl-back, .tl-fwd { flex: none; width: 44px; height: 44px; padding: 0 0 3px; border: 2px solid #c5d0d8; border-radius: 10px; background: #fff; color: #2b6c9e; font-size: 24px; line-height: 1; cursor: pointer; }
/* The button "Clear", to the right of the year box: the page as it was at the start. */
.tl-clear { flex: none; min-height: 44px; padding: 0 8px; border: 0; border-radius: 10px; background: transparent; color: #1f5c8c; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.tl-clear:focus-visible { outline: 3px solid #f2a900; outline-offset: -3px; }
.tl-year { box-sizing: border-box; min-height: 44px; flex: 1 1 auto; min-width: 0; width: 100%; max-width: 170px; font: 600 18px system-ui, sans-serif; padding: 0 12px; border: 2px solid #c5d0d8; border-radius: 10px; }
/* A phone: the names of what is on have a row of their own (row 5), so two columns are enough. A narrow phone: less
   room around the year box, so that "2500 BCE" and the button "Clear" fit beside it. */
@media (max-width: 520px) { #timeline { grid-template-columns: 52px minmax(0, 1fr); } }
@media (max-width: 400px) { #timeline { padding: 10px 8px; } .tl-year { padding: 0 6px; font-size: 16px; } .tl-clear { padding: 0 4px; } }
@media (max-width: 359px) { #timeline { grid-template-columns: 44px minmax(0, 1fr); column-gap: 6px; padding: 10px 6px; } .tl-play { width: 44px; height: 44px; } .tl-steps { gap: 2px; } .tl-year { padding: 0 3px; } .tl-clear { padding: 0 2px; } }
/* The names of what is on, each with its close button: beside the year box, or in a row of their own on a narrow
   screen. There can be two: what was found (a topic of a list, or a result of the search) and the map of the tab "Shows". */
.tl-ons { display: flex; gap: 8px; min-width: 0; }
.tl-on { display: flex; align-items: center; flex: 0 1 auto; min-width: 0; min-height: 44px; border-radius: 10px; background: #e6f0f7; font-weight: 600; }
.tl-ons[hidden], .tl-on[hidden] { display: none; }
.tl-on small { margin-right: 6px; font-size: 12px; font-weight: 400; color: #4a5560; } /* the tab that it comes from */
.tl-on-name { min-width: 0; min-height: 44px; padding: 0 0 0 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; font: inherit; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-on-close { flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; font-size: 16px; color: #4a5560; cursor: pointer; }
.tl-on-name:focus-visible, .tl-on-close:focus-visible { outline: 3px solid #f2a900; outline-offset: -3px; }
@media (max-width: 520px) { .tl-ons { grid-column: 1 / -1; grid-row: 5; flex-wrap: wrap; } } /* two names that do not fit get a row each */
/* The names of the events, in a row of their own above the controls. During play it is one row: a name that does not
   fit goes to a second row, which is cut off, so only whole names show. */
.tl-now { grid-column: 1 / -1; grid-row: 1; display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; height: 30px; overflow: hidden; }
.tl-now[hidden] { display: none; }
.tl-now.all { height: auto; max-height: min(98px, 24vh); overflow-y: auto; } /* the play stands still: the events of the year, up to 3 rows, then it scrolls */
@media (min-height: 900px) { .tl-now.all { max-height: 132px; } }
/* A phone on its side: there is no room for the names above the timeline. With them, the tab "Details" covered the tab "Find". */
@media (max-height: 480px) { .tl-now { display: none; } }
/* Small buttons (the owner): there are many events, and large names hid the map. 30 pixels is over the 24 that WCAG 2.2 asks for. */
.tl-now button { flex: none; max-width: 100%; min-height: 30px; padding: 0 8px; border: 1px solid #c9d3dc; border-radius: 8px; background: #fff; color: inherit;
  font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; animation: tl-now-in .25s ease-out; }
.tl-now button:focus-visible { outline: 3px solid #f2a900; outline-offset: -3px; }
@keyframes tl-now-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .tl-now button { animation: none; } }
.tl-range { grid-column: 1 / -1; grid-row: 3; width: 100%; height: 44px; margin: 0; cursor: pointer; accent-color: #2b6c9e; }
.tl-ticks { grid-column: 1 / -1; grid-row: 4; position: relative; height: 18px; font-size: 12px; color: #4a5560; }
.tl-ticks span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.tl-ticks .first { transform: none; }
.tl-ticks .skip { display: none; }
.tl-ticks .last { transform: translateX(-100%); }
.tl-play:focus-visible, .tl-year:focus-visible, .tl-range:focus-visible, .tl-back:focus-visible, .tl-fwd:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
.tl-year[aria-invalid="true"] { border-color: #b3261e; background: #fdecea; }
@media (max-width: 520px) { .tl-ticks .minor { display: none; } }
.tl-msg { grid-column: 1 / -1; grid-row: 4; z-index: 1; height: 18px; background: #fff; font-size: 13px; font-weight: 600; color: #b3261e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-msg:empty { visibility: hidden; }
.tl-msg.note { font-weight: 400; color: #4a5560; } /* a note, not an error: the year is after the last year of the map data */

/* Search box: in the panel of the tab "Find" */
#search { margin-top: 8px; border: 2px solid #c5d0d8; border-radius: 12px; }
.sb-row { display: flex; align-items: center; }
.sb-input { flex: 1; min-width: 0; box-sizing: border-box; min-height: 44px; font: 16px system-ui, sans-serif; padding: 0 12px; border: 2px solid transparent; border-radius: 12px; background: transparent; }
.sb-input:focus-visible, .sb-clear:focus-visible, .sb-opt:focus-visible { outline: 3px solid #f2a900; outline-offset: -3px; }
.sb-clear { flex: none; width: 44px; height: 44px; border: 0; background: transparent; font-size: 16px; color: #4a5560; cursor: pointer; }
.sb-list { list-style: none; margin: 0; padding: 4px 0; border-top: 1px solid #e1e6ea; }
.sb-opt, .sb-none { display: flex; flex-direction: column; justify-content: center; min-height: 44px; box-sizing: border-box; padding: 4px 14px; cursor: pointer; }
.sb-none { color: #4a5560; cursor: default; }
.sb-opt[aria-selected="true"], .sb-opt:hover { background: #e6f0f7; box-shadow: inset 4px 0 0 #2b6c9e; }
.sb-detail { font-size: 12px; color: #4a5560; }
.sb-input::-webkit-search-cancel-button { display: none; }

/* The three tabs on the left edge: "Find" at the top (the search box and the school topics), "Help" under it, and
   "Details" just above the timeline. Each is a <details> element, so the browser opens and closes it, also with the
   keyboard. The three have the same name, so the browser keeps only one open. Closed, only the tab with its word shows. The body has a fixed
   width: without one, the panel grew as wide as the whole legend in one row, and the buttons of the switch with it. */
.drawer { --tab: calc(44px + env(safe-area-inset-left)); min-height: 104px; padding-left: var(--tab); border-radius: 0 12px 12px 0; }
/* The three drawers are a column from the top to the timeline: "Find", "Help", and "Details" at its end. An open drawer
   pushes the tabs below it down, so a drawer and a tab never overlap. The column itself takes no clicks. */
#drawers { position: fixed; z-index: 2; left: 0; top: var(--top); bottom: calc(var(--bottom) + var(--tl-h, 140px) + 8px);
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; pointer-events: none; }
#drawers > .drawer { position: relative; flex: none; pointer-events: auto; }
#find { min-height: 88px; }
#help { min-height: 80px; }
#details { margin-top: auto; }
/* A low screen (a phone on its side): the three tabs are shorter, so that all three fit above the timeline. There is
   no room below an open drawer: the two closed tabs go away until the child closes it. */
@media (max-height: 480px) { #find { min-height: 62px; } #help { min-height: 62px; } #details { min-height: 80px; } #drawers { gap: 4px; }
  #drawers:has(.drawer[open]) .drawer:not([open]) { display: none; } }
.drawer > summary { position: absolute; left: 0; top: 0; bottom: 0; width: var(--tab); box-sizing: border-box; padding-left: env(safe-area-inset-left);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; list-style: none; border-radius: 0 12px 12px 0;
  font-weight: 600; cursor: pointer; user-select: none; -webkit-user-select: none; }
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary span { writing-mode: vertical-rl; transform: rotate(180deg); } /* reads from the bottom to the top */
#level-name { display: block; font-size: 12px; font-weight: 400; color: #4a5560; } /* the detail level, in a second line: it shows also when the tab is closed */
.drawer > summary::before { content: "›"; font-size: 20px; line-height: 1; color: #2b6c9e; }
.drawer[open] > summary::before { content: "‹"; }
.drawer[open] > summary { border-right: 1px solid #dde3e8; border-radius: 0; }
.drawer > summary:focus-visible { outline: 3px solid #f2a900; outline-offset: -3px; }
.drawer-body { display: block; box-sizing: border-box; width: min(300px, calc(100vw - var(--tab) - 70px)); padding: 0 14px 10px; overflow-y: auto; }
/* An open drawer ends where the tabs of the other two start (88, 80 and 104 pixels high, with gaps of 8). */
.drawer-body { --room: calc(100vh - var(--top) - var(--tl-h, 140px) - var(--bottom) - 8px); }
#find .drawer-body { max-height: calc(var(--room) - 200px); }
#help .drawer-body { max-height: calc(var(--room) - 208px); }
#details .drawer-body { max-height: calc(var(--room) - 184px); }
@media (max-height: 480px) { #drawers .drawer-body { max-height: var(--room); } }
.help h2 { margin: 12px 0 4px; font-size: 15px; }
.help ul { margin: 0; padding-left: 18px; }
.help li, .help p { margin: 0 0 6px; font-size: 14px; line-height: 1.4; }
/* The school topics: a menu for the country, then the topics of the country and the topics of the world. */
.t-country { display: flex; align-items: center; gap: 8px; min-height: 44px; margin-top: 8px; font-size: 13px; color: #4a5560; white-space: nowrap; }
.t-country select { flex: 1; min-width: 0; min-height: 44px; padding: 0 8px; border: 2px solid #c5d0d8; border-radius: 10px; background: #fff; color: #1d1d1f; font: 600 15px system-ui, sans-serif; }
#topics h2 { margin: 12px 2px 4px; font-size: 12px; font-weight: 600; color: #4a5560; text-transform: uppercase; letter-spacing: 0.04em; }
.t-list { list-style: none; margin: 0; padding: 0; }
.t-list li { border-top: 1px solid #e1e6ea; }
.t-row { display: flex; flex-direction: column; justify-content: center; width: 100%; min-height: 44px; box-sizing: border-box; padding: 4px 8px; border: 0;
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.t-row b { font-weight: 600; }
.t-row small { font-size: 12px; color: #4a5560; }
.t-row:hover { background: #e6f0f7; box-shadow: inset 4px 0 0 #2b6c9e; }
.t-country select:focus-visible, .t-row:focus-visible { outline: 3px solid #f2a900; outline-offset: -3px; }
/* Two tabs in the panel: radio buttons, so the arrow keys change the tab. */
.tabs { display: flex; border: 0; border-bottom: 2px solid #dde3e8; margin: 0 0 4px; padding: 0; }
.tabs label { position: relative; }
.tabs input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.tabs span { display: flex; align-items: center; min-height: 44px; padding: 0 14px; margin-bottom: -2px; border-bottom: 3px solid transparent; font-weight: 600; color: #4a5560; }
.tabs input:checked + span { color: #1d1d1f; border-bottom-color: #2b6c9e; }
.tabs input:focus-visible + span { outline: 3px solid #f2a900; outline-offset: -3px; }
#find:not(:has(#tab-search:checked)) #pane-search, #find:not(:has(#tab-lists:checked)) #pane-lists, #find:not(:has(#tab-maps:checked)) #pane-maps { display: none; }
#pane-sources, #details:has(#tab-sources:checked) #pane-map { display: none; }
#details:has(#tab-sources:checked) #pane-sources { display: block; }
#pane-sources { font-size: 13px; }
#pane-sources p { margin: 0; }
#pane-sources a { color: #1f5c8c; }
#pane-sources a:focus-visible { outline: 3px solid #f2a900; outline-offset: 1px; }
#pane-sources p a { display: inline-flex; align-items: center; min-height: 44px; }
.credits { margin: 8px 0 0; padding-left: 18px; }
.credits li { margin-bottom: 4px; }
/* Detail level: three radio buttons drawn as one switch */
.level { display: flex; flex-wrap: wrap; border: 0; margin: 8px 0 2px; padding: 0; }
.level legend { padding: 0 0 4px; font-size: 12px; color: #4a5560; }
.level label { position: relative; flex: 1; }
.level input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.level span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 12px; border: 2px solid #c5d0d8; margin-left: -2px; font-weight: 600; }
.level label:first-of-type span { margin-left: 0; border-radius: 10px 0 0 10px; }
.level label:last-of-type span { border-radius: 0 10px 10px 0; }
.level input:checked + span { position: relative; background: #2b6c9e; border-color: #2b6c9e; color: #fff; }
.level input:focus-visible + span { position: relative; outline: 3px solid #f2a900; outline-offset: 2px; }
.map-shows { display: flex; align-items: center; gap: 8px; margin: 8px 0 2px; font-size: 14px; white-space: nowrap; }
.theme-key[hidden], .map-shows[hidden] { display: none; }
.map-note { margin: 2px 0 6px; font-size: 12px; color: #4a5560; }
#shows .t-row[aria-pressed="true"] { background: #e6f0f7; box-shadow: inset 4px 0 0 #2b6c9e; } /* the show that is on */
.map-shows select { flex: 1; min-width: 0; min-height: 44px; padding: 0 8px; border: 2px solid #c5d0d8; border-radius: 10px; background: #fff; font: inherit; font-weight: 600; }
.map-shows select:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
.theme-key { margin: 6px 0; }
.theme-title { margin: 0 0 4px; font-weight: 600; }
.theme-key .key i { width: 18px; height: 12px; border: 1px solid #8a8f94; border-radius: 2px; }
.theme-count { margin: 4px 0 0; font-size: 13px; color: #4a5560; }
.today-label { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.today-label input { width: 22px; height: 22px; margin: 0; accent-color: #c0392b; }
.today-label:has(:focus-visible) { outline: 3px solid #f2a900; outline-offset: -2px; border-radius: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 2px 10px; margin: 0; font-size: 12px; color: #4a5560; }
.key { display: inline-flex; align-items: center; gap: 5px; }
.key i { display: inline-block; width: 18px; height: 0; border-top: 2px solid #4a4a50; }
.key .k-dash { border-top-style: dashed; }
.key[hidden] { display: none; }
.key .k-cable { border-top: 2px dashed #9a4d1c; }
.key .k-lane { height: 10px; border: 0; background: linear-gradient(90deg, #cbdded 0 33%, #b0cbe3 33% 66%, #8fb4d6 66%); }
.key .k-hatch { height: 10px; border: 1px solid #4a4a50; background: repeating-linear-gradient(135deg, #4a4a50 0 1px, transparent 1px 4px); }
.key .k-cross { height: 10px; border: 1px dashed #4a4a50;
  background: repeating-linear-gradient(45deg, #8a8a90 0 1px, transparent 1px 5px), repeating-linear-gradient(135deg, #8a8a90 0 1px, transparent 1px 5px); }

.maplibregl-ctrl-bottom-left { display: none; }

/* Preview build badge: under the zoom buttons, beneath every panel so it never covers them */
#preview { position: fixed; z-index: 1; top: calc(var(--top) + 96px); right: var(--right); box-sizing: border-box; max-width: min(200px, calc(100% - var(--left) - var(--right)));
  margin: 0; padding: 6px 10px; background: #fff3c4; border: 2px solid #8a5a00; border-radius: 8px; font-size: 13px; font-weight: 700; color: #1d1d1f; pointer-events: none; }

/* Popup */
.maplibregl-popup-content { border-radius: 12px; padding: 14px 16px; font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
.popup p, .popup h2 { margin: 0 0 6px; }
.popup-name { font-size: 18px; padding-right: 24px; }
.popup-data-name { color: #4a5560; font-size: 13px; }
.popup-links { display: flex; flex-wrap: wrap; gap: 0 16px; margin-bottom: 0 !important; }
.popup a, .popup-links a { display: inline-flex; align-items: center; min-height: 44px; color: #1f5c8c; }
.popup p a { min-height: 0; }
.popup p.popup-links a { min-height: 44px; }
/* The box of a school topic: never higher than the room above the timeline (a phone on its side); it scrolls then. */
.topic-box .maplibregl-popup-content { box-sizing: border-box; max-height: calc(100vh - var(--tl-h, 140px) - var(--bottom) - 48px); overflow-y: auto; }
.pin .popup-name { font-size: 16px; } /* the pin of a place of today: smaller than the box of a topic */
.pin .popup p { margin-bottom: 0; }
.popup h2:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
.popup a:focus-visible, .maplibregl-popup-close-button:focus-visible { outline: 3px solid #f2a900; outline-offset: 1px; }
.maplibregl-popup-close-button { width: 44px; height: 44px; font-size: 22px; }

/* Sources page */
.prose { max-width: 40rem; margin: 0 auto; padding: 24px 16px 48px; font-size: 17px; line-height: 1.55; }
.prose h1 { font-size: 28px; } .prose h2 { font-size: 21px; margin-top: 32px; }
.prose a { color: #1f5c8c; } .prose a:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
