/* ================================================================
   SLEEP RESET — Design System
   Kaleidoscope Coaching
   Mobile-first · No external dependencies · System font stack
================================================================ */


/* ----------------------------------------------------------------
   1. DESIGN TOKENS
---------------------------------------------------------------- */
:root {
  /* ---- Background layers (darkest → lightest) ---- */
  --bg:          #0a0e1a;
  --bg-surface:  #131726;
  --bg-surface2: #181d30;
  --bg-surface3: #1e2440;
  --bg-hover:    #242b4a;

  /* ---- Borders ---- */
  --border:    #1e2438;
  --border-md: #2a3050;
  --border-lg: #353d62;

  /* ---- Accent: soft indigo ---- */
  --accent:       #4f46e5;
  --accent-hover: #5b53f0;
  --accent-dim:   rgba(79, 70, 229, 0.13);
  --accent-glow:  rgba(79, 70, 229, 0.32);
  --accent-text:  #818cf8;

  /* ---- Text ---- */
  --text:       #f0eff4;
  --text-sec:   #8b8fa8;
  --text-muted: #464d6e;

  /* ---- Amber: tips & highlights ---- */
  --amber:      #f59e0b;
  --amber-dim:  rgba(245, 158, 11, 0.11);
  --amber-text: #fbbf24;
  --amber-bdr:  rgba(245, 158, 11, 0.22);

  /* ---- Semantic ---- */
  --success: #22c55e;
  --danger:  #ef4444;

  /* ---- Typography ---- */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui,
          'Helvetica Neue', Arial, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  /* ---- Spacing (4 px base) ---- */
  --s1:  4px;
  --s2:  8px;
  --s3:  12px;
  --s4:  16px;
  --s5:  20px;
  --s6:  24px;
  --s8:  32px;
  --s10: 40px;
  --s12: 48px;
  --s16: 64px;

  /* ---- Page padding ---- */
  --page-x: 18px;

  /* ---- Radii ---- */
  --r-sm:   6px;
  --r-md:   10px;
  --r-lg:   14px;
  --r-xl:   18px;
  --r-2xl:  24px;
  --r-full: 9999px;

  /* ---- Navigation ---- */
  --nav-h: 68px;

  /* ---- Transitions ---- */
  --t-fast:   0.15s ease;
  --t-base:   0.22s ease;
  --t-slow:   0.35s ease;
  --t-spring: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}


/* ----------------------------------------------------------------
   2. RESET & BASE
---------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  min-height: 100%;
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.2;
  font-weight: 600;
  color: var(--text);
}

p { line-height: 1.65; }

button {
  font-family: var(--font);
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

textarea, input {
  font-family: var(--font);
  font-size: inherit;
}

ul, ol { list-style: none; }

a {
  color: var(--accent-text);
  text-decoration: none;
}

code {
  font-family: var(--mono);
  font-size: 0.83em;
  background: var(--bg-surface3);
  color: var(--accent-text);
  padding: 2px 6px;
  border-radius: var(--r-sm);
}


/* ----------------------------------------------------------------
   3. UTILITY CLASSES
---------------------------------------------------------------- */
.hidden {
  display: none !important;
}

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


/* ----------------------------------------------------------------
   4. SHARED COMPONENTS
---------------------------------------------------------------- */

/* --- Section label --- */
.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-sec);
  margin-top: var(--s6);
  margin-bottom: var(--s3);
}

/* --- Badge --- */
.badge {
  display: inline-block;
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: var(--bg-surface3);
  color: var(--text-sec);
  white-space: nowrap;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--r-full);
  padding: 14px 28px;
  transition: opacity var(--t-base), transform var(--t-fast),
              box-shadow var(--t-base);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

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

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
}

.btn-primary:disabled,
.btn-primary[aria-disabled="true"] {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none;
}

.btn-large {
  font-size: 1.05rem;
  padding: 16px 40px;
}

