:root {
  --bg: #fff8ee;
  --surface: #ffffff;
  --text: #1f1a17;
  --muted: #5c524b;
  --line: #e6d9c8;
  --primary: #b4471f;
  --primary-text: #ffffff;
  --accent: #2f6b45;
  --danger: #b3261e;
  --mine: #dff3d4;
  --badge: #d93025;
  --radius: 14px;
  --tap: 52px;
  --imp-h: 0px; /* impersonation banner height */
  --font: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; /* js/diag.js checks this rule to tell whether styles.css applied */
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.no-scroll { overflow: hidden; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
a { color: var(--primary); }
img { max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }


.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: var(--tap); min-width: var(--tap); padding: 8px 18px;
  border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 18px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:focus-visible, .cell:focus-visible, .tab:focus-visible, .voice-bubble:focus-visible { outline: 3px solid #1a5fb4; outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { min-height: 44px; font-size: 16px; padding: 4px 12px; }
.btn-huge { font-size: 24px; min-height: 76px; width: min(100%, 420px); padding: 12px 24px; }
.btn-bar { border: none; background: transparent; color: inherit; padding: 6px 10px; font-size: 17px; }

/* top bar */
.topbar {
  position: sticky; top: var(--imp-h); z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 12px; min-height: 60px;
  background: var(--primary); color: #fff;
}
.brand { font-size: 22px; margin: 0; }
#settings-btn { font-size: 26px; } /* admins only, a lone gear (SPEC §0.18) */

/* impersonation banner (dad viewing as someone else) */
/* Fixed above everything a person acts in (timeline, pages, lightbox), below sheets, toasts and the recorder. */
body.imp-on { --imp-h: calc(48px + env(safe-area-inset-top)); padding-top: var(--imp-h); }
.imp-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 25; height: var(--imp-h);
  display: flex; align-items: center; justify-content: center; gap: 12px; padding: env(safe-area-inset-top) 12px 0;
  color: #fff; font-size: 17px;
}
/* The bar slides in as a pseudo-element, so the banner's own box (what taps hit) never moves. */
.imp-banner::before { content: ""; position: absolute; inset: 0; z-index: -1; background: #222; }
.imp-banner:not([hidden])::before { animation: slide-down .25s ease-out; }
.imp-banner:not([hidden]) > * { animation: fade-in .25s ease-out; }
.imp-banner .btn { min-height: 40px; padding: 2px 14px; font-size: 16px; }
.imp-on .lightbox { top: var(--imp-h); padding-top: 0; }
.posted-by { font-size: 13px; color: var(--muted, #777); }

/* full-page states */
.screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  min-height: 70vh; padding: 32px 20px; text-align: center; font-size: 20px;
}
.screen h1, .screen h2 { font-size: 26px; }
.screen-icon { font-size: 64px; line-height: 1; }
.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 5px solid var(--line); border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* SPEC §0.24: loading indicators that only appear when loading is slow (a fast load never shows them). */
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
.cell-wait {
  position: absolute; inset: 0; margin: auto; width: 26px; height: 26px; border-width: 3px;
  border-color: rgba(255, 255, 255, .45); border-top-color: #fff; opacity: 0;
  animation: spin 1s linear infinite, appear .2s ease-out 1.5s forwards;
}
.lb-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  pointer-events: none; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); font-size: 17px;
}
.lb-loading[hidden], .lb-slow[hidden] { display: none; }
.lb-loading .spinner { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; opacity: 0; animation: spin 1s linear infinite, appear .2s ease-out .6s forwards; }

/* timeline */
.timeline-host { padding: 0 0 40px; }
.month-title {
  position: sticky; top: calc(60px + var(--imp-h)); z-index: 2;
  margin: 0; padding: 10px 14px; font-size: 22px;
  background: rgba(255, 248, 238, .96);
}
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.cell {
  position: relative; display: block; width: 100%; aspect-ratio: 1 / 1; padding: 0; margin: 0;
  border: 0; overflow: hidden; cursor: pointer;
  background: #e8dccb center / cover no-repeat;
}
.thumb { display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s ease-out; }
.thumb.loaded { opacity: 1; }
.badge {
  position: absolute; z-index: 1; font-size: 15px; font-weight: 700; line-height: 1;
  padding: 5px 7px; border-radius: 999px; color: #fff; pointer-events: none;
}
.badge-video { left: 5px; bottom: 5px; background: rgba(0, 0, 0, .65); }
.badge-unread { right: 5px; top: 5px; min-width: 28px; text-align: center; background: var(--badge); border: 2px solid #fff; }
.badge-count { right: 5px; top: 5px; background: rgba(0, 0, 0, .55); font-weight: 600; }
.timeline-status { text-align: center; color: var(--muted); padding: 18px; margin: 0; }
.timeline-status .bi { align-items: center; }
.empty { font-size: 22px; }
.sentinel { height: 1px; }

/* lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.lb-bar {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 6px; min-height: 60px; padding: 4px 6px;
  background: #1f1a17; color: #fff;
}
.lb-when { flex: 1; text-align: center; font-size: 16px; }
.lb-download { color: #fff; }
.lb-stage-wrap { position: relative; background: #000; touch-action: pan-y; }
.lb-stage {
  display: flex; align-items: center; justify-content: center;
  min-height: 40vh; max-height: 72vh; user-select: none;
}
/* zoomed (js/gestures.js): every finger is ours, the enlarged photo stays inside the stage, no ‹ › over it */
.lb-stage-wrap.zoomed { touch-action: none; }
.lb-stage-wrap.zoomed .lb-stage { overflow: hidden; }
.lb-stage-wrap.zoomed .lb-nav { visibility: hidden; }
.lb-media { display: block; max-width: 100%; max-height: 72vh; width: auto; height: auto; object-fit: contain; }
img.lb-media { flex: none; transform-origin: 50% 50%; will-change: transform; background-size: 100% 100%; background-repeat: no-repeat; } /* lqip until d.webp is in */
video.lb-media { width: 100%; background: #000; }
.lightbox.lb-closing { pointer-events: none; }
.lb-error { color: #fff; padding: 24px; text-align: center; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 72px; border: 0; border-radius: 12px;
  background: rgba(0, 0, 0, .45); color: #fff; font-size: 40px; line-height: 1; cursor: pointer;
}
.lb-prev { left: 4px; }
.lb-next { right: 4px; }

/* comments; while the panel is on screen the composer is pinned to the bottom (above the keyboard: --kb,
   js/comments.js), the list scrolls above it (--composer-h leaves room under the list and for scrollIntoView) */
.comments { max-width: 760px; margin: 0 auto; padding: 14px 12px calc(var(--composer-h, 0px) + var(--kb, 0px) + 24px); }
.comment { scroll-margin-bottom: calc(var(--composer-h, 0px) + var(--kb, 0px) + 12px); }
.comments-title { font-size: 21px; }
.comment-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.comment {
  align-self: flex-start; max-width: 88%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px; -webkit-touch-callout: none;
}
.comment.mine { align-self: flex-end; background: var(--mine); }
.comment-new { animation: rise-in .25s ease-out; }
.comment-head { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--muted); }
.comment-author { font-weight: 700; color: var(--text); font-size: 17px; }
.comment-more {
  margin-left: auto; min-width: 44px; min-height: 44px; border: 0; background: transparent;
  font-size: 22px; color: var(--muted); cursor: pointer;
}
.comment-text { margin: 4px 0 0; font-size: 19px; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty-thread { text-align: center; padding: 12px 0; }
.empty-thread .bi { align-items: center; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.voice-bubble {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 6px;
  min-height: 48px; min-width: 120px; padding: 6px 14px;
  border: 2px solid var(--line); border-radius: 24px; background: #fff7e6;
  font: inherit; font-size: 19px; font-weight: 600; color: var(--text); cursor: pointer;
}
.voice-w2 { min-width: 140px; } .voice-w3 { min-width: 160px; } .voice-w4 { min-width: 180px; }
.voice-w5 { min-width: 195px; } .voice-w6 { min-width: 210px; } .voice-w7 { min-width: 220px; }
.voice-w8 { min-width: 230px; } .voice-w9 { min-width: 240px; } .voice-w10 { min-width: 250px; }
.voice-bubble.playing { border-color: var(--accent); background: #e3f4e8; }
.voice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.voice-row .voice-bubble { margin-top: 0; }
.voice-to-text {
  min-height: 44px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 22px;
  background: transparent; color: var(--muted); font: inherit; font-size: 15px; cursor: pointer;
}
.voice-to-text[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.voice-to-text:focus-visible { outline: 3px solid #1a5fb4; outline-offset: 2px; }
.voice-transcript { margin: 4px 2px 0; font-size: 15px; line-height: 1.45; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.voice-transcript.busy { display: flex; align-items: center; gap: 8px; }
.voice-transcript .spinner { flex: none; width: 18px; height: 18px; border-width: 3px; }
.voice-transcript .bi { align-items: flex-start; }
.voice-transcript.compare .cmp-line { display: block; }
.voice-transcript .cmp-label { font-weight: 600; }
.voice-transcript mark.diff { background: #ffe08a; color: #3b2f00; border-radius: 3px; padding: 0 1px; }
.voice-pending {
  display: inline-flex; align-items: center; margin-top: 6px; min-height: var(--tap); padding: 6px 14px;
  border: 2px dashed var(--line); border-radius: 24px; background: #fff7e6;
  font: inherit; font-size: 18px; color: var(--text); cursor: pointer;
}
.voice-pending:disabled { cursor: default; color: var(--muted); }
.voice-pending:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.comments-retry { margin-top: 8px; }
.voice-bubble.playing .voice-icon { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.composer {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px max(12px, env(safe-area-inset-right), calc((100% - 736px) / 2)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left), calc((100% - 736px) / 2));
  background: var(--bg); border-top: 1px solid var(--line);
}
/* in flow (same height) at the end of the list until the panel is on screen */
.comments.pinned .composer { position: fixed; z-index: 4; left: 0; right: 0; bottom: var(--kb, 0px); box-shadow: 0 -4px 12px rgba(0, 0, 0, .06); }
.kb-open .composer { padding-bottom: 10px; } /* the keyboard covers the home-indicator area */
.hold-to-talk {
  width: 100%; min-height: 64px; font-size: 22px;
  background: #fff; border: 3px solid var(--accent); color: var(--accent);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}
.hold-to-talk.pressed { background: var(--accent); color: #fff; }
.hold-to-talk.recording { animation: rec-pulse 1s ease-in-out infinite; }
.no-voice { margin: 0; padding: 10px; border-radius: var(--radius); background: #fdecea; color: var(--danger); text-align: center; }
.composer-form { display: flex; gap: 8px; align-items: stretch; }
.composer-text {
  flex: 1; min-width: 0; height: var(--tap); padding: 0 12px;
  border: 2px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--text);
  font: inherit; font-size: 19px;
}
.composer-text:focus { outline: none; border-color: var(--accent); }
.send { min-width: 76px; }

.rec-overlay {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .25); pointer-events: none;
}
.rec-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: min(80vw, 300px); padding: 24px 16px; border-radius: 18px;
  background: rgba(31, 26, 23, .9); color: #fff; text-align: center; font-size: 18px;
}
.rec-overlay:not([hidden]) .rec-card { animation: pop-in .15s ease-out; }
.rec-mic { font-size: 56px; line-height: 1; animation: pulse 1.2s ease-in-out infinite; }
.rec-timer { font-size: 26px; font-variant-numeric: tabular-nums; font-weight: 700; }
/* slide-up-to-cancel hint: an arrow drifting up while recording */
.rec-up { font-size: 26px; line-height: 1; height: 26px; opacity: 0; }
.rec-overlay.recording .rec-up { animation: drift-up 1s ease-out infinite; }
.rec-overlay.cancel .rec-card { background: rgba(179, 38, 30, .95); }
.rec-overlay.cancel .rec-mic, .rec-overlay.cancel .rec-up { animation: none; }

/* sheets and toasts; .sheet-backdrop/.sheet only mark the live sheet (js/dom.js) */
.sheet-bg {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .45); animation: fade-in .2s ease-out;
}
.sheet-bg:not(.sheet-backdrop) { pointer-events: none; }
.sheet-panel {
  display: flex; flex-direction: column; gap: 10px; width: min(100%, 520px);
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg); border-radius: 20px 20px 0 0; animation: sheet-up .25s ease-out;
}
.sheet-panel .btn { width: 100%; min-height: 60px; font-size: 20px; }
.sheet-title { text-align: center; font-size: 20px; margin: 0 0 6px; }
.settings-hello { font-size: 24px; font-weight: 700; margin: 0; }
.settings-head p { margin: 4px 0; }
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom) + var(--composer-h, 0px) + var(--kb, 0px)); /* above a pinned composer */
  transform: translateX(-50%); z-index: 50; pointer-events: none;
  max-width: 90vw; padding: 12px 20px; border-radius: 14px;
  background: rgba(31, 26, 23, .92); color: #fff; font-size: 18px; text-align: center;
  animation: toast-in .25s ease-out;
}

/* motion (SPEC §0.16): transform/opacity only; loops (recording pulse, cancel hint) run 1 s cycles */
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px); } }
@keyframes slide-down { from { transform: translateY(-100%); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes pop-in { from { opacity: 0; transform: scale(.9); } }
@keyframes rec-pulse { 50% { transform: scale(1.03); } }
@keyframes drift-up { from { opacity: 0; transform: translateY(10px); } 40% { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }
@media (prefers-reduced-motion: reduce) {
  *:not(.spinner), *::before, *::after { animation: none !important; transition: none !important; }
  .rec-overlay.recording .rec-up { opacity: 1; } /* the slide-up-to-cancel arrow, standing still */
}

/* invite page */
.invite-page { background: var(--bg); }
.invite .screen { min-height: 90vh; }
.invite-note { min-height: 1.5em; color: var(--danger); }
.inapp-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 40px 24px; text-align: center;
  background: #1f1a17; color: #fff; font-size: 20px;
}
.inapp-title { font-size: 28px; }
.inapp-arrow { position: absolute; top: 8px; right: 18px; font-size: 72px; line-height: 1; color: #ffcc66; }

/* help page */
.help { max-width: 720px; margin: 0 auto; padding: 16px 18px 48px; font-size: 19px; }
.help h2 { margin-top: 1.4em; font-size: 23px; }
.help ol { padding-left: 1.4em; }
.help li { margin: .5em 0; }
.help .back { margin-top: 24px; }

/* pages (upload, admin) */
.page { max-width: 760px; margin: 0 auto; padding: 8px 14px 48px; }
.page-head { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; }
.page-title { margin: 0; font-size: 23px; }
.page-title .bi { align-items: flex-start; }
.fab {
  position: fixed; z-index: 6; right: calc(16px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  min-height: 64px; padding: 8px 22px; border-radius: 32px; font-size: 21px; box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row .btn { flex: 1; }
.tag {
  display: inline-flex; margin-left: 8px; padding: 2px 10px; border-radius: 999px;
  background: #e3f4e8; color: var(--accent); font-size: 15px; font-weight: 700; vertical-align: middle;
}
.tag .bi { flex-direction: row; gap: 4px; align-items: baseline; }

/* form controls */
.choices { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; padding: 0; border: 0; }
.choices legend { font-size: 20px; font-weight: 700; margin-bottom: 8px; padding: 0; }
.choices legend .bi, .field > .bi { align-items: flex-start; }
.choice {
  display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 8px 16px;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface); font-size: 19px; cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: #e3f4e8; }
.choice input { width: 26px; height: 26px; margin: 0; accent-color: var(--accent); }
.choice .bi { align-items: flex-start; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 18px; }
.text-input {
  min-height: var(--tap); padding: 8px 12px; border: 2px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--text); font: inherit; font-size: 19px; width: 100%;
}
.text-input:focus { outline: none; border-color: var(--accent); }
