/* ============================================================
   Night Rescue Kit — interior design system
   Dim mode by default. Auto-flips to light between 7 AM and 8 PM
   only if the user hasn't manually overridden.
   ============================================================ */

:root {
  --font-serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  /* Dim tokens (default) */
  --surface:        #23201D;
  --surface-lifted: #2C2925;
  --surface-hover:  #34302B;
  --ink-primary:    #EFE6D7;
  --ink-secondary:  #B6AC9F;
  --ink-tertiary:   #877E73;
  --hairline:       #3D3833;
  --accent:         #C9A89B;
  --alert:          #D89571;
  --alert-bg:       rgba(216, 149, 113, 0.07);
  --alert-border:   rgba(216, 149, 113, 0.25);
  --on-accent:      #23201D;

  /* Motion */
  --t-fast: 160ms;
  --t-base: 240ms;
  --t-slow: 360ms;
  --ease:   cubic-bezier(0.22, 0.61, 0.36, 1);

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-8: 48px;
  --space-10: 64px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  /* App shell width */
  --shell-max: 480px;
}

[data-theme="light"] {
  --surface:        #F7F1E8;
  --surface-lifted: #FBF7F0;
  --surface-hover:  #EFE6D7;
  --ink-primary:    #2A2622;
  --ink-secondary:  #5C544B;
  --ink-tertiary:   #8A7F73;
  --hairline:       #E5D5C2;
  --accent:         #C9A89B;
  --alert:          #B86F3F;
  --alert-bg:       rgba(184, 111, 63, 0.05);
  --alert-border:   rgba(184, 111, 63, 0.3);
  --on-accent:      #FBF7F0;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--surface);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 18px;
  line-height: 1.65;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--t-base) var(--ease), color var(--t-base) var(--ease);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 4px;
}

/* ============================================================
   App shell — single phone-sized frame on tablet/desktop,
   full-bleed on phones.
   ============================================================ */

.shell {
  max-width: var(--shell-max);
  margin: 32px auto;
  min-height: calc(100dvh - 64px);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 32px 64px -24px rgba(0,0,0,0.45);
  transition: background var(--t-base) var(--ease), border-color var(--t-base) var(--ease);
}
@media (max-width: 540px) {
  .shell {
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    border: 0;
    min-height: 100dvh;
    box-shadow: none;
  }
}

/* Top emergency bar — persistent */
.top-bar {
  background: var(--surface-lifted);
  border-bottom: 1px solid var(--hairline);
  padding: 10px 20px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-tertiary);
  font-weight: 500;
  letter-spacing: 0.05em;
}
.top-bar a {
  color: var(--alert);
  font-style: italic;
  text-decoration: none;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.brand-tag {
  font-family: var(--font-serif);
  font-size: 18px;
  font-style: italic;
  color: var(--ink-primary);
  letter-spacing: 0.005em;
}
.brand-tag span { font-style: normal; }
.header-controls { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--ink-secondary);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--surface-hover); color: var(--ink-primary); }
.icon-btn svg { width: 20px; height: 20px; }

/* Bottom persistent navigation */
.bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-top: 1px solid var(--hairline);
  background: var(--surface-lifted);
  flex-shrink: 0;
}
.bottom-nav a {
  font-size: 13px;
  color: var(--ink-tertiary);
  letter-spacing: 0.01em;
  transition: color var(--t-fast) var(--ease);
  padding: 6px 0;
}
.bottom-nav a:hover, .bottom-nav a:focus-visible { color: var(--ink-primary); }

/* ============================================================
   Screens — only one visible at a time, controlled by the router
   ============================================================ */

.screen {
  display: none;
  flex: 1;
  padding: 32px 24px 24px;
  flex-direction: column;
  animation: fade-in var(--t-base) var(--ease);
}
.screen.active { display: flex; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Back row — present on every non-entry screen */
.back-row { margin: -8px 0 16px; }
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-tertiary);
  padding: 8px 4px 8px 0;
  letter-spacing: 0.01em;
  transition: color var(--t-fast) var(--ease);
}
.back-btn:hover, .back-btn:focus-visible { color: var(--ink-primary); }
.back-btn svg { width: 14px; height: 14px; }

/* ============================================================
   Welcome screen (#/)
   ============================================================ */