/* Bottom padding spacer — sits above nav */
.bottom-padding {
  height: var(--s12);
}


/* ----------------------------------------------------------------
   5. STORAGE WARNING BANNER
---------------------------------------------------------------- */
.storage-warning {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--amber);
  color: #1a0f00;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  padding: var(--s2) var(--page-x);
  padding-top: calc(var(--s2) + env(safe-area-inset-top, 0px));
  line-height: 1.5;
}


/* ----------------------------------------------------------------
   6. ONBOARDING SCREEN
---------------------------------------------------------------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 500;
}

.onboarding-screen {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: var(--s10) var(--page-x);
  padding-top: calc(var(--s10) + env(safe-area-inset-top, 0px));
}

.onboarding-content {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--s6) 0 var(--s10);
}

.onboarding-brand {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: var(--s8);
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.onboarding-brand::before,
.onboarding-brand::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-md);
  max-width: 48px;
}

.onboarding-headline {
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.025em;
  color: var(--text);
  margin-bottom: var(--s5);
}

.onboarding-description {
  font-size: 1rem;
  color: var(--text-sec);
  line-height: 1.75;
  margin-bottom: var(--s8);
  max-width: 320px;
}

.onboarding-features {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  margin-bottom: var(--s8);
}

.feature-row {
  display: flex;
  align-items: center;
  gap: var(--s4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s3) var(--s4);
  text-align: left;
}

.feature-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 30px;
  text-align: center;
  line-height: 1;
}

.feature-text {
  font-size: 0.93rem;
  font-weight: 500;
  color: var(--text);
}

.onboarding-fine-print {
  margin-top: var(--s4);
  font-size: 0.77rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}


/* ----------------------------------------------------------------
   7. APP SHELL & VIEW SYSTEM
---------------------------------------------------------------- */
.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}

/* All views stacked, switched via opacity */
.view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--nav-h);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
  overflow: hidden;
}

.view.active {
  opacity: 1;
  pointer-events: auto;
}

/* Scrollable inner container */
.view-scroll {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--page-x);
  /* Use scroll-padding to keep focus targets clear of nav */
  scroll-padding-bottom: var(--s6);
}

/* Shared view header (Calendar, Progress, About) */
.view-header {
  padding: var(--s6) 0 var(--s4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--s2);
}

.view-title {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.022em;
  color: var(--text);
}


/* ----------------------------------------------------------------
   8. BOTTOM NAVIGATION
---------------------------------------------------------------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: rgba(19, 23, 38, 0.92);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  color: var(--text-muted);
  transition: color var(--t-base);
  padding-bottom: var(--s1);
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 0.22s var(--t-spring);
}

.nav-btn.active .nav-icon {
  transform: scale(1.15) translateY(-1px);
}

.nav-label {
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}


/* ----------------------------------------------------------------
   9. TODAY VIEW — Header & Streak
---------------------------------------------------------------- */
.today-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s5) 0 var(--s3);
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.day-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent-dim);
  border: 1px solid rgba(79, 70, 229, 0.2);
  padding: 5px 12px;
  border-radius: var(--r-full);
}

.streak-bar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--text-sec);
  margin-bottom: var(--s2);
}

.streak-flame {
  font-size: 0.95rem;
}


/* ----------------------------------------------------------------
   10. SESSION CARD
---------------------------------------------------------------- */
.session-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s5);
  margin-bottom: var(--s3);
}

.session-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--s3);
}

.session-info {
  flex: 1;
}

.session-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: -0.015em;
  margin-bottom: var(--s2);
}

.session-description {
  font-size: 0.87rem;
  color: var(--text-sec);
  line-height: 1.65;
  margin-bottom: var(--s5);
}

/* Morning session note */
.morning-note {
  margin-top: var(--s4);
  padding: var(--s3) var(--s4);
  background: var(--amber-dim);
  border: 1px solid var(--amber-bdr);
  border-radius: var(--r-md);
  font-size: 0.82rem;
  color: var(--amber-text);
  line-height: 1.55;
}


