/* Warm: a thoughtful, inviting self-assessment. Tokens first — colours, type,
   radii and rhythm live here and nowhere else, so the look can change again in
   one place. The shell's slot must survive every redesign: keep clear of the
   corner with var(--shell-slot), never a fixed 80px. */
:root {
  --shell-switcher-size: 48px;
  --shell-switcher-inset: 16px;
  --shell-switcher-gap: 16px;
  --shell-slot: 80px; /* inset + size + gap: the corner the shell owns */

  --paper: #f6efe2;
  --cream: #fbf6ec;
  --brown: #6e4a28;
  --brown-deep: #5a3b1f;
  --olive: #5d5b33;
  --olive-soft: #8a8455;
  --ink: #2b2620;
  --muted: #6e6459;
  --cream-ink: #fff9ef;
  --rule: rgba(110, 74, 40, 0.22);
  --rule-soft: rgba(110, 74, 40, 0.13);
  --wash: rgba(110, 74, 40, 0.08);

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", "Segoe UI", Tahoma, sans-serif;

  --blob: 58% 42% 55% 45% / 48% 60% 40% 52%;
  --pill: 999px;
  --card: 10px;
  --chip: 4px;
  --gap: 12px;
  color-scheme: light dark;
}
/* The same page in a phone set to dark. --paper here is the dark theme-color
   tag in index.html, as --paper above is the light one: change them together. */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #2b2620;
    --cream: #38312a;
    --brown: #d8c49a;
    --brown-deep: #f0dfbe;
    --olive: #b9b47e;
    --olive-soft: #8a8455;
    --ink: #f6efe2;
    --muted: #b3a898;
    --cream-ink: #2b2620;
    --rule: rgba(246, 239, 226, 0.25);
    --rule-soft: rgba(246, 239, 226, 0.14);
    --wash: rgba(246, 239, 226, 0.07);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--sans); }
body { min-height: 100dvh; }

/* Phone first; a wide window gets a real layout below, never a narrow strip. */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding-top: 8px;
  padding-right: calc(20px + max(var(--shell-safe-right, 0px), env(safe-area-inset-right, 0px)));
  padding-bottom: calc(max(var(--shell-safe-bottom, 0px), env(safe-area-inset-bottom, 0px)) + var(--shell-slot));
  padding-left: calc(20px + max(var(--shell-safe-left, 0px), env(safe-area-inset-left, 0px)));
}

/* The app's bar: the width of the window, in the flow of the page. */
.top-bar {
  position: sticky; top: 0; z-index: 2; background: var(--paper);
  display: flex; align-items: flex-start; gap: var(--gap);
  margin: 0; padding-bottom: 8px;
  padding-top: calc(24px + max(var(--shell-safe-top, 0px), env(safe-area-inset-top, 0px)));
  padding-right: calc(20px + max(var(--shell-safe-right, 0px), env(safe-area-inset-right, 0px)));
  padding-left: calc(20px + max(var(--shell-safe-left, 0px), env(safe-area-inset-left, 0px)));
}
.top-bar .page-heading { flex: 1; min-width: 0; margin: 0; }
@media (min-width: 760px) {
  .top-bar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 600px) minmax(0, 1fr); gap: 0; }
  .top-bar .page-heading { grid-column: 2; }
  .top-bar .top-actions { grid-column: 3; justify-self: end; }
}
.page-heading { font-family: var(--serif); font-size: 1.6rem; font-weight: 500; letter-spacing: -0.01em; margin: 0 0 8px; }

/* The note trigger: the app's own control, in the app's own colours. */
.note-trigger {
  appearance: none; flex: none;
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--rule-soft); border-radius: var(--card);
  background: var(--cream); color: var(--brown);
}
.top-actions { display: flex; flex: none; align-items: center; gap: 8px; }
.install-app {
  appearance: none; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--rule-soft); border-radius: var(--card);
  background: var(--cream); color: var(--brown-deep); font: inherit; font-weight: 600;
}
.install-app:focus-visible,
.note-trigger:focus-visible { outline: 2px solid var(--brown); outline-offset: 2px; }
.quiet { color: var(--muted); margin: 0; }
.faint { color: var(--muted); }
.serif { font-family: var(--serif); }

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

