/* Message Album — offline archive stylesheet.
   No framework, no CDN, no external font. Designed to still render correctly
   in a decade: system fonts, standard CSS, graceful degradation. */

/* The browser's own `[hidden] { display: none }` is a user-agent rule, so any
   author `display:` on the same element beats it. `.privacy`, `.partial` and
   `.message` all set `display: flex`, which silently defeated every
   `element.hidden = true` in app.js: search left non-matching messages on
   screen, the privacy note ignored its Dismiss button, and a complete archive
   painted an empty orange "incomplete backup" bar above the conversation.
   This one rule is what makes `hidden` mean hidden. Keep it first. */
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- tokens */

:root {
  /* Type, space and shape are shared by every theme; only colour varies. */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
    "Segoe UI Emoji";
  --size-xs: 0.6875rem;
  --size-sm: 0.75rem;
  --size-base: 0.9375rem;
  --size-md: 1.0625rem;
  --size-lg: 1.375rem;

  /* Space + shape */
  --gap-1: 0.25rem;
  --gap-2: 0.5rem;
  --gap-3: 0.75rem;
  --gap-4: 1rem;
  --gap-5: 1.5rem;
  --gap-6: 2.5rem;
  --radius-bubble: 1.25rem;
  --radius-md: 0.875rem;
  --radius-sm: 0.5rem;
  --measure: 52rem;

  --shadow-chrome: 0 1px 0 var(--hairline);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, 0.14), 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* Themes — generated from palettes verified against WCAG AA (4.5:1) for
   every text pair. Regenerate rather than hand-editing colour values. */

/* classic ------------------------------------------------------------ */
:root {
  color-scheme: light;
  --surface: #ffffff;
  --surface-sunken: #f5f5f7;
  --surface-raised: #ffffff;
  --bubble-in: #ebebef;
  --bubble-in-text: #14141a;
  --text: #14141a;
  --text-secondary: #62626b;
  --text-tertiary: #6e6e75;
  --hairline: rgba(0,0,0,.09);
  --hairline-strong: rgba(0,0,0,.16);
  --chrome: rgba(252,252,253,.72);
  --overlay: rgba(120,120,130,.12);
  --overlay-hover: rgba(120,120,130,.2);
  --accent: #0972ea;
  --accent-strong: #0057cc;
  --accent-text: #ffffff;
  --accent-soft: rgba(9,114,234,.12);
  --highlight: #ffd60a;
  --highlight-soft: rgba(255,214,10,.35);
  --warn: #8a6100;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-appearance="light"]) {
    color-scheme: dark;
    --surface: #000000;
    --surface-sunken: #0b0b0d;
    --surface-raised: #1c1c1f;
    --bubble-in: #26262b;
    --bubble-in-text: #f2f2f5;
    --text: #f2f2f5;
    --text-secondary: #a0a0aa;
    --text-tertiary: #7a7a83;
    --hairline: rgba(255,255,255,.11);
    --hairline-strong: rgba(255,255,255,.2);
    --chrome: rgba(20,20,23,.72);
    --overlay: rgba(150,150,165,.16);
    --overlay-hover: rgba(150,150,165,.26);
    --accent: #0874e0;
    --accent-strong: #0a5cbe;
    --accent-text: #ffffff;
    --accent-soft: rgba(8,116,224,.24);
    --highlight: #ffd60a;
    --highlight-soft: rgba(255,214,10,.3);
    --warn: #e5b53c;
  }
}

:root[data-appearance="dark"] {
  color-scheme: dark;
  --surface: #000000;
  --surface-sunken: #0b0b0d;
  --surface-raised: #1c1c1f;
  --bubble-in: #26262b;
  --bubble-in-text: #f2f2f5;
  --text: #f2f2f5;
  --text-secondary: #a0a0aa;
  --text-tertiary: #7a7a83;
  --hairline: rgba(255,255,255,.11);
  --hairline-strong: rgba(255,255,255,.2);
  --chrome: rgba(20,20,23,.72);
  --overlay: rgba(150,150,165,.16);
  --overlay-hover: rgba(150,150,165,.26);
  --accent: #0874e0;
  --accent-strong: #0a5cbe;
  --accent-text: #ffffff;
  --accent-soft: rgba(8,116,224,.24);
  --highlight: #ffd60a;
  --highlight-soft: rgba(255,214,10,.3);
  --warn: #e5b53c;
}

