:root {
  color-scheme: light;

  /* Core palette */
  --bg: #f8f5ef;
  --card: #ffffff;
  --text: #17130f;
  --muted: #625b53;
  --line: #e6ded2;
  --accent: #17130f;
  --accent-text: #ffffff;
  --focus: #775a2d;
  --error: #9f1d1d;

  /* Surfaces */
  --surface: #fafaf7;
  --input-bg: #ffffff;

  /* Overlays & shadows */
  --body-glow: rgba(255, 255, 255, 0.82);
  --preview-bg: rgba(255, 255, 255, 0.65);
  --code-bg: rgba(0, 0, 0, 0.05);
  --backdrop-color: rgba(20, 16, 12, 0.45);
  --shadow-card: rgba(40, 30, 20, 0.12);
  --shadow-modal: rgba(20, 16, 12, 0.20);
  --shadow-sm: rgba(20, 16, 12, 0.08);

  /* Toast */
  --toast-bg: #17130f;
  --toast-text: #ffffff;

  /* Demo banner */
  --demo-bg: #fff7e6;
  --demo-border: #f4dfb1;
  --demo-text: #6b4b15;

  /* Badges */
  --badge-onetime-bg: #f1ece4;
  --badge-onetime-text: #5b5347;
  --badge-yes-bg: #def3e2;
  --badge-yes-text: #1d6b34;
  --badge-manual-bg: #fbeed1;
  --badge-manual-text: #6b4b15;

  /* Warning */
  --warning-bg: #fff7e6;
  --warning-border: #f4dfb1;
  --warning-text: #6b4b15;

  /* Copy success */
  --copy-ok-bg: #def3e2;
  --copy-ok-text: #1d6b34;
  --copy-ok-border: #b8e2c2;

  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ── Dark mode: system preference fallback (JS disabled / attribute absent) ── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #18130e;
    --card: #211c17;
    --text: #f0ebe3;
    --muted: #9e8878;
    --line: #352c22;
    --accent: #e8ddd0;
    --accent-text: #18130e;
    --focus: #d4a84b;
    --error: #f07070;
    --surface: #1c1812;
    --input-bg: #2a2318;
    --body-glow: rgba(80, 60, 35, 0.10);
    --preview-bg: rgba(0, 0, 0, 0.20);
    --code-bg: rgba(255, 255, 255, 0.08);
    --backdrop-color: rgba(0, 0, 0, 0.60);
    --shadow-card: rgba(0, 0, 0, 0.40);
    --shadow-modal: rgba(0, 0, 0, 0.50);
    --shadow-sm: rgba(0, 0, 0, 0.25);
    --toast-bg: #f0ebe3;
    --toast-text: #18130e;
    --demo-bg: #261a06;
    --demo-border: #4a3312;
    --demo-text: #c9933b;
    --badge-onetime-bg: #2a2318;
    --badge-onetime-text: #9a8878;
    --badge-yes-bg: #0d2416;
    --badge-yes-text: #4aab64;
    --badge-manual-bg: #261a06;
    --badge-manual-text: #c9933b;
    --warning-bg: #261a06;
    --warning-border: #4a3312;
    --warning-text: #c9933b;
    --copy-ok-bg: #0d2416;
    --copy-ok-text: #4aab64;
    --copy-ok-border: #1a4a2e;
  }
}

/* ── Dark mode: explicit user override ──────────────────────────────────── */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #18130e;
  --card: #211c17;
  --text: #f0ebe3;
  --muted: #9e8878;
  --line: #352c22;
  --accent: #e8ddd0;
  --accent-text: #18130e;
  --focus: #d4a84b;
  --error: #f07070;
  --surface: #1c1812;
  --input-bg: #2a2318;
  --body-glow: rgba(80, 60, 35, 0.10);
  --preview-bg: rgba(0, 0, 0, 0.20);
  --code-bg: rgba(255, 255, 255, 0.08);
  --backdrop-color: rgba(0, 0, 0, 0.60);
  --shadow-card: rgba(0, 0, 0, 0.40);
  --shadow-modal: rgba(0, 0, 0, 0.50);
  --shadow-sm: rgba(0, 0, 0, 0.25);
  --toast-bg: #f0ebe3;
  --toast-text: #18130e;
  --demo-bg: #261a06;
  --demo-border: #4a3312;
  --demo-text: #c9933b;
  --badge-onetime-bg: #2a2318;
  --badge-onetime-text: #9a8878;
  --badge-yes-bg: #0d2416;
  --badge-yes-text: #4aab64;
  --badge-manual-bg: #261a06;
  --badge-manual-text: #c9933b;
  --warning-bg: #261a06;
  --warning-border: #4a3312;
  --warning-text: #c9933b;
  --copy-ok-bg: #0d2416;
  --copy-ok-text: #4aab64;
  --copy-ok-border: #1a4a2e;
}

