/* Readover — a reading lamp for your own notes. */

@font-face {
  font-family: 'Literata';
  src: url('../vendor/literata-5.2.5/literata-latin-wght-normal.woff2') format('woff2');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Literata';
  src: url('../vendor/literata-5.2.5/literata-latin-ext-wght-normal.woff2') format('woff2');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Literata';
  src: url('../vendor/literata-5.2.5/literata-latin-wght-italic.woff2') format('woff2');
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

:root {
  --tabbar: calc(54px + env(safe-area-inset-bottom));
  --paper: #e8ebe3;
  --card: #f7f8f3;
  --ink: #1d2320;
  --text: var(--ink);
  --text-muted: var(--muted);
  --muted: #4b5650;
  --faint: #5f6a62; /* text on paper and cards: 4.5:1 or more */
  --line: #d3d8cf;
  --action: #2e5b4f;
  --action-ink: #f7f8f3;
  --marker: #f3d54a;
  --marker-ink: #1d2320;
  --star: #c9971b;
  --danger: #a33a2c;
  --overlay: rgba(20, 24, 22, 0.42);
  --healthy: #3f8f5a;
  --thirsty: #b87a12;
  --wilting: #8b7b68;
  --wilting-ink: #665a4c;

  --serif: 'Literata', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --measure: 34rem;
  --top: calc(52px + env(safe-area-inset-top));
  --bottom: env(safe-area-inset-bottom);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #141816;
    --card: #1c221f;
    --ink: #e3e7df;
    --text: var(--ink);
    --text-muted: var(--muted);
    --muted: #aab4ad;
    --faint: #8a948c;
    --line: #2c3430;
    --action: #8dbfaa;
    --action-ink: #141816;
    --marker: #e8c547;
    --marker-ink: #141816;
    --star: #e8c547;
    --danger: #e08a7c;
    --overlay: rgba(0, 0, 0, 0.55);
    --healthy: #6cc08a;
    --thirsty: #e0a540;
    --wilting: #a8957d;
    --wilting-ink: #b9a68e;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --paper: #141816;
  --card: #1c221f;
  --ink: #e3e7df;
  --text: var(--ink);
  --text-muted: var(--muted);
  --muted: #aab4ad;
  --faint: #8a948c;
  --line: #2c3430;
  --action: #8dbfaa;
  --action-ink: #141816;
  --marker: #e8c547;
  --marker-ink: #141816;
  --star: #e8c547;
  --danger: #e08a7c;
  --overlay: rgba(0, 0, 0, 0.55);
  --healthy: #6cc08a;
  --thirsty: #e0a540;
  --wilting: #a8957d;
  --wilting-ink: #b9a68e;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
}
body {
  overflow: hidden;
  overscroll-behavior: none;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}
[tabindex='-1']:focus {
  outline: none;
}
a {
  color: var(--action);
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.i {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.i-sm {
  width: 16px;
  height: 16px;
}
.i-lg {
  width: 32px;
  height: 32px;
}
.glyph,
.growth-glyph,
.growth-tag svg,
.growth-badge svg,
.grow svg,
.grow .glyph {
  max-width: 16px;
  max-height: 16px;
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
  flex: none;
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  height: var(--top);
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Desktop Window Controls Overlay (WCO) Integration */
@media (display-mode: window-controls-overlay) {
  :root {
    --top: env(titlebar-area-height, calc(52px + env(safe-area-inset-top)));
  }

  .topbar {
    position: fixed;
    top: env(titlebar-area-y, 0);
    left: env(titlebar-area-x, 0);
    width: env(titlebar-area-width, 100%);
    height: env(titlebar-area-height, var(--top));
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    -webkit-app-region: drag;
    app-region: drag;
  }

  .topbar button,
  .topbar a,
  .topbar input,
  .topbar .brand,
  .topbar .topbar-actions,
  .topbar .scope-chip,
  .topbar .scope-btn,
  .topbar .icon-btn,
  .topbar .sync-dot {
    -webkit-app-region: no-drag;
    app-region: no-drag;
  }
}
.brand {
  border: 0;
  background: none;
  padding: 6px 0;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.scope-chip,
.scope-btn,
#scope-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 46vw;
  min-width: 0;
  min-height: 44px;
  height: 44px;
  box-sizing: border-box;
  flex-shrink: 1;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px 6px 14px;
  font-size: 0.875rem;
  color: var(--muted);
}
.scope-chip span,
.scope-btn span,
#scope-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
}
.icon-btn:hover {
  color: var(--ink);
}
#star-filter[aria-pressed='true'] {
  color: var(--star);
}
#star-filter[aria-pressed='true'] .i {
  fill: currentColor;
}

/* ---------- Feed ---------- */
.feed {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  outline: none;
}
.feed::-webkit-scrollbar {
  display: none;
}
.card {
  position: relative;
  height: 100vh;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  place-items: center;
  padding: calc(var(--top) + 8px) 72px calc(24px + var(--bottom)) 24px;
  user-select: none;
  -webkit-user-select: none;
}
.card-body {
  width: 100%;
  max-width: var(--measure);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  position: relative;
}

.card-where {
  position: static;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 0 10px;
  font-size: 0.8125rem;
  color: var(--faint);
}
.card-where .crumb {
  color: var(--muted);
}
.card-where .crumb + .crumb::before {
  content: '/';
  margin: 0 0.4em;
  color: var(--faint);
}

.card-title {
  position: static;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.6rem, 1.2rem + 2vw, 2.3rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 12px;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.card-body .preview,
.card-body .prose {
  position: relative;
  width: 100%;
}

/* Note preview: clipped, with a fade that tells you there is more */
.preview {
  position: relative;
  min-height: 0;
  overflow: hidden;
  flex: 0 1 auto;
}
.preview.clipped::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 5rem;
  background: linear-gradient(to bottom, transparent, var(--paper));
  pointer-events: none;
}
.more {
  align-self: flex-start;
  margin-top: 14px;
  border: 0;
  background: none;
  padding: 6px 0;
  color: var(--action);
  font-weight: 600;
  font-size: 0.9375rem;
}

/* Long-form prose, shared by cards and the reader */
.prose {
  font-family: var(--serif);
  font-size: clamp(1.0625rem, 1rem + 0.3vw, 1.1875rem);
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.prose > :first-child {
  margin-top: 0;
}
.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose pre,
.prose table {
  margin: 0 0 1em;
}
.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-weight: 600;
  line-height: 1.25;
  margin: 1.6em 0 0.5em;
}
.prose h1 {
  font-size: 1.45em;
}
.prose h2 {
  font-size: 1.25em;
}
.prose h3,
.prose h4 {
  font-size: 1.05em;
}
.prose ul,
.prose ol {
  padding-left: 1.3em;
}
.prose li + li {
  margin-top: 0.25em;
}
.prose blockquote {
  margin-left: 0;
  padding-left: 1em;
  border-left: 3px solid var(--marker);
  color: var(--ink);
  font-style: italic;
}
.prose mark,
.hl-quote mark {
  background: linear-gradient(transparent 12%, color-mix(in srgb, var(--marker) 70%, transparent) 12% 92%, transparent 92%);
  color: inherit;
  padding: 0 0.1em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background: color-mix(in srgb, var(--line) 60%, transparent);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}
.prose pre {
  overflow-x: auto;
  padding: 0.9em 1em;
  background: color-mix(in srgb, var(--line) 45%, transparent);
  border-radius: 6px;
  font-size: 0.85em;
  line-height: 1.5;
}
.prose pre code {
  background: none;
  padding: 0;
}
.prose pre.plain {
  font-family: var(--serif);
  font-size: 1em;
  white-space: pre-wrap;
  background: none;
  padding: 0;
}
.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}
.prose hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2em 0;
}
.prose table {
  border-collapse: collapse;
  font-size: 0.9em;
  display: block;
  overflow-x: auto;
}
.prose th,
.prose td {
  min-width: 6.5em;
  border-bottom: 1px solid var(--line);
  padding: 0.4em 0.7em;
  text-align: left;
}
.prose .wikilink {
  color: var(--action);
  border-bottom: 1px dotted currentColor;
}
.prose input[type='checkbox'] {
  margin-right: 0.4em;
}

/* Highlight card: the one loud thing in the app */
.card-highlight .card-body {
  justify-content: center;
}
.hl-quote {
  font-family: var(--serif);
  font-weight: 450;
  font-size: clamp(1.5rem, 1.05rem + 2.4vw, 2.35rem);
  line-height: 1.42;
  letter-spacing: -0.01em;
  margin: 0;
  overflow: hidden;
  text-wrap: pretty;
}
.hl-quote.long {
  font-size: clamp(1.2rem, 1rem + 1.2vw, 1.6rem);
  line-height: 1.5;
}
.hl-quote .swipe {
  background: linear-gradient(transparent 14%, var(--marker) 14% 90%, transparent 90%);
  color: var(--marker-ink);
  padding: 0 0.12em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.hl-quote p {
  margin: 0 0 0.6em;
}
.hl-quote p:last-child {
  margin-bottom: 0;
}
.hl-note {
  margin: 18px 0 0;
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 1.0625rem;
}
.hl-from {
  margin-top: 28px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.4;
}
.hl-from b {
  display: block;
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.0625rem;
}

/* A seed: a highlight from an export, waiting to become an insight */
.seed-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}
.seed-label {
  font-size: 0.8125rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.seed-label::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--action);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--action) 20%, transparent);
  vertical-align: 1px;
}
.water-btn {
  padding: 8px 18px;
  border: 0;
}
.water-btn svg,
.rail .water-btn svg {
  width: 20px;
  height: 20px;
  max-width: 20px;
  max-height: 20px;
  aspect-ratio: 1 / 1;
}
.seed-done {
  font-size: 0.875rem;
  color: var(--action);
  font-weight: 600;
}

