/* Patient form.
   Sizing rules: body text never below 19px, tap targets never below 68px,
   and the primary action always sits in the bottom third within thumb reach. */

body {
  font-size: 20px;
  line-height: 1.5;
  overscroll-behavior-y: none;
  /* The step transition slides in from the right; never let that create a scrollbar. */
  overflow-x: hidden;
}

.app {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
  /* The step transition slides in from off-screen right. `clip` contains that
     without creating a scroll container, so the sticky header and footer keep
     working. body's overflow-x:hidden is the fallback for older browsers. */
  overflow-x: clip;
}

/* ---------- Header: logo, progress, language ---------- */

.hdr {
  position: sticky;
  top: 0;
  z-index: 20;
  /* Opaque rather than blurred: backdrop-filter on a sticky header costs real
     frames on the budget Android phones this runs on, for no visible gain. */
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 12px;
}

.hdr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
}

.hdr-logo { height: 34px; width: auto; display: block; }

.hdr-controls { display: flex; align-items: center; gap: 8px; min-width: 0; }
.langbar { display: flex; gap: 6px; }

/* Read-aloud toggle. Doubles as "repeat this screen" when already on. */
.speakbtn {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--card);
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, border-color .15s, transform .1s;
}
.speakbtn:active { transform: scale(.94); }
.speakbtn[aria-pressed="true"] {
  background: var(--cyan-soft);
  border-color: var(--cyan);
}
.speakbtn[aria-pressed="false"] { opacity: .6; }
/* On but with no voice installed for the chosen language. */
.speakbtn.novoice {
  background: var(--warn-soft);
  border-color: var(--warn);
  border-style: dashed;
}
.speakbtn.speaking { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(41, 171, 214, .5); }
  50%      { box-shadow: 0 0 0 8px rgba(41, 171, 214, 0); }
}

/* The toggle is introduced full-size on the welcome screen, where there is room
   to say what it does, then lives as an icon in the header from then on. */
.listen-toggle {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  min-height: 72px;
  padding: 12px 18px;
  margin-bottom: 14px;
  border-radius: var(--r-lg);
  border: 2px solid var(--line-strong);
  border-bottom-width: 4px;
  background: var(--card);
  font-size: 19px;
  font-weight: 700;
  color: var(--charcoal);
  cursor: pointer;
  text-align: left;
}
.listen-toggle:active { transform: translateY(2px); border-bottom-width: 2px; }
.listen-toggle[aria-pressed="true"] { border-color: var(--cyan); background: var(--cyan-soft); }
.listen-toggle .ico { font-size: 28px; flex: 0 0 auto; }
.listen-toggle .txt { flex: 1; }
.listen-toggle .state {
  flex: 0 0 auto;
  font-size: 15px; font-weight: 800;
  padding: 6px 14px; border-radius: 999px;
  background: var(--line); color: var(--grey);
}
.listen-toggle[aria-pressed="true"] .state { background: var(--cyan); color: #fff; }

.langbtn {
  border: 2px solid var(--line-strong);
  background: var(--card);
  color: var(--grey);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s, color .12s, background .12s;
}
.langbtn:hover { transform: translateY(-1px); }
.langbtn[aria-pressed="true"] {
  background: var(--cyan-soft);
  border-color: var(--cyan);
  color: var(--cyan-dark);
}

/* Segmented progress — each answered question lights up, Duolingo style. */
.progress {
  display: flex;
  gap: 4px;
  margin-top: 12px;
}
.progress[hidden] { display: none; }

.seg {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.seg i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--cyan-dark));
  transition: width .45s cubic-bezier(.2, .9, .3, 1);
}
/* Named "filled"/"active" rather than "done"/"current": a bare `.done` would
   also match the thank-you screen's `.done` rule and inherit its padding. */
.seg.filled i { width: 100%; }
.seg.active i { width: 55%; }

.progress-label {
  margin: 8px 0 0;
  font-size: 15px;
  color: var(--grey);
  font-weight: 600;
  text-align: center;
}

/* ---------- Screen body ---------- */

.screen {
  flex: 1;
  padding: 26px 18px 20px;
  animation: slideIn .32s cubic-bezier(.2, .9, .3, 1);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(22px); }
  to   { opacity: 1; transform: translateX(0); }
}
.screen.back { animation-name: slideInBack; }
@keyframes slideInBack {
  from { opacity: 0; transform: translateX(-22px); }
  to   { opacity: 1; transform: translateX(0); }
}

