/* ============================================
   BASELINE — Design System & Styles
   Biohacking / Alta Performance Aesthetic
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* --- CSS Custom Properties --- */
:root {
  --bg-primary: #121212;
  --bg-card: #1e1e1e;
  --bg-card-hover: #252525;
  --bg-surface: #181818;
  --bg-elevated: #2a2a2a;

  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-tertiary: #6b6b6b;
  --text-muted: #4a4a4a;

  --accent: #00e5ff;
  --accent-glow: rgba(0, 229, 255, 0.25);
  --accent-soft: rgba(0, 229, 255, 0.08);
  --accent-border: rgba(0, 229, 255, 0.15);

  --danger: #ff4757;
  --danger-glow: rgba(255, 71, 87, 0.25);
  --danger-soft: rgba(255, 71, 87, 0.08);
  --danger-border: rgba(255, 71, 87, 0.2);

  --success: #2ed573;
  --success-glow: rgba(46, 213, 115, 0.25);

  --warning: #ffa502;

  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-accent: 0 4px 24px var(--accent-glow);
  --shadow-danger: 0 4px 24px var(--danger-glow);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  --navbar-height: 72px;
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-primary);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- App Shell --- */
.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background: var(--bg-primary);
}

/* Subtle side borders on desktop */
@media (min-width: 481px) {
  .app-shell {
    box-shadow: -1px 0 0 var(--bg-card), 1px 0 0 var(--bg-card);
  }

  body {
    background: #0a0a0a;
  }
}

/* --- Main Content Area --- */
.main-content {
  padding: 20px 20px calc(var(--navbar-height) + var(--safe-area-bottom) + 24px);
  animation: fadeInUp 0.5s var(--transition-base) both;
}

.main-content.no-nav {
  padding-bottom: 24px;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 8px;
  margin-bottom: 8px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow), 0 0 16px var(--accent-glow);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.inactive {
  background: var(--text-tertiary);
  box-shadow: none;
  animation: none;
}

.header-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
}

.header-logo {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text-tertiary);
  text-transform: uppercase;
}

/* --- Timer Display (Dashboard) --- */
.timer-section {
  text-align: center;
  padding: 32px 0 24px;
}

.timer-label {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.timer-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.timer-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}

.timer-value {
  font-family: var(--font-mono);
  font-size: 3.2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  text-shadow: 0 0 20px var(--accent-glow), 0 0 40px rgba(0, 229, 255, 0.1);
  transition: var(--transition-fast);
}

.timer-unit {
  font-size: 0.6rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.timer-separator {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 300;
  color: var(--text-tertiary);
  padding-bottom: 22px;
  animation: blink 1.5s ease-in-out infinite;
}

/* --- Resilience Stat --- */
.resilience-stat {
  text-align: center;
  margin-top: 4px;
  padding: 12px 0;
}

.resilience-label {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.resilience-value {
  color: var(--success);
  font-weight: 700;
  font-family: var(--font-mono);
}

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  transition: transform var(--transition-base), background var(--transition-base);
}

.card:hover {
  background: var(--bg-card-hover);
}

.card-accent-border {
  border-left: 3px solid var(--accent);
  border-color: var(--accent-border);
  border-left-color: var(--accent);
}

.card-title {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon {
  font-size: 0.85rem;
}

.card-text {
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text-secondary);
  font-weight: 400;
}

.card-text strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* --- Buttons --- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 18px 24px;
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-primary);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.btn:active::after {
  opacity: 1;
}

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

/* Primary (Accent) Button */
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #00b8d4 100%);
  color: var(--bg-primary);
  box-shadow: var(--shadow-accent);
}

.btn-primary:hover {
  box-shadow: 0 6px 32px var(--accent-glow);
  transform: translateY(-1px);
}

/* Danger Outline Button */
.btn-danger-outline {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1.5px solid var(--danger-border);
  font-size: 0.78rem;
  padding: 14px 20px;
  letter-spacing: 1px;
}

.btn-danger-outline:hover {
  background: rgba(255, 71, 87, 0.12);
  border-color: var(--danger);
  box-shadow: var(--shadow-danger);
}

/* Secondary / Ghost Button */
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Success Button */
.btn-success {
  background: linear-gradient(135deg, var(--success) 0%, #1abc9c 100%);
  color: var(--bg-primary);
  box-shadow: 0 4px 24px var(--success-glow);
}

.btn-success:hover {
  box-shadow: 0 6px 32px var(--success-glow);
  transform: translateY(-1px);
}

/* --- Bottom Navigation --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--navbar-height);
  padding-bottom: var(--safe-area-bottom);
  background: rgba(18, 18, 18, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
}

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

.nav-item .nav-label {
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  transition: color var(--transition-fast);
}

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

.nav-item.active .nav-icon {
  transform: scale(1.1);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.nav-item:not(.active):hover .nav-label {
  color: var(--text-secondary);
}

/* --- SOS Page Styles --- */
.sos-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  text-align: center;
}

