/*
 * Brand tokens mirror packages/shared/src/theme.ts.
 *
 * Translucent surfaces change the contrast maths, so every glass layer here is
 * measured against what it actually resolves to over gold, not against opaque
 * cream. At 72% the card resolves to #EFDAA9: ink 10.14, navy 6.45 — both AAA.
 * Inputs are white at 65% over that card: ink 12.70, navy 8.08.
 *
 * Base size is 16px rather than the native app's 18: iOS Safari zooms the page
 * when a focused input is under 16px, and 16 is the floor that avoids it.
 */
:root {
  --gold: #F2B518;
  --navy: #2B468E;
  --cream: #EEE8E1;
  --red: #EE3B51;
  --periwinkle: #9BADD9;
  --ink: #1A2A55;
  --white: #FFFFFF;

  /* A near-white warm tint, not cream: any translucent layer picks up the gold
     beneath it, and cream at 72% resolved to a muddy tan (#EFDAA9). This lands
     at #FBF1D9 — ink 12.41, navy 7.89, both AAA and visibly cleaner. */
  --glass-card: rgba(253, 251, 248, 0.86);
  --glass-input: rgba(255, 255, 255, 0.72);
  --glass-edge: rgba(255, 255, 255, 0.55);
  --glass-shadow: 0 8px 32px rgba(26, 42, 85, 0.16);
  --blur: saturate(180%) blur(20px);

  /* iOS-era radii: generous and consistent. */
  --r-card: 26px;
  --r-field: 14px;
  --r-button: 16px;

  --touch: 44px;   /* Apple HIG minimum */

  /*
   * Resident-adjustable text size. The phone is handed to a stranger who may
   * not have their reading glasses, and asking them to dig through iOS
   * settings is not an option — so the app carries its own control.
   */
  --text-scale: 1;
  font-size: calc(16px * var(--text-scale));
}

* { box-sizing: border-box; }

/*
 * The document itself never scrolls. position:fixed is what actually stops
 * iOS rubber-banding — overflow:hidden alone does not — so the page cannot be
 * dragged around while a resident is filling the form.
 */
html, body {
  margin: 0;
  padding: 0;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  /* Not background-attachment: fixed — Safari on iOS renders it unreliably.
     The screen is already viewport-height, so the gradient never scrolls. */
  background: radial-gradient(120% 80% at 50% 0%, #F7C63F 0%, var(--gold) 55%, #E8A80F 100%);
  background-color: var(--gold);
}

/* ------------------------------------------------------------------ *
 * Screen scaffold
 *
 * Fixed header, scrolling middle, fixed actions. The form is meant to fit
 * without scrolling; when a large accessibility text size makes that
 * impossible, only the middle moves and the buttons stay reachable.
 * ------------------------------------------------------------------ */

.screen {
  min-height: 100vh;    /* fallback for WebKit older than dvh support */
  max-height: 100vh;
  min-height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding:
    calc(12px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(14px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
  max-width: 34rem;
  margin: 0 auto;
}

.head { flex: none; }

.body {
  flex: 1;
  min-height: 0;          /* lets it actually shrink inside the flex column */
  /*
   * Every step is built to fit, so this never engages at the default text
   * size. It is a safety net for the largest scale settings: clipping a
   * button off the bottom of the screen would be worse than letting this
   * one region move.
   */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.body.centred { justify-content: center; }

.actions {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ------------------------------------------------------------------ *
 * Text-size control
 * ------------------------------------------------------------------ */

.textsize {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex: none;
}
.textsize .label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--navy);
  opacity: 0.7;
  margin-right: 2px;
}
.textsize button {
  width: 40px;
  min-width: 40px;
  min-height: 34px;
  padding: 0;
  font-weight: 800;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: var(--navy);
  border: 1px solid rgba(43, 70, 142, 0.28);
  box-shadow: none;
  /* Fixed against the scale it controls, or the buttons grow as you press. */
  font-size: 15px;
  line-height: 1;
}
.textsize button:nth-of-type(2) { font-size: 19px; }
.textsize button[disabled] { opacity: 0.4; }

/* ------------------------------------------------------------------ *
 * Type
 * ------------------------------------------------------------------ */

h1, h2, h3 { margin: 0; line-height: 1.2; color: var(--navy); }
h1 { font-size: 1.3rem;  font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem;  font-weight: 800; letter-spacing: -0.01em; }
h3 { font-size: 0.95rem; font-weight: 700; }

p { margin: 0; line-height: 1.45; font-size: 0.9rem; }
.muted { color: var(--ink); opacity: 0.7; font-size: 0.78rem; line-height: 1.35; }
.centre { text-align: center; }

.banner {
  display: inline-block;
  background: var(--red);
  color: var(--white);
  font-size: 1.05rem;        /* red needs >=18px bold to reach AA */
  font-weight: 800;
  padding: 5px 15px;
  border-radius: 999px;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 14px rgba(238, 59, 81, 0.3);
}

/* ------------------------------------------------------------------ *
 * Glass
 * ------------------------------------------------------------------ */

.card {
  background: var(--glass-card);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-card);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Older WebKit without backdrop-filter would render near-transparent panels. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .card { background: var(--cream); }
  input, textarea { background: var(--white) !important; }
}

.masthead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(43, 70, 142, 0.95);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--cream);
  border-radius: 20px;
  box-shadow: var(--glass-shadow);
}
.masthead img { width: 32px; height: 32px; border-radius: 9px; flex: none; }
.masthead .who { font-size: 0.88rem; font-weight: 700; line-height: 1.2; color: var(--white); }
.masthead .sub { font-size: 0.72rem; opacity: 0.85; }

