/* ============================================
   Sepsis Advocate Companion
   Calm, editorial, steady at 3am.
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Playfair+Display:wght@700;900&family=Public+Sans:wght@400;500;600;700&display=swap');

:root {
  /* Palette — deep navy + warm cream paper + sepsis red for emergencies */
  --ink:        #1d3a5f;
  --ink-deep:   #122541;
  --ink-soft:   #4a5f7e;
  --paper:      #f5efe6;
  --paper-warm: #ebe2d3;
  --paper-card: #fbf7f0;
  --line:       #d9cfbe;
  --accent:     #b8593f;     /* warm terracotta — for highlights */
  --emergency:  #c0392b;     /* sepsis red — emergencies only */
  --emergency-deep: #8b1e10;
  --good:       #4a7c59;     /* recovery green */
  --shadow:     0 1px 2px rgba(18,37,65,0.04), 0 4px 16px rgba(18,37,65,0.06);
  --shadow-lift:0 2px 4px rgba(18,37,65,0.06), 0 12px 32px rgba(18,37,65,0.10);

  /* Typography */
  --serif:   'Fraunces', 'Iowan Old Style', Georgia, serif;
  --display: 'Playfair Display', 'Iowan Old Style', Georgia, serif;
  --sans:    'Public Sans', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Rhythm */
  --r-1: 0.25rem;
  --r-2: 0.5rem;
  --r-3: 0.75rem;
  --r-4: 1rem;
  --r-5: 1.5rem;
  --r-6: 2rem;
  --r-7: 3rem;
  --r-8: 4rem;

  --radius:    14px;
  --radius-lg: 22px;

  /* Safe area */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-image:
    radial-gradient(ellipse at top left,  rgba(29,58,95,0.04), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(184,89,63,0.04), transparent 60%);
}

/* ============================================
   Layout shell
   ============================================ */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + var(--r-5)) var(--r-5) calc(var(--safe-bottom) + 96px);
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--r-6);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--r-3);
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper-card);
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 900;
  font-size: 17px;
  letter-spacing: -0.01em;
  line-height: 1;
}

.brand-text {
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.005em;
  line-height: 1.1;
}

.brand-text small {
  display: block;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin-top: 2px;
}

.install-btn {
  display: none;
  background: var(--ink);
  color: var(--paper-card);
  border: 0;
  padding: 10px 16px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.01em;
}

.install-btn.visible { display: inline-flex; align-items: center; gap: 6px; }
.install-btn:hover { background: var(--ink-deep); }

/* ============================================
   Home — module grid
   ============================================ */
.home-hero {
  margin-bottom: var(--r-7);
}

.eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  margin-bottom: var(--r-3);
}

.h-display {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.2rem, 7vw, 3.2rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
  color: var(--ink-deep);
  margin: 0 0 var(--r-4);
}

.h-display em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}

.lede {
  font-size: 18px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0;
  max-width: 52ch;
}

.module-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--r-4);
}

.module-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--r-5);
  text-decoration: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: var(--r-3);
  min-height: 180px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.module-card:active { transform: scale(0.98); }
.module-card:hover { box-shadow: var(--shadow-lift); border-color: var(--ink); }

.module-card.span-2 { grid-column: 1 / -1; min-height: 140px; }

.module-card.recognise {
  background: linear-gradient(160deg, #1d3a5f 0%, #122541 100%);
  color: var(--paper-card);
  border-color: var(--ink-deep);
  grid-column: 1 / -1;
  min-height: 160px;
}
.module-card.recognise .module-meta { color: rgba(245,239,230,0.72); }
.module-card.recognise .module-icon { background: rgba(245,239,230,0.12); color: var(--paper-card); }

.module-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--paper-warm);
  color: var(--ink);
  display: grid;
  place-items: center;
}

.module-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.15;
}

.module-meta {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.45;
}

.module-arrow {
  margin-top: auto;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ============================================
   Page header (sub-pages)
   ============================================ */
.page-head {
  margin-bottom: var(--r-6);
}

.back-btn {
  background: none;
  border: 0;
  color: var(--ink-soft);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: var(--r-4);
}
.back-btn:hover { color: var(--ink); }

.page-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.8rem, 5.5vw, 2.4rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
  color: var(--ink-deep);
  margin: 0 0 var(--r-3);
}

