:root {
  color-scheme: light dark;
  --bg: #faf7f2; --surface: #fff; --ink: #2a2420; --muted: #756a60; --line: #e6ded3;
  --accent: #9a4f2b; --accent-ink: #fff; --tint: #f1e6da; --danger: #b3261e;
  --family: #c0562f; --friends: #2f7d6d; --work: #3b5bb5; --animal: #8a6d1d; --object: #7a5ea8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412; --surface: #211e1b; --ink: #f0e9e1; --muted: #a79b8f; --line: #38322c;
    --accent: #e0905f; --accent-ink: #1b140f; --tint: #2e261f; --danger: #ff8a80;
    --family: #e57c55; --friends: #54b9a6; --work: #7f9bf0; --animal: #d4b04a; --object: #b79ae0;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, sans-serif; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .4em 0; }
h2 { font-size: 1.15rem; margin: 1.4em 0 .5em; }
h3 { font-size: 1rem; margin: 1.4em 0 .5em; }
.muted, .hint { color: var(--muted); font-size: .9rem; }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 1.25rem; text-decoration: none; color: var(--ink); }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); }
.top nav a.on { background: var(--tint); color: var(--ink); }
.who { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); }
.flash { margin: 0; padding: 10px 16px; background: var(--tint); }
.flash.alert { color: var(--danger); }

