/* ======================================================
   TerraLoc Track View - map-first layout
   ====================================================== */

:root {
  --tl-track-top-offset: 0px;
  --tl-track-radius: 1.15rem;
  --tl-track-radius-sm: 0.85rem;
  --tl-track-shadow-sm: 0 10px 26px rgba(15, 23, 42, 0.12);
  /* The kit owns this now; kept as an alias so nothing here changes. */
  --tl-track-shadow-md: var(--tl-card-shadow, 0 20px 48px rgba(15, 23, 42, 0.18));
  --tl-track-border: rgba(255, 255, 255, 0.42);
  --tl-track-overlay-bg: rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.82);
  --tl-track-overlay-bg-strong: rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.9);
  --tl-track-overlay-muted: rgba(var(--bs-secondary-bg-rgb, 248, 249, 250), 0.88);
  --tl-track-graph-h: clamp(88px, 11vh, 120px);
  /* The kit owns this now; the phone override below still applies. */
  --tl-track-transport-h: 3.5rem;
  /* Brand gradient, shared with the competition analyzer transport bar */
  --tl-track-grad-start: var(--tl-accent);
  --tl-track-grad-end: var(--tl-accent-hover);
}

.tl-track-page {
  margin: 0;
  padding: 0;
}

/*
 * THE STAGE IS A RAIL BESIDE A MAP.
 *
 * It was one column with everything floated on top of the map, and the wash
 * behind it was a blue-to-gold radial pair from the sky product. The rail is
 * a real column now, full height at the left edge with its own hairline, the
 * way the mockup draws it: a panel that belongs to the page rather than a
 * cluster of buttons parked on a hillside.
 */
/* .tl-stage carries the arrangement: side by side, and stacked with the rail
   at the foot of it on a phone. What is left here is how tall it is. */
.tl-track-stage {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--tl-track-top-offset, 0px));
  height: calc(100svh - var(--tl-track-top-offset, 0px));
  background: var(--tl-paper, #F3F2EC);
}

.tl-track-map-stage {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.tl-track-map-wrap {
  position: relative;
  min-height: 0;
  height: 100%;
}

/* A day with no line: a pool swim, counted in lengths with no position. No map to draw, no
   profile and nothing to play back; the figures panel, opened by track.js, is the page. */
.tl-track-no-line .tl-track-map-wrap {
  display: none;
}

.tl-track-map-wrap {
  overflow: hidden;
  isolation: isolate;
}

.tl-map {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  background: var(--bs-tertiary-bg, #d7e3ef);
  transform: translateZ(0);
  backface-visibility: hidden;
}

.tl-track-overlay {
  position: absolute;
  z-index: 6;
}

.tl-track-title {
  font-size: clamp(1rem, 1.55vw, 1.34rem);
  font-weight: 700;
  line-height: 1.08;
  color: var(--bs-body-color, #111);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
}

.tl-track-meta-list {
  margin-top: 0.38rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  font-size: 0.78rem;
  color: var(--bs-secondary-color, #6c757d);
}

.tl-track-meta-list span,
.tl-track-meta-list a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: inherit;
  text-decoration: none;
}

.tl-track-meta-list a:hover {
  color: var(--bs-primary);
}
/* The rail's height and its scrolling live on .tl-stage in tl-ui.css now, with
   the rest of what a rail does. */
/*
   A FACT, NOT A BUTTON.

   This was a pill: 2.15rem tall, rounded to 999px, on its own background with
   a border and a drop shadow. Nothing about "3.2 km" is pressable, and five
   of them beside a title read as a toolbar. The light theme already stripped
   all of it in .tl-track-facts below, and the dark theme put the background
   and border straight back on a rule of equal weight further down the file,
   which is why the strip looked right on one face and like a row of buttons
   on the other. Flat in the base, so there is nothing for either face to
   disagree about.
*/
.tl-track-center-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  color: var(--bs-secondary-color, #6c757d);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
}

.tl-track-center-chip i {
  color: var(--bs-primary);
}

.tl-track-reactions .tl-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.tl-track-photo-fan {
  --tl-track-fan-left: 4.5rem;
  --tl-track-fan-top: 10rem;
  position: absolute;
  left: var(--tl-track-fan-left);
  top: var(--tl-track-fan-top);
  z-index: 7;
  display: flex;
  align-items: flex-end;
  gap: 0.42rem;
  opacity: 0;
  pointer-events: none;
  transform: translate3d(0, 8px, 0) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tl-track-photo-fan.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translate3d(0, 0, 0) scale(1);
}

.tl-track-photo-fan a {
  display: block;
}

.tl-track-photo-fan .gallery-image {
  width: 4.35rem;
  height: 4.35rem;
  object-fit: cover;
  border-radius: 1rem;
  border: 1px solid var(--tl-track-border);
  box-shadow: var(--tl-track-shadow-sm);
  background: var(--tl-track-overlay-bg);
  cursor: pointer;
}

.tl-track-photo-fan .gallery-image:nth-of-type(1) {
  transform: rotate(-13deg) translateY(0.25rem);
}

.tl-track-photo-fan .gallery-image:nth-of-type(2) {
  transform: rotate(-6deg) translateY(0.1rem);
}

.tl-track-photo-fan .gallery-image:nth-of-type(3) {
  transform: rotate(0deg);
}

.tl-track-photo-fan .gallery-image:nth-of-type(4) {
  transform: rotate(7deg) translateY(0.1rem);
}

.tl-track-photo-fan .gallery-image:nth-of-type(5) {
  transform: rotate(13deg) translateY(0.25rem);
}

.tl-track-photo-fan .gallery-image:nth-of-type(n + 6) {
  display: none;
}.tl-speed-stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.tl-speed-readout {
  min-width: 3.2ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--bs-body-color, #212529);
}
/* ============================================================= *\
   THE DOCK

   A transport pill floated in the middle of the map and an altitude
   sheet slid up from the bottom edge, pushing the pill as it came.
   Two surfaces, two shadows, and a profile you had to go and find.

   One card now, pinned to the map's bottom edge: playback on the
   left, the profile filling the middle, the readouts and the two
   toggles on the right, and a mono line under all of it saying when
   and where the day happened. Opening the profile grows the card
   upward instead of shoving anything.
\* ============================================================= */

.tl-track-play-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--tl-accent, #46603C);
  color: var(--tl-paper, #F3F2EC);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.tl-track-play-btn:hover {
  background: var(--tl-accent-hover, #2E4228);
}

.tl-track-play-btn i {
  font-size: 0.8rem;
  pointer-events: none;
}

.tl-track-transport-speed {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 32px;
  padding: 0 0.5rem;
  border: 1px solid var(--tl-hairline, #DFDCCB);
  border-radius: 8px;
}

.tl-track-transport-speed button {
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--tl-muted, #5C6253);
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tl-track-transport-speed button:hover:not(:disabled) {
  color: var(--tl-ink, #23281F);
}

.tl-track-transport-speed button:disabled {
  opacity: 0.35;
  cursor: default;
}

.tl-speed-stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.tl-speed-readout {
  min-width: 3.2ch;
  text-align: center;
  font-family: var(--tl-font-mono, ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--tl-ink, #23281F);
}

/* Reset is a word, not a glyph: a circling arrow is read as "reload the
   page" at least as often as "start the replay again". */
.tl-track-dock-reset {
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--tl-cta-hover, #A8512E);
  cursor: pointer;
  text-transform: uppercase;
}

.tl-track-dock-reset:hover {
  color: var(--tl-cta, #C86B3F);
}

/* ---------------------------------------------------------------
   The profile, which is also the timeline
   --------------------------------------------------------------- */

/* Open: the same canvas, drawn tall enough to read a gradient off. */
.tl-track-map-wrap.tl-chart-open .tl-track-profile {
  height: var(--tl-track-chart-h);
}

/*
   OPEN, THE PROFILE TAKES THE WHOLE ROW.

   The dock is one flex line: transport, then the profile, then the clock and
   the buttons. At 44px that is right, the profile being a strip between two
   sets of controls. Opened to 200px it is wrong: the chart was 777px of a
   1292px row with the transport parked in empty space on one side and the
   readouts in empty space on the other, and the graph everyone opened the
   dock to read got 60% of the width.

   Wrapping and giving the profile the full basis puts it on its own line with
   the controls underneath, which is the same markup and no new element.
*/
.tl-track-map-wrap.tl-chart-open .tl-track-dock-row {
  flex-wrap: wrap;
  align-items: center;
  row-gap: 0.35rem;
}

.tl-track-map-wrap.tl-chart-open .tl-track-profile {
  order: -1;
  flex: 1 1 100%;
  width: 100%;
}

/* The readouts and the buttons keep to the right of the control line; the
   transport keeps to the left. Without this they all pack left and the row
   ends in a metre of nothing. */
.tl-track-map-wrap.tl-chart-open .tl-track-clock {
  margin-left: auto;
}

#altChart {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: ew-resize;
}

/* The canvas cannot take focus, so the range input behind it is what a
   keyboard drives. It is off-screen, which means the focus ring has to be
   drawn by the thing the athlete can actually see. */
/* ---------------------------------------------------------------
   Readouts and the two toggles
   --------------------------------------------------------------- */

/*
   THE TIME AND THE ALTITUDE UNDER THE PLAYHEAD, AS ONE READOUT.

   They were two sizes and two colours for one fact: the clock at .78rem in
   ink, the altitude at .7rem in the accent green. Green is this site's
   interactive colour and an altitude is not interactive, so the eye kept
   going to it as though it were a link, and the pair read as a heading with
   a footnote rather than as one line you scrub.

   Same size, same weight, one muted step between them.
*/
/* No fixed width reserved for it: an empty column of nothing is worse than a
   label that appears when the playback starts. */
.tl-track-resume-follow {
  border-color: var(--tl-accent, #46603C);
  color: var(--tl-accent, #46603C);
}

/* ---------------------------------------------------------------
   When and where, in one mono line
   --------------------------------------------------------------- */

/* The context line: where and when, either end and the middle. .6rem was
   below the size anything is meant to be read at, and the ends were set
   larger than the middle for no reason anyone could name. One size. */
.tl-xc-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(var(--bs-primary-rgb, 13, 110, 253), 0.12);
  border-radius: 1.25rem;
  background:
    radial-gradient(circle at top right, rgba(13, 110, 253, 0.12), transparent 34%),
    radial-gradient(circle at bottom left, rgba(32, 201, 151, 0.14), transparent 28%),
    rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.96);
  box-shadow:
    0 18px 38px rgba(15, 23, 42, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

.tl-xc-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(125deg, rgba(255, 255, 255, 0.22), transparent 38%, transparent 62%, rgba(13, 110, 253, 0.06));
  pointer-events: none;
}

.tl-xc-card-body {
  position: relative;
  display: grid;
  gap: 0.78rem;
}

.tl-xc-topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.55rem 0.85rem;
  align-items: center;
}

.tl-xc-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.7rem;
  min-width: 0;
  flex: 1 1 24rem;
}

.tl-xc-heading .badge {
  padding: 0.46rem 0.78rem;
  font-size: 0.74rem;
}

#xcPills {
  flex: 1 1 24rem;
  width: auto;
  min-width: 0;
  margin-right: -0.15rem;
  padding-bottom: 0.1rem;
}

#xcPills .pill {
  border-radius: 999px;
  padding-block: 0.42rem;
  border-color: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.14);
  background: rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.8);
  color: var(--bs-body-color, #111);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
  white-space: nowrap;
}

#xcPills .btn-check:checked + .pill {
  border-color: transparent;
  background: linear-gradient(135deg, var(--bs-primary), color-mix(in srgb, var(--bs-primary) 60%, #28c76f));
  color: #fff;
}

#xcPills .btn-check:checked + .pill i,
#xcPills .btn-check:checked + .pill .long,
#xcPills .btn-check:checked + .pill .sep {
  color: inherit;
}

.tl-xc-badge-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-start;
  align-self: center;
}

.tl-xc-badge-cloud > * {
  border-radius: 999px;
  padding: 0.34rem 0.68rem;
  background: rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.72);
  border: 1px solid rgba(var(--bs-body-color-rgb, 33, 37, 41), 0.08);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.06);
}

.tl-xc-summary {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) repeat(3, minmax(0, 0.88fr));
  gap: 0.75rem;
  align-items: stretch;
}

