/* «كتاب منبثق» — tokens first. One accent (marigold) reserved for the donate action + the active state. */
:root {
  --desk: #3B4634;          /* warm felt-green desk (lifted from the first round's #2B3529) */
  --desk-2: #435040;
  --desk-line: #56644C;
  --cream: #F4EDDF;         /* paper */
  --cream-2: #E7DDC8;
  --ink: #1F2620;
  --text: #F4EDDF;          /* on desk: 13.1:1 */
  --text-2: #DCD5C3;        /* on desk: 8.0:1 */
  --text-3: #C4BDA8;        /* on desk: 5.3:1 */
  --accent: #EDB44A;        /* marigold — on desk 8.9:1, ink on accent 9.4:1 */
  --accent-ink: #231A08;
  --focus: #FFE3A3;
  --line: rgba(244, 237, 223, .52);   /* control borders: ≥3:1 non-text */

  --font-display: 'Beiruti', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-ui: 'IBM Plex Sans Arabic', system-ui, sans-serif;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px;
  --panel-w: 480px;

  /* motion tokens (mirrored in motion-spec.json; springs live in app.js SP) */
  --t-fast: 140ms; --t-ui: 220ms; --ease-out: cubic-bezier(.2, .8, .2, 1); --blink: 150ms;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--desk);
  /* desk felt: an inline SVG noise tile, very faint */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .9 0 0 0 0 .85 0 0 0 0 .7 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; inset-inline-start: var(--s4); top: -60px; z-index: 10; background: var(--cream); color: var(--ink); padding: var(--s2) var(--s4); border-radius: var(--r-sm); }
.skip:focus { top: var(--s4); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* ---------------------------------------------------------------- layout */
.layout {
  min-height: 100vh; min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr);   /* RTL: column 1 is on the right */
}
/* panel */
.panel {
  padding: clamp(24px, 5vh, 56px) clamp(32px, 4vw, 56px);
  display: flex; flex-direction: column; justify-content: center; gap: clamp(14px, 2.4vh, 22px);
  position: relative; z-index: 2;
  background: transparent;
}
.scene {
  position: relative; min-width: 0; overflow: hidden;
  background:
    radial-gradient(60% 55% at 34% 30%, rgba(255, 226, 172, .22), rgba(255, 226, 172, 0) 70%),
    radial-gradient(90% 80% at 50% 62%, rgba(84, 98, 72, .85) 0%, rgba(59, 70, 52, 0) 75%);
}
.stage-fit { position: absolute; inset: 8px 0 56px 0; }
.stage {
  position: absolute; left: 0; top: 0; width: 1000px; height: 720px;
  transform-origin: 0 0; direction: ltr;
  perspective: 1500px; perspective-origin: 500px 40px;
}
.layer2d { position: absolute; left: 0; top: 0; width: 1000px; height: 720px; overflow: visible; pointer-events: none; }
#leaf-rest-a, #leaf-rest-b, #ground { transition: none; }

