:root {
  --ink: #232043;
  --ground: #F8F7FB;
  --surface: #FFFFFF;
  --accent: #C98A2E;
  --accent-soft: #F6EEDF;
  --support: #5B8C7B;
  --support-ink: #3F6F5F;   /* sage dark enough to be read as small text on white */
  --muted: #6B6885;
  --line: #E4E2EE;
  /* amber is too light to carry text on white, so text on amber is ink */
  --on-accent: #232043;
  --accent-edge: #B57A22;
  --shadow: 0 1px 2px rgba(35, 32, 67, .05), 0 8px 24px rgba(35, 32, 67, .06);
  --focus: #232043;
  --radius: 16px;
  --slide: 230ms;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #EDEBF7;
    --ground: #16142B;
    --surface: #211E3B;
    --accent: #D9A04B;
    --accent-soft: #2D2632;
    --support: #86B5A3;
    --support-ink: #86B5A3;
    --muted: #A7A3C2;
    --line: #34305A;
    --on-accent: #1A1830;
    --accent-edge: #E2AE5E;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --focus: #F1C27D;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #EDEBF7;
  --ground: #16142B;
  --surface: #211E3B;
  --accent: #D9A04B;
  --accent-soft: #2D2632;
  --support: #86B5A3;
  --support-ink: #86B5A3;
  --muted: #A7A3C2;
  --line: #34305A;
  --on-accent: #1A1830;
  --accent-edge: #E2AE5E;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --focus: #F1C27D;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { direction: rtl; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: "IBM Plex Sans Arabic", Tajawal, system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, input, textarea { font: inherit; color: inherit; }

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

[hidden] { display: none !important; }

/* numbers and ranges read left-to-right inside Arabic */
/* a short phrase that must not break across lines */
.nowrap { white-space: nowrap; }

.num { unicode-bidi: isolate; direction: ltr; display: inline-block; }

/* ------------------------------------------------------------------ frame */

.app {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

@media (min-width: 600px) and (min-height: 700px) {
  body { padding: 32px 0; }
  .app {
    min-height: 0;
    height: min(860px, calc(100dvh - 64px));
    background: var(--ground);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
}

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 8px 20px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--ground);
}

.back {
  flex: none;
  width: 44px;
  height: 44px;
  margin-inline-start: -8px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
@media (hover: hover) { .back:hover { background: var(--line); } }

.progress {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}
/* RTL: the fill starts at the right edge and grows leftward */
.progress-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  border-radius: 4px;
  transform-origin: right center;
  transform: scaleX(0);
  transition: transform 300ms ease;
}

.count {
  flex: none;
  min-width: 4.5em;
  text-align: left;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ stage + slide */

.stage {
  position: relative;
  flex: 1;
  display: grid;
  overflow: hidden;
}

.screen {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px 20px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--ground);
}

/* RTL: the next question sits to the LEFT, so going forward the strip moves right */
.screen.enter-fwd  { animation: in-from-left  var(--slide) cubic-bezier(.2, .7, .2, 1) both; }
.screen.leave-fwd  { animation: out-to-right  var(--slide) cubic-bezier(.4, 0, .6, 1) both; }
.screen.enter-back { animation: in-from-right var(--slide) cubic-bezier(.2, .7, .2, 1) both; }
.screen.leave-back { animation: out-to-left   var(--slide) cubic-bezier(.4, 0, .6, 1) both; }

@keyframes in-from-left  { from { transform: translateX(-28%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes out-to-right  { from { transform: none; opacity: 1; } to { transform: translateX(28%); opacity: 0; } }
@keyframes in-from-right { from { transform: translateX(28%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes out-to-left   { from { transform: none; opacity: 1; } to { transform: translateX(-28%); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .screen.enter-fwd, .screen.enter-back { animation: fade-in 120ms linear both; }
  .screen.leave-fwd, .screen.leave-back { animation: fade-out 1ms linear both; }
  .progress-fill { transition: none; }
  .option, .dot { transition: none !important; }
}
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }

/* ------------------------------------------------------------------ question */

.q-head { padding-top: clamp(8px, 11vh, 110px); }
.q-head:focus, .exchange:focus, .done h1:focus { outline: none; }
.q-lead { display: block; font-size: 1.1875rem; font-weight: 500; line-height: 1.8; margin-bottom: 14px; }
.text-answer { display: flex; flex-direction: column; }

.q-title {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.6;
  font-weight: 600;
  letter-spacing: 0;
  text-wrap: pretty;
}
.q-title:focus { outline: none; }
.q-title:focus-visible { outline: 3px solid var(--focus); outline-offset: 6px; border-radius: 4px; }

.q-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: .9375rem;
}

/* the answers live in the lower part of the screen, under the thumb */
.answers {
  margin-top: auto;
  padding-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: clamp(0px, 3vh, 32px);
}

.group { display: flex; flex-direction: column; gap: 10px; }
.group-label {
  font-size: .875rem;
  font-weight: 500;
  color: var(--muted);
}

.options { display: flex; flex-direction: column; gap: 10px; }
.options.grid { display: grid; grid-template-columns: 1fr 1fr; }

.option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 12px 18px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.5;
  text-align: start;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 120ms ease;
}
.options.grid .option { justify-content: center; text-align: center; padding-inline: 12px; }
@media (hover: hover) { .option:hover { border-color: var(--accent-edge); } }
.option:active { transform: scale(.985); }

.option .mark {
  flex: none;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.options.grid .option .mark { display: none; }
.option .mark svg { opacity: 0; }

.option[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.option[aria-checked="true"] .mark {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.option[aria-checked="true"] .mark svg { opacity: 1; }

/* ------------------------------------------------------------------ 1–5 scale */

.scale { display: flex; flex-direction: column; gap: 12px; }
.dots {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.dot {
  flex: 1;
  max-width: 64px;
  aspect-ratio: 1;
  min-height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 120ms ease;
}
@media (hover: hover) { .dot:hover { border-color: var(--accent-edge); } }
.dot:active { transform: scale(.95); }
.dot[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.scale-ends {
  display: flex;
  justify-content: space-between;
  font-size: .875rem;
  color: var(--muted);
}

/* ------------------------------------------------------------------ the commercial question */

/* screens with more to read, or a keyboard coming up, start higher */
.q-commercial .q-head, .q-record_value .q-head, .q-wish .q-head, .q-contact .q-head { padding-top: clamp(4px, 3vh, 28px); }
.q-commercial .q-title, .q-record_value .q-title { font-size: 1.25rem; }
.q-commercial .answers, .q-record_value .answers { padding-top: 20px; }

.scenario { margin: 0 0 18px; }
.sc-lead { margin: 0 0 10px; color: var(--muted); font-size: 1rem; }

/* one example message, drawn as a message — not as a paragraph about one */
.msg {
  position: relative;
  max-width: 94%;
  padding: 12px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  border-start-start-radius: 4px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.0625rem;
  line-height: 1.7;
}
.msg p { margin: 0; }
.msg-from {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--support-ink);
}
.msg-from::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.msg-ask {
  margin-top: 8px !important;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  border-inline-start: 3px solid var(--accent);
}
.msg-ask strong { font-weight: 600; }

/* the two-year record: three things she would keep */
.rec ul { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rec li { position: relative; padding-inline-start: 20px; line-height: 1.6; }
.rec li::before {
  content: "";
  position: absolute;
  inset-inline-start: 2px;
  top: .62em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--accent);
}

.sc-payoff {
  margin: 14px 0 0;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.7;
}

/* ------------------------------------------------------------------ text + fields */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .9375rem; font-weight: 500; }
.field label .opt { color: var(--muted); font-weight: 400; }

.input, .textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 12px 16px;
  font-size: 1.0625rem;
  line-height: 1.6;
  text-align: right;
  transition: border-color 150ms ease;
}
.input { min-height: 52px; }
.textarea { min-height: 8.5rem; resize: vertical; margin-top: 12px; }

/* sentence openers above the wish box */
.starters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.starter {
  min-height: 44px;
  padding: 8px 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: .9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease;
}
@media (hover: hover) { .starter:hover { border-color: var(--accent-edge); } }
.starter:active { background: var(--accent-soft); }
.input:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 1; }

.fields { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.fine { margin: 14px 0 0; font-size: .875rem; color: var(--muted); }
.fields .fine { margin: 0; }
.fields .field-lead { margin-top: 6px; font-size: .9375rem; }

.hp { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------------ buttons */

.actions { display: flex; flex-direction: column; gap: 6px; margin-top: 22px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 12px 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.125rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: filter 150ms ease, transform 120ms ease;
}
@media (hover: hover) { .btn:hover { filter: brightness(1.05); } }
.btn:active { transform: scale(.985); }

.link {
  align-self: center;
  min-height: 48px;
  padding: 8px 16px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 12px;
}
@media (hover: hover) { .link:hover { color: var(--ink); } }

/* ------------------------------------------------------------------ welcome */

.welcome { padding-top: max(40px, env(safe-area-inset-top)); }
/* on a tall phone the hook drops a little from the top edge; the button keeps the thumb zone */
.welcome::before { content: ""; flex: 1 1 0; max-height: 10vh; }

.exchange {
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.exchange .ask, .exchange .reply {
  margin: 0;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0;
}
.exchange .ask { font-size: clamp(2.125rem, 9vw, 2.625rem); }
.exchange .reply {
  font-size: clamp(2.125rem, 9vw, 2.625rem);
  align-self: flex-end;
  color: var(--muted);
}

.thread {
  display: block;
  width: 72px;
  height: 14px;
  margin: 28px 0 22px;
  color: var(--accent);
}

.lede {
  margin: 0 0 18px;
  font-size: 1.1875rem;
  font-weight: 600;
}
.welcome p.body {
  margin: 0 0 14px;
  font-size: 1.0625rem;
}
.welcome .scene {
  margin: 0 0 6px;
  font-size: 1.0625rem;
  color: var(--muted);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 26px 0 0;
  padding: 0;
  list-style: none;
  font-size: .9375rem;
  color: var(--muted);
}
.meta li { display: inline-flex; align-items: center; gap: 6px; }
.meta li + li::before { content: "·"; margin-inline-end: 4px; }
.meta svg { color: var(--accent); }

.foot {
  margin: 14px 0 0;
  text-align: center;
  font-size: .8125rem;
  color: var(--muted);
}
.foot .site {
  display: block;
  width: fit-content;
  margin: 2px auto 0;
  padding: 4px 8px;
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}
@media (hover: hover) { .foot .site:hover { color: var(--ink); text-decoration-color: currentColor; } }

.welcome .actions, .done .actions { margin-top: auto; padding-top: 28px; }

/* ------------------------------------------------------------------ completion */

.done { padding-top: max(40px, env(safe-area-inset-top)); }
.done-mark {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--support);
  color: var(--support);
  margin-bottom: 18px;
}
.done h1 {
  margin: 0 0 12px;
  font-size: 2rem;
  line-height: 1.35;
  font-weight: 600;
}
.done h1:focus { outline: none; }
.done p { margin: 0 0 12px; }

.rule {
  height: 1px;
  border: 0;
  background: var(--line);
  margin: 26px 0;
}

.done-h { margin: 0 0 6px; font-size: 1.1875rem; line-height: 1.6; font-weight: 600; }
.done .done-sub { margin: 0 0 14px; color: var(--muted); font-size: 1rem; }
.done .fine:empty { display: none; }

/* her own words, handed back to her */
.her-words {
  margin: 4px 0 14px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border-inline-start: 3px solid var(--accent);
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form .input { flex: 1; min-width: 0; }
.btn.small {
  width: auto;
  flex: none;
  min-height: 52px;
  padding: 10px 18px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--support);
  font-weight: 500;
}

.noscript { padding: 24px; text-align: center; }