/* ----------------------------------------------------------------
   11. AUDIO PLAYER
---------------------------------------------------------------- */
.audio-player {
  background: var(--bg-surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s5);
  overflow: hidden;
}

/* --- Placeholder state (no audio file) --- */
.audio-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s8) var(--s4);
  text-align: center;
  min-height: 110px;
}

.audio-placeholder-icon {
  color: var(--text-muted);
  opacity: 0.6;
}

.audio-placeholder p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
}

/* --- Player controls wrapper --- */
.player-controls {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Time display */
.player-time-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-sec);
  margin-bottom: var(--s4);
  letter-spacing: 0.03em;
}

.time-separator {
  color: var(--text-muted);
}

/* --- Progress bar (scrubable) --- */
.progress-bar-container {
  padding: var(--s2) 0;           /* expand vertical touch target */
  margin-bottom: var(--s5);
  cursor: pointer;
  touch-action: none;             /* prevent page scroll while scrubbing */
}

.progress-bar-track {
  position: relative;
  height: 4px;
  background: var(--bg-surface3);
  border-radius: var(--r-full);
  overflow: visible;
}

.progress-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #7c73f0);
  border-radius: var(--r-full);
  pointer-events: none;
}

.progress-bar-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-base);
}

/* Show thumb on hover or when playing */
.audio-player:hover .progress-bar-thumb,
.audio-player.is-playing .progress-bar-thumb {
  opacity: 1;
}

/* Expand track height on hover for easier scrubbing */
.progress-bar-container:hover .progress-bar-track {
  height: 6px;
}

/* --- Main controls row --- */
.player-main-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s8);
}

/* Play / Pause button — large indigo circle */
.play-pause-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 22px rgba(79, 70, 229, 0.45);
  transition: transform 0.18s var(--t-spring),
              box-shadow var(--t-base),
              background var(--t-fast);
  flex-shrink: 0;
}

.play-pause-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 6px 32px rgba(79, 70, 229, 0.6);
}

.play-pause-btn:active {
  transform: scale(0.91);
  box-shadow: 0 2px 12px rgba(79, 70, 229, 0.35);
}

.play-icon,
.pause-icon {
  display: block;
}

/* Skip buttons */
.player-skip-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface3);
  color: var(--text-sec);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast),
              transform 0.15s ease;
  flex-shrink: 0;
}

.player-skip-btn:hover {
  background: var(--border-md);
  color: var(--text);
}

.player-skip-btn:active {
  transform: scale(0.88);
}


/* ----------------------------------------------------------------
   12. TASK LIST
---------------------------------------------------------------- */
.task-list {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  margin-bottom: var(--s4);
}

.task-row {
  display: flex;
  align-items: center;
  gap: var(--s4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s4);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast),
              transform var(--t-fast);
  min-height: 54px;
}

.task-row:hover {
  background: var(--bg-surface2);
  border-color: var(--border-md);
}

.task-row:active {
  transform: scale(0.985);
}

.task-row.checked {
  background: var(--bg-surface);
  border-color: var(--border);
  cursor: default;
}

/* Circular checkbox */
.task-circle {
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 50%;
  border: 2px solid var(--border-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.25s ease, border-color 0.25s ease,
              transform 0.28s var(--t-spring);
}

.task-row.checked .task-circle {
  background: var(--accent);
  border-color: var(--accent);
}

/* Pop animation on check */
.task-row.checking .task-circle {
  animation: task-check-pop 0.35s var(--t-spring) forwards;
}

/* SVG checkmark inside circle */
.task-checkmark {
  display: none;
  color: #ffffff;
}

.task-row.checked .task-checkmark {
  display: block;
}

/* Task label */
.task-label {
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.45;
  flex: 1;
  transition: color var(--t-base), opacity var(--t-base);
}

.task-row.checked .task-label {
  text-decoration: line-through;
  color: var(--text-sec);
  opacity: 0.6;
}


/* ----------------------------------------------------------------
   13. TIP CARD
---------------------------------------------------------------- */
.tip-card {
  background: var(--amber-dim);
  border: 1px solid var(--amber-bdr);
  border-radius: var(--r-lg);
  padding: var(--s4) var(--s5);
  margin-bottom: var(--s4);
}

.tip-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--amber);
  margin-bottom: var(--s2);
}

