:root {
  --ev: #c0182d; --wa: #f2a600; --sa: #1a9e8c; --ink: #14202b; --mut: #4b5a69;
  --card: #ffffff; --line: #cfd7df; --ph: 80px; --th: 48px;
  --shadow: 0 2px 10px rgba(10, 25, 40, .28);
  font-size: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #eef1f4; color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
#map { position: absolute; inset: 0; background: #eef1f4; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.grow { flex: 1; }
.small { font-size: .8rem; color: var(--mut); line-height: 1.35; }

/* top bar */
#top { position: absolute; z-index: 5; top: 12px; left: 12px; right: 12px; display: flex; gap: 6px; align-items: center; pointer-events: none; }
#top > * { pointer-events: auto; flex: none; }
#places { display: flex; gap: 6px; }
.pl { background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 8px 14px 8px 8px; font-weight: 700; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; white-space: nowrap; line-height: 1.1; }
.pl kbd { background: #e3e9ef; border-radius: 6px; padding: 2px 7px; font-size: .78rem; font-family: inherit; color: var(--mut); }
.pl.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.pl.on kbd { background: #3b4c5d; color: #fff; }
.pl .full { display: none; }   /* short names unless the screen is very wide */
#searchwrap { position: relative; }
#q { width: 140px; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); box-shadow: var(--shadow); }
#sugg { position: absolute; top: 100%; left: 0; min-width: 280px; margin: 4px 0 0; padding: 0; list-style: none; background: var(--card); border-radius: 10px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; }
#sugg li { padding: 9px 14px; cursor: pointer; } #sugg li:hover { background: #e8eef4; } #sugg li small { color: var(--mut); }
#modes { display: flex; gap: 4px; }
#modes .chip { padding: 9px 14px; box-shadow: var(--shadow); border-radius: 12px; white-space: nowrap; }
#modes .chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
#seg { display: flex; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); border: 2px solid var(--line); overflow: hidden; }
#seg button { border: 0; background: transparent; padding: 9px 16px; font-weight: 700; white-space: nowrap; }
#seg button.on { background: var(--ink); color: #fff; }
#period, #more { padding: 9px 10px; font-weight: 700; font-size: inherit; border-radius: 12px; border: 2px solid var(--line); background: var(--card); box-shadow: var(--shadow); max-width: 170px; }
.ibtn { background: var(--card); border: 2px solid var(--line); border-radius: 12px; width: 46px; height: 44px; box-shadow: var(--shadow); font-size: 1.1rem; }
.chip { display: inline-block; background: var(--card); border: 2px solid var(--line); border-radius: 10px; padding: 6px 12px; color: var(--ink); text-decoration: none; font-weight: 600; }

/* status card */
#status { position: absolute; z-index: 4; top: calc(var(--th) + 24px); left: 12px; max-width: min(660px, 56vw); background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 18px; }
#place { font-size: clamp(1.6rem, 2.6vw, 2.5rem); font-weight: 800; line-height: 1.05; }
#place small { font-size: .5em; color: var(--mut); font-weight: 600; margin-left: 8px; }
#sentence { margin-top: 8px; font-size: clamp(1.15rem, 1.8vw, 1.75rem); font-weight: 700; display: flex; flex-wrap: wrap; gap: 8px 10px; line-height: 1.15; }
#sentence small { font-size: .62em; font-weight: 600; opacity: .9; }
.pill { display: inline-flex; align-items: center; gap: 8px; border-radius: 12px; padding: 6px 14px 6px 8px; }
.pill .ic { width: 1.5em; height: 1.5em; font-size: .9em; }
.pill.ev { background: var(--ev); color: #fff; } .pill.wa { background: var(--wa); color: #1d1500; } .pill.sa { background: var(--sa); color: #fff; }
.pill b { font-size: 1.15em; font-variant-numeric: tabular-nums; }
#when { margin-top: 8px; font-size: .9rem; color: var(--mut); }
.eu-card { margin-top: 8px; color: var(--ink); font-size: .95rem; }
.eu-row { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; margin-top: 4px; }
.eu-k { color: var(--mut); width: 100%; font-size: .85rem; }
.eu-ch b { font-variant-numeric: tabular-nums; }
.eu-street { margin-top: 8px; background: var(--ink); color: #fff; border-color: var(--ink); cursor: pointer; }

/* icons: shape + glyph so the level never relies on colour only */
.ic { display: inline-flex; align-items: center; justify-content: center; width: 1.4em; height: 1.4em; font-style: normal; font-weight: 900; color: #fff; flex: none; line-height: 1; }
.ic.ev { background: var(--ev); border-radius: 50%; border: 2px solid #fff; }
.ic.wa { background: var(--wa); color: #1d1500; clip-path: polygon(50% 4%, 98% 94%, 2% 94%); padding-top: .35em; font-size: .8em; }
.ic.sa { background: var(--sa); border-radius: 50%; border: 2px solid #fff; }
.pill .ic.ev, .pill .ic.sa { background: #fff; color: var(--ev); border-color: #fff; }
.pill.sa .ic.sa { color: var(--sa); }
.pill.wa .ic.wa { background: #1d1500; color: var(--wa); }

/* legend */
#legend { position: absolute; z-index: 4; right: 12px; bottom: calc(var(--ph) + 20px); background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 14px; width: 300px; max-width: calc(100vw - 24px); }
#legend .r { display: flex; align-items: center; gap: 10px; padding: 3px 0; font-weight: 700; }
#legend .r span { font-weight: 500; color: var(--mut); font-size: .85rem; }
#legend .ln { width: 34px; flex: none; display: flex; align-items: center; }
#legend .ln i { display: block; width: 100%; border-radius: 3px; }
#legend .dot { width: 16px; height: 16px; border-radius: 50%; flex: none; margin: 0 9px; }
#legend .note { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); font-size: .75rem; color: var(--mut); line-height: 1.3; }
#legend .about { color: var(--ink); font-weight: 700; white-space: nowrap; }

/* player: play / step / speed buttons and the date */
#player { position: absolute; z-index: 5; left: 50%; transform: translateX(-50%); bottom: 12px; width: min(1320px, calc(100vw - 24px)); background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 10px 16px; }
#ctl { display: flex; align-items: center; gap: 10px; }
.play { width: 64px; height: 52px; border-radius: 14px; border: 0; background: var(--ink); color: #fff; font-size: 1.5rem; flex: none; }
#player .ibtn { box-shadow: none; flex: none; }
#b-speed { width: auto; min-width: 64px; padding: 0 10px; white-space: nowrap; font-weight: 700; font-size: .95rem; }
#datebox { margin-left: 10px; min-width: 0; }
#date { font-size: clamp(1.3rem, 2vw, 1.9rem); font-weight: 800; line-height: 1.1; }
#win { font-size: .95rem; color: var(--mut); }
body.live-mode #b-prev, body.live-mode #b-play, body.live-mode #b-next, body.live-mode #b-speed { display: none; }   /* latest forecast = one view */

/* drawer */
#drawer { position: absolute; z-index: 8; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); background: var(--card); box-shadow: -4px 0 18px rgba(10, 25, 40, .35); padding: 16px 20px; overflow: auto; }
#drawer h2 { margin: 0 0 8px; } #drawer h3 { margin: 16px 0 4px; }
#drawer label { display: block; font-weight: 600; margin-top: 10px; }
.rowv { display: flex; align-items: center; gap: 10px; } .rowv input[type=range] { flex: 1; } .rowv span { min-width: 3.4em; text-align: right; font-weight: 700; }
.chk { display: flex !important; gap: 8px; align-items: center; }
#toast { position: absolute; z-index: 9; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(20, 32, 43, .92); color: #fff; padding: 14px 22px; border-radius: 12px; font-weight: 700; font-size: 1.1rem; pointer-events: none; }
#offtag { position: absolute; z-index: 3; right: 12px; bottom: calc(var(--ph) + 210px); background: #fff7e0; border: 1px solid #e3c36b; border-radius: 8px; padding: 3px 10px; font-size: .78rem; font-weight: 600; }

/* "pick dates" dialog */
#custom { position: fixed; inset: 0; z-index: 30; background: rgba(10,20,30,.35); display: flex; align-items: center; justify-content: center; }
#custom .cdlg { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; width: min(320px, calc(100vw - 32px)); }
#custom label { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
#custom input { font: inherit; padding: 4px 6px; border: 2px solid var(--line); border-radius: 8px; }
#custom .cbtns { display: flex; justify-content: flex-end; gap: 8px; }
#custom .cbtns .ibtn { width: auto; min-width: 0; padding: 6px 14px; }
#custom .go { background: #1d3b53; color: #fff; }
#custom small { color: var(--mut); }

/* map bits */
.maplibregl-popup-content { font-family: inherit; font-size: 1rem; padding: 10px 14px; border-radius: 10px; }
.maplibregl-popup-content b { display: block; }
.maplibregl-ctrl-bottom-left { bottom: calc(var(--ph) + 12px); }
.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-top-right { display: none; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* no data */
.fatal { max-width: 640px; margin: 12vh auto; padding: 24px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); line-height: 1.45; }
.fatal h1 { font-size: 1.4rem; margin: 0 0 12px; }
html:has(.fatal), body:has(.fatal) { overflow: auto; }

/* Europe scope: Towns-only menus hidden */
body.scope-europe #more, body.scope-europe #period { display: none !important; }
/* presenter mode (key P): only the story stays */
body.presenter, body.presenter * { cursor: none !important; }
body.presenter #b-exp, body.presenter #searchwrap, body.presenter #drawer, body.presenter .maplibregl-ctrl-bottom-left, body.presenter #modes, body.presenter .about { display: none !important; }
/* presentation in a deck (?present=1): no pickers, no player controls */
body.present #top, body.present #b-prev, body.present #b-play, body.present #b-next, body.present #b-speed, body.present #custom, body.present .about { display: none !important; }
body.present #status { top: 16px; }
body.present #date { font-size: 2.1rem; }

/* wide screens: legend and player share the bottom row */
@media (min-width: 1100px) { #player { left: 12px; transform: none; width: calc(100vw - 336px); } #legend { bottom: 12px; } }
@media (min-width: 2201px) { .pl .full { display: inline; } .pl .short { display: none; } #q { width: 190px; } }
@media (max-width: 1700px) { .pl kbd { display: none; } #more { max-width: 130px; } #period { max-width: 140px; } }
@media (max-width: 1500px) { :root { font-size: 17px; } #top { flex-wrap: wrap; row-gap: 6px; } #top .grow { display: none; }
  #q { width: 120px; } .pl { padding: 7px 11px 7px 6px; gap: 6px; } #seg button { padding: 9px 12px; } #places { gap: 5px; } }
@media (max-height: 800px) { :root { font-size: 16px; } #status { padding: 8px 14px; } }
/* phones: compact cards, legend above the player */
@media (max-width: 700px) {
  :root { font-size: 14px; }
  #top { top: 8px; left: 8px; right: 8px; }
  #places { flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; }
  #status { left: 8px; right: 8px; max-width: none; top: calc(var(--th) + 16px); padding: 8px 12px; }
  #player { padding: 6px 10px; bottom: 8px; width: calc(100vw - 16px); }
  .play { width: 52px; height: 44px; }
  #legend { right: 8px; left: 8px; width: auto; max-width: none; padding: 6px 10px; bottom: calc(var(--ph) + 14px); }
  #legend .r span { display: none; }
}

/* first-visit intro: what the map shows and how it was built (shown once, reopened from the settings drawer) */
#intro { position: fixed; inset: 0; z-index: 40; background: rgba(10, 20, 30, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
#intro[hidden] { display: none; }
.in-card { background: var(--card); color: var(--ink); border-radius: 18px; box-shadow: 0 8px 40px rgba(10, 25, 40, .4); max-width: 640px; width: 100%; max-height: calc(100vh - 32px); overflow: auto; padding: 22px 26px 20px; }
.in-tag { margin: 0 0 4px; font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--mut); }
.in-card h2 { margin: 0 0 8px; font-size: 1.45rem; line-height: 1.2; }
.in-lead { margin: 0 0 14px; color: var(--mut); line-height: 1.45; }
.in-steps { margin: 0 0 12px; padding: 0; list-style: none; counter-reset: st; }
.in-steps li { counter-increment: st; position: relative; padding: 0 0 12px 40px; line-height: 1.45; font-size: .93rem; }
.in-steps li::before { content: counter(st); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; font-weight: 700; font-size: .85rem; display: flex; align-items: center; justify-content: center; }
.in-steps b { display: block; margin-bottom: 1px; }
.in-warn { margin: 0 0 14px; padding: 8px 12px; border-left: 4px solid var(--wa); background: #fff8e6; border-radius: 6px; font-size: .85rem; line-height: 1.4; }
.in-act { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.in-go { background: var(--ink); color: #fff; border-color: var(--ink); }
@media (max-width: 560px) { .in-card { padding: 18px 16px 16px; } .in-card h2 { font-size: 1.2rem; } .in-steps li { font-size: .88rem; } }

/* "How we built it": large in-app dialog; its text is the <article id="doc"> of about.html (one source for both) */
#howto { position: fixed; inset: 0; z-index: 41; background: rgba(10, 20, 30, .5); display: flex; align-items: center; justify-content: center; padding: 16px; }
#howto[hidden] { display: none; }
.ht-card { background: var(--card); color: var(--ink); border-radius: 18px; box-shadow: 0 8px 40px rgba(10, 25, 40, .4); width: min(1100px, 100%); height: min(92vh, 1000px); display: flex; flex-direction: column; overflow: hidden; }
.ht-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 22px 12px; border-bottom: 2px solid var(--line); }
.ht-head > div { flex: 1; } .ht-head h2 { margin: 0; font-size: 1.45rem; line-height: 1.2; }
.ht-ext { font-size: .8rem; color: var(--mut); white-space: nowrap; margin-top: 8px; }
.ht-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 210px 1fr; }
#ht-nav { padding: 14px 10px 14px 16px; border-right: 1px solid var(--line); overflow: auto; }
#ht-nav a { display: block; padding: 7px 10px; border-radius: 8px; color: var(--mut); text-decoration: none; font-size: .88rem; font-weight: 600; }
#ht-nav a:hover { background: #eef1f4; color: var(--ink); } #ht-nav a.on { background: var(--ink); color: #fff; }
#ht-doc { overflow: auto; padding: 18px 30px 40px; line-height: 1.55; font-size: .95rem; outline: none; scroll-behavior: smooth; }
.ab article { max-width: 760px; }
.ab p { margin: 0 0 12px; } .ab .lead { font-size: 1.08rem; } .ab .small { font-size: .8rem; } .ab .mut { color: var(--mut); }
.ab a { color: #1f5fbf; }
.ab h2 { font-size: 1.2rem; margin: 34px 0 10px; padding-top: 14px; border-top: 2px solid var(--line); scroll-margin-top: 4px; }
.ab h2:first-of-type { margin-top: 22px; }
.ab h3 { font-size: 1rem; margin: 20px 0 6px; }
.ab .flow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.ab .flow div { background: #f6f8fa; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: .86rem; line-height: 1.4; }
.ab .flow b { display: block; font-size: .96rem; margin-bottom: 3px; }
.ab .flow i { font-style: normal; display: inline-block; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; text-align: center; font-weight: 700; font-size: .78rem; line-height: 22px; margin-right: 6px; }
.ab .feat { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin: 10px 0 14px; padding: 0; list-style: none; }
.ab .feat li { background: #f6f8fa; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: .84rem; line-height: 1.35; }
.ab .feat b { display: block; font-size: .9rem; }
.ab .levels { display: grid; gap: 8px; margin: 12px 0; }
.ab .lv { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.ab .lv p { margin: 0; }
.ab .ic { width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; font-weight: 900; color: #fff; }
.ab .ic.ev { background: var(--ev); border-radius: 50%; } .ab .ic.sa { background: var(--sa); border-radius: 50%; }
.ab .ic.wa { background: var(--wa); color: #1d1500; clip-path: polygon(50% 4%, 98% 94%, 2% 94%); padding-top: 8px; font-size: .75rem; }
.ab .score { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.ab .score div { background: #f6f8fa; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.ab .score b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.ab .score span { font-size: .78rem; color: var(--mut); line-height: 1.3; display: block; }
.ab .tbl { overflow-x: auto; margin: 10px 0 14px; border: 1px solid var(--line); border-radius: 12px; }
.ab table { border-collapse: collapse; width: 100%; font-size: .82rem; }
.ab th, .ab td { text-align: left; vertical-align: top; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.ab th { background: #f6f8fa; } .ab tr:last-child td { border-bottom: 0; } .ab td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ab ol.steps { padding-left: 1.3em; margin: 8px 0; } .ab ol.steps li { margin-bottom: 8px; }
@media (max-width: 760px) {
  #howto { padding: 0; } .ht-card { border-radius: 0; height: 100%; }
  .ht-head { padding: 14px 16px 10px; } .ht-head h2 { font-size: 1.2rem; } .ht-ext { display: none; }
  .ht-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #ht-nav { display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; }
  #ht-nav a { white-space: nowrap; padding: 6px 10px; }
  #ht-doc { padding: 14px 16px 32px; } .ab .flow { grid-template-columns: 1fr; }
}

/* chain diagram + worked example inside the dialog (same rules as about.html) */
.ab .chain { display: grid; gap: 10px; margin: 14px 0 6px; }
.ab .chain .lane { display: grid; grid-template-columns: 1.35fr 1fr 1.15fr; gap: 26px; position: relative; }
.ab .chain .nd { position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: .82rem; line-height: 1.35; background: var(--card); }
.ab .chain .nd small { display: block; font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--mut); }
.ab .chain .nd b { display: block; font-size: .95rem; margin: 1px 0 4px; }
.ab .chain .nd ul { margin: 0; padding-left: 1.05em; } .chain .nd li { margin: 0 0 2px; }
.ab .chain .nd .lab { margin: 6px 0 0; padding-top: 6px; border-top: 1px dashed var(--line); color: var(--mut); font-size: .76rem; }
.ab .chain .md { background: var(--ink); color: var(--card); border-color: var(--ink); align-self: center; }
.ab .chain .md small { color: inherit; opacity: .75; }
.ab .chain .out { align-self: center; }
.ab .chain .lane > .nd + .nd::before { content: "→"; position: absolute; left: -23px; top: 50%; transform: translateY(-50%); font-weight: 700; font-size: 1.25rem; color: var(--ink); }
.ab .chain .chips { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 4px; }
.ab .chain .chips i { font-style: normal; font-weight: 700; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; background: rgba(127, 140, 155, .12); }
.ab .chain .merge { position: relative; margin-top: 14px; border: 2px solid var(--ink); border-radius: 12px; padding: 10px 14px; font-size: .9rem; line-height: 1.4; }
.ab .chain .merge::before { content: "↓"; position: absolute; top: -24px; right: 18%; font-weight: 700; font-size: 1.25rem; color: var(--ink); }
.ab .chain .merge small { display: block; font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--mut); }
.ab .chain .merge b { display: block; margin: 2px 0 8px; }
.ab .chain .lvls { display: flex; gap: 6px; flex-wrap: wrap; }
.ab .chain .pill { border-radius: 8px; padding: 3px 9px; font-size: .8rem; font-weight: 700; }
.ab .chain .pill.wa { background: var(--wa); color: #1d1500; } .chain .pill.ev { background: var(--ev); color: #fff; }
.ab table.sum tr.tot td { font-weight: 700; background: rgba(127, 140, 155, .1); }
.ab .bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 4px 0 8px; border: 1px solid var(--line); }
.ab .bar .s1 { background: #f6d27a; } .bar .s2 { background: #f2a600; } .bar .s3 { background: #d9622b; } .bar .s4 { background: #c0182d; }
@media (max-width: 760px) {
.ab .chain .lane { grid-template-columns: 1fr; gap: 20px; }
.ab .chain .lane > .nd + .nd::before { content: "↓"; left: 50%; top: -18px; transform: translateX(-50%); }
.ab .chain .lane + .lane { margin-top: 10px; padding-top: 12px; border-top: 1px dashed var(--line); }
.ab .chain .merge::before { right: 50%; }
}
