:root {
  --color-primary: #f97316;
  --color-on-primary: #0f172a;
  --color-secondary: #fb923c;
  --color-accent: #22c55e;
  --color-on-accent: #0f172a;
  --color-background: #1f2937;
  --color-foreground: #f8fafc;
  --color-card: #313742;
  --color-muted: #37414f;
  --color-muted-foreground: #cbd5e1;
  --color-border: #374151;
  --color-destructive: #ef4444;
  --color-cool: #38bdf8;

  --radius: 16px;
  --space: 8px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --font-body: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-display: 'Barlow Condensed', var(--font-body);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(249, 115, 22, 0.22), transparent 60%),
    var(--color-background);
  color: var(--color-foreground);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

#app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
}

.view[hidden] {
  display: none !important;
}

.eyebrow {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--color-primary);
}

h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 9vw, 3rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.01em;
}

.sub {
  margin: 0 0 24px;
  color: var(--color-muted-foreground);
}

/* ---------- Home ---------- */

.workout-list {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.workout-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 18px 20px;
  text-align: left;
  color: var(--color-foreground);
  background: var(--color-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.workout-card:hover {
  transform: translateY(-2px);
  border-color: var(--color-secondary);
}

.workout-card:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

.workout-card.is-selected {
  border-color: var(--color-primary);
  background: linear-gradient(180deg, rgba(249, 115, 22, 0.16), var(--color-card));
  box-shadow: var(--shadow);
}

.card-name {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
}

.card-tagline {
  color: var(--color-muted-foreground);
  font-size: 0.95rem;
}

.card-meta {
  margin-top: 4px;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--color-secondary);
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 22px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
  color: var(--color-muted-foreground);
  -webkit-tap-highlight-color: transparent;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-box {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--color-muted);
  border: 1px solid var(--color-border);
  transition: background 0.2s ease;
}

.switch-box::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-muted-foreground);
  transition: transform 0.2s ease, background 0.2s ease;
}

.switch input:checked + .switch-box {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.switch input:checked + .switch-box::after {
  transform: translateX(20px);
  background: var(--color-on-accent);
}

.switch input:focus-visible + .switch-box {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

/* ---------- Buttons ---------- */

.btn {
  min-height: 52px;
  padding: 0 20px;
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 600;
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

.btn-primary {
  width: 100%;
  color: var(--color-on-accent);
  background: var(--color-accent);
}

.btn-primary:hover {
  background: #34d27b;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.btn-ghost {
  color: var(--color-foreground);
  background: transparent;
  border-color: var(--color-border);
}

.btn-ghost:hover {
  border-color: var(--color-muted-foreground);
}

.btn-danger {
  color: #fca5a5;
  background: transparent;
  border-color: rgba(239, 68, 68, 0.6);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* ---------- Train ---------- */

#view-train {
  --phase-color: var(--color-secondary);
  display: flex;
  flex-direction: column;
}

#view-train[data-phase='prep'] {
  --phase-color: var(--color-cool);
}
#view-train[data-phase='warmup'] {
  --phase-color: var(--color-secondary);
}
#view-train[data-phase='work'] {
  --phase-color: var(--color-primary);
}
#view-train[data-phase='rest'] {
  --phase-color: var(--color-accent);
}
#view-train[data-phase='cooldown'] {
  --phase-color: var(--color-cool);
}

.progress-all {
  width: 100%;
  height: 8px;
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--color-muted);
  border-radius: 999px;
}

#progress-all-bar {
  width: 0;
  height: 100%;
  background: var(--phase-color);
  border-radius: inherit;
  transition: width 0.25s linear, background 0.25s ease;
}

.train-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.phase-chip {
  padding: 4px 14px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: #0f172a;
  background: var(--phase-color);
  border-radius: 999px;
  transition: background 0.25s ease;
}

.step-label {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-muted-foreground);
  font-variant-numeric: tabular-nums;
}

.ring-wrap {
  position: relative;
  width: min(74vw, 300px);
  max-width: 100%;
  margin: 10px auto 4px;
}

.ring {
  display: block;
  width: 100%;
  height: auto;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--color-muted);
  stroke-width: 14;
}

.ring-progress {
  fill: none;
  stroke: var(--phase-color);
  stroke-width: 14;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.25s linear, stroke 0.25s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.countdown {
  font-family: var(--font-display);
  font-size: clamp(3.6rem, 22vw, 5.5rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.countdown-unit {
  font-size: 0.9rem;
  letter-spacing: 0.2em;
  color: var(--color-muted-foreground);
}

.exercise {
  margin-top: 10px;
  text-align: center;
}

.ex-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 8vw, 2.4rem);
  font-weight: 700;
}

.ex-tip {
  margin: 6px 0 0;
  color: var(--color-muted-foreground);
}

.next-label {
  min-height: 1.4em;
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: var(--color-secondary);
}

.controls {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

.controls .btn {
  width: 100%;
  padding: 0 10px;
}

/* ---------- Done ---------- */

.done-card {
  padding: 28px 22px;
  text-align: center;
  background: var(--color-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 24px 0;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 8px;
  background: var(--color-muted);
  border-radius: 14px;
}

.stat-num {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  color: var(--color-muted-foreground);
}

.done-actions {
  display: grid;
  gap: 10px;
}

/* ---------- Timeline ---------- */

.timeline-panel[hidden] {
  display: none;
}

.timeline-panel {
  margin-bottom: 22px;
  animation: reveal 0.28s ease both;
}

.timeline-wrap {
  padding: 18px 18px 4px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.timeline-title {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--color-muted-foreground);
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tl-item {
  position: relative;
  padding: 0 0 18px 46px;
}

.tl-item::before {
  content: '';
  position: absolute;
  left: 13px;
  top: 28px;
  bottom: -2px;
  width: 3px;
  border-radius: 2px;
  background: var(--color-border);
}

.tl-item:last-child {
  padding-bottom: 4px;
}

.tl-item:last-child::before {
  display: none;
}

.tl-node {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 26px;
  height: 26px;
  border: 3px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-card);
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.tl-node::after {
  content: '';
  position: absolute;
  left: 8px;
  top: 4px;
  width: 6px;
  height: 11px;
  border: solid var(--color-on-accent);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.2s ease;
}

.tl-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.tl-name {
  font-weight: 600;
}

.tl-meta {
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--color-muted-foreground);
}

.tl-rest {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--color-muted-foreground);
  background: var(--color-muted);
  border-radius: 999px;
}

.tl-item.is-active .tl-node {
  background: var(--color-primary);
  border-color: var(--color-primary);
  animation: pulse 1.4s ease-in-out infinite;
}

.tl-item.is-active .tl-name {
  color: var(--color-primary);
}

.tl-item.is-done .tl-node {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.tl-item.is-done .tl-node::after {
  transform: rotate(45deg) scale(1);
}

.tl-item.is-done .tl-name {
  color: var(--color-muted-foreground);
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.28);
  }
  50% {
    box-shadow: 0 0 0 9px rgba(249, 115, 22, 0.06);
  }
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Utility ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 380px) {
  .controls {
    grid-template-columns: 1fr 1fr;
  }
  .controls .btn-primary {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  .workout-card:hover {
    transform: none;
  }
}