:root {
  --bg: #ffffff;
  --ink: #222222;
  --muted: #666666;
  --line: #d4d4d4;
  --soft: #f3f3f3;
  --dot: #3b3b3b;
  --missing: #9a9a9a;
  --pin: #d9480f;      /* pinned cities */
  --selected: #1971c2; /* the selected city */
  --warn: #8a4b00;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
a { color: var(--selected); }
h1 { font-size: 1.3rem; margin: 0 0 0.3rem; }
h2 { font-size: 0.95rem; margin: 0.6rem 0 0.3rem; }
h2:first-child { margin-top: 0; }
h3 { font-size: 0.85rem; margin: 0.9rem 0 0.25rem; text-transform: capitalize; color: var(--muted); }
button, select, input { font: inherit; }
button { border: 1px solid var(--line); background: var(--soft); border-radius: 4px; padding: 0.3rem 0.7rem; cursor: pointer; }
button.small { font-size: 0.8rem; padding: 0.1rem 0.45rem; }
button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button.linkish { border: 0; background: none; padding: 0; color: var(--selected); text-decoration: underline; cursor: pointer; text-align: left; font-size: inherit; }
select { max-width: 100%; padding: 0.3rem; border-radius: 4px; border: 1px solid var(--line); background: var(--bg); }
.note { color: var(--muted); font-size: 0.85rem; }
.warn { color: var(--warn); font-size: 0.85rem; }
.error { color: #b00020; font-weight: 600; }

.intro { padding: 0.8rem 1rem 0; max-width: 72rem; }
.intro p { margin: 0; font-size: 0.92rem; }
#help { margin-top: 0.4rem; max-width: 60rem; }
#help ul { margin: 0; padding-left: 1.2rem; font-size: 0.88rem; color: var(--muted); }
#help li { margin: 0.15rem 0; }
#help[hidden] { display: none; }

main { padding: 0.6rem 1rem 2rem; }

/* Toolbar: the two axis pickers, search, and the filters button. */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; align-items: center; padding: 0.4rem 0; }
.pick { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.pick .arrow { font-weight: 700; white-space: nowrap; }
.pick select { width: 17rem; max-width: 60vw; min-width: 0; }
.pick button.tune { font-size: 0.8rem; padding: 0.2rem 0.5rem; white-space: nowrap; }
.tool { flex: 1 1 10rem; min-width: 8rem; }
.tool input[type="search"] { width: 100%; max-width: 16rem; padding: 0.3rem 0.5rem; border: 1px solid var(--line); border-radius: 4px; }
#filters-toggle { white-space: nowrap; }
#search-note { margin: 0 0 0.3rem; }
#search-note[hidden] { display: none; }

/* Drop-down sections under the toolbar (axis settings, filters). */
.drop { border: 1px solid var(--line); border-radius: 6px; background: var(--soft); padding: 0.7rem 0.9rem; margin: 0.2rem 0 0.6rem; }
.drop[hidden] { display: none; }
.drop-head { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; margin-bottom: 0.3rem; }
.drop-head h2 { margin: 0; flex: 1; }
.ingredients { list-style: none; margin: 0.4rem 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.ingredients li { border: 1px solid var(--line); border-radius: 4px; background: var(--bg); padding: 0.4rem 0.5rem; flex: 1 1 15rem; max-width: 22rem; }
.ingredients select { width: 100%; }
.ing-row { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.3rem; }
.ing-row input[type="range"] { flex: 1; min-width: 0; }
.ing-row output { width: 2rem; text-align: right; font-variant-numeric: tabular-nums; }
.ing-row label.check { margin: 0; }
.drop-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.3rem; }

.filter-cols { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem 2rem; }
.filter-cols .note { margin: 0 0 0.3rem; }
label.check { display: flex; gap: 0.4rem; align-items: baseline; flex-wrap: wrap; margin: 0.3rem 0; font-size: 0.9rem; }
label.check input[type="checkbox"] { margin: 0; position: relative; top: 2px; }
#f-minpop { width: 7rem; padding: 0.1rem 0.3rem; }
#country-list { max-height: 14rem; overflow-y: auto; margin-top: 0.3rem; columns: 11rem; }
#country-list label { break-inside: avoid; margin: 0.15rem 0; }
#reset { margin-top: 0.6rem; }

/* Plot and panel side by side. */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.2rem; align-items: start; }
#plot-wrap { position: relative; width: 100%; }
#plot { display: block; touch-action: manipulation; }
.axis text { font-size: 11px; fill: var(--muted); }
.axis path, .axis line { stroke: var(--line); }
.axis-title { font-size: 12px; font-weight: 600; fill: var(--ink); }
.axis-sub { font-size: 11px; fill: var(--muted); }
.strip { fill: var(--soft); }
.strip-label { font-size: 10px; fill: var(--missing); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.overlay { fill: transparent; cursor: crosshair; }
.good-area { fill: var(--selected); fill-opacity: 0.07; pointer-events: none; }
.good-line { stroke: var(--selected); stroke-opacity: 0.55; stroke-dasharray: 4 3; pointer-events: none; }
.good-text { font-size: 10px; fill: var(--selected); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; pointer-events: none; }
.good-text.corner { font-weight: 600; }
.line-row { display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; align-items: center; margin: 0.4rem 0; font-size: 0.9rem; }
.line-row input[type="number"] { width: 6rem; padding: 0.1rem 0.3rem; }

.dot { stroke: var(--dot); stroke-width: 1.2; }
.dot.filled { fill: var(--dot); fill-opacity: 0.75; }
.dot.hollow { fill: var(--bg); fill-opacity: 0.6; }
.dot.missing { stroke: var(--missing); stroke-width: 1.8; }
.dot.missing.filled { fill: var(--missing); }
.dot.missing.hollow { fill: var(--bg); fill-opacity: 1; }
.dot.pinned { stroke: var(--pin); stroke-width: 2; }
.dot.pinned.filled { fill: var(--pin); fill-opacity: 1; }
.dot.pinned.hollow { fill-opacity: 1; }
.dot.selected { stroke: var(--selected); stroke-width: 3; }
.dot.selected.filled { fill: var(--selected); fill-opacity: 1; }
.label { font-size: 10.5px; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; pointer-events: none; }
.label.pinned { font-size: 12px; font-weight: 600; fill: var(--pin); }
.label.selected { font-size: 12px; font-weight: 600; fill: var(--selected); }

#tooltip {
  position: absolute; z-index: 5; max-width: min(320px, 90vw);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); padding: 0.5rem 0.6rem; font-size: 0.82rem; pointer-events: none;
}
#tooltip[hidden] { display: none; }
#tooltip ul { margin: 0.05rem 0 0.15rem; padding-left: 1rem; color: var(--muted); }
#tooltip li { margin: 0; }
.tt-head { display: flex; gap: 0.3rem; align-items: baseline; flex-wrap: wrap; }
.tt-name { font-weight: 700; }
.tt-axis { margin-top: 0.25rem; }
.tt-close { margin-left: auto; }
.tt-actions { display: flex; gap: 0.5rem; margin-top: 0.4rem; }
#tooltip.docked {
  position: static; max-width: none; margin: 0.4rem 0 0; pointer-events: auto; font-size: 0.85rem;
  box-shadow: none; border-color: var(--selected);
}

