/* ===== Tokens ===== */
:root {
  --ink: #2A1D2C;            /* outline ink — same as the 3D inverted-hull lines */
  --ink-2: #4A3A48;          /* secondary text (≈ 10.1:1 on paper) */
  --muted: #5E4C5B;          /* hint text (≈ 7.5:1 on paper) */
  --paper: #FFF9EE;
  --paper-2: #FFF0D6;
  --line: #E9D9BE;
  --accent: #FFC23D;         /* the ONE accent: donate + active states */
  --accent-press: #F2AE14;
  --sky-1: #86CFEA; --sky-2: #BEE6F3; --sky-3: #E3F4F7;
  --focus: #1546B8;
  --r-lg: 30px; --r-md: 20px; --r-sm: 14px;
  --edge: 0 6px 0 var(--ink);
  --edge-sm: 0 4px 0 var(--ink);
  --font-display: "Beiruti", "Readex Pro", "Noto Kufi Arabic", "Geeza Pro", sans-serif;
  --font-ui: "Readex Pro", "IBM Plex Sans Arabic", "Geeza Pro", system-ui, sans-serif;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 40px;
  --dur-ui: 160ms; --ease-toy: cubic-bezier(.34, 1.56, .64, 1);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 55%, var(--sky-3) 100%);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; inset-inline-start: var(--s4); top: -60px; z-index: 10; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--r-sm); padding: var(--s2) var(--s4); font-weight: 600; }