/* Book card */
.card-book .card-body {
  align-items: center;
  text-align: center;
}
.card-book-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
}
.card-book-cover {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 1rem auto;
}
.cover {
  width: min(62vw, 270px, 40dvh);
  aspect-ratio: 2 / 3;
  border-radius: 3px 8px 8px 3px;
  overflow: hidden;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.45);
  border: 0;
  padding: 0;
  background: var(--card);
  flex: none;
}
.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cover-plain {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px 18px;
  text-align: left;
  color: #f5f3ea;
  font-family: var(--serif);
  background: var(--tone, #2e5b4f);
}
.cover-plain strong {
  font-size: 1.35rem;
  line-height: 1.2;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.cover-plain span {
  font-size: 0.85rem;
  opacity: 0.8;
}
.book-title {
  font-family: var(--serif);
  font-size: clamp(1.25rem, 1.1rem + 0.8vw, 1.6rem);
  font-weight: 600;
  line-height: 1.2;
  margin: 26px 0 4px;
  text-wrap: balance;
}
.card-book-title,
.feed-card .card-title,
.card-book .book-title {
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.book-author {
  color: var(--muted);
  margin: 0;
}
.book-progress {
  width: min(240px, 70%);
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 20px auto 0;
  overflow: hidden;
}
.book-progress > i {
  display: block;
  height: 100%;
  background: var(--action);
}
.btn-read {
  margin-top: 18px;
}

/* Right-hand rail, reels-style */
.rail {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: calc(28px + var(--bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rail button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--card) 80%, transparent);
  color: var(--muted);
  box-shadow: 0 0 0 1px var(--line);
}
.rail button:hover {
  color: var(--ink);
}
.rail .rail-more-dots {
  font-size: 1.4rem;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -1px;
}
.rail .star-btn[aria-pressed='true'] {
  color: var(--star);
}
.rail .star-btn[aria-pressed='true'] .i {
  fill: currentColor;
}
.rail .star-btn.pop .i {
  animation: pop 0.35s ease;
}
@keyframes pop {
  50% {
    transform: scale(1.35);
  }
}
.rail .water-btn {
  color: var(--muted);
}
.rail .water-btn:hover {
  color: var(--healthy);
}
.rail .water-btn .i,
.rail .water-btn .glyph {
  width: 20px;
  height: 20px;
}
.rail .water-btn:active {
  transform: scale(0.92);
}

/* Loading / empty / error */
.skeleton {
  width: 100%;
  max-width: var(--measure);
}
.skeleton i {
  display: block;
  height: 14px;
  margin: 12px 0;
  border-radius: 4px;
  background: var(--line);
  opacity: 0.6;
}
.skeleton i:first-child {
  height: 32px;
  width: 70%;
  margin-bottom: 24px;
}
.skeleton i:nth-child(3) {
  width: 92%;
}
.skeleton i:last-child {
  width: 60%;
}
.card-message .card-body {
  gap: 14px;
  overflow-y: auto; /* small screens: the buttons stay reachable */
}
.card-message h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.6rem, 1.3rem + 1.5vw, 2.1rem);
  line-height: 1.2;
  margin: 0;
}
.card-message p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 1.0625rem;
}
.card-message .row-actions {
  margin-top: 10px;
}
.card-error .error-text {
  color: var(--danger);
  font-size: 0.9375rem;
}

/* ---------- Buttons and fields ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.9375rem;
}
.btn:hover {
  border-color: var(--faint);
}
.btn-primary {
  background: var(--action);
  border-color: var(--action);
  color: var(--action-ink);
}
.btn-primary:hover {
  border-color: var(--action);
  filter: brightness(1.08);
}
.btn-quiet {
  border-color: transparent;
  background: none;
  color: var(--muted);
}
.btn[disabled] {
  opacity: 0.55;
  cursor: progress;
}
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--muted);
  min-width: 0;
}
.field input,
.field select,
.field textarea,
.settings-group > input,
.token-row input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  color: var(--ink);
}
.field textarea {
  font-family: var(--serif);
  line-height: 1.55;
  resize: vertical;
}
.field summary {
  cursor: pointer;
}
.field details[open] summary,
details.field[open] summary {
  margin-bottom: 6px;
}
.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field-trio {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 12px;
}
.destinations-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 14px;
}
.destination-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.destination-card h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

/* ---------- Sheets (native <dialog>) ---------- */
.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  border-radius: 18px 18px 0 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
}
.sheet::backdrop,
.sheet-backdrop {
  background: var(--overlay);
  pointer-events: auto;
}
.sheet[open] {
  animation: sheet-in 0.22s ease-out;
}
@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}
@media (min-width: 640px) {
  .sheet {
    margin: auto;
    border-radius: 14px;
    overflow: hidden;
  }
  .sheet-inner {
    padding-bottom: 24px;
  }
}
.sheet-tall {
  height: 88dvh;
}
.sheet-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0 20px calc(24px + var(--bottom));
  height: 100%;
  overflow-y: auto;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  /* Sticky at the very top, so nothing shows above it while scrolling. */
  padding: 16px 0 12px;
  margin: 0;
}
.sheet h2 {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0;
}
.sheet h3 {
  font-size: 1rem;
  margin: 0 0 8px;
}
.hint {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
  margin: 0 0 10px;
}
.version {
  text-align: center;
  color: var(--faint);
}
.field.field-fill {
  flex: 1 0 auto;
  min-height: 180px;
  display: flex;
  flex-direction: column;
}
.field.field-fill textarea {
  flex: 1;
  min-height: 180px; /* grows into spare room; comfortable visible height */
  resize: vertical;
}

.seg {
  border: 0;
  padding: 3px;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  background: var(--paper);
  border-radius: 12px;
}
.seg label {
  flex: 1 1 auto;
}
.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.seg span {
  display: block;
  text-align: center;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
}
.seg input:checked + span {
  background: var(--card);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--line);
}
.seg input:focus-visible + span {
  outline: 2px solid var(--action);
}

.source-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}
.source {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.source-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.source-detail {
  font-size: 0.8125rem;
  color: var(--muted);
  grid-column: 1;
  line-height: 1.45;
}
.source-detail .warn {
  color: var(--danger);
}
.source-actions {
  grid-row: 1 / span 2;
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 2px;
}
.source-actions button {
  border: 0;
  background: none;
  color: var(--action);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px;
}
.source-actions .remove {
  color: var(--danger);
}
.empty-sources {
  color: var(--muted);
  font-size: 0.9375rem;
  padding: 14px 0;
}
.repo-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  background: var(--paper);
}
.repo-form .field input {
  background: var(--card);
}
.edit-source-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 0;
}
.edit-source-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.password-input-wrap {
  display: flex;
  align-items: center;
  position: relative;
  width: 100%;
}
.password-input-wrap input {
  width: 100%;
  padding-right: 42px;
}
.password-toggle-btn {
  position: absolute;
  right: 6px;
  background: none;
  border: 0;
  padding: 6px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.password-toggle-btn:hover {
  color: var(--ink);
}
.edit-source-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.settings-group {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.keys dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 18px;
  margin: 0;
  font-size: 0.875rem;
}
.keys dt {
  color: var(--ink);
  font-weight: 600;
}
.keys dd {
  margin: 0;
  color: var(--muted);
}
@media (pointer: coarse) {
  .keys {
    display: none;
  }
}

/* ---------- Full-screen readers ---------- */
.reader {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  animation: reader-in 0.2s ease-out;
}
@keyframes reader-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}
.reader-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
  min-height: var(--top);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.reader-bar .title {
  flex: 1;
  min-width: 0;
  font-size: 0.9375rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-bar .status {
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
}
.reader-bar .btn {
  padding: 7px 14px;
}
.reader-bar .star-btn[aria-pressed='true'] {
  color: var(--star);
}
.reader-bar .star-btn[aria-pressed='true'] .i {
  fill: currentColor;
}
.reader-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
}