/* paper pieces */
.piece, .cast { position: absolute; pointer-events: none; will-change: transform; }
/* every paper part is its own composited layer: moving parts never repaint the filtered paper art */
.part { position: absolute; inset: 0; will-change: transform; }
.art { display: block; width: 100%; height: 100%; overflow: visible; }
.wipe { position: absolute; left: 0; top: 0; width: 3000px; height: 3000px; overflow: hidden; transform-origin: 0 0; will-change: transform; }
.wipe-in { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.part-eyelids { transform: scaleY(0); }
.part-eyelids.blink { animation: blink var(--blink) ease-in-out 1; }
#leaf, .seg, .corner { will-change: transform; }
.cast svg { display: block; width: 100%; height: 100%; overflow: visible; }

@keyframes blink { 0%, 100% { transform: scaleY(0); } 45%, 55% { transform: scaleY(1); } }

/* the page plane: the 3D sheet that the turning leaf + breeze corner live in (matches the drawn book) */
#pageplane { position: absolute; left: 0; width: 1000px; transform-origin: 50% 100%; transform-style: preserve-3d; pointer-events: none; }
#leaf { position: absolute; top: 0; transform-origin: 100% 50%; transform-style: preserve-3d; visibility: hidden; }
.seg { position: absolute; top: 0; height: 100%; width: 50%; transform-style: preserve-3d; }
#seg-in { right: 0; }
#seg-out { right: 50%; transform-origin: 100% 50%; }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face svg { display: block; width: 100%; height: 100%; }
.face.back { transform: rotateY(180deg); }
.seg .shade { position: absolute; inset: 0; background: linear-gradient(to left, rgba(60, 40, 20, .5), rgba(60, 40, 20, .2)); opacity: 0; transform: translateZ(.6px); pointer-events: none; }
.turn-shadow { position: absolute; top: 0; height: 100%; width: 420px; opacity: 0; }
#turn-shadow-l { left: 80px; background: linear-gradient(to left, rgba(40, 26, 12, .55), rgba(40, 26, 12, 0) 70%); }
#turn-shadow-r { left: 500px; background: linear-gradient(to right, rgba(40, 26, 12, .55), rgba(40, 26, 12, 0) 70%); }

/* breeze: outer-near corner of the left page lifts on its diagonal */
.corner { position: absolute; left: 80px; bottom: 0; width: 64px; height: 64px; transform-style: preserve-3d; opacity: 0; }
.corner .under { position: absolute; inset: 0; clip-path: polygon(0 0, 0 100%, 100% 100%); background: linear-gradient(45deg, rgba(120, 96, 60, .35), rgba(120, 96, 60, 0)); }
.corner .flap { position: absolute; inset: 0; clip-path: polygon(0 0, 0 100%, 100% 100%); background: linear-gradient(45deg, #EFE6D3, #F7F0E2 60%); transform-origin: 50% 50%; }
.corner.lift { animation: corner-show 1.9s ease-in-out 1; }
.corner.lift .flap { animation: corner-lift 1.9s cubic-bezier(.4, 0, .3, 1) 1; }
@keyframes corner-show { 0%, 100% { opacity: 0; } 8%, 92% { opacity: 1; } }
@keyframes corner-lift { 0%, 100% { transform: rotate3d(1, -1, 0, 0deg); } 40% { transform: rotate3d(1, -1, 0, 38deg); } 62% { transform: rotate3d(1, -1, 0, 30deg); } }

#pull-tab { position: absolute; width: 34px; height: 23px; transition: opacity var(--t-ui); }
#pull-tab svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* scene description */
.desc-btn {
  position: absolute; inset-inline-end: var(--s5); top: var(--s5); z-index: 3;
  font: 500 14px/1 var(--font-ui); color: var(--text-2); background: rgba(43, 53, 41, .82);
  border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; min-height: 44px; cursor: pointer;
}
.desc-btn:hover { color: var(--text); border-color: var(--text-2); }
.scene-desc {
  position: absolute; inset-inline-end: var(--s5); top: 76px; z-index: 3; max-width: 420px; margin: 0;
  background: var(--cream); color: var(--ink); padding: var(--s4) var(--s5); border-radius: var(--r-md);
  font-size: 15px; line-height: 1.75; box-shadow: 0 1px 0 #C9BEA6, 0 14px 30px rgba(0, 0, 0, .3);
}

/* ---------------------------------------------------------------- panel type */
.eyebrow { margin: 0; display: flex; align-items: center; gap: var(--s2); font-size: 14px; font-weight: 500; color: var(--text-2); }
.eyebrow .mark { width: 18px; height: 14px; background: var(--accent); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 72%, 0 100%); }
h1 { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: clamp(34px, 3.3vw, 48px); line-height: 1.15; color: var(--text); }
.lede { margin: 0; color: var(--text-2); font-size: 16.5px; line-height: 1.75; max-width: 40ch; }

.amount-block { display: grid; gap: var(--s3); }
.lbl { font-size: 14px; font-weight: 600; color: var(--text-2); }
.stepper { display: grid; grid-template-columns: 56px minmax(0, 1fr) 56px; align-items: center; gap: var(--s3); }
.step {
  width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--line); background: transparent; color: var(--text);
  display: grid; place-items: center; cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.step svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.step:hover:not([aria-disabled="true"]) { background: rgba(244, 237, 223, .08); border-color: var(--text-2); }
.step:active:not([aria-disabled="true"]) { transform: scale(.94); }
.step[aria-disabled="true"] { opacity: .45; cursor: default; }
.field {
  position: relative; height: 92px; border-radius: var(--r-md);
  background: var(--cream); color: var(--ink);
  display: flex; align-items: center; justify-content: center; gap: var(--s3);
  box-shadow: 0 1.5px 0 #C9BEA6, 0 3px 0 rgba(0, 0, 0, .18), 0 14px 28px rgba(0, 0, 0, .28);
}
.field:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.field input {
  width: 3.1ch; min-width: 0; border: 0; background: transparent; color: var(--ink); padding: 0;
  font-family: var(--font-display); font-weight: 800; font-size: 64px; line-height: 1; text-align: center;
  font-variant-numeric: tabular-nums; outline: none;
}
.field input::selection { background: #F3CF84; }
.unit { font-family: var(--font-display); font-weight: 700; font-size: 22px; color: #4A4A3C; min-width: 4.2em; }

.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2); }
.chip {
  display: grid; justify-items: center; gap: 0; padding: 8px 4px 9px; cursor: pointer;
  border-radius: var(--r-sm); border: 1.5px solid var(--line); background: transparent; color: var(--text);
  font: inherit; transition: background var(--t-fast), border-color var(--t-fast);
}
.chip b { font-family: var(--font-display); font-weight: 800; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.chip span { font-size: 12.5px; line-height: 1.3; color: var(--text-2); }
.chip:hover { background: rgba(244, 237, 223, .06); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: rgba(237, 180, 74, .14); }
.chip[aria-pressed="true"] span { color: var(--text); }

.impact { display: grid; gap: var(--s3); padding-top: var(--s4); border-top: 1px solid var(--desk-line); }
.impact-line { margin: 0; font-size: 17px; font-weight: 500; line-height: 1.6; color: var(--text); min-height: 1.6em; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 6px 18px; }
.checklist li { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--text-3); transition: color var(--t-ui); }
.checklist li i { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--text-3); display: grid; place-items: center; flex: none; transition: background var(--t-ui), border-color var(--t-ui); }
.checklist li.on { color: var(--text); }
.checklist li.on i { background: var(--accent); border-color: var(--accent); }
.checklist li.on i::after { content: ''; width: 7px; height: 4px; border: solid var(--accent-ink); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.next { margin: 0; font-size: 14px; color: var(--text-3); }
.next:empty { display: none; }

.donate {
  height: 60px; width: 100%; border: 0; border-radius: var(--r-md); cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--font-display); font-weight: 800; font-size: 22px;
  box-shadow: 0 2px 0 #B98523, 0 12px 24px rgba(0, 0, 0, .22);
  transition: transform var(--t-fast), filter var(--t-fast);
}
.donate:hover { filter: brightness(1.05); }
.donate:active { transform: translateY(1px); }
.donate[aria-disabled="true"] { background: #6C6A55; color: #F4EDDF; box-shadow: none; cursor: default; }

.foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); }
.switch { display: inline-flex; align-items: center; gap: 10px; background: none; border: 0; color: var(--text-2); font: 500 14px/1 var(--font-ui); padding: 6px 0; min-height: 44px; cursor: pointer; }
.switch .track { width: 40px; height: 24px; border-radius: 99px; border: 1.5px solid var(--line); position: relative; transition: background var(--t-fast); }
.switch .knob { position: absolute; top: 3px; inset-inline-start: 3px; width: 15px; height: 15px; border-radius: 50%; background: var(--text-2); transition: inset-inline-start var(--t-fast), background var(--t-fast); }
.switch[aria-checked="true"] { color: var(--text); }
.switch[aria-checked="true"] .track { background: rgba(237, 180, 74, .22); border-color: var(--accent); }
.switch[aria-checked="true"] .knob { inset-inline-start: 19px; background: var(--accent); }
.foot-note { font-size: 12.5px; color: var(--text-3); }

