/* Life Questionnaire — designed for readability by older adults:
   large type, high contrast (WCAG AA+), big touch targets (≥ 56px),
   visible focus, labels always shown, no hover-only or gesture-only controls. */

:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f2ede4;
  --ink: #1d1a16;          /* 16:1 on bg */
  --ink-soft: #4a443c;     /* 8.9:1 on bg */
  --line: #cfc6b8;
  --primary: #0b5d5e;      /* 7.4:1 with white */
  --primary-ink: #ffffff;
  --primary-soft: #e3f0ef;
  --accent: #8a4b14;       /* warm brown, 7:1 on white */
  --danger: #a4161a;
  --success: #1e6b2e;
  --focus: #ffbf47;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Lora", Georgia, serif;
  --tap: 56px;
  --maxw: 760px;
}

html { font-size: 20px; -webkit-text-size-adjust: 100%; }
html[data-text-size="normal"] { font-size: 18px; }
html[data-text-size="large"]  { font-size: 20px; }
html[data-text-size="xlarge"] { font-size: 23px; }
html[data-text-size="xxlarge"]{ font-size: 26px; }

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); line-height: 1.55;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
@media (min-width: 900px) { body { padding-bottom: 0; } }

h1, h2, h3 { font-family: var(--serif); line-height: 1.25; margin: 0 0 .5em; color: var(--ink); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; margin-top: 1.4em; }
h3 { font-size: 1.12rem; }
p { margin: 0 0 1em; }
a { color: var(--primary); text-underline-offset: 3px; text-decoration-thickness: 2px; }
img { max-width: 100%; }

:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 7px var(--ink); border-radius: 6px; }

.skip-link { position: absolute; left: -9999px; top: 8px; background: var(--ink); color: #fff; padding: 12px 16px; z-index: 100; }
.skip-link:focus { left: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.boot { max-width: var(--maxw); margin: 20vh auto; text-align: center; padding: 0 16px; }

/* ---------- Layout ---------- */
.topbar {
  background: var(--primary); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.topbar-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 16px; }
.brand { color: #fff; text-decoration: none; font-family: var(--serif); font-weight: 600; font-size: 1.15rem; }
.brand small { display: block; font-family: var(--font); font-weight: 400; font-size: .8rem; opacity: .92; }
.topnav { margin-left: auto; display: none; gap: 4px; }
.topnav a { color: #fff; text-decoration: none; padding: 10px 16px; border-radius: 10px; font-weight: 700; }
.topnav a[aria-current="page"] { background: rgba(255,255,255,.2); }
@media (min-width: 900px) { .topnav { display: flex; } }

main:focus { outline: none; box-shadow: none; }
main { max-width: var(--maxw); margin: 0 auto; padding: 20px 16px 40px; }
main.wide { max-width: 1100px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 2px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 72px; text-decoration: none; color: var(--ink-soft); font-size: .8rem; font-weight: 700;
}
.bottomnav a svg { width: 28px; height: 28px; }
.bottomnav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }
@media (min-width: 900px) { .bottomnav { display: none; } }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.hero { border: 2px solid var(--primary); }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .78rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); padding: 12px 22px; border-radius: 12px;
  font: inherit; font-weight: 700; font-size: 1rem; line-height: 1.2;
  border: 2px solid var(--primary); background: var(--primary); color: var(--primary-ink);
  cursor: pointer; text-decoration: none; text-align: center;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--primary); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--primary); text-decoration: underline; padding-left: 8px; padding-right: 8px; }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 68px; font-size: 1.1rem; }