.tip-text {
  font-size: 0.88rem;
  color: var(--text-sec);
  line-height: 1.7;
}


/* ----------------------------------------------------------------
   14. REFLECTION SECTION
---------------------------------------------------------------- */
.reflection-section {
  margin-bottom: var(--s4);
}

.reflection-prompt {
  font-size: 0.9rem;
  color: var(--text-sec);
  line-height: 1.65;
  font-style: italic;
  margin-bottom: var(--s3);
}

.reflection-textarea {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.65;
  padding: var(--s4);
  resize: vertical;
  min-height: 100px;
  outline: none;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}

.reflection-textarea::placeholder {
  color: var(--text-muted);
}

.reflection-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}


/* ----------------------------------------------------------------
   15. COMPLETE TODAY BUTTON
---------------------------------------------------------------- */
.complete-section {
  padding: var(--s3) 0 var(--s2);
  display: flex;
  justify-content: center;
}

.btn-complete {
  width: 100%;
  max-width: 360px;
  padding: 17px 32px;
  font-size: 1rem;
  letter-spacing: 0.01em;
}

/* State: day already complete */
.btn-complete.is-done {
  background: var(--bg-surface2);
  color: var(--success);
  cursor: default;
  opacity: 1 !important;
  transform: none !important;
  border: 1px solid rgba(34, 197, 94, 0.2);
}


/* ----------------------------------------------------------------
   16. CALENDAR VIEW
---------------------------------------------------------------- */
.calendar-container {
  padding-bottom: var(--s6);
}

/* Week block wrapper */
.week-block {
  margin-bottom: var(--s5);
}

/* Week separator label */
.week-separator-label {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) 0 var(--s3);
}

.week-sep-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.week-sep-num {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.week-sep-theme {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-sec);
  white-space: nowrap;
}

/* 5-column day grid */
.day-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--s2);
}

/* --- Day tile base --- */
.day-tile {
  aspect-ratio: 1 / 1;
  border-radius: var(--r-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  position: relative;
  overflow: hidden;
  transition: transform var(--t-fast), background var(--t-fast),
              border-color var(--t-fast);
}

.day-tile.clickable {
  cursor: pointer;
}

.day-tile.clickable:hover {
  background: var(--bg-surface2);
  border-color: var(--border-md);
  transform: scale(1.05);
}

.day-tile.clickable:active {
  transform: scale(0.95);
}

.day-number {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.day-status-icon {
  font-size: 0.7rem;
  line-height: 1;
}

.day-today-label {
  font-size: 0.48rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--accent-text);
}

/* --- FUTURE: locked --- */
.day-tile.future {
  opacity: 0.35;
  cursor: default;
}

.day-tile.future .day-number {
  color: var(--text-muted);
}

/* --- TODAY (not yet complete) --- */
.day-tile.today {
  border: 2px solid var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
  cursor: default;
}

.day-tile.today .day-number {
  color: var(--accent-text);
  font-weight: 700;
}

/* --- TODAY COMPLETE --- */
.day-tile.today-complete {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  cursor: default;
}

.day-tile.today-complete .day-number,
.day-tile.today-complete .day-today-label,
.day-tile.today-complete .day-status-icon {
  color: #ffffff;
}

/* --- COMPLETE --- */
.day-tile.complete {
  background: var(--accent);
  border-color: var(--accent);
}

.day-tile.complete .day-number,
.day-tile.complete .day-status-icon {
  color: #ffffff;
}

/* --- MISSED --- */
.day-tile.missed {
  background: var(--bg-surface);
  border-color: var(--amber-bdr);
}

.day-tile.missed .day-number {
  color: var(--text-sec);
}

.day-tile.missed .day-status-icon {
  color: var(--amber-text);
}


/* ----------------------------------------------------------------
   17. DAY DETAIL MODAL (slide up from bottom)
---------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 16, 0.78);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--t-slow);
}

/* .hidden is handled by JS: removes display:none, then adds .open */
.modal-overlay.open {
  opacity: 1;
}

.day-detail-panel {
  background: var(--bg-surface);
  border-top-left-radius: var(--r-2xl);
  border-top-right-radius: var(--r-2xl);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.modal-overlay.open .day-detail-panel {
  transform: translateY(0);
}

/* Drag handle bar */
.day-detail-panel::before {
  content: '';
  display: block;
  width: 38px;
  height: 4px;
  background: var(--border-md);
  border-radius: var(--r-full);
  margin: var(--s3) auto var(--s1);
}

/* Panel header */
.day-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--s2) var(--page-x) var(--s4);
  border-bottom: 1px solid var(--border);
}

