:root {
  color-scheme: light dark;
  --bg: #f4f3ef;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: rgba(255, 255, 255, 0.9);
  --surface-dark: rgba(22, 22, 24, 0.78);
  --text: #171719;
  --muted: #6f717a;
  --hairline: rgba(16, 18, 27, 0.08);
  --accent: #1274ff;
  --accent-strong: #0c5ad4;
  --success: #11a267;
  --warning: #e6872d;
  --shadow: 0 24px 60px rgba(20, 24, 35, 0.12);
  --radius-lg: 28px;
  --radius-md: 22px;
  --radius-sm: 16px;
  --spacing: 16px;
  --spacing-lg: 24px;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Segoe UI", sans-serif;
  --section-base: #d6e8ff;
  --section-cardio: #ffe1c7;
  --section-machines: #d7f1e1;
  --section-core: #efe0ff;
  --section-halters: #ffe0e5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1014;
    --surface: rgba(23, 24, 28, 0.74);
    --surface-strong: rgba(28, 29, 34, 0.94);
    --text: #f3f4f7;
    --muted: #a1a5b3;
    --hairline: rgba(255, 255, 255, 0.08);
    --accent: #5da2ff;
    --accent-strong: #7bb5ff;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(18, 116, 255, 0.14), transparent 30%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent 20%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  min-height: 100svh;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: none;
  color: inherit;
}

.app-shell {
  width: min(100%, 860px);
  margin: 0 auto;
  min-height: 100svh;
  padding:
    max(18px, env(safe-area-inset-top))
    16px
    calc(110px + env(safe-area-inset-bottom))
    16px;
}

.topbar,
.status-strip,
.hero-panel,
.action-bar,
.exercise-item,
.sheet__panel {
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  animation: rise-in 380ms ease-out both;
}

.topbar__meta h1,
.hero-panel h2,
.sheet__header h3,
.section__title,
.exercise-item__name {
  margin: 0;
}

.topbar__meta h1 {
  font-size: clamp(1.8rem, 6vw, 2.5rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.4rem;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--hairline);
  border-radius: 20px;
  background: var(--surface);
  animation: rise-in 460ms ease-out both;
}

.status-strip__label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

.status-strip__value {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.status-pill {
  min-width: 78px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(17, 162, 103, 0.12);
  color: var(--success);
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.status-pill.is-offline {
  background: rgba(230, 135, 45, 0.14);
  color: var(--warning);
}

.workspace {
  display: grid;
  gap: 18px;
}

.hero-panel {
  padding: 22px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--surface-strong), var(--surface));
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
  animation: rise-in 540ms ease-out both;
}

.hero-panel h2 {
  font-size: clamp(1.5rem, 5.2vw, 2rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.hero-panel__copy {
  margin: 12px 0 0;
  max-width: 34ch;
  color: var(--muted);
  line-height: 1.45;
}

.section-list {
  display: grid;
  gap: 14px;
}

.section {
  border-radius: var(--radius-md);
  overflow: hidden;
  overflow: clip;
  background: color-mix(in srgb, var(--section-color, var(--section-base)) 16%, transparent);
}

.section__header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 64px;
  padding: 18px;
  background: color-mix(in srgb, var(--section-color, var(--section-base)) 70%, transparent);
  color: var(--text);
  text-align: left;
}

.section__header:after {
  content: "";
  position: absolute;
  inset: auto 18px 0;
  height: 1px;
  background: var(--hairline);
}

.section__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.section__title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section__count,
.section__chevron {
  color: var(--muted);
  font-size: 0.95rem;
}

.section__chevron {
  transition: transform 180ms ease;
}

.section.is-open .section__chevron {
  transform: rotate(90deg);
}

.section__body {
  display: grid;
  gap: 10px;
  padding: 10px 0 0;
}

.exercise-item {
  margin: 0 6px 6px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
  animation: rise-in 240ms ease both;
}

.exercise-item.is-complete {
  border-color: color-mix(in srgb, var(--success) 35%, var(--hairline));
}

.exercise-item__top,
.exercise-item__defaults,
.exercise-item__fields,
.exercise-item__notes {
  display: flex;
  align-items: center;
}

.exercise-item__top {
  justify-content: space-between;
  gap: 12px;
}

.exercise-item__title {
  display: grid;
  gap: 4px;
}

.exercise-item__name {
  font-size: 1.05rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.exercise-item__defaults {
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(18, 116, 255, 0.09);
  color: var(--accent);
  font-weight: 600;
}

.check-toggle {
  position: relative;
  width: 52px;
  height: 32px;
}

.check-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.check-toggle span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(127, 134, 154, 0.24);
  transition: background 160ms ease;
}

.check-toggle span:after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
  transition: transform 160ms ease;
}

.check-toggle input:checked + span {
  background: var(--success);
}

.check-toggle input:checked + span:after {
  transform: translateX(20px);
}

.exercise-item__fields {
  gap: 10px;
  margin-top: 14px;
  align-items: stretch;
  flex-wrap: wrap;
}

.field {
  min-width: 0;
  flex: 1;
  min-width: 88px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.field input,
.exercise-item__notes textarea {
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  .field input,
  .exercise-item__notes textarea {
    background: rgba(255, 255, 255, 0.03);
  }
}

.exercise-item__notes {
  flex-direction: column;
  align-items: stretch;
  margin-top: 10px;
}

.exercise-item__notes textarea {
  resize: vertical;
  min-height: 88px;
}

.exercise-item__actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.exercise-item__hint {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.secondary-button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}

.action-bar {
  position: fixed;
  right: 16px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--hairline);
  border-radius: 28px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.action-bar__summary {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.primary-button {
  min-width: 148px;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.field input:disabled,
.exercise-item__notes textarea:disabled {
  opacity: 0.56;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
}

.sheet.is-open {
  display: block;
}

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 12, 0.34);
}

.sheet__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  gap: 14px;
  max-height: min(76svh, 680px);
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: var(--surface-strong);
  animation: sheet-up 220ms ease both;
}

.sheet__grabber {
  width: 42px;
  height: 5px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--hairline);
}

.sheet__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.sheet__content {
  overflow: auto;
  padding-bottom: 4px;
}

.history-list,
.summary-list {
  display: grid;
  gap: 12px;
}

.history-item,
.summary-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--hairline);
}

.history-item:last-child,
.summary-item:last-child {
  border-bottom: 0;
}

.history-item__row,
.summary-item__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-item__title,
.summary-item__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.history-item__meta,
.summary-item__meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 640px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .hero-panel,
  .status-strip,
  .exercise-item,
  .action-bar {
    border-radius: 22px;
  }

  .exercise-item__top {
    align-items: flex-start;
  }

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

  .action-bar {
    gap: 10px;
  }

  .primary-button {
    min-width: 132px;
  }
}

@media (max-width: 420px) {
  .status-strip,
  .action-bar,
  .history-item__row,
  .summary-item__row {
    align-items: flex-start;
    flex-direction: column;
  }

  .exercise-item__fields {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(22px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