.page-intro {
  color: var(--ink-soft);
  font-size: 16px;
  margin: 0;
  max-width: 60ch;
}

/* ============================================
   Recognise — emergency styling
   ============================================ */
.emergency-banner {
  background: var(--emergency);
  color: #fff;
  padding: var(--r-5);
  border-radius: var(--radius);
  margin-bottom: var(--r-5);
  display: flex;
  gap: var(--r-4);
  align-items: flex-start;
}
.emergency-banner h3 {
  font-family: var(--serif);
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}
.emergency-banner p { margin: 0; font-size: 14px; line-height: 1.5; opacity: 0.95; }
.emergency-banner .icon { flex-shrink: 0; }

.signs-acronym {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--r-5);
  margin-bottom: var(--r-5);
}

.signs-title {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin: 0 0 var(--r-4);
}

.sign-item {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: var(--r-4);
  padding: var(--r-3) 0;
  border-top: 1px solid var(--line);
  align-items: baseline;
}
.sign-item:first-of-type { border-top: 0; padding-top: 0; }

.sign-letter {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 32px;
  color: var(--emergency);
  line-height: 1;
  letter-spacing: -0.02em;
}

.sign-word { font-weight: 600; font-size: 16px; margin: 0 0 2px; color: var(--ink-deep); }
.sign-detail { font-size: 14px; color: var(--ink-soft); margin: 0; line-height: 1.5; }

.call-action {
  display: block;
  text-align: center;
  background: var(--emergency);
  color: #fff;
  padding: 18px;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 700;
  font-size: 17px;
  margin: var(--r-5) 0;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 16px rgba(192,57,43,0.25);
  transition: background 0.15s ease, transform 0.1s ease;
}
.call-action:hover { background: var(--emergency-deep); }
.call-action:active { transform: scale(0.98); }
.call-action small {
  display: block;
  font-size: 12px;
  font-weight: 500;
  opacity: 0.9;
  letter-spacing: 0.05em;
  margin-top: 4px;
  text-transform: uppercase;
}

.audience-toggle {
  display: flex;
  gap: 4px;
  background: var(--paper-warm);
  padding: 4px;
  border-radius: 999px;
  margin-bottom: var(--r-5);
}
.audience-toggle button {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.audience-toggle button.active {
  background: var(--paper-card);
  color: var(--ink-deep);
  box-shadow: var(--shadow);
}

/* Decision tree question card */
.decision-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--r-5);
  margin-bottom: var(--r-4);
}
.decision-q {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  margin: 0 0 var(--r-4);
  line-height: 1.3;
  color: var(--ink-deep);
}
.decision-actions { display: flex; gap: var(--r-3); }
.decision-btn {
  flex: 1;
  background: var(--ink);
  color: var(--paper-card);
  border: 0;
  padding: 14px;
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.decision-btn.no { background: var(--paper-warm); color: var(--ink); }
.decision-btn:hover { opacity: 0.92; }

/* ============================================
   Track — daily check-in
   ============================================ */
.checkin-form .field {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--r-5);
  margin-bottom: var(--r-3);
}

.field-label {
  display: block;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--ink-deep);
}

.field-help {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 var(--r-4);
}

.scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.scale button {
  background: var(--paper-warm);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 14px 4px;
  font: inherit;
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--serif);
}
.scale button:hover { background: var(--paper-card); border-color: var(--line); }
.scale button.selected {
  background: var(--ink);
  color: var(--paper-card);
  border-color: var(--ink-deep);
  transform: scale(1.05);
}

.scale-labels {
  display: flex;
  justify-content: space-between;
  margin-top: var(--r-3);
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 500;
}

.notes-input {
  width: 100%;
  background: var(--paper-warm);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  resize: vertical;
  min-height: 80px;
  font-family: var(--sans);
}
.notes-input:focus {
  outline: none;
  background: var(--paper-card);
  border-color: var(--ink);
}

.save-btn {
  width: 100%;
  background: var(--ink);
  color: var(--paper-card);
  border: 0;
  padding: 16px;
  border-radius: var(--radius);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: var(--r-4);
  letter-spacing: 0.01em;
}
.save-btn:hover { background: var(--ink-deep); }
.save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.history-block {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--r-5);
  margin-top: var(--r-5);
}

