/* =========================================================================
   Terra Rescues — Design System
   Single source of truth for color, type, spacing, radius, motion, and the
   shared components (nav, buttons, cards, forms, footer, icons). Every page
   links this file; nothing here should be redefined per-page.
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }

:root {
  /* ---- Color — light (green-biased paper) ---------------------------- */
  --bg: #F4F7F3;
  --surface: #FFFFFF;
  --surface-2: #EAF1EA;
  --ink: #14211A;
  --ink-2: #34433B;
  --muted: #5F6E64;
  --line: #DBE4DA;
  --line-strong: #C7D3C6;

  --brand: #0F5132;
  --brand-2: #16704A;
  --brand-soft: #E3F0E8;
  --accent: #E8913D;
  --accent-ink: #5E2F00;
  --accent-soft: #FBEAD6;

  --danger: #C0392B;
  --ok: #1E874B;
  --warn: #B9722A;

  /* Dark hero surface — constant across themes (it's always a dark panel) */
  --hero-1: #0A3D26;
  --hero-2: #0F5132;
  --hero-3: #14603E;
  --on-hero: #EAF3EC;
  --on-hero-muted: #B7CFBF;
  --on-hero-faint: #7FA08C;

  /* ---- Type --------------------------------------------------------- */
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --text-xs: 0.78rem;
  --text-sm: 0.9rem;
  --text-base: 1.0625rem;
  --text-lg: 1.2rem;
  --text-xl: clamp(1.35rem, 1.2rem + 0.6vw, 1.6rem);
  --text-2xl: clamp(1.8rem, 1.5rem + 1.4vw, 2.4rem);
  --text-3xl: clamp(2.1rem, 1.62rem + 2.1vw, 3rem);
  --text-4xl: clamp(2.5rem, 1.85rem + 2.9vw, 3.9rem);

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --fw-heavy: 800;

  --lh-tight: 1.08;
  --lh-snug: 1.3;
  --lh-body: 1.6;
  --tracking-tight: -0.02em;
  --tracking-wide: 0.14em;

  /* ---- Spacing (8pt) ------------------------------------------------- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;
  --sp-9: 96px;

  /* ---- Radius — three sizes + full round ----------------------------- */
  --r-sm: 10px;   /* inputs, chips, small controls */
  --r-md: 16px;   /* cards, buttons, icon tiles */
  --r-lg: 24px;   /* large panels, hero mockup */
  --r-pill: 999px;

  /* ---- Motion — one easing curve, three durations -------------------- */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-inout: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-1: 150ms;
  --dur-2: 260ms;
  --dur-3: 640ms;

  /* ---- Elevation — two levels --------------------------------------- */
  --shadow-sm: 0 8px 24px -14px rgba(10, 40, 26, 0.30);
  --shadow-lg: 0 30px 60px -30px rgba(10, 40, 26, 0.42);

  /* ---- Layout ------------------------------------------------------- */
  --maxw: 1120px;
  --maxw-narrow: 760px;
  --nav-h: 66px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0A1710;
    --surface: #10231A;
    --surface-2: #16301F;
    --ink: #EAF3EC;
    --ink-2: #CBDBCF;
    --muted: #9EB2A5;
    --line: #223A2C;
    --line-strong: #2E4A38;

    --brand: #34A76A;
    --brand-2: #4FBE84;
    --brand-soft: #16301F;
    --accent: #E8913D;
    --accent-ink: #EAF3EC;
    --accent-soft: #2A2015;

    --danger: #E8776A;
    --ok: #5FCB8B;
    --warn: #E0A45F;

    --shadow-sm: 0 10px 28px -16px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 30px 64px -28px rgba(0, 0, 0, 0.7);
  }
}

