/* The Beaumont Family Story
   Warm, book-like, deliberately quiet. The content is the point.
   Cache-busted by filemtime() via asset() — no manual version bumping. */

:root {
  --ink:      #2b2622;
  --muted:    #7a7068;
  --paper:    #faf7f2;
  --card:     #fffdfa;
  --rule:     #e2dad0;
  --accent:   #7c4a2d;
  --accent-l: #f0e6dd;
  --warn:     #a8541f;
  --error:    #8c2f2f;
  --ok:       #3f6b45;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.65;
}

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

.muted { color: var(--muted); }


/* ---- Page chrome ---- */

header.site {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: baseline;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
}

.brand {
  font-size: 1.15rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.01em;
}

header.site nav { display: flex; gap: 1.25rem; font-size: 0.95rem; }
header.site nav a.on { color: var(--ink); text-decoration: none; border-bottom: 2px solid var(--accent); }

main { max-width: 46rem; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

footer.site {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
}
footer.site p { margin: 0; }

h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 400; margin: 0 0 0.5rem; }
h2 { font-size: 1.2rem; font-weight: 400; margin: 2.25rem 0 0.75rem;
     padding-bottom: 0.4rem; border-bottom: 1px solid var(--rule); }

.lede { color: var(--muted); margin-top: 0; }
.crumb { font-size: 0.9rem; margin: 0 0 1.5rem; }
.hint  { font-size: 0.85rem; color: var(--muted); margin: 0.35rem 0 1rem; }


/* ---- Sign-in ---- */

.auth-page {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 2.25rem;
  max-width: 26rem;
  width: 100%;
}
.auth-card h1 { border-bottom: 1px solid var(--rule); padding-bottom: 1rem; margin-bottom: 1.25rem; }


/* ---- Who's who ---- */

ul.people { list-style: none; padding: 0; margin: 1.5rem 0 0; }

ul.people li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
}

ul.people a { text-decoration: none; display: flex; gap: 0.75rem; align-items: baseline; flex-wrap: wrap; }
ul.people .name { font-size: 1.15rem; }
ul.people a:hover .name { text-decoration: underline; }
ul.people .dates { color: var(--muted); font-size: 0.9rem; }
ul.people .snippet { margin: 0.3rem 0 0.2rem; color: var(--ink); }
ul.people .count { margin: 0; font-size: 0.85rem; color: var(--muted); }
ul.people .count.thin { color: var(--warn); }

ul.memories { list-style: none; padding: 0; margin: 0; }
ul.memories li { padding: 0.5rem 0; border-bottom: 1px solid var(--rule); }
ul.memories .when { color: var(--muted); font-size: 0.9rem; margin-left: 0.5rem; }

ul.relations { list-style: none; padding: 0; margin: 0; }
ul.relations li { padding: 0.35rem 0; }

.tag {
  display: inline-block;
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.1rem 0.45rem;
  margin-left: 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--muted);
  vertical-align: middle;
}

.empty {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1.5rem;
  margin-top: 1.5rem;
}


/* ---- A person, a memory ---- */

.full-name { color: var(--muted); margin: 0 0 0.25rem; font-style: italic; }
.facts { color: var(--muted); font-size: 0.95rem; margin: 0 0 1.5rem; }
.people-line { font-size: 0.95rem; margin: -1rem 0 1.5rem; }

.bio, .narrative { font-size: 1.05rem; }
.narrative.raw { color: var(--ink); border-left: 3px solid var(--rule); padding-left: 1rem; }

.sources ul { list-style: none; padding: 0; }
.sources li { padding: 0.6rem 0; border-bottom: 1px solid var(--rule); font-size: 0.95rem; }
.sources .who { color: var(--ink); }

blockquote {
  margin: 0.5rem 0 0;
  padding-left: 1rem;
  border-left: 3px solid var(--accent-l);
  color: var(--muted);
  font-size: 0.95rem;
}
blockquote cite { display: block; margin-top: 0.4rem; font-size: 0.85rem; font-style: normal; }

.conflict {
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--warn);
  border-radius: 3px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.conflict.resolved { border-left-color: var(--ok); }
.conflict .what { margin: 0 0 0.75rem; }
.conflict .sides { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.conflict .resolution { margin: 0.9rem 0 0; font-size: 0.9rem; }

@media (max-width: 34rem) {
  .conflict .sides { grid-template-columns: 1fr; }
}


/* ---- Admin ---- */

ul.stats { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 1.75rem; margin: 1.5rem 0 2rem; }
ul.stats li { font-size: 0.9rem; color: var(--muted); }
ul.stats strong { display: block; font-size: 1.6rem; font-weight: 400; color: var(--ink); }
ul.stats li.needs-attention strong { color: var(--warn); }

nav.admin-nav { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
nav.admin-nav a {
  display: block;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--ink);
}
nav.admin-nav a:hover { border-color: var(--accent); }
nav.admin-nav strong { display: block; font-weight: 400; font-size: 1.1rem; color: var(--accent); }
nav.admin-nav span { font-size: 0.88rem; color: var(--muted); }

.admin-actions { margin-top: 2rem; font-size: 0.9rem; }


/* ---- Forms ---- */

form.stacked { margin: 1.5rem 0 2rem; }
form.stacked label { display: block; margin-bottom: 0.3rem; font-size: 0.9rem; }
form.stacked .row { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }

input[type=text], input[type=email], textarea, select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  margin-bottom: 1rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--card);
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }

