.cw-traffic {
  --traffic-bg: #fff;
  --traffic-text: #20252c;
  --traffic-muted: #727983;
  --traffic-line: #e8ebef;
  --traffic-inset: #f3f5f7;
  --traffic-tick: #dce1e6;
  --traffic-light: #168567;
  --traffic-busy: #a7740e;
  --traffic-heavy: #cf483e;
  /* The instrument: near-black surface, one warm signal, 3px cells at a 7px
     pitch (see docs/design-language.md, "Instruments"). Tokens come from the
     theme; the fallbacks are the same values so the widget holds up without it. */
  --traffic-instrument: var(--icrt-instrument, #121316);
  --traffic-dot-off: var(--icrt-dot-off, #2b2e35);
  --traffic-signal: var(--icrt-signal, #ff7a1a);
  --traffic-cells: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='7' height='7'%3E%3Crect x='2' y='2' width='3' height='3' rx='.6'/%3E%3C/svg%3E");
  background: var(--traffic-bg);
  color: var(--traffic-text);
  border: 1px solid var(--traffic-line);
  border-radius: 20px;
  padding: 20px;
  width: 100%;
  max-width: 520px;
  min-width: 0;
  box-sizing: border-box;
  font-family: inherit;
  line-height: 1.4;
  container-type: inline-size;
}
.s-dark .cw-traffic {
  --traffic-bg: #181a1f;
  --traffic-text: #f0f1f3;
  --traffic-muted: #999fa9;
  --traffic-line: #2c2f36;
  --traffic-inset: #20232a;
  --traffic-tick: #363a43;
  --traffic-light: #59d7ac;
  --traffic-busy: #efbd5a;
  --traffic-heavy: #f27769;
}
.cw-traffic [hidden] { display: none !important; }
.cw-traffic p, .cw-traffic ul { margin: 0; padding: 0; }
.cw-traffic__header { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 16px; }
/* Sentence case like every other label here: a tracked-caps eyebrow is the
   template tell the design language bans. */
.cw-traffic .cw-traffic__eyebrow { color: var(--traffic-muted); font-size: 11px; font-weight: 500; letter-spacing: 0; text-transform: none; margin-bottom: 4px; }
.cw-traffic__header > div { min-width: 0; }
.cw-traffic__city { display: flex; position: relative; align-items: center; width: fit-content; max-width: 100%; }
.cw-traffic__city select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent; box-shadow: none;
  color: var(--traffic-text); font: inherit; font-weight: 650; font-size: 27px; line-height: 1.25;
  padding: 0 25px 0 0; height: auto; min-height: 36px; cursor: pointer; width: auto; max-width: 100%; field-sizing: content;
}
.cw-traffic__city option { background: var(--traffic-bg); color: var(--traffic-text); font-size: 17px; }
.cw-traffic__city svg { width: 16px; height: 16px; position: absolute; right: 0; pointer-events: none; fill: none; stroke: var(--traffic-muted); stroke-width: 1.7; }
.cw-traffic button.cw-traffic__locate {
  display: grid; place-items: center; flex: 0 0 40px; width: 40px; height: 40px; min-height: 40px;
  padding: 0; border: 1px solid var(--traffic-line); border-radius: 50%; box-shadow: none;
  color: var(--traffic-text); background: var(--traffic-inset); text-transform: none; letter-spacing: 0; cursor: pointer;
}
.cw-traffic button.cw-traffic__locate:hover { background: var(--traffic-tick); }
.cw-traffic button.cw-traffic__locate:disabled { opacity: .5; cursor: wait; }
.cw-traffic__locate svg { width: 20px; height: 20px; }
.cw-traffic :focus-visible { outline: 2px solid #447bd7; outline-offset: 4px; }
.cw-traffic .cw-traffic__notice { padding: 10px 12px; margin-bottom: 14px; border-radius: 10px; background: var(--traffic-inset); color: var(--traffic-text); font-size: 12px; }
.cw-traffic [data-level="light"] { --level: var(--traffic-light); --level-lit: var(--traffic-light); }
.cw-traffic [data-level="busy"] { --level: var(--traffic-busy); --level-lit: var(--traffic-signal); }
.cw-traffic [data-level="heavy"] { --level: var(--traffic-heavy); --level-lit: var(--traffic-heavy); }
.cw-traffic [data-level="unknown"] { --level: var(--traffic-muted); --level-lit: var(--traffic-muted); }
.cw-traffic__overview { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 17px; }
.cw-traffic__scope { display: block; color: var(--traffic-muted); font-size: 11px; margin-bottom: 3px; }
.cw-traffic__overview strong { font-size: 21px; line-height: 1.35; font-weight: 500; }
.cw-traffic__meter { display: flex; gap: 11px; align-items: center; flex-shrink: 0; }
.cw-traffic__meter i {
  width: 24px; height: 17px; background: var(--traffic-line);
  -webkit-mask: var(--traffic-cells) -2px -2px / 7px 7px; mask: var(--traffic-cells) -2px -2px / 7px 7px;
}
.cw-traffic__meter .is-on { background: var(--level-lit); }
.cw-traffic__map { position: relative; overflow: hidden; isolation: isolate; border-radius: 12px; background: var(--traffic-instrument); aspect-ratio: 3 / 2; width: 100%; }
/* The real OpenStreetMap basemap, rendered plainly. It was halftoned through
   the LED cells for a while and nobody could recognise Taipei in it: a map
   has to stay a map, so the grid lives on the meters and not here. The <img>
   is cropped to the SVG viewBox by the custom properties content() writes. */
.cw-traffic__basemap {
  position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
}
.cw-traffic__basemap img {
  position: absolute; display: block; margin: 0; max-width: none;
  left: calc(-100% * var(--cw-vx, 0) / var(--cw-vw, 360)); top: calc(-100% * var(--cw-vy, 0) / var(--cw-vh, 240));
  width: calc(100% * 360 / var(--cw-vw, 360)); height: calc(100% * 240 / var(--cw-vh, 240));
}
.cw-traffic__map > svg { display: block; position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; }
.cw-traffic__map svg [data-level="light"] { --level: #59d7ac; }
.cw-traffic__map svg [data-level="busy"] { --level: var(--traffic-signal); }
.cw-traffic__map svg [data-level="heavy"] { --level: #f27769; }
/* Lit cells along the road: zero-length dashes with round caps, one every 7px.
   non-scaling-stroke keeps the pitch and the dot size in screen pixels however
   far the viewBox zooms in on a city. */
.cw-traffic__route { stroke: var(--level); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.cw-traffic__tail { stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.cw-traffic__tail-gradient stop { stop-color: var(--level); }
.cw-traffic__pin circle { fill: var(--traffic-instrument); stroke: var(--level); stroke-width: 1.2; }
.cw-traffic__pin text { fill: #fff; font-size: 10px; font-weight: 650; stroke: none; }
.cw-traffic__leader { stroke: var(--level); stroke-width: .7; opacity: .55; }
.cw-traffic__glow { stroke: var(--level); stroke-width: 10; opacity: .16; vector-effect: non-scaling-stroke; }
.cw-traffic__map .is-active .cw-traffic__route { stroke-width: 5; }
.cw-traffic__map .is-active .cw-traffic__glow { opacity: .38; stroke-width: 14; }
.cw-traffic__north { position: absolute; top: 12px; right: 12px; z-index: 2; color: #a4adb6; font-size: 9px; letter-spacing: .15em; }
.cw-traffic a.cw-traffic__map-credit { position: absolute; right: 8px; bottom: 5px; z-index: 2; color: #b5bec7; background: rgba(18, 19, 22, .8); padding: 1px 4px; border-radius: 3px; font-size: 8px; text-decoration: none; }
.cw-traffic__map-message { position: absolute; bottom: 30px; left: 12px; right: 12px; z-index: 2; text-align: center; padding: 10px; color: #c9d1d9; background: rgba(18, 19, 22, .9); border-radius: 8px; font-size: 12px; }
.cw-traffic__list-heading { display: flex; justify-content: space-between; margin: 18px 0 6px; color: var(--traffic-muted); font-size: 10px; letter-spacing: .03em; }
.cw-traffic ul.cw-traffic__roads { list-style: none; }
.cw-traffic__roads li { list-style: none; display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 9px 0; margin: 0; border-bottom: 1px solid var(--traffic-line); }
.cw-traffic__number { color: var(--level); font-size: 11px; border: 1px solid var(--traffic-line); border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; }
.cw-traffic__more { margin: 4px 0 0; padding: 0; }
.cw-traffic__more summary { display: flex; justify-content: space-between; align-items: center; color: var(--traffic-muted); cursor: pointer; padding: 10px 0; list-style: none; font-size: 11px; }
.cw-traffic__more summary::-webkit-details-marker { display: none; }
.cw-traffic__more summary:hover { color: var(--traffic-text); }
.cw-traffic__more .cw-traffic__collapse, .cw-traffic__more[open] .cw-traffic__expand { display: none; }
.cw-traffic__more[open] .cw-traffic__collapse { display: inline; }
.cw-traffic__more[open] summary > span:last-child { transform: rotate(180deg); }
.cw-traffic__roads li:last-child { border-bottom: 0; }
.cw-traffic__road-name { min-width: 0; }
.cw-traffic__road-name strong { display: block; color: var(--traffic-text); font-size: 14px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cw-traffic__road-name > span { display: block; font-size: 10px; margin-top: 4px; color: var(--traffic-muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cw-traffic__road-level { text-align: right; }
.cw-traffic__ticks { display: flex; justify-content: flex-end; gap: 4px; margin-bottom: 5px; }
.cw-traffic__ticks i {
  width: 3px; height: 10px; background: var(--traffic-line);
  -webkit-mask: var(--traffic-cells) -2px -2px / 7px 7px; mask: var(--traffic-cells) -2px -2px / 7px 7px;
}
.cw-traffic__ticks .is-on { background: var(--level-lit); }
.cw-traffic__road-level small { display: block; font-size: 10px; color: var(--level); }
.cw-traffic__road-level small span { color: var(--traffic-muted); }
.cw-traffic__footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 5px 12px; border-top: 1px solid var(--traffic-line); padding-top: 12px; margin-top: 7px; color: var(--traffic-muted); font-size: 9px; }
.cw-traffic__footer > span { display: inline-flex; align-items: center; gap: 8px; }
.cw-traffic__footer a { color: var(--traffic-muted); text-decoration: none; }
/* The live badge, two-tone: a signal square holding a dark dot, then a light
   label on the instrument surface. Stale unlights the square. */
.cw-traffic__live {
  display: inline-flex; align-items: center; height: 16px; padding-right: 6px; border-radius: 4px; overflow: hidden;
  background: var(--traffic-instrument); box-shadow: inset 0 0 0 1px var(--icrt-instrument-line, rgba(255, 255, 255, .08));
  color: #f0f1f3; font-size: 9px; font-weight: 600; line-height: 1; letter-spacing: 0; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.cw-traffic__freshness { position: relative; display: block; width: 16px; height: 16px; margin-right: 6px; background: var(--traffic-signal); }
.cw-traffic__freshness::before { content: ""; position: absolute; top: 6px; left: 6px; width: 4px; height: 4px; border-radius: 50%; background: var(--traffic-instrument); }
.cw-traffic__live.is-stale .cw-traffic__freshness { background: var(--traffic-dot-off); }
.cw-traffic__empty { display: flex; gap: 10px; align-items: center; padding: 24px 0; }
.cw-traffic__empty > span { color: var(--traffic-light); display: grid; place-items: center; width: 28px; height: 28px; border: 1px solid var(--traffic-line); border-radius: 50%; flex-shrink: 0; }
.cw-traffic__empty strong { font-size: 13px; font-weight: 600; }
.cw-traffic__empty p { font-size: 11px; color: var(--traffic-muted); margin-top: 4px; }
.cw-traffic.is-loading .cw-traffic__content { opacity: .45; }
.cw-traffic.is-loading .cw-traffic__roads, .cw-traffic.is-loading .cw-traffic__map > svg { visibility: hidden; }
@container (max-width: 270px) {
  .cw-traffic__city select { font-size: 24px; }
  .cw-traffic__overview strong { font-size: 19px; }
  .cw-traffic__meter i { width: 17px; }
}
@media (max-width: 360px) { .cw-traffic { padding: 18px; } }