/* paper ------------------------------------------------------------ */
:root[data-palette="paper"] {
  color-scheme: light;
  --surface: #fbf7f0;
  --surface-sunken: #f3ece1;
  --surface-raised: #fffdf9;
  --bubble-in: #efe6d8;
  --bubble-in-text: #2a2118;
  --text: #2a2118;
  --text-secondary: #5c4f3f;
  --text-tertiary: #6b5c4a;
  --hairline: rgba(70,50,25,.14);
  --hairline-strong: rgba(70,50,25,.26);
  --chrome: rgba(251,247,240,.78);
  --overlay: rgba(120,95,60,.12);
  --overlay-hover: rgba(120,95,60,.2);
  --accent: #a0522d;
  --accent-strong: #7d3f22;
  --accent-text: #ffffff;
  --accent-soft: rgba(160,82,45,.13);
  --highlight: #e0a020;
  --highlight-soft: rgba(224,160,32,.34);
  --warn: #8a5a00;
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="paper"]:not([data-appearance="light"]) {
    color-scheme: dark;
    --surface: #14100c;
    --surface-sunken: #1b1611;
    --surface-raised: #241d16;
    --bubble-in: #2b231a;
    --bubble-in-text: #f2e9dc;
    --text: #f2e9dc;
    --text-secondary: #b8a894;
    --text-tertiary: #9c8b76;
    --hairline: rgba(240,225,200,.13);
    --hairline-strong: rgba(240,225,200,.24);
    --chrome: rgba(20,16,12,.76);
    --overlay: rgba(200,175,140,.14);
    --overlay-hover: rgba(200,175,140,.24);
    --accent: #c9743f;
    --accent-strong: #e08a55;
    --accent-text: #1a1208;
    --accent-soft: rgba(201,116,63,.26);
    --highlight: #e8b45c;
    --highlight-soft: rgba(232,180,92,.3);
    --warn: #e0a355;
  }
}

:root[data-palette="paper"][data-appearance="dark"] {
  color-scheme: dark;
  --surface: #14100c;
  --surface-sunken: #1b1611;
  --surface-raised: #241d16;
  --bubble-in: #2b231a;
  --bubble-in-text: #f2e9dc;
  --text: #f2e9dc;
  --text-secondary: #b8a894;
  --text-tertiary: #9c8b76;
  --hairline: rgba(240,225,200,.13);
  --hairline-strong: rgba(240,225,200,.24);
  --chrome: rgba(20,16,12,.76);
  --overlay: rgba(200,175,140,.14);
  --overlay-hover: rgba(200,175,140,.24);
  --accent: #c9743f;
  --accent-strong: #e08a55;
  --accent-text: #1a1208;
  --accent-soft: rgba(201,116,63,.26);
  --highlight: #e8b45c;
  --highlight-soft: rgba(232,180,92,.3);
  --warn: #e0a355;
}

/* nocturne ------------------------------------------------------------ */
:root[data-palette="nocturne"] {
  color-scheme: light;
  --surface: #f7f7fb;
  --surface-sunken: #eeeef5;
  --surface-raised: #ffffff;
  --bubble-in: #e8e8f2;
  --bubble-in-text: #1a1a2e;
  --text: #1a1a2e;
  --text-secondary: #565673;
  --text-tertiary: #63637f;
  --hairline: rgba(30,30,60,.11);
  --hairline-strong: rgba(30,30,60,.2);
  --chrome: rgba(247,247,251,.76);
  --overlay: rgba(90,90,130,.12);
  --overlay-hover: rgba(90,90,130,.2);
  --accent: #5b4bd6;
  --accent-strong: #4636c4;
  --accent-text: #ffffff;
  --accent-soft: rgba(91,75,214,.13);
  --highlight: #f0c000;
  --highlight-soft: rgba(240,192,0,.32);
  --warn: #7a5200;
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="nocturne"]:not([data-appearance="light"]) {
    color-scheme: dark;
    --surface: #08080f;
    --surface-sunken: #0f0f1a;
    --surface-raised: #1a1a2b;
    --bubble-in: #222036;
    --bubble-in-text: #eceaf7;
    --text: #eceaf7;
    --text-secondary: #a8a4c4;
    --text-tertiary: #8f8ab0;
    --hairline: rgba(200,195,240,.13);
    --hairline-strong: rgba(200,195,240,.24);
    --chrome: rgba(10,10,20,.76);
    --overlay: rgba(150,145,200,.16);
    --overlay-hover: rgba(150,145,200,.26);
    --accent: #5aa8ee;
    --accent-strong: #8fc9ff;
    --accent-text: #04121f;
    --accent-soft: rgba(90,168,238,.28);
    --highlight: #ffd85c;
    --highlight-soft: rgba(255,216,92,.3);
    --warn: #e8bd63;
  }
}

