:root {
  --ink: #3B3345;
  --ink-soft: #5E5566;
  --muted: #7A6F7E;
  --cream: #FBF3EA;
  --paper: #FFFFFF;
  --sand: #F6ECE1;
  --track: #EFE3D6;
  --line: #E3D3C3;
  --coral: #F2765C;
  --coral-deep: #C95A43;
  --coral-text: #C24E36;
  --mustard: #F2C14E;
  --mustard-deep: #C99A2E;
  --teal: #4FA3A5;
  --teal-text: #3E8A84;
  --mint: #8FD3C6;
  --mint-deep: #6FB5A8;
  --sage: #9CC5A1;
  --lavender: #B9AEE0;
  --lavender-deep: #9A8DCB;
  --lavender-soft: #F3F0FB;
  --lavender-text: #4F4488;
  --peach: #FCE3D2;
  --paper-shadow: 0 2px 0 #EAD8C6, 0 8px 18px rgba(122, 78, 58, 0.10);
  --paper-shadow-lg: 0 3px 0 #EAD8C6, 0 10px 24px rgba(122, 78, 58, 0.10);
  --display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--body);
  font-weight: 600;
  min-height: 100vh;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
:focus-visible { outline: 3px solid var(--lavender-text); outline-offset: 2px; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 800; }
.center { text-align: center; }
.error { color: var(--coral-text); font-weight: 800; }

/* A notice for browsers that can't reach a bike. */
.browser-notice {
  display: flex; align-items: center; gap: 12px; margin: 14px 32px 0; padding: 12px 18px; border-radius: 16px;
  background: #FDE3DC; border: 2px solid var(--coral); font-weight: 700; line-height: 1.4;
}
.browser-notice b { font-family: var(--display); font-size: 17px; }
.notice-mark { width: 34px; height: 34px; border-radius: 50%; background: var(--coral); color: #fff; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 20px; flex-shrink: 0; }
.unavailable { opacity: 0.45; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; padding: 18px 32px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: var(--lavender); color: var(--ink);
  box-shadow: 0 3px 0 var(--lavender-deep), 0 8px 16px rgba(122, 78, 58, 0.15);
  transform: rotate(-4deg);
}
.brand-name { font-family: var(--display); font-weight: 700; font-size: 24px; }
.bike-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px;
  border-radius: 999px; background: var(--paper); box-shadow: 0 2px 0 #EAD8C6;
  font-size: 14px; font-weight: 800;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: #D6C7B8; }
.chip.ok .dot { background: #6FA67E; }
.chip.warn .dot { background: var(--mustard); animation: dot-pulse 0.9s ease-in-out infinite; }
.chip.ok .dot { animation: dot-pop 0.4s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes dot-pulse { 50% { transform: scale(1.5); opacity: 0.55; } }
@keyframes dot-pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.6); } }
.pace-row { margin-bottom: 10px; }
.pace-row .link { font-size: 15px; }

.app-foot { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 18px; padding: 8px 32px 28px; font-size: 13px; font-weight: 700; color: var(--muted); }
.app-foot a { color: var(--lavender-text); text-underline-offset: 3px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 14px; border: 0;
  font-weight: 800; font-size: 14px;
}
.btn.wide { width: 100%; }
.btn-paper { background: var(--paper); box-shadow: 0 2px 0 #EAD8C6; }
.btn-paper:hover { background: #FFFDFB; }
.btn-ghostly { background: var(--lavender-soft); border: 2px dashed var(--lavender-deep); color: var(--lavender-text); }
.btn-lilac { background: var(--lavender-soft); border: 2px solid var(--lavender); color: var(--lavender-text); }
.btn-start {
  min-height: 64px; border-radius: 20px; background: var(--coral); color: var(--ink);
  font-family: var(--display); font-weight: 700; font-size: 22px;
  box-shadow: 0 4px 0 var(--coral-deep), 0 10px 20px rgba(122, 78, 58, 0.2);
}
.btn-start:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--coral-deep); }
.btn-start.small-btn { min-height: 44px; font-size: 16px; border-radius: 14px; }
.link { background: none; border: 0; padding: 4px; color: var(--lavender-text); font-weight: 800; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 10px; border: 0; background: var(--paper);
  box-shadow: 0 2px 0 #EAD8C6; display: inline-grid; place-items: center; font-weight: 800; font-size: 18px;
}

/* ---------- setup ---------- */
main { padding: 0 32px 40px; }
.screen { max-width: 1120px; margin: 0 auto; }
.title { font-family: var(--display); font-weight: 700; font-size: 36px; margin: 4px 0 16px; }
.title-sm { font-family: var(--display); font-weight: 700; font-size: 26px; margin: 0 0 10px; }
.setup-grid { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 32px; }
/* The four setup steps: paper tags strung along a dashed line, each with a
   numbered button of its own colour. The current one is lifted and tilted. */
