@layer stage {
  /* The map sheet. */
  .stage {
    margin: 0; min-inline-size: 0;
    background: var(--sheet); border: 0.07rem solid var(--rule); border-radius: var(--radius);
    display: grid; gap: 0.75rem; padding: 0.75rem;
    grid-auto-rows: max-content;          /* a panel keeps its height; the stage scrolls when there is too much */
    contain: layout style;
    container: stage / inline-size;       /* panels inside lay themselves out by the stage's width */
  }
  .canvas { inline-size: 100%; block-size: auto; max-block-size: 50dvh; }
  .canvas text { font-family: var(--font-body); fill: var(--ink); }

  /* ---- road ---- */
  .asphalt { fill: var(--asphalt); }
  .lane { stroke: var(--signal); stroke-width: 2.5; stroke-dasharray: 14 12; }
  .post { stroke: var(--ink-3); stroke-width: 2; }
  .canvas .post-number { font-family: var(--font-num); font-size: 17px; fill: var(--ink-2); text-anchor: middle; }

  /* ---- depot and sites ---- */
  .mark-stem { stroke: var(--ink-3); stroke-width: 2; }
  .mark-site .mark-shape { fill: var(--sheet); stroke: var(--ink); stroke-width: 2.5; }
  .mark-depot .mark-shape { fill: var(--ink); stroke: var(--ink); stroke-width: 2.5; }
  .canvas .mark-label { font-family: var(--font-num); font-size: 18px; font-weight: 700; text-anchor: middle; }
  .canvas .mark-depot .mark-label { fill: var(--sheet); font-family: var(--font-body); font-size: 15px; }
  .mark.is-visited .mark-shape { fill: var(--ink-3); stroke: var(--ink-3); }
  .mark.is-visited .mark-label { fill: var(--sheet); }
  .mark.is-spot .mark-shape { stroke: var(--signal); stroke-width: 5; }
  .canvas .site-name { font-size: 16px; fill: var(--ink-2); }
  .is-pickable .mark-site { cursor: pointer; }
  .is-pickable .mark-site:hover .mark-shape { stroke: var(--signal); stroke-width: 5; }
  .mark.is-picked .mark-shape { fill: var(--signal); }

  /* ---- truck ---- */
  .truck-box { fill: var(--signal); stroke: var(--ink); stroke-width: 1.5; }
  .truck-cab { fill: var(--sheet); stroke: var(--ink); stroke-width: 1.5; }
  .truck-window { fill: var(--ink-3); }
  .truck-wheel { fill: var(--ink); }

  /* ---- measuring ---- */
  .measure-line { stroke: var(--ink); stroke-width: 2; }
  .measure-plate { fill: var(--sheet); stroke: var(--ink); stroke-width: 1.5; }
  .canvas .measure-text { font-family: var(--font-num); font-size: 15px; text-anchor: middle; }

  /* ---- looking for the nearest site ---- */
  .look-arc { fill: none; stroke: var(--ink-2); stroke-width: 2; stroke-dasharray: 6 6; }
  .look-plate { fill: var(--sheet); stroke: var(--ink-2); stroke-width: 1.5; }
  .canvas .look-text { font-family: var(--font-num); font-size: 17px; font-weight: 700; text-anchor: middle; }
  .look.is-picked .look-arc { stroke: var(--ink); stroke-dasharray: none; stroke-width: 3; }
  .look.is-picked .look-plate { fill: var(--signal); stroke: var(--ink); }
  .look.is-picked .look-text { fill: var(--on-signal); }
  .look.is-dropped { opacity: 0.3; }

  /* ---- legs driven ---- */
  .leg-line { stroke-width: 4; stroke-linecap: round; }
  .leg-drop { stroke-width: 1.2; stroke-dasharray: 3 4; opacity: 0.55; }
  .canvas .leg-text { font-size: 14px; fill: var(--ink-2); text-anchor: middle; }
  .leg.is-hot .leg-text { fill: var(--bad); font-weight: 700; }
  .leg.is-cut .leg-line { stroke: var(--bad); stroke-dasharray: 5 7; }
  .leg.is-cut .leg-text { fill: var(--bad); text-decoration: line-through; }
  .layer-legs.is-dim .leg:not(.is-hot) { opacity: 0.35; }
  .canvas .band-name { font-size: 15px; font-weight: 700; }

  /* ---- town map ---- */
  .grid-line { stroke: var(--rule); stroke-width: 1; }
  .route-line { stroke-width: 4; stroke-linecap: round; }
  .route-line.is-thin { stroke-width: 2.5; }
  .route-line.is-ghost { stroke: var(--ink-3); stroke-width: 2; stroke-dasharray: 3 6; }
  .route-line.is-hot { stroke: var(--bad); }
  .route-line.is-fresh { stroke-width: 7; }
  .tree-link { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
  .tree-link.is-depot { stroke: var(--route-hk); stroke-dasharray: 7 6; }
  .crossing { fill: none; stroke: var(--bad); stroke-width: 3; }

  /* ---- choice tree ---- */
  .tree-edge { stroke: var(--ink-3); stroke-width: 2; }
  .canvas .tree-order { font-family: var(--font-num); font-size: 15px; text-anchor: middle; fill: var(--ink-2); }
  .canvas .tree-count { font-size: 15px; fill: var(--ink-2); }

  /* ---- trip meter ---- */
  .odometer {
    order: -1; justify-self: start;
    display: flex; align-items: baseline; gap: 0.4rem;
    padding: 0.25rem 0.7rem; border-radius: var(--radius);
    background: var(--ink); color: var(--sheet);
  }
  .odometer-label, .odometer-unit { font-size: 0.8125rem; }
  .odometer-value { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 1.7rem; line-height: 1.1; min-inline-size: 1.6ch; text-align: end; color: var(--signal); }

  /* ---- panels under the drawing ---- */
  .panel { min-inline-size: 0; }

  table.dist { border-collapse: collapse; margin-inline: auto; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
  table.dist caption { caption-side: top; font-family: var(--font-body); color: var(--ink-2); font-size: 0.9375rem; padding-block-end: 0.35rem; }
  table.dist th, table.dist td { border: 0.07rem solid var(--rule); inline-size: 3.6rem; block-size: clamp(1.9rem, 4.6dvh, 2.6rem); text-align: center; font-size: 1.25rem; }
  table.dist th { font-family: var(--font-body); font-size: 1rem; background: var(--paper); font-weight: 700; }
  table.dist .corner { position: relative; font-weight: 400; font-size: 0.75rem; color: var(--ink-3); }
  .corner-from { position: absolute; inset-block-end: 0.15rem; inset-inline-start: 0.3rem; }
  .corner-to { position: absolute; inset-block-start: 0.15rem; inset-inline-end: 0.3rem; }
  table.dist tr.is-row > th { background: var(--signal); color: var(--on-signal); }
  table.dist td.is-row { background: var(--wash); }
  table.dist td.is-off { color: var(--ink-3); background: transparent; text-decoration: line-through; }
  table.dist td.is-hot, table.dist td.is-min { background: var(--signal); color: var(--on-signal); font-weight: 700; }
  table.dist td.is-new { background: var(--wash); transition: background-color 0.8s; }
  table.dist td.is-right { outline: 0.2rem solid var(--good); outline-offset: -0.2rem; }
  table.dist td.is-wrong { outline: 0.2rem dashed var(--bad); outline-offset: -0.2rem; }
  table.dist td > button { inline-size: 100%; block-size: 100%; min-block-size: 0; padding: 0; border: 0; border-radius: 0; background: transparent; font: inherit; }
  table.dist.is-askable td > button:hover { background: var(--wash); }

  .flyer {
    position: absolute; translate: -50% -50%; z-index: 1; pointer-events: none;
    font-family: var(--font-num); font-size: 1.25rem; font-weight: 700;
    background: var(--signal); color: var(--on-signal); border-radius: 1rem; padding: 0 0.6rem;
  }

  /* ---- scoreboard of orders tried ---- */
  .board-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.3rem; counter-reset: order; }
  .board-row {
    counter-increment: order;
    display: grid; grid-template-columns: 1.2rem max-content 5.6rem minmax(2rem, 1fr) 2.8rem; align-items: center; gap: 0.6rem;
    font-size: 0.9375rem; padding: 0.15rem 0.4rem; border-radius: 0.3rem;
  }
  .board-row::before { content: counter(order); font-family: var(--font-num); color: var(--ink-3); }
  .board-sum, .board-total { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 1.0625rem; }
  .board-total { font-weight: 700; text-align: end; }
  .board-track { block-size: 0.6rem; background: var(--paper); border-radius: 0.3rem; overflow: clip; }
  .board-bar { display: block; block-size: 100%; inline-size: 0; background: var(--ink-3); transition: inline-size 0.25s linear; }
  .board-row.is-best { background: var(--wash); }
  .board-row.is-best .board-bar { background: var(--good); }
  .board-row.is-rest .board-total { color: var(--ink-2); }
  .board-row.is-pair { outline: 0.15rem solid var(--ink); }
  @container stage (inline-size < 24rem) { .board-row { grid-template-columns: 1.2rem minmax(0, 1fr) 3rem; } .board-sum, .board-track { display: none; } }

  /* ---- order counter ---- */
  .counter { display: grid; gap: 0.35rem; justify-items: center; text-align: center; padding-block: 1.25rem; }
  .counter-sites { font-family: var(--font-title); font-weight: 900; font-size: 1.375rem; }
  .counter-product { font-family: var(--font-num); color: var(--ink-2); font-size: 1.125rem; }
  .counter-number { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: clamp(1.5rem, 0.6rem + 5cqi, 3.2rem); line-height: 1.15; color: var(--ink); }
  .counter-number.is-bump { animation: bump 0.35s ease-out; }
  @keyframes bump { from { scale: 1.12; } to { scale: 1; } }
  @media (prefers-reduced-motion: reduce) { .counter-number.is-bump { animation: none; } }
  .counter-words { color: var(--ink-2); min-block-size: 1.75em; }
  .counter-time { margin-block-start: 0.5rem; padding: 0.4rem 0.9rem; border-radius: var(--radius); background: var(--paper); }
  .counter-time strong { font-family: var(--font-num); font-size: 1.25em; }
  .counter-control { display: grid; gap: 0.25rem; margin-block-start: 0.75rem; color: var(--ink-2); font-size: 0.9375rem; inline-size: min(100%, 24rem); }
  .counter-control input { inline-size: 100%; accent-color: var(--ink); }

  /* ---- note cards ---- */
  .notes { display: grid; gap: 0.75rem; padding-block: 0.5rem; }
  @container stage (inline-size > 30rem) { .notes-2 { grid-template-columns: 1fr 1fr; } .notes-3 { grid-template-columns: repeat(3, 1fr); } }
  .note { border: 0.1rem solid var(--rule); border-radius: var(--radius); padding: 0.8rem 1rem; display: grid; gap: 0.35rem; align-content: start; background: var(--paper); }
  .note h3 { font-size: 1.1875rem; }
  .note p { font-size: 0.9688rem; color: var(--ink-2); }
  .note-tag { font-family: var(--font-num); color: var(--ink-3); }
  .note.nn { border-color: var(--route-nn); } .note.two { border-color: var(--route-2opt); } .note.hk { border-color: var(--route-hk); }
  .note.nn h3 { color: var(--route-nn); } .note.two h3 { color: var(--route-2opt); } .note.hk h3 { color: var(--route-hk); }
  .note.plain h3 { color: var(--ink); }
  .note.later { border-style: dashed; }

  .stage-line { text-align: center; color: var(--ink-2); font-size: 0.9688rem; }
  .stage-line .num { font-size: 1.25em; color: var(--ink); }
}
