:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #15181c;
  --muted: #5f6772;
  --border: #e0e4e9;
  /* hull red, port-count's colour: --accent fills and underlines, --link the text links */
  --accent: #b5432a;
  --accent-text: #ffffff;
  --link: #9c3620;
  --track: #e8ebef;
  --radius: 12px;
  --map-0: #e9ebee; --map-1: #f7e3dc; --map-2: #ebbfae; --map-3: #d98d72; --map-4: #c25e40; --map-5: #8f3520;
  --map-sea: #eef3f8;
  /* port bubbles */
  --pt: #b5432a; --pt-sel: #ffd3c4;
  --bar: #c25e40; --bar-2: #ebbfae; --bar-3: #d98d72; --up: #1f7a4d; --down: #b5432a;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1215; --surface: #181c21; --text: #e7eaee; --muted: #9aa2ad; --border: #2a3038;
  --accent: #f0805f; --accent-text: #1a0904; --link: #f6977a; --track: #262c33;
  --map-0: #2c3038; --map-1: #3d2620; --map-2: #66362a; --map-3: #94493a; --map-4: #c9654b; --map-5: #f2a389;
  --map-sea: #14171c;
  --pt: #f0805f; --pt-sel: #5a2416;
  --bar: #e0735a; --bar-2: #66362a; --bar-3: #94493a; --up: #6fd99b; --down: #f6977a;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1215; --surface: #181c21; --text: #e7eaee; --muted: #9aa2ad; --border: #2a3038;
    --accent: #f0805f; --accent-text: #1a0904; --link: #f6977a; --track: #262c33;
    --map-0: #2c3038; --map-1: #3d2620; --map-2: #66362a; --map-3: #94493a; --map-4: #c9654b; --map-5: #f2a389;
    --map-sea: #14171c;
    --pt: #f0805f; --pt-sel: #5a2416;
    --bar: #e0735a; --bar-2: #66362a; --bar-3: #94493a; --up: #6fd99b; --down: #f6977a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--link); }
h1, h2, h3, p { margin: 0; }

main, .foot { max-width: 1200px; margin: 0 auto; padding: 0 16px; } /* 1200 as the sister projects, so the maps line up */
main { padding-top: 16px; min-height: 100vh; display: flex; flex-direction: column; gap: 16px; } /* always scrolls, as the sister pages do */
.muted { color: var(--muted); font-weight: 400; }