.welcome { justify-content: center; align-items: center; text-align: center; gap: 24px; }
.welcome .mark {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  color: var(--accent);
  margin-bottom: 8px;
}
.welcome .mark svg { width: 26px; height: 26px; }
.welcome h1 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 36px;
  line-height: 1.15;
  margin: 0;
  letter-spacing: -0.01em;
}
.welcome h1 em { font-style: italic; }
.welcome .pivot {
  font-family: var(--font-serif);
  font-size: 19px;
  font-style: italic;
  color: var(--ink-secondary);
  margin: 0;
  max-width: 340px;
}
.welcome .prompt {
  font-size: 15px;
  color: var(--ink-tertiary);
  margin: 8px 0 0;
}
.welcome .actions {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* ============================================================
   Quick Start entry
   ============================================================ */

.lead {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 32px;
  line-height: 1.2;
  margin: 8px 0 4px;
  letter-spacing: -0.01em;
}
.lead em { font-style: italic; }
.sub {
  font-size: 14px;
  color: var(--ink-tertiary);
  margin: 0 0 24px;
}

.triage-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.triage-btn {
  width: 100%;
  text-align: left;
  padding: 18px 20px;
  min-height: 64px;
  background: var(--surface-lifted);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  color: var(--ink-primary);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.triage-btn:hover, .triage-btn:focus-visible {
  background: var(--surface-hover);
  border-color: var(--ink-tertiary);
  transform: translateY(-1px);
}
.triage-btn .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  opacity: 0.6;
}

.fine-link {
  margin-top: 24px;
  display: block;
  text-align: center;
  font-size: 13px;
  color: var(--ink-tertiary);
  padding: 12px 0;
  letter-spacing: 0.01em;
}
.fine-link:hover, .fine-link:focus-visible { color: var(--ink-secondary); }

/* ============================================================
   Answer / module text screens
   ============================================================ */

.answer-headline,
.module-headline {
  font-family: var(--font-serif);
  font-weight: 400;
  font-style: italic;
  font-size: 28px;
  line-height: 1.3;
  color: var(--ink-primary);
  margin: 0 0 24px;
  letter-spacing: -0.005em;
}
.module-eyebrow {
  font-size: 12px;
  color: var(--ink-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 8px;
  font-weight: 500;
}

.block { margin-bottom: 22px; }
.block-label {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  margin: 0 0 6px;
}
.block p {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink-primary);
}
.block p em { font-style: italic; color: var(--ink-secondary); }
.block ul, .block ol {
  margin: 8px 0 0;
  padding-left: 20px;
}
.block li { margin-bottom: 6px; }

/* Step-list style (used in Overwhelm reset, 20/20/20, etc.) */
.step-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
}
.step-list li {
  position: relative;
  padding: 10px 0 10px 28px;
  border-bottom: 1px solid var(--hairline);
  font-size: 16px;
  line-height: 1.55;
}
.step-list li:last-child { border-bottom: 0; }
.step-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18px;
  width: 12px;
  height: 12px;
  border: 1px solid var(--ink-tertiary);
  border-radius: 3px;
}

/* Alert / boundary block — used for "this becomes medical if" */
.alert-block {
  background: var(--alert-bg);
  border: 1px solid var(--alert-border);
  border-radius: var(--r-md);
  padding: 16px 18px;
  margin: 8px 0 24px;
}
.alert-block .label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--alert);
  font-weight: 500;
  margin: 0 0 6px;
}
.alert-block p {
  margin: 0;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink-primary);
}
.alert-block em { color: var(--ink-secondary); }
.alert-block ul {
  margin: 8px 0 0;
  padding-left: 20px;
}
.alert-block li { margin-bottom: 4px; }

/* Card-on-surface (e.g. tinted boxes) */
.tint-card {
  background: var(--surface-lifted);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 18px 20px;
  margin: 0 0 22px;
}
.tint-card h3 {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 18px;
  margin: 0 0 8px;
  color: var(--ink-primary);
}
.tint-card p { font-size: 15px; line-height: 1.6; margin: 0 0 6px; color: var(--ink-secondary); }
.tint-card p:last-child { margin-bottom: 0; }

/* ============================================================
   Action buttons (bottom of answer/module screens)
   ============================================================ */

.actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 24px;
}
.action-btn {
  width: 100%;
  padding: 16px 18px;
  background: var(--ink-primary);
  color: var(--surface);
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 56px;
  text-align: center;
  letter-spacing: 0.005em;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.action-btn:hover, .action-btn:focus-visible {
  opacity: 0.92;
  transform: translateY(-1px);
}
.action-btn.secondary {
  background: transparent;
  color: var(--ink-primary);
  border: 1px solid var(--hairline);
}
.action-btn.secondary:hover, .action-btn.secondary:focus-visible {
  background: var(--surface-hover);
  border-color: var(--ink-tertiary);
}
.action-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ============================================================
   Audio screen — player + track list + transcript
   ============================================================ */

.audio-screen h1 {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 28px;
  line-height: 1.3;
  margin: 0 0 6px;
}
.audio-screen .meta {
  font-size: 14px;
  color: var(--ink-tertiary);
  margin: 0 0 24px;
}

.audio-player {
  background: var(--surface-lifted);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 24px 22px;
  margin-bottom: 20px;
}
.audio-now {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 20px;
  margin: 0 0 16px;
  color: var(--ink-primary);
}
.audio-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}
.play-big {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--ink-primary);
  color: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--t-fast) var(--ease);
}
.play-big:hover, .play-big:focus-visible { transform: scale(1.04); }
.play-big svg { width: 22px; height: 22px; margin-left: 2px; }
.play-big[data-playing="true"] svg { margin-left: 0; }

.audio-progress { flex: 1; }
.progress-bar {
  height: 4px;
  background: var(--hairline);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 200ms linear;
}
.audio-time-row {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-tertiary);
  font-variant-numeric: tabular-nums;
}

