*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Surfaces (iOS grouped-list pattern) ── */
  --bg: #F2F2F7;              /* iOS systemGroupedBackground — page canvas */
  --surface: #FFFFFF;         /* card fill */
  --surface-light: #E5E5EA;   /* iOS separator grey — dot bg, ring track, btn-pause */
  --border: #D1D1D6;          /* iOS systemGray4 — card hairlines */

  /* ── Brand ── */
  --primary: #6C63FF;
  --primary-dark: #5549e0;
  --primary-tint: rgba(108, 99, 255, 0.10);

  /* ── Phase colors — darkened for AA contrast on white ── */
  --run:      #E53935;
  --walk:     #00A76F;
  --warmup:   #E67E00;
  --cooldown: #1E88E5;

  /* ── Phase tints (badge/tag fills) ── */
  --run-tint:      rgba(229, 57, 53, 0.12);
  --walk-tint:     rgba(0, 167, 111, 0.12);
  --warmup-tint:   rgba(230, 126, 0, 0.14);
  --cooldown-tint: rgba(30, 136, 229, 0.12);

  /* ── Text ── */
  --text: #1C1C1E;            /* iOS label */
  --text-dim: #8E8E93;        /* iOS secondaryLabel */

  /* ── Shape ── */
  --radius: 20px;
  --radius-sm: 12px;
  --radius-lg: 24px;

  /* ── Elevation ── */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 2px 8px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.08);
  --shadow-primary: 0 6px 20px rgba(108,99,255,.30);

  /* ── Translucent chrome (iOS blur) ── */
  --header-bg: rgba(242, 242, 247, 0.72);
  --blur-chrome: saturate(180%) blur(20px);
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  max-width: 420px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* ── App Header ── */
#app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  -webkit-backdrop-filter: var(--blur-chrome);
  backdrop-filter: var(--blur-chrome);
  border-bottom: 0.5px solid var(--border);
  padding: 10px 20px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(108, 99, 255, 0.25);
}
.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--primary);
}

/* ── App Content ── */
#app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 16px 8px;
  overflow: hidden;
  min-height: 0;
}

/* ── Phase Badge ── */
#phase-badge {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 4px 14px;
  border-radius: 20px;
  margin-bottom: 8px;
  transition: background-color 0.4s, color 0.4s, opacity 0.3s, transform 0.3s;
  opacity: 0;
}
#phase-badge.visible { opacity: 1; }
#phase-badge.pop {
  animation: badge-pop 0.4s ease;
}
@keyframes badge-pop {
  0%   { transform: scale(0.9); }
  50%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}
#phase-badge.phase-warmup  { background: var(--warmup-tint);   color: var(--warmup);   }
#phase-badge.phase-run     { background: var(--run-tint);      color: var(--run);      }
#phase-badge.phase-walk    { background: var(--walk-tint);     color: var(--walk);     }
#phase-badge.phase-cooldown{ background: var(--cooldown-tint); color: var(--cooldown); }
#phase-badge.phase-idle    { background: var(--primary-tint);  color: var(--primary);  }

/* ── SVG Ring ── */
.timer-ring-wrapper {
  position: relative;
  width: min(220px, 42vw, 36vh);
  height: min(220px, 42vw, 36vh);
  margin-bottom: 8px;
  transition: filter 0.4s;
}
.timer-ring-wrapper.glowing {
  filter: drop-shadow(0 0 12px rgba(108, 99, 255, 0.30));
}
.timer-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.ring-bg {
  fill: none;
  stroke: var(--surface-light);
  stroke-width: 6;
}
.ring-progress {
  fill: none;
  stroke: var(--ring-color, var(--primary));
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s linear, stroke 0.4s;
}

/* ── Time Display ── */
#time-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(32px, 8vw, 48px);
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text);
  transition: color 0.4s;
}

/* ── Round Info ── */
#round-info {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
  transition: opacity 0.3s;
}

/* ── Dot Progress ── */
#dot-progress {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
  max-width: 280px;
  min-height: 12px;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-light);
  transition: background-color 0.3s, box-shadow 0.3s;
}
.dot.completed {
  background: var(--ring-color, var(--primary));
}
.dot.current {
  background: var(--ring-color, var(--primary));
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.20);
  animation: pulse-dot 1s infinite alternate;
}
@keyframes pulse-dot {
  from { transform: scale(1); }
  to   { transform: scale(1.35); }
}

/* ── Up Next ── */
#up-next {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-align: center;
  min-height: 16px;
  transition: opacity 0.3s;
}
#up-next span { color: var(--text); font-weight: 600; }

/* ── Controls ── */
.controls { display: flex; gap: 16px; align-items: center; }
.controls.hidden { display: none; }

.btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  padding: 12px 28px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s, background 0.4s;
  min-width: 80px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.96); }

.btn-start {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: var(--shadow-primary);
}
.btn-pause {
  background: var(--surface-light);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-stop {
  background: var(--surface);
  color: var(--run);
  border: 1px solid var(--run-tint);
}

/* ── Celebration ── */
#celebration {
  position: absolute;
  inset: 0;
  background: rgba(242, 242, 247, 0.95);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
  z-index: 10;
}
#celebration.visible { opacity: 1; pointer-events: auto; }
#celebration .emoji { font-size: 64px; }
#celebration h2 { font-size: 26px; font-weight: 700; }
#celebration p { color: var(--text-dim); font-size: 15px; }
#celebration .btn-start { margin-top: 12px; }