/* ------------------------------------------------------------------ *
 * Fields
 *
 * The placeholder carries the field name and a persistent caption sits
 * underneath, so the purpose survives once the field has text in it — a
 * placeholder alone disappears exactly when it is still needed.
 * ------------------------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

input[type="text"], input[type="email"], input[type="tel"], input[type="password"], textarea {
  font: inherit;
  font-size: max(16px, 1rem);         /* never under 16px: iOS zooms on focus */
  color: var(--ink);
  background: var(--glass-input);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(43, 70, 142, 0.22);
  border-radius: var(--r-field);
  padding: 10px 13px;
  min-height: var(--touch);
  width: 100%;
  min-width: 0;
  box-shadow: inset 0 1px 2px rgba(26, 42, 85, 0.06);
}
input::placeholder, textarea::placeholder { color: rgba(26, 42, 85, 0.5); }
textarea { min-height: 84px; resize: none; line-height: 1.4; }

.hint {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--navy);
  opacity: 0.62;
  padding-left: 3px;
  line-height: 1.25;
}

input:focus, textarea:focus, button:focus-visible {
  outline: 3px solid rgba(43, 70, 142, 0.85);
  outline-offset: 1px;
  border-color: var(--navy);
}

.invalid { border-color: var(--red) !important; box-shadow: 0 0 0 2px rgba(238, 59, 81, 0.2); }
.error { color: #A8102A; font-size: 0.72rem; font-weight: 700; padding-left: 3px; }

/* ------------------------------------------------------------------ *
 * Buttons
 * ------------------------------------------------------------------ */

button {
  font: inherit;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: var(--r-button);
  min-height: var(--touch);
  padding: 11px 18px;
  cursor: pointer;
  width: 100%;
  font-size: 1.05rem;                 /* >=18px bold, so red labels clear AA */
  transition: transform 0.08s ease, filter 0.15s ease;
}
button:active { transform: scale(0.985); }

.btn-primary {
  background: linear-gradient(180deg, #3554A6 0%, var(--navy) 100%);
  color: var(--white);
  box-shadow: 0 6px 18px rgba(43, 70, 142, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-accent {
  background: linear-gradient(180deg, #F5566A 0%, var(--red) 100%);
  color: var(--white);
  box-shadow: 0 6px 18px rgba(238, 59, 81, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.btn-quiet {
  background: rgba(255, 255, 255, 0.42);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: var(--navy);
  border-color: rgba(43, 70, 142, 0.35);
}
.btn-link {
  background: none; border: none; box-shadow: none;
  color: var(--navy);
  text-decoration: underline;
  font-size: 0.82rem; font-weight: 700;
  min-height: auto; padding: 6px; width: auto;
}

/*
 * Disabled used to be opacity on red, which muddied into a washed orange that
 * read as broken rather than inactive. A flat neutral is unambiguous, and navy
 * on it measures 6.30 — comfortably AA even at body size.
 */
button[disabled] {
  background: rgba(255, 255, 255, 0.45);
  color: rgba(43, 70, 142, 0.65);
  border-color: rgba(43, 70, 142, 0.18);
  box-shadow: none;
  cursor: default;
  transform: none;
}

.row { display: flex; gap: 10px; align-items: flex-start; }
.row > * { flex: 1 1 0; min-width: 0; }

/* ------------------------------------------------------------------ *
 * Toggle — label and choices on one line to save vertical room
 * ------------------------------------------------------------------ */

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.toggle-row .toggle-label {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}
.toggle {
  flex: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: 148px;
}
.toggle button {
  background: rgba(255, 255, 255, 0.55);
  color: var(--navy);
  border: 1px solid rgba(43, 70, 142, 0.28);
  font-size: 0.92rem;
  font-weight: 700;
  padding: 9px 6px;
  min-height: 40px;
  box-shadow: none;
}
.toggle button[aria-pressed="true"] {
  background: linear-gradient(180deg, #3554A6 0%, var(--navy) 100%);
  color: var(--white);
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(43, 70, 142, 0.3);
}

/* ------------------------------------------------------------------ *
 * Rating scale
 *
 * This is what overflowed the screen at large accessibility text sizes: as
 * flex items the buttons kept min-width:auto, so they refused to shrink below
 * their digit + padding and pushed "5" off the edge. A grid of
 * minmax(0, 1fr) tracks can always divide the width, and the font size is
 * capped against the viewport so the digits scale down instead of out.
 * ------------------------------------------------------------------ */

.scale {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  width: 100%;
}
.scale button {
  min-width: 0;
  width: 100%;
  padding: 0;
  min-height: clamp(46px, 13vw, 62px);
  font-size: clamp(1rem, 4.5vw, 1.35rem);
  font-weight: 800;
  background: rgba(255, 255, 255, 0.6);
  color: var(--navy);
  border: 1px solid rgba(43, 70, 142, 0.25);
  border-radius: var(--r-field);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  overflow: hidden;
}
.scale button[aria-pressed="true"] {
  background: linear-gradient(180deg, #F5566A 0%, var(--red) 100%);
  color: var(--white);
  border-color: transparent;
  box-shadow: 0 5px 16px rgba(238, 59, 81, 0.36);
}

.scale-ends {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--navy);
  opacity: 0.75;
}
.scale-ends span { min-width: 0; }

/* ------------------------------------------------------------------ *
 * Progress, chips, wall
 * ------------------------------------------------------------------ */

.pips { display: flex; gap: 5px; justify-content: center; }
.pips span {
  height: 5px; flex: 1; max-width: 40px; min-width: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
}
.pips span.on { background: var(--navy); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: rgba(43, 70, 142, 0.93);
  color: var(--white);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.72rem;
  font-weight: 700;
}
.chip.warn { background: rgba(238, 59, 81, 0.9); }
.chip.idle { background: rgba(255, 255, 255, 0.5); color: var(--ink); }

.wall {
  background: rgba(43, 70, 142, 0.93);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--cream);
  border-radius: var(--r-card);
  padding: 30px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--glass-shadow);
}
.wall h2 { color: var(--white); font-size: 1.4rem; }
.wall p { color: var(--cream); font-size: 0.95rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(26, 42, 85, 0.92);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: var(--white);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
  z-index: 20;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--glass-shadow);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