.q-title {
  font-size: 31px;
  line-height: 1.25;
  font-weight: 800;
  margin: 0 0 10px;
  letter-spacing: -.01em;
  color: var(--charcoal);
}

.q-hint {
  font-size: 18px;
  color: var(--grey);
  margin: 0 0 22px;
  line-height: 1.45;
}

/* ---------- Choice cards ---------- */

.options { display: grid; gap: 12px; }
.options.two-col { grid-template-columns: 1fr 1fr; }

.opt {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 72px;
  padding: 14px 16px;
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line-strong);
  border-bottom-width: 4px;
  border-radius: var(--r-lg);
  color: var(--charcoal);
  font-size: 20px;
  font-weight: 650;
  line-height: 1.3;
  cursor: pointer;
  transition: transform .1s ease, border-color .15s, background .15s, box-shadow .15s;
}

.opt:hover { border-color: var(--grey-light); }
.opt:active { transform: translateY(2px); border-bottom-width: 2px; }

.opt .emoji {
  font-size: 30px;
  line-height: 1;
  flex: 0 0 auto;
  width: 38px;
  text-align: center;
}

.opt .label { flex: 1; }

/* The tick only exists once chosen; its arrival is the reward. */
.opt .tick {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  display: grid;
  place-items: center;
  font-size: 17px;
  color: transparent;
  transition: background .15s, border-color .15s, color .15s, transform .18s;
}

.opt[aria-pressed="true"] {
  border-color: var(--terracotta);
  background: var(--terracotta-soft);
  box-shadow: var(--shadow-sm);
}
.opt[aria-pressed="true"] .tick {
  background: var(--terracotta);
  border-color: var(--terracotta);
  color: #fff;
  transform: scale(1.08);
}
.opt[aria-pressed="true"] .label { color: var(--terracotta-dark); }

.opt.pop { animation: pop .3s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.035); }
  100% { transform: scale(1); }
}

/* Clinical terms in the optional expert branch: denser than the plain-language
   cards, because these lists are long and the reader here is a confident one. */
.options.terms { gap: 8px; }
.options.terms .opt {
  min-height: 56px;
  padding: 11px 14px;
  font-size: 17px;
  font-weight: 600;
  border-bottom-width: 3px;
}
.options.terms .opt .tick { width: 24px; height: 24px; font-size: 14px; }

@media (min-width: 480px) {
  .options.terms { grid-template-columns: 1fr 1fr; }
}

/* Right/left eye cards read better side by side and larger. */
.options.eyes { grid-template-columns: 1fr 1fr; }
.options.eyes .opt {
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-height: 138px;
  text-align: center;
  font-size: 19px;
}
.options.eyes .opt .emoji { font-size: 44px; width: auto; }
.options.eyes .opt .tick { position: absolute; }
.options.eyes .opt { position: relative; }
.options.eyes .opt .tick { top: 10px; right: 10px; width: 26px; height: 26px; font-size: 15px; }
.options.eyes .opt:nth-child(1) .emoji { transform: scaleX(-1); }

/* ---------- Text inputs ---------- */

.field {
  width: 100%;
  padding: 18px 18px;
  font-size: 24px;
  font-weight: 600;
  border: 2px solid var(--line-strong);
  border-bottom-width: 4px;
  border-radius: var(--r-lg);
  background: var(--card);
  color: var(--charcoal);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field::placeholder { color: var(--grey-light); font-weight: 500; }
.field:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px var(--cyan-soft);
}
textarea.field { min-height: 132px; resize: vertical; font-size: 20px; line-height: 1.45; }

.field-note {
  margin: 10px 2px 0;
  font-size: 16px;
  color: var(--grey-light);
}

/* One-time code: wide tracking so each digit is separately readable. */
.code-field {
  text-align: center;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: .34em;
  text-indent: .34em;      /* re-centres text that letter-spacing pushes left */
  padding: 20px 12px;
  font-variant-numeric: tabular-nums;
}
.code-field::placeholder { letter-spacing: .26em; font-size: 32px; }

.otp-actions {
  display: grid;
  gap: 2px;
  margin-top: 14px;
}
.otp-actions .btn-skip:disabled {
  color: var(--grey-light);
  text-decoration: none;
  cursor: default;
}

.demo-banner {
  background: var(--warn-soft);
  border: 2px dashed var(--warn);
  color: var(--warn);
  border-radius: var(--r-md);
  padding: 12px 15px;
  font-size: 17px;
  font-weight: 750;
  text-align: center;
  margin-bottom: 16px;
}

