/* One system for every surface. Tokens, type scale and rules are written up in web/DESIGN.md.
   Identity: 옻칠 (lacquer) surfaces, 자개 (nacre) for the one accent, the hexagon for badges. Data colours live in
   js/palettes.js; the yield colours are mirrored here because CSS needs them too. */
:root {
  /* surfaces */
  --lacquer: #17222c; --lacquer-2: #1f2e3a; --lacquer-3: #2a3c4a; --ink: #0f171e;
  --sea-deep: #1b3a52;
  --float: rgb(23 34 44 / .94);            /* panels that sit on the map */
  --line: rgb(232 239 233 / .1);           /* hairlines inside a surface */
  --line-strong: #2f4353;                  /* edges of a surface, control borders */
  /* text: 13.8:1, 7.8:1 and 9.7:1 on --lacquer */
  --pearl: #e8efe9; --pearl-dim: #a9b8b4; --nacre: #9fd3c7;
  /* yields and their neighbours (js/palettes.js is the source) */
  --food: #ea9602; --production: #d15d4d; --gold: #f2dc4e; --science: #6ea4f4; --culture: #a66db3; --health: #68bf9b; --other: #6f7d86;
  --warn: #f58860;
  /* shape: 4px for controls, 8px for surfaces, the hexagon for badges, a full round only for the play button and toast */
  --r-1: 4px; --r-2: 8px;
  --radius-s: var(--r-1); --radius-l: var(--r-2); /* names used by logos.css */
  --hex: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  /* space: a 4px base */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px;
  /* type: Pretendard for the interface, Gowun Batang only for names and titles */
  --font-ui: "Pretendard Variable", Pretendard, system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-title: "Gowun Batang", "Nanum Myeongjo", serif;
  --t-meta: 11px; --t-small: 12px; --t-ui: 13px; --t-body: 14px; --t-lead: 16px; --t-stat: 18px; --t-title: 20px; --t-display: 28px;
  --bar-h: 48px; --dock-w: 216px; --panel-w: 392px; --gap: 12px; --tap: 32px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--sea-deep); color: var(--pearl); font-family: var(--font-ui); font-size: var(--t-body); line-height: 1.45;
  font-variant-numeric: tabular-nums; -webkit-text-size-adjust: 100%; accent-color: var(--nacre); caret-color: var(--nacre); }
body { display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); overflow: hidden; height: 100dvh; }
::selection { background: rgb(159 211 199 / .32); color: #fff; }
* { scrollbar-width: thin; scrollbar-color: var(--lacquer-3) transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
h1, h2, h3, h4, p { margin: 0; }
h2 { text-wrap: balance; }
a { color: var(--nacre); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--nacre); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--pearl-dim); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
/* headings that take focus when a dialog or the panel opens (so a pointer-opened dialog shows no ring on its close button) */
.dlg-head h2:focus, .cp-banner h2:focus { outline: 0; }
#map:focus-visible { outline-offset: -3px; }
.ico { display: inline-block; flex: none; vertical-align: -3px; }
.num { text-align: right; }

/* ---- controls ---- */
.tb-btn, .ghost, .icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); border-radius: var(--r-1); white-space: nowrap; }
.tb-btn { padding: 0 10px; background: none; border: 0; font-size: var(--t-ui); font-weight: 500; }
.tb-btn:hover, .tb-btn[aria-expanded="true"] { background: var(--lacquer-3); }
.tb-btn:disabled { opacity: .5; cursor: progress; }
.ghost { padding: 0 10px; background: none; border: 1px solid var(--line-strong); font-size: var(--t-ui); }
.ghost:hover { border-color: var(--nacre); }
.icon-btn { width: var(--tap); padding: 0; background: none; border: 0; color: var(--pearl-dim); }
.icon-btn:hover { background: var(--lacquer-3); color: var(--pearl); }
input[type="search"], select { background: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r-1); padding: 0 10px; min-height: var(--tap); }
input[type="search"]::placeholder { color: var(--pearl-dim); opacity: 1; }
input[type="search"]:hover, select:hover { border-color: #456073; }
input[type="checkbox"] { width: 15px; height: 15px; margin: 0; flex: none; }
.check, .toggle, .tb-chg { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--t-ui); }
kbd { display: inline-block; min-width: 24px; text-align: center; padding: 1px 6px; font: 600 var(--t-small) var(--font-ui); background: var(--lacquer-2); border: 1px solid var(--line-strong); border-radius: var(--r-1); }

/* ---- top bar ---- */
#topbar { display: flex; align-items: center; gap: var(--s-4); min-width: 0; min-height: var(--bar-h); padding: var(--safe-t) calc(var(--s-3) + var(--safe-r)) 0 calc(var(--s-4) + var(--safe-l));
  background: var(--lacquer); border-bottom: 1px solid var(--line-strong); z-index: 12; }
.brand { display: flex; align-items: center; gap: var(--s-2); white-space: nowrap; font-family: var(--font-title); font-weight: 700; font-size: 17px; }
.seal { width: 20px; height: 22px; background: var(--food); clip-path: var(--hex); display: grid; place-items: center; }
.seal::after { content: ""; width: 12px; height: 13px; background: var(--production); clip-path: var(--hex); }
.yields { display: flex; gap: var(--s-4); flex: 1 1 0; min-width: 0; overflow: hidden; font-size: var(--t-ui); }
.yield { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.yield b { font-weight: 600; }
.yield small { color: var(--pearl-dim); font-size: var(--t-meta); }
.search { position: relative; }
.search input { width: 180px; }
#search-results { position: absolute; top: calc(100% + 6px); right: 0; z-index: 7; width: 260px; max-height: 320px; overflow: auto; list-style: none; margin: 0; padding: var(--s-1);
  background: var(--lacquer-2); border: 1px solid var(--line-strong); border-radius: var(--r-2); display: none; }
#search-results.open { display: block; }
#search-results li { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); min-height: var(--tap); padding: 0 var(--s-2); border-radius: var(--r-1); cursor: pointer; }
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--lacquer-3); }
#search-results li .muted { font-size: var(--t-small); }
.top-actions { display: flex; align-items: center; gap: 2px; }
.menu-wrap { position: relative; display: flex; }
#btn-share-more { padding: 0 4px; margin-left: -2px; }
.more-wrap { display: none; }

/* ---- menus: a popover under its button; a bottom sheet on phones ---- */
.menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 8; display: grid; gap: 1px; min-width: 220px; max-height: min(70vh, 560px); overflow-y: auto; padding: var(--s-1);
  background: var(--lacquer-2); border: 1px solid var(--line-strong); border-radius: var(--r-2); }
.menu button { display: flex; align-items: center; gap: var(--s-2); width: 100%; min-height: 36px; padding: 6px var(--s-3); background: none; border: 0; border-radius: var(--r-1); text-align: left; font-size: var(--t-ui); }
.menu button:hover, .menu button:focus-visible { background: var(--lacquer-3); }
.menu .ico { color: var(--pearl-dim); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-1) 0; }
.menu-title { padding: var(--s-2) var(--s-3) var(--s-1); font-size: var(--t-small); color: var(--pearl-dim); }
#scene-menu { width: 340px; }
.scene-item { align-items: flex-start !important; }
.scene-item .ico { margin-top: 2px; }
.scene-item b { display: block; font-weight: 600; }
.scene-item small { display: block; color: var(--pearl-dim); font-size: var(--t-small); line-height: 1.4; white-space: normal; }
.scene-item[aria-current="true"] b { color: var(--nacre); }
.scrim { position: fixed; inset: 0; z-index: 11; background: rgb(8 12 16 / .55); }