/* ---------- masthead ---------- */
.masthead { position: relative; margin: 12px 0 24px; }
.masthead.slim { margin-bottom: 16px; }
.blob {
  position: absolute; top: -14px; right: -18px; width: 150px; height: 132px;
  background: var(--olive); opacity: 0.12;
  border-radius: var(--blob);
  pointer-events: none;
}
.kick {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--brown);
  margin: 0 0 4px;
}
.kick::before { content: ""; width: 26px; height: 1px; background: var(--rule); flex: none; }
.kick::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.mast-title { font-size: 2rem; font-weight: 500; line-height: 1.15; letter-spacing: -0.01em; margin: 14px 0 0; }
.mast-title.small { font-size: 1.6rem; }
.greeting { font-family: var(--serif); font-style: italic; font-size: 1.2rem; color: var(--brown); margin: 8px 0 0; }
.intro { font-size: 0.95rem; line-height: 1.55; color: var(--muted); margin: 12px 0 0; max-width: 46ch; }
.notice {
  background: var(--wash); border: 1px solid var(--rule-soft);
  border-radius: var(--card); padding: 12px 16px; margin: 16px 0 20px;
}

/* ---------- buttons ---------- */
.actions { display: flex; flex-wrap: wrap; gap: var(--gap); margin-top: 16px; }
.actions.wrap .btn { flex: 1 1 auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 0.95rem; font-weight: 600; letter-spacing: 0.01em;
  min-height: 44px; padding: 11px 20px; border-radius: var(--pill); cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--brown); color: var(--cream-ink); }
.btn-quiet { background: transparent; color: var(--brown-deep); border-color: var(--rule); }
.btn:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; }

/* ---------- sheets, labels, quotes ---------- */
.label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--brown);
  margin: 0 0 12px;
}
.sheet {
  background: var(--cream);
  border: 1px solid var(--rule-soft);
  border-radius: var(--card);
  box-shadow: 0 6px 18px rgba(90, 66, 38, 0.08);
  padding: 22px;
  margin-bottom: 28px;
}
.sheet-line { margin: 0 0 10px; }
.how { margin: 0 2px 20px; }
.quote { border-left: 2px solid var(--brown); padding: 2px 0 2px 16px; margin: 0 4px 32px; }
.quote p { font-family: var(--serif); font-style: italic; font-size: 1.15rem; line-height: 1.5; margin: 0; }
.quote cite { display: block; font-style: normal; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--brown); margin-top: 8px; font-weight: 600; }

/* ---------- progress ---------- */
.progress { position: relative; background: var(--wash); border-radius: var(--pill); height: 26px; margin: 12px 0 20px; overflow: hidden; }
.progress-fill { position: absolute; inset: 0 auto 0 0; background: var(--olive); border-radius: var(--pill); transition: width 0.25s ease; }
.progress-cap { position: relative; display: block; text-align: center; font-size: 12.5px; font-weight: 600; line-height: 26px; color: var(--ink); }

/* ---------- questions ---------- */
.questions { display: grid; gap: 16px; margin-bottom: 8px; }
.q {
  background: var(--cream); border: 1px solid var(--rule-soft);
  border-radius: var(--card); padding: 18px; margin: 0;
  box-shadow: 0 6px 18px rgba(90, 66, 38, 0.06);
}
.q.is-missing { border-color: var(--brown); }
.q legend { padding: 0; margin-bottom: 12px; }
.q-num { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--brown); margin-bottom: 6px; }
.q-text { display: block; font-family: var(--serif); font-size: 1.15rem; line-height: 1.4; }
.q-error { color: var(--brown-deep); font-weight: 600; margin: 10px 0 0; }
.scale { display: grid; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--rule-soft); border-radius: var(--chip);
  cursor: pointer; background: transparent;
}
.choice:has(input:checked) { border-color: var(--brown); background: var(--wash); }
.choice:has(input:focus-visible) { outline: 2px solid var(--olive); outline-offset: 2px; }
.choice input { width: 20px; height: 20px; accent-color: var(--brown); flex: none; }
.choice-num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--wash); color: var(--brown-deep); font-weight: 600;
}
.choice:has(input:checked) .choice-num { background: var(--brown); color: var(--cream-ink); }
.choice-label { font-weight: 500; }
.choice-short { display: none; }