/* honesty line, scene-description link, input notes, row highlight */
.honest { margin: 0; font-size: 14px; line-height: 1.6; color: var(--text-2); }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--text); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.input-note { margin: 0; min-height: 0; font-size: 14px; color: #FFE3A3; }
.input-note:empty { display: none; }
.checklist li { position: relative; }
.checklist li::after { content: ''; position: absolute; inset: -3px -6px; border-radius: 6px; background: rgba(237, 180, 74, .36); opacity: 0; pointer-events: none; }
.checklist li.flash::after { animation: rowflash 1.4s ease-out 1; will-change: opacity; }
@keyframes rowflash { 0% { opacity: 1; } 100% { opacity: 0; } }
.desc-btn { display: inline-flex; align-items: center; gap: 8px; }
.desc-btn svg { width: 18px; height: 18px; }
.scene-desc:focus { outline: 3px solid var(--focus); outline-offset: 3px; }
/* reduced motion, after interaction: pieces cross-fade instead of snapping (WCAG: reduce, not remove) */
.reduced.interacted .piece, .reduced.interacted .part, .reduced.interacted .cast, .reduced.interacted #leaf-rest-a, .reduced.interacted #leaf-rest-b { transition: opacity 200ms ease !important; }
.reduced .checklist li.flash::after { animation: rowflash 1.4s ease-out 1 !important; }

/* ---------------------------------------------------------------- dialog */
.thanks {
  border: 0; border-radius: var(--r-lg); padding: var(--s6) var(--s6) var(--s5); width: min(420px, calc(100vw - 32px));
  background: var(--cream); color: var(--ink); text-align: center;
  box-shadow: 0 2px 0 #C9BEA6, 0 30px 60px rgba(0, 0, 0, .4);
}
.thanks::backdrop { background: rgba(20, 26, 19, .38); }
.thanks-lead { font-size: 16.5px; }
.summary { text-align: start; background: #EFE5D0; border-radius: var(--r-md); padding: 14px 16px; margin: 6px 0 12px; }
.summary p { margin: 0 0 8px; font-size: 15px; }
.summary-title { font-weight: 600; }
.summary-items { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.summary-items li { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
.summary-items svg { width: 24px; height: 24px; }
.summary-fund { color: #4A4A3C; }
.summary-next { margin: 0; padding: 0 1.2em 0 0; font-size: 14.5px; color: #3F3E33; }
.summary-next b { font-weight: 600; margin-inline-end: 4px; }
@media (min-width: 1000px) {
  /* desktop: the card sits over the reading side so the book (and the student's walk) stays in view */
  .thanks { margin-block: auto; margin-inline-start: 30px; margin-inline-end: auto; }
}
.thanks h2 { font-family: var(--font-display); font-weight: 800; font-size: 34px; margin: var(--s2) 0 var(--s2); line-height: 1.2; }
.thanks p { margin: 0 0 var(--s3); line-height: 1.75; }
.thanks .muted { color: #57564A; }
.thanks .small { font-size: 13.5px; }
.thanks .donate { margin-top: var(--s3); }
.thanks-mark svg { width: 64px; height: 64px; filter: drop-shadow(1px 2px 1px rgba(60, 40, 20, .3)); }
.thanks[open] { animation: settle 260ms var(--ease-out); }
@keyframes settle { from { opacity: 0; transform: translateY(8px); } }

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

/* ---------------------------------------------------------------- responsive */
/* fit 1440×900 (and anything ≤ 940 tall) without a vertical scroll */
@media (max-height: 940px) and (min-width: 1000px) {
  .panel { gap: 14px; padding-block: 24px; }
  .lede { font-size: 15.5px; line-height: 1.65; }
  .impact { gap: 10px; padding-top: 14px; }
}
@media (max-height: 820px) and (min-width: 1000px) {
  .panel { gap: 11px; padding-block: 14px; }
  h1 { font-size: 31px; }
  h1 br { display: none; }
  .honest { font-size: 13.5px; line-height: 1.5; }
  .chip { padding-block: 6px; }
  .foot { margin-top: -4px; }
  .lede { font-size: 15px; line-height: 1.65; }
  .field { height: 80px; }
  .field input { font-size: 56px; }
  .donate { height: 56px; }
  .impact { padding-top: var(--s3); gap: var(--s2); }
}
@media (max-width: 1180px) and (min-width: 1000px) {
  :root { --panel-w: 420px; }
}
@media (max-width: 999px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: minmax(380px, 46vh) auto; }
  .scene { grid-row: 1; }
  .panel { grid-row: 2; background: var(--desk); padding: 20px 32px 24px; gap: 14px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 32px; align-content: start; }
  .panel > .eyebrow, .panel > h1, .panel > .lede { grid-column: 1 / -1; }
  .panel h1 br { display: none; }
  h1 { font-size: 32px; }
  .lede { max-width: none; font-size: 15.5px; }
  .amount-block { grid-column: 1; }
  .impact { grid-column: 2; border-top: 0; padding-top: 30px; align-content: start; }
  .checklist { grid-template-columns: repeat(2, auto); }
  .donate-bar, .foot { grid-column: 1 / -1; }
  .stage-fit { inset: 0; }
  .desc-btn { top: 14px; bottom: auto; }
  .scene-desc { top: 58px; bottom: auto; }
}
/* ---------------------------------------------------------------- phones (390×844, 360×800, 430×932) */
@media (max-width: 600px) {
  .layout { grid-template-rows: auto auto; }
  /* phones: the whole open book fitted to the width; the description pill sits under it, off the page */
  .scene { display: flex; flex-direction: column; align-items: center; padding: 6px 0 4px; }
  .stage-fit { position: relative; inset: auto; width: 100%; aspect-ratio: 920 / 716; }
  .panel { grid-template-columns: 1fr; padding: 14px 16px 0; gap: 14px; }
  /* thumb order: title → amount → impact → the longer explanation */
  .panel > .eyebrow { display: none; }
  .panel > h1 { order: 1; } .amount-block { order: 2; } .impact { order: 3; } .panel > .lede { order: 4; } .donate-bar { order: 5; } .foot { order: 6; }
  .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }   /* still names the input */
  .amount-block, .impact { grid-column: 1; }
  h1 { font-size: 26px; line-height: 1.25; }
  .lede { font-size: 16px; line-height: 1.7; }
  .lbl { font-size: 15px; }
  .field { height: 78px; }
  .field input { font-size: 54px; }
  .unit { font-size: 20px; }
  .chip { min-height: 58px; padding: 8px 2px; }
  .chip span { font-size: 13px; }
  .impact { padding-top: 14px; border-top: 1px solid var(--desk-line); }
  .impact-line { font-size: 17px; }
  .checklist { grid-template-columns: repeat(2, auto); gap: 8px 22px; }
  .checklist li { font-size: 16px; }
  .next { font-size: 16px; }
  /* the donate action stays under the thumb while the panel scrolls */
  .donate-bar { position: sticky; bottom: 0; z-index: 5; margin: 0 -16px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    background: linear-gradient(to bottom, rgba(59, 70, 52, 0), var(--desk) 28%); }
  .foot { flex-direction: column; align-items: flex-start; gap: 4px; padding-bottom: 20px; }
  .switch { min-height: 44px; font-size: 16px; }
  .foot-note { font-size: 14px; }
  .desc-btn { position: static; min-height: 44px; font-size: 15px; margin-top: 2px; }
  .honest { font-size: 15px; }
  .linkish { display: inline-flex; align-items: center; min-height: 44px; padding-inline: 2px; }
  .scene-desc { position: static; max-width: none; margin: 10px 12px 2px; }
}