/* mathemantique bar above the top bar, as on the sister apps */
.site-bar { background: #007FFF; text-align: center; padding: .4rem 16px; padding-left: calc(16px + 100vw - 100%); } /* the scrollbar's width added on the left: the name sits at the window's centre */
.site-bar a { color: #fff; text-decoration: none; font-family: Georgia, 'Times New Roman', serif; font-size: 1.15rem; font-weight: bold; letter-spacing: .02em; }
.site-bar a:hover { text-decoration: underline; }

.topbar { display: flex; align-items: center; gap: .5rem 1rem; padding: .7rem 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .01em; flex: 1; }
.brand .muted { font-weight: 400; margin-left: .4rem; }
.theme-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 2px; background: var(--bg); flex-shrink: 0; }
.theme-toggle button { font: inherit; font-size: .82rem; border: 0; background: transparent; color: var(--muted); padding: .25rem .65rem; border-radius: 999px; cursor: pointer; }
.theme-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
@media (max-width: 560px) { .brand .muted { display: block; margin-left: 0; } }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.panel h2 { font-size: 1.05rem; margin-bottom: .5rem; }
.panel h3, .side-head { font-size: .9rem; margin-bottom: .3rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 1.05rem; margin: 0 0 .6rem; }
.crumbs .sep { color: var(--muted); }
.crumbs .here { font-weight: 700; }
button.link { border: 0; background: none; padding: 0; font: inherit; color: var(--link); cursor: pointer; text-align: left; }
button.link:hover { text-decoration: underline; }

/* map with its filters on the left: the same layout as the sister projects */
.map-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.map-filters { display: flex; flex-direction: column; gap: .7rem; min-width: 0; font-size: .9rem; }
.map-filters label { display: flex; flex-direction: column; gap: .2rem; color: var(--muted); }
.map-filters select { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .3rem .4rem; }
.map-main { min-width: 0; }
@media (max-width: 820px) { .map-layout { grid-template-columns: minmax(0, 1fr); } }
.summary { color: var(--muted); }
.note { color: var(--muted); font-size: .82rem; margin-top: .4rem; }

.periods { display: flex; flex-wrap: wrap; gap: 6px; }
.periods button { font: inherit; font-size: .85rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 4px 12px; cursor: pointer; }
.periods button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.totals { width: 100%; border-collapse: collapse; font-size: .85rem; }
.totals td { padding: 3px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.totals td.n { text-align: right; font-variant-numeric: tabular-nums; padding-left: 8px; white-space: nowrap; }
.totals tr.on td { font-weight: 700; }
.totals tr.sub td:first-child { padding-left: .8rem; color: var(--muted); }

.ranks { margin: 0; padding-left: 1.5rem; font-size: .85rem; }
.ranks li { padding: 1px 0; }
.ranks .n { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: .3rem; white-space: nowrap; }

.worldmap { position: relative; }
.worldmap svg { display: block; width: 100%; height: auto; max-height: 72vh; background: var(--map-sea); border-radius: 8px; touch-action: auto; cursor: grab; }
.worldmap svg.zoomed { touch-action: none; }
.worldmap svg.dragging { cursor: grabbing; }
.worldmap .unit { stroke: var(--surface); stroke-width: .6; vector-effect: non-scaling-stroke; cursor: pointer; fill-rule: evenodd; }
.worldmap .unit.dot { stroke-width: 1; }
.worldmap .unit:hover, .worldmap .unit:focus { stroke: var(--text); stroke-width: 1.5; outline: none; }
.worldmap .unit.selected { stroke: var(--text); stroke-width: 2; }
.worldmap .inset { fill: none; stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.worldmap .pt { fill: var(--pt); fill-opacity: .72; stroke: var(--surface); stroke-width: .8; vector-effect: non-scaling-stroke; }
.worldmap .pt.off { opacity: .3; pointer-events: none; }
.worldmap .pt.on { cursor: pointer; }
.worldmap .pt.on:hover, .worldmap .pt.on:focus, .worldmap .pt.hover { stroke: var(--text); stroke-width: 1.8; fill-opacity: .9; outline: none; }
.worldmap .pt.sel { fill: var(--pt); fill-opacity: 1; stroke: var(--text); stroke-width: 2.2; }
.worldmap .hit { fill: transparent; pointer-events: all; cursor: pointer; }
.map-zoom { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 4px; }
.map-zoom button { font: inherit; min-width: 30px; height: 30px; padding: 0 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 1rem; line-height: 1; }
.map-zoom button.reset { font-size: .7rem; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-c0 { fill: var(--map-0); background: var(--map-0); }
.map-c1 { fill: var(--map-1); background: var(--map-1); }
.map-c2 { fill: var(--map-2); background: var(--map-2); }
.map-c3 { fill: var(--map-3); background: var(--map-3); }
.map-c4 { fill: var(--map-4); background: var(--map-4); }
.map-c5 { fill: var(--map-5); background: var(--map-5); }
.map-legend { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center; gap: .3rem 1.2rem; margin-top: .5rem; font-size: .8rem; color: var(--muted); }
.map-legend .bubble { display: inline-flex; align-items: center; gap: .35rem; }
.map-legend svg { display: block; }
.map-legend circle { fill: var(--pt); fill-opacity: .72; stroke: var(--surface); }
.chart-tip { position: absolute; transform: translateX(-50%); pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem; font-size: .82rem; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; color: var(--text); z-index: 5; }
.chart-tip .tip-head { font-weight: 600; margin-bottom: .15rem; }

/* the goods and partners of the place: bars in a list */
.detail { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 32px; }
@media (max-width: 820px) { .detail { grid-template-columns: minmax(0, 1fr); } }
.bars { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; padding: 3px 0; }
.bars .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .n { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.bars .bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bars .bar i { display: block; height: 100%; background: var(--bar); border-radius: 3px; }
.bars button.link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars li.on .name, .bars li.on button.link { font-weight: 700; }

/* the partners' world map: the port's trade lanes */
.worldmap .lanes { pointer-events: none; }
.worldmap .lane { fill: none; stroke: var(--text); stroke-opacity: .6; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.worldmap .lane-end { fill: var(--text); stroke: var(--surface); stroke-width: .8; vector-effect: non-scaling-stroke; }
.worldmap .lane-port { fill: var(--pt); stroke: var(--surface); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
#world svg { max-height: 60vh; }

/* month by month */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 200px; }
.chart .bar { fill: var(--bar-2); }
.chart .bar.jan { fill: var(--bar-3); }
.chart .bar.on { fill: var(--bar); }
.chart .hit { fill: transparent; }
.chart .grid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.download { font-size: .85rem; align-self: flex-start; margin-top: .4rem; }
.month-text { font-size: .95rem; line-height: 1.55; max-width: 70rem; }

/* the biggest changes */
.movers { margin: 0; padding-left: 1.5rem; font-size: .88rem; }
.movers li { padding: 2px 0; }
.movers .n { font-variant-numeric: tabular-nums; margin-left: .4rem; white-space: nowrap; }
.movers li.up .n { color: var(--up); }
.movers li.down .n { color: var(--down); }

.elsewhere { list-style: none; margin: .5rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; font-size: .9rem; }
.elsewhere .n { font-weight: 700; font-variant-numeric: tabular-nums; margin-left: .3rem; }

.foot { color: var(--muted); font-size: 0.8rem; padding-top: 16px; padding-bottom: 32px; display: flex; flex-direction: column; gap: 6px; }
