/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f5f7fa;
  --surface:     #ffffff;
  --primary:     #5c6ef8;
  --primary-dark:#4656e8;
  --secondary:   #e8eafd;
  --accent:      #f472b6;
  --text:        #1e2a3a;
  --text-muted:  #6b7280;
  --border:      #e5e7eb;
  --success:     #10b981;
  --radius:      14px;
  --shadow:      0 2px 12px rgba(0,0,0,.07);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.12);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 960px; margin: 0 auto;
  padding: .75rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.logo { font-size: 1.3rem; font-weight: 700; color: var(--primary); letter-spacing: -.5px; }
.header-nav { display: flex; gap: .5rem; flex-wrap: wrap; }
.nav-btn {
  background: none; border: none; cursor: pointer;
  padding: .4rem .85rem; border-radius: 999px;
  font-size: .9rem; font-weight: 500; color: var(--text-muted);
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--secondary); color: var(--primary); }
.nav-btn.active { background: var(--primary); color: #fff; }

/* ── Views ── */
#app { max-width: 960px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.view { display: none; }
.view.active { display: block; }

.section-header { margin-bottom: 2rem; }
.section-header h2 { font-size: 1.6rem; font-weight: 700; margin-bottom: .3rem; }
.subtitle { color: var(--text-muted); font-size: .95rem; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

/* ── Routine Grid ── */
.routine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}
.routine-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  padding: 1.5rem;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
  display: flex; flex-direction: column; gap: .75rem;
}
.routine-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}
.routine-card .routine-icon { font-size: 2.5rem; }
.routine-card h3 { font-size: 1.05rem; font-weight: 700; }
.routine-card .routine-meta { font-size: .82rem; color: var(--text-muted); display: flex; gap: .75rem; flex-wrap: wrap; }
.routine-card .routine-desc { font-size: .88rem; color: var(--text-muted); }
.routine-card .start-btn {
  margin-top: auto;
  background: var(--primary); color: #fff;
  border: none; border-radius: 999px;
  padding: .5rem 1.2rem; font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: background .15s;
  align-self: flex-start;
}
.routine-card .start-btn:hover { background: var(--primary-dark); }

/* ── Session ── */
.session-container { max-width: 540px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.5rem; }
.session-header { display: flex; align-items: center; gap: 1rem; }
.back-btn {
  background: none; border: 1.5px solid var(--border); border-radius: 999px;
  padding: .35rem .85rem; cursor: pointer; font-size: .88rem; color: var(--text-muted);
  transition: border-color .15s, color .15s; white-space: nowrap;
}
.back-btn:hover { border-color: var(--primary); color: var(--primary); }
.session-header h2 { font-size: 1.2rem; font-weight: 700; flex: 1; }
.session-progress { font-size: .88rem; color: var(--text-muted); white-space: nowrap; }