.steps { position: relative; list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 10px 0 24px; padding: 0; }
.steps::before { content: ''; position: absolute; left: 8%; right: 8%; top: 50%; border-top: 3px dashed var(--line); }
.steps li { position: relative; }
.step {
  position: relative; width: 100%; border: 0; border-radius: 16px; padding: 12px 10px 9px 14px; text-align: left; cursor: pointer;
  background: var(--paper); color: var(--ink-soft); font-family: inherit; display: flex; flex-direction: column; gap: 1px;
  box-shadow: 0 2px 0 #EAD8C6, 0 6px 12px rgba(122, 78, 58, 0.08); transition: transform 0.15s;
}
.step:hover { transform: translateY(-2px); }
.step-num {
  position: absolute; top: -10px; left: -6px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; font-size: 15px; color: var(--ink); background: var(--step, var(--sand));
  border: 3px solid var(--cream); box-shadow: 0 2px 0 rgba(59, 51, 69, 0.15);
}
.steps li:nth-child(1) { --step: var(--mustard); --step-deep: var(--mustard-deep); }
.steps li:nth-child(2) { --step: #9CC5A1; --step-deep: #6FA67E; }
.steps li:nth-child(3) { --step: #F7A593; --step-deep: var(--coral-deep); }
.steps li:nth-child(4) { --step: var(--mint); --step-deep: var(--mint-deep); }
.step .step-name { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.step .step-pick { font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step[aria-current="step"] {
  background: var(--step); color: var(--ink); transform: rotate(-2deg) translateY(-2px);
  box-shadow: 0 3px 0 var(--step-deep), 0 8px 14px rgba(122, 78, 58, 0.18);
}
.step[aria-current="step"] .step-num { background: var(--paper); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.step-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }
.step-nav .btn { min-width: 110px; }
.group { border: 0; padding: 0; margin: 0 0 20px; }
.group legend { font-family: var(--display); font-weight: 600; font-size: 18px; margin-bottom: 10px; padding: 0; }

.durations { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.dur {
  height: 78px; border: 0; border-radius: 16px; background: var(--paper); box-shadow: 0 2px 0 #EAD8C6;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform 0.15s;
}
/* A newly picked card gives a press and a pop. */
.dur.picked { animation: card-pick 0.3s cubic-bezier(0.3, 1.5, 0.5, 1); }
.type.picked { animation: tile-pick 0.3s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes card-pick { 0% { transform: scale(0.94); } 55% { transform: rotate(-3deg) translateY(-5px) scale(1.05); } }
@keyframes tile-pick { 0% { transform: scale(0.97); } 55% { transform: scale(1.025); } }
/* Moving between steps, the new step's contents slide in from the side it lies on. */
[data-step].from-right { animation: step-from-right 0.2s ease-out; }
[data-step].from-left { animation: step-from-left 0.2s ease-out; }
@keyframes step-from-right { from { transform: translateX(28px); opacity: 0; } }
@keyframes step-from-left { from { transform: translateX(-28px); opacity: 0; } }
/* Start sits back until a bike is connected, then gives one bounce. */
#btn-start { transition: opacity 0.25s, filter 0.25s; }
#btn-start.waiting { opacity: 0.55; filter: saturate(0.6); }
#btn-start.ready { animation: start-ready 0.5s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes start-ready { 35% { transform: translateY(-7px) scale(1.03); } 70% { transform: translateY(1px); } }
@media (prefers-reduced-motion: reduce) {
  .preview-chart svg .step-bar, .dur.picked, .type.picked, [data-step], #btn-start.ready, .type-fold.opening, .chip .dot { animation: none !important; }
  #btn-shuffle svg, .type-new svg { transition: none; }
}
.dur .num { font-family: var(--display); font-weight: 700; font-size: 28px; line-height: 1; }
.dur .lbl { font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.custom-dur {
  margin-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px 8px 16px; border-radius: 16px; background: var(--paper); box-shadow: 0 2px 0 #EAD8C6;
}
.custom-dur.on { background: var(--mustard); box-shadow: 0 3px 0 var(--mustard-deep), 0 8px 14px rgba(122, 78, 58, 0.18); }
.custom-label { font-weight: 800; font-size: 14px; color: var(--ink-soft); }
.custom-dur.on .custom-label { color: var(--ink); }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper input {
  width: 64px; height: 40px; border: 2px solid var(--track); border-radius: 12px; background: var(--cream); color: var(--ink);
  font-family: var(--display); font-weight: 700; font-size: 22px; text-align: center; -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.custom-dur.on .stepper input { border-color: var(--mustard-deep); background: #FFF6DE; }
.effort-setup { min-width: 64px; text-align: center; font-family: var(--display); font-weight: 700; font-size: 20px; }
.seg-toggle.sound-toggle { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 420px; }
.seg-toggle.knob-kinds { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 10px; }
.dialog-sub { font-family: var(--display); font-weight: 700; font-size: 18px; margin: 16px 0 6px; }
.sound-toggle .seg { cursor: pointer; }
.seg-toggle.effort-words { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.effort-words .seg { cursor: pointer; padding: 0 2px; }
.effort-note { margin: 8px 2px 0; line-height: 1.45; }
.custom-unit { font-weight: 800; font-size: 14px; }
.stepper .icon-btn { width: 40px; height: 40px; font-size: 20px; }
.dur[aria-pressed="true"] { background: var(--mustard); box-shadow: 0 3px 0 var(--mustard-deep), 0 8px 14px rgba(122, 78, 58, 0.18); transform: rotate(-2deg); }

.types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.type {
  min-height: 58px; padding: 6px 14px; border-radius: 14px; border: 2px solid var(--paper);
  background: var(--paper); box-shadow: 0 2px 0 #EAD8C6; display: flex; align-items: center; gap: 12px; text-align: left;
}
.type.wide { grid-column: span 2; }
.type-random {
  grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
  border: 2px dashed var(--lavender-deep); border-radius: 14px; background: var(--lavender-soft); color: var(--lavender-text);
  font-family: inherit; font-weight: 800; font-size: 15px; cursor: pointer;
}
.type-open {
  grid-column: 1 / -1; border-radius: 16px; border: 2px solid var(--group);
  background: color-mix(in srgb, var(--group) 28%, var(--cream));
}
.type-open .type-group { width: 100%; border-radius: 12px 12px 0 0; }
/* The open group's rides ease open: a grid row growing from nothing to their own height.
   The row clips the list rather than squeezing it, so the rides keep their size as they show. */
.type-fold { display: grid; grid-template-rows: 1fr; }
.type-fold.opening { animation: fold-open 0.22s ease-out; }
.type-fold > .type-clip { overflow: hidden; min-height: 0; }
@keyframes fold-open { from { grid-template-rows: 0fr; } }
.type-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 10px; }
.type-group {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 16px;
  border: 0; border-radius: 14px; background: var(--sand); color: var(--ink); font-family: inherit; cursor: pointer; text-align: left;
  font-family: var(--display); font-weight: 600; font-size: 17px;
}
.type-group-pick { margin-left: auto; font-family: var(--body); font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.type-group-arrow { width: 9px; height: 9px; border-right: 2.5px solid var(--ink-soft); border-bottom: 2.5px solid var(--ink-soft); transform: rotate(-45deg); transition: transform 0.15s; }
.type-group[aria-expanded="true"] .type-group-arrow { transform: rotate(45deg); }
.type-new {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px;
  background: var(--lavender-soft); border: 2px solid var(--lavender); color: var(--lavender-text); font-size: 13px; font-weight: 800; white-space: nowrap;
}
.type .sw { width: 18px; height: 18px; border-radius: 6px; flex-shrink: 0; box-shadow: 0 1px 0 rgba(59, 51, 69, 0.2); }
.type .name { display: block; font-weight: 800; font-size: 15px; }
.type .hint { display: block; font-size: 12px; font-weight: 700; color: var(--muted); }

.ghosts { display: flex; flex-direction: column; gap: 8px; }
.ghost-opt {
  min-height: 50px; padding: 6px 14px; border-radius: 14px; border: 2px solid var(--paper);
  background: var(--paper); box-shadow: 0 2px 0 #EAD8C6; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left;
}
.ghost-opt .name { font-weight: 800; font-size: 15px; }
.ghost-opt .sub { font-size: 13px; font-weight: 700; color: var(--muted); }
.ghost-opt[aria-pressed="true"] { border: 2px dashed #8C80B8; background: var(--lavender-soft); }
.ghost-opt:disabled { opacity: 0.45; cursor: default; box-shadow: none; }

.card { background: var(--paper); border-radius: 22px; box-shadow: var(--paper-shadow); }
.preview { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.preview-title { font-family: var(--display); font-weight: 700; font-size: 26px; margin: 0 0 2px; }
.preview-head p { margin: 0; }
.code-btn { background: none; border: 0; padding: 0; color: var(--lavender-text); font-weight: 800; text-decoration: underline dotted; text-underline-offset: 3px; }
.preview-chart { height: 210px; padding: 10px 6px 4px; border-radius: 16px; background: var(--peach); }
.preview-chart svg { display: block; filter: drop-shadow(0 2px 2px rgba(122, 78, 58, 0.18)); }
.preview-chart rect { cursor: pointer; }
/* A new ride grows in from the left; a shuffled one drops away first. */
.preview-chart .step-bar { transform-box: fill-box; transform-origin: 50% 100%; }
.preview-chart svg.grow .step-bar { animation: bar-grow 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.15) both; animation-delay: calc(var(--along) * 240ms); }
.preview-chart svg.drop .step-bar { animation: bar-drop 0.12s ease-in both; }
@keyframes bar-grow { from { transform: scaleY(0); } }
@keyframes bar-drop { to { transform: scaleY(0); } }
#btn-shuffle svg, .type-new svg { transition: transform 0.35s cubic-bezier(0.3, 1.4, 0.5, 1); }
#btn-shuffle svg.spun, .type-new svg.spun { transform: rotate(360deg); }
.preview-chart svg.picked .step-bar:not(.on) { opacity: 0.4; }
.preview-chart-wrap { position: relative; }
.preview-pick {
  position: absolute; top: 8px; transform: translateX(-50%); pointer-events: none; margin: 0; width: max-content; max-width: min(250px, 80%);
  background: var(--ink); color: var(--cream); padding: 7px 12px; border-radius: 12px; font-size: 12px; font-weight: 700; line-height: 1.45;
  box-shadow: 0 6px 16px rgba(59, 51, 69, 0.25);
}
.preview-pick::after {
  content: ''; position: absolute; top: 100%; left: var(--caret, 50%); transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: var(--ink); border-bottom: 0;
}
.preview-pick b { display: block; font-size: 13px; font-weight: 800; }
.axis { display: flex; justify-content: space-between; font-size: 12px; font-weight: 800; color: var(--muted); }
.zones { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.zones span { display: inline-flex; align-items: center; gap: 6px; }
.zones i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stats:has(> .stat[hidden]) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { background: var(--sand); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat-num { font-family: var(--display); font-weight: 700; font-size: 24px; }
.stat-label { font-size: 12px; font-weight: 800; color: var(--muted); }
.setup-right { display: flex; flex-direction: column; gap: 16px; padding-top: 58px; }
.mode-toggle { max-width: 420px; }
.nudge { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: #FFF6DE; border: 2px dashed var(--mustard-deep); line-height: 1.4; }
.nudge .link { padding: 0; font-size: 13px; }
.nudge.good { background: #EAF4E8; border-color: var(--sage); }
.top-nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-right: auto; padding-left: 12px; }
.top-nav .link { text-decoration: none; color: var(--ink-soft); font-size: 15px; }
.top-nav .link:hover { color: var(--lavender-text); text-decoration: underline; text-underline-offset: 3px; }
.top-nav .link[aria-current="page"] { color: var(--ink); text-decoration: underline; text-decoration-thickness: 3px; text-decoration-color: var(--lavender-deep); text-underline-offset: 6px; }
.data-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 12px; }
/* The two cards stand the same height, with their buttons level at the bottom. */
.data-cards .stats-card { display: flex; flex-direction: column; align-items: flex-start; }
.data-cards .stats-card .btn { margin-top: auto; }
.backup-title { margin: 28px 0 4px; }
.stats-card .calib-table td:last-child { width: 1%; white-space: nowrap; }
.stats-card .link { font-size: 13px; padding: 0; }
.data-cards .btn { cursor: pointer; }
.stats-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats-card { padding: 20px 24px; margin-bottom: 16px; }
.stats-card .calib-table td, .stats-card .calib-table th { padding: 7px 6px; }
.stats-card .calib-table td:nth-child(2), .stats-card .calib-table th:nth-child(2) { text-align: left; padding-left: 24px; }

/* ---------- ride ---------- */
.ride-layout { display: flex; justify-content: center; align-items: flex-start; gap: 28px; flex-wrap: wrap; }
.panel-home { width: 400px; min-height: 720px; }
.panel {
  width: 400px; height: 720px; padding: 16px 20px 18px; display: flex; flex-direction: column; gap: 10px;
  background: var(--cream); border-radius: 26px; box-shadow: var(--paper-shadow-lg);
}
.panel-home.away {
  display: grid; place-items: center; border-radius: 26px; border: 2px dashed var(--lavender-deep); background: var(--lavender-soft);
}
.panel-home.away::before { content: 'The ride is in the floating window'; font-family: var(--display); font-weight: 600; font-size: 18px; color: var(--lavender-text); }
.pip-body { margin: 0; background: var(--cream); overflow: hidden; display: flex; justify-content: center; }
.pip-body .panel { border-radius: 0; box-shadow: none; flex-shrink: 0; transform-origin: top center; }
.panel-top { display: flex; align-items: center; gap: 10px; }
.total { display: inline-flex; align-items: baseline; gap: 5px; }
.total-num { font-family: var(--display); font-weight: 700; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.total-lbl { font-size: 13px; font-weight: 800; color: var(--muted); }
.total-bar { flex: 1; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.total-bar > i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--lavender); }
.panel-buttons { display: inline-flex; gap: 6px; position: relative; }
/* Sound: a small pop-up under the speaker button. */
.sound-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 6; width: 210px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px; background: var(--paper); border-radius: 16px;
  box-shadow: 0 2px 0 #EAD8C6, 0 12px 28px rgba(59, 51, 69, 0.22); font-size: 13px; font-weight: 800; color: var(--ink-soft);
}
.sound-row { display: flex; align-items: center; gap: 10px; }
.sound-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--coral-deep); }
.sound-row.check { cursor: pointer; }
.sound-row.check input { width: 18px; height: 18px; accent-color: var(--coral-deep); }
.scene-wrap {
  position: relative; width: 360px; height: 222px; flex-shrink: 0; border-radius: 22px; overflow: hidden;
  background: var(--peach); box-shadow: 0 2px 0 #EAD8C6, 0 8px 18px rgba(122, 78, 58, 0.12);
}
#scene { width: 360px; height: 222px; display: block; }
.scene-hud { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; pointer-events: none; }
.pill { padding: 6px 10px; border-radius: 10px; font-weight: 800; font-size: 14px; white-space: nowrap; box-shadow: 0 3px 8px rgba(122, 78, 58, 0.2); }
.pill:empty { display: none; }
.pill.paper { background: var(--paper); font-variant-numeric: tabular-nums; }
.pill.gap { font-family: var(--display); font-weight: 700; font-size: 24px; line-height: 1.1; padding: 6px 14px; border-radius: 12px; background: var(--paper); transform: rotate(-2deg); font-variant-numeric: tabular-nums; }
.pill.gap::after { content: attr(data-word); margin-left: 6px; font-family: var(--body); font-size: 14px; font-weight: 800; }
.pill.gap.ahead { background: var(--mint); }
.pill.gap.behind { background: var(--coral); }
.pill.gap.gate { background: var(--mustard); }
.pill.gap.changed { animation: gap-bounce 0.5s ease-out; }
@keyframes gap-bounce { 40% { transform: rotate(-2deg) scale(1.28); } }
.scene-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(251, 243, 234, 0.72);
  font-family: var(--display); font-weight: 700; font-size: 22px; text-align: center; padding: 24px;
}
/* Without a smart bike, the overlay is the start button, and then the count. */
.scene-overlay.tap { cursor: pointer; }
.scene-overlay.tap #overlay-text { padding: 10px 22px; border-radius: 14px; background: var(--mint); box-shadow: 0 3px 0 rgba(122, 78, 58, 0.25); }
.scene-overlay.count { font-size: 88px; }

/* Step countdown: the biggest thing in the window. */
.stage { padding: 12px 14px 12px; display: flex; flex-direction: column; gap: 6px; }
.cd-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.zone-chip { padding: 2px 9px; border-radius: 8px; font-family: var(--display); font-weight: 700; font-size: 13px; background: #9DB9F2; flex-shrink: 0; }
.step-label { font-weight: 800; font-size: 16px; white-space: nowrap; }
.next-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.next-label.soon { color: var(--ink); }
.cd-row { display: flex; gap: 10px; }
.cd-num { font-family: var(--display); font-weight: 700; font-size: 74px; line-height: 0.95; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.cd-row { align-items: baseline; padding-left: 2px; }
.cd-left { font-size: 15px; font-weight: 800; color: var(--muted); }
/* In or out of the saddle for this step; standing is the one that stands out. */
/* The spin class block this step belongs to. */
.block-label { align-self: flex-start; padding: 3px 10px; border-radius: 9px; background: var(--lavender-soft); color: var(--lavender-text); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.block-label.changed { animation: badge-pulse 0.6s ease-in-out 3; }
.block-chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 2px 0; }
.block-chips-title { flex-basis: 100%; font-size: 12px; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em; }
.chip-toggle { border: 2px solid var(--line); border-radius: 999px; padding: 4px 10px; background: transparent; color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 800; cursor: pointer; text-decoration: line-through; }
.chip-toggle[aria-pressed="true"] { background: var(--paper); border-color: var(--paper); color: var(--ink); text-decoration: none; box-shadow: 0 2px 0 #EAD8C6; }
.chip-toggle:disabled { opacity: 0.45; cursor: default; }
.badges { margin-left: auto; align-self: center; display: flex; flex-direction: column; gap: 5px; min-width: 132px; text-align: center; }
/* What to do this step, in a word. */
.action { padding: 5px 12px; border-radius: 12px; font-family: var(--display); font-weight: 700; font-size: 22px; line-height: 1.15; background: var(--sand); }
.action.push { background: #F7A593; box-shadow: 0 2px 0 var(--coral); }
.action.recover { background: #BFD1F7; }
.action.add { background: var(--mustard); box-shadow: 0 2px 0 var(--mustard-deep); }
.saddle { padding: 4px 10px; border-radius: 10px; background: var(--sand); color: var(--ink-soft); font-size: 12px; font-weight: 800; line-height: 1.2; }
.saddle.standing { background: var(--lavender); color: var(--ink); font-size: 14px; box-shadow: 0 2px 0 var(--lavender-deep); }
.action.changed, .saddle.changed { animation: badge-pulse 0.6s ease-in-out 3; }
@keyframes badge-pulse { 50% { transform: scale(1.12); } }
/* On a creeping climb, "Add 2" beats until the resistance is on. */
.action.add, .action.add.changed { animation: add-beat 0.9s ease-in-out infinite; }
@keyframes add-beat { 50% { transform: scale(1.1); box-shadow: 0 2px 0 var(--mustard-deep), 0 0 0 4px rgba(242, 193, 78, 0.4); } }
/* A push keeps beating for as long as it lasts. */
.action.push, .action.push.changed { animation: push-beat 1.1s ease-in-out infinite; }
@keyframes push-beat { 50% { transform: scale(1.1); box-shadow: 0 2px 0 var(--coral), 0 0 0 4px rgba(242, 118, 92, 0.3); } }
.cd-bar { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; margin: 2px 0 4px; }
.cd-bar > i { display: block; height: 100%; width: 0; border-radius: 5px; background: var(--sage); transition: width 0.2s linear; }
.stage.soon .cd-num { color: var(--coral-text); }
.stage.soon .cd-bar > i { background: var(--coral); }
.stage.soon { animation: soon-pulse 1s ease-in-out infinite; }
@keyframes soon-pulse { 50% { box-shadow: 0 2px 0 #EAD8C6, 0 0 0 4px rgba(242, 118, 92, 0.35); } }

/* Target vs now, side by side. "Now" is coloured by how close you are. */
.numbers { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.num-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.num-col { border-radius: 14px; padding: 6px 12px 8px; background: var(--sand); display: flex; flex-direction: column; min-width: 0; }
.num-lbl { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.num-big { display: block; font-family: var(--display); font-weight: 700; font-size: 56px; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num-arrow { margin-left: 8px; font-size: 40px; }
.num-aim { font-size: 15px; font-weight: 800; color: var(--ink-soft); margin-top: 2px; }
.num-aim b { font-family: var(--display); font-weight: 700; font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; }
/* Each tile is coloured by how you're doing on that number. */
.num-col.on { background: var(--sage); }
.num-col.low { background: var(--mustard); }
.num-col.high { background: #9DB9F2; }
.num-col.on .num-lbl, .num-col.low .num-lbl, .num-col.high .num-lbl { color: var(--ink-soft); }
/* Without a smart bike the tiles show the targets themselves, large. */
.panel.follow .num-aim { display: none; }
.panel.follow .num-big { font-size: 48px; padding: 4px 0 2px; }
.panel.follow .num-col.word .num-big { font-size: 32px; line-height: 1.1; margin: auto 0; }
.panel.follow .num-col.word.long .num-big { font-size: 25px; }
.stage-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.aside-line { margin: 0 2px; font-size: 12px; font-weight: 800; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.effort { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.effort-lbl { font-size: 12px; font-weight: 800; color: var(--muted); }
.effort .icon-btn { width: 34px; height: 34px; background: var(--sand); box-shadow: 0 2px 0 #E6D5C3; font-size: 20px; }
.effort-val { min-width: 52px; text-align: center; padding: 4px 6px; border-radius: 9px; font-family: var(--display); font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; background: var(--sand); }
.effort-val.up { background: #F7B3A4; }
.effort-val.down { background: #C9D8F7; }
.effort-val.flash, .num-aim b.flash { animation: effort-flash 0.5s ease-out; }
.num-aim b { display: inline-block; }
@keyframes effort-flash { from { transform: scale(1.25); } to { transform: scale(1); } }
/* After the finish, the route strip gives way to the way out. */
.done-box { display: flex; align-items: center; gap: 12px; font-size: 12px; font-weight: 800; color: var(--muted); }
.done-box .btn-start { flex: 1; min-height: 52px; font-size: 20px; position: relative; overflow: hidden; }
/* Once the pedals stop, the button darkens from the left as the ride runs out of time. */
.done-box .btn-start i { position: absolute; inset: 0 auto 0 0; width: 0; background: rgba(59, 51, 69, 0.28); transition: width 0.25s linear; }
.done-box .btn-start span { position: relative; }
.done-box > span { min-width: 9.5em; }
.route { padding: 8px 16px 10px; display: flex; flex-direction: column; gap: 4px; }
.route-head { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; font-weight: 800; color: var(--muted); }
#route-dist { color: var(--ink); font-size: 14px; }
#route-svg svg { display: block; filter: drop-shadow(0 1.5px 1.5px rgba(122, 78, 58, 0.18)); }

.ride-side { width: 300px; display: flex; flex-direction: column; gap: 16px; }
.side-card { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.side-card p { margin: 0; }
.side-title { font-family: var(--display); font-weight: 700; font-size: 20px; margin: 0; }
.seg-toggle { display: grid; grid-template-columns: 1fr 1fr; background: var(--sand); border-radius: 12px; padding: 4px; gap: 4px; }
.seg { border: 0; background: transparent; border-radius: 9px; min-height: 36px; font-weight: 800; font-size: 13px; }
.seg.on { background: var(--paper); box-shadow: 0 2px 0 #EAD8C6; }
.sim-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 14px; align-items: center; }
.sim-ctrl { display: inline-flex; align-items: center; gap: 10px; justify-self: end; }
.sim-val { font-family: var(--display); font-weight: 700; font-size: 20px; min-width: 40px; text-align: center; }

/* ---------- summary ---------- */
.eyebrow { font-family: var(--display); font-weight: 600; color: var(--muted); margin: 0; font-size: 16px; }
.sum-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px 24px; margin-bottom: 12px; }
.sum-head .title { margin: 0 0 4px; font-size: 38px; line-height: 1.15; }
.sum-head p { margin: 0; }
/* How far ahead or behind, picked out in the headline. */
.sum-gap { font-style: normal; white-space: nowrap; padding: 0 10px; border-radius: 12px; background: var(--mint); }
.sum-gap.behind { background: #F7B3A4; }
.sum-gap.best { background: var(--mustard); display: inline-block; }
.sum-gap.stamped { animation: best-stamp 0.5s ease-out; }
@keyframes best-stamp { 0% { transform: scale(1.5); } 60% { transform: scale(0.96); } 80% { transform: scale(1.03); } }
/* The ride's figures, small beside the headline. */
.sum-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.sum-chip { background: var(--paper); border-radius: 12px; box-shadow: 0 2px 0 #EAD8C6; padding: 6px 12px; font-size: 13px; font-weight: 800; color: var(--ink-soft); white-space: nowrap; }
.sum-chip b { font-family: var(--display); font-size: 17px; color: var(--ink); margin-left: 5px; font-variant-numeric: tabular-nums; }
.sum-chip small { margin-left: 6px; color: var(--muted); font-weight: 800; }
.sum-chip small.good { color: var(--teal-text); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--paper); border-radius: 18px; padding: 14px 18px; display: flex; flex-direction: column; gap: 2px; box-shadow: 0 2px 0 #EAD8C6; }
.tile-label { font-size: 12px; font-weight: 800; color: var(--muted); }
.tile-num { font-family: var(--display); font-weight: 700; font-size: 28px; }
.tile-sub { font-size: 13px; font-weight: 800; color: var(--muted); }
.tile-sub.good { color: var(--teal-text); }
.chart-card { padding: 16px 20px 18px; margin-bottom: 16px; }
.card-title { font-family: var(--display); font-weight: 700; font-size: 20px; margin: 0 0 8px; }
.legend { display: inline-flex; gap: 16px; font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
/* The ride chart is drawn for a wide card; on a phone it scrolls sideways rather than shrinking. */
.ride-chart { overflow-x: auto; }
.ride-chart-plot { position: relative; min-width: 640px; }
.ride-chart-plot svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.ride-chart-plot text { font-weight: 800; }
.ride-readout {
  position: absolute; transform: translateX(-50%); pointer-events: none; display: flex; gap: 16px;
  background: var(--ink); color: var(--cream); padding: 5px 14px; border-radius: 14px; font-size: 12px; font-weight: 800; white-space: nowrap;
}
.ride-readout i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
#ride-blocks { overflow-x: auto; }
/* A block's name over the chart and its line in the table pick each other out. */
.ride-chart-plot g[data-block] { cursor: default; }
.ride-chart-plot g.lit rect { stroke: var(--ink); stroke-width: 2; }
.ride-verdict { margin: 0 0 10px; font-weight: 800; line-height: 1.4; }
.ride-verdict:empty { display: none; }
/* Every other line is shaded, so a line is easy to follow across. */
.block-table tbody tr:nth-child(even) td { background: #F9F0E6; }
.block-table tbody tr.lit td { background: var(--sand); }
.block-table { width: 100%; border-collapse: collapse; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.block-table th { text-align: right; font-size: 12px; font-weight: 800; color: var(--muted); padding: 6px 8px; border-bottom: 2px solid var(--line); }
.block-table td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.block-table th:first-child, .block-table td:first-child { text-align: left; white-space: normal; }
.block-table small { margin-left: 4px; color: var(--coral-text); font-weight: 800; }
.block-table td.low { color: var(--coral-text); }
.block-table td.none { color: var(--muted); }
.bar { height: 12px; border-radius: 6px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: #F6A96B; }
.sum-blocks { padding: 18px 22px; max-width: 680px; }
.sum-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.sum-actions .btn-start { padding: 0 28px; }

/* ---------- dialogs & toast ---------- */
.dialog {
  border: 0; border-radius: 24px; padding: 26px; width: min(520px, calc(100vw - 32px));
  background: var(--cream); color: var(--ink); box-shadow: 0 20px 60px rgba(59, 51, 69, 0.3);
}
.dialog::backdrop { background: rgba(59, 51, 69, 0.35); }
.dialog p { line-height: 1.45; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; }
.field input { font: inherit; font-size: 20px; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--track); background: var(--paper); color: var(--ink); text-transform: uppercase; }
.calib-dots { display: flex; gap: 6px; margin: 2px 0 12px; }
.calib-dots i { flex: 1; height: 8px; border-radius: 4px; background: var(--track); }
.calib-dots i.done { background: var(--sage); }
.calib-dots i.now { background: var(--mustard); }
.calib-ring { display: flex; align-items: center; gap: 14px; margin-top: 14px; line-height: 1.35; }
.calib-ring svg { width: 64px; height: 64px; flex-shrink: 0; }
.calib-ring circle { transition: stroke-dasharray 0.3s; }
.calib-ring text { font-family: var(--display); font-weight: 700; font-size: 20px; fill: var(--ink); }
.calib-ring b { display: block; font-family: var(--display); font-size: 19px; }
.big-number { display: block; font-family: var(--display); font-weight: 700; font-size: 56px; line-height: 1; }
.big-number small { font-size: 20px; color: var(--muted); }
.calib-ask { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 8px 0; }
.calib-ask > div { background: var(--paper); border-radius: 16px; padding: 10px 14px; box-shadow: 0 2px 0 #EAD8C6; }
.calib-ask .stepper { margin-top: 8px; }
.calib-ask-lbl { display: block; font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.calib-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.calib-table td, .calib-table th { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.calib-table th:first-child, .calib-table td:first-child { text-align: left; }
.calib-banner {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 24px; padding: 18px 22px;
  border-radius: 22px; background: #FFF6DE; border: 3px solid var(--mustard-deep); box-shadow: var(--paper-shadow);
}
.resume-banner { background: var(--lavender-soft); border-color: var(--lavender-deep); }
.calib-banner-text { flex: 1 1 320px; }
.calib-banner .card-title { margin-bottom: 2px; }
.calib-banner p { margin: 0; line-height: 1.4; }
.dialog-wide { width: min(620px, calc(100vw - 32px)); }
.model-chart { position: relative; background: var(--paper); border-radius: 16px; padding: 12px 8px 6px; box-shadow: 0 2px 0 #EAD8C6; }
.model-chart svg { display: block; }
.model-legend { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px; margin: 0 6px 6px; font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.model-tip {
  position: absolute; top: 34px; pointer-events: none; background: var(--ink); color: var(--cream);
  padding: 6px 10px; border-radius: 10px; font-size: 12px; font-weight: 800; line-height: 1.5; white-space: nowrap;
}
.model-tip i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.model-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.model-facts .stat { background: var(--paper); padding: 10px 14px; }
.model-facts .stat-num { font-size: 20px; }
.calib-table .est td { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  background: var(--ink); color: var(--cream); padding: 12px 18px; border-radius: 14px; font-weight: 800;
  box-shadow: 0 10px 30px rgba(59, 51, 69, 0.3); max-width: calc(100vw - 32px);
}

@media (max-width: 960px) {
  .setup-grid { grid-template-columns: 1fr; }
  .setup-right { padding-top: 0; }
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .browser-notice { margin-left: 16px; margin-right: 16px; }
}

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .topbar { padding-top: 12px; padding-bottom: 12px; gap: 10px; }
  .top-nav { padding-left: 0; order: 3; flex-basis: 100%; }
  .title { font-size: 30px; }
  .block-table td, .block-table th { padding-left: 4px; padding-right: 4px; }
  /* No room for every column: the watts go, as the column least to act on. */
  .block-table th:nth-child(4), .block-table td:nth-child(4) { display: none; }
  .sum-blocks, .chart-card { padding: 14px; }

  /* Build a ride: one column, with Start always in reach at the bottom of the screen. */
  /* Stacked in one column, the parts need more air between them than side by side. */
  #setup-title { margin-top: 22px; }
  .steps { margin-top: 16px; margin-bottom: 36px; }
  .setup-grid { gap: 52px; }
  .types, .type-list { grid-template-columns: 1fr; }
  .type.wide { grid-column: auto; }
  .seg-toggle.effort-words { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .preview { padding: 16px; }
  .preview-head { flex-wrap: wrap; }
  /* Start is docked to the bottom edge as a full-width bar, so it reads as part
     of the screen and not as a button floating over the page. */
  #screen-setup { padding-bottom: 96px; }
  .setup-right .btn-start {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; width: 100%;
    min-height: 64px; padding-bottom: env(safe-area-inset-bottom, 0px); border-radius: 0;
    box-shadow: 0 -3px 0 var(--coral-deep), 0 -10px 24px rgba(59, 51, 69, 0.18);
  }
  .setup-right .btn-start:active { transform: none; }

  /* The ride fills the screen: the header steps aside and the panel is scaled to fit. */
  body.riding .topbar { display: none; }
  body.riding main { padding: 8px 8px 24px; }
  .ride-layout { gap: 16px; }
  .ride-side { width: 100%; }

  /* Statistics: two tiles a row, and the table keeps to the columns that matter. */
  .stats-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-card { padding: 16px; overflow-x: auto; }
  .stats-card svg { min-width: 520px; }
  .stats-card .calib-table th:nth-child(4), .stats-card .calib-table td:nth-child(4),
  .stats-card .calib-table th:nth-child(5), .stats-card .calib-table td:nth-child(5) { display: none; }
  .stats-card .calib-table td:nth-child(2), .stats-card .calib-table th:nth-child(2) { padding-left: 8px; }
  .data-cards { grid-template-columns: 1fr; }

  .sum-head .title { font-size: 28px; }
  .sum-actions { flex-direction: column; }

  .dialog { padding: 18px; }
  .model-facts { grid-template-columns: 1fr; }
  .calib-banner { padding: 14px 16px; }
}
@media (max-width: 460px) {
  .durations { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .steps { gap: 8px; }
  .step { padding: 12px 6px 8px 10px; }
}