:root[data-palette="nocturne"][data-appearance="dark"] {
  color-scheme: dark;
  --surface: #08080f;
  --surface-sunken: #0f0f1a;
  --surface-raised: #1a1a2b;
  --bubble-in: #222036;
  --bubble-in-text: #eceaf7;
  --text: #eceaf7;
  --text-secondary: #a8a4c4;
  --text-tertiary: #8f8ab0;
  --hairline: rgba(200,195,240,.13);
  --hairline-strong: rgba(200,195,240,.24);
  --chrome: rgba(10,10,20,.76);
  --overlay: rgba(150,145,200,.16);
  --overlay-hover: rgba(150,145,200,.26);
  --accent: #5aa8ee;
  --accent-strong: #8fc9ff;
  --accent-text: #04121f;
  --accent-soft: rgba(90,168,238,.28);
  --highlight: #ffd85c;
  --highlight-soft: rgba(255,216,92,.3);
  --warn: #e8bd63;
}

/* meadow ------------------------------------------------------------ */
:root[data-palette="meadow"] {
  color-scheme: light;
  --surface: #f8faf6;
  --surface-sunken: #eef3ea;
  --surface-raised: #ffffff;
  --bubble-in: #e6ede1;
  --bubble-in-text: #17251a;
  --text: #17251a;
  --text-secondary: #47593f;
  --text-tertiary: #526347;
  --hairline: rgba(25,50,30,.12);
  --hairline-strong: rgba(25,50,30,.22);
  --chrome: rgba(248,250,246,.78);
  --overlay: rgba(80,110,80,.12);
  --overlay-hover: rgba(80,110,80,.2);
  --accent: #2f7d4f;
  --accent-strong: #23613c;
  --accent-text: #ffffff;
  --accent-soft: rgba(47,125,79,.13);
  --highlight: #d8a41c;
  --highlight-soft: rgba(216,164,28,.32);
  --warn: #7a5300;
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="meadow"]:not([data-appearance="light"]) {
    color-scheme: dark;
    --surface: #0a0f0b;
    --surface-sunken: #101711;
    --surface-raised: #18211a;
    --bubble-in: #1e281f;
    --bubble-in-text: #e9f2e8;
    --text: #e9f2e8;
    --text-secondary: #a3b89e;
    --text-tertiary: #8ba286;
    --hairline: rgba(210,235,205,.12);
    --hairline-strong: rgba(210,235,205,.22);
    --chrome: rgba(10,15,11,.78);
    --overlay: rgba(150,185,150,.14);
    --overlay-hover: rgba(150,185,150,.24);
    --accent: #4aa86c;
    --accent-strong: #6fc98c;
    --accent-text: #04120a;
    --accent-soft: rgba(74,168,108,.26);
    --highlight: #e2c264;
    --highlight-soft: rgba(226,194,100,.3);
    --warn: #dcc06a;
  }
}

:root[data-palette="meadow"][data-appearance="dark"] {
  color-scheme: dark;
  --surface: #0a0f0b;
  --surface-sunken: #101711;
  --surface-raised: #18211a;
  --bubble-in: #1e281f;
  --bubble-in-text: #e9f2e8;
  --text: #e9f2e8;
  --text-secondary: #a3b89e;
  --text-tertiary: #8ba286;
  --hairline: rgba(210,235,205,.12);
  --hairline-strong: rgba(210,235,205,.22);
  --chrome: rgba(10,15,11,.78);
  --overlay: rgba(150,185,150,.14);
  --overlay-hover: rgba(150,185,150,.24);
  --accent: #4aa86c;
  --accent-strong: #6fc98c;
  --accent-text: #04120a;
  --accent-soft: rgba(74,168,108,.26);
  --highlight: #e2c264;
  --highlight-soft: rgba(226,194,100,.3);
  --warn: #dcc06a;
}

/* ----------------------------------------------------------------- base */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--size-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: transparent;
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--chrome);
  border-bottom: 1px solid var(--hairline);
  padding-top: env(safe-area-inset-top);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .topbar {
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
  }
}

.topbar-inner {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--gap-3) var(--gap-4);
  display: flex;
  align-items: center;
  gap: var(--gap-3);
}

.identity {
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  min-width: 0;
  flex: 1 1 auto;
}