.btn svg { width: 1.3em; height: 1.3em; flex: none; }
.btn.recording { background: var(--danger); border-color: var(--danger); color: #fff; }

.field { margin-bottom: 18px; }
.field label, .field legend, .label { display: block; font-weight: 700; margin-bottom: 6px; }
.field .hint { display: block; color: var(--ink-soft); font-size: .88rem; margin: -2px 0 8px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; font: inherit; font-size: 1rem; color: var(--ink);
  min-height: var(--tap); padding: 12px 14px;
  border: 2px solid #8b8274; border-radius: 10px; background: #fff;
}
textarea { min-height: 220px; line-height: 1.6; resize: vertical; }
textarea.answer { min-height: 300px; font-size: 1.05rem; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
fieldset { border: 0; padding: 0; margin: 0 0 18px; }

.check { display: flex; gap: 14px; align-items: flex-start; min-height: var(--tap); padding: 12px 0; cursor: pointer; }
.check input { width: 28px; height: 28px; flex: none; margin-top: 2px; accent-color: var(--primary); }

/* Big choice cards (radio buttons) */
.choices { display: grid; gap: 10px; }
.choices.two { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.choice span {
  display: block; padding: 16px 18px 16px 58px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  min-height: var(--tap); position: relative; font-weight: 700;
}
.choice span small { display: block; font-weight: 400; color: var(--ink-soft); }
.choice span::before {
  content: ""; position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 50%; border: 3px solid #8b8274; background: #fff;
}
.choice input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
.choice input:checked + span::before { border-color: var(--primary); background: radial-gradient(var(--primary) 0 45%, #fff 50%); }
.choice input:focus-visible + span { outline: 4px solid var(--focus); outline-offset: 2px; }
.choice input:disabled + span { opacity: .55; }

.alert { border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; border: 2px solid; }
.alert.error { border-color: var(--danger); background: #fdecec; color: #6e0e10; }
.alert.success { border-color: var(--success); background: #e8f5eb; color: #123f1b; }
.alert.info { border-color: var(--primary); background: var(--primary-soft); color: #083d3e; }

.progress { height: 16px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; background: var(--primary); }

.question-title { font-family: var(--serif); font-size: 1.6rem; line-height: 1.3; margin: 0 0 12px; }
.details { margin: 0 0 8px; padding-left: 1.2em; }
.details li { margin-bottom: 6px; }

.toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
@media (max-width: 420px) { .toolbar { grid-template-columns: 1fr; } }
.interim { font-style: italic; color: var(--ink-soft); min-height: 1.5em; }

.media-list { display: grid; gap: 12px; }
.media-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }
.media-item audio { width: 100%; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.photo-grid figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.photo-grid img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--surface-2); }
.photo-grid figcaption { padding: 8px 10px; font-size: .88rem; }

.avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem; flex: none; overflow: hidden; border: 2px solid var(--line); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 112px; height: 112px; font-size: 2rem; }

/* Family tree */
.generation { margin-bottom: 24px; }
.generation h2 { font-size: 1rem; font-family: var(--font); color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--line); padding-bottom: 6px; }
.gen-row { display: flex; flex-wrap: wrap; gap: 12px; }
.couple { display: flex; gap: 6px; align-items: stretch; padding: 6px; border-radius: 16px; background: var(--surface-2); }
.couple .join { align-self: center; color: var(--accent); font-weight: 700; }
.person-card {
  display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 10px 14px 10px 10px; min-width: 220px; min-height: 84px;
}
.person-card:hover { border-color: var(--primary); }
.person-card strong { display: block; }
.person-card .meta { font-size: .82rem; color: var(--ink-soft); }
.person-card.me { border-color: var(--primary); }

.story { border-left: 4px solid var(--primary); padding: 4px 0 4px 18px; margin: 0 0 32px; }
.story h3 { font-size: 1.2rem; }
.story .body { white-space: pre-wrap; font-size: 1.05rem; }
.chapter-heading { margin-top: 1.8em; padding-bottom: 6px; border-bottom: 2px solid var(--line); }

.q-list { list-style: none; padding: 0; margin: 0; }
.q-list li a { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 14px 4px; min-height: var(--tap); border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 700; white-space: nowrap; border: 1px solid; }
.badge.done { color: var(--success); border-color: var(--success); background: #e8f5eb; }
.badge.skip { color: var(--accent); border-color: var(--accent); background: #fbf1e6; }
.badge.todo { color: var(--ink-soft); border-color: var(--line); }
.badge.pending { color: #6b4e00; border-color: #b98b00; background: #fff6d6; }

table.simple { width: 100%; border-collapse: collapse; }
table.simple td, table.simple th { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }

details.panel { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); margin-bottom: 12px; }
details.panel > summary { cursor: pointer; padding: 14px 16px; font-weight: 700; min-height: var(--tap); list-style-position: inside; }
details.panel > div { padding: 0 16px 16px; }

.steps { color: var(--ink-soft); font-weight: 700; margin-bottom: 8px; }
.sticky-actions { position: sticky; bottom: calc(80px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); padding-top: 18px; z-index: 5; }
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 12px; z-index: 50; font-weight: 700; max-width: calc(100% - 32px); box-shadow: var(--shadow); }

@media print {
  .topbar, .bottomnav, .no-print, .skip-link { display: none !important; }
  body { background: #fff; padding: 0; font-size: 12pt; }
  main { max-width: none; padding: 0; }
  .story { break-inside: avoid-page; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
