/* What the world grows (world-food.html): a 3D map of the world's food (js/page-world-3d.js), or
   bubbles on a flat map without WebGL; one control panel on the map (foods, a food's kinds, regions),
   a hint on how to move, a panel for the country or food you open, and the table.
   Colours: eight soft mid-tones, validated for neighbouring layers (lightness, chroma, colour-blind
   and normal-vision separation). Kinds inside a food are shades of its colour, darkest first. */

.p-world {
  --wf-meat: #e66f5a; --wf-milk: #8f82e3; --wf-veg: #78bb5a; --wf-fruit: #e68bbb;
  --wf-grain: #e0a826; --wf-oil: #4cb9a0; --wf-sugar: #b07243; --wf-fish: #5898df;
  --wf-land: #ebe8e1; --wf-land-faint: #f0eee8; --wf-ink: #3b2f2a; --wf-edge: var(--paper);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .p-world { --wf-land: #22221f; --wf-land-faint: #191917; --wf-ink: #0e0e0d; }
}
:root[data-theme="dark"] .p-world { --wf-land: #22221f; --wf-land-faint: #191917; --wf-ink: #0e0e0d; }

/* ---------- Hero ---------- */
.p-world .wf-hero { padding-block: var(--space-16) var(--space-8); }
.p-world .wf-hero .mb-eyebrow { margin-bottom: var(--space-6); }
.p-world .wf-hero__grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-12); align-items: end; }
.p-world .wf-hero__grid .lead { padding-bottom: 10px; }

/* ---------- Chips ---------- */
.p-world .wf-sec { padding-block: var(--space-4) var(--space-24); }
.p-world .wf-sw { width: 14px; height: 14px; border-radius: 4px; flex: none; display: inline-block; }

/* the option switch (for review, goes when one is chosen) */

/* ---------- The map: the full width of the screen ---------- */
.p-world .wf-fig { margin: 0; }
.p-world .wf-map { position: relative; width: 100%; background: var(--paper); }
.p-world .wf-map > svg { display: block; width: 100%; height: auto; max-height: calc(100svh - 120px); touch-action: manipulation; }
.p-world .wf-c { cursor: pointer; }

/* the three looks */
.p-world .wf-land use { fill: var(--wf-land); stroke: var(--wf-edge); stroke-width: calc(1 * var(--u, 1)); }

.p-world .wf-bub { transition: transform .7s cubic-bezier(.5,0,.2,1); }
.p-world .wf-bub__ring { fill: var(--paper); }
.p-world .wf-bub__hole { fill: var(--paper); }
.p-world .wf-arc { stroke: var(--paper); stroke-width: 1px; vector-effect: non-scaling-stroke; transition: opacity .25s ease; }
.p-world .wf-bub__code { font: 600 .36px/1 var(--font-mono); fill: var(--ink-2); letter-spacing: .02em; opacity: 0; pointer-events: none; }
.p-world .wf-bub.is-big .wf-bub__code { opacity: 1; }
.p-world .wf-bub.is-hl .wf-bub__ring { fill: var(--ink); }
.p-world .wf-bub.is-sel .wf-bub__ring { fill: var(--ink); }


/* hovering a food chip fades the other foods */
.p-world svg[data-hg] [data-g] { opacity: .14; }
.p-world svg[data-hg="0"] [data-g="0"], .p-world svg[data-hg="1"] [data-g="1"], .p-world svg[data-hg="2"] [data-g="2"], .p-world svg[data-hg="3"] [data-g="3"],
.p-world svg[data-hg="4"] [data-g="4"], .p-world svg[data-hg="5"] [data-g="5"], .p-world svg[data-hg="6"] [data-g="6"], .p-world svg[data-hg="7"] [data-g="7"] { opacity: 1; }


