/* Our Daily Bread — phone-first styles. */

:root {
  --scale: 1;
  --bg: #f4efe6;
  --surface: #fffdf8;
  --paper: #fbf5e8;
  --paper-edge: #e9dfca;
  --ink: #2b2520;
  --muted: #74685b;
  --line: #e2d8c4;
  --accent: #8a5a2b;
  --accent-ink: #fffaf0;
  --accent-soft: #f1e3cc;
  --danger: #a23b2a;
  --shadow: 0 1px 2px rgb(60 40 20 / .08), 0 4px 14px rgb(60 40 20 / .08);
  --hl-yellow: rgb(255 214 74 / .45);
  --hl-green: rgb(126 200 120 / .38);
  --hl-blue: rgb(110 170 240 / .35);
  --hl-pink: rgb(240 130 170 / .35);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15120e;
  --surface: #201c17;
  --paper: #27221b;
  --paper-edge: #3a3227;
  --ink: #ede5d7;
  --muted: #a89c8c;
  --line: #3a332a;
  --accent: #d9a660;
  --accent-ink: #1d160d;
  --accent-soft: #3a2e1e;
  --danger: #e2826f;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 18px rgb(0 0 0 / .35);
  --hl-yellow: rgb(230 190 60 / .32);
  --hl-green: rgb(110 190 110 / .28);
  --hl-blue: rgb(100 160 235 / .3);
  --hl-pink: rgb(230 120 160 / .28);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-size: calc(17px * var(--scale)); -webkit-text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
svg { width: 1.4em; height: 1.4em; flex: none; }
/* The hidden icon sheet must take up no space, or the page scrolls a little. */
svg.sprite { position: absolute; top: 0; left: 0; width: 0; height: 0; overflow: hidden; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- App frame ---------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px;
  min-height: 52px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--ink);
  font-family: var(--serif); font-size: 1.15rem; font-weight: 600;
}
.brand svg { color: var(--accent); width: 1.6em; height: 1.6em; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--ink);
}
.icon-btn:active { background: var(--accent-soft); }
#themeToggle .moon { display: none; }
[data-theme="dark"] #themeToggle .moon { display: block; }
[data-theme="dark"] #themeToggle .sun { display: none; }

#view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  outline: none;
}
#view.fill { overflow: hidden; display: flex; flex-direction: column; }

.tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabbar-h);
  text-decoration: none;
  color: var(--muted);
  font-size: .78em;
  font-weight: 500;
}
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.4; }
.no-chrome .tabbar, .no-chrome .topbar { display: none; }
/* While reading, the reader's own bar replaces the site header, leaving more room for the page. */
.reading .topbar { display: none; }
.reading #view { padding-top: env(safe-area-inset-top); }
/* Buttons and bars grow only a little with the text-size setting, so the extra size goes to the scripture. */
.tabbar, .reader-bar, .reader-foot { font-size: calc(17px * min(var(--scale), 1.2)); }

/* ---------- Common pieces ---------- */