.skip:focus { top: var(--s3); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* ===== Top bar ===== */
.topbar {
  height: 76px; display: flex; align-items: center; justify-content: space-between;
  padding-inline: var(--s7); gap: var(--s4);
}
.brand { display: flex; align-items: center; gap: var(--s3); }
.brand-mark { width: 42px; height: 42px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text b { font-family: var(--font-display); font-weight: 800; font-size: 22px; }
.brand-text small { font-size: 13px; color: var(--ink-2); }
.toggle {
  display: inline-flex; align-items: center; gap: var(--s3);
  min-height: 46px; padding: 0 var(--s4) 0 var(--s4);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: var(--edge-sm); cursor: pointer; font-weight: 600; font-size: 15px;
  transition: transform var(--dur-ui) ease, box-shadow var(--dur-ui) ease;
}
.toggle:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.toggle-track { width: 40px; height: 24px; border-radius: 999px; background: #D9CCD6; border: 2.5px solid var(--ink); position: relative; flex: none; transition: background var(--dur-ui); }
.toggle-thumb { position: absolute; top: 2px; inset-inline-start: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; border: 2.5px solid var(--ink); transition: inset-inline-start var(--dur-ui) var(--ease-toy); }
.toggle[aria-pressed="true"] .toggle-track { background: var(--accent); }
.toggle[aria-pressed="true"] .toggle-thumb { inset-inline-start: 18px; }

/* ===== Layout ===== */
.layout {
  display: grid; grid-template-columns: minmax(380px, 456px) 1fr; gap: var(--s5);
  padding: 0 var(--s7) var(--s6); height: calc(100vh - 76px); min-height: 600px;
}
.stage { position: relative; min-height: 0; }
.stage-inner {
  position: absolute; inset: 0 0 8px 0; overflow: hidden;
  border: 3px solid var(--ink); border-radius: var(--r-lg); box-shadow: 0 8px 0 var(--ink);
  background: radial-gradient(120% 90% at 50% 20%, #B7E6F5 0%, #93D3EA 55%, #7FC7E2 100%);
}
#scene-canvas, .fallback, #scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: contain; }
#scene-canvas { touch-action: pan-y; }

/* ===== Panel ===== */
.panel {
  align-self: center;
  background: var(--paper); border: 3px solid var(--ink); border-radius: var(--r-lg);
  box-shadow: 0 8px 0 var(--ink);
  padding: var(--s5) var(--s6) var(--s5);
  display: flex; flex-direction: column; gap: var(--s4);
  max-height: calc(100% - 12px); overflow: auto;
}
.eyebrow { margin: 0; font-size: 14px; font-weight: 600; color: var(--ink-2); display: inline-flex; align-items: center; gap: var(--s2); }
.eyebrow::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--ink); }
h1 { margin: var(--s1) 0 var(--s1); font-family: var(--font-display); font-weight: 900; font-size: 38px; line-height: 1.15; letter-spacing: 0; text-wrap: balance; }
.lede { text-wrap: pretty; margin: 0; font-size: 15.5px; color: var(--ink-2); line-height: 1.7; }

.amount-label { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: var(--s2); }
.stepper { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; gap: var(--s3); }
.step-btn {
  width: 64px; height: 64px; border-radius: var(--r-md);
  background: #fff; border: 3px solid var(--ink); box-shadow: var(--edge-sm);
  display: grid; place-items: center; cursor: pointer;
  transition: transform 90ms ease, box-shadow 90ms ease, background var(--dur-ui);
}
.step-btn svg { width: 26px; height: 26px; }
.step-btn:hover { background: var(--paper-2); }
.step-btn:active, .step-btn.is-pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.step-btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.amount-field {
  height: 104px; border-radius: var(--r-md); border: 3px solid var(--ink); background: #fff;
  display: flex; align-items: center; justify-content: center; gap: var(--s2); padding-inline: var(--s3);
  box-shadow: inset 0 -5px 0 #F3E6CF;
  cursor: text;
}
.amount-field:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
#amount {
  font-family: var(--font-display); font-weight: 900; font-size: 84px; line-height: 1;
  width: 3.1ch; min-width: 0; text-align: center; border: 0; background: transparent; color: var(--ink);
  font-variant-numeric: tabular-nums; padding: 0; caret-color: var(--focus);
  direction: ltr;
}
#amount:focus { outline: none; }
.amount-unit { font-family: var(--font-display); font-weight: 800; font-size: 26px; color: var(--ink-2); white-space: nowrap; }

.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s2); margin-top: var(--s3); }
.chip {
  height: 52px; border-radius: var(--r-sm); border: 3px solid var(--ink); background: #fff;
  box-shadow: 0 3px 0 var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-display); font-weight: 800; font-size: 22px;
  transition: transform 90ms ease, box-shadow 90ms ease, background var(--dur-ui);
}
.chip svg { width: 26px; height: 26px; flex: none; }
.chip:hover { background: var(--paper-2); }
@media (hover: none) { .step-btn:hover, .chip:hover { background: #fff; } }
.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent); }