/* Explicit theme stamps win over the media query in both directions. */
:root[data-theme="light"] {
  --bg: #F4F7F3; --surface: #FFFFFF; --surface-2: #EAF1EA; --ink: #14211A;
  --ink-2: #34433B; --muted: #5F6E64; --line: #DBE4DA; --line-strong: #C7D3C6;
  --brand: #0F5132; --brand-2: #16704A; --brand-soft: #E3F0E8; --accent: #E8913D;
  --accent-ink: #5E2F00; --accent-soft: #FBEAD6; --danger: #C0392B; --ok: #1E874B; --warn: #B9722A;
  --shadow-sm: 0 8px 24px -14px rgba(10, 40, 26, 0.30);
  --shadow-lg: 0 30px 60px -30px rgba(10, 40, 26, 0.42);
}
:root[data-theme="dark"] {
  --bg: #0A1710; --surface: #10231A; --surface-2: #16301F; --ink: #EAF3EC;
  --ink-2: #CBDBCF; --muted: #9EB2A5; --line: #223A2C; --line-strong: #2E4A38;
  --brand: #34A76A; --brand-2: #4FBE84; --brand-soft: #16301F; --accent: #E8913D;
  --accent-ink: #EAF3EC; --accent-soft: #2A2015; --danger: #E8776A; --ok: #5FCB8B; --warn: #E0A45F;
  --shadow-sm: 0 10px 28px -16px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 30px 64px -28px rgba(0, 0, 0, 0.7);
}

/* =========================================================================
   Base
   ========================================================================= */
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--text-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
  margin: 0;
}
h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); letter-spacing: -0.01em; }
h4 { font-size: var(--text-lg); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--sp-5); }
.wrap-narrow { max-width: var(--maxw-narrow); }

.eyebrow {
  font-family: var(--sans);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--brand-2);
  margin: 0;
}
.num { font-variant-numeric: tabular-nums; }

/* One visible, consistent focus ring everywhere. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* =========================================================================
   Icons — one line set, sized proportionally to its text context
   ========================================================================= */
.icon {
  width: 1.5em;
  height: 1.5em;
  display: inline-block;
  vertical-align: middle;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-tile {
  width: 48px;
  height: 48px;
  border-radius: var(--r-md);
  background: var(--brand-soft);
  color: var(--brand-2);
  display: grid;
  place-items: center;
  flex: none;
}
.icon-tile .icon { width: 24px; height: 24px; }
.icon-tile.accent { background: var(--accent-soft); color: var(--accent-ink); }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  --btn-bg: transparent;
  --btn-fg: var(--ink);
  --btn-bd: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-family: var(--sans);
  font-weight: var(--fw-bold);
  font-size: var(--text-sm);
  line-height: 1;
  padding: 13px 22px;
  border-radius: var(--r-pill);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--dur-1) var(--ease),
              box-shadow var(--dur-2) var(--ease),
              background var(--dur-2) var(--ease),
              opacity var(--dur-2) var(--ease);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn .icon { width: 1.1em; height: 1.1em; }

.btn-brand { --btn-bg: var(--brand); --btn-fg: #fff; box-shadow: var(--shadow-sm); }
.btn-accent { --btn-bg: var(--accent); --btn-fg: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-ghost { --btn-bd: var(--line-strong); --btn-fg: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-on-dark { --btn-bg: rgba(255,255,255,0.12); --btn-fg: #fff; --btn-bd: rgba(255,255,255,0.28); }
.btn-on-dark:hover { --btn-bg: rgba(255,255,255,0.2); }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 26px; font-size: var(--text-base); }

/* Progress spinner — shown while a button is busy (add class .is-loading). */
.btn .spinner {
  width: 1.05em;
  height: 1.05em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  display: none;
  animation: spin 0.7s linear infinite;
}
.btn.is-loading { pointer-events: none; }
.btn.is-loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   Nav / topbar
   ========================================================================= */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  height: var(--nav-h);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: var(--fw-heavy);
  font-size: 1.06rem;
  letter-spacing: var(--tracking-tight);
  color: inherit;
}
.brand .mark {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: var(--brand-soft);
  color: var(--brand-2);
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}
.brand .mark .icon { width: 20px; height: 20px; }
/* When the mark is the official logo image, it fills the tile edge-to-edge
   (the logo carries its own tile); the tile's rounded corners still apply. */
.brand img.mark { object-fit: cover; background: transparent; display: block; }
.nav-links { display: flex; align-items: center; gap: var(--sp-6); }
.nav-links a {
  color: var(--muted);
  font-weight: var(--fw-semibold);
  font-size: var(--text-sm);
  transition: color var(--dur-1) var(--ease);
}
.nav-links a:hover { color: var(--ink); }
.nav-cta { display: flex; align-items: center; gap: var(--sp-3); }
.icon-btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--dur-1) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .icon { width: 18px; height: 18px; }

.topbar-home {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--brand-2);
  font-weight: var(--fw-bold);
  font-size: var(--text-sm);
}
.topbar-home:hover { text-decoration: underline; }

