:root {
  color-scheme: light;
  --orange: #fc4c02;
  --orange-dark: #d73f00;
  --ink: #161718;
  --muted: #687079;
  --line: #e4e7eb;
  --paper: #ffffff;
  --soft: #f5f6f8;
  --mint: #00a878;
  --cyan: #0891b2;
  --danger: #c92a2a;
  --shadow: 0 16px 40px rgba(18, 21, 25, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--soft);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(252, 76, 2, 0.10), rgba(245, 246, 248, 0) 320px),
    var(--soft);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) 14px calc(88px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 12px;
  backdrop-filter: blur(18px);
}

.brand,
.icon-action,
.bottom-nav button,
.record-card {
  border: 0;
  cursor: pointer;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 26px 13px, #ffffff 0 4px, transparent 5px),
    linear-gradient(135deg, var(--orange), #ff7a1a);
  box-shadow: 0 10px 24px rgba(252, 76, 2, 0.34);
  position: relative;
  flex: 0 0 auto;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  bottom: 8px;
  width: 11px;
  height: 11px;
  border: 2px solid #fff;
  border-radius: 50%;
}

.brand-mark::before {
  left: 7px;
}

.brand-mark::after {
  right: 6px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  line-height: 1.1;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.icon-action {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--orange);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
}

.status-banner {
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid rgba(252, 76, 2, 0.24);
  border-radius: 8px;
  background: #fff7f2;
  color: #702300;
  box-shadow: 0 8px 22px rgba(112, 35, 0, 0.06);
}

.status-banner[data-type="success"] {
  border-color: rgba(0, 168, 120, 0.26);
  background: #eefaf6;
  color: #064b37;
}

.status-banner[data-type="info"] {
  border-color: rgba(0, 119, 204, 0.24);
  background: #eef7ff;
  color: #084b6f;
}

.status-banner[data-type="error"] {
  border-color: rgba(201, 42, 42, 0.28);
  background: #fff1f1;
  color: #7f1d1d;
}

.views {
  width: min(100%, 980px);
  margin: 0 auto;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.tracker-panel,
.summary-card,
.metric-card,
.map-section,
.settings-strip,
.chart-panel,
.best-panel {
  border: 1px solid rgba(22, 23, 24, 0.08);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 10px 28px rgba(18, 21, 25, 0.08);
}

.tracker-panel {
  display: grid;
  gap: 18px;
  padding: 20px;
  overflow: hidden;
}

.tracker-copy {
  display: grid;
  align-items: start;
  justify-content: start;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--orange-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 9vw, 3.7rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.state-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #edf7f3;
  color: #066144;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.ride-button {
  display: grid;
  place-items: center;
  width: min(74vw, 260px);
  aspect-ratio: 1;
  justify-self: center;
  border: 0;
  border-radius: 50%;
  background:
    linear-gradient(160deg, #ff7a1a, var(--orange) 58%, #c93500);
  color: #fff;
  box-shadow:
    0 20px 36px rgba(252, 76, 2, 0.34),
    inset 0 -12px 26px rgba(97, 22, 0, 0.18);
  font-size: clamp(1.55rem, 7vw, 2.35rem);
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.ride-button:active {
  transform: scale(0.98);
}

.ride-button.is-stop {
  background:
    linear-gradient(160deg, #ff4d4d, #e03131 58%, #a31212);
  box-shadow:
    0 20px 36px rgba(224, 49, 49, 0.30),
    inset 0 -12px 26px rgba(66, 0, 0, 0.18);
}

.ride-actions,
.dialog-actions,
.detail-header {
  display: flex;
  gap: 10px;
}

.ride-actions {
  justify-content: center;
}

.secondary-action,
.ghost-action,
.danger-action,
.save-action {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-weight: 800;
  cursor: pointer;
}

.secondary-action {
  background: #fff7f2;
  border-color: rgba(252, 76, 2, 0.36);
  color: var(--orange-dark);
}

.secondary-action:disabled,
.ghost-action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.ghost-action {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.danger-action {
  background: #fff1f1;
  color: var(--danger);
}

.save-action {
  background: var(--orange);
  color: #fff;
}

.compact {
  min-height: 38px;
}

.metrics-grid,
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.live-metrics,
.dashboard-grid,
.detail-stats {
  margin-top: 12px;
}

.metric-card,
.summary-card {
  min-width: 0;
  padding: 14px;
}

.metric-card span,
.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong,
.summary-card strong {
  display: block;
  margin-top: 5px;
  font-size: clamp(1.35rem, 7vw, 2.05rem);
  line-height: 1;
  letter-spacing: 0;
}

#durationValue,
#detailDuration {
  font-size: clamp(1.22rem, 6.2vw, 1.85rem);
}

.metric-card small,
.summary-card small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-weight: 700;
}

.primary-metric {
  border-color: rgba(252, 76, 2, 0.34);
  background: #fff7f2;
}

.highlight {
  background:
    linear-gradient(160deg, var(--orange), #ff7a1a);
  color: #fff;
  border-color: transparent;
}

.highlight span,
.highlight small {
  color: rgba(255, 255, 255, 0.82);
}

.map-section,
.chart-panel,
.best-panel,
.settings-strip {
  margin-top: 12px;
  padding: 14px;
}

.section-heading,
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.page-heading {
  display: block;
  margin: 10px 0 14px;
}

.page-heading.with-action {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
}

.page-heading.with-action .secondary-action {
  flex: 0 0 auto;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: right;
}

.map-surface {
  width: 100%;
  height: min(62vh, 390px);
  min-height: 280px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(0, 168, 120, 0.15), rgba(8, 145, 178, 0.12)),
    #e8ecef;
}

.map-surface.tall {
  height: min(68vh, 480px);
}

.leaflet-container {
  font: inherit;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.settings-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.settings-strip h2 {
  margin: 0;
}

.weight-control {
  display: grid;
  grid-template-columns: auto minmax(64px, 86px) auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.weight-control input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  font-weight: 900;
}

.ride-list {
  display: grid;
  gap: 10px;
}

.ride-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  width: 100%;
  padding: 14px;
  border: 1px solid rgba(22, 23, 24, 0.08);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
  box-shadow: 0 10px 28px rgba(18, 21, 25, 0.07);
  cursor: pointer;
}

.ride-item strong,
.ride-item small,
.ride-item span {
  display: block;
}

.ride-item strong {
  font-size: 1rem;
}

.ride-item .manual-badge {
  display: inline-flex;
  width: fit-content;
  margin: 6px 0 0;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef7ff;
  color: #084b6f;
  font-size: 0.72rem;
  font-weight: 900;
}

.ride-item small,
.ride-item span {
  margin-top: 4px;
  color: var(--muted);
}

.ride-item .ride-km {
  align-self: center;
  color: var(--orange-dark);
  font-size: 1.3rem;
  font-weight: 900;
}

.ride-item .route-preview-wrap {
  grid-column: 1 / -1;
  margin-top: 4px;
  color: inherit;
}

.route-preview,
.route-preview-wrap {
  min-width: 0;
}

.route-preview-svg {
  display: block;
  width: 100%;
  height: 118px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(252, 76, 2, 0.08), rgba(0, 168, 120, 0.08)),
    #f7f9fb;
}

.route-preview.large .route-preview-svg {
  height: 168px;
}

.route-preview-svg rect {
  fill: transparent;
}

.route-preview-shadow,
.route-preview-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.route-preview-shadow {
  stroke: rgba(22, 23, 24, 0.18);
  stroke-width: 9;
}

.route-preview-line {
  stroke: var(--orange);
  stroke-width: 5;
}

.route-preview-start {
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 3;
}

.route-preview-end {
  fill: var(--orange);
  stroke: #fff;
  stroke-width: 3;
}

.route-preview-empty {
  display: grid;
  place-items: center;
  min-height: 96px;
  border: 1px dashed #cdd2d8;
  border-radius: 8px;
  background: #f7f9fb;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.summary-route-card {
  display: grid;
  gap: 10px;
}

.empty-state {
  padding: 24px 16px;
  border: 1px dashed #cdd2d8;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.note-text {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.segmented-control button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.segmented-control button.is-selected {
  background: var(--orange);
  color: #fff;
}

.stats-overview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.analysis-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(22, 23, 24, 0.08);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(18, 21, 25, 0.07);
}

.analysis-card.featured {
  grid-column: 1 / -1;
  background:
    linear-gradient(135deg, #fff7f2, #ffffff 70%);
  border-color: rgba(252, 76, 2, 0.28);
}

.stats-overview .analysis-card:not(.featured):last-child {
  grid-column: 1 / -1;
}

.analysis-card span,
.analysis-card small {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.analysis-card span {
  font-size: 0.74rem;
  text-transform: uppercase;
}

.analysis-card strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.45rem, 7vw, 2.35rem);
  line-height: 1;
}

.analysis-card small {
  margin-top: 8px;
  font-size: 0.82rem;
  line-height: 1.35;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.distance {
  background: var(--orange);
}

.legend-dot.kcal {
  background: var(--mint);
}

.distance-chart {
  margin-top: 12px;
  min-height: 238px;
}

.stats-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-grid {
  stroke: #e8ebef;
  stroke-width: 1;
}

.chart-axis-line {
  stroke: #cfd5dc;
  stroke-width: 1.5;
}

.chart-axis,
.chart-label,
.chart-value {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chart-label {
  font-size: 12px;
}

.chart-value {
  fill: var(--ink);
  font-size: 12px;
}

.chart-bar {
  fill: url("#statsBarGradient");
}

.stats-svg .chart-bar {
  fill: var(--orange);
}

.kcal-line {
  fill: none;
  stroke: var(--mint);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  fill: #fff;
  stroke: var(--mint);
  stroke-width: 3;
}

.period-bars {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.period-bars.professional {
  gap: 10px;
}

.period-row-pro {
  display: grid;
  grid-template-columns: minmax(70px, 0.7fr) minmax(0, 1.6fr) minmax(82px, 0.8fr);
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(22, 23, 24, 0.07);
  border-radius: 8px;
  background: #fbfcfd;
}

.period-label strong,
.period-label small,
.period-values strong,
.period-values small {
  display: block;
}

.period-label strong {
  font-size: 0.92rem;
}

.period-label small,
.period-values small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.period-visual {
  display: grid;
  gap: 7px;
}

.mini-bar {
  display: block;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0f2;
}

.mini-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.mini-bar.distance i {
  background: linear-gradient(90deg, var(--orange), #ff8b3d);
}

.mini-bar.kcal i {
  background: linear-gradient(90deg, var(--mint), var(--cyan));
}

.period-values {
  text-align: right;
}

.period-values strong {
  font-size: 0.94rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 62px 1fr 74px;
  align-items: center;
  gap: 10px;
}

.bar-row span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0f2;
}

.bar-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--orange), var(--mint));
}

.bar-row strong {
  font-size: 0.86rem;
  text-align: right;
}

.best-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.record-card {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid rgba(22, 23, 24, 0.08);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
  box-shadow: 0 8px 20px rgba(18, 21, 25, 0.06);
}

.record-card span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.record-card strong {
  font-size: 1.55rem;
  line-height: 1;
}

.record-card small {
  color: var(--muted);
  font-weight: 700;
}

.record-card em {
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 700;
  line-height: 1.35;
}

.bottom-nav {
  position: fixed;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  z-index: 30;
  display: flex;
  gap: 4px;
  width: calc(100vw - 24px);
  min-width: 0;
  max-width: calc(100vw - 24px);
  margin: 0 auto;
  padding: 6px;
  border: 1px solid rgba(22, 23, 24, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transform: none;
  overflow: hidden;
}

.bottom-nav button {
  display: grid;
  place-items: center;
  gap: 2px;
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 900;
}

.bottom-nav button span {
  font-size: 1rem;
  line-height: 1;
}

.bottom-nav button.is-active {
  background: var(--orange);
  color: #fff;
}

.summary-dialog {
  width: min(calc(100vw - 28px), 520px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.summary-dialog::backdrop {
  background: rgba(10, 12, 14, 0.58);
}

.summary-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 1.7rem;
}

.summary-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.summary-metrics span {
  padding: 10px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-weight: 800;
}

.summary-metrics strong {
  color: var(--ink);
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 800;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  resize: vertical;
}

.field small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.calorie-preview {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid rgba(252, 76, 2, 0.24);
  border-radius: 8px;
  background: #fff7f2;
}

.calorie-preview span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.calorie-preview strong {
  color: var(--orange-dark);
  font-size: 2rem;
  line-height: 1;
}

.calorie-preview small {
  color: var(--muted);
  font-weight: 700;
}

.dialog-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

body.is-riding {
  background:
    linear-gradient(180deg, rgba(252, 76, 2, 0.10), rgba(245, 246, 248, 0) 320px),
    var(--soft);
  color: var(--ink);
}

body.is-riding .topbar,
body.is-riding .brand small,
body.is-riding .section-heading span {
  color: var(--muted);
}

body.is-riding .tracker-panel,
body.is-riding .metric-card,
body.is-riding .map-section {
  background: var(--paper);
  border-color: rgba(22, 23, 24, 0.08);
  box-shadow: 0 10px 28px rgba(18, 21, 25, 0.08);
}

body.is-riding .metric-card span,
body.is-riding .metric-card small {
  color: var(--muted);
}

body.is-riding .primary-metric {
  background: #fff7f2;
  border-color: rgba(252, 76, 2, 0.34);
}

body.is-riding .ghost-action {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

body.is-riding .bottom-nav {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(22, 23, 24, 0.08);
}

body.is-riding .bottom-nav button.is-active {
  background: var(--orange);
  color: #fff;
}

@media (max-width: 440px) {
  .page-heading.with-action .secondary-action {
    width: 100%;
  }

  .manual-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 720px) {
  .app-shell {
    padding-inline: 24px;
  }

  .tracker-panel {
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 26px;
  }

  .tracker-copy {
    display: block;
  }

  .ride-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .metrics-grid,
  .dashboard-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .best-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats-overview {
    grid-template-columns: 1.45fr repeat(3, minmax(0, 1fr));
  }

  .analysis-card.featured {
    grid-column: auto;
  }

  .stats-overview .analysis-card:not(.featured):last-child {
    grid-column: auto;
  }
}

@media (min-width: 980px) {
  .tracker-panel {
    grid-template-columns: 1fr auto auto;
  }

  .ride-actions {
    grid-column: auto;
    flex-direction: column;
  }

  .metrics-grid,
  .dashboard-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