.tl-xc-hero-card {
  display: grid;
  gap: 0.18rem;
  align-content: center;
  padding: 0.95rem 1.05rem;
  border-radius: 1.05rem;
  background:
    linear-gradient(145deg, rgba(13, 110, 253, 0.12), rgba(13, 110, 253, 0.04)),
    rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.88);
  border: 1px solid rgba(var(--bs-primary-rgb, 13, 110, 253), 0.1);
  min-height: 0;
}

.tl-xc-hero-kicker {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--bs-secondary-color, #6c757d);
}

.tl-xc-hero-value {
  font-size: clamp(1.8rem, 3vw, 2.35rem);
  line-height: 0.95;
  font-weight: 800;
  color: var(--bs-body-color, #111);
}

.tl-xc-hero-note {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--bs-secondary-color, #6c757d);
}

.tl-xc-kpi-column {
  display: contents;
}

.tl-xc-kpi-card,
.tl-xc-legs-card {
  border-radius: 1.05rem;
  border: 1px solid rgba(var(--bs-body-color-rgb, 33, 37, 41), 0.07);
  background: rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.76);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.tl-xc-kpi-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  align-items: center;
  padding: 0.82rem 0.88rem;
  min-height: 0;
}

.tl-xc-kpi-icon,
.tl-xc-legs-icon {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  border-radius: 0.8rem;
  background: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.1);
  color: var(--bs-primary);
  flex: 0 0 auto;
}

.tl-xc-kpi-body,
.tl-xc-legs-body {
  min-width: 0;
}

.tl-xc-kpi-label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bs-secondary-color, #6c757d);
}

.tl-xc-kpi-value {
  font-size: 1rem;
  font-weight: 800;
  color: var(--bs-body-color, #111);
  font-variant-numeric: tabular-nums;
}

.tl-xc-legs-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.72rem;
  align-items: start;
  padding: 0.82rem 0.92rem;
}

.tl-xc-legs-value {
  margin-top: 0.16rem;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--bs-body-color, #111);
}

.tl-xc-kpi-value {
  font-size: clamp(1.02rem, 1.35vw, 1.22rem);
  line-height: 1.08;
  white-space: nowrap;
}

/* ==================================================================
   THE ACTIVITY HEADER STRIP

   Below the app bar, above the map: title, when and who, the sport and its
   numbers, with the reactions opposite. All of it floated over the terrain
   before, which made it depend on whatever tile happened to be underneath
   and left the reactions parked in a corner of a hillside.
   ================================================================== */