.day-detail-title-group {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.day-detail-day-num {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-text);
}

.day-detail-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.015em;
  line-height: 1.25;
  margin-top: 2px;
}

.day-detail-theme {
  margin-top: var(--s1);
}

/* Close button */
.modal-close-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-surface3);
  color: var(--text-sec);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 4px;
  transition: background var(--t-fast), color var(--t-fast);
}

.modal-close-btn:hover {
  background: var(--border-md);
  color: var(--text);
}

/* Panel body */
.day-detail-body {
  padding: 0 var(--page-x) var(--s10);
}

/* Detail — audio card (read-only) */
.detail-audio-card {
  background: var(--bg-surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s4) var(--s5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s2);
}

.detail-audio-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

/* Detail — task list (read-only) */
.detail-task-list {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  margin-bottom: var(--s2);
}

.detail-task-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--bg-surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.detail-task-icon {
  font-size: 0.88rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  line-height: 1;
}

.detail-task-label {
  font-size: 0.87rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.detail-task-row.done .detail-task-label {
  color: var(--text-sec);
}

.detail-task-row.done {
  border-color: rgba(79, 70, 229, 0.18);
}

/* Detail — reflection */
.detail-reflection-section {
  margin-top: var(--s2);
}

.detail-reflection-text {
  font-size: 0.9rem;
  color: var(--text-sec);
  line-height: 1.7;
  font-style: italic;
  background: var(--bg-surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s4);
}


/* ----------------------------------------------------------------
   18. PROGRESS VIEW
---------------------------------------------------------------- */

/* Completion overview card */
.progress-overview {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s5);
  margin-top: var(--s4);
  margin-bottom: var(--s4);
}

.progress-program-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-sec);
  margin-bottom: var(--s3);
}

.completion-bar-wrap {
  height: 8px;
  background: var(--bg-surface3);
  border-radius: var(--r-full);
  overflow: hidden;
  margin-bottom: var(--s3);
}

.completion-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, #7c73f0 100%);
  border-radius: var(--r-full);
  transition: width 1.1s cubic-bezier(0.4, 0, 0.2, 1);
}

.completion-label {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

/* Stat cards */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s2);
  margin-bottom: var(--s2);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s4) var(--s2);
  text-align: center;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-text);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat-label {
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: var(--s1);
  line-height: 1.4;
}

/* Weekly breakdown cards */
.week-cards {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  margin-bottom: var(--s6);
}

.week-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s4) var(--s5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
}

.week-card.complete-week {
  border-color: rgba(79, 70, 229, 0.25);
  background: var(--accent-dim);
}

.week-card-left {
  flex: 1;
  min-width: 0;
}

.week-card-name {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: 3px;
}

.week-card-theme {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}

.week-card-focus {
  font-size: 0.8rem;
  color: var(--text-sec);
  line-height: 1.5;
}