button {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.55rem 1.4rem;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:hover { background: #63391f; }

.actions { display: flex; gap: 1.25rem; align-items: center; }

form.inline { display: inline; }
button.link {
  background: none; border: none; padding: 0; color: var(--accent);
  font-size: 0.88rem; text-decoration: underline; cursor: pointer;
}
button.link:hover { background: none; }
button.link.danger { color: var(--error); }

.auth-card button { width: 100%; margin-top: 0.5rem; }

@media (max-width: 34rem) {
  form.stacked .row { grid-template-columns: 1fr; }
}


/* ---- Tables ---- */

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--rule); }
th { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
tr.inactive td { opacity: 0.55; }
.row-actions { display: flex; gap: 0.9rem; white-space: nowrap; }


/* ---- Alerts ---- */

.alert {
  padding: 0.75rem 1rem;
  border-radius: 3px;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  border: 1px solid;
}
.alert-success { background: #f1f5f0; border-color: #cfdccf; color: var(--ok); }
.alert-error   { background: #f9efef; border-color: #e2c9c9; color: var(--error); }


/* ---- The interview ----
   Bigger than the rest of the app on purpose: this page is used by someone
   in their eighties, sometimes at arm's length on a propped-up iPad. */

.interview { max-width: 34rem; }
.interview .topic { background: var(--card); border: 1px solid var(--rule);
  border-radius: 4px; padding: 0.9rem 1.1rem; font-size: 1.05rem; }

.controls { display: flex; gap: 1rem; flex-wrap: wrap; margin: 1.75rem 0 1rem; }

button.big {
  font-size: 1.25rem;
  padding: 0.9rem 2rem;
  border-radius: 4px;
  min-height: 3.4rem;          /* comfortably tappable with an unsteady hand */
}
button.big.secondary { background: var(--card); color: var(--accent); }
button.big.secondary:hover { background: var(--accent-l); }

.status { font-size: 1rem; color: var(--muted); min-height: 1.6rem; margin: 0.5rem 0 0; }
.status.listening { color: var(--accent); }
.status.listening::before {
  content: '●'; margin-right: 0.45rem; animation: pulse 1.4s ease-in-out infinite;
}
.status.warn { color: var(--warn); }
.status.done { color: var(--ok); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) {
  .status.listening::before { animation: none; }
}

.transcript { margin: 1.5rem 0; }
.transcript .line {
  font-size: 1.1rem;
  line-height: 1.6;
  margin: 0 0 1rem;
  padding: 0.7rem 1rem;
  border-radius: 4px;
}
.transcript .interviewer { background: var(--card); border: 1px solid var(--rule); }
.transcript .storyteller { background: var(--accent-l); border: 1px solid #e3d3c5; }

.text-fallback { margin-top: 2rem; }
.text-fallback label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.35rem; }
.row-inline { display: flex; gap: 0.75rem; align-items: stretch; }
.row-inline input { margin-bottom: 0; }
.row-inline button { white-space: nowrap; }

@media (max-width: 34rem) {
  .controls button.big { width: 100%; }
  .row-inline { flex-direction: column; }
}

/* Live transcription, shown while they're still speaking so it's visibly
   hearing them rather than apparently ignoring them. */
.interim {
  font-size: 1.05rem;
  color: var(--muted);
  font-style: italic;
  margin: 0.25rem 0 0;
  min-height: 1.5rem;
}

.settings { margin: 2rem 0; border-top: 1px solid var(--rule); padding-top: 1rem; }
.settings summary { cursor: pointer; font-size: 0.95rem; color: var(--accent); }
.settings .setting { margin: 1.25rem 0; }
.settings label { display: block; font-size: 0.95rem; margin-bottom: 0.3rem; }
.settings select { max-width: 22rem; margin-bottom: 0.25rem; }
.settings .hint { display: block; font-size: 0.85rem; color: var(--muted); }

/* Screen-stays-awake notice: reassurance, not a warning. */
.hint.wake { color: var(--ok); }

/* ---- The bar ----
   Controls, status and the microphone indicator stay put as the transcript
   grows. A long conversation should never mean scrolling to the top to find
   "Finish for today". */

.bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  margin: 1.5rem -1.5rem 0;
  padding: 0.9rem 1.5rem calc(0.9rem + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  border-top: 1px solid var(--rule);
}
.bar-inner { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.bar-text { flex: 1 1 12rem; min-width: 0; }
.bar .status, .bar .interim { margin: 0; }
.bar .controls { margin: 0; }

/* The microphone indicator. Deliberately large and wordless. */
.mic { position: relative; width: 2.6rem; height: 2.6rem; flex: 0 0 auto; }
.mic .dot {
  position: absolute; inset: 0.8rem;
  border-radius: 50%;
  background: var(--rule);
  transition: background 0.2s;
}
.mic .ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}
.mic.live .dot     { background: #1f7a3d; }
.mic.live .ring    { border-color: #1f7a3d; animation: listen 1.6s ease-out infinite; }
.mic.talking .dot  { background: var(--accent); }
.mic.talking .ring { border-color: var(--accent-l); animation: none; }
.mic.trouble .dot  { background: var(--warn); }

@keyframes listen {
  0%   { transform: scale(0.75); opacity: 1; }
  100% { transform: scale(1.15); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .mic.live .ring { animation: none; opacity: 0.6; }
}

@media (max-width: 34rem) {
  .bar-inner { gap: 0.75rem; }
  .bar .controls button.big { width: auto; flex: 1 1 auto; font-size: 1.05rem; padding: 0.75rem 1rem; }
}

/* Diagnostic log, only present with ?debug=1 */
.debug {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.75rem;
  max-height: 20rem;
  overflow: auto;
  user-select: text;
}