/* Floating Reader Action Dock - Botanical Theme */
.reader-dock {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: color-mix(in srgb, var(--surface, #fcfbf9) 94%, transparent) !important;
  border: 1px solid color-mix(in srgb, var(--line, #e2ded6) 80%, transparent) !important;
  box-shadow: 0 8px 24px -4px rgba(28, 25, 23, 0.08), 0 2px 6px -1px rgba(28, 25, 23, 0.04) !important;
  border-radius: 9999px;
  padding: 6px 10px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  padding-top: env(safe-area-inset-top, 0px);
  z-index: 60;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  max-width: calc(100vw - 32px);
}

.reader-dock[hidden] {
  display: none !important;
}

.reader-dock-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9999px;
  background: transparent;
  border: none;
  color: var(--text, #1c1917) !important;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px; /* WCAG touch target */
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.reader-dock-btn svg {
  width: 20px;
  height: 20px;
  max-width: 20px;
  max-height: 20px;
  aspect-ratio: 1 / 1;
}

.reader-dock-btn:hover {
  background: color-mix(in srgb, var(--text, #1c1917) 6%, transparent) !important;
}

.reader-dock-btn:active {
  transform: scale(0.97);
}

/* Primary Action: Deep Botanical Accent instead of electric blue */
.reader-dock-btn-primary {
  color: var(--healthy, #2d5a3f) !important; /* Forest / Garden Green */
  font-weight: 600 !important;
}

.reader-dock-btn-primary svg {
  stroke: var(--healthy, #2d5a3f) !important;
}

.reader-dock-divider {
  width: 1px;
  height: 18px;
  background: var(--line, #e2ded6);
  margin: 0 2px;
}

/* ---------- Transient Chrome for Book & Document Readers ---------- */
.reader.reader-doc {
  background: var(--paper);
  position: fixed;
  inset: 0;
  z-index: 55;
  overflow: hidden;
}

.reader-doc .reader-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 25;
  transition: transform 0.24s cubic-bezier(0.2, 0.9, 0.4, 1), opacity 0.18s ease;
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
  background: color-mix(in srgb, var(--paper, #fcfbf9) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
}

.reader-doc.chrome-hidden .reader-bar {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.reader-doc .epub-stage,
.reader-doc .pdf-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Full-Page Authoring Canvas (.writer-canvas) ---------- */
#writer-canvas,
.writer-canvas {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: auto;
  background: var(--bg, #fbf9f5);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: writer-in 0.22s ease-out;
}

.writer-canvas[hidden] {
  display: none !important;
}

@keyframes writer-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

body.has-writer {
  overflow: hidden !important;
}

/* Minimal Header Strip */
.writer-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: var(--top, 52px);
  min-height: 52px;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line, #e2ded6);
  background: color-mix(in srgb, var(--bg, #fbf9f5) 96%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 25;
}

.writer-crumbs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 50vw;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.writer-crumbs:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  color: var(--ink);
}

.writer-crumb-src {
  font-weight: 500;
}

.writer-crumb-sep {
  opacity: 0.5;
}

.writer-crumb-folder {
  color: var(--ink);
  font-weight: 600;
}

.writer-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.writer-status {
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
}

.writer-done-btn {
  background: var(--healthy, #2d5a3f) !important;
  color: #ffffff !important;
  border: none !important;
  border-radius: 9999px !important;
  padding: 6px 16px !important;
  font-weight: 600 !important;
  font-size: 0.875rem !important;
  min-height: 36px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.writer-done-btn:hover {
  background: color-mix(in srgb, var(--healthy, #2d5a3f) 85%, #000) !important;
}

.writer-done-btn:active {
  transform: scale(0.97);
}

/* Scroll & Ergonomic 68ch Measure */
.writer-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

.writer-measure {
  max-width: 68ch;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 80px;
  box-sizing: border-box;
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  pointer-events: auto;
  overscroll-behavior-y: contain;
}

.writer-title {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--serif);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink, #1c1917);
  margin-bottom: 20px;
  padding: 0;
}

.writer-title::placeholder {
  color: color-mix(in srgb, var(--muted) 65%, transparent);
}

.writer-body {
  position: relative;
  z-index: 1;
  pointer-events: auto;
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink, #1c1917);
  flex: 1;
  min-height: 360px;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.writer-body::placeholder {
  color: color-mix(in srgb, var(--muted) 60%, transparent);
  font-style: italic;
}

/* Sticky Virtual Keyboard Accessory Bar */
.writer-accessory-bar {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  padding-top: env(safe-area-inset-top, 0px);
  background: color-mix(in srgb, var(--surface, #fcfbf9) 95%, transparent);
  border-top: 1px solid var(--line, #e2ded6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 20;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.writer-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--line, #e2ded6);
  background: var(--card, #ffffff);
  color: var(--ink, #1c1917);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 40px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.writer-bar-btn:hover {
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border-color: var(--action);
}

.writer-bar-btn:active {
  transform: scale(0.97);
}

.writer-btn-glyph {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
}

/* Sliding Research Drawer */
.research-drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 54dvh;
  max-height: 540px;
  background: var(--card, #fbf9f5);
  border-top: 1px solid var(--line, #e2ded6);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 32px rgba(28, 25, 23, 0.14);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.research-drawer.open {
  transform: translateY(0);
}

.research-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px 8px;
  border-bottom: 1px solid var(--line, #e2ded6);
}

.research-drawer-title {
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink);
}

.research-drawer-search {
  padding: 10px 18px;
  border-bottom: 1px solid var(--line, #e2ded6);
}

.research-drawer-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line, #e2ded6);
  background: var(--paper, #f7f8f3);
  font-size: 0.875rem;
  color: var(--ink);
  outline: none;
}

.research-drawer-input:focus {
  border-color: var(--action);
}

.research-drawer-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Desktop Research Drawer Side-Panel */
@media (min-width: 1024px) {
  .research-drawer {
    top: var(--top, 52px);
    bottom: 0;
    right: 0;
    left: auto;
    width: 420px;
    height: auto;
    max-height: none;
    border-top: none;
    border-left: 1px solid var(--line, #e2ded6);
    border-radius: 0;
    box-shadow: -8px 0 32px rgba(28, 25, 23, 0.08);
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .research-drawer.open {
    transform: translateX(0);
  }
}
.reader-article {
  max-width: 38rem;
  margin: 0 auto;
  padding: 32px 22px calc(80px + var(--bottom));
  user-select: text;
  -webkit-user-select: text;
}
.reader-article .card-where {
  margin-bottom: 10px;
}
.reader-article .card-title {
  margin-bottom: 26px;
}
.reader-article .prose {
  font-size: clamp(1.0625rem, 1rem + 0.35vw, 1.2rem);
  line-height: 1.7;
}
.reader-foot {
  margin-top: 40px;
  font-size: 0.875rem;
  color: var(--faint);
}
.flash {
  animation: flash 2.2s ease-out;
}
@keyframes flash {
  0%,
  40% {
    background: color-mix(in srgb, var(--marker) 55%, transparent);
  }
}
.editor {
  max-width: 44rem;
  margin: 0 auto;
  padding: 16px 16px calc(120px + var(--bottom));
}
/* The textarea grows to fit the note, so the page has a single scroll area
   (a short box scrolling inside a scrolling page is unusable on phones). */
.editor textarea {
  display: block;
  width: 100%;
  min-height: 60vh;
  border: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  background: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--ink);
}

/* PDF */
.pdf-stage {
  flex: 1;
  overflow: auto;
  padding: 16px 12px calc(40px + var(--bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: color-mix(in srgb, var(--paper) 70%, var(--line));
}
.pdf-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
}
.pdf-wrap .pdf-stage {
  flex: 1;
}
.pdf-page {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  flex: none;
  max-width: 100%;
}
.pdf-page canvas {
  display: block;
  width: 100%;
  height: 100%;
}
/* PDF.js text layer (selectable, invisible text over the page image) */
.textLayer {
  position: absolute;
  text-align: initial;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  z-index: 0;
  user-select: text;
  -webkit-user-select: text;
}
.textLayer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.textLayer span.markedContent {
  top: 0;
  height: 0;
}
.textLayer ::selection {
  background: color-mix(in srgb, var(--marker) 55%, transparent);
}
.textLayer br::selection {
  background: transparent;
}
.textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  cursor: default;
  user-select: none;
}
.textLayer span.ro-hl {
  background: rgba(243, 213, 74, 0.45);
  border-radius: 2px;
}
.flash-page {
  animation: flash-page 2.4s ease-out;
}
@keyframes flash-page {
  0%,
  35% {
    box-shadow: 0 0 0 4px var(--marker), 0 1px 4px rgba(0, 0, 0, 0.18);
  }
}

/* EPUB */
.epub-stage {
  flex: 1;
  position: relative;
  min-height: 0;
}
.epub-area {
  position: absolute;
  inset: 8px 0 calc(8px + var(--bottom));
  max-width: 42rem;
  margin: 0 auto;
}
.epub-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18%;
  max-width: 120px;
  border: 0;
  background: none;
  z-index: 2;
  color: transparent;
}
.epub-nav.prev {
  left: 0;
}
.epub-nav.next {
  right: 0;
}
@media (hover: hover) {
  .epub-nav:hover {
    color: var(--faint);
    font-size: 2rem;
  }
}
/* ---------- Reading Appearance Customizer & Themes ---------- */

.reader-bar .appearance-btn {
  font-family: var(--serif, Georgia, serif);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.5px;
  min-width: 44px;
  min-height: 44px;
}
.reader-bar .appearance-btn .btn-aa {
  display: inline-block;
  line-height: 1;
}

.appearance-popover {
  position: absolute;
  top: calc(var(--top, 52px) + 6px);
  right: 12px;
  z-index: 80;
  width: 300px;
  max-width: calc(100vw - 24px);
  background: var(--surface, #fcfbf9);
  border: 1px solid var(--line, #e2ded6);
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(28, 25, 23, 0.16);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-sizing: border-box;
  animation: popover-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popover-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.appearance-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.appearance-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted, #78716c);
}

.appearance-themes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: none;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 6px 4px;
  cursor: pointer;
  min-height: 44px;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.theme-swatch:hover {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

.theme-swatch.is-active {
  border-color: var(--healthy, #2d5a3f);
  background: color-mix(in srgb, var(--healthy) 8%, transparent);
}

.swatch-preview {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}

.swatch-preview.theme-paper {
  background: #fbf9f5;
  border-color: #d6d3cb;
}

.swatch-preview.theme-sepia {
  background: #f4ecd8;
  border-color: #c9bc9c;
}

.swatch-preview.theme-dark {
  background: #1e1e1d;
  border-color: #44403c;
}

.swatch-preview.theme-night {
  background: #000000;
  border-color: #333333;
}

.swatch-name {
  font-size: 0.75rem;
  font-weight: 500;
  color: inherit;
}

.appearance-seg {
  display: flex;
  background: var(--paper, #f5f4ef);
  border: 1px solid var(--line, #e2ded6);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.appearance-seg .seg-btn {
  flex: 1;
  border: 0;
  background: none;
  border-radius: 6px;
  padding: 8px 10px;
  min-height: 36px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}

.appearance-seg .seg-btn.is-active {
  background: var(--surface, #ffffff);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.appearance-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--paper, #f5f4ef);
  border: 1px solid var(--line, #e2ded6);
  border-radius: 8px;
  padding: 4px;
}

.stepper-btn {
  min-height: 36px;
  min-width: 44px;
  padding: 4px 14px;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: 6px;
}

.stepper-val {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
  min-width: 50px;
  text-align: center;
}

/* Reader Appearance Container Themes */
.reader[data-reader-theme='sepia'] {
  background: #f4ecd8 !important;
  color: #433422 !important;
}
.reader[data-reader-theme='sepia'] .reader-bar {
  background: #ede3cc !important;
  color: #433422 !important;
  border-bottom-color: #d8cdb4 !important;
}
.reader[data-reader-theme='sepia'] .reader-bar .title,
.reader[data-reader-theme='sepia'] .reader-bar .status {
  color: #7d6951 !important;
}
.reader[data-reader-theme='sepia'] .appearance-popover {
  background: #f7f0df !important;
  border-color: #dfd4be !important;
  color: #433422 !important;
}
.reader[data-reader-theme='sepia'] .appearance-seg,
.reader[data-reader-theme='sepia'] .appearance-stepper {
  background: #ece3cf !important;
  border-color: #ded3bd !important;
}
.reader[data-reader-theme='sepia'] .appearance-seg .seg-btn.is-active {
  background: #fbf6ec !important;
  color: #433422 !important;
}
.reader[data-reader-theme='sepia'] .pdf-stage {
  background: #dfd4be !important;
}
.reader[data-reader-theme='sepia'] .pdf-page {
  background: #f4ecd8 !important;
  box-shadow: 0 1px 4px rgba(67, 52, 34, 0.15) !important;
}
.reader[data-reader-theme='sepia'] .pdf-page canvas {
  filter: sepia(0.4) contrast(0.95) brightness(0.96) !important;
}

.reader[data-reader-theme='dark'] {
  background: #1e1e1d !important;
  color: #e7e5e4 !important;
}
.reader[data-reader-theme='dark'] .reader-bar {
  background: #181716 !important;
  color: #e7e5e4 !important;
  border-bottom-color: #2e2c29 !important;
}
.reader[data-reader-theme='dark'] .reader-bar .title,
.reader[data-reader-theme='dark'] .reader-bar .status {
  color: #a8a29e !important;
}
.reader[data-reader-theme='dark'] .appearance-popover {
  background: #242220 !important;
  border-color: #383531 !important;
  color: #e7e5e4 !important;
}
.reader[data-reader-theme='dark'] .appearance-seg,
.reader[data-reader-theme='dark'] .appearance-stepper {
  background: #191817 !important;
  border-color: #2e2c29 !important;
}
.reader[data-reader-theme='dark'] .appearance-seg .seg-btn.is-active {
  background: #2d2b29 !important;
  color: #f5f5f4 !important;
}
.reader[data-reader-theme='dark'] .pdf-stage {
  background: #141413 !important;
}
.reader[data-reader-theme='dark'] .pdf-page {
  background: #1e1e1d !important;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5) !important;
}
.reader[data-reader-theme='dark'] .pdf-page canvas {
  filter: invert(0.88) hue-rotate(180deg) contrast(0.92) brightness(0.95) !important;
}

.reader[data-reader-theme='night'] {
  background: #000000 !important;
  color: #cccccc !important;
}
.reader[data-reader-theme='night'] .reader-bar {
  background: #000000 !important;
  color: #cccccc !important;
  border-bottom-color: #1a1a1a !important;
}
.reader[data-reader-theme='night'] .reader-bar .title,
.reader[data-reader-theme='night'] .reader-bar .status {
  color: #888888 !important;
}
.reader[data-reader-theme='night'] .appearance-popover {
  background: #111111 !important;
  border-color: #222222 !important;
  color: #cccccc !important;
}
.reader[data-reader-theme='night'] .appearance-seg,
.reader[data-reader-theme='night'] .appearance-stepper {
  background: #0a0a0a !important;
  border-color: #1e1e1e !important;
}
.reader[data-reader-theme='night'] .appearance-seg .seg-btn.is-active {
  background: #1f1f1f !important;
  color: #ffffff !important;
}
.reader[data-reader-theme='night'] .pdf-stage {
  background: #000000 !important;
}
.reader[data-reader-theme='night'] .pdf-page {
  background: #000000 !important;
  box-shadow: 0 0 0 1px #1a1a1a !important;
}
.reader[data-reader-theme='night'] .pdf-page canvas {
  filter: invert(1) hue-rotate(180deg) contrast(0.95) !important;
}

.selection-bar {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--bottom));
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: var(--ink);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.selection-bar .btn {
  border: 0;
}
.selection-bar .btn-quiet {
  color: var(--paper);
}
.selection-bar .btn-mark {
  background: var(--marker);
  color: var(--marker-ink);
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.reader-error {
  margin: 20vh auto 0;
  max-width: 26rem;
  padding: 0 24px;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- Staging Banner (PWA Ingestion) ---------- */
.staging-banner {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  padding-top: env(safe-area-inset-top, 0px);
  background: color-mix(in srgb, var(--card) 95%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 35;
  transition: opacity 0.2s ease, transform 0.2s ease;
  animation: staging-banner-slide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes staging-banner-slide {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.staging-banner.is-closing {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}
.staging-banner-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}
.staging-banner-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--healthy) 14%, transparent);
  color: var(--healthy);
  flex-shrink: 0;
}
.staging-banner-icon .i {
  width: 18px;
  height: 18px;
  fill: currentColor;
}
.staging-banner-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  gap: 2px;
  line-height: 1.25;
}
.staging-banner-provenance {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  font-family: var(--sans);
}
.staging-banner-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--sans);
}
.staging-banner-size {
  font-size: 0.8125rem;
  font-weight: normal;
  color: var(--muted);
  margin-left: 6px;
}
.staging-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.btn-staging-commit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--healthy);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  min-height: 36px;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-staging-commit:hover {
  background: color-mix(in srgb, var(--healthy) 85%, #000);
}
.btn-staging-commit:active {
  transform: scale(0.98);
}
.btn-staging-commit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-staging-commit .i {
  width: 15px;
  height: 15px;
  fill: currentColor;
}
.btn-staging-dismiss {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: var(--sans);
  cursor: pointer;
  min-height: 36px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.btn-staging-dismiss:hover {
  background: color-mix(in srgb, var(--card) 60%, var(--line));
  color: var(--ink);
}
.btn-staging-dismiss:active {
  transform: scale(0.98);
}
.btn-staging-dismiss .i {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

@media (max-width: 640px) {
  .staging-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 12px;
  }
  .staging-banner-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .btn-staging-commit,
  .btn-staging-dismiss {
    width: 100%;
    min-height: 44px;
  }
  .staging-banner-title {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
  }
}

.reader[data-reader-theme='sepia'] .staging-banner {
  background: #f4ecd8 !important;
  border-bottom-color: #dfd4be !important;
  color: #433422 !important;
}
.reader[data-reader-theme='sepia'] .staging-banner-title {
  color: #433422 !important;
}
.reader[data-reader-theme='sepia'] .btn-staging-dismiss {
  border-color: #dfd4be !important;
  color: #7d6951 !important;
}

.reader[data-reader-theme='dark'] .staging-banner {
  background: #242220 !important;
  border-bottom-color: #383531 !important;
  color: #e7e5e4 !important;
}
.reader[data-reader-theme='dark'] .staging-banner-title {
  color: #e7e5e4 !important;
}
.reader[data-reader-theme='dark'] .btn-staging-dismiss {
  border-color: #383531 !important;
  color: #a8a29e !important;
}

.reader[data-reader-theme='night'] .staging-banner {
  background: #111111 !important;
  border-bottom-color: #222222 !important;
  color: #cccccc !important;
}
.reader[data-reader-theme='night'] .staging-banner-title {
  color: #cccccc !important;
}
.reader[data-reader-theme='night'] .btn-staging-dismiss {
  border-color: #222222 !important;
  color: #888888 !important;
}

/* ---------- Banner + toast ---------- */
.banner {
  position: fixed;
  z-index: 25;
  top: calc(var(--top) + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 0 0 1px var(--line), 0 10px 30px -12px rgba(0, 0, 0, 0.3);
  font-size: 0.9375rem;
}
.banner p {
  margin: 0;
  flex: 1;
}
.banner .btn {
  padding: 7px 14px;
}
.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(22px + var(--bottom));
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 11px 12px 11px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9375rem;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.toast button {
  border: 0;
  background: none;
  color: var(--marker);
  font-weight: 700;
  padding: 2px 6px;
}

@media (min-width: 900px) {
  .card {
    padding-right: 24px;
  }
  .rail {
    right: calc(50% - var(--measure) / 2 - 96px);
    bottom: 50%;
    transform: translateY(50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
.hl-quote {
  min-height: 0;
  flex: 0 1 auto;
}

/* Sync status dot */
.sync-dot {
  width: 32px;
  min-width: 28px;
  flex-shrink: 0;
  height: 42px;
  border: 0;
  background: none;
  display: inline-grid;
  place-items: center;
  padding: 0;
}
.sync-dot span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--faint);
  transition: background-color 0.3s, border-color 0.3s, opacity 0.6s;
}
.sync-dot[data-state='done'] span {
  background: var(--action);
  border-color: var(--action);
}
.sync-dot[data-state='error'] span {
  background: var(--danger);
  border-color: var(--danger);
}
.outbox-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
}
.outbox-item p {
  flex: 1;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}
.outbox-item b {
  color: var(--ink);
  font-weight: 600;
}
.outbox-item .err {
  color: var(--danger);
}
.outbox-item button {
  border: 0;
  background: none;
  color: var(--action);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 2px 4px;
}

/* "You wrote this 3 days ago": why a card is back */
.card-reason {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 0.8125rem;
  color: var(--muted);
}
.card-reason::before {
  content: '';
  width: 14px;
  height: 6px;
  border-radius: 2px;
  background: var(--marker);
  flex: none;
}
.card-book .card-reason {
  justify-content: center;
}

/* Keep-safe setup */
.setup-intro {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.55;
}
.setup-steps {
  margin: 0;
  padding: 0 0 0 1.4em;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.setup-steps li::marker {
  font-weight: 700;
  color: var(--action);
}
.setup-steps h3 {
  margin: 0 0 4px;
}
.setup-steps p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.5;
}
.setup-steps .btn {
  display: inline-block;
  text-decoration: none;
}
.setup-steps .field + .field {
  margin-top: 10px;
}
.card-nudge h2 {
  max-width: 18ch;
}

@media (max-width: 520px) {
  /* Library rows: actions go under the details so names aren't squeezed */
  .source {
    grid-template-columns: 1fr;
  }
  .source-actions {
    grid-row: auto;
    grid-column: 1;
    margin-left: -8px;
    flex-wrap: wrap;
  }
}

/* Your own note on a highlight */
.hl-comment {
  margin: 18px 0 0;
  padding: 10px 0 0 14px;
  border-left: 2px solid var(--line);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-line;
}

/* Note on a highlight */
.note-quote {
  margin: 0;
  padding-left: 12px;
  border-left: 3px solid var(--marker);
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  line-height: 1.5;
}
/* Book contents */
.toc {
  display: flex;
  flex-direction: column;
}
.toc-item {
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  padding: 12px;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink);
}
.toc-item:hover {
  background: var(--paper);
}
.epub-area foliate-view {
  display: block;
  width: 100%;
  height: 100%;
}
.selection-bar .btn-quiet {
  padding-left: 12px;
  padding-right: 12px;
}
.selection-bar .btn {
  white-space: nowrap;
}

/* ---------- Bottom tab bar ---------- */
nav.tabbar,
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  inset: auto 0 0 0;
  z-index: 50;
  height: var(--tabbar);
  padding-bottom: env(safe-area-inset-bottom, 16px);
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  justify-content: space-around;
  gap: 8px;
  background: color-mix(in srgb, var(--paper, var(--surface)) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

/* Suppress top-level views and global navigation bar when reading */
body.has-reader nav.tabbar,
body.has-reader .tabbar,
body:has(.reader) nav.tabbar,
body:has(.reader) .tabbar,
body.has-book-reader nav.tabbar,
body.has-book-reader .tabbar,
body:has(.reader-doc) nav.tabbar,
body:has(.reader-doc) .tabbar {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

body.has-reader #feed,
body.has-reader .feed,
body.has-reader #shelf,
body.has-reader #notes,
body.has-reader .banner,
body:has(.reader) #feed,
body:has(.reader) .feed,
body:has(.reader) #shelf,
body:has(.reader) #notes,
body:has(.reader) .banner {
  display: none !important;
}

.tab {
  flex: 0 1 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--faint);
  font-size: 0.75rem;
  font-weight: 600;
  min-height: 44px;
  min-width: 44px;
}
.tab .i {
  width: 22px;
  height: 22px;
}
.tab[aria-current='page'] {
  color: var(--ink);
}
.tab[aria-current='page'] .i {
  stroke-width: 2;
}
/* Leave room for the tab bar */
.card {
  padding-bottom: calc(24px + var(--tabbar));
}
.rail {
  bottom: calc(24px + var(--tabbar));
}
.toast {
  bottom: calc(14px + var(--tabbar));
}

/* ---------- Shelf ---------- */
.shelf {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  padding: var(--top) 0 var(--tabbar);
}
.shelf-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 20px 40px;
}
.shelf-heading {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.35rem;
  margin: 18px 0 14px;
}
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr));
  gap: 22px 18px;
}
@media (max-width: 420px) {
  .shelf-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.shelf-book-card {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.shelf-book {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  width: 100%;
}
.shelf-book-menu-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(18, 22, 20, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.88;
  transition: opacity 0.15s ease, background 0.15s ease, transform 0.15s ease;
  z-index: 3;
}
.shelf-book-menu-btn:hover,
.shelf-book-menu-btn:focus-visible {
  opacity: 1;
  background: rgba(18, 22, 20, 0.95);
  transform: scale(1.08);
}
.shelf-cloud-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 3px 7px;
  border-radius: 4px;
  background: rgba(18, 22, 20, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
  z-index: 2;
  pointer-events: none;
}
.shelf-actions-btn {
  margin-left: 2px;
}

/* Book Details & Management Sheet */
.book-details-diag {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 10px 0 16px;
}
.book-details-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.book-details-badges .badge,
.storage-breakdown-row .badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  background: var(--bg-hover, rgba(0, 0, 0, 0.06));
  color: var(--ink);
  border: 1px solid var(--line);
}
.badge-format {
  background: rgba(58, 86, 75, 0.12) !important;
  color: #2e5b4f !important;
  border-color: rgba(58, 86, 75, 0.25) !important;
}
.badge-size {
  font-variant-numeric: tabular-nums;
}
.badge-warning,
.badge-danger {
  background: rgba(180, 40, 40, 0.12) !important;
  color: #a82020 !important;
  border-color: rgba(180, 40, 40, 0.25) !important;
}
.badge-success {
  background: rgba(30, 130, 70, 0.12) !important;
  color: #1e7a44 !important;
  border-color: rgba(30, 130, 70, 0.25) !important;
}
.badge-muted {
  background: rgba(100, 110, 120, 0.1) !important;
  color: var(--muted) !important;
  border-color: var(--line) !important;
}
.book-details-meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  font-size: 0.875rem;
  padding: 14px;
  background: var(--bg-hover, rgba(0, 0, 0, 0.03));
  border-radius: 8px;
  border: 1px solid var(--line);
}
.book-meta-label {
  font-weight: 600;
  color: var(--muted);
}
.book-meta-val {
  color: var(--ink);
  word-break: break-word;
}
.book-meta-path {
  font-family: var(--mono, monospace);
  font-size: 0.8125rem;
}
.book-details-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.storage-breakdown-summary {
  padding: 12px 14px;
  background: var(--bg-hover, rgba(0, 0, 0, 0.03));
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 16px;
  font-size: 0.9375rem;
  line-height: 1.4;
}
.storage-breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
}
.storage-breakdown-row {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface, #fff);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.storage-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9375rem;
}
.storage-row-details {
  font-size: 0.8125rem;
  color: var(--muted);
}
.shelf-cover {
  aspect-ratio: 2 / 3;
  width: 100%;
  border-radius: 3px 7px 7px 3px;
  overflow: hidden;
  background: var(--tone, #2e5b4f);
  box-shadow: 0 12px 24px -14px rgba(0, 0, 0, 0.5);
  margin-bottom: 6px;
  display: flex;
  align-items: flex-end;
}
.shelf-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.shelf-cover span {
  padding: 14px 12px;
  color: #f5f3ea;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.shelf-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.shelf-meta {
  font-size: 0.8125rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shelf-progress {
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
  margin-top: 4px;
}
.shelf-progress i {
  display: block;
  height: 100%;
  background: var(--action);
}
.shelf-empty {
  max-width: 30rem;
  margin: 18vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: flex-start;
}
.shelf-empty h2 {
  font-family: var(--serif);
  font-size: 1.8rem;
  margin: 0;
}
.shelf-empty p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}
@media (min-width: 900px) {
  .rail {
    bottom: 50%;
  }
}

/* ---------- Notes view ---------- */
.notes {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  padding: var(--top) 0 var(--tabbar);
}
.notes-inner {
  max-width: 44rem;
  margin: 0 auto;
  padding: 10px 20px 40px;
}
.notes-top {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--paper);
  padding: 6px 0 8px;
}
.notes-search {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  color: var(--ink);
}
.notes-coverage {
  margin: 8px 2px 0;
}
.linklike {
  border: 0;
  background: none;
  padding: 0;
  color: var(--action);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.notes-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0 6px;
}
.notes-bar .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  flex: none;
}
.notes-heading {
  display: flex;
  align-items: center;
  min-width: 0;
}
.notes-heading h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  font-family: var(--serif);
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}
.notes-heading .notes-count,
.notes-crumbs .notes-count {
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--muted);
}
.notes-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  min-width: 0;
  font-size: 0.9375rem;
  color: var(--muted);
}
.crumb-btn {
  border: 0;
  background: none;
  padding: 4px 2px;
  color: var(--action);
  font-weight: 600;
}
.crumb-btn[aria-current] {
  color: var(--ink);
}
.crumb-btn + .crumb-btn::before {
  content: '/';
  color: var(--faint);
  font-weight: 400;
  margin: 0 6px 0 2px;
}
.notes-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}
.note-row,
.folder-row,
.pick-item,
.backlink {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  padding: 13px 4px;
  color: var(--ink);
}
.note-row b,
.pick-item b,
.backlink b {
  overflow-wrap: anywhere;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.0625rem;
}
.note-row span,
.pick-item span,
.backlink span {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.folder-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.folder-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.folder-name::before {
  content: '';
  width: 16px;
  height: 12px;
  border: 1.6px solid var(--faint);
  border-radius: 2px 3px 3px 3px;
  box-shadow: inset 0 3px 0 -1.6px var(--faint);
}
.folder-count {
  color: var(--faint);
  font-size: 0.875rem;
}
.note-row:hover,
.folder-row:hover,
.pick-item:hover,
.backlink:hover {
  background: color-mix(in srgb, var(--card) 70%, transparent);
}
.notes-empty {
  color: var(--muted);
  padding: 20px 4px;
  line-height: 1.5;
}
.notes-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.observatory-trigger-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--surface, var(--card)) 90%, transparent);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.observatory-trigger-btn:hover {
  background: color-mix(in srgb, var(--text, var(--ink)) 5%, transparent);
}
.notes-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 20px;
  max-width: 420px;
  margin: 0 auto;
}
.empty-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--healthy) 12%, transparent);
  color: var(--healthy);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.notes-empty-state h3 {
  margin: 0 0 8px 0;
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ink);
}
.notes-empty-state .hint {
  margin: 0 0 20px 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--muted);
}
.empty-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.notes-bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 8px 0 12px;
  font-size: 0.875rem;
}
.notes-bulk-count {
  font-weight: 600;
  color: var(--ink);
  margin-right: auto;
}
.note-row.selecting {
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
}
.note-row.selecting.is-selected {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.note-row.selecting .note-select-check {
  margin-top: 4px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
  pointer-events: none;
}
.note-row.selecting .note-content-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
  text-align: left;
}

/* Menus and pickers */
.menu-list {
  display: flex;
  flex-direction: column;
}
.menu-item,
.sheet-action {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  padding: 14px 4px;
  font-size: 1rem;
  color: var(--ink);
  text-align: left;
}
.menu-item .i,
.sheet-action .i {
  color: var(--muted);
}
.menu-item.danger,
.menu-item.danger .i,
.sheet-action.danger,
.sheet-action.danger .i {
  color: var(--danger);
}
.menu-divider {
  border: none;
  border-top: 1px solid var(--line, #e7e5e4);
  margin: 6px 0;
}
.pick-list {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}
.pick-row {
  border-bottom: 1px solid var(--line);
}
.pick-line {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pick-line .pick-item {
  flex: 1;
  min-width: 0;
  border-bottom: 0;
}
.pick-item small {
  color: var(--faint);
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pick-item[aria-expanded='true'] b {
  color: var(--action);
}
.pick-link {
  flex: none;
  padding: 6px 14px;
}
.pick-link:not(:disabled) {
  color: var(--action);
  border-color: color-mix(in srgb, var(--action) 45%, transparent);
}
.pick-preview {
  margin: 0 4px 14px;
  padding: 12px 14px;
  max-height: 46vh;
  overflow-y: auto;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
}
.pick-preview .prose {
  font-size: 0.95rem;
  line-height: 1.6;
}
.pick-heading {
  margin: 16px 4px 2px;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.pick-cover {
  margin: 8px 2px 0;
}
.sheet-inner > input[type='search'] {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 1rem;
  color: var(--ink);
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* Linked from */
.backlinks {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.backlinks h2 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 4px;
}
.backlink {
  width: 100%;
}
.backlink-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}
.backlink-row .backlink {
  flex: 1;
}
.backlink-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.conn-mutual {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--sans);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--muted);
  padding: 1px 7px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--muted) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  letter-spacing: 0.02em;
  line-height: 1.3;
}
.link-back-btn {
  font-size: 0.75rem;
  padding: 4px 8px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-right: 4px;
}
.connections-subhead {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--muted);
  margin: 22px 0 6px !important;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.prose a.wikilink {
  color: var(--action);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--action) 45%, transparent);
  cursor: pointer;
}

/* ---------- Engagement ---------- */
/* Long notes: one section per slide */
.slides {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  min-height: 0;
  flex: 0 1 auto;
  gap: 0;
  overscroll-behavior-x: contain;
}
.slides::-webkit-scrollbar {
  display: none;
}
.slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  max-height: 52dvh;
  overflow: hidden;
  position: relative;
  padding-right: 4px;
  -webkit-mask-image: linear-gradient(to bottom, #000 82%, transparent);
  mask-image: linear-gradient(to bottom, #000 82%, transparent);
}
.slide h2:first-child {
  margin-top: 0;
}
.slide-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.slide-dots {
  display: flex;
  gap: 6px;
  flex: 1;
}
.slide-dots i {
  width: 18px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
.slide-dots i.on {
  background: var(--marker);
}
.slide-count {
  font-size: 0.8125rem;
  color: var(--muted);
}
.slide-nav {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
}
.slide-nav:disabled {
  opacity: 0.35;
}

/* Connected: two notes that link to each other */
.card-connection .card-body {
  justify-content: center;
  gap: 4px;
}
.conn-note {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 18px 18px 20px;
  color: var(--ink);
}
.conn-note b {
  font-family: var(--serif);
  font-size: 1.3rem;
  line-height: 1.2;
}
.conn-note span {
  font-family: var(--serif);
  color: var(--muted);
  line-height: 1.5;
}
.conn-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--faint);
  font-size: 0.8125rem;
  margin: 6px 18px;
}
.conn-link i {
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* Hub cards */
.conn-hub-main {
  width: 100%;
}
.conn-hub-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}
.conn-backlink-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.conn-backlink-item:hover {
  background: color-mix(in srgb, var(--card) 85%, var(--accent));
  border-color: var(--accent);
}
.conn-backlink-item strong {
  font-family: var(--serif);
  font-size: 1.0625rem;
  font-weight: 600;
}
.conn-backlink-item span {
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.4;
}

/* Settings: learning */
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9375rem;
  margin-bottom: 10px;
}
.check input {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  accent-color: var(--action);
}
.learn-summary ul {
  margin: 4px 0 10px;
  padding-left: 1.2em;
  font-size: 0.9375rem;
}
.learn-label {
  margin: 8px 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ---------- Settings details ---------- */
.settings-first {
  border-top: 0;
  padding-top: 4px;
}
.token-status {
  margin: 8px 0 6px;
}
.token-status .ok {
  color: var(--action);
  font-weight: 600;
}
.token-status .err {
  color: var(--danger, #b4472e);
}
details.how {
  font-size: 0.875rem;
  color: var(--muted);
}
details.how summary {
  cursor: pointer;
  color: var(--action);
  font-weight: 600;
  padding: 4px 0;
}
details.how ol {
  margin: 6px 0 4px;
  padding-left: 1.3em;
  line-height: 1.55;
}
details.how li + li {
  margin-top: 4px;
}
.more-options summary {
  cursor: pointer;
  color: var(--action);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 2px 0;
}
.more-options[open] > summary {
  margin-bottom: 12px;
}
.more-options > .field,
.more-options > .field-pair {
  margin-bottom: 12px;
}

.notes-bar-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.compose-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: -6px;
}
.compose-tools .btn,
.compose-paste,
.compose-include-insight,
.compose-include-citation,
.compose-link-note,
.compose-attach-image {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  white-space: nowrap;
}
.compose-tools .btn:hover,
.compose-paste:hover,
.compose-include-insight:hover,
.compose-include-citation:hover,
.compose-link-note:hover,
.compose-attach-image:hover {
  background: var(--card);
}
.insight-picker {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 300px;
}
.insight-picker-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: 52vh;
  padding-right: 2px;
}
.insight-picker-empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 12px;
  font-size: 0.9rem;
}
.insight-picker-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.insight-picker-card:hover {
  background: var(--card);
  border-color: var(--action);
}
.insight-picker-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.insight-picker-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.citation-suggestions-header {
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 4px 2px 2px;
}
.citation-intent-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: 4px;
  padding: 1px 6px;
  line-height: 1.3;
}
.insight-picker-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}
.insight-picker-source {
  font-size: 0.8rem;
  color: var(--muted);
}
.insight-picker-quote {
  font-family: var(--serif);
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink);
  border-left: 2px solid var(--line);
  padding-left: 10px;
  margin: 0;
  font-style: italic;
}
.insight-picker-thought {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}
.insight-picker-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.insight-picker-insert {
  font-size: 0.8rem;
  padding: 4px 10px;
}

/* ---------- Inline [[ Wiki-Link Autocomplete ---------- */
.wiki-autocomplete-menu {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 4px;
  overscroll-behavior: contain;
}
.wiki-autocomplete-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  min-height: 44px; /* Accessible touch target */
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  transition: background 0.1s ease;
  font-family: inherit;
}
.wiki-autocomplete-item:hover,
.wiki-autocomplete-item.active {
  background: color-mix(in srgb, var(--action) 12%, transparent);
}
.wiki-autocomplete-title {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.wiki-autocomplete-path {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  font-family: var(--mono);
}
/* ---------- Bounded Citation Callout Cards ---------- */
.citation-card {
  margin: 1.5rem 0;
  padding: 16px 18px;
  background: color-mix(in srgb, var(--surface) 50%, var(--paper));
  border: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  position: relative;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.citation-card:hover {
  border-color: color-mix(in srgb, var(--line) 95%, transparent);
  background: color-mix(in srgb, var(--surface) 65%, var(--paper));
}

.citation-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}

.citation-card-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
}

.citation-glyph {
  font-family: var(--serif);
  font-size: 1.25rem;
  line-height: 0.9;
  color: var(--accent);
  font-weight: 700;
}

.citation-kicker {
  line-height: 1;
}

.citation-source-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--action);
  text-decoration: none;
  padding: 3px 8px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--action) 8%, transparent);
  transition: background-color 0.15s ease, color 0.15s ease;
  cursor: pointer;
  max-width: 100%;
}
.citation-source-link:hover {
  background: color-mix(in srgb, var(--action) 16%, transparent);
  text-decoration: underline;
}

.citation-source-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.citation-arrow {
  font-size: 0.8125rem;
  font-weight: 700;
  opacity: 0.8;
  line-height: 1;
}

.citation-card-quote {
  margin: 0;
  padding: 0;
  border: none;
  font-family: var(--serif);
  font-size: 0.9375rem;
  font-style: italic;
  line-height: 1.65;
  color: var(--ink);
  quotes: "“" "”";
}

.citation-card-quote p {
  margin: 0.4rem 0;
}
.citation-card-quote p:first-child {
  margin-top: 0;
}
.citation-card-quote p:last-child {
  margin-bottom: 0;
}

.citation-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}

.citation-card-meta .citation-dash {
  color: var(--muted);
  font-weight: 400;
}

.citation-card-meta .citation-attribution {
  font-style: normal;
}
.compose-submit-bar {
  position: sticky;
  bottom: 0;
  background: var(--card);
  padding: 12px 20px calc(12px + var(--bottom));
  margin: auto -20px calc(-24px - var(--bottom));
  border-top: 1px solid var(--line);
  z-index: 10;
  display: flex;
}
@media (min-width: 640px) {
  .compose-submit-bar {
    padding: 16px 20px 20px;
    margin: auto -20px -24px;
  }
}
.compose-submit-bar .btn-save-note {
  width: 100%;
  min-height: 44px;
  font-size: 1rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.clip-dupe {
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--marker) 22%, transparent);
  color: var(--ink);
  margin: 0;
}
.clip-related {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.clip-link-btn {
  padding: 7px 14px;
}
.clip-links {
  display: contents;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px 5px 12px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 0.875rem;
}
.chip-x {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 4px;
}
.clip-where {
  margin: 0;
}

/* ---------- The garden: growth tags, Water, the tag sheet ---------- */
.glyph,
.growth-glyph,
.growth-tag svg,
.growth-badge svg,
.grow svg,
.grow .glyph {
  max-width: 16px;
  max-height: 16px;
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
  flex: none;
}
.grow-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 0 0 14px;
}
.grow {
  --c: var(--faint);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  align-self: flex-start;
  margin: 0 0 14px;
  padding: 4px 11px 4px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 70%, transparent);
  color: var(--muted);
  font: 500 0.78rem/1.2 var(--sans);
  letter-spacing: 0.01em;
  cursor: pointer;
}
.grow-row .grow {
  margin: 0;
}
.grow .glyph {
  color: var(--c);
}
.grow b {
  font-weight: 650;
  color: var(--ink);
}
.grow.healthy {
  --c: var(--healthy);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--healthy) 16%, transparent), 0 0 14px color-mix(in srgb, var(--healthy) 32%, transparent);
}
.grow.thirsty {
  --c: var(--thirsty);
}
.grow.wilting {
  --c: var(--wilting);
  background: color-mix(in srgb, var(--wilting) 10%, transparent);
}
.grow.wilting b {
  color: var(--wilting-ink);
}
.grow.resting,
.grow.pruned,
.grow.unknown {
  --c: var(--faint);
}
.reader-grow:empty {
  display: none;
}
.reader-article .card-title + .reader-grow {
  margin: -12px 0 22px;
}