.legend { font-size: 0.8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; align-items: center; margin: 0.4rem 0; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--dot); margin-right: -0.4rem; vertical-align: middle; }
.key.filled { background: var(--dot); }
.key.hollow { background: var(--bg); }
.key.none { background: var(--bg); border-color: var(--missing); border-width: 2px; }
.key.pinned { background: var(--pin); border-color: var(--pin); }
.key.ref { background: var(--pin); border-color: var(--pin); border-radius: 0; transform: rotate(45deg) scale(0.85); }
.key.selected { background: var(--selected); border-color: var(--selected); }
.key.good { background: rgba(25, 113, 194, 0.12); border: 1px dashed var(--selected); border-radius: 2px; }

#captions p { margin: 0.2rem 0; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
#captions strong { color: var(--ink); }
#status p { margin: 0.3rem 0; font-size: 0.9rem; }
#missing-list h3, #outside-list h3 { text-transform: none; color: var(--ink); }
#outside-list details { margin: 0.2rem 0; }
#outside-list summary, #panel details.also summary { font-size: 0.88rem; color: var(--ink); }
ul.outside { list-style: none; margin: 0.2rem 0 0.4rem; padding: 0; columns: 14rem; max-height: 18rem; overflow-y: auto; font-size: 0.85rem; }
#panel ul.outside { columns: 1; max-height: 12rem; }
ul.outside li { break-inside: avoid; margin: 0.1rem 0; }
#missing-list ul { font-size: 0.85rem; padding-left: 1.1rem; max-height: 22rem; overflow-y: auto; }
#missing-list li { margin: 0.15rem 0; }