.p-world .wf-tip {
  position: absolute; z-index: 2; pointer-events: none; min-width: 200px; max-width: 260px; padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-float); font-size: 13px; line-height: 1.4; color: var(--ink-2);
}
.p-world .wf-tip b { display: block; color: var(--ink); font-weight: 600; font-size: 15px; }
.p-world .wf-tip .wf-tip__t { font: 500 12px/1.4 var(--font-mono); color: var(--muted); margin-bottom: 8px; }
.p-world .wf-tip .wf-tip__go { font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.p-world .wf-tip ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.p-world .wf-tip li { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; }
.p-world .wf-tip li.is-on span:nth-child(2) { color: var(--ink); font-weight: 600; }
.p-world .wf-tip li span:last-child { font: 500 12px/1 var(--font-mono); color: var(--ink); font-variant-numeric: tabular-nums; }

.p-world .wf-views { position: absolute; left: max(var(--gutter), calc((100vw - 1320px) / 2 + var(--gutter))); bottom: 16px; display: flex; gap: 2px; padding: 3px; border-radius: var(--radius-pill); background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--line); backdrop-filter: blur(6px); }
.p-world .wf-views button { all: unset; cursor: pointer; padding: 6px 12px; border-radius: var(--radius-pill); font: 500 13px/1.2 var(--font-sans); color: var(--muted); }
.p-world .wf-views button:hover { color: var(--ink); }
.p-world .wf-views button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.p-world .wf-views button:focus-visible { outline: 2px solid var(--carmine); outline-offset: 2px; }

.p-world .wf-cap { display: block; margin-top: var(--space-3); font-size: 13px; line-height: 1.5; color: var(--muted); }