.page-pad { padding: 8px 16px 32px; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-label {
  font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.card-label svg { width: 1.1em; height: 1.1em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px;
  padding: 0 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-weight: 600; margin-bottom: 6px; }
.field small { display: block; color: var(--muted); margin-top: 4px; }
input[type="text"], input[type="password"], textarea {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: max(16px, 1rem); /* 16px+ stops iPhone zooming in */
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.error { color: var(--danger); font-weight: 500; margin: 0 0 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip {
  flex: none;
  min-height: 40px; padding: 0 16px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-weight: 500;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.segmented { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.segmented button {
  flex: 1; min-height: 44px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; color: var(--muted);
}
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg);
  padding: 12px 20px; border-radius: 999px;
  font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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

.auth {
  min-height: 100%;
  display: flex; flex-direction: column; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 20px 32px;
  max-width: 440px; margin: 0 auto;
}
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo svg { width: 64px; height: 64px; color: var(--accent); }
.auth-logo h1 { font-size: 2rem; margin: 8px 0 4px; }
.auth-switch { text-align: center; margin-top: 18px; }
.auth-switch button { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 8px; }

/* ---------- Home ---------- */

.greeting { margin: 4px 0 16px; }
.greeting h1 { margin: 0; }
.verse-day blockquote {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 1.3rem;
  line-height: 1.5;
}
.verse-day .ref { font-weight: 600; color: var(--muted); }
.reflection { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.reflection p { margin: 0 0 .7em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 8px; text-align: center;
}
.stat b { display: block; font-family: var(--serif); font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--muted); }
.actions { display: grid; gap: 10px; margin-bottom: 18px; }

/* ---------- Contents (book list) ---------- */

.toc-head { position: sticky; top: 0; background: var(--bg); padding: 4px 16px 10px; z-index: 2; }
.goto { display: flex; gap: 8px; margin: 10px 0; }
.goto input { flex: 1; }
.goto .btn { min-height: 52px; }
.book-list { list-style: none; margin: 0; padding: 0 16px 24px; }
.book-list a {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 58px;
  padding: 0 4px;
  border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--ink);
  font-family: var(--serif); font-size: 1.15rem;
}
.book-list a span { font-family: var(--sans); font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.book-list a span svg { width: 1em; height: 1em; }
.section-label { padding: 18px 4px 4px; font-size: .78rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); border-bottom: 1px solid var(--line); }

.num-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
}
.num-grid button, .num-grid a {
  display: grid; place-items: center;
  aspect-ratio: 1;
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600; font-size: 1.05rem;
}
.num-grid .current { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.num-grid .read { background: var(--accent-soft); }

/* ---------- Reader / the book ---------- */

.reader { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 12px; }
.reader-bar { display: flex; align-items: center; gap: 4px; padding: 2px 0 8px; }
.reader-title {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 44px; border: 0; background: transparent;
  font-family: var(--serif); font-size: 1.15em; font-weight: 600;
}
.reader-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-title svg { width: 1em; height: 1em; color: var(--muted); }
.size-btn { font-family: var(--serif); font-weight: 700; width: 44px; }
.size-btn small { font-size: .7em; }

.book {
  position: relative;
  flex: 1;
  min-height: 0;
  perspective: 2200px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
/* The stack of pages under the current one */
.book::before, .book::after {
  content: ""; position: absolute; inset: 0; border-radius: 4px 10px 10px 4px;
  background: var(--paper); border: 1px solid var(--paper-edge);
}
.book::before { transform: translate(6px, 6px); opacity: .55; }
.book::after { transform: translate(3px, 3px); opacity: .85; }

.page, .leaf-face {
  position: absolute; inset: 0;
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: 4px 10px 10px 4px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
/* spine shading on the left edge */
.page::before, .leaf-face::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 22px; pointer-events: none;
  background: linear-gradient(to right, rgb(0 0 0 / .12), transparent);
}
.page { z-index: 1; }

/* Text stops above a strip reserved for the page number, so they can never overlap. */
.page-content, .measure {
  position: absolute; inset: 0 0 2.4rem 0;
  padding: 22px 20px 4px 28px;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 1.12rem;
  line-height: 1.62;
}
.page-num {
  position: absolute; bottom: 0; left: 0; right: 0; height: 2.4rem;
  display: flex; align-items: center; justify-content: center;
  border-top: 1px solid color-mix(in srgb, var(--paper-edge) 60%, transparent);
  margin: 0 28px;
  font-size: .78rem; color: var(--muted); font-family: var(--serif);
}
.measure { visibility: hidden; position: absolute; pointer-events: none; overflow: hidden; }

.ch-head { text-align: center; margin: 0 0 14px; }
.ch-head .bk { font-size: .82rem; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.ch-head .ch { font-size: 1.6rem; font-weight: 600; display: block; }
.ch-head .ornament { display: block; color: var(--accent); font-size: .9rem; letter-spacing: .4em; margin-top: 2px; }

.v {
  display: block;
  margin: 0 0 .35em;
  padding: 1px 4px;
  margin-left: -4px;
  border-radius: 4px;
  cursor: pointer;
}
.v sup {
  font-family: var(--sans); font-size: .62em; font-weight: 700; color: var(--accent);
  margin-right: .3em; vertical-align: .45em;
}
.v .mark { color: var(--accent); font-size: .75em; margin-left: .3em; }
.v.hl-yellow { background: var(--hl-yellow); }
.v.hl-green { background: var(--hl-green); }
.v.hl-blue { background: var(--hl-blue); }
.v.hl-pink { background: var(--hl-pink); }
/* Selected verses get an outline (keeps any highlight color visible, doesn't move text). */
.v.selected { outline: 2px solid var(--accent); outline-offset: 0; }
.v.selected:not([class*="hl-"]) { background-color: var(--accent-soft); }
.v.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }
.end-of-book { text-align: center; color: var(--muted); margin-top: 2em; font-style: italic; }

/* The turning leaf */
.leaf {
  position: absolute; inset: 0; z-index: 5;
  transform-origin: left center;
  transform-style: preserve-3d;
  will-change: transform;
}
.leaf-face { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.leaf-face.back { transform: rotateY(180deg); background: var(--paper); }
.leaf-face.back::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to left, rgb(0 0 0 / .10), transparent 40%);
}
.leaf-shade {
  position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(to left, rgb(0 0 0 / .28), rgb(0 0 0 / 0) 70%);
  opacity: 0;
}

/* The strip under the book: page arrows normally, the action bar while verses are selected.
   Fixed height, so switching between them never changes the page size. */
.reader-foot { position: relative; flex: none; height: max(84px, 5.8em); }
.pager[hidden], .selbar[hidden], .hl-pop[hidden] { display: none !important; }
.pager {
  height: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.pager .hint { font-size: .75em; opacity: .8; }
.pager .turn {
  width: 64px; height: 56px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.pager .turn svg { width: 30px; height: 30px; }
.pager .turn[disabled] { opacity: .35; }
.pager .where { text-align: center; font-size: .85em; color: var(--muted); line-height: 1.3; }

.selbar { height: 100%; display: flex; flex-direction: column; justify-content: center; gap: .35em; padding: 4px 0 6px; }
.selbar-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 2px; }
.selbar-top b { font-family: var(--serif); font-size: .98em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selbar-clear {
  display: inline-flex; align-items: center; gap: 2px; flex: none;
  border: 0; background: none; color: var(--muted); font-size: .85em; font-weight: 600; padding: 4px 6px;
}
.selbar-clear svg { width: 1.1em; height: 1.1em; }
.selbar-actions { display: flex; gap: 6px; }
.act {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 3.3em; padding: 4px 2px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink);
  font-size: .72em; font-weight: 600;
  box-shadow: var(--shadow);
}
.act[hidden] { display: none; }
.act svg { width: 1.35em; height: 1.35em; }
.act:active { transform: translateY(1px); }
.act.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.act.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.act .dot { width: 1.25em; height: 1.25em; border-radius: 50%; border: 2px solid var(--muted); }
.act .dot.hl-yellow { background: var(--hl-yellow); border-color: rgb(220 175 20); }
.act .dot.hl-green { background: var(--hl-green); border-color: rgb(80 165 80); }
.act .dot.hl-blue { background: var(--hl-blue); border-color: rgb(75 135 215); }
.act .dot.hl-pink { background: var(--hl-pink); border-color: rgb(215 95 140); }
.hl-pop {
  position: absolute; bottom: calc(100% - 4px); left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; gap: 10px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .2);
}

/* ---------- Bottom sheets ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgb(0 0 0 / .35);
  opacity: 0; transition: opacity .2s;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 760px; margin: 0 auto;
  max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgb(0 0 0 / .2);
  transform: translateY(100%);
  transition: transform .25s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: none; }
.sheet-backdrop.open { opacity: 1; }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 4px 20px; }
.sheet-head h2 { margin: 0; font-size: 1.2rem; }
.sheet-body { overflow-y: auto; padding: 6px 20px 20px; }
.sheet-tall { height: 90dvh; max-height: 90dvh; }
.sheet-chat .sheet-body { padding: 0; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Passage chooser */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin-bottom: 14px; }
.crumbs button { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 6px 4px; }
.crumbs span { color: var(--muted); }
.crumbs b { padding: 6px 4px; }
.book-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.book-grid button {
  min-height: 50px; padding: 8px 14px; text-align: left;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  font-family: var(--serif); font-size: 1.05rem;
}
.pick-whole {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 62px; padding: 10px 16px;
  border: 1.5px solid var(--accent); border-radius: 14px; background: var(--accent-soft);
  text-align: left; font-weight: 600; font-size: 1.05rem;
}
.pick-whole svg { color: var(--accent); }
.pick-whole small { display: block; font-weight: 400; font-size: .85rem; color: var(--muted); }
.picker-h { font-family: var(--sans); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 20px 0 8px; }
.num-grid button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.picker-foot { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0 2px; margin-top: 8px; }
.link-btn { display: block; margin: 16px auto 0; padding: 10px; border: 0; background: none; color: var(--muted); text-decoration: underline; }

.verse-preview {
  font-family: var(--serif); font-size: 1.05rem; line-height: 1.5;
  background: var(--paper); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px;
  max-height: 8.5em; overflow-y: auto;
}
.swatches { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.swatch {
  width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center;
}
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface) inset; }
.swatch.none { background: var(--surface); color: var(--muted); }
.swatch[data-c="yellow"] { background: var(--hl-yellow); }
.swatch[data-c="green"] { background: var(--hl-green); }
.swatch[data-c="blue"] { background: var(--hl-blue); }
.swatch[data-c="pink"] { background: var(--hl-pink); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.sheet-actions .btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- Ask (chat) ---------- */

.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 0 12px 8px; }
.chat-head h1 { flex: 1; font-size: 1.4rem; margin: 0; }
.chat-head .btn { min-height: 42px; padding: 0 14px; font-size: .92rem; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
.msg { margin: 0 0 14px; max-width: 92%; }
.msg.user { margin-left: auto; }
.msg .bubble { padding: 12px 16px; border-radius: 18px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg .bubble p { margin: 0 0 .6em; }
.msg .bubble p:last-child, .msg .bubble ul:last-child, .msg .bubble ol:last-child { margin-bottom: 0; }
.msg .bubble ul, .msg .bubble ol { margin: 0 0 .6em; padding-left: 1.3em; }
.msg .ctx { font-size: .78rem; color: var(--muted); text-align: right; margin-top: 3px; }
.typing span { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.chat-intro { text-align: center; padding: 16px 8px; }
.chat-intro svg { width: 44px; height: 44px; color: var(--accent); }

.composer { border-top: 1px solid var(--line); padding: 8px 12px 10px; background: var(--bg); }
.chat.embedded .chat-head { padding: 0 12px 6px; }
.chat-head-space { flex: 1; }
.ctx-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.ctx-chip {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%;
  min-height: 40px; padding: 6px 12px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid transparent; border-radius: 999px;
  font-size: .9rem; font-weight: 600;
}
.ctx-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-chip svg { width: 1.1em; height: 1.1em; }
.ctx-chip.empty { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-weight: 500; }
.ctx-x {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: transparent; color: var(--muted);
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 52px; max-height: 40dvh; resize: none; border-radius: 26px; padding: 13px 18px; }
.send {
  width: 52px; height: 52px; flex: none; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.send[disabled] { opacity: .45; }

.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-list li { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.conv-list a { flex: 1; padding: 14px 4px; text-decoration: none; color: var(--ink); min-width: 0; }
.conv-list a b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list a small { color: var(--muted); }

/* ---------- Notes ---------- */

.note-item {
  display: block; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; border-left-width: 6px;
}
.note-item .ref { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.note-item .ref svg { width: 1em; height: 1em; color: var(--accent); }
.note-item .text { font-family: var(--serif); margin: 4px 0 0; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.note-item .note { margin: 8px 0 0; white-space: pre-wrap; }
.note-item.hl-yellow { border-left-color: rgb(230 185 30); }
.note-item.hl-green { border-left-color: rgb(90 170 90); }
.note-item.hl-blue { border-left-color: rgb(80 140 220); }
.note-item.hl-pink { border-left-color: rgb(220 100 145); }

/* ---------- Me ---------- */

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.size-control { display: flex; align-items: center; gap: 10px; }
.size-control .btn { width: 56px; padding: 0; font-family: var(--serif); }
.size-sample { font-family: var(--serif); font-size: 1.1rem; margin: 10px 0 0; color: var(--muted); }
.memory-summary { font-family: var(--serif); font-size: 1.05rem; line-height: 1.6; white-space: pre-wrap; }
.mem-group h3 { font-family: var(--sans); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 16px 0 6px; }
.mem-list { list-style: none; margin: 0; padding: 0; }
.mem-list li { display: flex; align-items: flex-start; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mem-list li span { flex: 1; padding-top: 10px; }
.mem-list .icon-btn { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Larger screens: a little more breathing room. */
@media (min-width: 700px) {
  .reader { padding: 0 24px; }
  .page-content, .measure { padding: 34px 40px 6px 48px; }
}