/* Detail panel: pinned table, then the selected city. */
#panel { font-size: 0.88rem; border-left: 1px solid var(--line); padding-left: 1rem; min-width: 0; }
table.pins { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 0.2rem 0 0.4rem; }
table.pins th { text-align: left; font-weight: 600; font-size: 0.78rem; color: var(--muted); padding: 0.15rem 0.3rem 0.15rem 0; border-bottom: 1px solid var(--line); }
table.pins th.num, table.pins td.num { text-align: right; }
table.pins td { padding: 0.2rem 0.3rem 0.2rem 0; border-bottom: 1px solid var(--soft); vertical-align: top; }
table.pins td.act { text-align: right; white-space: nowrap; }
table.pins tr.sel td { background: #eaf2fb; }
.panel-head { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 0.8rem; }
.panel-head h2 { font-size: 1.15rem; margin: 0; flex: 1; }
button.pin.on { background: var(--pin); color: #fff; border-color: var(--pin); }
.where { margin: 0.4rem 0 0.2rem; }
.where .score { font-weight: 600; }
.where ul { margin: 0.1rem 0 0.4rem; padding-left: 1.1rem; color: var(--muted); font-size: 0.82rem; }
.ind { display: flex; gap: 0.5rem; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--soft); padding: 0.25rem 0; }
.ind details { flex: 1; min-width: 0; }
.ind summary { cursor: pointer; font-size: inherit; color: var(--ink); list-style: none; }
.ind summary::-webkit-details-marker { display: none; }
.ind summary::after { content: " ⓘ"; color: var(--muted); font-size: 0.75rem; }
.ind details p { margin: 0.2rem 0; font-size: 0.8rem; color: var(--muted); }
.ind-value { text-align: right; font-variant-numeric: tabular-nums; max-width: 60%; }
.ind.blank .ind-value { color: var(--muted); font-style: italic; white-space: normal; max-width: 55%; }
.level { display: inline-block; margin-left: 0.35rem; font-size: 0.72rem; border: 1px solid var(--line); border-radius: 3px; padding: 0 0.3rem; color: var(--muted); }
.level.region, .level.country { border-style: dashed; }
details summary { cursor: pointer; font-size: 0.78rem; color: var(--muted); }
details p { margin: 0.2rem 0; }

@media (max-width: 1000px) {
  .stage { display: block; }
  #panel { border-left: 0; padding-left: 0; margin-top: 1rem; scroll-margin-top: 0.5rem; }
  .filter-cols { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .intro { padding: 0.6rem 0.75rem 0; }
  main { padding: 0.4rem 0.75rem 2rem; }
  .pick { width: 100%; }
  .pick select { flex: 1; width: auto; max-width: none; min-width: 0; }
  .tool input[type="search"] { max-width: none; }
}

/* iOS Safari zooms the page when a focused field is under 16px; keep fields at 16px on touch. */
@media (pointer: coarse) {
  input, select, button.tune { font-size: 16px; }
}