/* ── Skip Button ── */
.btn-skip {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}
.btn-skip:active { background: var(--surface); }

/* ── Preset Cards ── */
#preset-panel {
  width: 100%;
  margin-bottom: 10px;
  transition: opacity 0.3s, transform 0.3s;
}
#preset-panel.hidden { display: none; }
.preset-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.preset-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.preset-row::-webkit-scrollbar { display: none; }
.preset-card {
  flex: 0 0 auto;
  scroll-snap-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-width: 100px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.3s, background 0.3s, transform 0.1s, box-shadow 0.3s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.preset-card:active { transform: scale(0.97); }
.preset-card.selected {
  border-color: var(--primary);
  background: var(--primary-tint);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}
.preset-card .emoji { font-size: 16px; margin-bottom: 1px; }
.preset-card .preset-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.preset-card .preset-detail {
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Custom Stepper ── */
#custom-stepper {
  width: 100%;
  margin-top: 12px;
  transition: max-height 0.3s, opacity 0.3s;
  overflow: hidden;
}
#custom-stepper.hidden { display: none; }
.stepper-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stepper-item {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.stepper-item.full { grid-column: 1 / -1; }
.stepper-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.stepper-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stepper-btn {
  background: var(--surface-light);
  border: none;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.stepper-btn:active { background: var(--primary); }
.stepper-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  min-width: 50px;
  text-align: center;
}

/* ── Workout Summary ── */
#workout-summary {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-top: 6px;
}
#workout-summary.hidden { display: none; }
.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.summary-total {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.summary-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.summary-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.summary-tag.warmup   { background: var(--warmup-tint);   color: var(--warmup);   }
.summary-tag.run      { background: var(--run-tint);      color: var(--run);      }
.summary-tag.walk     { background: var(--walk-tint);     color: var(--walk);     }
.summary-tag.cooldown { background: var(--cooldown-tint); color: var(--cooldown); }

/* ── Install Banner ── */
#install-banner {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text);
}
#install-banner.hidden { display: none; }
#install-banner span { flex: 1; }
.btn-install {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 2px 10px rgba(108, 99, 255, 0.3);
  padding: 8px 20px;
  font-size: 13px;
  border-radius: 10px;
  white-space: nowrap;
}
.btn-install-dismiss {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.2s, background 0.2s;
}
.btn-install-dismiss:hover { color: var(--text); background: var(--surface-light); }

/* ── Bottom Tab Nav ── */
#tab-nav {
  position: sticky;
  bottom: 0;
  z-index: 20;
  width: 100%;
  display: flex;
  background: var(--header-bg);
  -webkit-backdrop-filter: var(--blur-chrome);
  backdrop-filter: var(--blur-chrome);
  border-top: 0.5px solid var(--border);
  padding: 6px 0;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 0 4px;
  cursor: pointer;
  transition: color 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
}
.tab-btn.active {
  color: var(--primary);
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab-label { font-size: 11px; }

/* ── Tab Screens ── */
.tab-screen {
  width: 100%;
}
.tab-screen.hidden { display: none !important; }
#tab-timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  flex: 1;
  min-height: 0;
}

/* ── Heatmap ── */
.heatmap {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 14px;
}
.heatmap-cell {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
  color: var(--text-dim);
  padding-bottom: 3px;
  transition: background 0.3s;
}
.heatmap-cell.completed { background: var(--walk-tint);   border-color: rgba(0, 167, 111, 0.40);  color: var(--walk); }
.heatmap-cell.partial   { background: var(--warmup-tint); border-color: rgba(230, 126, 0, 0.40);  color: var(--warmup); }
.heatmap-cell.today     { border: 2px solid var(--primary); }

/* ── Stats Row ── */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Bar Chart ── */
.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius);
  padding: 14px 12px 8px;
  margin-bottom: 16px;
}
.chart-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}
.bar {
  width: 100%;
  background: linear-gradient(to top, var(--primary), #9b93ff);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  margin-top: auto;
  transition: height 0.5s ease;
}
.bar-label {
  font-size: 9px;
  color: var(--text-dim);
  font-weight: 600;
}

/* ── Session List ── */
.session-list { display: flex; flex-direction: column; gap: 8px; }
.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  opacity: 0;
  animation: fade-in 0.4s ease forwards;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.session-info { display: flex; flex-direction: column; gap: 2px; }
.session-preset { font-size: 14px; font-weight: 600; color: var(--text); }
.session-meta { font-size: 11px; color: var(--text-dim); }
.session-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.session-badge.done    { background: var(--walk-tint);   color: var(--walk);   }
.session-badge.partial { background: var(--warmup-tint); color: var(--warmup); }

/* ── History Tab Screen ── */
#tab-history {
  padding-bottom: 24px;
}
#history-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
  font-size: 14px;
}
#history-empty .empty-emoji { font-size: 36px; display: block; margin-bottom: 10px; }
