/* Baby Development Hub — v2 post-critique */
:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-hover: #1f3460;
  --text: #e2e2e2;
  --text-muted: #a0b0c0;
  --accent: #7b68ee;
  --accent-glow: rgba(123, 104, 238, 0.3);
  --safe-green: #5cb85c;
  --warm-amber: #f0ad4e;
  --soft-pink: #e8a0bf;
  --calm-blue: #5dade2;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --max-w: 860px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* -- Focus styles -- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, .age-tab:focus-visible, .filter-chip:focus-visible, .activity-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* -- Reduced motion -- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Wrapper */
.page-wrap {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.header {
  padding: 28px 4px 16px;
  text-align: center;
}
.header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
}
.header h1 span { color: var(--accent); }
.header .subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Age selector tabs */
.age-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 0 6px;
  justify-content: center;
}
.age-tab {
  flex: 1;
  max-width: 140px;
  min-width: 80px;
  padding: 12px 10px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  line-height: 1.3;
}
.age-tab:active { transform: scale(0.96); }
.age-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.age-tab .tab-emoji { font-size: 1.3rem; display: block; margin-bottom: 3px; }

/* Filter chips */
.filter-row {
  display: flex;
  gap: 6px;
  padding: 10px 0;
  justify-content: center;
  flex-wrap: wrap;
}
.filter-chip {
  padding: 7px 16px;
  border-radius: 20px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}
.filter-chip:active { transform: scale(0.95); }
.filter-chip.active { background: rgba(123,104,238,0.15); border-color: var(--accent); color: var(--accent); }
.filter-chip[data-type="visual"].active { background: rgba(93,173,226,0.15); border-color: var(--calm-blue); color: var(--calm-blue); }
.filter-chip[data-type="audio"].active { background: rgba(123,104,238,0.15); border-color: var(--accent); color: var(--accent); }
.filter-chip[data-type="language"].active { background: rgba(232,160,191,0.15); border-color: var(--soft-pink); color: var(--soft-pink); }
.filter-chip[data-type="cognitive"].active { background: rgba(240,173,78,0.15); border-color: var(--warm-amber); color: var(--warm-amber); }
.filter-chip[data-type="sleep"].active { background: rgba(92,184,92,0.15); border-color: var(--safe-green); color: var(--safe-green); }

/* Main content */
.content { padding: 4px 0 100px; }

/* AAP notice */
.aap-notice {
  background: rgba(240,173,78,0.06);
  border: 1px solid rgba(240,173,78,0.15);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.75rem;
  line-height: 1.55;
  color: rgba(240,173,78,0.85);
}
.aap-notice strong { color: var(--warm-amber); }

/* Intro / onboarding */
.onboarding {
  text-align: center;
  padding: 8px 12px 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.onboarding-dismiss {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 14px;
  font-size: 0.7rem;
  color: var(--accent);
  cursor: pointer;
  border: 1px solid var(--accent);
  border-radius: 20px;
  background: transparent;
}

/* Progress */
.progress-container { margin-bottom: 14px; }
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Activity grid */
.activity-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 580px) { .activity-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 800px) { .activity-grid { grid-template-columns: repeat(4, 1fr); } }

/* Cards */
.activity-card {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 18px 14px 16px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  border: 1px solid rgba(255,255,255,0.04);
  border-left: 3px solid rgba(255,255,255,0.06);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}
.activity-card:active { transform: scale(0.97); }
.activity-card:hover {
  border-color: rgba(123,104,238,0.3);
  border-left-color: rgba(123,104,238,0.3);
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  transform: translateY(-2px);
}
/* Type-colored left border */
.activity-card[data-type="visual"] { border-left-color: var(--calm-blue); }
.activity-card[data-type="audio"] { border-left-color: var(--accent); }
.activity-card[data-type="language"] { border-left-color: var(--soft-pink); }
.activity-card[data-type="cognitive"] { border-left-color: var(--warm-amber); }
.activity-card[data-type="sleep"] { border-left-color: var(--safe-green); }
.activity-card .card-icon { font-size: 2rem; margin-bottom: 10px; }
.activity-card h3 {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 5px;
  color: #fff;
  line-height: 1.25;
}
.activity-card p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.45;
  flex: 1;
}
.activity-card .card-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}
.activity-card .card-done {
  position: absolute;
  bottom: 12px;
  right: 12px;
  font-size: 0.7rem;
  color: var(--safe-green);
}

