:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --ink: #1d2520;
  --muted: #66736b;
  --line: #dbe2da;
  --accent: #256d58;
  --accent-strong: #174d3e;
  --warning: #b45309;
  --complete: #2f7d32;
  --radius: 8px;
  --bottom-action-reserve: 280px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

button {
  font: inherit;
  overflow-wrap: anywhere;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: clamp(12px, 4vw, 20px);
}

.loading-panel {
  min-height: 60vh;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.topbar {
  display: grid;
  gap: 18px;
  padding: 20px 0 18px;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.current-card h2,
.overview-card h2,
.workout-list h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.1;
}

.day-label,
.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 700;
}

.topbar-summary,
.current-note,
.overview-card p,
.overview-modules,
.empty-state,
.timer-done {
  color: var(--muted);
}

.topbar-summary {
  max-width: 72ch;
  margin: 10px 0 0;
}

.topbar-meta {
  display: grid;
  align-content: end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.progress-bar {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebe4;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 18px 0 0;
  padding-bottom: calc(var(--bottom-action-reserve) + env(safe-area-inset-bottom));
}

.current-card,
.overview-card,
.workout-list,
.details-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.current-card {
  padding: 20px;
}

.current-card h2 {
  font-size: clamp(1.5rem, 5vw, 2.35rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.current-stats {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.current-stats div {
  display: grid;
  gap: 2px;
  padding: 12px;
  border-radius: 6px;
  background: #f5f8f3;
}

.current-stats dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.current-stats dd {
  margin: 0;
  font-weight: 700;
}

.current-note {
  margin: 14px 0 0;
}

.timer-display {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid #cbd9d1;
  border-radius: 8px;
  background: #eff6f1;
}

.timer-label {
  min-width: 0;
  color: var(--accent-strong);
  font-weight: 700;
}

.timer-value {
  font-size: clamp(1.8rem, 8vw, 3rem);
  line-height: 1;
}

.timer-done {
  margin: 10px 0 0;
  color: var(--warning);
  font-weight: 700;
}

.overview-card {
  padding: 18px;
}

.module-selector {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.sync-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.sync-panel summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  min-height: 44px;
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 700;
}

.sync-panel summary strong {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.sync-fields {
  display: grid;
  gap: 10px;
  padding: 0 18px 16px;
}

.sync-fields label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.sync-fields input {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fbfdf9;
  font: inherit;
}

.module-selector-head {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.module-selector h2,
.module-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.module-selector h2 {
  font-size: 1.05rem;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.segmented-button {
  min-height: 44px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  background: #f7faf6;
  cursor: pointer;
  font-weight: 700;
}

.segmented-button.is-active {
  color: #fbfdf9;
  border-color: var(--accent);
  background: var(--accent);
}

.module-grid {
  display: grid;
  gap: 0;
}

.module-card {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  box-shadow: inset 4px 0 0 transparent;
}

.module-card:first-child {
  border-top: 0;
}

.module-card.is-included {
  background: #f3f8f1;
  box-shadow: inset 4px 0 0 var(--accent);
}

.module-card-main {
  min-width: 0;
}

.module-card h3 {
  font-size: 1rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.module-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.module-card-actions {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 8px;
}

.overview-number {
  margin: 10px 0 6px;
  color: var(--accent-strong);
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
}

.overview-card p {
  margin: 8px 0 0;
}

.overview-modules {
  font-size: 0.9rem;
}

.workout-list {
  overflow: hidden;
}

.workout-list h2 {
  padding: 16px 18px 8px;
  font-size: 1.05rem;
}

.workout-list ol {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.workout-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 6px 10px;
  align-items: start;
  min-width: 0;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.workout-row.is-current {
  background: #edf6ef;
  box-shadow: inset 4px 0 0 var(--accent);
}

.workout-row.is-complete {
  color: var(--muted);
  background: #f7faf6;
}

.workout-row.is-complete .row-status {
  border-color: #cfe1cf;
  color: var(--complete);
  background: #eef7ee;
}

.row-status {
  display: inline-grid;
  min-width: 36px;
  min-height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.row-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.row-main strong,
.row-target,
.row-rest,
.row-note {
  min-width: 0;
  overflow-wrap: anywhere;
}

.row-target,
.row-rest,
.row-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.row-rest,
.row-note {
  grid-column: 2;
  display: block;
  font-size: 0.82rem;
  line-height: 1.35;
}

.row-note:empty {
  display: none;
}

.row-rest:empty {
  display: none;
}

.details-panel {
  display: grid;
  gap: 0;
}

.details-panel details + details {
  border-top: 1px solid var(--line);
}

.details-panel summary {
  min-height: 44px;
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 700;
}

.details-panel ul,
.details-panel p {
  margin: 0;
  padding: 0 18px 16px 34px;
  color: var(--muted);
}

.details-panel p {
  padding-left: 18px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  min-width: 44px;
  border-radius: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  color: #fbfdf9;
  background: var(--accent);
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-strong);
}

.secondary-button {
  color: var(--accent-strong);
  border-color: var(--line);
  background: var(--surface);
}

.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: #bacac0;
  background: #f3f7f2;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.start-button {
  width: 100%;
  margin-top: 18px;
}

.bottom-actions {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 10px clamp(12px, 4vw, 20px) calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.96);
}

.bottom-actions > button {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
}

.bottom-actions button:only-child {
  flex-basis: 100%;
}

.rest-quick-actions {
  display: flex;
  flex: 1 0 100%;
  flex-wrap: nowrap;
  gap: 8px;
}

.rest-quick-actions .secondary-button {
  flex: 1 1 0;
  min-width: 0;
  padding-right: 10px;
  padding-left: 10px;
}

@media (max-width: 390px) {
  :root {
    --bottom-action-reserve: 300px;
  }

  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .current-card,
  .overview-card {
    padding: 16px;
  }

  .timer-display {
    grid-template-columns: minmax(0, 1fr);
  }

  .timer-value {
    font-size: 2.2rem;
  }

  .bottom-actions > button,
  .rest-quick-actions .secondary-button {
    padding-right: 10px;
    padding-left: 10px;
  }

  .bottom-actions .primary-button {
    flex-basis: 100%;
  }
}

@media (min-width: 760px) {
  :root {
    --bottom-action-reserve: 128px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
    align-items: end;
  }

  .layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
    align-items: start;
  }

  .current-card {
    grid-column: 1;
  }

  .module-selector {
    grid-column: 1;
  }

  .sync-panel {
    grid-column: 1;
  }

  .workout-list {
    grid-column: 1;
  }

  .overview-card,
  .details-panel {
    grid-column: 2;
  }

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

  .module-card {
    grid-template-columns: minmax(0, 1fr) minmax(210px, 0.45fr);
    align-items: center;
  }

  .sync-panel summary {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .workout-row {
    grid-template-columns: 52px minmax(0, 1.4fr) minmax(80px, 0.45fr) minmax(180px, 1fr);
    align-items: center;
    padding: 14px 18px;
  }

  .row-rest,
  .row-note {
    display: block;
    grid-column: auto;
    font-size: 0.9rem;
    line-height: 1.5;
  }

  .bottom-actions {
    flex-wrap: nowrap;
  }

  .bottom-actions > button {
    flex: 1 1 112px;
    white-space: normal;
  }

  .rest-quick-actions {
    flex: 0 1 300px;
    flex-wrap: nowrap;
  }
}

@media (min-width: 1040px) {
  .app-shell,
  .bottom-actions {
    width: min(1120px, calc(100% - 48px));
  }

  .layout {
    grid-template-columns: minmax(300px, 0.95fr) minmax(360px, 1.05fr) minmax(230px, 0.65fr);
    gap: 18px;
  }

  .current-card {
    grid-column: 1;
  }

  .module-selector {
    grid-column: 1;
  }

  .sync-panel {
    grid-column: 3;
  }

  .workout-list {
    grid-column: 2;
    grid-row: span 2;
  }

  .overview-card,
  .details-panel {
    grid-column: 3;
  }
}