/* ---- stage ---- */
#stage { position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#flow-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* the loading line (js/stages.js): one step at a time, near the top edge of the map, gone once the map answers.
   Four hexagon marks: done (nacre), the step running (nacre, breathing unless motion is reduced), still to come. */
.stages { position: absolute; top: var(--gap); left: 50%; transform: translateX(-50%); z-index: 5; display: flex; align-items: center; gap: var(--s-2);
  max-width: calc(100% - 2 * var(--gap)); padding: 6px var(--s-3); background: var(--float); border: 1px solid var(--line-strong); border-radius: var(--r-2);
  font-size: var(--t-small); color: var(--pearl); white-space: nowrap; pointer-events: none; }
.st-pips { display: inline-flex; gap: 3px; }
.st-pips i { width: 8px; height: 9px; clip-path: var(--hex); background: var(--lacquer-3); }
.st-pips i.done { background: var(--nacre); }
.st-pips i.now { background: var(--nacre); animation: st-breathe 1.2s var(--ease) infinite alternate; }
@keyframes st-breathe { from { opacity: .3; } to { opacity: .85; } }
.stages.done { opacity: 0; transition: opacity .3s var(--ease) .55s; }
.stages.failed { white-space: normal; color: var(--warn); pointer-events: auto; }
@media (prefers-reduced-motion: reduce) { .st-pips i.now { animation: none; opacity: .6; } .stages.done { transition: none; opacity: 1; } }
/* until the map answers (app.js adds body.live) its floating panels are empty: they keep their place, unseen */
body:not(.live) :is(#lens-dock, #minimap) { visibility: hidden; }
/* a lens whose tiles are on their way (app.js setLens): its button says so; the legend has its own line */
.lens-btn[aria-busy="true"] .nm::after { content: "불러오는 중"; margin-left: var(--s-2); font-size: var(--t-meta); font-weight: 400; color: var(--pearl-dim); }
.lg-loading { margin: var(--s-2) 0 0; color: var(--nacre); font-size: var(--t-small); }
#lens-dock, #legend, #minimap, #timebar, #scene-strip, #hint { background: var(--float); border: 1px solid var(--line-strong); border-radius: var(--r-2); }

/* ---- lens dock ---- */
#lens-dock { position: absolute; left: calc(var(--gap) + var(--safe-l)); top: var(--gap); width: var(--dock-w); max-height: calc(100% - var(--legend-h, 220px) - 3 * var(--gap));
  display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--s-2) var(--s-2); }
.dock-handle { display: none; }
.dh-x { display: none; margin-left: auto; color: var(--pearl-dim); }
#lens-dock.open .dh-x { display: inline-flex; }
.dock-filter { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: var(--s-2); margin: 0 calc(-1 * var(--s-2)) var(--s-1); padding: var(--s-2) var(--s-3); color: var(--pearl-dim);
  background: var(--lacquer); border-bottom: 1px solid var(--line); border-radius: var(--r-2) var(--r-2) 0 0; }
.dock-filter input { flex: 1; min-width: 0; min-height: 28px; padding: 0 2px; background: none; border: 0; font-size: var(--t-ui); }
.dock-filter input:focus { outline: 0; }
.dock-filter:focus-within { box-shadow: inset 0 -2px 0 var(--nacre); }
.dock-empty { margin: var(--s-2) var(--s-1); font-size: var(--t-small); }
.dock-group { display: flex; flex-direction: column; gap: 1px; }
.dock-group > summary { display: flex; align-items: center; gap: 6px; min-height: 28px; margin-top: var(--s-2); padding: 0 6px; border-radius: var(--r-1); cursor: pointer; list-style: none; color: var(--pearl-dim); }
.dock-group > summary::-webkit-details-marker { display: none; }
.dock-group > summary:hover { color: var(--pearl); }
.dock-group > summary h3 { flex: 1; font-size: var(--t-small); font-weight: 600; }
.dock-group > summary .chev { transition: transform .16s var(--ease); }
.dock-group:not([open]) > summary .chev { transform: rotate(-90deg); }
.lens-btn { display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--tap); padding: 0 var(--s-2); background: none; border: 0; border-radius: var(--r-1); text-align: left; font-size: var(--t-ui); }
.lens-btn .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lens-btn:hover { background: var(--lacquer-2); }
.lens-btn[aria-pressed="true"] { background: var(--lacquer-3); font-weight: 600; box-shadow: inset 0 0 0 1px rgb(159 211 199 / .55); }
#lens-dock .toggle { min-height: var(--tap); padding: 0 var(--s-2); }