.avatar {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  /* Built from the active theme's accent so the avatar belongs to the theme. */
  background: linear-gradient(150deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: var(--accent-text);
  font-size: var(--size-sm);
  font-weight: 650;
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  user-select: none;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.identity-text { min-width: 0; }

.identity h1 {
  margin: 0;
  font-size: var(--size-md);
  font-weight: 620;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.identity p {
  margin: 0.1rem 0 0;
  font-size: var(--size-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions { display: flex; align-items: center; gap: var(--gap-1); flex: 0 0 auto; }

.icon-button {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-button:hover { background: var(--overlay); color: var(--text); }
.icon-button svg { width: 1.05rem; height: 1.05rem; display: block; }

/* Search ---------------------------------------------------------------- */

.searchbar {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gap-4) var(--gap-3);
  display: flex;
  align-items: center;
  gap: var(--gap-2);
}

.search {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: var(--gap-2);
  min-width: 0;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-md);
  background: var(--overlay);
  transition: box-shadow 0.15s ease;
}

.search:focus-within { box-shadow: 0 0 0 2px var(--accent); }
.search svg { width: 0.95rem; height: 0.95rem; flex: 0 0 auto; color: var(--text-tertiary); }

.search input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* Explicit placeholder colour: the UA default is often too faint to meet
   contrast, and it varies by browser. */
.search input::placeholder { color: var(--text-secondary); opacity: 1; }

/* Theme and appearance pickers ------------------------------------------ */

.picker-wrap { position: relative; display: inline-flex; }

/* The chevron is painted with a mask so it takes the theme's own colour; a
   fixed grey failed 3:1 against the lighter themes. */
@supports ((mask-image: url("")) or (-webkit-mask-image: url(""))) {
  .picker-wrap::after {
    content: "";
    position: absolute;
    right: 0.45rem;
    top: 50%;
    width: 0.7rem;
    height: 0.7rem;
    transform: translateY(-50%);
    pointer-events: none;
    background-color: var(--text-secondary);
    -webkit-mask: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat center / contain;
  }
}

.picker {
  appearance: none;
  -webkit-appearance: none;
  max-width: 8.5rem;
  padding: 0.3rem 1.5rem 0.3rem 0.6rem;
  /* A control needs a 3:1 boundary to be identifiable (WCAG 1.4.11); the
     decorative hairline used elsewhere is far below that. */
  border: 1px solid color-mix(in srgb, var(--text) 55%, transparent);
  border-radius: var(--radius-sm);
  background-color: var(--overlay);
  color: var(--text);
  font: inherit;
  font-size: var(--size-sm);
  line-height: 1.2;
  cursor: pointer;
  text-overflow: ellipsis;
}

.picker:hover { background-color: var(--overlay-hover); }
/* Native option lists are painted by the OS; keep them legible in dark mode. */
.picker option { background: var(--surface-raised); color: var(--text); }

/* Message-order toggle ---------------------------------------------------- */

.order-toggle {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background-color: var(--overlay);
  color: var(--text);
  font: inherit;
  font-size: var(--size-sm);
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}
.order-toggle:hover { background-color: var(--overlay-hover); }
.order-toggle svg { width: 0.95rem; height: 0.95rem; display: block; }
@media (max-width: 34rem) { .order-toggle span { display: none; } }

/* Privacy notice --------------------------------------------------------- */

.privacy {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(0.5rem, env(safe-area-inset-right));
  background: var(--accent-soft);
  color: var(--text);
  font-size: var(--size-sm);
  border-bottom: 1px solid var(--hairline);
}
.privacy #privacy-icon { width: 1.15rem; height: 1.15rem; flex: 0 0 auto; margin-top: 0.05rem; color: var(--accent); }
.privacy p { margin: 0; flex: 1; line-height: 1.45; }
.privacy .privacy-dismiss { flex: 0 0 auto; margin: -0.2rem -0.2rem 0 0; }
.privacy.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); }
.privacy.warn #privacy-icon { color: var(--warn); }

/* Incomplete (free-version) album ---------------------------------------- */

/* Heavier than the privacy note and not dismissible: this one says messages
   are missing, and the person reading it may be deciding whether the original
   is safe to delete. It also prints, because a printed transcript that hides
   its own incompleteness is worse than no transcript. */
.partial {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--warn) 26%, transparent);
  color: var(--text);
  font-size: var(--size-sm);
  font-weight: 600;
  border-bottom: 1px solid var(--hairline);
}
.partial svg { width: 1.15rem; height: 1.15rem; flex: 0 0 auto; margin-top: 0.05rem; color: var(--warn); }
.partial p { margin: 0; flex: 1; line-height: 1.45; }