.audio-pending {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: var(--surface-hover);
  font-size: 13px;
  color: var(--ink-secondary);
  font-style: italic;
  line-height: 1.5;
}

.track-list {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.track-item {
  padding: 14px 16px;
  background: var(--surface-lifted);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.track-item:hover, .track-item:focus-visible { background: var(--surface-hover); }
.track-item.active {
  border-color: var(--accent);
  background: var(--surface-hover);
}
.track-info { flex: 1; min-width: 0; }
.track-title {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 17px;
  color: var(--ink-primary);
  margin: 0 0 2px;
}
.track-meta { font-size: 12px; color: var(--ink-tertiary); }
.track-play {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.track-play svg { width: 12px; height: 12px; margin-left: 1px; }

/* Transcript panel (compliance + accessibility) */
.transcript {
  background: transparent;
  border-top: 1px solid var(--hairline);
  padding: 20px 0 0;
  margin-top: 4px;
}
.transcript summary {
  cursor: pointer;
  font-size: 14px;
  color: var(--ink-tertiary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
  padding: 8px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.transcript summary::-webkit-details-marker { display: none; }
.transcript summary::after {
  content: "+";
  margin-left: auto;
  font-size: 18px;
  color: var(--ink-tertiary);
  transition: transform var(--t-fast) var(--ease);
}
.transcript[open] summary::after { content: "−"; }
.transcript-body {
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink-secondary);
  padding-top: 12px;
}
.transcript-body p { margin: 0 0 12px; }
.transcript-body em { color: var(--ink-primary); }
.transcript-body .stage {
  display: block;
  font-family: var(--font-sans);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink-tertiary);
  font-style: normal;
  margin: 6px 0 12px;
  padding-left: 14px;
  border-left: 1px solid var(--hairline);
}

/* ============================================================
   Reassurance scripts — card stack
   ============================================================ */

.reassurance-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reassurance-card {
  background: var(--surface-lifted);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 22px 22px 18px;
  position: relative;
}
.reassurance-card .quote {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 19px;
  line-height: 1.45;
  margin: 0;
  color: var(--ink-primary);
}
.reassurance-card .star {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-tertiary);
  border-radius: 50%;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.reassurance-card .star:hover, .reassurance-card .star:focus-visible {
  color: var(--accent);
  background: var(--surface-hover);
}
.reassurance-card .star[aria-pressed="true"] { color: var(--accent); }
.reassurance-card .star svg { width: 18px; height: 18px; }

/* ============================================================
   Resource list (Module 11)
   ============================================================ */

.resource-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.resource-card {
  background: var(--surface-lifted);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 18px 20px;
}
.resource-card .cat {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  margin: 0 0 6px;
  font-weight: 500;
}
.resource-card h3 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 19px;
  line-height: 1.3;
  margin: 0 0 6px;
  color: var(--ink-primary);
}
.resource-card p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-secondary);
  margin: 0 0 4px;
}
.resource-card .note {
  font-style: italic;
  color: var(--ink-secondary);
  margin-top: 8px;
  font-size: 14px;
}

/* ============================================================
   Browse (full Kit index)
   ============================================================ */

.module-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.module-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  background: var(--surface-lifted);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  width: 100%;
  text-align: left;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.module-card:hover, .module-card:focus-visible {
  background: var(--surface-hover);
  border-color: var(--ink-tertiary);
  transform: translateY(-1px);
}
.module-card .num {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 22px;
  color: var(--accent);
  width: 36px;
  flex-shrink: 0;
}
.module-card .info { flex: 1; min-width: 0; }
.module-card .title {
  font-size: 16px;
  font-weight: 500;
  color: var(--ink-primary);
  margin: 0 0 2px;
}
.module-card .desc {
  font-size: 13px;
  color: var(--ink-tertiary);
  margin: 0;
  line-height: 1.45;
}
.module-card .arrow {
  color: var(--ink-tertiary);
  flex-shrink: 0;
}
.module-card .arrow svg { width: 16px; height: 16px; }

/* ============================================================
   Numbers / phone-call directory (Module 10)
   ============================================================ */

.call-directory {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  border-top: 1px solid var(--hairline);
}
.call-directory li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 15px;
}
.call-directory .when { color: var(--ink-secondary); flex: 1; }
.call-directory .num-link {
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--ink-primary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.call-directory .num-link:hover { color: var(--accent); }

/* ============================================================
   Footer disclaimer (visible on every screen, footer of bottom-nav)
   ============================================================ */

.shell-footer {
  padding: 10px 20px 14px;
  text-align: center;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  font-size: 11px;
  color: var(--ink-tertiary);
  line-height: 1.5;
  letter-spacing: 0.01em;
}

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

/* ============================================================
   Print — minimal, used for the in-app printable views
   ============================================================ */
@media print {
  body { background: white; color: black; }
  .top-bar, .app-header, .bottom-nav, .shell-footer, .actions, .back-row { display: none; }
  .shell { box-shadow: none; border: 0; max-width: 100%; margin: 0; }
  .screen { padding: 0; }
}