/* ---- legend ---- */
#legend { position: absolute; left: calc(var(--gap) + var(--safe-l)); bottom: var(--gap); width: 300px; padding: var(--s-3); font-size: var(--t-small); }
#legend .title { display: flex; align-items: baseline; gap: 6px; font-size: var(--t-body); font-weight: 600; }
.lg-year { color: var(--nacre); }
.lg-src, .lg-more { margin-left: auto; background: none; border: 0; padding: 0 2px; font-size: var(--t-small); font-weight: 400; color: var(--pearl-dim); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.lg-src:hover, .lg-more:hover { color: var(--pearl); }
.lg-more { display: inline-block; }
#legend:not(.open) .note { display: none; }
#legend .title .lg-src { margin-left: var(--s-3); }
/* what the lens measures, in one plain line; named bands over the ramp; which way the colours run and the reference value */
.lg-formula { margin-top: 2px; color: var(--pearl); line-height: 1.45; text-wrap: pretty; }
.bands { position: relative; height: 16px; margin-top: var(--s-2); font-size: var(--t-meta); color: var(--pearl-dim); }
.hist + .bands { margin-top: 0; }
.bands span { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; border-left: 1px solid var(--pearl-dim); }
.bands span:first-child { border-left: 0; }
.bands.ends span:first-child { justify-content: flex-start; }
.bands.ends span:last-child { justify-content: flex-end; border-left: 0; }
.bands.ends span:first-child i::before { content: "← "; }
.bands.ends span:last-child i::after { content: " →"; }
.bands.ends i { padding: 0 4px 0 0; background: var(--lacquer); border-radius: 2px; } /* (covers the histogram's marks where they cross the words) */
.bands.ends span:last-child i { padding: 0 0 0 4px; }
.bands i { font-style: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 3px; }
#legend .ramp { position: relative; }
.ramp-ref { position: absolute; top: -3px; bottom: -3px; width: 0; border-left: 2px dashed #fff; margin-left: -1px; filter: drop-shadow(0 0 1px #000); }
.hm-ref { border-left: 1px dashed rgb(232 239 233 / .7); bottom: 0; }
.lg-dir { margin-top: var(--s-1); color: var(--pearl-dim); line-height: 1.45; text-wrap: pretty; }
.lg-ref { color: var(--pearl); white-space: nowrap; }
.lg-ref i { display: inline-block; height: 10px; border-left: 2px dashed #fff; margin-right: 5px; vertical-align: -1px; }
#legend .note { margin: var(--s-2) 0 0; color: var(--pearl-dim); line-height: 1.5; text-wrap: pretty; }
#legend .ramp { height: 8px; border-radius: 2px; }
#legend .ticks { display: flex; justify-content: space-between; margin-top: 3px; color: var(--pearl-dim); }
.lg-na { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-2); color: var(--pearl-dim); }
.lg-na i { width: 14px; height: 10px; border-radius: 2px; flex: none; }
.lg-na span { margin-left: auto; }
/* 비교 단위: segmented control, the line that says which unit is on screen, and (phones) a chip in the title row */
.lg-name { min-width: 0; }
.lg-unit { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-2); }
.lu-k { color: var(--pearl-dim); }
.seg { display: flex; margin-left: auto; border: 1px solid var(--line-strong); border-radius: var(--r-1); overflow: hidden; }
.seg button { min-height: 24px; padding: 0 9px; background: none; border: 0; border-left: 1px solid var(--line-strong); font-size: var(--t-small); color: var(--pearl-dim); white-space: nowrap; }
.seg button:first-child { border-left: 0; }
.seg button:hover { color: var(--pearl); background: var(--lacquer-2); }
.seg button[aria-pressed="true"] { background: var(--lacquer-3); color: var(--pearl); font-weight: 600; box-shadow: inset 0 -2px 0 var(--nacre); }
.seg button:focus-visible { outline-offset: -2px; }
.lg-now { margin-top: 3px; color: var(--nacre); font-size: var(--t-meta); }
.lg-how { color: var(--pearl); }
.lg-uchip { display: none; flex: none; min-height: 22px; padding: 0 8px; background: var(--lacquer-3); border: 1px solid var(--line-strong); border-radius: var(--r-1); font-size: var(--t-meta); font-weight: 500; color: var(--nacre); white-space: nowrap; }
/* histogram over the ramp: bars share the ramp's colours; hovering or brushing filters the map */
.hist { position: relative; display: flex; align-items: flex-end; height: 44px; margin-bottom: 2px; cursor: crosshair; touch-action: none; user-select: none; }
.hb { flex: 1; height: 100%; display: flex; align-items: flex-end; padding: 0 .5px; }
.hb i { display: block; width: 100%; border-radius: 1px 1px 0 0; pointer-events: none; border-top: 1.5px solid rgb(232 239 233 / .6); }
.hb i[style*="height:0%"] { border-top: 0; }
.hb.off i { opacity: .22; }
.hm { position: absolute; top: -2px; bottom: -12px; width: 0; border-left: 2px solid #fff; margin-left: -1px; pointer-events: none; filter: drop-shadow(0 0 1px #000); }
.hm-sel { border-left-color: var(--nacre); }
.hist.strip { border-bottom: 1px solid var(--line); }
.sd { position: absolute; width: 9px; height: 9px; margin-left: -4.5px; border-radius: 50%; box-shadow: 0 0 0 1px rgb(232 239 233 / .7); pointer-events: none; }
.sd.off { opacity: .22; }
.hist-read { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); min-height: 22px; margin-top: var(--s-1); color: var(--pearl-dim); }
.hr-clear { min-height: 22px; padding: 0 var(--s-2); background: none; border: 1px solid var(--line-strong); border-radius: var(--r-1); font-size: var(--t-meta); }
.hr-clear:hover { border-color: var(--nacre); }
/* leaderboard */
.lb { margin-top: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--line); }
.lb summary { cursor: pointer; font-weight: 600; }
.lb-rank { font-weight: 400; color: var(--pearl-dim); margin-left: var(--s-1); }
.lb-list { margin-top: var(--s-1); max-height: clamp(110px, calc(100dvh - 664px), 360px); overflow-y: auto; overscroll-behavior: contain; }
.lb ol + ol { margin-top: 3px; padding-top: 3px; border-top: 1px dashed var(--line-strong); }
.lb ol, .top-cities, .cats, .bv-key, .flow-key { list-style: none; margin: 0; padding: 0; }
.lb li button, .top-cities button { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: var(--s-1); width: 100%; min-height: 22px; padding: 0 var(--s-1); background: none; border: 0; border-radius: var(--r-1); text-align: left; font-size: var(--t-small); }
.lb li button:hover, .lb li button.on, .top-cities button:hover { background: var(--lacquer-3); }
.lb .n, .lb .v, .top-cities .n, .top-cities .v { color: var(--pearl-dim); }
.lb li button { grid-template-columns: 24px minmax(0, 1fr) auto auto; gap: var(--s-2); align-items: center; }
.lb .n, .lb .v { text-align: right; }
.lb .n { padding-right: 2px; }
.lb .b { min-width: 30px; font-size: var(--t-meta); color: var(--nacre); white-space: nowrap; }
.lb .nm, .top-cities .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* categorical and bivariate keys */
.cats { display: grid; gap: 6px; }
.cats li { display: grid; grid-template-columns: 12px auto 1fr; gap: var(--s-2); align-items: center; }
.cats i, .bv-key i, .flow-key i { width: 12px; height: 12px; border-radius: 2px; flex: none; box-shadow: inset 0 0 0 1px rgb(232 239 233 / .25); }
.cats b { font-weight: 600; }
.cats span { color: var(--pearl-dim); text-align: right; }
.bivar { display: flex; gap: var(--s-4); align-items: center; color: var(--pearl-dim); }
.bv-grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 2px; width: 84px; height: 84px; margin: 3px 0; }
.bv-grid i { display: block; border-radius: 2px; box-shadow: inset 0 0 0 1px rgb(232 239 233 / .14); }
.bv-y, .bv-x { display: block; white-space: nowrap; font-size: var(--t-meta); }
.bv-x { text-align: right; }
.bv-key { display: grid; gap: var(--s-1); }
.bv-key li { display: flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--pearl); }
.bv-key span { color: var(--pearl-dim); }
.flow-note { margin-top: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--line); color: var(--pearl-dim); line-height: 1.5; }
.flow-note b { color: var(--pearl); }
.flow-key { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-3); margin-top: var(--s-2); color: var(--pearl); }
.flow-key li { display: inline-flex; align-items: center; gap: 6px; }
.flow-key i { height: 4px; width: 14px; box-shadow: none; }

