/* Palette echoes the `survey-quiet` basemap profile from ~/basemaps, so the
   page and the map read as one surface rather than a map pasted into a form. */
:root {
  --paper:      #f4f2ee;
  --paper-warm: #efece6;
  --ink:        #2b2822;
  --ink-soft:   #6a635a;
  --ink-faint:  #9a938a;
  --line:       #ddd8cf;
  --line-soft:  #e8e4dc;
  --accent:     #7a5c3e;   /* trajectory path; warm against the cool basemap */
  --accent-soft:#b08a5f;
  --water:      #d8e2e8;
  --danger:     #8c3a2e;
  --ok:         #4a6b46;
  --radius:     10px;
  --pad:        clamp(1rem, 4vw, 1.75rem);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  /* Room for the fixed footer nav, including the iOS home indicator. */
  padding-bottom: calc(5rem + env(safe-area-inset-bottom));
}

.hp { position: absolute; left: -9999px; top: 0; width: 1px; height: 1px; overflow: hidden; }

/* --- chrome ---------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-inner {
  max-width: 44rem; margin: 0 auto;
  padding: .6rem var(--pad);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { font-size: .82rem; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }
.lang { display: flex; gap: .25rem; }
.lang button {
  border: 1px solid transparent; background: none; color: var(--ink-faint);
  font: inherit; font-size: .8rem; letter-spacing: .05em;
  padding: .15rem .45rem; border-radius: 6px; cursor: pointer;
}
.lang button[aria-current="true"] { color: var(--ink); border-color: var(--line); background: var(--paper-warm); }

.progress { height: 2px; background: var(--line-soft); }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .35s ease; }

.shell { max-width: 44rem; margin: 0 auto; padding: var(--pad); }
.loading { color: var(--ink-faint); }

.navbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem var(--pad) calc(.7rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line-soft);
}
.navbar > .btn:last-child { margin-left: auto; }
.navbar-status { font-size: .82rem; color: var(--ink-faint); text-align: center; flex: 1; }

/* --- controls -------------------------------------------------------------- */

.btn {
  font: inherit; font-weight: 500;
  padding: .65rem 1.15rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--paper-warm); color: var(--ink);
  cursor: pointer; min-height: 2.9rem;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.ghost { background: none; border-color: transparent; color: var(--ink-soft); }
.btn.small { padding: .35rem .7rem; min-height: 2.2rem; font-size: .85rem; }
.btn.danger { color: var(--danger); }

h1.section-title { font-size: 1.5rem; line-height: 1.25; margin: .25rem 0 .75rem; font-weight: 600; }
h2.group-title {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint); margin: 2.5rem 0 -.5rem;
}
.section-intro { color: var(--ink-soft); margin: 0 0 1.5rem; }

.q { margin: 0 0 2rem; }
.q-label { display: block; font-weight: 500; margin-bottom: .5rem; }
.q-help { display: block; color: var(--ink-soft); font-size: .88rem; margin: -.25rem 0 .6rem; }
.q-warning {
  display: block; font-size: .85rem; font-style: italic;
  color: var(--ink-soft); border-left: 2px solid var(--accent-soft);
  padding: .4rem 0 .4rem .75rem; margin: .6rem 0;
}
.q-required { color: var(--danger); font-weight: 400; }
.q-error { color: var(--danger); font-size: .85rem; margin-top: .4rem; }
.q.invalid > .q-label { color: var(--danger); }

/* Question number, matching the printed instrument. Inline rather than hung in
   the margin: the column is 44rem wide and centred, so on the screens where a
   margin exists at all it is narrower than the number. */
.q-num {
  color: var(--ink-faint); font-variant-numeric: tabular-nums;
  font-weight: 400; margin-right: .5rem;
}
.q.invalid > .q-label .q-num { color: inherit; }