/* Jump to top / bottom --------------------------------------------------- */

.jump {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  z-index: 20;
}
.jump-button {
  width: 2.4rem;
  height: 2.4rem;
  background: var(--chrome);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--hairline);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
}
.jump-button:hover { color: var(--text); background: var(--surface-raised); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

.search-status {
  flex: 0 0 auto;
  font-size: var(--size-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  white-space: nowrap;
}

.search-nav { display: flex; gap: 0.15rem; flex: 0 0 auto; }
.search-nav .icon-button { width: 1.75rem; height: 1.75rem; border-radius: var(--radius-sm); }
.search-nav .icon-button[disabled] { opacity: 0.35; cursor: default; }
.search-nav .icon-button[disabled]:hover { background: transparent; color: var(--text-secondary); }

/* --------------------------------------------------------------- transcript */

.transcript {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--gap-4) var(--gap-4) var(--gap-6);
  padding-bottom: calc(var(--gap-6) + env(safe-area-inset-bottom));
}

/* Each day is its own containment boundary: the browser can skip layout and
   paint for offscreen days entirely, which is what keeps very long
   conversations fast. */
.day-group {
  content-visibility: auto;
  contain-intrinsic-size: auto 600px;
}

.day-label {
  position: sticky;
  top: 0.5rem;
  z-index: 5;
  width: fit-content;
  margin: var(--gap-5) auto var(--gap-4);
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: var(--chrome);
  border: 1px solid var(--hairline);
  color: var(--text-secondary);
  font-size: var(--size-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .day-label {
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
  }
}

.day-group:first-of-type .day-label { margin-top: var(--gap-2); }

/* Messages -------------------------------------------------------------- */

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-block: 0.09rem;
  scroll-margin-block: 6rem;
}

.message.outgoing { align-items: flex-end; }

/* A little more air between speakers than within one speaker's run. */
.message + .message.turn-start { margin-top: 0.55rem; }

.sender {
  margin: 0 0.85rem 0.2rem;
  font-size: var(--size-xs);
  font-weight: 600;
  color: var(--text-tertiary);
}

.bubble {
  position: relative;
  max-width: min(38rem, 82%);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-bubble);
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  white-space: pre-wrap;
}

.outgoing .bubble {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: var(--accent-text);
}

/* Squared inner corner on the last bubble of a run reads as a speech tail
   without the fragility of a drawn tail. */
.message.turn-end:not(.outgoing) .bubble { border-bottom-left-radius: 0.3rem; }
.message.turn-end.outgoing .bubble { border-bottom-right-radius: 0.3rem; }

.subject { display: block; font-weight: 650; margin-bottom: 0.1rem; }

/* Differentiated by size and rule rather than by opacity: faded text drops
   below the contrast floor on the accent bubble in every theme. */
.reply-chip {
  display: block;
  margin: -0.1rem 0 0.25rem;
  padding-left: 0.55rem;
  border-left: 2px solid currentColor;
  font-size: var(--size-sm);
}

.unsent { font-style: italic; }

/* Reaction chips ride the bubble's lower edge, tucked in from the corner so
   they read as attached to the message rather than colliding with it. */
.reactions {
  display: flex;
  gap: 0.2rem;
  margin: -0.7rem 1rem 0;
  position: relative;
  z-index: 2;
}

.outgoing .reactions { flex-direction: row-reverse; }

.reaction {
  display: grid;
  place-items: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-size: var(--size-xs);
  line-height: 1;
}

/* One timestamp per run of messages; the full date is available as a tooltip
   on any bubble, so nothing is lost and the column stays quiet. */
.meta {
  margin: 0.15rem 0.85rem 0.35rem;
  font-size: var(--size-xs);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* Attachments ----------------------------------------------------------- */

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-2);
  max-width: min(38rem, 82%);
  margin-top: 0.2rem;
}

.outgoing .attachments { justify-content: flex-end; }

.attachment {
  display: block;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  line-height: 0;
  max-width: 100%;
  transition: transform 0.15s ease;
}

.attachment:hover { transform: translateY(-1px); }

/* Photos are part of the conversation, not the whole page: cap them so a
   single image never dominates the column. */
.attachment img,
.attachment video {
  display: block;
  max-width: 100%;
  max-height: 17rem;
  width: auto;
  height: auto;
  background: var(--surface-sunken);
}

