/* ══════════════════════════════════════════════
   dougdevitre.org — the homepage app
   A lighthouse over a harbor: fog by day, harbor ink by night, one lamp.
   Mobile first. Every touch target is at least 48px; primary ones 56px+.
   Contrast ratios are measured against --bg (WCAG 2.2 AA).
   ══════════════════════════════════════════════ */

:root {
  --bg: #EEF2F4;          /* morning fog */
  --surface: #FFFFFF;
  --ink: #13212F;         /* 14.9:1 on --bg */
  --muted: #4A5865;       /* 6.6:1 on --bg */
  --line: #C6D1D9;
  --lamp: #F2B43A;        /* the beacon; fills and glows, never small text */
  --lamp-ink: #7A4E00;    /* lamp as text on light: 6.9:1 on --bg */
  --on-lamp: #13212F;     /* text on a lamp fill: 9.1:1 */
  --shade: 0 1px 0 rgba(19, 33, 47, 0.06), 0 8px 24px -16px rgba(19, 33, 47, 0.35);
  --serif: 'DM Serif Display', Georgia, serif;
  --sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --gutter: 16px;
  --tap: 56px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0F1E2E;          /* harbor ink */
  --surface: #172B3E;
  --ink: #EAF0F4;         /* 14.2:1 on --bg */
  --muted: #A9B8C4;       /* 8.0:1 on --bg */
  --line: #2B4359;
  --lamp-ink: #F2B43A;    /* 9.0:1 on --bg */
  --shade: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 30px -18px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }   /* component display rules must not unhide */
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1.0625rem/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  overflow-wrap: break-word;   /* at 200% text a long word wraps instead of widening the page */
}
img, svg { display: block; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 400; line-height: 1.15; margin: 0; }
h2 { font-size: clamp(1.75rem, 6vw, 2.4rem); }
h3 { font-size: 1.3rem; }
p { margin: 0; }

:focus-visible { outline: 3px solid var(--lamp); outline-offset: 3px; border-radius: 8px; }

.skip-link {
  position: absolute; left: var(--gutter); top: -100px; z-index: 50;
  background: var(--lamp); color: var(--on-lamp); padding: 12px 18px; border-radius: 12px;
  font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ── Top bar ── */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar-name { display: grid; text-decoration: none; min-height: 44px; align-content: center; }
.bar-person { font-family: var(--serif); font-size: 1.2rem; line-height: 1.1; }
.bar-role { font-size: 0.8rem; color: var(--muted); }
.bar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 48px; height: 48px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--ink); cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#sound-toggle .i-off, #sound-toggle[aria-pressed="false"] .i-on { display: none; }
#sound-toggle[aria-pressed="false"] .i-off { display: block; }

main { max-width: 760px; margin: 0 auto; padding: 0 var(--gutter); }
section { padding: 40px 0; }
section + section { border-top: 1px solid var(--line); }
.section-lead { color: var(--muted); margin: 8px 0 20px; max-width: 60ch; }

/* ── The lamp (hero) ── */
.lamp { position: relative; padding-top: 44px; isolation: isolate; overflow-x: clip; }   /* the beam must not widen the page */
.lamp h1 { font-size: clamp(2.4rem, 10vw, 3.6rem); max-width: 14ch; letter-spacing: -0.01em; }
.lamp-lead { margin: 16px 0 24px; max-width: 46ch; font-size: 1.125rem; }
.beam {
  position: absolute; z-index: -1; pointer-events: none;
  top: -40px; right: -60px; width: 420px; height: 420px;
  background: conic-gradient(from 200deg at 85% 15%, transparent 0deg, color-mix(in srgb, var(--lamp) 34%, transparent) 14deg, transparent 30deg);
  opacity: 0.35; transform-origin: 85% 15%;
}
.lit .beam { animation: sweep 2.6s cubic-bezier(.45,.05,.3,1) 1; opacity: 0.9; }
@keyframes sweep { from { transform: rotate(-30deg); } to { transform: rotate(60deg); opacity: 0.35; } }

.lamp-actions { display: grid; gap: 12px; }
.big-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  min-height: var(--tap); padding: 14px 24px; border-radius: 16px;
  border: 2px solid var(--lamp); background: var(--lamp); color: var(--on-lamp);
  font: 700 1.0625rem/1.2 var(--sans); text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
.big-btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.big-btn:active, .door:active, .chip:active, .gate:active { transform: scale(0.98); }
.play-glyph {
  width: 0; height: 0; border-style: solid;
  border-width: 9px 0 9px 15px; border-color: transparent transparent transparent currentColor;
}
[data-playing="true"] .play-glyph { width: 14px; height: 18px; border: 0; border-left: 5px solid currentColor; border-right: 5px solid currentColor; }
.listen-btn {
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 18px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 500 1rem var(--sans); cursor: pointer; margin-bottom: 16px;
}
.listen-btn .play-glyph { border-width: 7px 0 7px 11px; }