@media (max-width: 900px) { .nav-links { display: none; } }
@media (max-width: 520px) {
  .nav-cta { gap: var(--sp-2); }
  .nav-cta .btn { padding: 10px 14px; }
}
@media (max-width: 380px) { .nav-login { display: none; } }

/* =========================================================================
   Cards & forms
   ========================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-6);
  box-shadow: var(--shadow-sm);
}
.card-lg { border-radius: var(--r-lg); box-shadow: var(--shadow-lg); }

label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  color: var(--muted);
  margin: var(--sp-4) 0 var(--sp-2);
}
input, select, textarea {
  width: 100%;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 13px 14px;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 22%, transparent);
}
.field-err { color: var(--danger); font-size: var(--text-xs); font-weight: var(--fw-semibold); margin-top: 5px; }
.msg {
  margin-top: var(--sp-4);
  padding: 12px 14px;
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  display: none;
}
.msg.err { display: block; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.msg.ok { display: block; background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }

/* =========================================================================
   Footer
   ========================================================================= */
footer.site-footer { border-top: 1px solid var(--line); padding: var(--sp-7) 0 var(--sp-8); color: var(--muted); }
.foot-grid { display: flex; justify-content: space-between; gap: var(--sp-6); flex-wrap: wrap; align-items: flex-start; }
.foot-links { display: flex; gap: var(--sp-7); flex-wrap: wrap; }
.foot-col { display: flex; flex-direction: column; gap: var(--sp-3); }
.foot-col b { color: var(--ink); font-size: var(--text-xs); letter-spacing: 0.06em; text-transform: uppercase; font-weight: var(--fw-bold); }
.foot-col a { color: var(--muted); font-size: var(--text-sm); transition: color var(--dur-1) var(--ease); }
.foot-col a:hover { color: var(--ink); }
.foot-bottom { margin-top: var(--sp-7); display: flex; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; font-size: var(--text-xs); color: var(--muted); }

/* Compact single-row footer (auth / legal pages). */
.footer-inner {
  max-width: var(--maxw-narrow);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-8);
  color: var(--muted);
  font-size: var(--text-sm);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  justify-content: space-between;
}
.footer-inner a { color: var(--muted); margin-right: var(--sp-4); transition: color var(--dur-1) var(--ease); }
.footer-inner a:hover { color: var(--ink); }

/* =========================================================================
   Motion utilities — reveal on scroll, intentional stagger
   ========================================================================= */
.js .reveal { opacity: 0; transform: translateY(20px); transition: opacity var(--dur-3) var(--ease), transform var(--dur-3) var(--ease); }
.js .reveal.in { opacity: 1; transform: none; }
/* Stagger children of a revealed group by declaration order. */
.stagger.in > * { animation: rise var(--dur-3) var(--ease) both; }
.stagger.in > *:nth-child(1) { animation-delay: 0ms; }
.stagger.in > *:nth-child(2) { animation-delay: 70ms; }
.stagger.in > *:nth-child(3) { animation-delay: 140ms; }
.stagger.in > *:nth-child(4) { animation-delay: 210ms; }
.stagger.in > *:nth-child(5) { animation-delay: 280ms; }
.stagger.in > *:nth-child(6) { animation-delay: 350ms; }
.stagger.in > *:nth-child(7) { animation-delay: 420ms; }
.stagger.in > *:nth-child(8) { animation-delay: 490ms; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* Skeleton loaders — for data-heavy sections while they fetch. */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--r-sm);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 55%, transparent), transparent);
  animation: shimmer 1.3s var(--ease-inout) infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

html { scroll-behavior: smooth; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
  .btn:hover { transform: none; }
}
