:root {
  /* Walnut: warm paper and ink by day, walnut brown by night, with teal for actions and amber for recording. */
  --bg: #F5F0E8; --surface: #FFFDF9; --sunk: #EAE3D8; --fg: #2A221C; --muted: #6E6256;
  --line: #D6CCBE; --accent: #1F6E67; --link: #1F6E67; --accent-soft: #DCEBE7; --record: #B07418; --on-accent: #FFFFFF; --danger: #A23B2E;
  --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
/* Dark follows the phone's setting, unless Settings chose light or dark for this app. */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #191512; --surface: #231E1A; --sunk: #2D2721; --fg: #EFE7DD; --muted: #B0A496;
  --line: #3C352E; --accent: #2F7F78; --link: #86C6BE; --accent-soft: #26332F; --record: #C88A2E; --on-accent: #FFFFFF; --danger: #E8907E; color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #191512; --surface: #231E1A; --sunk: #2D2721; --fg: #EFE7DD; --muted: #B0A496;
  --line: #3C352E; --accent: #2F7F78; --link: #86C6BE; --accent-soft: #26332F; --record: #C88A2E; --on-accent: #FFFFFF; --danger: #E8907E; color-scheme: dark }
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 18px/1.5 var(--font); -webkit-text-size-adjust: 100%; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(18px + env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) 28px max(18px, env(safe-area-inset-left, 0px)); }
.page { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; min-height: 100%; }
h1 { font-size: 1.65rem; line-height: 1.25; margin: 0; text-wrap: balance; }
h2 { font-size: 1.2rem; margin: 0; }
p { margin: 0; }
a { color: var(--link); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }

nav#tabs { display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
nav#tabs a { flex: 1; text-align: center; padding: 14px 4px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .95rem; position: relative; }
nav#tabs a.on { color: var(--link); box-shadow: inset 0 3px 0 var(--link); }
#family-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--record); margin-left: 5px; }

button, .btn { font: inherit; font-weight: 700; border: 0; border-radius: 14px; padding: 14px 18px; background: var(--accent); color: var(--on-accent);
  cursor: pointer; text-align: center; text-decoration: none; display: block; width: 100%; min-height: 52px; }
button.ghost, .btn.ghost { background: none; border: 2px solid var(--link); color: var(--link); }
button.quiet { background: var(--sunk); color: var(--fg); }
button.danger { background: none; border: 2px solid var(--danger); color: var(--danger); }
button.link { background: none; color: var(--link); width: auto; min-height: 44px; padding: 8px 6px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
button.inline { width: auto; min-height: 44px; padding: 8px 16px; }
button:disabled { opacity: .5; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--record); outline-offset: 2px; }
a.link-a { color: var(--link); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; padding: 8px 6px; min-height: 44px; display: inline-flex; align-items: center; }
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; }