.badge-visual { background: rgba(93,173,226,0.15); color: var(--calm-blue); }
.badge-audio { background: rgba(123,104,238,0.15); color: var(--accent); }
.badge-cognitive { background: rgba(240,173,78,0.15); color: var(--warm-amber); }
.badge-language { background: rgba(232,160,191,0.15); color: var(--soft-pink); }
.badge-sleep { background: rgba(92,184,92,0.15); color: var(--safe-green); }

/* ---- Player overlay ---- */
.player-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: none;
  flex-direction: column;
}
.player-overlay.active { display: flex; }

.player-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Desktop: centered modal */
@media (min-width: 768px) {
  .player-overlay {
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    align-items: center;
    justify-content: center;
  }
  .player-inner {
    max-width: 520px;
    width: 95%;
    height: auto;
    max-height: 88vh;
    border-radius: 20px;
    overflow: hidden;
    background: var(--bg);
    box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  }
  .visual-area {
    min-height: 280px;
    max-height: 360px;
    aspect-ratio: 4/3;
  }
  /* Wider page on large screens */
  .page-wrap { max-width: 960px; }
  .header { padding-top: 36px; }
}

.player-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}
.player-back {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: none;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-back:hover { background: var(--bg-hover); }
.player-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  flex: 1;
}

/* Canvas */
.visual-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  min-height: 220px;
}
@media (min-width: 768px) {
  .visual-area { min-height: 300px; max-height: 400px; }
}
.visual-area canvas { width: 100%; height: 100%; display: block; }

/* Player controls */
.player-controls {
  padding: 14px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-top: 1px solid rgba(255,255,255,0.05);
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.btn-play {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: transform 0.15s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-play:active { transform: scale(0.92); }
.btn-play:hover { box-shadow: 0 8px 28px var(--accent-glow); }

.btn-secondary {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.14); }

/* Volume */
.volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}
.volume-row span { font-size: 0.85rem; }
.volume-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
  outline: none;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

/* Timer */
.timer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 4px;
}
.timer-select {
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
}

/* Evidence */
.evidence-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--calm-blue);
  font-weight: 600;
  user-select: none;
  border-radius: 10px;
  background: rgba(93,173,226,0.06);
  transition: background 0.15s;
}
.evidence-toggle:hover { background: rgba(93,173,226,0.12); }
.evidence-toggle::before { content: '📚'; font-size: 0.9rem; }
.evidence-toggle::after {
  content: '▾';
  margin-left: auto;
  font-size: 0.7rem;
  transition: transform 0.2s;
}
.evidence-toggle.open::after { transform: rotate(180deg); }

.evidence-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease-out;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.6;
  padding: 0 14px;
}
.evidence-body.open {
  max-height: 600px;
  padding-top: 8px;
  padding-bottom: 12px;
}
.evidence-body p { margin-bottom: 8px; }
.evidence-body cite {
  display: block;
  font-style: italic;
  margin-top: 4px;
  padding-left: 10px;
  border-left: 2px solid var(--accent);
  font-size: 0.68rem;
}

/* Background mode indicator */
.bg-mode-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--safe-green);
  z-index: 200;
  display: none;
}
.bg-mode-indicator.active { display: block; }

/* Safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .player-controls { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
  .content { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
}

/* Empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.empty-state .empty-emoji { font-size: 2rem; margin-bottom: 8px; display: block; }

/* Spinner */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