.pager { display: flex; flex-wrap: wrap; gap: var(--gap); margin: 20px 0 32px; }
.pager .btn { flex: 1 1 160px; }
.missing {
  border: 1px solid var(--rule); border-radius: var(--card);
  background: var(--cream); padding: 14px 16px; margin: 16px 0;
}
.missing p { margin: 0 0 8px; }
.missing-link {
  appearance: none; margin: 0 8px 8px 0; padding: 8px 14px; min-height: 44px;
  border-radius: var(--pill); border: 1px solid var(--rule);
  background: transparent; color: var(--brown-deep); font-weight: 600; cursor: pointer;
}

/* ---------- results ---------- */
.overall-num { font-size: 2.2rem; font-weight: 500; margin: 2px 0 4px; }
.result-columns { display: grid; gap: 20px; margin-bottom: 8px; }
.group-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.group-title { font-size: 1.35rem; font-weight: 500; margin: 0; }
.group-score { font-family: var(--serif); font-size: 1.5rem; color: var(--brown); margin: 0; white-space: nowrap; }
.meter { display: flex; gap: 6px; margin: 12px 0 6px; }
.pip { flex: 1; height: 8px; border-radius: var(--chip); background: var(--wash); }
.pip.on { background: var(--olive); }
.copies { list-style: none; margin: 14px 0 0; padding: 0; }
.copy-line {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 12px 2px; border-top: 1px solid var(--rule-soft);
}
.copy-text { font-size: 0.95rem; }
.copy-answer { font-size: 0.85rem; font-weight: 600; color: var(--brown); }
.copy-one {
  grid-column: 2; grid-row: 1 / span 2; align-self: center;
  appearance: none; min-height: 44px; padding: 8px 14px;
  border-radius: var(--pill); border: 1px solid var(--rule);
  background: transparent; color: var(--brown-deep); font-weight: 600; cursor: pointer;
}

/* ---------- past runs ---------- */
.past-run {
  appearance: none; width: 100%; text-align: left; cursor: pointer;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 13px 2px; border: 0; border-bottom: 1px solid var(--rule-soft);
  background: transparent; color: var(--ink);
}
.past-run:first-of-type { border-top: 1px solid var(--rule-soft); }
.past-date { font-weight: 600; }
.past-score { color: var(--brown); font-weight: 600; white-space: nowrap; }

/* Messages that are not the page: keep out of the shell's corner. */
#toast {
  position: fixed; left: 16px; right: var(--shell-slot);
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--shell-switcher-inset));
  pointer-events: none; z-index: 5;
}
#toast:empty { display: none; }
#toast > * { background: var(--ink); color: var(--paper); border-radius: var(--card); padding: 12px 16px; }

/* A wide window is a layout, not a strip: the reading column stays where the
   heading keeps to it, while the assessment and the results use the room —
   questions and group scores side by side where that reads better. */
@media (min-width: 900px) {
  body[data-route="assess"] .page,
  body[data-route="results"] .page { max-width: 1100px; }
  body[data-route="assess"] .top-bar,
  body[data-route="results"] .top-bar { grid-template-columns: minmax(0, 1fr) minmax(0, 1060px) minmax(0, 1fr); }
  body[data-route="assess"] .masthead,
  body[data-route="results"] .masthead { max-width: 640px; }
  .questions { grid-template-columns: 1fr 1fr; align-items: start; }
  .result-columns { grid-template-columns: 1fr 1fr; align-items: start; }
  .result-group:first-child { grid-column: 1 / -1; }
  .overall { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px 28px; align-items: center; }
  .overall .label { grid-column: 1 / -1; }
}