/* ---------- Voice note ---------- */

.voice { margin-top: 20px; text-align: center; }

.voice-or {
  font-size: 16px;
  color: var(--grey-light);
  margin: 0 0 12px;
  position: relative;
}
.voice-or::before,
.voice-or::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 18%;
  height: 1px;
  background: var(--line);
}
.voice-or::before { left: 0; }
.voice-or::after { right: 0; }

.voice-btn {
  width: 100%;
  min-height: 72px;
  border-radius: var(--r-lg);
  border: 2px solid var(--cyan);
  border-bottom-width: 4px;
  background: var(--cyan-soft);
  color: var(--cyan-dark);
  font-size: 20px;
  font-weight: 750;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.voice-btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.voice-btn:disabled { opacity: .6; cursor: default; }

.voice-btn.recording {
  background: var(--terracotta);
  border-color: var(--terracotta-dark);
  color: #fff;
  animation: recpulse 1.5s ease-in-out infinite;
}
@keyframes recpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200, 69, 42, .45); }
  50%      { box-shadow: 0 0 0 10px rgba(200, 69, 42, 0); }
}

.voice-status {
  margin: 10px 0 0;
  font-size: 17px;
  font-weight: 650;
  color: var(--grey);
  font-variant-numeric: tabular-nums;
  min-height: 24px;
}

.voice-player { width: 100%; margin-top: 12px; }
.voice-player[hidden] { display: none; }

.age-row { display: grid; grid-template-columns: 1fr; gap: 22px; }
.sub-label {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--grey);
  margin: 0 0 10px;
}

/* ---------- Error ---------- */

.err {
  margin-top: 16px;
  padding: 13px 16px;
  border-radius: var(--r-md);
  background: var(--coral-soft);
  border: 2px solid var(--coral);
  color: var(--terracotta-dark);
  font-size: 18px;
  font-weight: 650;
  animation: shake .34s;
}
.err[hidden] { display: none; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-7px); }
  55% { transform: translateX(6px); }
  80% { transform: translateX(-3px); }
}

/* ---------- Footer actions ---------- */

.foot {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255, 250, 247, 0), var(--bg) 26%);
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  gap: 12px;
  align-items: center;
}
.foot[hidden] { display: none; }

.btn {
  border: none;
  border-radius: var(--r-lg);
  font-size: 21px;
  font-weight: 800;
  padding: 19px 24px;
  min-height: 68px;
  cursor: pointer;
  transition: transform .1s ease, filter .15s, background .15s;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
  flex: 1;
  background: var(--terracotta);
  color: #fff;
  box-shadow: 0 4px 0 var(--terracotta-dark);
}
.btn-primary:active { box-shadow: 0 2px 0 var(--terracotta-dark); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-back {
  background: var(--card);
  color: var(--grey);
  border: 2px solid var(--line-strong);
  border-bottom-width: 4px;
  min-width: 68px;
  padding: 19px 20px;
  font-size: 22px;
}
.btn-back:active { border-bottom-width: 2px; }

.btn-skip {
  background: none;
  border: none;
  color: var(--grey);
  font-size: 18px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 4px;
  padding: 14px 8px;
  min-height: 52px;
  cursor: pointer;
  width: 100%;
}

/* ---------- Welcome ---------- */

.welcome { text-align: center; padding: 34px 20px 20px; }
.welcome-logo { width: min(300px, 82%); height: auto; margin: 12px auto 26px; display: block; }
.welcome h1 { font-size: 30px; font-weight: 800; margin: 0 0 12px; line-height: 1.25; }
.welcome p { font-size: 19px; color: var(--grey); margin: 0 auto 28px; max-width: 30ch; }

.lang-prompt {
  font-size: 17px;
  font-weight: 700;
  color: var(--grey);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 0 0 14px;
}

.lang-choices { display: grid; gap: 12px; margin-bottom: 26px; }
.lang-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 76px;
  border-radius: var(--r-lg);
  border: 2px solid var(--line-strong);
  border-bottom-width: 4px;
  background: var(--card);
  font-size: 24px;
  font-weight: 750;
  color: var(--charcoal);
  cursor: pointer;
  transition: transform .1s, border-color .15s, background .15s;
}
.lang-choice:active { transform: translateY(2px); border-bottom-width: 2px; }
.lang-choice[aria-pressed="true"] {
  border-color: var(--cyan);
  background: var(--cyan-soft);
  color: var(--cyan-dark);
}
.lang-choice small { font-size: 15px; font-weight: 600; color: var(--grey-light); }

