:root {
  color-scheme: dark;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f6f5e9;
  background: #141914;
  --text: #f6f5e9;
  --muted: #cbcebe;
  --lime: #e3ff88;
  --line: rgba(244, 247, 228, .19);
  --glass: rgba(25, 30, 23, .83);
}

* { box-sizing: border-box; }
body { margin: 0; }
button, select, input { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: wait; opacity: .65; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible, #bike-preview:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 3px;
}
#app { min-height: 100svh; position: relative; overflow: hidden; isolation: isolate; }
#world, .scrim { position: absolute; inset: 0; z-index: -2; }
#world { background: linear-gradient(#546369, #a8aa8e 48%, #485341 62%, #262c23); touch-action: none; cursor: grab; }
#world:active { cursor: grabbing; }
#world canvas:not(.rain) { display: block; width: 100%; height: 100%; }
.rain { position: absolute; inset: 0; pointer-events: none; width: 100%; height: 100%; }
.park-preview-fade { position: absolute; inset: 0; z-index: 2; background: #151e19; opacity: 0; pointer-events: none; }
.driver-speech { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
.driver-shout {
  position: absolute; top: 0; left: 0; margin: 0; width: max-content; max-width: min(13rem, 55vw);
  padding: 6px 10px; border: 1px solid #eed1a0; border-radius: 10px;
  color: #291f17; background: #fff5df; box-shadow: 0 3px 12px #1b170b77;
  font-size: clamp(.81rem, 1.2vw, 1rem); font-weight: 740; line-height: 1.23; text-align: center;
}
.driver-shout::after {
  content: ''; position: absolute; top: 100%; left: var(--tail-x, 50%); transform: translateX(-50%);
  border: 7px solid transparent; border-top: 11px solid #fff5df; border-bottom: 0;
}
.driver-shout:is([data-edge="left"], [data-edge="right"])::after {
  top: 50%; transform: translateY(-50%); border: 7px solid transparent;
}
.driver-shout[data-edge="left"]::after { left: auto; right: 100%; border-left: 0; border-right: 10px solid #fff5df; }
.driver-shout[data-edge="right"]::after { left: 100%; border-right: 0; border-left: 10px solid #fff5df; }
.driver-shout[data-kind="rider-name"] {
  padding: 3px 8px; border-color: #ede1bd8a; border-radius: 6px;
  background: #212a25eb; color: #fff5df; font-size: .76rem;
}
.driver-shout[data-kind="rider-name"]::after {
  border-width: 4px 4px 0; border-top-color: #212a25eb;
}
.scrim {
  z-index: -1;
  background: linear-gradient(180deg, rgba(16,22,20,.67), transparent 23%, transparent 56%, rgba(14,18,15,.64));
  pointer-events: none;
}
.loading-overlay {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 50% 42%, rgba(28, 38, 30, .58), rgba(14, 19, 15, .88) 72%);
  backdrop-filter: blur(8px);
  transition: opacity .36s ease, visibility .36s ease;
}
.loading-overlay.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-overlay[hidden] { display: none; }
.loading-card {
  width: min(440px, 100%); padding: 30px 28px 26px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px;
  background: rgba(20, 27, 22, .92);
  border: 1px solid rgba(227, 255, 136, .24);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .55);
}
.loading-emblem { position: relative; width: 78px; height: 78px; display: grid; place-items: center; margin-bottom: 2px; }
.loading-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid rgba(244, 247, 228, .12);
  border-top-color: var(--lime);
  border-right-color: rgba(227, 255, 136, .45);
  animation: slaps-spin 1.05s cubic-bezier(.45, .15, .55, .85) infinite;
}
.loading-emblem svg {
  width: 46px; height: 46px; padding: 6px; border-radius: 12px;
  background: var(--lime); color: #202b22;
  box-shadow: 0 6px 20px rgba(227, 255, 136, .24);
}
.loading-eyebrow { font-size: .72rem; font-weight: 780; letter-spacing: .2em; color: var(--lime); }
.loading-title { margin: 0; font-size: clamp(1.42rem, 3.2vw, 1.82rem); font-weight: 800; letter-spacing: -.04em; line-height: 1.08; }
.loading-bar-wrap { width: 100%; display: grid; gap: 8px; margin-top: 6px; }
.loading-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: .84rem; color: var(--muted); }
#loading-stage { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#loading-pct { font-weight: 780; color: var(--text); font-variant-numeric: tabular-nums; flex: none; }
.loading-track {
  position: relative; height: 8px; width: 100%; border-radius: 999px;
  background: rgba(244, 247, 228, .12); overflow: hidden;
}
.loading-fill {
  display: block; height: 100%; width: 5%; border-radius: inherit;
  background: linear-gradient(90deg, #b6e861, var(--lime), #f4ffb8);
  box-shadow: 0 0 12px rgba(227, 255, 136, .45);
  transition: width .22s ease-out;
}
.loading-hint { margin: 4px 0 0; font-size: .78rem; color: var(--muted); opacity: .84; }
.loading-retry { margin-top: 6px; padding: 10px 20px; border-radius: 10px; font-weight: 760; }
.loading-overlay[data-error="true"] .loading-ring { animation: none; border-color: rgba(255, 128, 128, .45); }
.loading-overlay[data-error="true"] .loading-fill { background: #ff7c7c; box-shadow: none; }
@keyframes slaps-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-ring { animation-duration: 2.8s; } }
.glass { background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(15px); box-shadow: 0 6px 25px #0d150e24; }
#app:is([data-graphics="balanced"], [data-graphics="performance"]) .glass { backdrop-filter: none; }
.topbar {
  height: 76px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px;
  padding: 0 clamp(16px, 3vw, 48px); border-bottom: 1px solid #f4f7e42e;
  background: #15201b36;
}
.brand { display: flex; gap: 11px; align-items: center; text-decoration: none; color: inherit; justify-self: start; }
.brand svg { width: 40px; height: 40px; background: var(--lime); color: #253027; padding: 4px; border-radius: 9px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.brand > span { font-weight: 830; letter-spacing: .15em; display: grid; line-height: 1.02; font-size: 1.06rem; }
.brand small { font-size: .68rem; font-weight: 660; letter-spacing: .2em; margin-top: 5px; color: var(--muted); }
.top-route { font-size: .81rem; font-weight: 700; letter-spacing: .125em; text-shadow: 0 1px 3px #17201a; justify-self: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.top-route span { color: var(--lime); padding: 0 8px; }
.top-actions { display: flex; gap: 10px; justify-self: end; }
.icon-button, .connect, .secondary {
  border: 1px solid var(--line); background: #17221dd1; border-radius: 9px; min-height: 42px;
}
.icon-button { display: grid; place-items: center; width: 42px; padding: 0; }
.camera-button { display: flex; align-items: center; gap: 6px; width: auto; padding: 0 11px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.icon-button svg, .connect svg { width: 19px; height: 19px; }
.connect { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px; font-size: .9rem; font-weight: 720; white-space: nowrap; }
.connect svg { color: var(--lime); }
.icon-button:hover, .connect:hover, .secondary:hover, .key-controls button:hover { background: #384636; }
.ride-title { position: absolute; top: 116px; left: clamp(16px, 4vw, 64px); text-shadow: 0 2px 18px #182219aa, 0 1px 4px #19231b9e; pointer-events: none; }
.route-kicker { display: flex; align-items: center; gap: 8px; color: var(--lime); font-size: .82rem; font-weight: 790; letter-spacing: .16em; }
.route-kicker > span:first-child { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ride-title h1 { font-size: clamp(2.45rem, 5.6vw, 5.4rem); line-height: .98; letter-spacing: -.071em; margin: 12px 0; font-weight: 790; }
.ride-title p { margin: 0; font-size: 1rem; font-weight: 570; color: #f1f3e6; }
.riding .ride-title h1 { font-size: clamp(1.4rem, 3vw, 2.5rem); margin: 8px 0; letter-spacing: -.05em; }
.riding .ride-title p { display: none; }
.view-tools { position: absolute; top: 98px; right: clamp(16px, 3vw, 48px); display: flex; gap: 6px; z-index: 1; }
.view-tools [hidden] { display: none; }
#preview-toggle .preview-play, #preview-toggle[data-paused="true"] .preview-pause { display: none; }
#preview-toggle[data-paused="true"] .preview-play { display: inline; }
.view-tools [aria-pressed="true"], .view-tools .ringing { color: var(--lime); background: #303e25; }
.clean .scrim, .clean .topbar, .clean .ride-title, .clean .map-card, .clean .ride-deck, .clean .segment-banner { visibility: hidden; }
.clean .view-tools { top: 16px; visibility: visible; }
.map-card { position: absolute; bottom: 220px; right: clamp(16px, 3vw, 48px); padding: 14px; width: 226px; border-radius: 13px; }
.map-heading, .profile-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.map-heading h2, .profile-heading h2, .metric > span { font-size: .8rem; letter-spacing: .12em; font-weight: 740; color: var(--muted); margin: 0; }
.map-heading > span { font-size: .72rem; font-weight: 760; letter-spacing: .08em; color: var(--lime); }
.map-card canvas { display: block; width: 100%; height: 122px; margin-top: 5px; }
.map-card p { margin: 4px 0 0; font-size: .85rem; color: #eff2df; }
.map-card #companion-status { color: #e8bce4; }
.map-card #pace-status { color: var(--pace-color, #60a5fa); font-weight: 640; }
.map-card #weather-live-status { color: var(--muted); font-size: .74rem; }
.map-card #peloton-legend, .map-card #challenge-status { color: #ffca7b; }
.map-card #draft-status { color: #d4f59b; display: flex; flex-direction: column; gap: 4px; }
.map-card #draft-status[hidden] { display: none; }
.meter-track { display: block; height: 4px; border-radius: 99px; background: rgba(244, 247, 228, .15); overflow: hidden; }
.meter-fill { display: block; height: 100%; width: 0%; border-radius: inherit; background: var(--lime); transition: width .16s ease, background-color .2s ease; }
.workout-hud { margin-top: 7px; padding-top: 6px; border-top: 1px solid var(--line); font-size: .83rem; }
.workout-hud strong { color: var(--lime); }
.workout-track { margin-top: 5px; }
.workout-hud[data-compliance="low"] .meter-fill { background: #78d2f0; }
.workout-hud[data-compliance="ok"] .meter-fill { background: var(--lime); }
.workout-hud[data-compliance="high"] .meter-fill { background: #ff9b59; }
#peloton-legend::before { content: ''; display: inline-block; width: .42em; height: .42em; margin-right: .5em; background: currentColor; transform: translateY(-.1em) rotate(45deg); }
.segments { margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--line); font-size: .82rem; }
.segments summary { width: fit-content; font-weight: 720; cursor: pointer; }
.segments summary::marker { color: var(--lime); }
#segment-pace { margin-left: 4px; color: #ffcf93; font-size: .71rem; font-variant-numeric: tabular-nums; }
#segment-pace.ahead { color: #91e5ee; }
.map-card #segment-category { color: var(--muted); font-size: .68rem; margin-top: 7px; }
.segment-times { max-height: 220px; overflow-y: auto; overscroll-behavior: contain; padding-right: 2px; }
.segment-times section { padding-top: 8px; }
.segment-times section + section { margin-top: 8px; border-top: 1px solid var(--line); }
.segment-times header { display: flex; justify-content: space-between; align-items: baseline; gap: 5px; }
.segment-times h3 { margin: 0; font-size: inherit; }
.segment-times header span { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.segment-times dl { display: flex; gap: 5px; margin: 5px 0 0; }
.segment-times dl div { flex: 1; min-width: fit-content; }
.segment-times dt { color: var(--muted); font-size: .67rem; }
.segment-times dd { margin: 0; font-weight: 720; font-variant-numeric: tabular-nums; }
.segment-times [data-live], .segment-times [data-best] { color: var(--lime); }
.segment-times [data-delta] { color: #ffcf93; }
.segment-times [data-delta].ahead { color: #91e5ee; }
.segment-times dl { flex-wrap: wrap; }
.ride-deck { position: absolute; bottom: 24px; left: clamp(16px, 3vw, 48px); right: clamp(16px, 3vw, 48px); display: grid; gap: 8px; }
.telemetry { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border-radius: 13px; }
.telemetry:has(.hr-metric:not([hidden])) { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.metric { padding: 13px clamp(8px, 2vw, 27px) 12px; position: relative; }
.metric[hidden] { display: none; }
.metric-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
#wkg { font-style: normal; font-size: .71rem; font-weight: 700; letter-spacing: .02em; color: var(--zone-color, var(--muted)); font-variant-numeric: tabular-nums; }
.power-metric { box-shadow: inset 0 -2px 0 0 var(--zone-color, transparent); transition: box-shadow .25s ease; }
.power-metric[data-zone] strong { color: var(--zone-color, var(--text)); }
.hr-metric strong { color: #ff8e96; }
.metric + .metric { border-left: 1px solid var(--line); }
.metric div { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.metric strong { font-size: clamp(1.6rem, 3.3vw, 3rem); letter-spacing: -.05em; line-height: 1.1; }
.metric small { font-size: .81rem; color: var(--muted); }
.metric:first-child strong, #grade.up { color: var(--lime); }
.lower-deck { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
.profile { min-width: 0; border-radius: 13px; padding: 9px 15px 7px; }
.profile-heading span { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.profile canvas { display: block; width: 100%; height: 41px; margin-top: 3px; }
.ride-controls { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 10px; border-radius: 13px; }
.ride-actions { display: flex; gap: 7px; margin-left: auto; }
#end-ride { white-space: nowrap; }
.key-controls { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.key-controls[hidden] { display: none; }
.key-controls span { font-size: .9rem; font-variant-numeric: tabular-nums; font-weight: 700; min-width: 58px; }
.key-controls button { width: 32px; height: 39px; border: none; background: transparent; font-size: 1.14rem; border-radius: 7px; }
.primary { background: var(--lime); color: #212a18; border: 0; border-radius: 8px; min-height: 43px; padding: 0 18px; font-weight: 790; white-space: nowrap; }
.primary:hover { background: #f0ffb5; }
#ride-toggle { min-width: 136px; }
#ride-symbol { margin-right: 9px; font-size: .78rem; }
.secondary { padding: 0 13px; }
.toast { position: absolute; bottom: 221px; left: clamp(16px, 3vw, 48px); max-width: min(420px, 45vw); border-radius: 9px; padding: 12px 15px; font-size: .91rem; }
.rage-hud {
  position: absolute; z-index: 1; top: 88px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px; width: max-content; max-width: min(350px, 54vw);
  padding: 10px 14px; border-radius: 9px; border-left: 3px solid #eabb70; pointer-events: none;
}
.rage-hud[hidden], #rage-value:empty { display: none; }
.rage-hud strong, #rage-detail { display: block; }
.rage-hud strong { color: #ffd892; font-size: .88rem; }
#rage-detail { margin-top: 3px; font-size: .77rem; color: var(--muted); }
.rage-hud output { color: var(--text); font-size: 1.14rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rage-hud button { pointer-events: auto; min-height: 34px; padding: 0 8px; font-size: .76rem; white-space: nowrap; }
.rear-view-icon { display: none; }
.rage-hud[data-phase="recovery"] { border-left-color: #ff9d7c; }
.rage-hud[data-phase="escaped"], .rage-hud[data-phase="recovered"] { border-left-color: var(--lime); }
.segment-banner {
  position: absolute; z-index: 1; top: 184px; left: clamp(16px, 4vw, 64px);
  width: min(268px, 34vw); padding: 10px 13px; border-radius: 10px;
  border-left: 3px solid #9bf0a8; pointer-events: none;
}
.segment-banner[hidden] { display: none; }
.segment-banner[data-target="pb"] { border-left-color: #80e7f1; }
.segment-banner[data-mode="approach"] { border-left-color: var(--lime); }
.segment-banner-head, .segment-banner-stats { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.segment-banner-head strong { font-size: .78rem; letter-spacing: .09em; text-transform: uppercase; color: var(--lime); }
.segment-banner-head span { font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.segment-banner-stats { margin-top: 4px; }
.segment-banner-stats output { font-size: 1.24rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.segment-banner-stats span { font-size: .78rem; font-weight: 740; font-variant-numeric: tabular-nums; color: #ffcf93; white-space: nowrap; }
.segment-banner-stats span.ahead { color: #91e5ee; }
.segment-banner[data-target="starter"] .segment-banner-stats span.ahead { color: #9bf0a8; }
.segment-banner-track {
  position: relative; height: 5px; margin-top: 7px; border-radius: 99px;
  background: rgba(244, 247, 228, .16);
}
.segment-banner-track[hidden] { display: none; }
.segment-banner-fill {
  display: block; height: 100%; width: 0%; border-radius: inherit;
  background: var(--lime); transition: width .14s linear;
}
.segment-banner-ghost {
  position: absolute; top: 50%; width: 9px; height: 9px; border-radius: 50%;
  transform: translate(-50%, -50%); background: #9bf0a8;
  border: 1.5px solid #152019; box-shadow: 0 0 6px rgba(155, 240, 168, .65);
}
.segment-banner[data-target="pb"] .segment-banner-ghost { background: #80e7f1; box-shadow: 0 0 6px rgba(128, 231, 241, .65); }
dialog { color: var(--text); width: min(440px, calc(100% - 25px)); border-radius: 15px; padding: 22px; max-height: 90svh; }
dialog::backdrop { background: #10191394; }
.dialog-header, .dialog-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog-header h2 { font-size: 1.45rem; margin: 0; letter-spacing: -.04em; }
.dialog-header .icon-button { font-size: 1.45rem; }
dialog label { display: flex; justify-content: space-between; gap: 8px; margin: 18px 0 7px; font-weight: 700; }
dialog select, dialog input { width: 100%; accent-color: var(--lime); }
dialog select {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 34px 9px 10px; appearance: none;
  background: linear-gradient(45deg,transparent 50%,var(--muted) 50%) right 15px center / 5px 5px no-repeat,
    linear-gradient(135deg,var(--muted) 50%,transparent 50%) right 10px center / 5px 5px no-repeat, #212920;
}
dialog p { color: var(--muted); line-height: 1.5; font-size: .91rem; }
#ride-history-label[hidden], #ride-history[hidden] { display: none; }
.ride-totals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-block: 13px 18px; }
.ride-totals div { padding: 9px; border: 1px solid var(--line); border-radius: 8px; }
.ride-totals dt { color: var(--muted); font-size: .76rem; }
.ride-totals dd { margin: 3px 0 0; font-size: 1.18rem; font-weight: 760; font-variant-numeric: tabular-nums; }
.rage-summary { margin: 0 0 14px; padding: 9px 11px; border: 1px solid var(--line); border-left: 3px solid #eabb70; border-radius: 8px; }
.rage-summary[hidden] { display: none; }
.rage-summary h3 { margin: 0 0 4px; font-size: .86rem; color: #ffd892; }
.rage-summary p { margin: 0; font-size: .82rem; color: var(--text); }
#ride-summary h3 { margin: 0; font-size: .95rem; }
#summary-laps { margin: 8px 0 16px; padding-left: 22px; max-height: 150px; overflow: auto; }
#summary-laps li { padding: 4px 0; font-variant-numeric: tabular-nums; }
.bike-settings { padding-top: 12px; border-top: 1px solid var(--line); margin-top: 14px; }
.settings-tabs {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px;
  margin: 14px 0 12px; padding: 4px; border-radius: 10px;
  background: rgba(16, 22, 17, .55); border: 1px solid var(--line);
}
.settings-tabs button {
  padding: 7px 6px; border-radius: 7px; font-size: .82rem; font-weight: 700;
  color: var(--muted); background: transparent; border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.settings-tabs button:hover { color: var(--text); }
.settings-tabs button[aria-selected="true"] {
  background: rgba(215, 240, 118, .16); color: var(--lime); border-color: rgba(215, 240, 118, .35);
}
.settings-body { max-height: 58svh; overflow-y: auto; padding-right: 2px; }
.settings-panel[hidden] { display: none; }
.settings-group-title {
  margin: 14px 0 6px; font-size: .72rem; font-weight: 800; letter-spacing: .1em;
  text-transform: uppercase; color: var(--lime);
}
.settings-panel > .settings-group-title:first-child,
.kit-settings > .settings-group-title:first-child { margin-top: 4px; }
.settings-panel label:first-of-type { margin-top: 8px; }
#settings .dialog-footer { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.kit-style-pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.kit-style-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; font-size: .76rem; font-weight: 700;
  color: var(--text); background: #212920; border: 1px solid var(--line);
}
.kit-style-pill:hover { border-color: var(--text); }
.kit-style-pill[aria-pressed="true"] {
  background: rgba(215, 240, 118, .18); border-color: var(--lime); color: var(--lime);
}
.kit-style-dot {
  width: 11px; height: 11px; border-radius: 50%; flex: none;
  border: 1px solid rgba(255, 255, 255, .35);
}
.kit-select-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.kit-select-row label { margin: 4px 0 5px; font-size: .82rem; }
.kit-color-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px;
  margin-top: 8px;
}
dialog .kit-color-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  margin: 0; padding: 6px 4px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: rgba(24, 32, 24, .65);
  font-size: .72rem; font-weight: 650; color: var(--muted);
}
dialog .kit-color-item:hover { border-color: var(--text); color: var(--text); }
.kit-color-item input[type="color"] {
  width: 34px; height: 22px; padding: 0; border: 0; background: transparent; cursor: pointer;
}
.kit-color-item input[type="color"]::-webkit-color-swatch-wrapper { padding: 1px; }
.kit-color-item input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(255, 255, 255, .28); border-radius: 4px; }
.kit-color-item input[type="color"]::-moz-color-swatch { border: 1px solid rgba(255, 255, 255, .28); border-radius: 4px; }
.bike-stage {
  position: relative; margin-top: 10px; height: clamp(154px, 26vh, 225px); overflow: hidden;
  border: 1px solid #d2e3d519; border-radius: 9px;
  background: radial-gradient(ellipse at 50% 42%, #e3e3dc, #b7bcb5 90%);
}
.bike-stage canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: pan-y; }
.bike-stage canvas[hidden] { display: none; }
.bike-stage canvas:active { cursor: grabbing; }
.bike-stage canvas:focus-visible { outline-offset: -3px; }
.bike-stage span { position: absolute; left: 9px; bottom: 7px; pointer-events: none; font-size: .68rem; color: #29352d; }
.bike-stage p { color: #29352d; margin: 0; padding: 12px; }
.paint-heading { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 8px; }
.paint-heading label { margin: 0; }
.paint-heading output { color: var(--muted); font-family: ui-monospace, monospace; font-size: .74rem; }
.paint-controls, #bike-swatches { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.paint-chip { width: 25px; height: 25px; border-radius: 100%; background: var(--paint); border: 1px solid #dae3d84a; }
.paint-chip:hover { border-color: var(--text); }
.paint-chip[aria-pressed="true"] { outline: 1px solid var(--lime); outline-offset: 2px; }
dialog .paint-custom {
  display: flex; align-items: center; margin: 0 0 0 auto; padding: 3px 8px 3px 5px;
  font-size: .76rem; border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.paint-custom input { width: 25px; height: 21px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.paint-custom input::-webkit-color-swatch-wrapper { padding: 2px; }
.paint-custom input::-webkit-color-swatch { border: 1px solid var(--line); border-radius: 3px; }
.paint-custom input::-moz-color-swatch { border: 1px solid var(--line); border-radius: 3px; }
dialog .mode-toggle { align-items: center; padding-block: 10px; border-top: 1px solid var(--line); margin-bottom: 0; }
.mode-toggle input { inline-size: 20px; block-size: 20px; margin: 0; flex: 0 0 auto; cursor: pointer; }
.ride-options { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 14px; }
.device-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 10px; padding-block: 12px; border-block: 1px solid var(--line); }
.device-metrics [hidden] { display: none; }
.device-metrics dt { color: var(--muted); font-size: .82rem; }
.device-metrics dd { margin: 4px 0 0; font-weight: 700; }
#workout-ftp, #challenge-url, #rider-name-input {
  color: var(--text); background: #1c261b; border: 1px solid var(--line); border-radius: 7px;
  padding: 9px 10px; font: inherit;
}
.pill-button {
  display: inline-flex; align-items: center; gap: 6px; height: 42px; padding: 0 11px;
  border-radius: 9px; border: 1px solid var(--line); background: rgba(20, 27, 21, .74);
  color: var(--text); font-size: .82rem; font-weight: 700; backdrop-filter: blur(10px);
}
.pill-button:hover { border-color: var(--text); }
.rider-pill { max-width: 230px; }
#rider-name-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-count {
  flex: none; font-size: .70rem; font-weight: 750; line-height: 1;
  padding: 3px 6px; border-radius: 999px; font-variant-numeric: tabular-nums;
  background: rgba(74, 222, 128, .15); color: #86efac;
}
.online-count[hidden] { display: none; }
.online-count[data-state="riders"] { background: rgba(192, 132, 252, .22); color: #e9d5ff; }
.online-count[data-state="offline"] { background: rgba(148, 163, 152, .16); color: var(--muted); }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: #6b766c; transition: background .2s, box-shadow .2s;
}
.live-dot[data-state="online"] { background: #4ade80; box-shadow: 0 0 7px rgba(74, 222, 128, .75); }
.live-dot[data-state="riders"] { background: #c084fc; box-shadow: 0 0 8px rgba(192, 132, 252, .85); }
#live-riders-status { color: #d8b4fe; font-weight: 700; }
#live-riders-status::before {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px;
  border-radius: 50%; background: #c084fc; vertical-align: 1px;
}
.changelog-list {
  display: flex; flex-direction: column; gap: 12px;
  max-height: 54svh; overflow-y: auto; margin: 10px 0 16px; padding-right: 2px;
}
.changelog-entry {
  padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(20, 28, 21, .65);
}
.changelog-entry-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.changelog-version {
  font-size: .82rem; font-weight: 800; color: var(--lime);
  padding: 2px 7px; border-radius: 999px; background: rgba(215, 240, 118, .14);
}
.changelog-meta { font-size: .74rem; color: var(--muted); }
.changelog-summary { margin: 7px 0 6px; font-size: .86rem; font-weight: 650; color: var(--text); }
.changelog-entry ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: .80rem; line-height: 1.45; }
.changelog-entry li { margin: 3px 0; }
#road-rage-help { margin-top: 0; }
.attribution { margin: 17px 0 0; font-size: .75rem; }
.attribution a { color: var(--muted); }
kbd { background: #344133; border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr auto; height: 64px; }
  .top-route { display: none; }
  .ride-title { top: 95px; }
  .view-tools { top: 81px; }
  .rage-hud { top: 76px; }
  .map-card { width: 180px; }
  .map-card canvas { height: 98px; }
  .metric { padding-inline: 9px; }
}
@media (max-width: 1020px) {
  .top-route { display: none; }
}
@media (max-width: 590px) {
  .paint-controls, #bike-swatches { gap: 6px; }
}
@media (max-height: 610px) and (min-width: 591px) {
  .ride-title { top: 92px; }
  .ride-title h1 { font-size: 3.3rem; }
  .map-card { bottom: 176px; }
  .ride-deck { bottom: 12px; }
  .metric { padding-block: 7px; }
  .profile canvas { height: 24px; }
  .toast { bottom: 178px; }
}

@media (orientation: portrait) and (max-width: 590px), (orientation: landscape) and (max-height: 500px) {
  #app {
    --hud-left: max(10px, env(safe-area-inset-left));
    --hud-right: max(10px, env(safe-area-inset-right));
    --hud-bottom: max(7px, env(safe-area-inset-bottom));
    min-height: 100dvh;
  }
  .top-route { display: none; }
  .brand { gap: 7px; }
  .brand svg { width: 32px; height: 32px; }
  .brand > span { font-size: .87rem; }
  .brand small { font-size: .54rem; margin-top: 3px; }
  .top-actions, .view-tools { gap: 4px; }
  .clean .view-tools { top: calc(8px + env(safe-area-inset-top)); }
  .topbar .icon-button { width: 36px; min-height: 36px; }
  .pill-button { height: 36px; padding: 0 7px; font-size: .73rem; }
  .rider-pill { max-width: 146px; }
  .online-count { font-size: .64rem; padding: 2px 5px; }
  #changelog-open { padding: 0 6px; font-size: .70rem; }
  .camera-button { width: 36px; padding: 0; justify-content: center; }
  #camera-label { display: none; }
  .topbar .icon-button svg, .topbar .connect svg { width: 17px; height: 17px; flex: none; }
  .topbar .connect { min-height: 36px; max-width: 132px; gap: 5px; padding-inline: 7px; font-size: .77rem; }
  #connect-label { overflow: hidden; text-overflow: ellipsis; }

  .ride-context {
    position: absolute; top: var(--hud-top); left: var(--hud-left);
    display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
    pointer-events: none;
  }
  .ride-title, .rage-hud, .segment-banner { position: static; }
  .segment-banner { width: 100%; padding: 6px 8px; border-radius: 7px; }
  .segment-banner-head strong { font-size: .65rem; }
  .segment-banner-head span, .segment-banner-stats span { font-size: .66rem; }
  .segment-banner-stats output { font-size: .95rem; }
  .segment-banner-track { height: 4px; margin-top: 4px; }
  .ride-title h1, .riding .ride-title h1 { margin: 3px 0; }
  #app:is(.riding, :has(#end-ride:not([hidden]))) .ride-title h1 { font-size: 1.1rem; }
  #app:has(#end-ride:not([hidden])) .ride-title p { display: none; }
  .route-kicker { font-size: .65rem; letter-spacing: .1em; gap: 5px; }
  .ride-title p { font-size: .73rem; }
  .rage-hud { transform: none; max-width: 100%; gap: 5px; padding: 4px 5px 4px 7px; border-radius: 7px; }
  .rage-hud strong, .rage-hud button { font-size: .71rem; }
  .rage-hud output { font-size: .82rem; }
  #rage-detail { margin-top: 2px; font-size: .66rem; line-height: 1.15; }
  .rage-hud[data-phase="ready"]:not([data-cue]) #rage-detail, .rage-hud:is([data-phase="recovered"], [data-phase="escaped"]) #rage-detail { display: none; }
  .rage-hud button { min-height: 32px; padding-inline: 5px; }
  .rage-hud[data-phase="chase"]:not([hidden]) {
    display: grid; grid-template-columns: minmax(0, 1fr) auto auto; row-gap: 0;
    grid-template-areas: "status gap look" "detail detail detail";
  }
  .rage-hud[data-phase="chase"] > div { display: contents; }
  .rage-hud[data-phase="chase"] #rage-status { grid-area: status; }
  .rage-hud[data-phase="chase"] #rage-value { grid-area: gap; }
  .rage-hud[data-phase="chase"] #rage-detail { grid-area: detail; }
  .rage-hud[data-phase="chase"] #rage-look { grid-area: look; }

  .map-card {
    right: var(--hud-right); display: flex; flex-direction: column;
    max-height: var(--hud-map-space); padding: 7px; border-radius: 9px;
  }
  .map-heading, .map-card canvas { flex: none; }
  .map-heading h2, .map-heading > span { font-size: .65rem; }
  .map-card canvas { margin-top: 3px; }
  .map-details { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .map-card p, .workout-hud, .segments { font-size: .71rem; line-height: 1.2; }
  .map-card p { margin-top: 3px; }
  .segments { margin-top: 5px; padding-top: 4px; }
  .segments summary { padding-block: 4px; }
  .workout-hud { margin-top: 4px; padding-top: 3px; }

  .ride-deck { left: var(--hud-left); right: var(--hud-right); bottom: var(--hud-bottom); gap: 4px; }
  .telemetry { border-radius: 9px; }
  .metric { padding: 2px 6px 3px; }
  .metric > span { display: block; font-size: .62rem; letter-spacing: .07em; line-height: 1.25; }
  .metric > .metric-head { display: flex; gap: 3px; }
  #wkg { font-size: .56rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .metric div { gap: 3px; }
  .metric small { font-size: .66rem; }
  .lower-deck { gap: 4px; }
  .profile { padding: 4px 7px; border-radius: 8px; }
  .profile-heading h2, .profile-heading span { font-size: .63rem; }
  .profile-heading span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .profile canvas { height: 19px; margin-top: 2px; }
  .ride-controls { gap: 6px; padding: 3px; border-radius: 8px; }
  .ride-actions { gap: 4px; }
  .key-controls span { min-width: 44px; font-size: .74rem; }
  .key-controls button { width: 30px; height: 34px; }
  .ride-actions #ride-toggle, #end-ride { min-width: 0; min-height: 36px; padding-inline: 8px; font-size: .78rem; }
  #ride-symbol { margin-right: 5px; }
  .toast { bottom: var(--hud-deck-top); left: var(--hud-left); padding: 6px 8px; font-size: .73rem; }
}

@media (orientation: portrait) and (max-width: 590px) {
  #app {
    --hud-top: calc(103px + env(safe-area-inset-top));
    --hud-map-width: clamp(131px, 38vw, 164px);
    /* Leave room for the ride deck and expanded Road Rage prompts on short screens. */
    --hud-map-space: clamp(104px, calc(100dvh - var(--hud-top) - var(--hud-bottom) - 282px), 226px);
    display: grid; grid-template: minmax(0, 1fr) auto / minmax(0, 1fr);
    padding: 0 var(--hud-right) var(--hud-bottom) var(--hud-left);
  }
  .topbar {
    position: absolute; inset: 0 0 auto;
    height: calc(53px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) var(--hud-right) 0 var(--hud-left);
  }
  .topbar .icon-button, .topbar .connect { min-height: 39px; }
  .topbar .icon-button { width: 39px; }
  .view-tools { top: calc(59px + env(safe-area-inset-top)); right: var(--hud-right); }
  .ride-context { width: min(235px, calc(100% - var(--hud-left) - var(--hud-right))); gap: 5px; }
  .ride-title h1 { font-size: clamp(1.65rem, 7.6vw, 2.18rem); }

  .map-card, .toast { position: relative; inset: auto; grid-area: 1 / 1; align-self: end; margin-bottom: 7px; }
  .map-card { justify-self: end; width: var(--hud-map-width); }
  .map-card canvas { height: clamp(54px, calc(var(--hud-map-space) - 70px), 105px); }
  .ride-deck { position: relative; inset: auto; grid-area: 2 / 1; }
  .telemetry, .telemetry:has(.hr-metric:not([hidden])) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric { padding: 2px 8px; }
  .metric strong { font-size: clamp(1.18rem, 5.3vw, 1.48rem); }
  .metric:nth-child(4) { border-left: 0; }
  .metric:nth-child(n + 4) { border-top: 1px solid var(--line); }
  .lower-deck { grid-template-columns: minmax(0, 1fr); }
  .profile { padding-block: 3px; }
  .profile canvas { height: 15px; }
  .ride-actions #ride-toggle, #end-ride { min-height: 40px; padding-inline: 10px; }
  .key-controls button { height: 38px; }
  .toast { justify-self: start; max-width: calc(100% - var(--hud-map-width) - 7px); }
}

@media (orientation: landscape) and (max-height: 500px) {
  #app {
    --hud-top: calc(54px + env(safe-area-inset-top));
    --hud-deck-top: calc(var(--hud-bottom) + 98px);
    --hud-map-space: calc(100dvh - var(--hud-top) - var(--hud-deck-top));
  }
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    height: calc(47px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) var(--hud-right) 0 var(--hud-left);
  }
  .view-tools { position: static; justify-self: center; }
  .ride-context { width: min(230px, 34vw); }
  .ride-title h1, .riding .ride-title h1 { font-size: clamp(1.15rem, 3vw, 1.8rem); }
  .map-card { top: var(--hud-top); bottom: auto; width: clamp(134px, 19vw, 184px); }
  .map-card canvas { height: clamp(49px, calc(var(--hud-map-space) - 60px), 112px); }
  .metric strong { font-size: clamp(1.03rem, 2.8vw, 1.35rem); }
  .toast { max-width: min(300px, 47vw); }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 620px) {
  #rage-look:not([hidden]) { display: grid; place-items: center; width: 34px; }
  #rage-look-label { display: none; }
  .rear-view-icon { display: block; width: 17px; height: 17px; }
  #rage-look[aria-pressed="true"] .rear-view-icon { transform: scaleX(-1); }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 520px) {
  .topbar { gap: 4px; }
  .topbar .icon-button { width: 34px; }
  .topbar .view-tools { gap: 3px; }
  .topbar .connect { max-width: 118px; gap: 4px; padding-inline: 6px; font-size: .72rem; }
}