.btn, .seg, button.link { font: inherit; cursor: pointer; }
.btn, .seg { white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 6px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); margin-top: 24px; }
.btn.on, .seg.on { background: var(--tint); border-color: var(--accent); }
.seg { padding: 6px 12px; }
button.link { background: none; border: 0; color: var(--muted); padding: 0 8px; min-height: 40px; }
form.button_to, form.inline { display: inline; margin: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar form { display: inline; }

.timeline { display: flex; align-items: flex-end; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.decades { display: flex; gap: 2px; }
.bar { flex: none; width: 46px; display: flex; flex-direction: column; align-items: center; padding: 4px 2px; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: .8rem; border: 2px solid transparent; }
.bar .col { display: flex; align-items: flex-end; width: 100%; height: 90px; }
.bar i { display: block; width: 100%; background: var(--accent); opacity: .7; border-radius: 4px 4px 0 0; }
.bar.unsorted { width: 64px; border-right: 1px solid var(--line); border-radius: 8px 0 0 8px; }
.bar.unsorted i { background: repeating-linear-gradient(45deg, var(--muted), var(--muted) 4px, transparent 4px, transparent 8px); }
.bar.on { background: var(--tint); color: var(--ink); }
.bar.over { border-color: var(--accent); border-style: dashed; }
.bar b { font-weight: 600; }
.bar small { font-size: .8rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.card { position: relative; display: block; aspect-ratio: 1; overflow: hidden; border-radius: 10px; background: var(--line); color: #fff; text-decoration: none; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .meta { position: absolute; inset: auto 0 0 0; padding: 18px 8px 6px; font-size: .78rem; line-height: 1.25; background: linear-gradient(transparent, rgba(0, 0, 0, .7)); }
.card .meta span { display: block; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.dragging { opacity: .4; }

.photo-page { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.photo-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; position: sticky; top: 8px; }
.pager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pager .spacer { flex: 1; }
.btn.off { opacity: .4; }
.related h2 { margin: 6px 0; font-size: 1.05rem; }
.related .strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.rel { flex: none; width: 104px; text-decoration: none; color: var(--ink); font-size: .78rem; line-height: 1.25; }
.rel img { width: 104px; height: 84px; object-fit: cover; border-radius: 8px; display: block; }
.rel span { display: block; margin-top: 2px; }
.rel b { display: block; }
.filmstrip { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 8px 16px; background: var(--bg); border-top: 1px solid var(--line); }
.filmstrip .era { flex: none; margin-left: 8px; padding-left: 10px; border-left: 2px solid var(--line); font-size: .75rem; font-weight: 600; color: var(--muted); }
.filmstrip .era:first-child { margin-left: 0; }
.filmstrip .frame { flex: none; display: block; border-radius: 6px; line-height: 0; }
.filmstrip img { width: 68px; height: 52px; object-fit: cover; border-radius: 6px; opacity: .7; }
.filmstrip .frame:hover img, .filmstrip .frame[aria-current] img { opacity: 1; }
.filmstrip .frame[aria-current] { outline: 3px solid var(--accent); outline-offset: 1px; }
main:has(.filmstrip) { padding-bottom: 96px; }
body:has(.filmstrip) .savebar { bottom: 84px; }
body:has(.filmstrip) .assistant-open { bottom: 96px; }
.savebar { position: sticky; bottom: 0; padding: 10px 0; background: var(--bg); }
.savebar .btn.wide { margin-top: 0; }
.stage-slot { min-height: 52vh; }
.stage { position: relative; display: inline-block; max-width: 100%; line-height: 0; }
.stage img { max-width: 100%; max-height: 52vh; border-radius: 10px; }
.stage.tagging { cursor: crosshair; touch-action: none; }
.stage.tagging .face { pointer-events: none; }
.face { opacity: 0; transition: opacity .15s; position: absolute; border: 2px solid var(--ring, #fff); border-radius: 6px; color: transparent; font-size: .8rem; line-height: 1.2; display: flex; align-items: flex-end; justify-content: center; text-decoration: none; }
.face:hover, .face:focus, .face.on, .stage.show-all .face { opacity: 1; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 6px #000; box-shadow: 0 0 0 1px rgba(0, 0, 0, .6); }
.people-list li.hot { background: var(--tint); border-radius: 8px; }
.draft { position: absolute; border: 2px dashed #fff; box-shadow: 0 0 0 1px #000; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.tools .group { display: inline-flex; gap: 4px; align-items: center; margin: 0 8px; }
.tools .group .muted { margin-right: 6px; }

aside h2 { margin: 0 0 6px; font-size: 1.05rem; }
.block { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.block:first-child { padding-top: 0; }
.answer { margin: 0; font-weight: 600; }
.btn.wide { width: 100%; margin-top: 14px; }
.context { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; margin: 0 0 16px; }
.context dt { color: var(--muted); }
.context dd { margin: 0; }
.people-list, .chips, .tiles { list-style: none; margin: 0; padding: 0; }
.people-list li { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack label { font-size: .85rem; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row > div { flex: 1; display: flex; flex-direction: column; gap: 4px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); width: 100%; }
.dictation { display: flex; align-items: center; gap: 10px; margin-top: 6px; min-height: 40px; }
.strip { display: flex; gap: 6px; overflow-x: auto; }
.strip img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; display: block; }

.avatar { --ring: var(--muted); display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: 50%; background: var(--line) no-repeat; box-shadow: 0 0 0 3px var(--ring); color: var(--ink); font-weight: 600; }
.avatar.sm { width: 28px; height: 28px; font-size: .7rem; box-shadow: 0 0 0 2px var(--ring); }
.avatar.md { width: 44px; height: 44px; }
.avatar.lg { width: 88px; height: 88px; font-size: 1.4rem; }
.avatar.xl { width: 120px; height: 120px; font-size: 1.8rem; }
.ring-family { --ring: var(--family); }
.ring-friends { --ring: var(--friends); }
.ring-work { --ring: var(--work); }
.ring-animal { --ring: var(--animal); }
.ring-object { --ring: var(--object); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.tiles a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 8px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); text-align: center; }
.tiles small { color: var(--muted); font-size: .8rem; }
.tiles.places a { padding: 24px 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips a { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 6px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink); background: var(--surface); }
.profile { display: flex; align-items: center; gap: 20px; padding: 8px 0; }
fieldset.parents { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 4px; }
.parents label { color: var(--ink); font-size: 1rem; }
.residence-form { max-width: 420px; margin-top: 8px; }
details.edit { margin-top: 32px; max-width: 420px; }
details.edit summary { cursor: pointer; color: var(--muted); margin-bottom: 12px; }

.login { max-width: 360px; margin: 10vh auto; }
.login form { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.login label { color: var(--muted); font-size: .85rem; }

body.slideshow { background: #000; color: #fff; }
body.slideshow .top, body.slideshow .flash { display: none; }
body.slideshow main { max-width: none; padding: 0; }
.show { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
.slide { position: absolute; inset: 0; margin: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px 16px 72px; opacity: 0; visibility: hidden; transition: opacity .6s ease, visibility 0s .6s; }
.slide.on { opacity: 1; visibility: visible; transition: opacity .6s ease; }
.slide img { max-width: 100%; max-height: calc(100% - 64px); object-fit: contain; }
.slide figcaption { margin-top: 12px; text-align: center; font-size: 1.05rem; }
.controls { position: fixed; bottom: 0; left: 0; right: 0; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: center; padding: 12px; background: rgba(0, 0, 0, .6); }
.controls button, .controls .close { font: inherit; color: #fff; background: none; border: 1px solid #555; border-radius: 10px; padding: 6px 14px; min-height: 40px; text-decoration: none; cursor: pointer; display: inline-flex; align-items: center; }

@media (max-width: 800px) {
  .photo-page { grid-template-columns: minmax(0, 1fr); }
  .photo-main { position: static; }
  .who { width: 100%; justify-content: space-between; }
  .tools .group { margin: 0; }
}

.map { height: 62vh; min-height: 320px; border-radius: 12px; border: 1px solid var(--line); z-index: 0; }
.decades-row { display: inline-flex; gap: 6px; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) { .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); } }

.switch { display: flex; gap: 8px; margin-bottom: 16px; }
.tree-wrap { overflow-x: auto; padding: 8px 0 24px; }
.tree { --link: color-mix(in srgb, var(--ink) 28%, var(--bg)); }
.tree, .tree ul { display: flex; justify-content: center; list-style: none; margin: 0; padding: 20px 0 0; position: relative; }
.tree { width: max-content; min-width: 100%; padding-top: 0; margin-bottom: 28px; }
.tree li { display: flex; flex-direction: column; align-items: center; padding: 20px 8px 0; position: relative; }
.tree li::before, .tree li::after { content: ""; position: absolute; top: 0; width: 50%; height: 20px; border-top: 2px solid var(--link); }
.tree li::before { right: 50%; }
.tree li::after { left: 50%; border-left: 2px solid var(--link); }
.tree li:only-child::before, .tree li:only-child::after { border-top: 0; }
.tree li:only-child::after { border-left: 2px solid var(--link); }
.tree li:first-child::before, .tree li:last-child::after { border-top: 0; }
.tree li:last-child::before { border-right: 2px solid var(--link); border-radius: 0 8px 0 0; }
.tree li:first-child::after { border-radius: 8px 0 0 0; }
.tree li:last-child::after { border-left: 0; }
.tree li:only-child::before { border: 0; }
.tree li:only-child::after { border-radius: 0; border-left: 2px solid var(--link); }
.tree > li { padding-top: 0; }
.tree > li::before, .tree > li::after { display: none; }
.tree ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 20px; border-left: 2px solid var(--link); }
.couple { display: flex; gap: 8px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.tree-card { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 104px; padding: 6px 4px; text-align: center; text-decoration: none; color: var(--ink); border-radius: 10px; }
.tree-card:hover { background: var(--tint); }
.tree-card b { font-size: .9rem; line-height: 1.15; }
.tree-card small { color: var(--muted); font-size: .78rem; }

.clues { margin: 12px 0; }
.clues summary { cursor: pointer; font-weight: 600; }
.clues h3 { margin: 10px 0 2px; font-size: .95rem; }
.clues ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: .9rem; }

.hint:empty { display: none; }
.row > input, .row > select { flex: 1; min-width: 0; }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { background: var(--tint); border-color: var(--accent); }
.menu .panel { position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; display: flex; flex-direction: column; gap: 10px; min-width: 280px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / .14); }
.menu .group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.clues a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

.card .unseen { position: absolute; top: 8px; right: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px #fff; }

.prose { max-width: 68ch; line-height: 1.55; }
.prose h2 { margin-top: 28px; }
.prose li { margin-bottom: 6px; }

.assistant-open { position: fixed; left: 16px; bottom: 16px; z-index: 20; box-shadow: 0 4px 16px rgb(0 0 0 / .2); }
.assistant { position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: min(440px, 100vw); display: flex; flex-direction: column; background: var(--bg); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgb(0 0 0 / .12); }
.assistant[hidden] { display: none; }
.assistant turbo-frame, .assistant-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.assistant-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.assistant-head span { display: flex; gap: 12px; align-items: center; }
.assistant-log { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 8px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.msg.mine { align-self: flex-end; background: var(--tint); }
.msg p { margin: 0 0 6px; }
.suggest { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.assistant-form { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.assistant-form textarea { width: 100%; resize: none; }
.suggest .seg, .msg .chips .btn { white-space: normal; text-align: left; height: auto; }
.msg .chips { gap: 6px; }

.dive { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 8px 16px; background: var(--tint); border-bottom: 1px solid var(--line); font-size: .9rem; }
.dive[hidden] { display: none; }
.dive .step { padding: 2px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.dive .step.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.dive .link { margin-left: auto; }
.dive:not([hidden]) ~ main .photo-main { top: 64px; }

.stories { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.stories li { padding: 8px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.stories li.echo { background: transparent; border-style: dashed; color: var(--muted); }
.stories small { display: block; margin-top: 2px; }
.controls button, .controls .close { white-space: nowrap; }
.slideshow .controls .stop { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.story-box { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); z-index: 40; width: min(520px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 8px; padding: 16px; background: var(--surface); color: var(--ink); border-radius: 14px; box-shadow: 0 12px 40px rgb(0 0 0 / .45); }
.story-box[hidden] { display: none; }
.story-box textarea, .story-box select { width: 100%; }
body.slideshow .assistant-open { display: none; }
@media (max-width: 600px) { .story-box { bottom: 120px; } }

.facts { display: grid; grid-template-columns: 4.2rem minmax(0, 1fr); align-items: start; gap: 10px 12px; }
.facts h2 { margin: 0; padding-top: 11px; font-size: .95rem; color: var(--muted); font-weight: 600; }
.facts .row { gap: 6px; }
.facts .row > input { min-width: 0; }
.facts .tools { margin-top: 6px; }
.facts .people-list { margin-bottom: 6px; }
.facts .people-list li { margin-bottom: 2px; }
.add-person { display: flex; gap: 6px; }
.add-person input[type=text] { flex: 1 1 0; width: auto; min-width: 0; }
.add-person select { flex: none; width: auto; max-width: 6.5rem; }
.add-person .btn { flex: none; width: auto; min-width: 44px; padding: 6px 12px; }
.facts .hint { margin: 4px 0 0; }
.story { position: relative; }
.story textarea { padding-right: 44px; }
.story .mic { position: absolute; top: 6px; right: 6px; min-height: 32px; padding: 2px 8px; }
.story .muted { display: block; font-size: .8rem; }
.story .muted:empty { display: none; }
@media (max-width: 480px) { .facts { grid-template-columns: minmax(0, 1fr); gap: 2px; } .facts h2 { margin-top: 8px; padding-top: 0; } }
.stage:not(.tagging) img { cursor: zoom-in; }

turbo-frame#photo { transition: opacity .18s ease; }
turbo-frame#photo.fading { opacity: 0; }
@media (prefers-reduced-motion: reduce) { turbo-frame#photo, .slide, .slide.on { transition: none; } }