* {
  box-sizing: border-box;
}

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(circle at top, var(--body-glow), transparent 32rem),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

img {
  -webkit-touch-callout: none;
  user-select: none;
}

a {
  color: var(--accent);
}

.page-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
}

.donation-card {
  width: min(100%, 42rem);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 2rem;
  box-shadow: 0 1.5rem 5rem var(--shadow-card);
  padding: clamp(1.25rem, 4vw, 2.5rem);
}

.site-header {
  text-align: center;
  margin-bottom: 2rem;
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 8vw, 4.25rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

.lede {
  max-width: 29rem;
  margin: 1rem auto 0;
  color: var(--muted);
  font-size: clamp(0.85rem, 0.5rem + 1.5vw, 1rem);
  line-height: 1.55;
}

.lede-break {
  display: none;
}

@media (max-width: 549.98px) {
  .lede-break {
    display: inline;
  }
}

.donation-form {
  display: grid;
  gap: 1.25rem;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

legend {
  margin-bottom: 0.6rem;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.segmented legend,
.amounts legend {
  grid-column: 1 / -1;
}

.segmented label,
.amount-button {
  position: relative;
  min-height: 3.25rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.segmented input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked),
.amount-button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.segmented label:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

@media (hover: hover) {
  .segmented label:hover,
  .amount-button:hover {
    transform: translateY(-1px);
  }
}

.amount-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.amount-button {
  width: 100%;
  font-weight: 600;
}

.custom-amount {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.8rem;
  color: var(--muted);
  font-weight: 700;
}

.input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.95rem 1rem;
  background: var(--input-bg);
}

.input-wrap:focus-within {
  border-color: var(--focus);
}

.currency-symbol {
  color: var(--muted);
}

#custom-amount {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.hint {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

.primary-button {
  min-height: 3.5rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  cursor: pointer;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.primary-button.is-loading {
  cursor: progress;
  opacity: 0.85;
}

.error {
  margin: 0;
  color: var(--error);
  font-weight: 700;
}

.status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.status:not(:empty) {
  margin: 1.8rem 0;
}

.checkout {
  margin-top: 1rem;
}

/* Breathing room when programmatically scrolling to Secure Payment */
.checkout-section-title,
.checkout {
  scroll-margin-top: 1rem;
}

@keyframes checkout-reveal {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: checkout-reveal 220ms ease both;
}

.preview-placeholder {
  margin-top: 1rem;
  padding: 1.5rem 1.25rem;
  border: 1px dashed var(--line);
  border-radius: 1.25rem;
  background: var(--preview-bg);
  display: grid;
  gap: 0.85rem;
}

.preview-placeholder h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.01em;
  text-align: center;
}

.preview-placeholder .preview-amount {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
}

.preview-placeholder .preview-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.preview-methods {
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.preview-methods li::before {
  content: "•";
  margin-right: 0.5rem;
  color: var(--accent);
}

.preview-disclaimer {
  margin: 0;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.checkout-section-title {
  margin: 0.5rem 0 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.checkout-section-title::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

.stripe-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

.demo-banner {
  margin: 0 0 1.25rem;
  padding: 0.7rem 0.9rem;
  border-radius: 0.85rem;
  background: var(--demo-bg);
  border: 1px solid var(--demo-border);
  color: var(--demo-text);
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: left;
}

.demo-banner strong {
  font-weight: 800;
}

.demo-banner code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  background: var(--code-bg);
  padding: 0.05rem 0.3rem;
  border-radius: 0.35rem;
}

.external-rails {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.external-rails h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.rail-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

@media (min-width: 460px) {
  .rail-list {
    grid-template-columns: repeat(4, 1fr);
  }
}

.rail-list > li {
  display: flex;
}

.rail {
  display: grid;
  grid-template-rows: auto auto;
  gap: 0.45rem;
  width: 100%;
  padding: 0.55rem 0.55rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 0.95rem;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: center;
  transition: border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.rail:focus-visible {
  border-color: var(--rail-bg, var(--accent));
  transform: translateY(-1px);
  box-shadow: 0 0.45rem 1.1rem var(--shadow-sm);
}

@media (hover: hover) {
  .rail:hover {
    border-color: var(--rail-bg, var(--accent));
    transform: translateY(-1px);
    box-shadow: 0 0.45rem 1.1rem var(--shadow-sm);
  }
}

/* Square avatar frame. Each provider asset is a 500x500 pre-rendered app-icon
   tile, so the chip itself is just an invisible square slot. A small drop
   shadow lifts each icon off the card surface like a home-screen app. */
.rail-chip {
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 3rem;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  background: transparent;
  overflow: visible;
  transition: transform 150ms ease;
}

.rail:focus-visible .rail-chip {
  transform: scale(1.04);
}

@media (hover: hover) {
  .rail:hover .rail-chip {
    transform: scale(1.04);
  }
}

.rail-chip img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 10px;
}

.rail-name {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 0.2rem;
}

/* Monthly badges still used inside the modal. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.badge.one-time {
  background: var(--badge-onetime-bg);
  color: var(--badge-onetime-text);
}

.badge.monthly-yes {
  background: var(--badge-yes-bg);
  color: var(--badge-yes-text);
}

.badge.monthly-manual {
  background: var(--badge-manual-bg);
  color: var(--badge-manual-text);
}

/* ----- Modal ----- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow-y: auto;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop-color);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  width: min(100%, 28rem);
  max-height: calc(100svh - 2rem);
  overflow-y: auto;
  background: var(--card);
  border-radius: 1.25rem;
  border: 1px solid var(--line);
  box-shadow: 0 1.5rem 3rem var(--shadow-modal);
  padding: 1.5rem;
  display: grid;
  gap: 0.85rem;
  align-content: start;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.modal-logo {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  object-fit: contain;
  flex: 0 0 auto;
}

.modal-panel h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 0;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

@media (hover: hover) {
  .modal-close:hover {
    color: var(--text);
  }
}

.modal-rows {
  display: grid;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
}

.modal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  background: var(--surface);
}

.modal-row-label {
  grid-column: 1 / -1;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.modal-row-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.modal-row-value.is-wrap {
  font-family: inherit;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  font-weight: 600;
}

.modal-copy-btn {
  border: 1px solid var(--line);
  background: var(--input-bg);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.modal-copy-btn.is-copied {
  background: var(--copy-ok-bg);
  color: var(--copy-ok-text);
  border-color: var(--copy-ok-border);
}

.modal-link-btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 0.85rem 1.1rem;
  font-weight: 800;
  font-size: 0.95rem;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}

.modal-link-btn[hidden] {
  display: none;
}

.modal-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.modal-fineprint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.modal-monthly-warning {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 0.7rem;
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 0.85rem;
  line-height: 1.45;
}

.modal-qr {
  display: block;
  margin: 0 auto;
  width: 12rem;
  max-width: 100%;
  height: auto;
  border-radius: 0.85rem;
  border: 1px solid var(--line);
  background: #fff; /* QR codes require white background to scan */
  padding: 0.5rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 60;
  padding: 0.65rem 1rem;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 0.8rem 2rem var(--shadow-modal);
}

.toast[hidden] {
  display: none;
}

.site-footer {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: center;
}

.site-footer p {
  margin: 0.25rem 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* ----- Theme toggle ----- */
.theme-toggle {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 45;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 0.25rem 0.75rem var(--shadow-sm);
  transition: color 150ms ease, border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

@media (hover: hover) {
  .theme-toggle:hover {
    color: var(--text);
    border-color: var(--muted);
    transform: scale(1.08);
    box-shadow: 0 0.35rem 1rem var(--shadow-card);
  }
}

.theme-toggle svg {
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}

@media (max-width: 540px) {
  .donation-card {
    border-radius: 1.35rem;
  }

  .amount-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

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