/* Water on a card - legacy bottom dashed box suppressed in favor of rail action */
.card-water-box,
.water-field {
  display: none !important;
}
.water-open .glyph,
.water-done .glyph,
.grow-act.water .glyph {
  color: var(--healthy);
}
.water-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 10px 12px;
  font: 1rem/1.5 var(--serif);
  color: var(--ink);
  resize: vertical;
}
.water-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.water-row .btn {
  padding: 7px 14px;
}
.water-done {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--healthy);
  font-weight: 600;
  font-size: 0.9rem;
}

/* The tag sheet */
.ladder {
  display: flex;
  gap: 6px;
  align-items: center;
  font: 0.8rem var(--sans);
  color: var(--faint);
  margin-top: -8px;
}
.ladder .on {
  color: var(--ink);
  font-weight: 650;
}
.grow-health {
  margin: 0;
}
.grow-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.grow-stats div {
  background: var(--paper);
  border-radius: 10px;
  padding: 9px 10px;
  font: 0.78rem var(--sans);
  color: var(--muted);
}
.grow-stats b {
  display: block;
  font: 600 1.15rem var(--serif);
  color: var(--ink);
}
.grow-acts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.grow-act {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--ink);
  text-align: left;
}
.grow-act b {
  font: 600 0.95rem var(--sans);
}
.grow-act span {
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--muted);
}
.grow-act .glyph {
  width: 18px;
  height: 18px;
}
.grow-act.prune .glyph {
  color: var(--wilting);
}
.grow-link {
  margin: -6px 0 0;
}
.grow-field-pair {
  grid-template-columns: minmax(110px, 1fr) minmax(160px, 2fr);
  gap: 12px;
  align-items: end;
}
.grow-field-pair input[name="canonical"] {
  min-width: 0;
  width: 100%;
}
@media (max-width: 480px) {
  .grow-field-pair {
    grid-template-columns: 1fr;
  }
}