.tl-track-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem 1.25rem;
  min-height: 52px;
  padding: 0.55rem clamp(1rem, 2vw, 1.5rem);
  background: var(--tl-panel, #FAF9F4);
  border-bottom: 1px solid var(--tl-hairline, #DFDCCB);
  position: relative;
  z-index: 3;
}

.tl-track-header-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  min-width: 0;
}

.tl-track-header-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--tl-ink, #23281F);
}

.tl-track-header-when {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tl-dim, #8B8F80);
}

.tl-track-header-when a {
  color: var(--tl-accent, #46603C);
  text-decoration: none;
}

/* The four numbers travel in a box so a narrow phone can keep them together.
   Everywhere else the box is not there, and they are chips in the strip. */
.tl-track-figures {
  display: contents;
}

/* The facts, no longer an overlay: a mono run of numbers after a sport chip,
   divided from the identity by a rule rather than by floating apart. */
.tl-track-facts {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.7rem;
  padding-left: 0.9rem;
  border-left: 1px solid var(--tl-hairline, #DFDCCB);
}

.tl-track-facts .tl-track-center-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--tl-font-mono, ui-monospace, monospace);
  font-size: 12px;
  color: var(--tl-muted, #5C6253);
}

.tl-track-facts .tl-track-center-chip i {
  color: var(--tl-dim, #8B8F80);
  font-size: 11px;
}

/* The sport reads as the label it is, not as another number. */
.tl-track-facts .tl-track-center-chip--sport {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--tl-ink, #23281F);
  padding-right: 0.7rem;
  border-right: 1px solid var(--tl-hairline, #DFDCCB);
}

.tl-track-reactions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* The wrapper div only ever holds the button, so the button is the pill and
   the div contributes nothing. The buttons carried btn-outline-light, drawn
   for a dark map: on paper that is white on cream. */
.tl-track-reactions .tl-react {
  display: contents;
}

.tl-track-reactions .tl-react-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--tl-hairline, #DFDCCB);
  background: var(--tl-panel, #FAF9F4);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--tl-ink, #3B4034);
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.tl-track-reactions .tl-react-btn:hover {
  border-color: var(--tl-accent, #46603C);
  color: var(--tl-accent, #46603C);
}

.tl-track-reactions .tl-react-btn[aria-pressed="true"] {
  border-color: var(--tl-accent, #46603C);
  background: color-mix(in srgb, var(--tl-accent, #46603C) 10%, transparent);
  color: var(--tl-accent, #46603C);
}

.tl-track-reactions .tl-count {
  font-family: var(--tl-font-mono, ui-monospace, monospace);
  color: var(--tl-dim, #8B8F80);
}

/* The wrapper is the fan's anchor: on a phone the sheet hangs off it. */
.tl-track-reactions-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* The folded row. Hidden by default; track.js shows it in portrait. */
.tl-track-reactions-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 30px;
  padding: 0 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--tl-hairline, #DFDCCB);
  background: var(--tl-panel, #FAF9F4);
  color: var(--tl-ink, #23281F);
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.tl-track-reactions-toggle.is-active,
.tl-track-reactions-toggle:hover {
  border-color: var(--tl-accent, #46603C);
}

.tl-track-reactions-toggle-count {
  font-family: var(--tl-font-mono, ui-monospace, monospace);
  font-size: 0.72rem;
  color: var(--tl-dim, #8B8F80);
}

/* Below 992px the header wraps and the pills scroll sideways, rather than
   turning one strip into three lines. */
@media (max-width: 991.98px) {
  .tl-track-header { align-items: flex-start; }

  .tl-track-facts { padding-left: 0; border-left: 0; width: 100%; }

  .tl-track-reactions-wrap { width: 100%; min-width: 0; }

  .tl-track-reactions {
    flex-wrap: nowrap;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .tl-track-reactions::-webkit-scrollbar { display: none; }
}

/* ------------------------------------------------------------------
   The fan, on a portrait phone

   Five labelled pills need about 480px. Below that the row lives behind
   the toggle and drops out of the header as a sheet, so the strip stays
   one line and every reaction is still one tap away.
   ------------------------------------------------------------------ */
@media (max-width: 575.98px) and (orientation: portrait) {
  .tl-track-reactions-wrap { width: auto; }

  /*
   * A LONE BUTTON DOES NOT NEED A ROW OF ITS OWN.
   *
   * The header is a wrapping flex row of two boxes: the identity and the
   * reactions. On a phone the identity is wider than the screen whatever it
   * holds, so it always took the whole line and pushed the folded reactions
   * button onto a second one: 30px plus a gap, for one button, out of a
   * header already eating 18% of the viewport.
   *
   * Dropping the identity's own box lets the title, the date, the facts and
   * the button wrap as one flow, so the button lands in the space the last
   * line of facts was leaving empty. The reactions box itself stays, because
   * the folded sheet is positioned against it.
   */
  .tl-track-header-main { display: contents; }

  /* The facts go the same way, or they stay one two-line box and the button
   * still has nowhere to sit. The rule that divides them from the title is
   * for a header that reads left to right; this one reads as a paragraph. */
  .tl-track-facts {
    display: contents;
  }

  /* The sport carries a right border to divide it from the numbers, which
     reads as a divider only while they are one horizontal strip. Wrapped, the
     sport ends a line and the border becomes a hairline hanging off it. */
  .tl-track-facts .tl-track-center-chip--sport {
    padding-right: 0;
    border-right: 0;
  }

  /* A line of their own, all four of them, never split. Tighter gaps than the
     header's because at 320px the four need every pixel of it. */
  .tl-track-figures {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
  }

  /*
   * AND THE BUTTON STOPS PUSHING THEM ABOUT.
   *
   * In the flow it lands after the numbers, so on a narrow phone it took a
   * fourth line for itself or shunted the last number onto one. It is one
   * small control that belongs beside the title, so it goes there and out of
   * the flow, and the title keeps clear of it.
   */
  .tl-track-reactions-wrap {
    position: absolute;
    top: 0.4rem;
    right: clamp(0.8rem, 2vw, 1.5rem);
  }

  /* Clear of the button, and a size that lets a long title stay on one line
     beside it at the widths most phones actually are. */
  .tl-track-header-title {
    font-size: 17px;
    padding-right: 2.9rem;
  }

  /* One flow now, so the header's own gaps are the only ones, and they are
   * the gaps between facts rather than between blocks. */
  .tl-track-header {
    gap: 0.3rem 0.7rem;
    padding: 0.4rem clamp(0.8rem, 2vw, 1.5rem);
    /* space-between exists to push the reactions to the far end on a wide
       header. Here they are out of the flow, so all it does is stretch every
       wrapped line and open a hole between the athlete and the country. */
    justify-content: flex-start;
  }

  /* The toggle no longer has a line of its own: it sits at the end of the
     last row of facts, hard against the right edge. So the sheet hangs from
     that edge and opens leftward. Opening rightward from there put 358px of
     sheet on a 390px screen starting at x=340, which is most of it off the
     side. */
  .tl-track-reactions.is-clustered {
    position: absolute;
    z-index: 12;
    top: calc(100% + 0.5rem);
    left: auto;
    right: 0;
    width: max-content;
    max-width: calc(100vw - 2rem);
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0.35rem;
    padding: 0.6rem;
    border-radius: 12px;
    border: 1px solid var(--tl-hairline, #DFDCCB);
    background: var(--tl-panel, #FAF9F4);
    box-shadow: 0 18px 34px -18px rgba(35, 40, 31, 0.5);
    overflow: visible;
    pointer-events: none;
    opacity: 0;
    transform: translate3d(0, -6px, 0);
    transition: opacity 0.18s ease, transform 0.18s ease;
  }

  .tl-track-reactions.is-clustered.is-open {
    pointer-events: auto;
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tl-track-reactions.is-clustered { transition: none; }
}

/* ==================================================================
   THE FOUR PANELS

   Track statistics, competition, comments and buddies. Each opened as a
   modal-xl with a dimming backdrop over the map, which is the subject
   every one of them is describing: you could read that an activity
   climbed 1 284 m, but not while looking at where.

   They are floating cards beside the rail now. The modal element still
   covers the viewport, because that is how Bootstrap positions and traps
   focus, but it does not take pointer events: only the card does, so the
   map behind stays draggable while a panel is open.
   ================================================================== */

.tl-track-panel {
  pointer-events: none;
}

.tl-track-panel .modal-dialog {
  pointer-events: auto;
  margin: 0;
  position: absolute;
  left: calc(var(--tl-rail-w, 64px) + var(--tl-card-gap, 0.85rem));
  /*
   * BELOW THE BASE MAP SWITCH, not on top of it.
   *
   * The switch sits at the top left of the map, which is where this opened:
   * a panel covered it completely, so changing to Satellite with the
   * statistics open meant closing them first. Its height is a token in
   * map-controls.css, declared where the control is, so this cannot drift.
   */
  top: calc(var(--tl-track-top-offset, 0px) + var(--tl-card-gap, 0.85rem)
            + var(--tl-mapstyle-h, 38px) + var(--tl-card-gap, 0.85rem));
  /* 372px had "Grade-adjusted pace 8:20 /km" ending hard against the right
     edge with the unit half off it. The panel sits over a map that is 1400px
     wide on a laptop; forty more pixels cost nothing and stop every two-column
     metric row from touching its own edge. */
  width: 412px;
  max-width: calc(100vw - 64px - 2.5rem);
  max-height: calc(100vh - var(--tl-track-top-offset, 0px)
                   - var(--tl-mapstyle-h, 38px) - var(--tl-card-gap, 0.85rem) * 3);
  max-height: calc(100svh - var(--tl-track-top-offset, 0px)
                   - var(--tl-mapstyle-h, 38px) - 3.4rem);
}

/* Comments and buddies are lists that want the room; statistics and the
   competition panel are read at a glance. */
/*
   An id beats two classes, so this width used to survive the phone reset
   below and the comments panel stayed 420px wide inside a 390px viewport:
   the editor toolbar, the box and the Send button all ran off the right of
   the screen. Declared only where a floating card makes sense, so there is
   nothing for the phone to undo.
*/
@media (min-width: 576px) {
.tl-track-panel#trackCommentsModal .modal-dialog,
.tl-track-panel#trackBuddiesModal .modal-dialog {
  width: 420px;
}
}

.tl-track-panel .modal-content {
  border: 1px solid var(--tl-hairline, #DFDCCB);
  border-radius: var(--tl-card-radius, 14px);
  background: color-mix(in srgb, var(--tl-panel, #FAF9F4) 97%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 24px 48px -24px rgba(35, 40, 31, 0.45);
  max-height: inherit;
}

.tl-track-panel .modal-header {
  padding: 0.85rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--tl-hairline, #DFDCCB);
}

.tl-track-panel .modal-title {
  font-family: var(--tl-font-display, 'Bricolage Grotesque', system-ui, sans-serif);
  font-size: 1rem;
  font-weight: 700;
  color: var(--tl-ink, #23281F);
}

.tl-track-panel .modal-title i {
  color: var(--tl-accent, #46603C);
  font-size: 0.9rem;
}

/* Bootstrap's close is a background-image X that no theme reaches. A bordered
   square with a real glyph matches the mockup and follows the night face. */
.tl-track-panel .btn-close {
  --bs-btn-close-bg: none;
  width: 26px;
  height: 26px;
  padding: 0;
  opacity: 1;
  border: 1px solid var(--tl-hairline, #DFDCCB);
  border-radius: 6px;
  background: none;
  color: var(--tl-muted, #5C6253);
  position: relative;
}

.tl-track-panel .btn-close::before {
  content: '\00d7';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  line-height: 1;
}

.tl-track-panel .btn-close:hover {
  border-color: var(--tl-accent, #46603C);
  color: var(--tl-accent, #46603C);
}

.tl-track-panel .modal-body {
  padding: 0.9rem 1.25rem 1.1rem;
}

/*
 * ON A PHONE THE PANELS RISE FROM THE BOTTOM AND STOP.
 *
 * They used to be full screen, which is Bootstrap's own answer and the wrong
 * one here: a panel that fills the phone hides the track it is describing, so
 * the only way to look at both is to close it and open it again. The planner's
 * cards come up to a set height over a map that stays visible, and that reads
 * better, so these do the same.
 *
 * modal-fullscreen-sm-down came off the dialogs to make it possible: it sets
 * height:100% on the content, and fighting that with overrides would leave two
 * rules arguing about the same box. modal-dialog-scrollable is still there and
 * is what makes the body scroll once the sheet has hit its height.
 */
@media (max-width: 575.98px) {
  .tl-track-panel .modal-dialog {
    position: absolute;
    top: auto;
    left: 0;
    right: 0;
    /*
     * ABOVE THE BAR, NOT OVER IT.
     *
     * It sat at the bottom of the window and covered the rail, so the only
     * way to read a different panel was to close this one first. The planner
     * stops at its bar and you can go straight from one card to the next; the
     * height comes from tl-ui.css so neither page can drift.
     */
    bottom: calc(var(--tl-rail-h, 0px) + env(safe-area-inset-bottom, 0px));
    margin: 0;
    width: auto;
    max-width: none;
    /*
     * As tall as what is in it, up to the sheet height.
     *
     * modal-dialog-scrollable gives the dialog an explicit height so its body
     * has something to scroll inside, and here that made every sheet the full
     * 58% whatever it held: Comments is 365px of content and sat at the top of
     * a 490px box with a gap under it, floating above the bar instead of
     * resting on it. Height comes from the content again, and the cap does the
     * work the fixed height was doing.
     */
    height: auto;
    max-height: var(--tl-sheet-h, 58svh);
  }

  .tl-track-panel .modal-content {
    max-height: var(--tl-sheet-h, 58svh);
    border: 0;
    /* Rounded at the top, flat where it meets the bar. */
    border-radius: var(--tl-card-radius, 14px) var(--tl-card-radius, 14px) 0 0;
    box-shadow: 0 -18px 44px -20px rgba(15, 23, 42, 0.5);
  }
}

.tl-track-download {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--tl-accent, #46603C);
  text-decoration: none;
  white-space: nowrap;
}

.tl-track-download:hover {
  color: var(--tl-accent-hover, #2E4228);
  text-decoration: underline;
}

.tl-track-download i {
  font-size: 0.72rem;
}

/* ------------------------------------------------------------------
   The numbers, at panel width

   The tiles were sized for a modal-xl: minmax(12rem) on an auto-fit grid,
   which inside a 372px card resolves to exactly one column, so every
   metric became a full-width block and the panel ran metres long. The
   three that lead it go three across, the way the mockup draws them, and
   the sport's own list drops the tile chrome and becomes a two-column
   label/value run, which is what a list of eight numbers wants to be.
   ------------------------------------------------------------------ */

.tl-track-panel .tl-stat-sections {
  gap: 0.9rem;
}

.tl-track-panel .tl-stat-section {
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}

.tl-track-panel .tl-stat-section-head {
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.tl-track-panel .tl-stat-section-icon {
  display: none;
}

.tl-track-panel .tl-stat-section-title {
  font-size: 0.86rem;
}

.tl-track-panel .tl-stat-grid-core {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}

.tl-track-panel .tl-stat-grid-core .tl-stat-tile {
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: 8px;
  background: var(--tl-paper, #F3F2EC);
}

.tl-track-panel .tl-stat-grid-core .tl-stat-tile::before {
  display: none;
}

.tl-track-panel .tl-stat-grid-core .tl-stat-tile-value {
  font-family: var(--tl-font-display, 'Bricolage Grotesque', system-ui, sans-serif);
  font-size: 1rem;
}

/* The per-sport run: rows, not tiles. Two columns while they fit. */
/*
   ONE COLUMN, NOT TWO.

   Two columns gave each label/value pair about 115px of a 412px panel, and
   "Grade-adjusted pace" alone is 116px. Everything after that was an attempt
   to squeeze it in: shrink the label, wrap it, clip the row, widen the panel.
   All of it treats a full sentence in a 115px box as a rendering problem.

   The pair is a row: label on the left, figure on the right, the panel's full
   width between them. Nothing needs to shrink, nothing wraps, and the section
   now reads the same way the Surface list below it does.
*/
@media (max-width: 575.98px) {
  .tl-track-panel .tl-stat-grid-core {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ==================================================================
   THE ACTIVITY PANEL, IN TERRALOC'S OWN VOCABULARY

   What was here was the fork's: Bootstrap's generic tokens with a TerraLoc
   palette bolted over the top, and stat tiles that cycled through four
   hard-coded accent colours (Bootstrap blue, #20c997 teal, #f59f00 amber,
   #e64980 pink) by :nth-child. Four colours that appear nowhere in
   terraloc-theme.css, assigned by position rather than by meaning, so the
   same metric changed colour depending on how many sat before it.

   This uses the theme's own layer: paper and panel grounds, hairline rules,
   PlexMono kickers, and ONE accent per section which is the sport's own
   colour, set inline from the registry and inherited through currentColor.
   Distance is not teal because it happens to be second in the list.
   ================================================================== */

.tl-track-stats-card {
  background: var(--tl-panel, #fff);
  border: 1px solid var(--tl-hairline, rgba(0, 0, 0, 0.1));
  border-radius: 1.25rem;
}

/* The glow was a blurred blue blob behind the panel header, from a dark
   product. On paper it is a smudge. */
.tl-track-stats-glow {
  display: none;
}

.tl-track-modal-stack {
  display: grid;
  gap: 1rem;
}

.card-elev {
  box-shadow: 0 0.3rem 0.9rem rgba(0, 0, 0, 0.05);
  background: var(--bs-body-bg);
}

.pill .long,
.pill .sep {
  display: none;
}

.btn-check:checked + .pill .long,
.btn-check:checked + .pill .sep,
.pill:focus-visible .long,
.pill:focus-visible .sep {
  display: inline;
}

.tl-xc-pills .btn:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: 2px;
}

/* ==================================================================
   THE PLAYBACK POPUP

   It was a blue glass panel: a rgba(19,102,225) gradient, a translucent
   white hairline and a blue drop shadow, with five rows of instrument
   shorthand in it. Sky colours on a sky product.

   TerraLoc's is paper: the panel ground, a hairline, ink text, a mono label
   column, and one line of the SPORT's colour along the top edge, set from
   --tl-popup-accent by the marker so a bike replay and a hike replay are
   told apart at a glance.
   ================================================================== */

.track-tip {
  --tl-popup-accent: var(--tl-accent, #46603C);
}

.track-tip .maplibregl-popup-content {
  position: relative;
  background: var(--tl-panel, #fff);
  color: var(--tl-ink, #23281F);
  border: 1px solid var(--tl-hairline, rgba(0, 0, 0, 0.12));
  border-radius: 0.8rem;
  padding: 0.5rem 0.65rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05), 0 10px 24px rgba(0, 0, 0, 0.10);
  overflow: hidden;
}

/* The sport's colour, as a rule across the top rather than a whole tinted
   panel: the numbers have to stay the most legible thing on the map. */
.track-tip .maplibregl-popup-content::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--tl-popup-accent);
}

.track-tip .maplibregl-popup-close-button {
  color: var(--tl-dim, #8B8F80);
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  border-radius: 0.35rem;
}

.track-tip .maplibregl-popup-close-button:hover {
  background: color-mix(in srgb, var(--tl-ink, #23281F) 8%, transparent);
  color: var(--tl-ink, #23281F);
}

.track-tip .maplibregl-popup-close-button:focus-visible {
  outline: 2px solid var(--tl-popup-accent);
  outline-offset: 1px;
}

/* The tip is a CSS triangle, so its colour lives on whichever border faces
   the anchor and all four have to be named. */
.track-tip.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.track-tip.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.track-tip.maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
  border-bottom-color: var(--tl-popup-accent);
}

.track-tip.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.track-tip.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.track-tip.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
  border-top-color: var(--tl-panel, #fff);
}

.track-tip.maplibregl-popup-anchor-left .maplibregl-popup-tip {
  border-right-color: var(--tl-panel, #fff);
}

.track-tip.maplibregl-popup-anchor-right .maplibregl-popup-tip {
  border-left-color: var(--tl-panel, #fff);
}

.track-tip .tl-popup {
  display: grid;
  gap: 0.15rem;
  min-width: 9.5rem;
  font-variant-numeric: tabular-nums;
}

.track-tip .tl-popup-time {
  font-family: var(--tl-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--tl-muted, #5C6253);
  padding-bottom: 0.3rem;
  margin-bottom: 0.15rem;
  border-bottom: 1px solid var(--tl-hairline, rgba(0, 0, 0, 0.1));
}

.track-tip .tl-popup-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: 0.75rem;
}

.track-tip .tl-popup-label {
  font-family: var(--tl-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tl-dim, #8B8F80);
}

.track-tip .tl-popup-value {
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  color: var(--tl-ink, #23281F);
}

#tl-reactions .tl-react [aria-pressed="true"] {
  background-color: var(--bs-success-bg-subtle);
  color: var(--bs-success-text);
  border-color: var(--bs-success);
}

#tl-reactions .tl-count.tl-tick {
  animation: tl-tick 0.4s ease;
}

@keyframes tl-tick {
  0% {
    transform: translateY(-4px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* The panel already has a height and scrolls; a second scroller inside it
   cut the list off at four rows with the map still visible below. */
.tl-buddies-scroll {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: min(52vh, 420px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.tl-track-buddies-preview {
  --tl-track-buddies-left: 4.5rem;
  --tl-track-buddies-top: 10rem;
  left: var(--tl-track-buddies-left);
  top: var(--tl-track-buddies-top);
  z-index: 7;
  display: flex;
  align-items: flex-end;
  gap: 0.42rem;
  opacity: 0;
  pointer-events: none;
  transform: translate3d(0, 8px, 0) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tl-track-buddies-preview.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translate3d(0, 0, 0) scale(1);
}

.tl-track-buddy-chip {
  position: relative;
  display: block;
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--bs-body-color, #111);
  text-align: left;
}

.tl-track-buddy-avatar,
.tl-buddy-avatar {
  width: 4rem;
  height: 4rem;
  display: grid;
  place-items: center;
  border-radius: 1rem;
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--tl-buddy-color, var(--bs-primary)) 62%, white);
  background: color-mix(in srgb, var(--tl-buddy-color, var(--bs-primary)) 12%, rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.96));
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.12);
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--bs-body-color, #111);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.tl-track-buddy-avatar img,
.tl-buddy-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tl-track-buddy-name {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.45rem);
  transform: translate(-50%, 0.25rem);
  max-width: 8rem;
  padding: 0.28rem 0.55rem;
  border-radius: 0.65rem;
  background: rgba(33, 37, 41, 0.86);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tl-track-buddy-dot,
.tl-buddy-row-color {
  width: 0.58rem;
  height: 0.58rem;
  border-radius: 999px;
  background: var(--tl-buddy-color, var(--bs-primary));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tl-buddy-color, var(--bs-primary)) 18%, transparent);
}

.tl-track-buddy-dot {
  display: none;
}

.tl-track-buddy-chip:hover .tl-track-buddy-avatar,
.tl-track-buddy-chip:focus-visible .tl-track-buddy-avatar,
.tl-track-buddy-chip.is-selected .tl-track-buddy-avatar {
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.18);
}

.tl-track-buddy-chip:hover .tl-track-buddy-name,
.tl-track-buddy-chip:focus-visible .tl-track-buddy-name {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tl-track-buddy-chip:nth-of-type(1) .tl-track-buddy-avatar {
  transform: rotate(-13deg) translateY(0.25rem);
}

.tl-track-buddy-chip:nth-of-type(2) .tl-track-buddy-avatar {
  transform: rotate(-6deg) translateY(0.1rem);
}

.tl-track-buddy-chip:nth-of-type(3) .tl-track-buddy-avatar {
  transform: rotate(0deg);
}

.tl-track-buddy-chip:nth-of-type(4) .tl-track-buddy-avatar {
  transform: rotate(7deg) translateY(0.1rem);
}

.tl-track-buddy-chip:nth-of-type(5) .tl-track-buddy-avatar {
  transform: rotate(13deg) translateY(0.25rem);
}

.tl-buddy-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--tl-hairline, #DFDCCB);
  border-radius: 10px;
  background: var(--tl-paper, #F3F2EC);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.tl-buddy-row:hover {
  border-color: var(--tl-accent, #46603C);
}

/* A ticked buddy is drawn on the map, so the row wears the same edge the
   selected athlete in the live list does. */
.tl-buddy-row:has(input:checked) {
  border-color: var(--tl-accent, #46603C);
  background: var(--tl-panel, #FAF9F4);
}

.tl-buddy-row-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1 1 auto;
}

/* In a 372px panel the 4rem tile is most of the row. The swatch on the right
   is what says which colour this buddy's line is drawn in, so the avatar can
   go back to being a face. */
.tl-buddy-row .tl-buddy-avatar {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border-width: 1px;
  font-size: 0.7rem;
}

.tl-buddy-row-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.tl-buddy-row-name {
  display: block;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.2;
  color: var(--tl-ink, #23281F);
}

/* Why this buddy is on the list: same outing, or the same line on another
   day, then the sport and the distance. */
.tl-buddy-row-sub {
  display: block;
  margin-top: 2px;
  font-family: var(--tl-font-mono, ui-monospace, monospace);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tl-dim, #8B8F80);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-buddies-empty {
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--tl-muted, #5C6253);
}

.tl-buddies-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.tl-buddies-foot .tl-btn-sm {
  height: 28px;
  padding: 0 0.7rem;
  font-size: 0.75rem;
}

.tl-buddies-overlaid {
  margin-left: auto;
  text-align: right;
}

@media (max-width: 991.98px) {
  .tl-xc-summary {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 767.98px) {
  :root {
    --tl-track-graph-h: clamp(78px, 9.5vh, 100px);
  }

  /* The rail turns into a bottom bar here. That lives on .tl-rail in
     tl-ui.css, because the planner needs the same behaviour and this page
     having its own copy is what made it a private rule in the first place. */

  .tl-track-title {
    font-size: 1rem;
  }

  .tl-track-meta-list {
    gap: 0.32rem 0.6rem;
    font-size: 0.72rem;
  }

  .tl-track-reactions {
    gap: 0.3rem;
  }

  .tl-track-reactions .tl-icon {
    font-size: 0.86rem;
  }

  /*
   * THE MAP OVERLAYS SPAN THE MAP WHEN THE RAIL IS A BAR.
   *
   * The photograph fan and the buddies fan each hang off their own rail
   * button: to the right of it, level with it. Once the rail moved along the
   * bottom both landed in the bottom right corner of the map, and an
   * absolutely positioned flex row with only a left edge is shrink-to-fit,
   * so the photographs had 89px of a 390px screen and five of them were
   * squeezed into the width of one. Both edges are given here so the row has
   * a width to centre inside, and they rest on the playback dock, whose top
   * track.js and track-buddies.js measure into the bottom.
   */
  .tl-track-photo-fan,
  .tl-track-buddies-preview {
    left: 0.75rem;
    right: 0.75rem;
    top: auto;
    bottom: var(--tl-track-overlay-bottom, 9rem);
    justify-content: center;
  }

  /* And nothing shrinks them again if a row ever does run out of room: a
     narrower thumbnail is not a smaller fan, it is a broken one. */
  .tl-track-photo-fan .gallery-image,
  .tl-track-buddy-chip {
    flex: 0 0 auto;
  }

  .tl-track-photo-fan .gallery-image {
    width: 3.55rem;
    height: 3.55rem;
    border-radius: 0.9rem;
  }

  .tl-track-buddies-preview { gap: 0.34rem; }

  .tl-track-buddy-avatar { width: 3.45rem; height: 3.45rem; }

  .tl-stat-grid,
.tl-stat-grid-core,
.tl-stat-grid-style,
.tl-stat-grid-daylight,
.tl-xc-kpi-column {
    grid-template-columns: 1fr;
  }

  .tl-xc-hero-card {
    min-height: auto;
    padding: 1rem 1.05rem;
  }

  .tl-xc-kpi-card,
.tl-xc-legs-card,
.tl-stat-tile,
.tl-stat-section {
    padding: 0.88rem 0.92rem;
  }

  .tl-track-stats-header {
    margin-bottom: 0.85rem;
  }

  .tl-track-stats-glow {
    width: 3.6rem;
    height: 3.6rem;
  }

  .tl-stat-tile-wide {
    grid-column: auto;
  }

}

@media (max-width: 575.98px) {
  :root {
    --tl-track-graph-h: clamp(72px, 9vh, 92px);
  }

  .tl-track-photo-fan {
    gap: 0.3rem;
  }

  .tl-track-photo-fan .gallery-image {
    width: 3.05rem;
    height: 3.05rem;
    border-radius: 0.8rem;
  }

  .tl-track-buddies-preview { gap: 0.26rem; }

  /*
   * THE NAME, NOT THE FACE.
   *
   * .tl-track-buddy-avatar was in this selector list, with a blank line
   * between it and the comma's other half, which reads as its own rule and
   * is not one. A buddy chip is an avatar and a name that appears over it on
   * hover, so hiding both left an empty button: the preview opened at zero
   * by zero and the rail's Buddies button looked dead on every phone. The
   * name goes, because a phone has no hover to show it with.
   */
  .tl-track-buddy-name { display: none; }

  .tl-xc-topbar,
  .tl-track-stats-header {
    gap: 0.7rem;
  }

  .tl-xc-hero-value {
    font-size: 1.9rem;
  }

  .tl-xc-badge-cloud > * {
    padding: 0.36rem 0.68rem;
  }

  .tl-stat-tile-icon,
  .tl-xc-kpi-icon,
  .tl-xc-legs-icon {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 0.8rem;
  }
}

/*
   ONE CARD, NOT TWO.

   In light the stats card carries the surface (--tl-paper) and the sections
   inside it are transparent: the panel reads as one card with kickers and
   hairlines dividing it. Dark had the card on a Bootstrap grey that belongs
   to no TerraLoc token, and I then gave the sections a paper background of
   their own, so every section became a second card cut into the first.

   The card takes the same token light gives it. The sections stay
   transparent, which they already are, and there is nothing dark-specific
   left for them.
*/
[data-bs-theme="dark"] .tl-track-stats-card {
  background: var(--tl-paper, #15150F);
  border-color: var(--tl-hairline, #2F2F26);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
}

[data-bs-theme="dark"] .tl-track-dock,
[data-bs-theme="dark"] .tl-xc-card {
  background: rgba(var(--bs-secondary-bg-rgb, 33, 37, 41), 0.86);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
}

[data-bs-theme="dark"] .tl-track-transport-speed button {
  background: rgba(var(--bs-secondary-bg-rgb, 33, 37, 41), 0.9);
  border-color: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.92);
}

[data-bs-theme="dark"] .tl-track-clock {
  color: rgba(255, 255, 255, 0.92);
}
[data-bs-theme="dark"] .tl-track-center-chip {
  color: rgba(255, 255, 255, 0.76);
}
/*
   THE DARK FACE MIRRORS THE LIGHT ONE, IT DOES NOT INVENT A SECOND ONE.

   These read --bs-tertiary-bg at 0.88 and 0.82: two near-blacks that came out
   DARKER than the panel they sit on, so the stats panel became a stack of
   holes cut into a grey card, one nested inside the next. In light the same
   elements are --tl-paper on --tl-panel, a single step lighter, and the theme
   has dark values for both. Using them makes the two faces the same design
   rather than two designs that happen to share markup.
*/
[data-bs-theme="dark"] .tl-xc-kpi-card,
[data-bs-theme="dark"] .tl-xc-legs-card,
[data-bs-theme="dark"] .tl-buddy-row,
[data-bs-theme="dark"] .tl-xc-badge-cloud > *,
[data-bs-theme="dark"] #xcPills .pill {
  background: rgba(var(--bs-tertiary-bg-rgb, 52, 58, 64), 0.82);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .tl-xc-kpi-icon,
[data-bs-theme="dark"] .tl-xc-legs-icon,
[data-bs-theme="dark"] .tl-track-buddy-avatar,
[data-bs-theme="dark"] .tl-buddy-avatar {
  background: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.18);
}

[data-bs-theme="dark"] .tl-track-buddies-preview {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

[data-bs-theme="dark"] .tl-track-buddy-avatar,
[data-bs-theme="dark"] .tl-buddy-avatar {
  background: color-mix(in srgb, var(--tl-buddy-color, var(--bs-primary)) 18%, rgba(var(--bs-secondary-bg-rgb, 33, 37, 41), 0.96));
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .tl-track-buddy-name {
  background: rgba(14, 16, 20, 0.92);
  color: rgba(255, 255, 255, 0.96);
}

[data-bs-theme="dark"] .tl-track-meta-list a:hover {
  color: var(--bs-info);
}
/* The dock on small screens: the profile keeps the middle, the two toggles
   and the footer line drop out. A 300px-wide card cannot hold nine things. */
@media (max-width: 767.98px) {
  :root {
    --tl-track-chart-h: clamp(140px, 30vh, 190px);
  }

  .tl-track-dock {
    left: 0.75rem;
    right: 0.75rem;
    gap: 0.35rem;
    padding: 0.45rem 0.6rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  }

  /*
     The dock is one row of transport, readout and buttons, and on a phone it
     does not fit: the mode icons ended at 444px and the Profile button at
     510px of a 390px screen, both off the side. It wraps here, and the
     readout takes the rest of the first line so the buttons drop cleanly
     rather than one at a time.
  */
  .tl-track-dock-row {
    gap: 0.45rem;
    flex-wrap: wrap;
    row-gap: 0.4rem;
  }

  /*
   * AND THE PROFILE TAKES A LINE OF ITS OWN, the way it does when it opens.
   *
   * Wrapping alone left it as a strip between the transport and the clock,
   * and on a 390px phone that strip is 86px: a 5.8km day drawn in a
   * thumb-width, next to a button that offers to make it bigger. It is the
   * shape of the day on every sport here, so it gets the dock's width, and
   * the controls read as the two groups they are underneath it: transport on
   * one line, what the line is drawn in on the next.
   *
   * Same three declarations as the .tl-chart-open rule further up, so
   * opening the profile changes its height and nothing else moves.
   */
  .tl-track-profile {
    order: -1;
    flex: 1 1 100%;
    width: 100%;
  }

  .tl-track-clock {
    margin-left: auto;
  }

  .tl-track-map-wrap.tl-chart-open .tl-track-clock {
    margin-left: auto;
  }

  .tl-track-dock-foot .tl-track-dock-edge {
    display: none;
  }

  /* Two of the three lines in the foot are the edges, hidden above. What is
     left is the timezone and the window, which has nowhere to wrap to. */
  .tl-track-dock-when {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tl-track-alt {
    display: none;
  }

  .tl-track-clock {
    min-width: 4.4rem;
    font-size: 0.76rem;
  }

  .tl-track-play-btn {
    width: 2.25rem;
    height: 2.25rem;
  }

}

/* Icon-only, because three words in the dock cost more room than the control
   is worth. The word is still on the button as its title and its label. */
/* ------------------------------------------------------------------
   The athlete, as one of the panel's sections
   ------------------------------------------------------------------ */
.tl-track-athlete-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--tl-hairline, #DFDCCB);
  flex: 0 0 auto;
}

.tl-track-athlete-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.tl-track-athlete-flag {
  font-size: 1.15rem;
  line-height: 1;
  flex: 0 0 auto;
}

.tl-track-athlete-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.8rem;
  font-size: 0.78rem;
  color: var(--tl-muted, #5C6253);
}

/* ==================================================================
   THE LEGS EDITOR

   The owner's panel for putting right what the recording got wrong. One row
   per leg in its sport's colour, a join between each pair, and underneath
   them what the playhead is on and the two things that can be done there.

   The row takes its sport colour as currentColor, set inline by the
   renderer, the same way the leg sections in the statistics panel do, so a
   sport colours its own row without a rule per sport. Text sets its own
   colour so the row does not turn into green prose.
   ================================================================== */

.tl-legs {
  display: grid;
  gap: 0.85rem;
}

.tl-legs-help {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--tl-muted, #5C6253);
}

.tl-legs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
}

/* The kicker line runs the full width so Remove can sit at its end; the
   facts and the sport picker share the line under it. */
.tl-legs-row {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(6rem, 7.6rem);
  grid-template-areas:
    "icon top   top"
    "icon facts sport";
  gap: 0.25rem 0.65rem;
  align-items: center;
  padding: 0.55rem 0.6rem 0.55rem 0.95rem;
  border-radius: 0.85rem;
  background: var(--tl-white, #FFFFFF);
  border: 1px solid var(--tl-hairline, #DFDCCB);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* The sport's hairline down the left edge, as on a stat tile. */
.tl-legs-row::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 0.22rem;
  background: currentColor;
}

/* The leg the playhead is on. */
.tl-legs-row.is-here {
  border-color: color-mix(in srgb, currentColor 55%, var(--tl-hairline, #DFDCCB));
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 14%, transparent);
}

.tl-legs-icon {
  grid-area: icon;
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  border-radius: 0.7rem;
  background: color-mix(in srgb, currentColor 13%, transparent);
}

.tl-legs-icon svg {
  display: block;
}

.tl-legs-row-top {
  grid-area: top;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.15rem 0.5rem;
  min-height: 1.1rem;
}

.tl-legs-row-top .tl-stat-kicker {
  margin: 0;
}

/* Where the leg's sport came from. Quiet, except when nobody said. */
.tl-legs-flag {
  font-family: var(--tl-font-mono, ui-monospace, monospace);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--tl-dim, #8B8F80);
}

.tl-legs-flag.is-manual {
  color: var(--tl-accent, #46603C);
}

.tl-legs-flag.is-assumed {
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--tl-warning-bg, #F4E1D6);
  color: var(--tl-warning, #9C4A1B);
}

.tl-legs .tl-legs-sport {
  grid-area: sport;
  height: 34px;
  min-width: 0;
  padding: 0 1.8rem 0 0.6rem;
  background-position: right 0.5rem center;
  border-radius: 8px;
  border: 1px solid var(--tl-hairline-strong, #C9C5B2);
  background-color: var(--tl-panel, #FAF9F4);
  color: var(--tl-ink, #23281F);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 32px;
}

.tl-legs .tl-legs-sport:focus {
  border-color: var(--tl-accent, #46603C);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tl-accent, #46603C) 18%, transparent);
  outline: none;
}

/* Quiet until pressed once, then it asks. A second press removes. */
.tl-legs-remove {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: 22px;
  padding: 0 0.45rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--tl-dim, #8B8F80);
  cursor: pointer;
  white-space: nowrap;
}

.tl-legs-remove i {
  font-size: 0.68rem;
}

.tl-legs-remove:hover,
.tl-legs-remove:focus-visible {
  color: var(--tl-danger, #A32219);
  outline: none;
  border-color: color-mix(in srgb, var(--tl-danger, #A32219) 35%, transparent);
}

.tl-legs-remove.is-armed {
  border-color: var(--tl-danger, #A32219);
  background: var(--tl-danger-bg, #F5DCD9);
  color: var(--tl-danger, #A32219);
}

.tl-legs-remove:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Wraps between facts, never inside one: "312 m" does not break. */
.tl-legs-fact {
  white-space: nowrap;
}

.tl-legs-facts {
  grid-area: facts;
  font-size: 0.72rem;
  color: var(--tl-muted, #5C6253);
  font-variant-numeric: tabular-nums;
}

/* ---- a join between two legs ---- */

.tl-legs-join {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.4rem;
  padding: 0.3rem 0 0.3rem 2.7rem;
  color: var(--tl-muted, #5C6253);
}

/* The seam: a dashed rule under the centre of the sport icons, where one leg
   hands over to the next. 0.95rem of row padding plus half the icon. */
.tl-legs-join::before {
  content: "";
  position: absolute;
  left: calc(0.95rem + 1.05rem - 1px);
  top: 0;
  bottom: 0;
  border-left: 2px dashed var(--tl-hairline-strong, #C9C5B2);
}

.tl-legs-join-at {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.tl-legs .tl-legs-merge {
  margin-left: auto;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

/* The join "Move the nearest join here" would move. */
.tl-legs-join.is-target {
  color: var(--tl-ink, #23281F);
}

.tl-legs-join.is-target::before {
  border-left-color: var(--tl-accent, #46603C);
}

.tl-legs-join.is-target .tl-lbl {
  color: var(--tl-accent, #46603C);
}

/* ---- at the playhead ---- */

.tl-legs-at {
  display: grid;
  gap: 0.5rem;
  padding: 0.8rem 0.85rem 0.85rem;
  border-radius: 0.85rem;
  background: var(--tl-paper, #F3F2EC);
  border: 1px solid var(--tl-hairline, #DFDCCB);
}

.tl-legs-readout {
  min-height: 1.2rem;
  font-size: 0.8rem;
  color: var(--tl-ink, #23281F);
  font-variant-numeric: tabular-nums;
}

.tl-legs-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tl-legs-actions .tl-btn {
  flex: 1 1 10rem;
  justify-content: center;
}

.tl-legs .tl-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  border-color: var(--tl-hairline-strong, #C9C5B2);
  color: var(--tl-ink, #3B4034);
}

/* Deletes track, so it arms like remove does: a first press asks, with the
   distance, and only a second one cuts. */
.tl-legs-cut-btn.is-armed,
.tl-legs-cut-btn.is-armed:hover {
  border-color: var(--tl-danger, #A32219);
  background: var(--tl-danger-bg, #F5DCD9);
  color: var(--tl-danger, #A32219);
}

.tl-legs-why,
.tl-legs-status {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--tl-muted, #5C6253);
}

.tl-legs-status.is-error {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: var(--tl-danger-bg, #F5DCD9);
  color: var(--tl-danger, #A32219);
}

.tl-legs.is-busy .tl-legs-list {
  opacity: 0.6;
}

/*
 * On a phone this sheet stops above the profile, not above the rail: it is
 * used by dragging the playhead on the profile, so covering it would leave
 * nothing to drag.
 *
 * --tl-legs-dock-h is how far up from the bottom of the window the top of the
 * dock is, measured in track-legs.js when the panel opens. The rail bar, the
 * dock and the gap the dock floats above are all in that one number, so this
 * adds nothing to it. Summing them here got the gap wrong and the sheet came
 * down over the first 15px of the profile.
 *
 * AND IT STOPS WHERE THE OTHERS DO.
 *
 * Standing on the dock rather than on the rail, it was still allowed the full
 * 58svh, so it reached the dock's whole height higher than every other sheet:
 * a top edge 127px above the statistics panel's, over the base map switch the
 * desktop rule goes out of its way to stay under, and no map left behind it.
 * Taking the dock off the height as well as off the bottom lands the top edge
 * level with Comments and Track statistics, and the panel scrolls for the
 * rest.
 *
 * The floor is only a stop against a dock taller than this page can build,
 * and it is deliberately low: every pixel of floor above the height the sum
 * asks for is a pixel the sheet climbs back over the map. With the profile
 * open, the tallest the dock gets, the sum still comes to about 196px.
 */
@media (max-width: 575.98px) {
  #trackLegsModal .modal-dialog {
    bottom: calc(var(--tl-legs-dock-h, 12rem) + 0.5rem);
    max-height: max(8rem, calc(var(--tl-sheet-h, 58svh) + var(--tl-rail-h, 0px)
                               - var(--tl-legs-dock-h, 12rem) - 0.5rem));
  }

  #trackLegsModal .modal-content {
    max-height: inherit;
  }
}