/* Search box footer: the note, plus a retry button when a lookup failed. */
.search-foot { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.search-foot .search-note { flex: 1 1 auto; }
/* A code that exists but sits outside the study area: worth saying, not worth
   refusing, so it is not styled as an error. */
.search-note.caution { color: var(--accent); }

.opts { display: grid; gap: .4rem; }
.opt {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .7rem .85rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper-warm); cursor: pointer; min-height: 2.9rem;
}
.opt:has(input:checked) { border-color: var(--ink); background: #fff; }
.opt input { margin-top: .2rem; accent-color: var(--ink); width: 1.05rem; height: 1.05rem; flex: none; }
.opt span { flex: 1; }

/* `search` belongs in this list: without it the address box fell back to the
   UA's default width — about half the column — which made the most important
   input in the instrument look like a leftover. */
input[type="text"], input[type="number"], input[type="email"], input[type="search"],
textarea, select {
  font: inherit; width: 100%; padding: .65rem .8rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--ink); min-height: 2.9rem;
}
/* Safari and iOS style search inputs as rounded pills with their own metrics. */
input[type="search"] { -webkit-appearance: none; appearance: none; box-sizing: border-box; }
input:focus-visible, textarea:focus-visible, select:focus-visible,
.opt:focus-within, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { min-height: 5.5rem; resize: vertical; }
input.narrow { max-width: 9rem; }
.other-input { margin-top: .4rem; }

/* slider */
.slider-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .75rem; }
.slider-row input[type="range"] { width: 100%; accent-color: var(--accent); height: 2.4rem; }
.slider-value {
  font-variant-numeric: tabular-nums; font-size: 1.1rem; min-width: 2.2rem;
  text-align: right; color: var(--ink-soft);
}
.slider-value.set { color: var(--ink); font-weight: 600; }
.slider-ends { display: flex; justify-content: space-between; font-size: .78rem; color: var(--ink-faint); }
.slider-item + .slider-item { margin-top: 1.1rem; }
.slider-item > label { display: block; font-size: .92rem; margin-bottom: .1rem; }

/* likert */
.likert { overflow-x: auto; }
.likert table { border-collapse: collapse; width: 100%; min-width: 30rem; }
.likert th { font-weight: 500; font-size: .74rem; color: var(--ink-faint); padding: .3rem; text-align: center; }
.likert th:first-child { text-align: left; width: 40%; }
.likert td { text-align: center; padding: .3rem; border-top: 1px solid var(--line-soft); }
.likert td:first-child { text-align: left; font-size: .92rem; }
.likert input { accent-color: var(--ink); width: 1.15rem; height: 1.15rem; }
.likert tr:has(input:checked) td:first-child { font-weight: 500; }
/* Under ~34rem the grid stops working; each statement becomes its own block. */
@media (max-width: 34rem) {
  .likert table, .likert thead, .likert tbody, .likert tr, .likert th, .likert td { display: block; }
  .likert table { min-width: 0; }
  .likert thead { display: none; }
  .likert tr { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .7rem; margin-bottom: .5rem; background: var(--paper-warm); }
  .likert td { border: 0; padding: .15rem 0; text-align: left; }
  .likert td:first-child { font-weight: 500; margin-bottom: .3rem; }
  .likert td[data-label]::before { content: attr(data-label); font-size: .85rem; color: var(--ink-soft); margin-right: .5rem; }
  .likert td { display: flex; align-items: center; gap: .4rem; flex-direction: row-reverse; justify-content: flex-end; }
  .likert td:first-child { display: block; }
}

/* numeric grid */
.numgrid { display: grid; gap: .5rem; }
.numgrid-row { display: grid; grid-template-columns: 1fr 6rem; align-items: center; gap: .75rem; }

/* --- map ------------------------------------------------------------------- */