/* ---- scene strip: the first-visit cards, then the caption of the scene on screen ---- */
#scene-strip { position: absolute; left: calc(300px + 2 * var(--gap) + var(--safe-l)); right: calc(180px + 2 * var(--gap) + 2px); bottom: var(--gap); max-width: 760px; margin: 0 auto; padding: var(--s-2) var(--s-3); z-index: 2; }
body.panel-open #scene-strip { right: calc(var(--panel-w) + 180px + 3 * var(--gap)); }
.ss-head { display: flex; align-items: center; gap: var(--s-2); min-height: 28px; }
.ss-head h3 { font-size: var(--t-ui); font-weight: 600; }
.ss-head p { flex: 1; min-width: 0; font-size: var(--t-small); color: var(--pearl-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-head .icon-btn { width: 28px; min-height: 28px; }
.ss-cards { display: flex; gap: var(--s-2); margin-top: var(--s-1); overflow-x: auto; scroll-snap-type: x proximity; overscroll-behavior-x: contain; padding-bottom: 2px; }
.ss-card { flex: 0 0 176px; scroll-snap-align: start; display: block; min-height: 58px; padding: var(--s-2) 10px; background: var(--lacquer-2); border: 1px solid var(--line); border-radius: var(--r-1); text-align: left; }
.ss-card:hover { border-color: var(--nacre); }
.ss-card b { display: block; font-size: var(--t-ui); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-card small { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; margin-top: 2px; font-size: var(--t-meta); line-height: 1.4; color: var(--pearl-dim); }
.ss-now { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px var(--s-2); align-items: center; }
.ss-now h3 { font-family: var(--font-title); font-size: var(--t-lead); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-now p { grid-column: 1; font-size: var(--t-small); color: var(--pearl-dim); line-height: 1.45; text-wrap: pretty; }
.ss-nav { grid-row: 1 / 3; grid-column: 2; display: flex; align-items: center; }
.ss-nav .count { margin: 0 var(--s-1); font-size: var(--t-meta); color: var(--pearl-dim); }

/* ---- minimap, timebar, tooltip, toast ---- */
#minimap { position: absolute; right: calc(var(--gap) + var(--safe-r)); bottom: var(--gap); cursor: pointer; }
body.panel-open #minimap { right: calc(var(--panel-w) + var(--gap)); }
/* the timebar (and the first-visit line) sit centred in the part of the map between the dock and the panel */
#timebar { position: absolute; top: var(--gap); left: calc(var(--dock-w) + 2 * var(--gap) + var(--safe-l)); right: calc(var(--gap) + var(--safe-r)); max-width: 560px; margin: 0 auto; z-index: 2; display: flex; align-items: center; gap: var(--s-4); padding: var(--s-2) var(--s-4) var(--s-2) var(--s-3); }
body.panel-open #timebar { right: calc(var(--panel-w) + var(--gap)); }
#timebar .play { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--nacre); background: none; color: var(--nacre); }
#timebar .play:hover { background: rgb(159 211 199 / .14); }
#timebar .year { font-family: var(--font-title); font-weight: 700; font-size: 26px; line-height: 1; }
#timebar .sub { margin-top: 2px; font-size: var(--t-meta); white-space: nowrap; }
#timebar input[type=range] { flex: 1; min-width: 0; height: 28px; }
/* first visit: one line at the top of the free part of the map; only its close button takes the pointer */
#hint { position: absolute; top: var(--gap); left: calc(var(--dock-w) + 2 * var(--gap) + var(--safe-l)); right: calc(var(--gap) + var(--safe-r)); z-index: 2; width: fit-content; max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-1) var(--s-1) var(--s-3); font-size: var(--t-ui); line-height: 1.45; pointer-events: none; }
#hint p { text-wrap: pretty; }
#hint b { color: var(--nacre); font-weight: 600; }
#hint .icon-btn { flex: none; pointer-events: auto; }
body.panel-open #hint { right: calc(var(--panel-w) + var(--gap)); }
#timebar:not([hidden]) ~ #hint { display: none; }
/* the tip lets the map show through: ink at 80% with a blur keeps pearl-dim text above 4.5:1 on the lightest tile */
#tooltip { position: absolute; z-index: 4; pointer-events: none; max-width: 224px; padding: 6px 10px; background: rgb(15 23 30 / .8); -webkit-backdrop-filter: blur(8px) saturate(1.2); backdrop-filter: blur(8px) saturate(1.2);
  border: 1px solid rgb(232 239 233 / .16); border-radius: var(--r-1); font-size: var(--t-small); line-height: 1.45; text-shadow: 0 1px 2px rgb(0 0 0 / .55); }
#tooltip.chip { z-index: 11; border-color: rgb(159 211 199 / .5); } /* after a tap: above the sheet's edge, gone in two seconds */
#tooltip .t-more { margin-top: var(--s-1); padding-top: var(--s-1); border-top: 1px solid var(--line); }
#tooltip .t-band { font-weight: 400; color: var(--nacre); }
#tooltip .t-head { font-weight: 600; font-size: var(--t-body); }
#tooltip .t-sub { color: var(--pearl-dim); }
#tooltip .row { display: flex; justify-content: space-between; gap: var(--s-4); }
#tooltip .row > span:first-child { color: var(--pearl-dim); }
#tooltip .row.yl { margin-top: var(--s-1); padding-top: var(--s-1); border-top: 1px solid var(--line); }
#tooltip .row.yl > span { color: var(--pearl); }
#toast { position: fixed; left: 50%; bottom: calc(28px + var(--safe-b)); transform: translateX(-50%); z-index: 20; padding: var(--s-2) var(--s-4); background: var(--ink); border: 1px solid var(--nacre); border-radius: 999px; font-size: var(--t-ui); }

/* ---- city and province panel ---- */
#city-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 3; width: var(--panel-w); max-width: 100vw; overflow: hidden auto; overscroll-behavior: contain; overflow-wrap: anywhere;
  background: var(--lacquer); border-left: 1px solid var(--line-strong); padding-right: var(--safe-r); }
.sheet-grip { display: none; }
.cp-banner { padding: var(--s-5) var(--s-5) var(--s-3); }
.cp-head { display: flex; align-items: flex-start; gap: var(--s-3); }
.cp-id { flex: 1; min-width: 0; }
.cp-banner h2 { font-family: var(--font-title); font-size: var(--t-display); font-weight: 700; line-height: 1.15; }
.cp-banner .prov { margin-top: 2px; color: var(--pearl-dim); font-size: var(--t-ui); }
.cp-title { display: inline-flex; align-items: center; gap: 6px; margin-top: var(--s-2); font-size: var(--t-ui); font-weight: 600; }
.cp-title::before { content: ""; width: 9px; height: 10px; background: var(--prov); clip-path: var(--hex); }
.cp-size { flex: none; width: 38px; height: 42px; display: grid; place-items: center; font-weight: 700; font-size: var(--t-lead); background: var(--prov); color: var(--prov-ink, #fff); clip-path: var(--hex); }
.cp-close { flex: none; margin: 0 -8px 0 -4px; }
.cp-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-4); }
.cp-nav { position: sticky; top: 0; z-index: 2; display: flex; gap: 2px; padding: var(--s-1) var(--s-4); background: var(--lacquer); border-block: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.cp-nav button { min-height: 30px; padding: 0 var(--s-2); background: none; border: 0; border-radius: var(--r-1); font-size: var(--t-small); color: var(--pearl-dim); white-space: nowrap; }
.cp-nav button:hover { color: var(--pearl); background: var(--lacquer-2); }
.cp-section { padding: var(--s-5) var(--s-5) var(--s-4); border-bottom: 1px solid var(--line); scroll-margin-top: 40px; }
.cp-section:last-child { border-bottom: 0; padding-bottom: calc(var(--s-6) + var(--safe-b)); }
.cp-section h3 { display: flex; align-items: center; gap: 6px; margin-bottom: var(--s-3); font-size: var(--t-ui); font-weight: 600; color: var(--nacre); }
.cp-section h3 small { margin-left: auto; font-size: var(--t-meta); font-weight: 400; color: var(--pearl-dim); text-align: right; }
.cp-section h4 { margin: var(--s-4) 0 var(--s-2); font-size: var(--t-small); font-weight: 600; color: var(--pearl-dim); }
.vt { margin-left: 6px; font-size: var(--t-meta); font-weight: 400; color: var(--pearl-dim); opacity: .8; white-space: nowrap; }
/* headline figures, then grouped facts as label · value · rank rows */
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4) var(--s-3); }
.stat .v { font-size: var(--t-stat); font-weight: 600; line-height: 1.2; white-space: nowrap; }
.stat .v small { font-size: var(--t-small); font-weight: 500; margin-left: 1px; }
.stat .k { margin-top: 2px; color: var(--pearl-dim); font-size: var(--t-small); line-height: 1.35; }
.stat .k .vt { display: block; margin: 0; white-space: normal; }
.facts { margin: 0; display: grid; }
.facts > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 var(--s-3); align-items: baseline; padding: 5px 0; border-top: 1px solid var(--line); }
.facts > div:first-child { border-top: 0; padding-top: 0; }
.facts dt { font-size: var(--t-ui); }
.facts dt small { display: block; font-size: var(--t-meta); color: var(--pearl-dim); }
.facts dd { margin: 0; text-align: right; font-size: var(--t-body); font-weight: 600; white-space: nowrap; }
.facts dd small { display: block; font-size: var(--t-meta); font-weight: 400; color: var(--pearl-dim); }
.facts .flag { color: var(--warn); font-weight: 600; }
.yield-rows { display: grid; gap: var(--s-3); }
.yield-row { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 2px var(--s-2); align-items: center; }
.yield-row .name { font-size: var(--t-ui); font-weight: 600; }
.yield-row .name small { display: block; font-weight: 400; font-size: var(--t-meta); color: var(--pearl-dim); }
.yield-row .val { text-align: right; font-weight: 600; }
.yield-row .val small { display: block; font-weight: 400; color: var(--pearl-dim); font-size: var(--t-meta); }
.bar { grid-column: 2 / 4; height: 4px; background: var(--lacquer-3); border-radius: 2px; }
.bar i { display: block; height: 100%; border-radius: 2px; }
/* 시도 panel: a figure, its rank, and a bar whose middle is the reference value (national figure or the median 시도) */
.cmp-rows { display: grid; gap: var(--s-3); }
.cmp-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px var(--s-3); align-items: start; }
.cmp-row .name { font-size: var(--t-ui); font-weight: 600; }
.cmp-row .name small, .cmp-row .val small { display: block; font-weight: 400; font-size: var(--t-meta); color: var(--pearl-dim); }
.cmp-row .val { text-align: right; font-weight: 600; white-space: nowrap; }
.bar.cmp { position: relative; grid-column: 1 / 3; }
.bar.cmp i { background: var(--nacre); }
.bar.cmp b { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--pearl); border-radius: 1px; box-shadow: 0 0 0 1px var(--lacquer); }
.jobs { display: grid; gap: 5px; font-size: var(--t-small); }
.job { display: grid; grid-template-columns: minmax(0, 132px) minmax(0, 1fr) 48px; gap: var(--s-2); align-items: center; }
.job .lbl { color: var(--pearl-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job .b { height: 8px; border-radius: 0 2px 2px 0; min-width: 2px; }
.job .n { text-align: right; }
.pyramid { display: grid; gap: 2px; font-size: var(--t-meta); }
.pyr-row { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: var(--s-2); align-items: center; }
.pyr-row .b { height: 7px; background: var(--nacre); border-radius: 0 2px 2px 0; }
.pyr-row.old .b { background: var(--food); }
.pyr-row span { color: var(--pearl-dim); text-align: right; }
.pyr-key { display: flex; gap: var(--s-4); margin-top: var(--s-2); font-size: var(--t-meta); color: var(--pearl-dim); }
.pyr-key i { display: inline-block; width: 10px; height: 7px; margin-right: 5px; border-radius: 1px; background: var(--nacre); }
.pyr-key i.old { background: var(--food); }
.districts { display: flex; flex-wrap: wrap; gap: 6px var(--s-4); font-size: var(--t-ui); }
.district small { color: var(--pearl-dim); margin-left: var(--s-1); font-size: var(--t-small); }
.district.wonder { font-family: var(--font-title); font-weight: 700; color: var(--gold); }
.infra { display: grid; gap: var(--s-2); font-size: var(--t-ui); }
.row2 { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: var(--s-2); line-height: 1.5; }
.row2 > span:first-child, .row2 small { color: var(--pearl-dim); }
.civd { display: grid; gap: var(--s-2); font-size: var(--t-ui); }
.civd-row { display: grid; grid-template-columns: 14px minmax(0, 76px) minmax(0, 1fr); gap: var(--s-2); align-items: baseline; }
.civd-row small { color: var(--pearl-dim); font-size: var(--t-small); line-height: 1.45; }
.civd-ico { width: 11px; height: 12px; clip-path: var(--hex); background: var(--nacre); align-self: center; }
.civd-ico[data-k="campus"] { background: var(--science); } .civd-ico[data-k="industrial"] { background: var(--production); }
.civd-ico[data-k="commercial"] { background: var(--gold); } .civd-ico[data-k="theater"], .civd-ico[data-k="heritage"] { background: var(--culture); }
.civd-ico[data-k="farm"] { background: var(--food); } .civd-ico[data-k="health"] { background: var(--health); }
.civd-ico[data-k="harbor"] { background: #56b4e9; } .civd-ico[data-k="aerodrome"] { background: #9aa7ae; } .civd-ico[data-k="logistics"] { background: #bbcc33; }
.civd-title { margin-top: var(--s-1); padding-top: var(--s-2); border-top: 1px solid var(--line); color: var(--pearl-dim); font-size: var(--t-small); }
.civd-title b { color: var(--pearl); }
.pips { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: var(--s-3); }
.pip { width: 12px; height: 14px; clip-path: var(--hex); }
.pip.other { background: none !important; box-shadow: none; clip-path: none; border: 1.5px solid var(--other); border-radius: 50%; width: 11px; height: 11px; margin: 1.5px .5px; }
.cit-rows { display: grid; gap: 5px; font-size: var(--t-small); }
.cit-row { display: grid; grid-template-columns: 10px minmax(0, 104px) minmax(0, 84px) minmax(0, 1fr); gap: var(--s-2); align-items: center; }
.cit-row .dot { width: 9px; height: 10px; clip-path: var(--hex); }
.cit-row small { color: var(--pearl-dim); font-size: var(--t-meta); } .cit-row small.hi { color: var(--nacre); } .cit-row small.lo { color: var(--warn); }
.sparks { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s-3) var(--s-4); }
.spark .k { font-size: var(--t-small); color: var(--pearl-dim); }
.spark .k small { margin-left: var(--s-1); font-size: var(--t-meta); }
.spark svg { width: 100%; height: 34px; display: block; }
.spark path { fill: none; stroke: var(--nacre); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.spark .v { font-size: var(--t-small); color: var(--pearl-dim); }
.spark .v b { color: var(--pearl); font-weight: 600; }
.trs { display: grid; gap: 6px; font-size: var(--t-ui); }
.trs-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 112px); gap: var(--s-3); align-items: baseline; }
.trs-row .k { display: flex; align-items: center; gap: 6px; }
.trs-row b { font-weight: 600; text-align: right; }
.trs-row small { color: var(--pearl-dim); font-size: var(--t-meta); }
.trs-note { margin-top: var(--s-3); font-size: var(--t-meta); }
.top-cities { display: grid; gap: 1px; }
.top-cities button { min-height: 28px; font-size: var(--t-ui); }
.prov-link, .prov-cell { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.prov-link:hover, .prov-cell:hover { color: var(--nacre); }

/* ---- dialogs: one shell (sticky title bar with a close button, scrolling body) ---- */
dialog.sheet { width: min(960px, calc(100vw - 32px)); max-height: min(88dvh, 900px); padding: 0; overflow: hidden; background: var(--lacquer); color: var(--pearl); border: 1px solid var(--line-strong); border-radius: var(--r-2); }
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet::backdrop { background: rgb(8 12 16 / .6); }
dialog#explorer-dialog { width: min(1400px, calc(100vw - 32px)); }
dialog#help-dialog { width: min(480px, calc(100vw - 32px)); }
.dlg-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-3) var(--s-3) var(--s-6); border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-family: var(--font-title); font-size: var(--t-title); font-weight: 700; }
.dlg-head form { display: flex; }
.dlg-body { overflow: auto; padding: var(--s-5) var(--s-6) var(--s-6); overscroll-behavior: contain; }
/* 정보: attribution, disclaimer, report and corrections */
.site-foot { position: absolute; right: calc(var(--gap) + var(--safe-r)); bottom: calc(var(--gap) + 212px); z-index: 2; min-height: 24px; padding: 0 var(--s-2); background: var(--float); border: 1px solid var(--line-strong); border-radius: var(--r-1); font-size: var(--t-meta); color: var(--pearl-dim); }
.site-foot:hover { color: var(--pearl); border-color: var(--nacre); }
body.panel-open .site-foot { right: calc(var(--panel-w) + var(--gap)); }
.about p { max-width: 68ch; margin: 0 0 var(--s-3); line-height: 1.6; text-wrap: pretty; }
.about h3 { margin: var(--s-4) 0 var(--s-2); font-size: var(--t-ui); color: var(--nacre); }
.about .tag { color: var(--pearl-dim); }
.about-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: var(--s-4) 0; }
.about textarea { display: block; width: 100%; max-width: 68ch; min-height: 150px; padding: var(--s-2) var(--s-3); background: var(--ink); color: var(--pearl); border: 1px solid var(--line-strong); border-radius: var(--r-1); font: inherit; font-size: var(--t-small); line-height: 1.5; }
.about .corr { list-style: none; margin: 0; padding: 0; max-width: 68ch; }
.about .corr li { padding: var(--s-2) 0; border-top: 1px solid var(--line); }
.about .corr small { display: block; color: var(--pearl-dim); }
.dlg-foot { margin-top: var(--s-4); max-width: 68ch; font-size: var(--t-small); line-height: 1.6; }
.lg-sub { font-size: var(--t-meta); font-weight: 400; color: var(--pearl-dim); }
.lg-limits { background: none; border: 0; padding: 0; font-size: inherit; color: var(--nacre); text-decoration: underline; text-underline-offset: 3px; }
/* first visit: the search box is the way in */
.search.invite input { border-color: var(--nacre); box-shadow: 0 0 0 3px rgb(159 211 199 / .18); }
.search input { width: 250px; }
/* 동네: the 행정동 of a city, sortable */
.dong-scroll { max-height: 264px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-1); }
.dongs { width: 100%; border-collapse: collapse; font-size: var(--t-small); }
.dongs th { position: sticky; top: 0; background: var(--lacquer-2); padding: 0; text-align: right; font-weight: 600; white-space: nowrap; }
.dongs th button { width: 100%; min-height: 28px; padding: 0 6px; background: none; border: 0; font-size: var(--t-meta); font-weight: 600; text-align: inherit; color: var(--pearl-dim); }
.dongs th[aria-sort] button { color: var(--nacre); }
.dongs th:first-child, .dongs td:first-child { text-align: left; }
.dongs td { padding: 4px 6px; text-align: right; white-space: nowrap; border-top: 1px solid var(--line); }
.dongs td small { color: var(--pearl-dim); font-size: var(--t-meta); }
.dongs tbody tr { cursor: pointer; }
.dongs tbody tr:hover, .dongs tbody tr.on { background: var(--lacquer-3); }
.dlg-loading, .dock-more { color: var(--nacre); font-size: var(--t-small); }
.dock-more { margin: 0; padding: var(--s-2); }
.dlg-lede { max-width: 68ch; color: var(--pearl-dim); line-height: 1.6; text-wrap: pretty; }
dialog h3 { margin: var(--s-6) 0 var(--s-2); font-size: var(--t-ui); font-weight: 600; color: var(--nacre); }
dialog a[data-city] { color: var(--pearl); text-decoration: underline; text-decoration-color: var(--nacre); text-underline-offset: 3px; }
dialog a[data-city]:hover { color: var(--nacre); }
/* advisors: columns of prose, no boxes */
#advisors-dialog .body { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--s-6) var(--s-8); margin-top: var(--s-5); }
.advisor header { display: flex; gap: var(--s-3); align-items: center; margin-bottom: var(--s-2); padding-bottom: var(--s-2); border-bottom: 1px solid var(--line); }
.advisor header b { font-size: var(--t-lead); font-weight: 600; }
.advisor header small { display: block; color: var(--pearl-dim); font-size: var(--t-small); }
.adv-seal { width: 28px; height: 31px; display: grid; place-items: center; background: var(--adv); color: var(--adv-ink, #10181f); font-family: var(--font-title); font-weight: 700; clip-path: var(--hex); }
.advisor ul { margin: 0; padding-left: 18px; line-height: 1.65; font-size: var(--t-body); }
.advisor li { margin-bottom: var(--s-2); text-wrap: pretty; }
.advisor li::marker { color: var(--line-strong); }
/* explorer */
.ex-tools { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin-bottom: var(--s-3); }
.ex-tools .count { margin-left: auto; font-size: var(--t-small); }
.ex-split { display: grid; grid-template-columns: minmax(0, 1fr) 520px; gap: var(--s-5); align-items: start; }
.ex-scroll, .alm-scroll { overflow: auto; border: 1px solid var(--line-strong); border-radius: var(--r-1); }
.ex-scroll { max-height: 62vh; }
.alm-scroll { max-height: 46vh; }
#explorer-dialog table, .alm-table { border-collapse: collapse; width: 100%; font-size: var(--t-small); }
#explorer-dialog th, .alm-table thead th { position: sticky; top: 0; z-index: 1; background: var(--lacquer-2); text-align: left; padding: var(--s-2); white-space: nowrap; font-weight: 600; }
#explorer-dialog th { cursor: pointer; }
#explorer-dialog th button, .row-open { all: unset; cursor: pointer; }
#explorer-dialog th button:focus-visible, .row-open:focus-visible { outline: 2px solid var(--nacre); outline-offset: 2px; border-radius: 2px; }
.row-open:hover { color: var(--nacre); }
#explorer-dialog th.num { text-align: right; }
#explorer-dialog th[aria-sort="descending"]::after, #explorer-dialog th[aria-sort="ascending"]::after { content: ""; display: inline-block; margin-left: 5px; vertical-align: 2px; border: 4px solid transparent; }
#explorer-dialog th[aria-sort="descending"]::after { border-top-color: var(--nacre); border-bottom-width: 0; }
#explorer-dialog th[aria-sort="ascending"]::after { border-bottom-color: var(--nacre); border-top-width: 0; }
#explorer-dialog td { padding: 5px var(--s-2); border-top: 1px solid var(--line); white-space: nowrap; }
#explorer-dialog tbody tr { cursor: pointer; }
#explorer-dialog tbody tr:hover { background: var(--lacquer-2); }
#explorer-dialog td:nth-child(2), #explorer-dialog th:nth-child(2) { position: sticky; left: 0; background: var(--lacquer); font-weight: 600; }
#explorer-dialog th:nth-child(2) { z-index: 2; background: var(--lacquer-2); }
#explorer-dialog tbody tr:hover td:nth-child(2) { background: var(--lacquer-2); }
.ex-plot { margin: 0; }
.sc-tools { display: flex; gap: var(--s-3); flex-wrap: wrap; align-items: center; font-size: var(--t-small); margin-bottom: var(--s-2); color: var(--pearl-dim); }
.sc-tools select { margin-left: var(--s-1); color: var(--pearl); }
svg.scatter { width: 100%; height: auto; display: block; }
svg.scatter text { fill: var(--pearl-dim); font-size: 11px; font-family: var(--font-ui); }
svg.scatter text.axis { fill: var(--pearl); font-size: 12px; }
svg.scatter text.lbl { fill: var(--pearl); font-size: 11px; paint-order: stroke; stroke: var(--lacquer); stroke-width: 3px; }
svg.scatter line.grid { stroke: var(--line); stroke-width: 1; }
svg.scatter circle { stroke: var(--lacquer); stroke-width: 1; fill-opacity: .9; cursor: pointer; }
svg.scatter circle:hover { stroke: #fff; stroke-width: 2; }
.ex-plot figcaption { font-size: var(--t-small); margin-top: var(--s-1); }
/* almanac */
.alm-table th, .alm-table td { padding: 6px var(--s-2); text-align: left; vertical-align: top; border-top: 1px solid var(--line); line-height: 1.45; }
.alm-table thead th { border-top: 0; }
.alm-table tbody th { font-weight: 600; white-space: nowrap; }
.alm-table tr.alm-group th { background: var(--lacquer-2); color: var(--pearl-dim); font-weight: 600; font-size: var(--t-meta); padding: var(--s-1) var(--s-2); }
.alm-table .mono { white-space: nowrap; font-size: var(--t-meta); }
.alm-table tr.hl > * { background: rgb(159 211 199 / .16); }
.alm-notes { margin: 0; display: grid; gap: var(--s-3); font-size: var(--t-ui); line-height: 1.6; max-width: 86ch; }
.alm-notes div { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: var(--s-3); }
.alm-notes dt { font-weight: 600; }
.alm-notes dd { margin: 0; color: var(--pearl-dim); text-wrap: pretty; }
#sources-list { margin: 0; padding-left: 18px; line-height: 1.6; font-size: var(--t-ui); max-width: 86ch; }
#sources-list li { margin-bottom: var(--s-2); }
/* help */
#help-dialog dl { margin: 0; display: grid; gap: var(--s-2); }
#help-dialog dl div { display: grid; grid-template-columns: 96px 1fr; gap: var(--s-3); align-items: baseline; }
#help-dialog dt { white-space: nowrap; }
#help-dialog dd { margin: 0; line-height: 1.5; font-size: var(--t-ui); }
#help-dialog h3:first-of-type { margin-top: var(--s-4); }

/* ---- widths ---- */
@media (max-width: 1500px) { #nation-yields .yield small { display: none; } .yields { gap: var(--s-3); } #btn-link .lbl { display: none; } }
@media (max-width: 1320px) { #btn-share .lbl { display: none; } #topbar { gap: var(--s-3); } }
@media (max-width: 1180px) { #nation-yields { visibility: hidden; } }
/* a laptop with the panel open has no room for the minimap beside a scene caption: the caption takes the width */
@media (min-width: 1101px) and (max-width: 1500px) {
  body.panel-open #minimap { display: none; }
  body.panel-open #scene-strip { right: calc(var(--panel-w) + var(--gap)); }
  body.panel-open .site-foot { bottom: calc(var(--gap) + var(--strip-h, 0px)); }
}
@media (max-width: 1100px) {
  /* tablet: the named dialogs move into the "more" menu, the dock and panel slim down */
  :root { --dock-w: 188px; --panel-w: 360px; }
  #btn-advisors, #btn-explorer, #btn-sources, #btn-link, #btn-help, #btn-share-more { display: none; }
  .more-wrap { display: flex; }
  #nation-yields { display: none; }
  .search { flex: 1; min-width: 0; }
  .search input { width: 100%; }
  #search-results { left: 0; right: auto; width: min(320px, 90vw); }
  .ex-split { grid-template-columns: minmax(0, 1fr); }
  #scene-strip { right: var(--gap); }
  body.panel-open #scene-strip, body.panel-open #minimap { display: none; }
  #minimap { display: none; }
  .site-foot { bottom: calc(var(--gap) + var(--strip-h, 0px)); min-height: 32px; } /* above the scene caption when there is one */
  /* touch: 44px targets */
  :root { --tap: 44px; }
  .lb li button, .top-cities button, .lb summary, .hr-clear, .cp-nav button, .dock-group > summary, .dock-filter input, .menu button { min-height: 44px; }
  .lb summary { display: flex; align-items: center; }
  .seg button { min-height: 44px; padding: 0 12px; }
  .ss-head .icon-btn, .ss-nav .icon-btn { width: 44px; min-height: 44px; }
  /* small text links keep their look and get a 44px hit area */
  .lg-src, .lg-more, .prov-link, .prov-cell { padding: 14px 8px; margin: -14px -8px; }
  .lg-src, .prov-link, .prov-cell { display: inline-block; }
  .lg-src, .lg-more { margin-left: auto; margin-right: -8px; }
  .check, .toggle, .tb-chg { min-height: 44px; }
  /* the ranking, with its 44px rows, opens on request */
  .lg-more { display: inline-block; }
  #legend .lg-src { margin-left: var(--s-3); }
  #legend:not(.open) .lb { display: none; }
  #timebar input[type=range] { height: 44px; }
  #explorer-dialog td { padding-block: 13px; }
  #timebar .play { width: 44px; height: 44px; }
}

/* ---- phones: map first; lenses in a bottom rail that opens into a sheet, legend above it, panel as a sheet ---- */
@media (max-width: 760px) {
  :root { --gap: 8px; --rail-h: calc(56px + var(--safe-b)); --t-display: 24px; }
  html, body { font-size: 15px; }
  #topbar { gap: var(--s-2); padding-left: calc(var(--s-3) + var(--safe-l)); padding-right: calc(var(--s-1) + var(--safe-r)); }
  .brand-name { display: none; }
  .top-actions { gap: 0; }
  .tb-btn { min-width: 44px; padding: 0 var(--s-2); }
  #btn-scenes .ico { display: none; }
  #btn-share .lbl { display: none; }
  input[type="search"], select { font-size: 16px; } /* no zoom-on-focus in iOS */

  .menu { position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 9; width: auto !important; max-height: 78dvh; padding: var(--s-2) var(--s-2) calc(var(--s-2) + var(--safe-b));
    border-width: 1px 0 0; border-radius: var(--r-2) var(--r-2) 0 0; }
  .menu button { min-height: 48px; font-size: var(--t-body); }
  .lg-src { display: none; }
  .scene-item { padding-block: var(--s-2) !important; }

  /* lens dock → rail */
  #lens-dock { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: var(--rail-h); max-height: none; z-index: 3; flex-direction: row; align-items: center; gap: 6px; overflow: auto hidden;
    padding: 0 var(--s-2) var(--safe-b) 0; border-width: 1px 0 0; border-radius: 0; background: var(--lacquer); scrollbar-width: none; }
  .dock-handle { position: sticky; left: 0; z-index: 2; flex: none; display: inline-flex; align-items: center; gap: 6px; height: 100%; min-width: 76px; padding: 0 var(--s-3) 0 calc(var(--s-3) + var(--safe-l)); background: var(--lacquer); border: 0; border-right: 1px solid var(--line-strong); font-size: var(--t-ui); font-weight: 600; }
  #lens-dock:not(.open) .dock-filter, #lens-dock:not(.open) .dock-empty, #lens-dock:not(.open) .dock-group > summary, #lens-dock:not(.open) .dock-group:not(:has(.lens-btn[data-id])) { display: none; }
  #lens-dock:not(.open) .dock-group { display: flex; flex-direction: row; flex: none; gap: 6px; }
  #lens-dock:not(.open) .dock-group::details-content { display: contents; }
  #lens-dock:not(.open) .lens-btn { flex: none; width: auto; padding: 0 var(--s-3); gap: 6px; border-radius: 22px; background: var(--lacquer-2); }
  #lens-dock:not(.open) .lens-btn[aria-pressed="true"] { background: var(--lacquer-3); }
  /* … and sheet */
  #lens-dock.open { height: min(72dvh, 620px); flex-direction: column; align-items: stretch; overflow: hidden auto; padding: 0 var(--s-2) calc(var(--s-3) + var(--safe-b)); border-radius: var(--r-2) var(--r-2) 0 0; z-index: 13; }
  #lens-dock.open .dock-handle { position: sticky; top: 0; left: auto; z-index: 3; height: 48px; min-height: 48px; width: calc(100% + 2 * var(--s-2)); margin: 0 calc(-1 * var(--s-2)); justify-content: space-between; padding: 0 var(--s-4); border-right: 0; }
  #lens-dock.open .dock-filter { top: 48px; border-radius: 0; }
  #lens-dock.open .dock-group .lens-btn { min-height: 44px; font-size: var(--t-body); }

  /* legend: one compact card above the rail; "자세히" opens the histogram and ranking */
  #legend { left: var(--gap); right: var(--gap); bottom: calc(var(--rail-h) + var(--gap)); width: auto; max-height: calc(100% - var(--rail-h) - 76px); overflow-y: auto; padding: var(--s-2) var(--s-3); }
  body.panel-open #legend { display: none; }
  .lg-more { display: inline-block; }
  .lg-src { display: none; }
  #legend .title { align-items: center; }
  #legend:not(.open) :is(.note, .hist, .hist-read, .lb, .flow-key, .lg-unit, .lg-now) { display: none; }
  .lg-uchip { display: inline-block; position: relative; }
  .site-foot { display: none; }
  #lens-dock:not(.open) .dock-more { display: none; }
  .lg-uchip::after { content: ""; position: absolute; inset: -11px -6px; } /* 44px target */
  .seg button { min-height: 44px; padding: 0 14px; }
  #legend:not(.open) .bivar { gap: var(--s-3); } #legend:not(.open) .bv-grid { width: 60px; height: 60px; }
  #legend.open .lg-src { display: inline-block; margin-left: var(--s-3); }
  #legend.open .hist { height: 56px; }
  .lb-list { max-height: none; } /* the opened legend scrolls as a whole */
  #legend.open { background: var(--lacquer); } /* opened over the map: nothing shows through */

  #scene-strip { left: var(--gap); right: var(--gap); bottom: calc(var(--rail-h) + var(--legend-h, 0px) + 2 * var(--gap)); padding: var(--s-2); }
  .ss-card { flex-basis: 164px; }
  .ss-now p { grid-column: 1 / 3; }
  .ss-nav { grid-row: 1; }

  #timebar, body.panel-open #timebar { left: var(--gap); right: var(--gap); top: var(--gap); max-width: none; gap: var(--s-2); padding: var(--s-1) var(--s-3) var(--s-1) var(--s-1); }
  #timebar .year { font-size: 20px; }
  #hint, body.panel-open #hint { left: var(--gap); right: var(--gap); max-width: none; padding-left: var(--s-3); font-size: var(--t-small); }
  .tb-chg { min-height: 44px; }
  #tooltip { max-width: min(224px, calc(100vw - 16px)); }

  /* city panel → bottom sheet: grip to drag or tap, close in the header */
  #city-panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: var(--sheet-h, 52%); max-height: calc(100% - 8px); z-index: 10; border-left: 0; border-top: 1px solid var(--line-strong); border-radius: var(--r-2) var(--r-2) 0 0; padding-right: 0; transition: height .28s var(--ease); }
  #city-panel.dragging { transition: none; }
  /* 44px to press or drag, of which the lower 20px overlaps the header's empty top */
  .sheet-grip { position: sticky; top: 0; z-index: 4; display: block; width: 100%; height: 44px; margin-bottom: -20px; padding: 0; background: linear-gradient(var(--lacquer) 24px, transparent 24px); border: 0; cursor: grab; touch-action: none; }
  .sheet-grip::before { content: ""; display: block; width: 40px; height: 4px; margin: 0 auto 30px; border-radius: 2px; background: var(--line-strong); }
  .cp-head > :is(.cp-size, .cp-close, .cp-logo) { position: relative; z-index: 5; }
  .cp-banner { padding: 0 var(--s-4) var(--s-3); }
  .cp-nav { top: 24px; padding-inline: var(--s-3); }
  .cp-section { padding: var(--s-4) var(--s-4) var(--s-4); scroll-margin-top: 64px; }
  .cp-close { margin: -4px -8px 0 -4px; }
  .cp-size { width: 34px; height: 38px; }
  .job { grid-template-columns: minmax(0, 116px) minmax(0, 1fr) 48px; }

  /* dialogs fill the screen */
  dialog.sheet, dialog#explorer-dialog, dialog#help-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .dlg-head { padding: calc(var(--s-1) + var(--safe-t)) var(--s-1) var(--s-1) var(--s-4); }
  .dlg-body { padding: var(--s-4) var(--s-4) calc(var(--s-6) + var(--safe-b)); }
  .ex-scroll { max-height: 56dvh; }
  .ex-tools input[type="search"] { flex: 1; min-width: 0; }
  .alm-notes div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  #help-dialog dl div { grid-template-columns: 84px 1fr; }
  #advisors-dialog .body { grid-template-columns: minmax(0, 1fr); }
  #toast { bottom: calc(var(--rail-h) + 16px); max-width: calc(100vw - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 380px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
@media (forced-colors: active) { .lens-btn[aria-pressed="true"] { outline: 2px solid; } }