.sos-back {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  letter-spacing: 0.5px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.sos-back:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.sos-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--accent);
  margin-bottom: 8px;
}

.sos-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 40px;
  max-width: 280px;
  line-height: 1.5;
}

/* Giant SOS Timer */
.sos-timer {
  font-family: var(--font-mono);
  font-size: 5rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-glow), 0 0 60px rgba(0, 229, 255, 0.08);
  line-height: 1;
  margin-bottom: 12px;
  letter-spacing: 4px;
  transition: color var(--transition-base);
}

.sos-timer.warning {
  color: var(--warning);
  text-shadow: 0 0 30px rgba(255, 165, 2, 0.25), 0 0 60px rgba(255, 165, 2, 0.08);
}

.sos-timer.danger {
  color: var(--danger);
  text-shadow: 0 0 30px var(--danger-glow), 0 0 60px rgba(255, 71, 87, 0.08);
  animation: pulse-text 0.8s ease-in-out infinite;
}

.sos-progress {
  width: 200px;
  height: 3px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 40px;
}

.sos-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 1s linear, background var(--transition-base);
  box-shadow: 0 0 8px var(--accent-glow);
}

.sos-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 400;
}

/* SOS Buttons */
.sos-btn-activate {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition-base);
  box-shadow: 0 0 40px var(--accent-glow), inset 0 0 40px var(--accent-soft);
  animation: breathe 3s ease-in-out infinite;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1.4;
}

.sos-btn-activate:hover {
  background: rgba(0, 229, 255, 0.15);
  box-shadow: 0 0 60px var(--accent-glow), inset 0 0 60px var(--accent-soft);
}

.sos-btn-activate:active {
  transform: scale(0.95);
}

.sos-btn-activate .btn-icon {
  font-size: 2rem;
  display: block;
}

.sos-btn-activate .btn-text {
  font-size: 0.7rem;
  max-width: 120px;
}

/* SOS Completion */
.sos-complete {
  animation: fadeInUp 0.5s ease both;
}

.sos-complete-icon {
  font-size: 3.5rem;
  margin-bottom: 20px;
}

.sos-complete-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.sos-complete-text {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 36px;
  line-height: 1.5;
}

.sos-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

/* --- Diary/Settings Placeholder Pages --- */
.page-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 24px;
  gap: 16px;
}

.page-placeholder .placeholder-icon {
  font-size: 3rem;
  opacity: 0.3;
}

.page-placeholder .placeholder-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.page-placeholder .placeholder-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  max-width: 260px;
  line-height: 1.5;
}

/* --- Confirmation Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-xl);
  padding: 28px 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  transform: scale(0.9) translateY(20px);
  transition: transform var(--transition-spring);
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.modal-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.modal-actions .btn {
  flex: 1;
  padding: 14px 16px;
  font-size: 0.78rem;
}

/* --- Breathing Exercise Modal --- */
.breathing-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.breathing-overlay.active {
  opacity: 1;
  visibility: visible;
}

.breathing-circle {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 24px;
  transition: all 4s ease-in-out;
  box-shadow: 0 0 30px var(--accent-glow);
}

.breathing-circle.inhale {
  transform: scale(1.3);
  background: var(--accent-soft);
}

.breathing-circle.hold {
  transform: scale(1.3);
  background: rgba(0, 229, 255, 0.12);
}

.breathing-circle.exhale {
  transform: scale(1);
  background: transparent;
}

.breathing-circle.hold-empty {
  transform: scale(1);
  background: transparent;
}

.breathing-instruction {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.breathing-phase {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.breathing-close {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 12px 32px;
  border-radius: var(--radius-full);
  font-family: var(--font-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all var(--transition-fast);
}

.breathing-close:hover {
  background: var(--bg-elevated);
}

/* --- Utility Classes --- */
.hidden {
  display: none !important;
}

.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

/* --- Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-dot {
  0%, 100% { 
    opacity: 1;
    box-shadow: 0 0 8px var(--accent-glow), 0 0 16px var(--accent-glow);
  }
  50% { 
    opacity: 0.5;
    box-shadow: 0 0 4px var(--accent-glow);
  }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

@keyframes breathe {
  0%, 100% {
    box-shadow: 0 0 40px var(--accent-glow), inset 0 0 40px var(--accent-soft);
  }
  50% {
    box-shadow: 0 0 60px var(--accent-glow), inset 0 0 60px rgba(0, 229, 255, 0.06);
  }
}

@keyframes pulse-text {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Staggered card entry */
.card:nth-child(1) { animation: fadeInUp 0.4s 0.1s ease both; }
.card:nth-child(2) { animation: fadeInUp 0.4s 0.2s ease both; }
.card:nth-child(3) { animation: fadeInUp 0.4s 0.3s ease both; }
.card:nth-child(4) { animation: fadeInUp 0.4s 0.4s ease both; }