/* Notes Control Bar & Tools */
.notes-tools,
.notes-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 0 14px;
}
.notes-controls-row .btn,
.notes-controls-row .notes-filter,
.notes-controls-row .notes-sort {
  min-height: 38px;
  touch-action: manipulation;
}
.notes-bar-actions .btn {
  min-height: 38px;
  touch-action: manipulation;
}
@media (pointer: coarse) {
  .notes-controls-row .btn,
  .notes-controls-row .notes-filter,
  .notes-controls-row .notes-sort,
  .notes-bar-actions .btn,
  .notes-bar-actions .observatory-trigger-btn {
    min-height: 44px;
  }
}
.notes-sort-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}
.notes-sort {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  color: var(--ink);
}
.notes-filter {
  padding: 6px 14px;
  font-size: 0.85rem;
  min-width: 0;
  max-width: 62%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notes-filter.active {
  background: color-mix(in srgb, var(--action) 14%, transparent);
  color: var(--action);
  border-color: color-mix(in srgb, var(--action) 40%, transparent);
}
.notes-count {
  margin: 6px 4px 0;
}
.note-row .row-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--faint);
}
.mini-grow,
.note-row .mini-grow {
  --c: var(--faint);
  display: inline-flex;
  overflow: visible;
  font-size: inherit;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-weight: 600;
}
.mini-grow .glyph {
  width: 13px;
  height: 13px;
  color: var(--c);
}
.mini-grow.healthy {
  --c: var(--healthy);
}
.mini-grow.thirsty {
  --c: var(--thirsty);
}
.mini-grow.wilting {
  --c: var(--wilting);
  color: var(--wilting-ink);
}

