/* ============================================
   Spine Recovery — Base Styles
   Design tokens, reset, typography, layout primitives
   ============================================ */

:root {
  --ink: #1a1a1a;
  --paper: #f5f0e8;
  --cream: #ede7d9;
  --rust: #c4522a;
  --teal: #2a6b6b;
  --gold: #b8860b;
  --muted: #7a7268;
  --border: #d4cec4;

  --font-serif: 'Fraunces', Georgia, serif;
  --font-mono: 'DM Mono', ui-monospace, monospace;
  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;

  --nav-height: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

main#app {
  padding: calc(var(--safe-top) + 16px) 16px 16px;
  max-width: 560px;
  margin: 0 auto;
}

button { font-family: inherit; cursor: pointer; }

/* Typography */
h1, h2, h3 { font-family: var(--font-serif); font-weight: 500; line-height: 1.2; margin: 0 0 12px; color: var(--ink); }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }

.label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Cards */
.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 8px rgba(26,26,26,0.04);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.1s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--rust); color: white; }
.btn.primary:hover { background: #a84220; }
.btn.secondary { background: transparent; color: var(--teal); border: 1.5px solid var(--teal); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.full { width: 100%; }
.start-btn { margin-top: 16px; }
.btn-row { display: flex; gap: 8px; margin-top: 16px; }

/* Back button */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px 6px 0;
  margin: -8px 0 4px -4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  align-self: flex-start;
}
.btn-back span { font-size: 18px; line-height: 1; }
.btn-back:hover { color: var(--ink); }
.btn-back:active { transform: scale(0.97); }

/* Key cue block */
.key-cue {
  background: var(--cream);
  border-left: 3px solid var(--rust);
  padding: 12px 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.5;
}
.key-cue .label { color: var(--rust); margin-bottom: 4px; display: block; }
.key-cue.warning { border-left-color: var(--gold); margin-top: 8px; }
.key-cue.warning .label { color: var(--gold); }
.key-cue.align-left { text-align: left; }

/* Callout pills */
.callout {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  margin: 4px 6px 0 0;
}
.callout.rust { color: var(--rust); background: rgba(196,82,42,0.12); }
.callout.teal { color: var(--teal); background: rgba(42,107,107,0.12); }
.callout.gold { color: var(--gold); background: rgba(184,134,11,0.15); }
.callout.muted { color: var(--muted); background: rgba(122,114,104,0.12); }
.callouts-top { margin: 0 0 8px; }

/* Bottom nav */
#bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--paper);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
#bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 0;
}
#bottom-nav button.active { color: var(--ink); }
#bottom-nav .nav-icon { font-size: 22px; line-height: 1; }

/* ============================================
   Exercise animation frame — real photo + SVG
   ============================================ */
.anim-frame {
  background: var(--cream);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  margin: 16px 0;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(26, 26, 26, 0.06),
              inset 0 -1px 2px rgba(255, 255, 255, 0.4);
}
.anim-frame svg { display: block; width: 100%; max-width: 400px; height: auto; }

/* Photo-based exercise animation — crossfades between two frames */
.photo-anim {
  position: relative;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #d6cdbd;
}
.photo-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-md);
}
.photo-frame.frame-a {
  animation: frameA 3s ease-in-out infinite;
}
.photo-frame.frame-b {
  animation: frameB 3s ease-in-out infinite;
}
@keyframes frameA {
  0%, 40% { opacity: 1; }
  55%, 90% { opacity: 0; }
  100% { opacity: 1; }
}
@keyframes frameB {
  0%, 40% { opacity: 0; }
  55%, 90% { opacity: 1; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .photo-frame.frame-a, .photo-frame.frame-b { animation: none; }
  .photo-frame.frame-b { opacity: 0.5; }
}

/* ============================================
   Progress bar (flow top) + set dots
   ============================================ */
.flow-progress {
  margin: -4px 0 16px;
}
.flow-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.flow-progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.flow-progress-fill {
  height: 100%;
  background: var(--rust);
  border-radius: 999px;
  transition: width 0.35s ease-out;
}

.set-dots {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 12px;
}
.set-dots .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cream);
  border: 2px solid var(--border);
  transition: all 0.2s ease;
}
.set-dots .dot.done {
  background: var(--rust);
  border-color: var(--rust);
}
.set-dots .dot.current {
  background: var(--paper);
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(42, 107, 107, 0.2);
  transform: scale(1.15);
}

/* ============================================
   Progress ring timer
   ============================================ */
.timer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 16px 0 4px;
}
.timer-label {
  margin-bottom: -4px;
}
.progress-ring {
  position: relative;
  width: 200px;
  height: 200px;
}
.progress-ring svg {
  display: block;
}
.progress-ring-arc {
  transition: stroke-dashoffset 1s linear;
}
.progress-ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 48px;
  font-weight: 500;
  color: var(--ink);
  pointer-events: none;
  letter-spacing: -0.02em;
}

/* (Legacy .timer used in workday/settings views) */
.timer {
  font-family: var(--font-serif);
  font-size: 56px;
  font-weight: 500;
  text-align: center;
  color: var(--ink);
  margin: 24px 0;
}

/* ============================================
   Exercise card + flow screens
   ============================================ */
.exercise-header { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.exercise-header h2 { margin: 0; }

.instruction-primary {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 500;
  color: var(--ink);
  text-align: center;
  margin: 18px 0 12px;
  letter-spacing: -0.01em;
}

.motion-note { margin: 12px 0 4px; font-size: 13px; }
.sub-label { margin: 4px 0 16px; }

.today-header { margin-bottom: 20px; }

.ex-list-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  list-style: none;
}
.exercise-list { list-style: none; padding: 0; margin: 12px 0 0; }

/* Side selector card */
.side-selector .side-emph,
.side-emph {
  color: var(--rust);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Celebration (between exercises) */
.celebration { padding: 32px 20px; }
.check-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--teal);
  color: white;
  font-size: 32px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  animation: pop 0.4s ease-out;
}
@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}

/* Complete screen */
.complete-screen { padding: 28px 20px 24px; }
.complete-screen .flame {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 4px;
}
.complete-screen .encourage {
  font-family: var(--font-serif);
  font-size: 18px;
  color: var(--ink);
  margin: 4px 0 16px;
}
.complete-stats {
  display: flex;
  justify-content: space-around;
  gap: 12px;
  margin: 16px 0 8px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.complete-stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.complete-stats .stat-value {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 500;
  color: var(--rust);
  line-height: 1;
}
.done-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 8px;
  text-align: left;
}
.done-list li {
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.done-list li:last-child { border-bottom: none; }
.done-list .tick {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--teal);
  color: white;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

/* Heatmap cell */
.heat-cell { aspect-ratio: 1; border-radius: 4px; background: var(--cream); }
.heat-cell.complete { background: var(--teal); }
.heat-cell.partial { background: var(--gold); }
.heat-cell.today { outline: 2px solid var(--ink); outline-offset: 1px; }

/* Utility */
.stack-sm > * + * { margin-top: 8px; }
.stack-md > * + * { margin-top: 16px; }
.stack-lg > * + * { margin-top: 24px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

/* Tighten on narrow screens (375px target) */
@media (max-width: 380px) {
  .progress-ring { width: 180px; height: 180px; }
  .progress-ring-text { font-size: 42px; }
  .complete-stats .stat-value { font-size: 24px; }
  h1 { font-size: 26px; }
}