/* ---------- Cheer interstitials ---------- */

.cheer {
  text-align: center;
  padding: 56px 24px;
  display: grid;
  place-content: center;
  gap: 6px;
  min-height: 52vh;
}
.cheer .big {
  font-size: 92px;
  line-height: 1;
  margin-bottom: 12px;
  animation: bounceIn .62s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes bounceIn {
  0%   { transform: scale(.3) translateY(30px); opacity: 0; }
  55%  { transform: scale(1.15) translateY(-8px); opacity: 1; }
  100% { transform: scale(1) translateY(0); }
}
.cheer h2 { font-size: 33px; font-weight: 800; margin: 0 0 8px; color: var(--terracotta); }
.cheer p { font-size: 20px; color: var(--grey); margin: 0; }

/* ---------- Consent ---------- */

.consent-box {
  border: 2px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: 22px;
  background: var(--card);
}
.consent-text { font-size: 20px; line-height: 1.5; margin: 0 0 20px; }
.consent-note {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 16px; color: var(--grey);
  background: var(--cyan-soft);
  border-radius: var(--r-md);
  padding: 13px 15px;
  margin-top: 18px;
}

/* ---------- Review summary before submit ---------- */

.review { margin-top: 4px; display: grid; gap: 10px; }
.review-item {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: 17px;
}
.review-item b { color: var(--grey); font-weight: 650; flex: 0 0 40%; }
.review-item span { text-align: right; font-weight: 650; }

/* ---------- Done ---------- */

.done { text-align: center; padding: 40px 22px; }
.done .big { font-size: 88px; animation: bounceIn .7s cubic-bezier(.2, 1.5, .4, 1); }
.done h2 { font-size: 32px; font-weight: 800; margin: 14px 0 8px; }
.done p { font-size: 19px; color: var(--grey); margin: 0 auto 26px; max-width: 28ch; }

.token-card {
  background: linear-gradient(160deg, var(--terracotta), var(--coral));
  color: #fff;
  border-radius: var(--r-xl);
  padding: 26px 24px;
  margin: 0 auto 24px;
  max-width: 340px;
  box-shadow: var(--shadow-lg);
}
.token-card .k {
  font-size: 15px; text-transform: uppercase; letter-spacing: .14em;
  font-weight: 700; opacity: .9; margin: 0 0 6px;
}
.token-card .v { font-size: 58px; font-weight: 850; letter-spacing: .02em; line-height: 1.05; }

.saved-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--ok-soft); color: var(--ok);
  border: 2px solid var(--ok);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 16px; font-weight: 750;
  margin-bottom: 26px;
}

#confetti {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 50;
}

/* ---------- Larger phones / tablets ---------- */

@media (min-width: 560px) {
  .q-title { font-size: 35px; }
  .age-row { grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (max-width: 400px) {
  .q-title { font-size: 27px; }
  .opt { font-size: 18px; min-height: 66px; }
  .options.two-col { grid-template-columns: 1fr; }
  /* Keep the logo, speaker and three language pills on one line. */
  .hdr-logo { height: 28px; }
  .speakbtn { width: 42px; height: 42px; font-size: 19px; }
  .langbtn { padding: 7px 10px; font-size: 14px; }
}

/* Below ~360px (iPhone SE, older budget Androids) the logo, speaker and three
   language names cannot share a line at a legible size. Rather than shrink the
   text further for the readers least able to cope with small type, the controls
   wrap onto their own centred row. */
@media (max-width: 360px) {
  .hdr { padding: 8px 12px 10px; }
  .hdr-row { flex-wrap: wrap; justify-content: center; row-gap: 8px; }
  .hdr-controls { width: 100%; justify-content: center; }
  .hdr-logo { height: 26px; }
  .langbtn { padding: 7px 11px; font-size: 14px; }
  .screen { padding: 20px 14px 16px; }
  .foot { padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); }
  .q-title { font-size: 25px; }
  .q-hint { font-size: 17px; }
  .field { font-size: 21px; padding: 16px 14px; }
  .code-field { font-size: 32px; letter-spacing: .26em; text-indent: .26em; }
  .btn { font-size: 19px; padding: 17px 18px; }
  .welcome { padding: 26px 14px 16px; }
  .welcome h1 { font-size: 26px; }
  .token-card .v { font-size: 46px; }
  .cheer .big { font-size: 74px; }
  .done .big { font-size: 70px; }
}