/* ---------- The panel: one country, one group, or one kind ---------- */
.p-world .wf-panel { margin-top: var(--space-12); scroll-margin-top: 90px; }
.p-world .wf-p__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2) var(--space-6); margin-bottom: var(--space-4); }
.p-world .wf-p__k { font: 500 12px/1.2 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.p-world .wf-p__h { margin: 0; font: 600 clamp(28px, 3.4vw, 44px)/1.05 var(--font-sans); letter-spacing: -0.03em; color: var(--ink); }
.p-world .wf-p__t { font: 500 15px/1.3 var(--font-mono); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.p-world .wf-p__t small { color: var(--muted); font-size: 12px; }

.p-world .wf-mix { display: flex; gap: 2px; height: 40px; margin-bottom: var(--space-3); }
.p-world .wf-mix span { min-width: 0; transition: flex-grow .45s ease; }
.p-world .wf-mix span:first-child { border-radius: 4px 0 0 4px; }
.p-world .wf-mix span:last-child { border-radius: 0 4px 4px 0; }
.p-world .wf-legend { list-style: none; margin: 0 0 var(--space-6); padding: 0; display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 13.5px; color: var(--ink-2); }
.p-world .wf-legend li { display: inline-flex; align-items: center; gap: 8px; }
.p-world .wf-legend b { font: 500 12.5px/1 var(--font-mono); color: var(--ink); }

.p-world .wf-groups { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); margin-top: var(--space-6); }
.p-world .wf-gc { padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.p-world .wf-gc.is-focus { border-color: var(--ink); }
.p-world .wf-gc__h { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; color: var(--ink); }
.p-world .wf-gc__h span:last-child { font: 500 13px/1 var(--font-mono); font-variant-numeric: tabular-nums; }
.p-world .wf-gc__v { margin: 2px 0 var(--space-3) 22px; font: 500 12px/1.3 var(--font-mono); color: var(--muted); }
.p-world .wf-gc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.p-world .wf-gc li { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; font-size: 12.5px; color: var(--ink-2); }
.p-world .wf-gc li span:nth-child(2) { font: 500 12px/1.3 var(--font-mono); color: var(--ink); font-variant-numeric: tabular-nums; }
.p-world .wf-gc li i { grid-column: 1 / -1; height: 8px; border-radius: 3px; background: var(--surface-sunk); overflow: hidden; display: block; }
.p-world .wf-gc li i b { display: block; height: 100%; border-radius: 3px; }
.p-world .wf-gc.is-zero { opacity: .45; }

.p-world .wf-rank { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-12); margin-top: var(--space-6); }
.p-world .wf-rank h3 { margin: 0 0 var(--space-4); font-size: 15px; font-weight: 600; color: var(--ink); }
.p-world .wf-rank h3 small { font: 500 12px/1 var(--font-mono); color: var(--muted); margin-left: 6px; }
.p-world .wf-rank ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.p-world .wf-rank li { display: grid; grid-template-columns: 22px 150px 1fr 72px; gap: 10px; align-items: center; font-size: 13.5px; color: var(--ink-2); }
.p-world .wf-rank li button { all: unset; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.p-world .wf-rank li button:hover { text-decoration: underline; text-underline-offset: 3px; }
.p-world .wf-rank li button:focus-visible { outline: 2px solid var(--carmine); outline-offset: 2px; }
.p-world .wf-rank li > span:first-child { font: 500 11px/1 var(--font-mono); color: var(--muted); }
.p-world .wf-rank .bar { height: 14px; border-radius: 0 4px 4px 0; min-width: 2px; }
.p-world .wf-rank li > span:last-child { font: 500 12.5px/1 var(--font-mono); color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.p-world .wf-p__note { margin-top: var(--space-6); font-size: 13px; color: var(--muted); }
.p-world .wf-back { all: unset; cursor: pointer; font-size: 14px; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.p-world .wf-back:hover { text-decoration-color: var(--ink); }
.p-world .wf-back:focus-visible { outline: 2px solid var(--carmine); outline-offset: 2px; }

/* ---------- The table ---------- */
.p-world .wf-table { margin-top: var(--space-12); border-top: 1px solid var(--line); padding-top: var(--space-4); }
.p-world .wf-table summary { cursor: pointer; font-weight: 600; color: var(--ink); font-size: 15px; }
.p-world .wf-table__scroll { overflow: auto; margin-top: var(--space-4); max-height: 520px; }
.p-world .wf-table table { border-collapse: collapse; width: 100%; font-size: 13px; }
.p-world .wf-table th, .p-world .wf-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.p-world .wf-table th { position: sticky; top: 0; background: var(--paper); font-weight: 600; color: var(--ink); font-size: 12px; }
.p-world .wf-table th:first-child, .p-world .wf-table td:first-child { text-align: left; }
.p-world .wf-table td { font-family: var(--font-mono); color: var(--ink-2); }
.p-world .wf-table td:first-child { font-family: var(--font-sans); color: var(--ink); }

/* ---------- How we count ---------- */
.p-world .wf-how { padding-block: var(--space-16); border-top: 1px solid var(--line); }
.p-world .wf-how__in { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: var(--space-12); }
.p-world .wf-how p { max-width: 68ch; margin: 0 0 var(--space-4); line-height: 1.6; }

@media (max-width: 1080px) {
  .p-world .wf-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .p-world .wf-rank { grid-template-columns: 1fr; gap: var(--space-8); }
}
@media (max-width: 760px) {
  .p-world .wf-hero__grid, .p-world .wf-how__in { grid-template-columns: 1fr; gap: var(--space-6); }
  .p-world .wf-map { overflow-x: auto; }
  .p-world .wf-map > svg { min-width: 760px; max-height: none; }
  .p-world .wf-views { position: static; margin: 8px var(--gutter); width: max-content; }
  .p-world .wf-groups { grid-template-columns: 1fr; }
  .p-world .wf-rank li { grid-template-columns: 20px 110px 1fr 60px; }
}
@media (prefers-reduced-motion: reduce) {
}

/* ---------- 3D towers (js/page-world-3d.js) ---------- */
.p-world .wf-map.is-3d { background: var(--paper); }
.p-world .wf-3d { position: relative; width: 100%; height: min(78vh, 60vw); min-height: 420px; }
.p-world .wf-3d[hidden] { display: none; }
.p-world .wf-map:not(.is-3d) .wf-3d { display: none; }
.p-world .wf-3d canvas { display: block; width: 100% !important; height: 100% !important; touch-action: none; cursor: grab; outline: none; }
.p-world .wf-3d canvas:active { cursor: grabbing; }
.p-world .wf-3d__labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.p-world .wf-3d__labels span { position: absolute; left: 0; top: 0; padding: 2px 5px; border-radius: 4px; background: color-mix(in srgb, var(--surface) 85%, transparent); font: 600 10.5px/1.2 var(--font-mono); color: var(--ink); letter-spacing: .02em; white-space: nowrap; transition: opacity .2s; will-change: transform; }
@media (max-width: 760px) {
  .p-world .wf-map.is-3d { overflow: visible; }
  .p-world .wf-3d { height: 70vh; min-height: 380px; }
}

/* ---------- One control panel on the map: foods (kinds open under the chosen one), regions, hint ---------- */
.p-world .wf-ctrl {
  position: absolute; z-index: 3; top: 16px; left: max(var(--gutter), calc((100vw - 1320px) / 2 + var(--gutter)));
  width: 252px; max-height: calc(100% - 32px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
  padding: 14px 10px 12px; border-radius: var(--radius-lg); border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-window);
}
.p-world .wf-ctrl__k { margin: 0 6px 6px; font: 500 11px/1 var(--font-mono); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.p-world .wf-foods { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 1px; }
.p-world .wf-food, .p-world .wf-kind {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 10px; width: 100%; cursor: pointer;
  padding: 7px 8px; border-radius: var(--radius-sm); font: 500 14px/1.25 var(--font-sans); color: var(--ink-2);
}
.p-world .wf-food:hover, .p-world .wf-kind:hover { background: var(--surface-sunk); color: var(--ink); }
.p-world .wf-food[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.p-world .wf-food[aria-pressed="true"] .wf-sw { box-shadow: 0 0 0 1.5px var(--paper); }
.p-world .wf-food:focus-visible, .p-world .wf-kind:focus-visible { outline: 2px solid var(--carmine); outline-offset: -2px; }
.p-world .wf-sw--all { background: conic-gradient(var(--wf-meat) 0 12.5%, var(--wf-milk) 0 25%, var(--wf-veg) 0 37.5%, var(--wf-fruit) 0 50%, var(--wf-grain) 0 62.5%, var(--wf-oil) 0 75%, var(--wf-sugar) 0 87.5%, var(--wf-fish) 0); border-radius: 50%; }
.p-world .wf-kinds { display: grid; gap: 1px; margin: 3px 0 6px 17px; padding-left: 9px; border-left: 1px solid var(--line-strong); }
.p-world .wf-kinds[hidden] { display: none; }
.p-world .wf-kind { padding: 5px 8px; font-size: 13px; gap: 8px; }
.p-world .wf-kind .wf-sw { width: 12px; height: 12px; }
.p-world .wf-kind[aria-pressed="true"] { background: var(--surface-sunk); color: var(--ink); font-weight: 600; }
.p-world .wf-ctrl .wf-views { position: static; display: flex; flex-wrap: wrap; gap: 2px; margin: 0 2px 12px; padding: 0; border: 0; background: none; backdrop-filter: none; }
.p-world .wf-ctrl .wf-views button { padding: 6px 10px; font-size: 13px; }

@media (max-width: 760px) {
  .p-world .wf-ctrl { position: static; width: auto; max-height: none; margin: 0 var(--gutter) 10px; padding: 10px; box-shadow: none; background: var(--surface); backdrop-filter: none; }
  .p-world .wf-foods { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
  .p-world .wf-foods li { display: contents; }
  .p-world .wf-food { width: auto; padding: 6px 10px; font-size: 13px; border: 1px solid var(--line); border-radius: var(--radius-pill); gap: 7px; }
  .p-world .wf-food .wf-sw { width: 11px; height: 11px; }
  .p-world .wf-kinds { order: 99; flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 0; padding: 8px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .p-world .wf-kind { width: auto; border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 5px 10px; }
  .p-world .wf-map { overflow: visible; display: flex; flex-direction: column; }
  .p-world .wf-map .wf-ctrl { order: -1; }
  .p-world .wf-3d { height: 100vw; min-height: 340px; max-height: 70vh; }
}

/* how to use the map: a pill at the bottom, always there */
.p-world .wf-hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 2; display: flex; gap: 4px 18px; flex-wrap: wrap; justify-content: center;
  width: max-content; max-width: calc(100% - 2 * var(--gutter)); padding: 9px 16px; border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line); box-shadow: var(--shadow-float); font-size: 13px; color: var(--ink-2); pointer-events: none;
  animation: wf-hint-in .5s .8s both cubic-bezier(.2,.7,.2,1); transition: opacity .4s ease, transform .4s ease;
}
.p-world .wf-hint span { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.p-world .wf-hint svg { width: 16px; height: 16px; fill: none; stroke: var(--ink); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
@keyframes wf-hint-in { from { opacity: 0; transform: translate(-50%, 10px); } }
@media (max-width: 760px) {
  .p-world .wf-hint { left: var(--gutter); right: var(--gutter); bottom: 10px; width: auto; max-width: none; transform: none; justify-content: flex-start; gap: 6px 14px; padding: 8px 12px; border-radius: var(--radius-md); font-size: 12.5px; animation-name: wf-hint-in-phone; }
  @keyframes wf-hint-in-phone { from { opacity: 0; transform: translateY(10px); } }
}
@media (prefers-reduced-motion: reduce) { .p-world .wf-hint { animation: none; transition: none; } }
.p-world .wf-tip .wf-tip__est { margin-top: 6px; font-size: 11.5px; color: var(--muted); }

/* the title on top, the introduction right under it */
.p-world .wf-hero { padding-block: var(--space-12) var(--space-8); }
.p-world .wf-intro { max-width: 62ch; margin: var(--space-6) 0 0; }
.p-world .wf-rank h3 { margin-bottom: 4px; }
.p-world .wf-rank__sub { margin: 0 0 var(--space-4); font-size: 13px; line-height: 1.45; color: var(--muted); max-width: 52ch; }