@media (max-width: 34rem) {
  .attachment img, .attachment video { max-height: 14rem; }
}

/* `width` must be a length, not `min(20rem, 100%)`. An <audio> has no intrinsic
   width, so inside the shrink-to-fit `.attachment` flex item the percentage
   resolved against a container whose own width came from this element: the
   circular reference collapsed to 0 and every voice note rendered as a 1px
   sliver. Images escape it because they have intrinsic width. A definite
   length gives the flex item a base size, and `max-width` then shrinks it to
   fit a narrow column instead of overflowing. */
.attachment audio { display: block; width: 20rem; max-width: 100%; }

.file {
  display: flex;
  align-items: center;
  gap: var(--gap-2);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  color: inherit;
  text-decoration: none;
  line-height: 1.3;
  font-size: var(--size-sm);
  max-width: 100%;
}

.file:hover { border-color: var(--hairline-strong); }
.file svg { width: 1.1rem; height: 1.1rem; flex: 0 0 auto; color: var(--text-secondary); }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file.missing { color: var(--warn); border-style: dashed; }

/* Search results --------------------------------------------------------- */

.message.match .bubble { box-shadow: 0 0 0 2px var(--highlight-soft); }

/* The active result is state information, so its ring uses a colour verified
   at 3:1 against the page in every theme rather than a decorative yellow. */
.message.current .bubble {
  box-shadow: 0 0 0 2px var(--accent-strong), var(--shadow-pop);
}

.empty {
  max-width: var(--measure);
  margin: var(--gap-6) auto;
  padding: 0 var(--gap-4);
  text-align: center;
  color: var(--text-secondary);
}

.empty svg { width: 2.5rem; height: 2.5rem; color: var(--text-tertiary); }
.empty p { margin: var(--gap-3) 0 0; }

/* Footer ---------------------------------------------------------------- */

.colophon {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--gap-5) var(--gap-4) calc(var(--gap-6) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
  color: var(--text-tertiary);
  font-size: var(--size-sm);
  text-align: center;
}

.colophon p { margin: 0.15rem 0; }

/* --------------------------------------------------------------- responsive */

/* Phones: give bubbles more of the width, tighten chrome. */
@media (max-width: 34rem) {
  :root { --size-base: 1rem; }
  .topbar-inner { padding: var(--gap-2) var(--gap-3); }
  .searchbar { padding: 0 var(--gap-3) var(--gap-2); }
  .transcript { padding-inline: var(--gap-3); }
  .bubble, .attachments { max-width: 88%; }
  .identity p { display: none; }
  .avatar { width: 2.15rem; height: 2.15rem; }
}

/* Landscape phones and short windows: the header must not eat the view. */
@media (max-height: 30rem) and (orientation: landscape) {
  .topbar-inner { padding-block: var(--gap-1); }
  .avatar { width: 1.9rem; height: 1.9rem; }
  .identity p { display: none; }
  .day-label { margin-block: var(--gap-3) var(--gap-2); }
}

/* Wide displays: hold the measure, let the page breathe. */
@media (min-width: 90rem) {
  :root { --measure: 58rem; }
}

/* ------------------------------------------------------- user preferences */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Derived from each theme's own tokens rather than hardcoded colours, so the
   increased-contrast preference works in every theme and both appearances. */
@media (prefers-contrast: more) {
  :root {
    --text-secondary: color-mix(in srgb, var(--text) 88%, var(--surface));
    --text-tertiary: color-mix(in srgb, var(--text) 78%, var(--surface));
    --hairline: color-mix(in srgb, var(--text) 40%, transparent);
    --hairline-strong: color-mix(in srgb, var(--text) 60%, transparent);
  }
  .bubble { border: 1px solid var(--hairline-strong); }
  .day-label, .file, .attachment { border-color: var(--hairline-strong); }
}

/* Printing an album should produce a clean, readable document. */
@media print {
  :root { --surface: #fff; --text: #000; --bubble-in: #f0f0f0; }
  .topbar, .searchbar, .colophon { display: none !important; }
  .day-group { content-visibility: visible; }
  .transcript { max-width: none; padding: 0; }
  .bubble { border: 1px solid #ccc; color: #000 !important; background: #f4f4f4 !important; }
  .outgoing .bubble { background: #e4eeff !important; }
  .message:not(.turn-end) .meta { opacity: 1; }
  .attachment img { max-height: 12rem; }
}