/* ---------- Type checklist (top-level folders) ---------- */
.type-checks {
  border: 0;
  padding: 0;
  margin: 0;
}
.type-checks legend {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 6px;
  padding: 0;
}
.type-checks legend .hint {
  font-weight: 400;
  margin-left: 6px;
}
.type-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.type-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.type-check span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 0.875rem;
  color: var(--ink);
  cursor: pointer;
}
.type-check small {
  color: var(--muted);
  font-size: 0.75rem;
}
.type-check input:checked + span {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--card);
}
.type-check input:checked + span small {
  color: inherit;
  opacity: 0.75;
}
.type-check input:focus-visible + span {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}
details.how.organise ul {
  margin: 6px 0 8px;
  padding-left: 1.2em;
  line-height: 1.55;
}
details.how.organise li + li {
  margin-top: 6px;
}
details.how.organise b {
  color: var(--ink);
}
details.how + details.how {
  margin-top: 2px;
}

.field-opt {
  color: var(--faint);
  margin-left: 4px;
}
.compose-add-type {
  align-self: flex-start;
  font-size: 0.875rem;
}
.relink {
  min-height: 1.6em;
}
.relink p {
  margin: 0;
}
.relink-list ul {
  margin: 6px 0 4px;
  padding-left: 1.2em;
  line-height: 1.5;
}
.relink-list small {
  color: var(--faint);
}

