/* <asili-route>: The Route's own styles (assets/asili-route.js). Ported from prototypes/2-colline (colline.css,
   .route*), every value remapped to the base tokens (merge table 7.1): no --asili-* token, no raw colour, no donor
   font. Colours come from the ground variables (--bg, --ink, --muted, --line), so the map follows the section it
   sits on. Ratios on sand (merge table 7.2): --ink 8.91:1 for the lines, dots and names; --muted 5.27:1 for the
   coastline, the dashed routes, the sea names, the table's heads and the caption.

   Layout, live (data-live, set by the script when motion is allowed): the section is two screens and the map
   pins below the fixed header while scrolling draws the routes. At 1024 and up the whole component pins, the words
   and the table left on columns 1 to 5, the map right on 6 to 12; below 1024 the heading scrolls away and the stage
   (the map, the table under it, the readout, the caption) pins. Still (reduced motion or no script): one screen,
   nothing pins, every route drawn, no readout. */

/* the section: its pin scrolls inside its own two screens (the kit's --h; --hm on a phone) */
main > section:has(> .wrap > asili-route[data-live]) { --h: 2; --hm: 2; }

asili-route {
  /* what the stage holds besides the map below 1024 (the table, the readout, the caption); the script measures
     it in the current language, this is the first guess */
  --route-rest: 300px;
  display: flex; flex-direction: column; gap: var(--s-6);
  flex: 1 0 auto; min-height: 0;
}
.route__head { display: grid; gap: var(--s-4); max-width: 760px; }
.route__lead { font-size: var(--t-lead); line-height: 1.5; max-width: 60ch; }

.route__stage { display: flex; flex-direction: column; gap: var(--s-4); }
asili-route[data-live] .route__stage { position: sticky; top: calc(var(--nav) + var(--s-4)); }

/* ---------------------------------------------------------------- the map */
.route__map { position: relative; aspect-ratio: 740 / 700; width: 100%; }
/* pinned below 1024: the map gives way so the whole stage fits the screen above the phone bar */
asili-route[data-live] .route__map {
  width: min(100%, calc((100svh - var(--nav) - 2 * var(--s-4) - var(--bar, 0px) - var(--route-rest)) * 740 / 700));
}
.route__map svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.route__coast { fill: none; stroke: var(--muted); stroke-linejoin: round; stroke-linecap: round; }
.route__ghost { fill: none; stroke: var(--muted); stroke-linejoin: round; stroke-linecap: round; }
/* every line in ink: where two routes meet they lie on one another and read as one */
.route__line { fill: none; stroke: var(--ink); stroke-linejoin: round; stroke-linecap: round; stroke-dasharray: 1000; }
.route__dot { fill: var(--ink); stroke: var(--bg); }
.route__dot--coast { fill: var(--bg); stroke: var(--ink); }
.route__tip { fill: var(--ink); visibility: hidden; }

.route__labels { position: absolute; inset: 0; pointer-events: none; }
.route__label {
  position: absolute; padding: 2px 6px; background: var(--bg); color: var(--ink);
  font: 600 var(--t-label)/1.2 var(--font-text); white-space: nowrap;
}
.route__label[data-side="left"]  { transform: translate(calc(-100% - var(--s-2)), -50%); }
.route__label[data-side="right"] { transform: translate(var(--s-2), -50%); }
.route__label[data-side="right-up"] { transform: translate(var(--s-2), -75%); }
.route__label[data-side="above"] { transform: translate(-50%, calc(-100% - var(--s-2))); }
/* the seas, upright (Archivo ships no italic here) and in the caption's muted */
.route__sea {
  position: absolute; max-width: 7.5em; transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  font: 400 var(--t-label)/1.2 var(--font-text); letter-spacing: 0.01em; text-align: center; color: var(--muted);
}
.route__sea--red { max-width: none; white-space: nowrap; }
.route__legs { display: none; }

/* ---------------------------------------------------------------- the table: the five origins and their figures */
.route__table { width: 100%; border-collapse: collapse; font-size: var(--t-small); line-height: 1.4; font-variant-numeric: tabular-nums; }
.route__table th, .route__table td { padding: var(--s-2) var(--s-3) var(--s-2) 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: baseline; }
.route__table :is(th, td):last-child { padding-right: 0; }
.route__table thead th { padding-top: 0; font: 500 var(--t-label)/1.4 var(--font-text); letter-spacing: 0.01em; color: var(--muted); }
.route__table tbody th { font-weight: 600; color: var(--ink); }
.route__table .route__num { text-align: right; white-space: nowrap; }
.route__table .route__pending { color: var(--muted); }

/* the readout, live only: what the routes still have to go, counting down as they draw */
.route__togo { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); }
asili-route:not([data-live]) .route__togo { display: none; }
.route__togo-label { font: 500 var(--t-label)/1.4 var(--font-text); letter-spacing: 0.01em; color: var(--muted); }
.route__togo-value {
  font: var(--display-weight) var(--t-stat)/1 var(--font-display); font-stretch: var(--display-stretch);
  letter-spacing: var(--display-tracking); font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink);
}

.route__caption { max-width: 60ch; font-size: var(--t-small); line-height: 1.5; color: var(--muted); text-wrap: pretty; }

/* ---------------------------------------------------------------- a phone: the seas leave the map for the caption
   (merge table 7 "Data": 13px labels collide at 342px); the origin names stay, placed so they never meet */
@media (max-width: 639px) {
  .route__sea { display: none; }
  .route__legs { display: inline; }
  .route__stage { gap: var(--s-3); }
  .route__table th, .route__table td { padding-block: 6px; }
}

/* ---------------------------------------------------------------- 1024 and up: words left, map right */
@media (min-width: 1024px) {
  asili-route {
    /* the map's height: one screen's content when still, the screen under the header when pinned */
    --route-h: calc(100svh - var(--padt) - var(--padb));
    display: grid; grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-template-rows: auto auto auto minmax(0, 1fr);
    column-gap: var(--gutter); row-gap: 0; align-items: start; flex: none;
  }
  asili-route[data-live] { position: sticky; top: calc(var(--nav) + var(--s-5)); --route-h: calc(100svh - var(--nav) - 2 * var(--s-5)); }
  .route__stage { display: contents; }
  .route__head { grid-column: 1 / span 5; grid-row: 1; }
  .route__table { grid-column: 1 / span 5; grid-row: 2; margin-top: var(--s-7); }
  .route__togo { grid-column: 1 / span 5; grid-row: 3; margin-top: var(--s-6); }
  .route__caption { grid-column: 1 / span 5; grid-row: 4; align-self: end; margin-top: var(--s-6); }
  .route__map,
  asili-route[data-live] .route__map { grid-column: 6 / -1; grid-row: 1 / -1; justify-self: end; width: min(100%, calc(var(--route-h) * 740 / 700)); }
}