.week-card-right {
  text-align: right;
  flex-shrink: 0;
}

.week-card-completion {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-sec);
  white-space: nowrap;
}

.week-card-completion.full {
  color: var(--success);
}

.week-card-days-range {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 3px;
  white-space: nowrap;
}

/* Collapsible about section */
.about-collapse-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: var(--s6);
}

.about-toggle-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s4) var(--s5);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-surface);
  transition: background var(--t-fast);
}

.about-toggle-btn:hover {
  background: var(--bg-surface2);
}

.about-chevron {
  font-size: 0.72rem;
  color: var(--text-sec);
  transition: transform 0.25s ease;
}

.about-toggle-btn[aria-expanded="true"] .about-chevron {
  transform: rotate(180deg);
}

.about-collapse-body {
  padding: var(--s4) var(--s5);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

.about-collapse-body p {
  font-size: 0.88rem;
  color: var(--text-sec);
  line-height: 1.75;
}


/* ----------------------------------------------------------------
   19. ABOUT VIEW
---------------------------------------------------------------- */
.about-body {
  padding-bottom: var(--s6);
}

.about-text-section {
  margin-top: var(--s4);
  margin-bottom: var(--s2);
}

.about-text-section p {
  font-size: 0.93rem;
  color: var(--text-sec);
  line-height: 1.8;
}

/* Sessions list */
.sessions-list {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: var(--s2);
}

.session-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--border);
}

.session-list-item:last-child {
  border-bottom: none;
}

.session-list-title {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
}

.session-list-meta {
  font-size: 0.78rem;
  color: var(--text-sec);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Audio file note box */
.audio-file-note {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s5);
  margin-bottom: var(--s2);
}

.audio-file-note p {
  font-size: 0.88rem;
  color: var(--text-sec);
  line-height: 1.65;
  margin-bottom: var(--s3);
}

.audio-filenames {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.audio-filenames li {
  padding: var(--s1) 0;
}


/* ----------------------------------------------------------------
   20. DAY 30 COMPLETION SCREEN
---------------------------------------------------------------- */
.completion-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s8) var(--page-x);
  overflow-y: auto;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.completion-screen.open {
  opacity: 1;
}

.completion-content {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.completion-emoji {
  font-size: 4.5rem;
  margin-bottom: var(--s6);
  animation: float 3.5s ease-in-out infinite;
  line-height: 1;
}

.completion-headline {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  color: var(--text);
  margin-bottom: var(--s2);
}

.completion-subheadline {
  font-size: 1rem;
  font-weight: 500;
  color: var(--accent-text);
  letter-spacing: 0.01em;
  margin-bottom: var(--s6);
}

.completion-message {
  font-size: 0.95rem;
  color: var(--text-sec);
  line-height: 1.8;
  max-width: 320px;
  margin-bottom: var(--s8);
}

.completion-stats {
  display: flex;
  gap: var(--s4);
  justify-content: center;
  margin-bottom: var(--s8);
}

.completion-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s5) var(--s8);
  min-width: 100px;
}

.completion-stat-value {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--accent-text);
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 4px;
}

.completion-stat-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.completion-brand {
  margin-top: var(--s6);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}


/* ----------------------------------------------------------------
   21. ANIMATIONS & KEYFRAMES
---------------------------------------------------------------- */

/* Task circle pop on check */
@keyframes task-check-pop {
  0%   { transform: scale(1);    }
  40%  { transform: scale(1.38); }
  65%  { transform: scale(0.88); }
  100% { transform: scale(1);    }
}

/* Floating completion emoji */
@keyframes float {
  0%, 100% { transform: translateY(0px);   }
  50%       { transform: translateY(-12px); }
}

/* General fade-up (applied by JS on view render) */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-up {
  animation: fade-up 0.3s ease both;
}

/* Completion button success state ripple */
@keyframes ripple-success {
  from {
    transform: scale(0);
    opacity: 0.6;
  }
  to {
    transform: scale(4);
    opacity: 0;
  }
}