/* Long words, paths and names wrap instead of running off the screen. */
.reader-foot,
.note-row span,
.folder-name,
.sheet-head h2,
.crumb,
.crumb-btn {
  overflow-wrap: anywhere;
}
/* Disclosure summaries are a comfortable tap. */
details > summary {
  min-height: 28px;
  display: list-item;
  padding-block: 4px;
}
/* Narrow phones: paired fields stack. */
@media (max-width: 359px) {
  .field-pair {
    grid-template-columns: 1fr;
  }
}
/* The new-note sheet: Save stays in reach however tall the form gets. */
#compose-form > button[type='submit'] {
  position: sticky;
  bottom: 0;
  box-shadow: 0 -12px 16px var(--card);
}

/* Very narrow phones: the brand gives way so every top-bar control fits. */
@media (max-width: 359px) {
  .topbar .brand {
    font-size: 1rem;
  }
  .scope-chip,
  .scope-btn,
  #scope-btn {
    max-width: 38vw;
    padding-left: 10px;
  }
}
.relink-taken {
  color: var(--danger);
}

/* Feed search dialog */
.feed-search-input {
  width: 100%;
  font-size: 1.0625rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  margin-bottom: 8px;
  box-sizing: border-box;
}
.feed-search-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 55vh;
  overflow-y: auto;
  margin-top: 8px;
}
.feed-search-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  border: 0;
  border-radius: 8px;
  padding: 10px 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.feed-search-item:hover {
  background: color-mix(in srgb, var(--card) 70%, transparent);
}
.feed-search-item b {
  font-family: var(--serif);
  font-size: 1.0625rem;
}
.feed-search-snippet {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.4;
}
.feed-search-item small {
  font-size: 0.75rem;
  color: var(--faint);
}
.home-btn {
  margin-right: 2px;
}
.discard-btn {
  margin-right: 4px;
}

/* ---------- Settings 4-Tab Workstation ---------- */
.settings-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: color-mix(in srgb, var(--paper) 80%, var(--line));
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-bottom: 20px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  height: auto;
  min-height: 44px;
  box-sizing: border-box;
}
.settings-tabs::-webkit-scrollbar {
  display: none;
}
.settings-tab {
  flex: 1 1 auto;
  min-width: max-content;
  height: auto;
  min-height: 36px;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: normal;
  overflow: visible;
  visibility: visible;
  opacity: 1;
}
.settings-tab:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--card) 45%, transparent);
}
.settings-tab.is-active {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}
.settings-tab:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 1px;
}
.settings-tab-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.settings-tab-panel[hidden] {
  display: none !important;
}

/* Connect Source Cards & Accordions */
.connect-sources-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}
.provider-accordion {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  overflow: hidden;
  transition: border-color 0.15s;
}
.provider-accordion[open] {
  border-color: var(--action);
}
.provider-accordion summary {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.provider-accordion summary::marker {
  color: var(--muted);
}
.provider-accordion-body {
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.provider-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.preset-chip {
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}
.preset-chip:hover {
  border-color: var(--action);
  color: var(--action);
}
.source-type-pill {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--card) 60%, var(--line));
  color: var(--muted);
  font-weight: 600;
}
.source-type-pill.writeable {
  background: color-mix(in srgb, #16a34a 12%, transparent);
  color: #15803d;
}
.source-type-pill.readonly {
  background: color-mix(in srgb, #ca8a04 15%, transparent);
  color: #a16207;
}

/* Export & Publishing Section */
.export-card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
}
.export-action-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.export-action-card h4 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.export-action-card p {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.45;
}

/* Ink-friendly vector print styles */
@media print {
  /* Strip all application chrome, topbars, nav rails, action sheets, buttons, and footers */
  nav, .rail, .top-rail, .topbar, .tabbar, dialog, .feed-actions, .note-actions, .shelf-bar-actions,
  button, .settings-tabs, .selection-bar, .reader-bar, .reader-bar *, .reader-tools, .connection-footer,
  .toast, #toast, .sync-dot, .brand, .feed-meta, .source-actions, .reader-status,
  .reader-grow, .reader-foot, .backlinks, .reader-dock, .writer-canvas {
    display: none !important;
  }

  /* Suppress background views (feed, shelf, notes, etc.) when reading a note */
  body:has(.reader) #feed,
  body:has(.reader) .feed,
  body:has(.reader) #shelf,
  body:has(.reader) #notes,
  body:has(.reader) .banner,
  body:has(.reader) > *:not(.reader),
  body.has-reader #feed,
  body.has-reader .feed,
  body.has-reader #shelf,
  body.has-reader #notes,
  body.has-reader .banner,
  body.has-reader > *:not(.reader) {
    display: none !important;
  }

  body, html {
    background: #ffffff !important;
    color: #111111 !important;
    box-shadow: none !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    position: static !important;
    font-size: 11pt !important;
    line-height: 1.65 !important;
  }

  .reader {
    background: #ffffff !important;
    color: #111111 !important;
    box-shadow: none !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    position: static !important;
    height: auto !important;
    overflow: visible !important;
  }

  .reader-scroll {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  .reader-article, .article-wrap, .article, .prose {
    background: transparent !important;
    box-shadow: none !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    position: static !important;
  }

  .reader-article .card-where {
    font-size: 9pt !important;
    color: #57534e !important;
    margin-bottom: 6pt !important;
  }

  .reader-article .card-title, .article-title {
    font-size: 22pt !important;
    line-height: 1.2 !important;
    margin-bottom: 16pt !important;
    color: #000000 !important;
  }
  /* Style citation cards with high-contrast, ink-friendly hairline borders & page-break guards */
  figure.citation-card, .citation-callout, blockquote {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    border: 1px solid #78716c !important;
    background: #fafaf9 !important;
    padding: 10pt 14pt !important;
    margin: 14pt 0 !important;
    border-radius: 4pt !important;
  }
  /* Automatically print URLs alongside external citations */
  a[href^="http"]::after {
    content: " (" attr(href) ")" !important;
    font-size: 0.82em !important;
    color: #57534e !important;
    word-break: break-all !important;
  }
  img {
    max-width: 100% !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    image-rendering: auto !important;
  }
}


/* Shelf Topbar & Actions */
.shelf-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.shelf-heading-main {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
}
.shelf-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.shelf-add-book-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.shelf-observatory-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--line);
  padding: 6px 14px;
  border-radius: 999px;
  transition: all 0.15s ease;
  cursor: pointer;
}
.shelf-observatory-btn:hover {
  background: var(--card);
  border-color: var(--ink);
}

/* ==========================================================================
   Highlight Deep-Linking & Provenance Action Button
   ========================================================================== */

.citation-jump-wrap {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  display: flex;
  justify-content: flex-end;
}
.btn-jump-source {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  font-size: 0.8125rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--action) 40%, var(--line));
  background: color-mix(in srgb, var(--action) 6%, var(--card));
  color: var(--action);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-jump-source:hover {
  background: color-mix(in srgb, var(--action) 14%, var(--card));
  transform: translateY(-1px);
}
.btn-jump-source b {
  font-weight: 600;
}
.btn-jump-source small {
  opacity: 0.8;
}
.btn-jump-source .jump-arrow {
  font-weight: 700;
}

/* ==========================================================================
   Image Attachments Drag & Drop and Upload
   ========================================================================== */

textarea.drag-active {
  border-color: var(--action) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--action) 20%, transparent) !important;
  background: color-mix(in srgb, var(--action) 3%, var(--card)) !important;
}
.compose-attach-image {
  gap: 5px;
}

/* ==========================================================================
   Diagnostics & Runtime Stress Suite
   ========================================================================== */

.diagnostics-sheet {
  max-width: 840px;
  width: 95vw;
}
.diagnostics-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 20px;
}
.diagnostics-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.diagnostics-tab-seg {
  display: flex;
  gap: 4px;
  background: color-mix(in srgb, var(--ink) 6%, var(--card));
  padding: 4px;
  border-radius: 8px;
}
.diagnostics-tab-seg .seg-btn {
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.diagnostics-tab-seg .seg-btn.is-active {
  background: var(--card);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.diagnostics-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.diagnostics-status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
}
.diagnostics-status-bar .badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--line);
  color: var(--ink);
}
.diagnostics-status-bar .badge-pass {
  background: #dcfce7;
  color: #166534;
}
.diagnostics-status-bar .badge-warn {
  background: #fef3c7;
  color: #92400e;
}
.diagnostics-status-bar .badge-fail {
  background: #fee2e2;
  color: #991b1b;
}
.diagnostics-status-bar .badge-running {
  background: #e0f2fe;
  color: #0369a1;
}
.diagnostics-results-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  flex: 1;
  padding-right: 2px;
}
.diag-empty {
  text-align: center;
  padding: 40px 20px;
}
.diag-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s ease;
}
.diag-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.diag-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.diag-status-pass .diag-badge {
  background: #10b981;
  color: #ffffff;
}
.diag-status-warn .diag-badge {
  background: #f59e0b;
  color: #ffffff;
}
.diag-status-fail .diag-badge {
  background: #ef4444;
  color: #ffffff;
}
.diag-card-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.diag-card-title b {
  font-size: 0.92rem;
  color: var(--ink);
}
.diag-card-title small {
  font-size: 0.75rem;
  color: var(--muted);
}
.diag-duration {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: auto;
}
.diag-card-msg {
  font-size: 0.86rem;
  color: var(--ink);
  line-height: 1.45;
  margin: 0;
}
.diag-card-detail {
  margin: 4px 0 0;
  padding: 6px 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 4%, var(--card));
  font-family: monospace;
  font-size: 0.74rem;
  line-height: 1.4;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
}

