:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #020617;
  color: #e2e8f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
}

button,
input,
select {
  border: 1px solid #334155;
  border-radius: 0.7rem;
  font: inherit;
  padding: 0.75rem 0.9rem;
}

button {
  background: #38bdf8;
  color: #082f49;
  cursor: pointer;
  font-weight: 700;
}

button.danger {
  background: #ef4444;
  color: #450a0a;
}

button.secondary {
  background: #334155;
  color: #e2e8f0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  background: #0f172a;
  color: #f8fafc;
  width: 100%;
}

label {
  color: #94a3b8;
  display: grid;
  font-size: 0.9rem;
  gap: 0.35rem;
}

h1,
h2,
p {
  margin: 0;
}

.shell {
  margin: 0 auto;
  max-width: 980px;
  padding: 1rem;
}

header {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.header-actions {
  align-items: center;
  display: flex;
  gap: 0.75rem;
}

.icon-button {
  align-items: center;
  aspect-ratio: 1;
  background: #1e293b;
  color: #e2e8f0;
  display: inline-grid;
  font-size: 1.2rem;
  justify-content: center;
  padding: 0.55rem;
}

.eyebrow {
  color: #38bdf8;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pill {
  background: #172554;
  border: 1px solid #1d4ed8;
  border-radius: 999px;
  color: #bfdbfe;
  padding: 0.35rem 0.65rem;
}

.card {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 1rem;
  margin: 0.85rem 0;
  padding: 0.85rem;
}

.modal-backdrop {
  align-items: center;
  background: rgb(2 6 23 / 78%);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 1rem;
  position: fixed;
  z-index: 10;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 1rem;
  box-shadow: 0 24px 80px rgb(0 0 0 / 45%);
  max-height: min(90vh, 760px);
  max-width: 860px;
  overflow: auto;
  padding: 1rem;
  width: 100%;
}

.modal h3 {
  color: #cbd5e1;
  margin: 1rem 0 0.75rem;
}

.hidden {
  display: none !important;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.inline {
  display: flex;
  gap: 0.5rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.section-header {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.metrics {
  align-items: stretch;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.metric {
  align-items: stretch;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid #334155;
  border-radius: 1rem;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  padding: 0.8rem;
}

.metric:not(.graph-card) {
  align-items: center;
  text-align: center;
}

.graph-card {
  background: #0f172a;
  gap: 0.4rem;
}

.graph-card .section-header {
  align-items: center;
  margin-bottom: 0;
}

.graph-card h2 {
  display: none;
}

.metric span,
.metric small {
  color: #94a3b8;
}

.metric strong {
  display: block;
  font-size: clamp(1.85rem, 6vw, 3.6rem);
  line-height: 1;
  margin: 0.35rem 0;
  min-height: 1em;
}

.metric-subvalue {
  color: #94a3b8;
  font-size: 0.85rem;
  margin-top: 0.45rem;
}

.power-meter {
  align-self: stretch;
  display: grid;
  gap: 0.2rem;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  margin-top: 0.55rem;
}

.metric > :last-child {
  margin-top: auto;
}

.power-segment {
  background: #1e293b;
  clip-path: polygon(0 0, 72% 0, 100% 50%, 72% 100%, 0 100%, 28% 50%);
  height: 0.85rem;
  opacity: 0.35;
}

.power-segment.active {
  opacity: 1;
}

.power-scale {
  align-self: stretch;
  color: #94a3b8;
  display: flex;
  font-size: 0.8rem;
  justify-content: space-between;
  margin-top: 0.35rem;
}

.heart-graph {
  align-self: stretch;
  height: 44px;
  margin-top: 0.35rem;
  overflow: visible;
  width: 100%;
}

.relationship-graph {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 0.75rem;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.relationship-graph .graph-labels .graph-power,
.relationship-graph .graph-labels .graph-cadence,
.relationship-graph .graph-labels .graph-speed,
.relationship-graph .graph-labels .graph-heart {
  fill: currentColor;
  stroke: none;
}

.graph-grid line {
  stroke: #1e293b;
  stroke-width: 1;
}

.graph-labels text {
  font-size: 12px;
}

.graph-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  line-height: 1.15;
  margin-top: 0.15rem;
}

.graph-header-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
  min-width: 0;
}

.info-button {
  align-items: center;
  background: #1e293b;
  border-color: #475569;
  border-radius: 50%;
  color: #bfdbfe;
  display: inline-grid;
  font-size: 0.8rem;
  font-weight: 800;
  height: 1.45rem;
  justify-content: center;
  padding: 0;
  width: 1.45rem;
}

.graph-legend span {
  font-size: 0.76rem;
}

.graph-live-button {
  font-size: 0.75rem;
  padding: 0.35rem 0.5rem;
}

.graph-power {
  color: #f97316;
  stroke: #f97316;
}

.graph-cadence {
  color: #38bdf8;
  stroke: #38bdf8;
}

.graph-speed {
  color: #22c55e;
  stroke: #22c55e;
}

.graph-heart {
  color: #ef4444;
  stroke: #ef4444;
}

.cadence-icon,
.speed-icon {
  align-self: stretch;
  height: 44px;
  margin-top: 0.35rem;
  overflow: visible;
  width: 100%;
}

.cadence-icon circle,
.cadence-icon line,
.cadence-icon rect,
.speed-icon circle,
.speed-icon line,
.speed-icon path {
  fill: none;
  stroke: #38bdf8;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.cadence-icon circle,
.speed-icon circle {
  fill: #0f172a;
}

#cadenceCrank {
  transform-box: fill-box;
  transform-origin: center;
}

.speed-icon .motion-lines {
  opacity: var(--speed-lines-opacity, 0.2);
  transform: scaleX(var(--speed-lines-scale, 0.35));
  transform-box: fill-box;
  transform-origin: right center;
}

.speed-icon .cyclist {
  transform: translateX(var(--speed-rider-offset, 0));
}

.heart-graph line,
.heart-tail line {
  fill: none;
  stroke: #ef4444;
  stroke-linecap: round;
  stroke-width: 3;
}

.heart-baseline {
  opacity: 0.45;
}

.heart-tail,
.heart-dot {
  opacity: 0;
}

.heart-graph.active .heart-baseline {
  opacity: 1;
  filter: drop-shadow(0 0 8px rgb(239 68 68 / 70%));
}

.heart-graph.active .heart-tail,
.heart-graph.active .heart-dot {
  opacity: 1;
}

.heart-dot {
  fill: #ef4444;
  stroke: #fecaca;
  stroke-width: 1.2;
}

.heart-graph.active .heart-dot {
  filter: drop-shadow(0 0 8px rgb(239 68 68 / 80%));
}

#sessions {
  display: grid;
  gap: 0.5rem;
}


.session-row {
  align-items: start;
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 0.75rem;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1.2fr 1fr 1fr auto auto auto auto;
  padding: 0.75rem;
}

.session-row label {
  font-size: 0.75rem;
}

.session-row input,
.session-row select {
  padding: 0.55rem 0.65rem;
}

.session-row button {
  align-self: end;
  padding: 0.55rem 0.75rem;
}

.session-meta {
  color: #94a3b8;
  font-size: 0.85rem;
}

@media (max-width: 820px) {
  .session-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .shell {
    padding: 0.55rem;
  }

  header {
    align-items: flex-start;
    gap: 0.5rem;
  }

  .header-actions {
    gap: 0.4rem;
    min-width: 0;
  }

  .pill {
    font-size: 0.82rem;
    max-width: 13rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  h1 {
    font-size: 1.75rem;
  }

  button,
  input,
  select {
    padding: 0.6rem 0.7rem;
  }

  .card {
    margin: 0.65rem 0;
    padding: 0.65rem;
  }

  .metrics {
    display: grid;
    gap: 0.55rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-items: stretch;
  }

  .metric {
    border-radius: 0.8rem;
    height: 132px;
    padding: 0.65rem;
    width: auto;
  }

  .phone-centered-card {
    grid-column: 1 / -1;
    justify-self: center;
    width: calc((100% - 0.55rem) / 2);
  }

  .metric span,
  .metric small,
  .metric-subvalue,
  .session-meta {
    font-size: 0.74rem;
  }

  .graph-legend span {
    font-size: 0.62rem;
  }

  .graph-card {
    gap: 0.5rem;
    grid-column: 1 / -1;
    height: 245px;
  }

  .relationship-graph {
    flex: 0 0 165px;
    min-height: 165px;
  }

  .graph-labels text {
    font-size: 12px;
  }

  .graph-line {
    stroke-width: 3;
  }

  .metric .graph-title-text {
    font-size: 0;
  }

  .metric .graph-title-text::after {
    content: "Graph";
    font-size: 0.78rem;
  }

  .graph-card .session-meta {
    display: none;
  }

  .graph-live-button {
    font-size: 0;
    padding: 0.35rem 0.45rem;
  }

  .graph-live-button::after {
    content: "Live";
    font-size: 0.72rem;
  }
}

#log {
  color: #cbd5e1;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}