.stretch-card {
  background: var(--surface); border-radius: var(--radius);
  border: 1.5px solid var(--border); padding: 2rem;
  text-align: center; display: flex; flex-direction: column; align-items: center; gap: .75rem;
  box-shadow: var(--shadow);
}
.stretch-illustration { font-size: 4rem; line-height: 1; }
.stretch-card h3 { font-size: 1.35rem; font-weight: 700; }
.stretch-card p { color: var(--text-muted); font-size: .93rem; max-width: 380px; }
.stretch-meta { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.tag {
  background: var(--secondary); color: var(--primary);
  border-radius: 999px; padding: .25rem .75rem; font-size: .78rem; font-weight: 600;
}

/* ── Timer ── */
.timer-section { display: flex; flex-direction: column; align-items: center; gap: 1.25rem; }
.timer-ring { position: relative; width: 160px; height: 160px; }
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--secondary); stroke-width: 8; }
.ring-fill {
  fill: none; stroke: var(--primary); stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset .5s linear, stroke .3s;
}
.ring-fill.done { stroke: var(--success); }
.timer-display {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.timer-display span { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.timer-display small { font-size: .78rem; color: var(--text-muted); }

.timer-controls { display: flex; gap: .75rem; align-items: center; }

/* ── Buttons ── */
.btn {
  border: none; border-radius: 999px; cursor: pointer;
  font-size: .95rem; font-weight: 600; padding: .55rem 1.4rem;
  transition: background .15s, color .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: var(--primary); }
.btn-secondary:hover:not(:disabled) { background: #dde0fc; }
.btn-outline {
  background: none; border: 1.5px solid var(--border); color: var(--text-muted);
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: #fee2e2; color: #ef4444; }
.btn-danger:hover:not(:disabled) { background: #fecaca; }

/* ── Progress ── */
.overall-progress { display: flex; flex-direction: column; gap: .6rem; }
.progress-bar {
  height: 8px; background: var(--secondary); border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--primary); border-radius: 999px;
  transition: width .4s ease;
}
.progress-steps { display: flex; gap: .4rem; flex-wrap: wrap; }
.step-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--secondary); border: 2px solid var(--border);
  transition: background .3s, border-color .3s;
}
.step-dot.done { background: var(--success); border-color: var(--success); }
.step-dot.current { background: var(--primary); border-color: var(--primary); }

.next-preview {
  text-align: center; font-size: .88rem; color: var(--text-muted);
  background: var(--secondary); border-radius: 999px; padding: .4rem 1rem;
}
.next-label { font-weight: 600; color: var(--primary); margin-right: .3rem; }

/* ── Completion ── */
.completion-screen {
  text-align: center; padding: 2rem;
  background: var(--surface); border-radius: var(--radius);
  border: 1.5px solid var(--success); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.completion-icon { font-size: 3.5rem; }
.completion-screen h3 { font-size: 1.5rem; font-weight: 800; }
.completion-screen p { color: var(--text-muted); }

/* ── History ── */
.stats-row {
  display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.stat-card {
  flex: 1; min-width: 120px;
  background: var(--surface); border-radius: var(--radius);
  border: 1.5px solid var(--border); padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: .15rem;
}
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: .78rem; color: var(--text-muted); font-weight: 500; }

.history-list { display: flex; flex-direction: column; gap: .75rem; }
.history-item {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 1rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
}
.history-item .hi-name { font-weight: 600; }
.history-item .hi-meta { font-size: .83rem; color: var(--text-muted); }
.history-item .hi-badge {
  background: #d1fae5; color: #065f46;
  border-radius: 999px; padding: .2rem .75rem; font-size: .8rem; font-weight: 600;
  white-space: nowrap;
}
.history-empty {
  text-align: center; padding: 3rem; color: var(--text-muted);
  font-size: 1rem; background: var(--surface); border-radius: var(--radius);
  border: 1px dashed var(--border);
}

/* ── Custom Stretches ── */
.custom-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 640px) { .custom-layout { grid-template-columns: 1fr; } }

.form-card label {
  display: flex; flex-direction: column; gap: .3rem;
  font-size: .85rem; font-weight: 600; color: var(--text-muted); margin-bottom: .75rem;
}
.form-card input, .form-card textarea, .form-card select {
  font-family: var(--font); font-size: .93rem;
  border: 1.5px solid var(--border); border-radius: 8px;
  padding: .5rem .75rem; color: var(--text); background: var(--bg);
  transition: border-color .15s;
  outline: none; width: 100%;
}
.form-card input:focus, .form-card textarea:focus, .form-card select:focus {
  border-color: var(--primary);
}

.custom-list { display: flex; flex-direction: column; gap: .6rem; }
.custom-item {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: .85rem 1rem;
  display: flex; align-items: center; gap: .75rem; cursor: pointer;
  transition: border-color .15s;
}
.custom-item.selected { border-color: var(--primary); background: var(--secondary); }
.custom-item .ci-icon { font-size: 1.5rem; flex-shrink: 0; }
.custom-item .ci-info { flex: 1; min-width: 0; }
.custom-item .ci-name { font-weight: 600; font-size: .92rem; }
.custom-item .ci-meta { font-size: .78rem; color: var(--text-muted); }
.custom-item .ci-delete {
  background: none; border: none; cursor: pointer; color: #ef4444;
  font-size: 1.1rem; padding: .25rem; flex-shrink: 0; opacity: .6;
  transition: opacity .15s;
}
.custom-item .ci-delete:hover { opacity: 1; }
.custom-empty {
  text-align: center; padding: 2rem; color: var(--text-muted);
  font-size: .9rem; background: var(--surface); border-radius: var(--radius);
  border: 1px dashed var(--border);
}

/* ── Responsive ── */
@media (max-width: 540px) {
  .routine-grid { grid-template-columns: 1fr; }
  .timer-ring { width: 130px; height: 130px; }
  .timer-display span { font-size: 2rem; }
}
