/* styles.css — mobile-first. A questionnaire can override the colour tokens through its "theme" block. */
:root {
  /* "only" keeps browsers from auto-darkening the page; the first line is for browsers that do not know "only". */
  color-scheme: light;
  color-scheme: only light;
  --bg: #f7f5f1;
  --card: #ffffff;
  --fg: #1e1c19;
  --muted: #5c5750;
  --border: #b9b2a6;
  --accent: #2c6652;
  --accent-fg: #ffffff;
  --accent-tint: #e6f0ec;
  --danger: #a3362b;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

/* The top inset is more than zero only where the page is drawn under the status bar (some in-app browsers). */
.app {
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.loading, .noscript { padding: 48px 16px; text-align: center; color: var(--muted); }
.loading p { margin: 0 0 8px; }
/* Appears when the page has still not started 8 seconds after it was opened (a script did not load).
   The page replaces the whole .loading block when it starts.
   LIMIT: by the clock only (the content policy allows no inline script), so a start that is merely slow
   shows the line too until the page appears; move the timing into a script file if that misleads people. */
.loading-late { visibility: hidden; animation: late 0s linear 8s forwards; }
@keyframes late { to { visibility: visible; } }

/* ---- strip above every page of a draft questionnaire or a test link ---- */
.banner {
  margin: 0 -16px; padding: 6px 16px; border-bottom: 1px solid #c9a227;
  background: #fff1b8; color: #4d3800; font-size: 14px; line-height: 1.3; font-weight: 600; text-align: center;
}

/* ---- top bar: back + progress ---- */
.top { display: flex; align-items: center; gap: 10px; height: 52px; }
.back {
  flex: none; width: 44px; height: 44px; margin-left: -10px;
  border: 0; background: none; color: var(--fg); border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
}
.back svg { width: 22px; height: 22px; }
.progress { flex: 1; height: 6px; border-radius: 3px; background: #e2ddd4; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .25s ease; }

/* ---- page ---- */
.screen { flex: 1; display: flex; flex-direction: column; padding-top: 8px; animation: enter .18s ease; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-title { margin: 4px 0 0; font-size: 26px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; outline: none; }
.slot:empty { display: none; }
.block { margin-top: 28px; scroll-margin-top: 16px; }
.q { margin: 0 0 4px; font-size: 19px; line-height: 1.3; font-weight: 700; outline: none; }
.help { margin: 0; color: var(--muted); font-size: 15px; }
.body { margin-top: 12px; }
.block.has-error .q { color: var(--danger); }
.block-error { margin: 8px 0 0; color: var(--danger); font-size: 15px; }
.block-error:empty { display: none; }

.notice p, .end p { margin: 0 0 12px; }
.notice h1, .end h1, .msg h1 { margin: 20px 0 14px; font-size: 26px; line-height: 1.25; outline: none; }
.msg { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 24px 4px; }
.msg p { color: var(--muted); margin: 0 0 14px; }

/* ---- options (single / multi) ----
   "chips" flow side by side and wrap; "list" puts one option per row (for long labels). */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opts[data-layout="list"] { display: grid; }
.opt {
  max-width: 100%; min-height: 46px; padding: 10px 16px;
  border: 1.5px solid var(--border); border-radius: 23px;
  background: var(--card); color: var(--fg);
  font: inherit; font-size: 16px; line-height: 1.3; text-align: left; cursor: pointer;
  transition: border-color .12s, background-color .12s, color .12s;
}
.opts[data-layout="list"] .opt { width: 100%; min-height: 52px; padding: 12px 16px; border-radius: var(--radius); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.opt.dim { opacity: .45; }
/* Why a tap on one more option had no effect. Stays at the bottom edge of the screen while its own
   place, under the options, is further down. */
.opt-note { position: sticky; bottom: 0; margin: 8px 0 0; padding: 6px 0; background: var(--bg); color: var(--danger); font-size: 15px; }
.opt-note:empty { display: none; }
.opt:focus-visible, .next:focus-visible, .back:focus-visible, .vas-track:focus-visible, .scale-btn:focus-visible, .other:focus-visible, .link-btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px;
}
.other {
  width: 100%; margin-top: 10px; padding: 12px 14px; min-height: 50px;
  border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--card);
  font: inherit; color: var(--fg);
}
.other-note { margin: 6px 0 0; font-size: 14px; line-height: 1.3; color: var(--muted); }

/* ---- scale (1..5) ----
   The numbers and the wording under them are two rows of equal columns. The columns may be narrower
   than a word, and each wording is centred on its column, so it stays under its number. */
.scale { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.scale-btn {
  min-width: 0; min-height: 56px; padding: 0; border: 1.5px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--fg); font: inherit; font-size: 20px; font-weight: 600; cursor: pointer;
}
.scale-btn[aria-checked="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.scale-labels { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; margin-top: 6px; font-size: 14px; line-height: 1.25; color: var(--muted); text-align: center; }
.scale-labels span { justify-self: center; }

/* ---- VAS ---- */
.vas-group { display: grid; gap: 22px; margin-top: 8px; }
.vas-ends { display: flex; justify-content: space-between; gap: 16px; font-size: 15px; line-height: 1.25; color: var(--fg); }
.vas-end { max-width: 46%; }
.vas-end-right { text-align: right; }
/* The track is the hit area: taller and wider than the visible line. pan-y leaves vertical page scrolling
   (and pinch zoom) to the browser; the script receives horizontal presses. Never use "manipulation" here
   (iOS then sends no pointercancel) or "none" (a scroll attempt would be recorded as an answer). */
.vas-track { position: relative; height: 56px; margin: 0 -4px; cursor: pointer; touch-action: pan-y pinch-zoom; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; border-radius: 12px; }
/* No padding or border on the line itself: its rectangle is what 0..100 is measured against.
   The 22px inset keeps both ends away from the screen edge, where the system "back" swipe starts. */
.vas-line { position: absolute; left: 22px; right: 22px; top: 50%; height: 4px; margin-top: -2px; background: #7d766c; border-radius: 2px; }
.vas-tick { position: absolute; top: -8px; width: 4px; height: 20px; background: #7d766c; border-radius: 2px; }
.vas-tick-left { left: 0; }
.vas-tick-right { right: 0; }
.vas-mark {
  position: absolute; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%; background: var(--accent); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35); pointer-events: none;
}
.vas-hint { margin: 0; font-size: 15px; color: var(--muted); }
.vas-hint:empty { display: none; }

/* ---- bottom ---- */
.foot { margin-top: auto; padding-top: 30px; }
.next {
  width: 100%; min-height: 56px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-fg); font: inherit; font-size: 18px; font-weight: 700; cursor: pointer;
}
.link-btn { display: block; width: 100%; min-height: 52px; margin-top: 10px; padding: 14px; border: 1.5px solid var(--accent); border-radius: var(--radius); background: none; color: var(--accent); font: inherit; font-weight: 600; text-align: center; text-decoration: none; cursor: pointer; }
.hint { margin: 0 0 10px; font-size: 15px; color: var(--danger); text-align: center; }
.hint:empty { display: none; }

/* ---- end page ---- */
.reward { margin: 18px 0; padding: 18px 16px; border: 1.5px dashed var(--accent); border-radius: var(--radius); background: var(--card); text-align: center; }
.reward-sample { margin: 0 0 10px; font-size: 14px; font-weight: 700; color: var(--danger); }
.reward-label { margin: 0 0 6px; font-size: 15px; color: var(--muted); }
.reward-code { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: .06em; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.reward-note { margin: 8px 0 0; font-size: 15px; color: var(--muted); }
.ref { margin-top: 18px; font-size: 14px; color: var(--muted); }
.spinner { width: 34px; height: 34px; margin: 0 auto 16px; border: 3px solid #d9d3c8; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
  .progress > span { transition: none; }
  .spinner { animation-duration: 2s; }
}