input, textarea, select { font: inherit; color: var(--fg); background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; }
textarea { min-height: 130px; resize: vertical; }
label { font-weight: 600; display: flex; flex-direction: column; gap: 6px; }
label.check { flex-direction: row; align-items: center; gap: 12px; font-weight: 500; padding: 10px 0; }
label.check input { width: 26px; height: 26px; flex: none; accent-color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card.soft { background: var(--sunk); border: 0; }
.card.warn { border-color: var(--record); }
.chip { display: inline-block; padding: 4px 12px; border-radius: 99px; background: var(--accent-soft); font-size: .88rem; }
.chip.plain { background: var(--sunk); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.talk { width: 168px; height: 168px; border-radius: 50%; background: var(--record); color: var(--bg); font-size: 1.5rem; margin: 0 auto;
  box-shadow: 0 0 0 12px var(--sunk); display: grid; place-items: center; padding: 0; }
.talk.stop::before { content: ""; width: 48px; height: 48px; border-radius: 10px; background: var(--bg); }
.timer { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; line-height: 1.1; }
.timer small { font-size: 1.1rem; color: var(--muted); font-weight: 500; }
canvas.wave { width: 100%; height: 110px; display: block; touch-action: none; border-radius: 12px; background: var(--surface); }
.ctrl { display: flex; justify-content: center; gap: 14px; }
.ctrl button { width: auto; min-width: 76px; }
.recbtn { background: var(--record); color: var(--bg); border-radius: 99px; font-size: 1.1rem; }

.list { display: flex; flex-direction: column; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--line);
  color: inherit; text-decoration: none; background: none; border-radius: 0; text-align: left; font-weight: 400; width: 100%; min-height: 56px; border-top: 0; border-left: 0; border-right: 0; }
.item b { font-weight: 600; }
.item .meta { color: var(--muted); font-size: .88rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.seg { display: flex; border: 2px solid var(--link); border-radius: 12px; overflow: hidden; }
.seg button { border-radius: 0; background: none; color: var(--link); min-height: 46px; padding: 8px; }
.seg button.on { background: var(--accent); color: var(--on-accent); }
button.back { align-self: flex-start; padding-left: 0; text-decoration: none; }
.back { color: var(--link); text-decoration: none; font-weight: 600; padding: 6px 0; display: inline-block; min-height: 40px; }

.player { display: flex; align-items: center; gap: 12px; }
.player button { width: 52px; height: 52px; min-height: 52px; border-radius: 50%; padding: 0; flex: none; font-size: .8rem; }
.player input[type=range] { flex: 1; padding: 0; border: 0; background: none; accent-color: var(--accent); height: 32px; }
.player .time { font-size: .88rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.transcript { font-size: 1.1rem; line-height: 1.7; }
.transcript span.s { cursor: pointer; border-radius: 4px; }
.transcript span.s.now { background: var(--accent-soft); }
.transcript span.s.picked { background: var(--accent-soft); }
.transcript span.s.dim { color: var(--muted); }
.transcript .unsure { border-bottom: 2px dotted var(--record); }
.reading { font-family: Georgia, "Times New Roman", serif; font-size: 1.15rem; line-height: 1.75; }
.reading h3 { font-style: italic; font-weight: 400; margin: 1.4em 0 .4em; font-size: 1.05rem; }
.reading p { margin: 0 0 .9em; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1rem; word-break: break-all; background: var(--sunk); padding: 12px; border-radius: 12px; user-select: all; }
/* Speakers: a name before each turn in a conversation. */
.spk { display: block; width: fit-content; margin: 12px 0 2px; padding: 0; min-height: 0; background: none; border: 0; border-radius: 6px;
  font: 700 .82rem/1.3 var(--font); color: var(--accent); cursor: pointer; text-align: left; }
.spk.c1 { color: var(--record); } .spk.c2 { color: var(--danger); } .spk.c3 { color: var(--muted); }
.spk.unknown { color: var(--muted); border: 1.5px dashed var(--muted); border-radius: 99px; padding: 1px 10px; }
.transcript .spk:first-child { margin-top: 0; }
.flag { background: transparent; border: 1.5px solid var(--record); color: var(--record); }
.sheet-dim { position: fixed; inset: 0; background: rgba(20, 15, 10, .4); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 560px; margin: 0 auto; max-height: 86vh; overflow-y: auto;
  background: var(--surface); color: var(--fg); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  padding: 10px max(18px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 12px; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); align-self: center; }
.sheet audio { width: 100%; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.steps li { display: flex; align-items: center; gap: 10px; font-size: .95rem; color: var(--muted); }
.steps li.done { color: var(--fg); }
.steps li.now { color: var(--fg); font-weight: 700; }
.steps .mark { width: 22px; height: 22px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: .75rem;
  border: 2px solid var(--line); }
.steps li.done .mark { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.steps li.now .mark { border-color: var(--record); border-top-color: transparent; }
@media (prefers-reduced-motion: no-preference) { .steps li.now .mark { animation: spin 1s linear infinite; } }
@keyframes spin { to { transform: rotate(360deg); } }
.jbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--accent-soft); border-radius: 12px; padding: 8px 14px; font-size: .92rem; font-weight: 600; }
.jbar a { font-weight: 600; }
.banner { background: var(--sunk); border-radius: 12px; padding: 10px 14px; font-size: .92rem; }
#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; max-width: 88vw; z-index: 5; text-align: center; }
@media print { nav#tabs, .noprint { display: none !important; } main { overflow: visible; } body { background: #fff; color: #000; } }
@media (prefers-reduced-motion: no-preference) { .talk:active { transform: scale(.97); } }

/* People page: a journal kept inside a backup, and an error under the box it's about. */
.kept-in { border-left: 3px solid var(--line); padding-left: 12px; }
.field-error { color: var(--danger); margin: 0; }