.transcript { margin-top: 16px; color: var(--muted); }
.transcript summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.transcript p { margin-top: 8px; max-width: 60ch; }

/* ── Doors (the table of contents) ── */
.door-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.door {
  --c: #5A8AAB;
  position: relative; display: grid; justify-items: center; align-content: start; gap: 8px;
  min-height: 150px; padding: 22px 10px 16px; text-align: center; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px 999px 18px 18px / 70px 70px 18px 18px;   /* an arched door */
  box-shadow: var(--shade); overflow: hidden; touch-action: manipulation;
  transition: border-color .2s, box-shadow .2s;
}
.door::before {  /* the lit window */
  content: ""; position: absolute; inset: 0 0 auto; height: 58%;
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--c) 30%, transparent), transparent 70%);
  pointer-events: none;
}
.door-icon { position: relative; width: 52px; height: 52px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; }
.door-icon svg { width: 26px; height: 26px; }
.door-name { position: relative; font-family: var(--serif); font-size: 1.12rem; line-height: 1.15; }
.door-status { position: relative; font-size: 0.85rem; color: var(--muted); }
.door:hover { border-color: var(--c); }
.door.caught { box-shadow: 0 0 0 2px var(--lamp), var(--shade); }

/* ── Find my door ── */
.finder-start { width: 100%; }
.finder-flow { padding: 20px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shade); }
.finder-progress { display: flex; gap: 6px; margin-bottom: 16px; }
.finder-progress span { flex: 1; height: 6px; border-radius: 999px; background: var(--line); transition: background-color .3s; }
.finder-progress span.on { background: var(--lamp); }
.finder-q { font-family: var(--serif); font-size: 1.6rem; line-height: 1.2; margin-bottom: 16px; }
.finder-q:focus { outline: none; }
.finder-options { display: grid; gap: 10px; }
.finder-option {
  min-height: var(--tap); padding: 14px 18px; border-radius: 16px; text-align: left;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: 500 1.0625rem/1.3 var(--sans); cursor: pointer; touch-action: manipulation;
}
.finder-option:active { transform: scale(0.98); }
.finder-option[aria-pressed="true"] { border-color: var(--lamp); box-shadow: inset 0 0 0 2px var(--lamp); }
.finder-back {
  margin-top: 14px; min-height: 44px; padding: 8px 4px; border: 0; background: none; color: var(--muted);
  font: 500 1rem var(--sans); text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.finder-result h3:focus { outline: none; }
.crisis {
  margin-bottom: 18px; padding: 16px 18px; border-radius: 16px; font-weight: 500;
  background: color-mix(in srgb, #C2410C 14%, var(--surface)); border: 2px solid #C2410C;
}
.match-list { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 10px; }
.match {
  --c: #5A8AAB;
  width: 100%; display: grid; grid-template-columns: 52px 1fr; gap: 14px; align-items: center;
  min-height: 84px; padding: 14px; border-radius: 20px; text-align: left; cursor: pointer;
  background: color-mix(in srgb, var(--c) 12%, var(--surface)); color: var(--ink);
  border: 2px solid var(--c); font: inherit; touch-action: manipulation;
}
.match:active { transform: scale(0.98); }
.match-text { display: grid; gap: 2px; }
.match-name { font-family: var(--serif); font-size: 1.25rem; line-height: 1.15; }
.match-why { color: var(--muted); font-size: 0.95rem; }
.match-flag { font-size: 0.85rem; font-weight: 700; color: var(--lamp-ink); }
.door.match-lit { border-color: var(--lamp); box-shadow: 0 0 0 3px var(--lamp), 0 0 28px -6px var(--lamp); }

/* ── Practice builder ── */
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 28px; counter-reset: step; }
.step { counter-increment: step; position: relative; padding-left: 52px; }
.step::before {
  content: counter(step); position: absolute; left: 0; top: -4px;
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--lamp); font-family: var(--serif); font-size: 1.2rem;
}
.step.done::before { background: var(--lamp); color: var(--on-lamp); }
.step h3 { margin-bottom: 12px; }
.step-note { color: var(--muted); margin-top: 10px; }
.step-note strong { color: var(--ink); }
.chip-row { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  --c: var(--lamp);
  min-height: 48px; padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 500 1rem var(--sans); cursor: pointer; touch-action: manipulation;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip[data-door] { border-left: 6px solid var(--c); }
.gate-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.gate {
  min-height: 72px; padding: 12px; border-radius: 16px; text-align: left;
  border: 2px dashed var(--line); background: transparent; color: var(--ink);
  font: 500 1rem/1.3 var(--sans); cursor: pointer; touch-action: manipulation;
}
.gate[aria-pressed="true"] { border-style: solid; border-color: var(--lamp); background: color-mix(in srgb, var(--lamp) 18%, var(--surface)); }
.gate[aria-pressed="true"]::before { content: "\2713\00a0"; color: var(--lamp-ink); font-weight: 700; }
.my-step {
  margin-top: 28px; padding: 22px; border-radius: 20px;
  background: var(--surface); border: 2px solid var(--lamp); box-shadow: var(--shade);
}
.my-step-text { font-family: var(--serif); font-size: 1.35rem; line-height: 1.35; margin: 10px 0 18px; }
.my-step-actions { display: grid; gap: 10px; }

/* ── BEACON ── */
.beacon-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.beacon-item button {
  width: 100%; min-height: 64px; display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: 12px;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
  color: var(--ink); font: 500 1.05rem var(--sans); text-align: left; cursor: pointer;
}
.beacon-letter { font-family: var(--serif); font-size: 2rem; color: var(--lamp-ink); text-align: center; }
.beacon-item p { padding: 10px 14px 4px 74px; color: var(--muted); }
.beacon-item p[hidden] { display: none; }

/* ── Work + notice ── */
.work p { max-width: 60ch; margin: 12px 0 20px; }
.notice { color: var(--muted); }
.notice h2 { font-size: 1.4rem; color: var(--ink); }
.notice p { margin: 10px 0; max-width: 62ch; }
.notice ul { padding-left: 20px; margin: 0; display: grid; gap: 6px; }
.notice strong { color: var(--ink); }

/* ── Detail sheet ── */
.sheet {
  --c: #5A8AAB;
  border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 90vh; max-height: 90dvh;
  border-radius: 24px 24px 0 0; background: var(--surface); color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0,0,0,.35);
}
.sheet::backdrop { background: rgba(10, 18, 28, 0.55); }
.sheet[open] { animation: rise .32s cubic-bezier(.2,.8,.2,1); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet-inner { padding: 0 var(--gutter) calc(24px + env(safe-area-inset-bottom)); }
.sheet-head {
  position: sticky; top: 0; z-index: 1; margin: 0 calc(var(--gutter) * -1) 16px;
  display: grid; grid-template-columns: 52px 1fr 48px; gap: 12px; align-items: center;
  padding: 18px var(--gutter);
  background: color-mix(in srgb, var(--c) 26%, var(--surface));
  transition: background-color .6s ease;     /* the blend between doors */
}
.sheet-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; transition: background-color .6s ease; }
.sheet-icon svg { width: 26px; height: 26px; }
.sheet-head h2 { font-size: 1.6rem; }
.sheet-meta { color: var(--muted); font-size: 0.95rem; }
.sheet-close { background: var(--surface); }
.sheet-listen { width: 100%; }
.sheet-desc { margin: 16px 0; font-size: 1.1rem; }
.sheet-facts { display: grid; gap: 12px; margin: 0 0 20px; }
.sheet-facts div { padding: 14px; border-radius: 14px; background: color-mix(in srgb, var(--c) 10%, var(--surface)); }
.sheet-facts dt { font-weight: 700; }
.sheet-facts dd { margin: 4px 0 0; color: var(--muted); }
.sheet-sub { margin: 20px 0 10px; }
.sheet-beacon { padding-left: 0; list-style: none; display: grid; gap: 8px; margin: 0; }
.sheet-beacon li { display: grid; grid-template-columns: 32px 1fr; gap: 8px; }
.sheet-beacon b { font-family: var(--serif); font-weight: 400; font-size: 1.4rem; color: var(--lamp-ink); line-height: 1.2; }
.sheet-beacon span { color: var(--muted); }
.sheet-beacon strong { color: var(--ink); font-weight: 500; }
.sheet-links { display: grid; gap: 10px; margin: 24px 0 12px; }
.sheet-fine { color: var(--muted); font-size: 0.9rem; }

/* ── Footer + back to top ── */
.foot { max-width: 760px; margin: 0 auto; padding: 32px var(--gutter) 96px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.95rem; }
.foot nav { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-bottom: 12px; }
.foot nav a { min-height: 44px; display: inline-flex; align-items: center; }
.back-to-top {
  position: fixed; right: var(--gutter); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 15;
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); display: grid; place-items: center; cursor: pointer;
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .2s, visibility .2s;
}
.back-to-top.show { opacity: 1; visibility: visible; pointer-events: auto; }   /* hidden = out of the tab order too */
.back-to-top svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Larger screens ── */
@media (min-width: 640px) {
  .door-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lamp-actions, .my-step-actions { grid-auto-flow: column; justify-content: start; }
  .gate-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .finder-start { width: auto; }
  .finder-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet { margin: auto; max-width: 560px; border-radius: 24px; }
}
@media (min-width: 960px) {
  main, .foot { max-width: 960px; }
  .door-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ── Reduced motion: no sweep, no rise, no smooth scroll ── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .lit .beam, .sheet[open] { animation: none; }
  .sheet-head, .sheet-icon { transition: none; }
}