.impact { border-top: 2px dashed var(--line); padding-top: var(--s4); }
.impact-line { text-wrap: balance; margin: 0 0 var(--s3); font-weight: 600; font-size: 17px; line-height: 1.55; min-height: 2lh; }
.next-hint { min-height: 1.6em; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, auto); justify-content: start; column-gap: var(--s4); row-gap: 6px; min-height: 62px; align-content: start; }
.checklist li { display: inline-flex; align-items: center; gap: 6px; height: 28px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.checklist .tick { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #857080; flex: none; display: grid; place-items: center; background: #fff; }
.checklist li.on { color: var(--ink); font-weight: 600; }
.checklist li.on .tick { border-color: var(--ink); background: var(--accent); }
.checklist li.on .tick::after { content: ""; width: 8px; height: 4px; border-inline-start: 2.4px solid var(--ink); border-bottom: 2.4px solid var(--ink); transform: translateY(-1px) rotate(-45deg) scaleX(-1); }
.next-hint { margin: var(--s3) 0 0; font-size: 14px; color: var(--muted); }

.cta { display: flex; flex-direction: column; gap: var(--s2); }
.fund-line { margin: 0; font-size: 14px; line-height: 1.6; color: var(--ink-2); text-wrap: pretty; }
.fund-line b { font-weight: 600; color: var(--ink); }
.stage-tools { position: absolute; bottom: calc(var(--s3) + 8px); inset-inline-end: var(--s3); display: flex; align-items: center; gap: var(--s2); z-index: 2; }
.stage-tools .toggle { min-height: 44px; font-size: 14px; padding-inline: var(--s3); }
.motion-note { font-size: 12.5px; background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 2px 10px; color: var(--ink-2); }
.donate {
  width: 100%; min-height: 64px; border-radius: var(--r-md); border: 3px solid var(--ink);
  background: var(--accent); box-shadow: var(--edge); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s3);
  font-family: var(--font-display); font-weight: 900; font-size: 26px; line-height: 1;
  transition: transform 90ms ease, box-shadow 90ms ease, background var(--dur-ui);
}
.donate svg { width: 24px; height: 24px; }
.donate:hover { background: #FFCD57; }
.donate:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); background: var(--accent-press); }
.donate[aria-disabled="true"] { background: #F3E9D8; cursor: not-allowed; color: var(--ink-2); }
.donate.small { min-height: 54px; font-size: 22px; width: auto; padding-inline: var(--s6); }
.fineprint { margin: 0; text-align: center; font-size: 13px; line-height: 1.5; color: var(--muted); text-wrap: balance; }

/* ===== Confirmation: anchored over the panel (never over Salma) ===== */
.thanks { border: 0; padding: 0 0 12px; margin: 0; background: transparent; overflow: visible; position: fixed; max-width: none; max-height: none; }
.thanks::backdrop { background: rgba(42, 29, 44, 0.08); }
.thanks-card {
  background: var(--paper); border: 3px solid var(--ink); border-radius: var(--r-lg); box-shadow: 0 8px 0 var(--ink);
  padding: var(--s5); display: flex; flex-direction: column; gap: var(--s3); max-height: calc(100vh - 40px); overflow: auto;
}
.thanks-head { display: flex; align-items: center; gap: var(--s3); }
.thanks-mark { width: 52px; height: 52px; flex: none; }
.thanks h2 { margin: 0; font-family: var(--font-display); font-weight: 900; font-size: 30px; line-height: 1.15; }
.thanks-amount { margin: 2px 0 0; font-size: 16px; color: var(--ink-2); }
.thanks-amount b { font-family: var(--font-display); font-weight: 900; font-size: 22px; color: var(--ink); }
.summary { border: 2px solid var(--ink); border-radius: var(--r-md); background: #fff; padding: var(--s3) var(--s4); }
.summary-title { margin: 0 0 var(--s2); font-size: 14px; font-weight: 600; color: var(--ink-2); }
.summary-items { list-style: none; margin: 0 0 var(--s2); padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.summary-items li { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding-inline: 6px 12px; border-radius: 999px; background: #FFF6DE; border: 2px solid var(--ink); font-size: 14px; font-weight: 600; }
.summary-items svg { width: 22px; height: 22px; }
.summary-text { margin: 0; font-size: 15px; line-height: 1.6; color: var(--ink); }
.next-steps { margin: 0; padding-inline-start: 1.2em; font-size: 15px; line-height: 1.7; color: var(--ink-2); }
.thanks .thanks-note { margin: 0; font-size: 13px; color: var(--muted); }
.thanks .donate.small { align-self: flex-start; }
.thanks[open] .thanks-card { animation: pop 260ms var(--ease-toy); }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

/* typed-value hint (never silently correct) */
.stepper { position: relative; }
.amount-hint {
  position: absolute; inset-inline: 0; top: calc(100% + 6px); margin: 0 auto; width: max-content; max-width: 100%; z-index: 3;
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 500; line-height: 1.4; padding: 6px 12px; border-radius: 10px;
}
.amount-block { position: relative; }
/* honesty line sits right after the impact sentence */
.impact .fund-line { margin: 0 0 var(--s3); font-size: 14px; color: var(--ink-2); }
.impact .fund-line b { color: var(--ink); font-weight: 600; }
/* reduced-motion crossfade overlay + changed-row highlight */
.xfade { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; z-index: 1; }
.checklist li.flash { animation: flash 1.2s ease-out; border-radius: 8px; }
html.reduced .checklist li.flash { animation-duration: 1.2s !important; }
@keyframes flash { 0%, 40% { background: #FFE7A3; box-shadow: 0 0 0 4px #FFE7A3; } 100% { background: transparent; box-shadow: 0 0 0 4px transparent; } }

.noscript { padding: var(--s5); background: var(--paper); }

/* ===== Short desktop screens (1366×768, 1024×768) ===== */
@media (min-width: 901px) and (max-height: 840px) {
  .eyebrow { display: none; }
  .impact-line { min-height: 2lh; }
  .checklist { min-height: 56px; }
  .checklist li { height: 25px; font-size: 13px; }
  .lede { font-size: 14px; }
  .fineprint { font-size: 12px; }
  .topbar { height: 64px; }
  .layout { height: calc(100vh - 64px); padding-bottom: var(--s5); }
  .panel { padding: var(--s4) var(--s5); gap: var(--s3); }
  h1 { font-size: 31px; }
  .lede { font-size: 14.5px; line-height: 1.6; }
  .amount-field { height: 84px; }
  #amount { font-size: 66px; }
  .step-btn { width: 56px; height: 56px; }
  .stepper { grid-template-columns: 56px 1fr 56px; }
  .chips { margin-top: var(--s2); }
  .chip { height: 46px; }
  .impact { padding-top: var(--s3); }
  .impact-line { font-size: 16px; margin-bottom: var(--s2); }
  .next-hint { margin-top: var(--s2); }
  .donate { min-height: 58px; font-size: 24px; }
}
@media (min-width: 901px) and (max-width: 1180px) {
  .layout { grid-template-columns: minmax(360px, 400px) 1fr; padding-inline: var(--s5); gap: var(--s4); }
  .topbar { padding-inline: var(--s5); }
  .panel { padding-inline: var(--s5); }
}

/* ===== Tablet (768 portrait) ===== */
@media (max-width: 900px) {
  .topbar { height: 68px; padding-inline: var(--s5); }
  .layout {
    grid-template-columns: 1fr; grid-template-rows: minmax(300px, 1fr) auto;
    height: calc(100vh - 68px); min-height: 860px; padding: 0 var(--s5) var(--s5); gap: var(--s3);
  }
  .stage { order: -1; }
  .panel {
    align-self: end; padding: var(--s5);
    display: grid; grid-template-columns: 1fr 1fr; column-gap: var(--s5); row-gap: var(--s4);
    grid-template-areas: "head head" "amount impact" "cta cta"; row-gap: var(--s3);
  }
  .panel-head { grid-area: head; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--s4); }
  .panel-head .eyebrow { display: none; }
  .lede { margin-top: var(--s1); }
  h1 { font-size: 30px; margin: 0; }
  h1 br { display: none; }
  .lede { font-size: 14.5px; }
  .amount-block { grid-area: amount; }
  .impact { grid-area: impact; border-top: 0; padding-top: 0; border-inline-start: 2px dashed var(--line); padding-inline-start: var(--s5); }
  .cta { grid-area: cta; }
  .amount-field { height: 86px; }
  #amount { font-size: 68px; }
  .stepper { grid-template-columns: 58px 1fr 58px; gap: var(--s2); }
  .step-btn { width: 58px; height: 58px; }
  .chip { height: 48px; font-size: 20px; gap: 4px; }
  .chip svg { width: 22px; height: 22px; }
  .impact-line { font-size: 16px; min-height: 50px; }
  .next-hint { min-height: 2lh; line-height: 1.5; }
  .checklist { grid-template-columns: repeat(2, auto); min-height: 92px; }
  .checklist li { height: 26px; font-size: 13.5px; }
}
/* ===== Phone (360–430 portrait): hero stage on top, controls below, sticky donate bar ===== */
@media (max-width: 560px) {
  .topbar { height: 56px; padding-inline: var(--s4); }
  .brand-mark { width: 36px; height: 36px; }
  .brand-text b { font-size: 18px; }
  .brand-text small { display: none; }
  .layout {
    display: flex; flex-direction: column; gap: 0; height: auto; min-height: 0;
    padding: 0 var(--s4) calc(112px + env(safe-area-inset-bottom));
  }
  .stage { order: -1; flex: none; height: max(330px, min(52vh, 520px)); margin-bottom: var(--s3); }
  .stage-tools .toggle { min-height: 44px; }
  .panel {
    display: flex; flex-direction: column; gap: var(--s3);
    padding: var(--s4) var(--s4) var(--s5); max-height: none; overflow: visible;
  }
  .panel-head { display: contents; }
  .panel-head h1 { order: 0; margin: 0; }
  .amount-block { order: 1; }
  .panel-head .lede { order: 2; }
  .impact { order: 3; }
  .panel-head .eyebrow { display: none; }
  h1 { font-size: 26px; }
  .lede, .fund-line, .impact .fund-line, .impact-line, .checklist li, .next-hint { font-size: 16px; }
  .impact { border-inline-start: 0; padding-inline-start: 0; border-top: 2px dashed var(--line); padding-top: var(--s4); }
  .checklist { grid-template-columns: repeat(2, auto); column-gap: var(--s5); row-gap: 8px; min-height: 0; }
  .checklist li { height: 28px; }
  .stepper { grid-template-columns: 60px 1fr 60px; gap: var(--s2); }
  .step-btn { width: 60px; height: 60px; }
  .amount-field { height: 76px; }
  #amount { font-size: 60px; }
  .amount-unit { font-size: 22px; }
  .amount-label { margin-bottom: var(--s1); }
  .chips { gap: 6px; }
  .chip { height: 52px; font-size: 20px; gap: 4px; padding: 0; }
  .chip svg { width: 22px; height: 22px; }
  /* sticky donate bar, always in the thumb zone */
  .cta {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 5;
    padding: 10px var(--s4) calc(8px + env(safe-area-inset-bottom));
    background: var(--paper); border-top: 3px solid var(--ink);
    box-shadow: 0 -6px 18px rgba(42, 29, 44, 0.12);
  }
  .donate { min-height: 52px; font-size: 22px; }
  /* hint would sit under the fixed donate bar; show it above the stepper instead */
  .amount-hint { top: -6px; }
  .cta { gap: 4px; }
  .fineprint { font-size: 12.5px; line-height: 1.3; }
  .thanks-card { padding: var(--s4); gap: var(--s2); border-radius: 24px 24px 0 0; }
  .thanks { padding-bottom: 0; }
  .thanks-mark { width: 40px; height: 40px; }
  .thanks h2 { font-size: 24px; }
  .summary { padding: var(--s2) var(--s3); }
  .summary-items li { height: 30px; font-size: 14px; }
  .summary-text, .next-steps { font-size: 14.5px; line-height: 1.55; }
  .thanks .donate.small { align-self: stretch; min-height: 48px; }
}

@media (max-width: 560px) and (max-height: 820px) {
  .stage { height: max(330px, 50vh); }
  .amount-field { height: 66px; }
  #amount { font-size: 52px; }
  .step-btn { width: 56px; height: 56px; }
  .stepper { grid-template-columns: 56px 1fr 56px; }
}
/* ===== Reduced motion (OS or toggle) ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
html.reduced *, html.reduced *::before, html.reduced *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }

/* capture/export helpers */
html.capture .skip { display: none; }