/* 100dvh mobile sheet layout with virtual keyboard resizing */
@media (max-width: 639px) {
  .sheet, .sheet-tall, #compose-sheet, #diagnostics-sheet {
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
    margin: 0;
  }
  .diagnostics-inner {
    max-height: 100dvh;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }
}

/* Service Worker In-App Update Banner */
.sw-update-banner {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 99999;
  background: var(--card, #ffffff);
  border: 1px solid var(--border, #cfd3ca);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border-radius: 999px;
  padding: 6px 12px 6px 14px;
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
  pointer-events: none;
}
.sw-update-banner.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.sw-update-content {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--ink, #141816);
  white-space: nowrap;
}
.sw-update-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary, #2b6b55);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary, #2b6b55) 20%, transparent);
}
.sw-update-text {
  font-weight: 500;
}
.sw-update-btn {
  background: var(--primary, #2b6b55);
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.sw-update-btn:hover {
  opacity: 0.9;
}
.sw-update-dismiss {
  background: transparent;
  border: none;
  color: var(--muted, #5c6158);
  font-size: 0.85rem;
  padding: 2px 6px;
  cursor: pointer;
}
.sw-update-dismiss:hover {
  color: var(--ink, #141816);
}

/* ==========================================================================
   The Knowledge Observatory (Meta Analytics & Graph Topology Dashboard)
   ========================================================================== */

.observatory-sheet {
  max-width: 900px;
  width: 95vw;
  max-height: 92dvh;
}
.observatory-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 92dvh;
  padding: 0;
  overflow: hidden;
}
#observatory-sheet .sheet-inner {
  overscroll-behavior-y: contain;
  padding-bottom: calc(36px + env(safe-area-inset-bottom, 0px)) !important;
}

.observatory-head {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.sheet-head-titles,
.observatory-header-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.sheet-head-titles .sheet-title,
.observatory-head .sheet-title,
.observatory-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.sheet-head-titles .sheet-title svg.i,
.observatory-head .sheet-title svg.i,
.observatory-title svg.i {
  color: var(--healthy);
  flex-shrink: 0;
}
.sheet-head-titles .sheet-subtitle,
.observatory-head .sheet-subtitle,
.observatory-subtitle {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}
.observatory-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.observatory-head .icon-btn,
.observatory-head-actions .icon-btn {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

/* Observatory Category Tabs - Scrollbar Suppression */
.observatory-tabs,
.observatory-nav,
#observatory-sheet .seg,
#observatory-sheet .observatory-tabs {
  display: flex;
  overflow-x: auto;
  white-space: nowrap;
  gap: 6px;
  padding: 8px 24px;
  background: color-mix(in srgb, var(--card) 60%, var(--paper));
  border-bottom: 1px solid var(--line);
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  -webkit-overflow-scrolling: touch;
}

.observatory-tabs::-webkit-scrollbar,
.observatory-nav::-webkit-scrollbar,
#observatory-sheet .seg::-webkit-scrollbar,
#observatory-sheet .observatory-tabs::-webkit-scrollbar {
  display: none !important; /* Chrome, Safari, Chromium */
  width: 0 !important;
  height: 0 !important;
}

.observatory-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.observatory-tab:hover {
  background: var(--line);
  color: var(--ink);
}
.observatory-tab.is-active {
  background: var(--card);
  color: var(--action);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  font-weight: 600;
}
.observatory-tab svg.glyph,
.observatory-tab svg.i {
  width: 16px;
  height: 16px;
  color: currentColor;
  flex-shrink: 0;
}

.observatory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

/* Observatory body & sections */
.observatory-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  padding-bottom: calc(36px + env(safe-area-inset-bottom, 0px)) !important;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.observatory-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Card primitives */
.observatory-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.observatory-card .card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.observatory-card .card-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
}
.observatory-card .card-desc {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--muted);
}
.observatory-empty-notice {
  padding: 16px;
  background: color-mix(in srgb, var(--line) 40%, transparent);
  border-radius: 8px;
  text-align: center;
  font-style: italic;
}

/* Macro Garden: Velocity and Health */
.observatory-diagnosis-card {
  border-left: 4px solid var(--healthy);
}
.observatory-diagnosis-card.status-thirsty {
  border-left-color: var(--thirsty);
}
.observatory-diagnosis-card.status-wilting {
  border-left-color: var(--danger);
}
.diagnosis-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.diagnosis-header svg.glyph {
  width: 20px;
  height: 20px;
  color: var(--action);
}
.diagnosis-title {
  font-size: 1rem;
  color: var(--ink);
}
.diagnosis-narrative {
  margin: 0;
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 1.5;
}
.health-bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--line);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}
.health-segment {
  height: 100%;
  transition: width 0.3s ease;
}
.seg-healthy { background: var(--healthy); }
.seg-thirsty { background: var(--thirsty); }
.seg-wilting { background: var(--wilting); }
.seg-resting { background: var(--muted); }

.health-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.82rem;
}
.health-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.health-chip::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.chip-healthy::before { background: var(--healthy); }
.chip-thirsty::before { background: var(--thirsty); }
.chip-wilting::before { background: var(--wilting); }
.chip-resting::before { background: var(--muted); }

/* Maturity Grid */
.observatory-maturity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.maturity-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.maturity-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.maturity-card-head svg.glyph {
  width: 18px;
  height: 18px;
  color: var(--action);
}
.maturity-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}
.maturity-count {
  margin-left: auto;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}
.maturity-bar-wrap {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}
.maturity-bar {
  height: 100%;
  background: var(--healthy);
  border-radius: 3px;
}
.stage-seed .maturity-bar { background: var(--thirsty); }
.stage-tree .maturity-bar { background: var(--action); }
.maturity-card-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.maturity-pct {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}
.maturity-desc {
  font-size: 0.78rem;
  line-height: 1.35;
}

/* Stats Ribbon */
.observatory-stats-ribbon {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  background: color-mix(in srgb, var(--card) 40%, var(--paper));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 18px;
}
.ribbon-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ribbon-stat b {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
}
.ribbon-stat span {
  font-size: 0.82rem;
}

/* Topology Metrics Row */
.topology-metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.topology-stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
}
.stat-sub {
  font-size: 0.78rem;
}

/* Lists and list rows */
.observatory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.observatory-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}
.observatory-list-row .row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.observatory-list-row .row-main svg.glyph {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--action);
}
.row-title {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-folder {
  font-size: 0.75rem;
  background: var(--line);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.row-age {
  font-size: 0.8rem;
}

/* Bridges */
.bridge-row .row-main {
  align-items: flex-start;
}
.bridge-glyph {
  font-size: 1.1rem;
  line-height: 1.2;
}
.bridge-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bridge-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.own-folder {
  background: color-mix(in srgb, var(--action) 15%, transparent);
  color: var(--action);
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.bridged-folder {
  background: color-mix(in srgb, var(--healthy) 15%, transparent);
  color: var(--healthy);
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.bridge-arrow {
  font-size: 0.8rem;
  color: var(--muted);
}
.connections-badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--line);
}

/* Associative Chains */
.chain-track {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 4px;
  -webkit-overflow-scrolling: touch;
}
.chain-step {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.chain-node {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.chain-node:hover {
  border-color: var(--action);
  background: color-mix(in srgb, var(--action) 6%, var(--card));
}
.chain-node svg.glyph {
  width: 16px;
  height: 16px;
  color: var(--action);
}
.chain-node-title {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
}
.chain-node-folder {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--line);
}
.chain-arrow {
  color: var(--muted);
  font-weight: 700;
}

/* Books Harvest */
.observatory-books-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.observatory-book-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
.book-card-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}
.book-swatch {
  width: 44px;
  height: 60px;
  border-radius: 6px;
  background: var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.book-swatch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.book-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.book-details .book-title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-details .book-author {
  font-size: 0.82rem;
}
.book-metrics-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.yield-badge {
  background: color-mix(in srgb, var(--action) 12%, transparent);
  color: var(--action);
  font-weight: 600;
}
.row-main.clickable {
  cursor: pointer;
}
.row-main.clickable:hover .row-title {
  color: var(--action);
  text-decoration: underline;
}
.book-card-main.clickable {
  cursor: pointer;
}
.book-card-main.clickable:hover .book-title {
  color: var(--action);
}
.book-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.format-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--line) 70%, transparent);
  color: var(--muted);
}
.observatory-book-card .badge,
.book-metrics-pills .badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.observatory-book-card .badge svg.i,
.book-metrics-pills .badge svg.i {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.book-swatch svg.i {
  width: 22px;
  height: 22px;
  color: var(--muted);
}

/* Domain Landscape */
.domain-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.domain-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.domain-row-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
}
.domain-bar-bg {
  height: 8px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.domain-bar-fill {
  height: 100%;
  background: var(--action);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* Tag Landscape */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.tag-chip:hover {
  border-color: var(--action);
  background: color-mix(in srgb, var(--action) 8%, var(--card));
}
.tag-count {
  font-size: 0.78rem;
  padding: 2px 7px;
  background: var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
}

/* Clusters */
.cluster-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.cluster-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}
.cluster-tags {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tag-badge {
  font-size: 0.8rem;
  background: var(--line);
}
.cluster-sym {
  color: var(--muted);
  font-size: 0.8rem;
}
.cluster-count {
  font-size: 0.8rem;
}

/* Utilities */
.tabular {
  font-variant-numeric: tabular-nums;
}

/* Loading & Error States */
.observatory-loading,
.observatory-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 20px;
  text-align: center;
}
.observatory-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--action);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 600px) {
  .settings-group .field-pair,
  .destination-card .field-pair,
  .settings-group .field-trio,
  .destination-card .field-trio {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .observatory-sheet {
    width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }
  .observatory-head {
    padding: 16px 16px 12px;
  }
  .observatory-nav {
    padding: 6px 16px;
  }
  .observatory-body {
    padding: 16px;
  }
  .observatory-book-card {
    flex-direction: column;
    align-items: flex-start;
  }
  .observatory-book-card .book-card-actions {
    width: 100%;
    margin-top: 8px;
  }
  .observatory-book-card .book-card-actions button {
    width: 100%;
  }
}