.btn-complete.completing::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.3);
  animation: ripple-success 0.55s ease forwards;
}


/* ----------------------------------------------------------------
   22. SCROLLBAR STYLING (webkit only)
---------------------------------------------------------------- */
.view-scroll::-webkit-scrollbar,
.day-detail-panel::-webkit-scrollbar {
  width: 3px;
}

.view-scroll::-webkit-scrollbar-track,
.day-detail-panel::-webkit-scrollbar-track {
  background: transparent;
}

.view-scroll::-webkit-scrollbar-thumb,
.day-detail-panel::-webkit-scrollbar-thumb {
  background: var(--border-md);
  border-radius: var(--r-full);
}


/* ----------------------------------------------------------------
   23. LIBRARY VIEW
---------------------------------------------------------------- */

/* Sticky now-playing card */
.lib-player-card {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  padding: var(--s4);
  margin-bottom: var(--s5);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

/* Empty state — shown before any session is selected */
.lib-player-empty {
  display: flex;
  align-items: center;
  gap: var(--s3);
  color: var(--text-muted);
  font-size: 0.875rem;
  min-height: 52px;
}

.lib-player-empty-icon {
  font-size: 1.5rem;
  line-height: 1;
}

/* Now-playing info row */
.lib-now-playing-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: var(--s1);
}

.lib-now-playing-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--s2);
}

.lib-now-playing-meta {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-surface3);
  padding: 2px 10px;
  border-radius: var(--r-full);
  margin-bottom: var(--s3);
}

/* Strip the default card appearance from the player inside the lib card */
.lib-audio-player {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 0;
}

/* Session list */
.lib-session-card {
  display: flex;
  align-items: center;
  gap: var(--s3);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s3);
  cursor: pointer;
  transition: background var(--t-base), border-color var(--t-base),
              transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.lib-session-card:hover {
  background: var(--bg-surface2);
  border-color: var(--border-md);
}

.lib-session-card:active {
  transform: scale(0.985);
}

.lib-session-card.lib-active {
  border-color: var(--accent);
  background: var(--bg-surface2);
}

.lib-session-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.lib-session-info {
  flex: 1;
  min-width: 0;
}

.lib-session-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 var(--s1) 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lib-session-meta {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-surface2);
  padding: 2px 8px;
  border-radius: var(--r-full);
}

.lib-session-card.lib-active .lib-session-meta {
  background: var(--accent-dim);
  color: var(--accent-text);
}

/* Small play indicator on the right of each card */
.lib-play-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-md);
  background: var(--bg-surface2);
  color: var(--text-sec);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast);
  flex-shrink: 0;
}

.lib-session-card:hover .lib-play-btn {
  border-color: var(--accent);
  color: var(--accent-text);
}

.lib-session-card.lib-active .lib-play-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}


/* ----------------------------------------------------------------
   24. RESPONSIVE — TABLET / DESKTOP (≥ 768px)
---------------------------------------------------------------- */
@media (min-width: 768px) {
  :root {
    --page-x: 28px;
    --nav-h:  72px;
  }

  /* Center the app in a framed shell */
  .app {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .bottom-nav {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 480px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  /* Modals stay full-screen (intentional) but panel max-width matches */
  .day-detail-panel {
    max-width: 480px;
    margin: 0 auto;
  }

  .completion-screen {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 480px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .onboarding-screen {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .storage-warning {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 480px;
    border-radius: 0 0 var(--r-sm) var(--r-sm);
  }

  /* Slightly larger type on desktop */
  .view-title {
    font-size: 1.75rem;
  }

  .session-card {
    padding: var(--s6);
  }

  .day-grid {
    gap: var(--s3);
  }

  .play-pause-btn {
    width: 70px;
    height: 70px;
  }
}

/* Dark canvas behind the framed app on wide screens */
@media (min-width: 900px) {
  body {
    background: #060810;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    min-height: 100vh;
  }
}