.map-wrap { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.map { height: min(52vh, 26rem); background: var(--paper-warm); }
.map.tall { height: min(58vh, 30rem); }
/* The read-only trajectory map carried into later sections. Short on purpose:
   it is context above a long form, not the subject of the page. */
.map.mini { height: min(30vh, 13rem); }

.traj-map { margin: 0 0 1.5rem; }
.traj-map-caption {
  margin: .4rem 0 0; font-size: .82rem; color: var(--ink-faint);
}

/* The search box sits under the map it drives, not above it. */
.picker-search { margin-top: .7rem; }
.map-hint {
  /* Top-left, not bottom-left: on a phone the bottom edge already carries the
     OpenStreetMap attribution, and the two overlapped. */
  position: absolute; left: .5rem; top: .5rem; z-index: 2;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border: 1px solid var(--line); border-radius: 6px;
  padding: .2rem .5rem; font-size: .76rem; color: var(--ink-soft);
  pointer-events: none;
}
.maplibregl-ctrl-attrib { font-size: .68rem; }

.search { position: relative; margin-bottom: .6rem; }
.search input { padding-right: 2.4rem; }
.search-spin {
  position: absolute; right: .8rem; top: 50%; transform: translateY(-50%);
  font-size: .78rem; color: var(--ink-faint);
}
.search-results {
  list-style: none; margin: .35rem 0 0; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: #fff;
}
.search-results:empty { display: none; }
.search-results li { padding: .6rem .8rem; cursor: pointer; font-size: .92rem; border-top: 1px solid var(--line-soft); }
.search-results li:first-child { border-top: 0; }
.search-results li:hover, .search-results li[aria-selected="true"] { background: var(--paper-warm); }
.search-note { font-size: .82rem; color: var(--ink-soft); margin: .35rem 0 0; }
.search-note.warn { color: var(--danger); }

/* precision segmented control */
.segmented { display: flex; gap: 0; margin-top: .6rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented button {
  flex: 1; font: inherit; font-size: .85rem; padding: .55rem .4rem; min-height: 2.7rem;
  border: 0; border-left: 1px solid var(--line); background: var(--paper-warm);
  color: var(--ink-soft); cursor: pointer;
}
.segmented button:first-child { border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.segmented-help { font-size: .8rem; color: var(--ink-faint); margin: .35rem 0 0; }

/* --- trajectory builder ---------------------------------------------------- */

.traj-prompt { font-size: 1.15rem; font-weight: 500; margin: 0 0 .75rem; }
.traj-prompt em { font-style: normal; color: var(--accent); }

.timeline {
  display: flex; gap: .4rem; overflow-x: auto; padding: .1rem .1rem .5rem;
  margin: 0 0 1rem; scrollbar-width: thin;
}
.timeline-chip {
  flex: none; display: flex; flex-direction: column; align-items: flex-start;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper-warm); padding: .4rem .6rem; cursor: pointer;
  font-size: .8rem; line-height: 1.3; min-width: 5.5rem; text-align: left;
}
.timeline-chip[aria-current="true"] { border-color: var(--ink); background: #fff; }
.timeline-chip b { font-variant-numeric: tabular-nums; font-weight: 600; }
.timeline-chip span { color: var(--ink-faint); max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-chip.add { border-style: dashed; color: var(--ink-soft); justify-content: center; }

.home-fields { margin-top: 1.25rem; }
.home-actions { display: flex; gap: .5rem; align-items: center; margin-top: 1.5rem; flex-wrap: wrap; }
.home-actions .spacer { flex: 1; }

.saved-flash { font-size: .8rem; color: var(--ok); opacity: 0; transition: opacity .2s; }
.saved-flash.on { opacity: 1; }

/* --- end screen ------------------------------------------------------------ */

.reward { text-align: center; padding: 1rem 0 2rem; }
.reward h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
.reward .map-link {
  display: block; word-break: break-all; font-size: 1rem;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; margin: 1rem 0; color: var(--ink);
}
.code-box {
  font: 600 1.25rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .08em; background: #fff; border: 1px dashed var(--ink-faint);
  border-radius: var(--radius); padding: .8rem; margin: .6rem 0 1rem;
  user-select: all; word-break: break-all;
}
.notice { background: var(--paper-warm); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.notice.small { padding: .7rem .85rem; font-size: .88rem; color: var(--ink-soft); }

/* --- consent --------------------------------------------------------------- */

.consent-body p { margin: 0 0 .9rem; }
.consent-body strong { font-weight: 600; }
.draft-note {
  font-size: .78rem; color: var(--danger); border: 1px dashed var(--danger);
  border-radius: 6px; padding: .4rem .6rem; margin: 1rem 0;
}