.history-title {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin: 0 0 var(--r-4);
}

.history-empty {
  font-size: 14px;
  color: var(--ink-soft);
  text-align: center;
  padding: var(--r-5) 0;
  font-style: italic;
}

.history-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: var(--r-4);
  padding: var(--r-3) 0;
  border-top: 1px solid var(--line);
  align-items: center;
}
.history-row:first-of-type { border-top: 0; }
.history-date {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 14px;
  color: var(--ink-deep);
}
.history-date small { display: block; font-family: var(--sans); font-size: 11px; color: var(--ink-soft); font-weight: 500; }
.history-bars { display: flex; gap: 4px; align-items: flex-end; height: 40px; }
.history-bar { flex: 1; background: var(--ink); border-radius: 3px 3px 0 0; min-height: 4px; opacity: 0.85; }
.history-bar.dim { background: var(--accent); opacity: 0.7; }

.spark-legend {
  display: flex;
  gap: var(--r-4);
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: var(--r-3);
  flex-wrap: wrap;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.spark-legend span::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: 1px;
}
.spark-legend .l-energy::before { background: var(--ink); }
.spark-legend .l-pain::before   { background: var(--accent); }

/* ============================================
   Caregiver
   ============================================ */
.care-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--r-5);
  margin-bottom: var(--r-3);
  display: flex;
  align-items: flex-start;
  gap: var(--r-4);
}

.care-check {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: var(--paper-warm);
  flex-shrink: 0;
  cursor: pointer;
  margin-top: 2px;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}
.care-check.checked {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}
.care-check svg { opacity: 0; transition: opacity 0.15s ease; }
.care-check.checked svg { opacity: 1; }

.care-text { flex: 1; }
.care-q {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  margin: 0 0 4px;
  color: var(--ink-deep);
  line-height: 1.3;
}
.care-note { font-size: 13px; color: var(--ink-soft); margin: 0; line-height: 1.5; }

.care-pullquote {
  border-left: 3px solid var(--accent);
  padding: var(--r-4) var(--r-5);
  margin: var(--r-6) 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink-deep);
}
.care-pullquote cite {
  display: block;
  font-style: normal;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin-top: var(--r-3);
}

/* ============================================
   Resources
   ============================================ */
.resource-section { margin-bottom: var(--r-6); }
.resource-section-title {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin: 0 0 var(--r-4);
}

.resource-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--r-4) var(--r-5);
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
  margin-bottom: var(--r-3);
  gap: var(--r-4);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.resource-link:hover {
  border-color: var(--ink);
  box-shadow: var(--shadow);
}
.resource-link-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 16px;
  margin: 0 0 2px;
  color: var(--ink-deep);
}
.resource-link-desc {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.4;
}
.resource-link-arrow {
  flex-shrink: 0;
  color: var(--ink-soft);
}

/* ============================================
   Disclaimer footer
   ============================================ */
.disclaimer {
  margin-top: var(--r-7);
  padding-top: var(--r-5);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.6;
  text-align: center;
}
.disclaimer strong { color: var(--ink); font-weight: 600; }

/* ============================================
   Toast notification
   ============================================ */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--ink-deep);
  color: var(--paper-card);
  padding: 14px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 100;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================
   Page transitions
   ============================================ */
.view {
  animation: fadeUp 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Stagger module cards on home */
.module-grid .module-card { animation: fadeUp 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) backwards; }
.module-grid .module-card:nth-child(1) { animation-delay: 0.05s; }
.module-grid .module-card:nth-child(2) { animation-delay: 0.12s; }
.module-grid .module-card:nth-child(3) { animation-delay: 0.19s; }
.module-grid .module-card:nth-child(4) { animation-delay: 0.26s; }
.module-grid .module-card:nth-child(5) { animation-delay: 0.33s; }

/* ============================================
   Responsive — keep it simple, mobile-first
   ============================================ */
@media (min-width: 540px) {
  .app { padding: var(--r-7) var(--r-6) calc(var(--safe-bottom) + 96px); }
}

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

/* Focus rings — accessible */
:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, a:focus-visible { outline-offset: 3px; }
