/* Bonsai — layout and components. Values come from tokens.css only. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--t-md);
  line-height: var(--lh-md);
  -webkit-font-smoothing: antialiased;
}
body[data-route="read"] { background: var(--surface); }
h1, h2, h3, p, ul, ol, figure, blockquote { margin: 0; }
ul, ol { padding: 0; }
img { max-width: 100%; height: auto; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip { position: absolute; left: var(--s-4); top: -100px; z-index: 10; background: var(--surface); padding: var(--s-2) var(--s-4); }
.skip:focus { top: var(--s-2); }

/* ---------- frame ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  height: var(--bar-h);
  padding: 0 var(--s-4);
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
  background: var(--bg);
}
.brand {
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: var(--control);
  color: var(--text); text-decoration: none;
  font-family: var(--font-read); font-style: italic; font-size: var(--t-2xl); line-height: 1;
}
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.nav a {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--control);
  color: var(--text-2); text-decoration: none;
  font-size: var(--t-sm); line-height: var(--lh-sm);
}
.nav a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.nav a[aria-current="page"]::before {
  content: ""; position: absolute; top: -1px; left: 30%; right: 30%;
  height: 2px; background: var(--accent);
}
.nav a:focus-visible { outline-offset: -4px; }

main {
  max-width: var(--col);
  margin: 0 auto;
  padding: 0 var(--s-4) calc(var(--nav-h) + var(--s-7) + env(safe-area-inset-bottom));
}
main:focus { outline: none; }
body[data-route="read"] .topbar,
body[data-route="read"] .nav { display: none; }
body[data-route="read"] main { max-width: none; padding: 0; }

@media (min-width: 900px) {
  .topbar { padding: 0 max(var(--s-5), calc((100vw - var(--col)) / 2 - var(--s-8))); height: var(--bar-h); }
  .nav .icon { display: none; } /* labels alone read faster in a top bar */
  .nav {
    position: static; display: flex; gap: var(--s-2);
    height: auto; padding: 0; border: 0; background: none;
  }
  .nav a { flex-direction: row; gap: var(--s-2); padding: 0 var(--s-3); font-size: var(--t-md); }
  .nav a[aria-current="page"]::before { top: auto; bottom: 0; left: var(--s-3); right: var(--s-3); }
  main { padding-bottom: var(--s-8); }
}

/* ---------- type ---------- */
.screen-title {
  font-family: var(--font-read); font-weight: 400;
  font-size: var(--t-3xl); line-height: var(--lh-3xl);
  margin: var(--s-5) 0 var(--s-6);
}
.section-title {
  font-size: var(--t-sm); line-height: var(--lh-sm); font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-2);
  margin-bottom: var(--s-3);
}
.meta { font-size: var(--t-sm); line-height: var(--lh-sm); color: var(--text-2); }
.lead { font-size: var(--t-md); color: var(--text-2); }
.section + .section { margin-top: var(--s-7); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--control); padding: 0 var(--s-4);
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: none; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: opacity var(--dur-1) var(--ease), background-color var(--dur-1) var(--ease);
}
.btn:active { opacity: .8; }
.btn-primary { min-height: var(--control-lg); background: var(--accent); color: var(--accent-ink); }
.btn-secondary { border-color: var(--line-strong); color: var(--text); }
.btn-text { min-height: var(--control); padding: 0 var(--s-2); border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; }
.btn-quiet { color: var(--text-2); font-weight: 400; }
.btn-danger { color: var(--danger); }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--control); height: var(--control); padding: 0;
  border: 0; border-radius: var(--r-sm); background: none; color: var(--text-2); cursor: pointer;
}
.btn-block { width: 100%; }
.icon { flex-shrink: 0; }

/* ---------- feed ---------- */
.tabs {
  display: flex; gap: var(--s-1);
  margin: 0 calc(-1 * var(--s-4)); padding: 0 var(--s-4);
  overflow-x: auto; scrollbar-width: none;
}
/* Feed topics: stuck under the top bar; they slide away while scrolling down, back on scrolling up. */
.topic-tabs {
  position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top)); z-index: 3;
  background: var(--bg); border-bottom: 1px solid transparent;
  transition: transform var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}
.topic-tabs.is-stuck { border-bottom-color: var(--line); }
.topic-tabs.is-away { transform: translateY(-100%); }
/* "3 new posts": floats just under the topics (or the top bar when they've slid away). */
.new-pill {
  position: fixed; left: 50%; z-index: 4; transform: translateX(-50%);
  top: calc(var(--bar-h) + env(safe-area-inset-top) + var(--control) + var(--s-2));
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: var(--control); padding: 0 var(--s-4);
  border: 0; border-radius: var(--r-full); background: var(--accent); color: var(--accent-ink);
  font-weight: 700; white-space: nowrap; box-shadow: var(--shadow-1); cursor: pointer;
  transition: top var(--dur-2) var(--ease);
}
.topic-tabs.is-away ~ .new-pill { top: calc(var(--bar-h) + env(safe-area-inset-top) + var(--s-2)); }
@media (prefers-reduced-motion: no-preference) { .new-pill:not([hidden]) { animation: pill-in var(--dur-2) var(--ease); } }
@keyframes pill-in { from { opacity: 0; transform: translate(-50%, calc(-1 * var(--s-2))); } }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  min-height: var(--control); padding: 0 var(--s-3);
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  background: none; color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.tab[aria-pressed="true"], .tab[aria-current="page"] { color: var(--text); font-weight: 700; border-bottom-color: var(--accent); }
a.tab { display: inline-flex; align-items: center; text-decoration: none; }
.tab-count { margin-left: var(--s-1); font-size: var(--t-sm); font-weight: 700; color: var(--accent); }
.tab-count:empty { display: none; }
.saved-tabs { margin: calc(-1 * var(--s-4)) calc(-1 * var(--s-4)) var(--s-5); }

.earlier { display: flex; align-items: center; gap: var(--s-3); color: var(--text-2); font-size: var(--t-sm); }
.earlier::before, .earlier::after { content: ""; flex: 1; height: 1px; background: var(--line-strong); }

/* Resurfacing cards (a reading-list article coming back, like a throwback) share the soft sage. */
.listed {
  position: relative; display: flex; flex-direction: column; gap: var(--s-2);
  padding: var(--s-4) var(--s-5); background: var(--surface-cool); border-radius: var(--r-md);
}

.feed { display: flex; flex-direction: column; gap: var(--s-6); margin-top: var(--s-5); }

.entry { position: relative; display: flex; flex-direction: column; gap: var(--s-2); }
/* A hairline between consecutive posts; the gap above it stays. */
.entry + .entry { border-top: 1px solid var(--line); padding-top: var(--s-6); }
/* Opened posts step back: quieter title and summary (plus "Opened" in the meta line). */
.entry.is-read .entry-title a { color: var(--text-2); }
.entry.is-read .entry-title { font-weight: 400; }
.entry-title {
  font-family: var(--font-read); font-weight: 500;
  font-size: var(--t-2xl); line-height: var(--lh-2xl);
}
.entry-title a { color: var(--text); text-decoration: none; }
.entry-title a::after { content: ""; position: absolute; inset: calc(-1 * var(--s-2)); border-radius: var(--r-sm); }
.entry-title a:focus-visible { outline: none; }
.entry-title a:focus-visible::after { outline: 2px solid var(--accent); outline-offset: 2px; }
.entry-excerpt {
  font-family: var(--font-read); font-size: var(--t-lg); line-height: var(--lh-lg); color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
/* Tags: what a post is about, then what it is. Quiet labels, not buttons. */
.tags { list-style: none; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.tags li {
  padding: 0 var(--s-2); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  font-size: var(--t-sm); line-height: var(--lh-sm); color: var(--text-2);
}
.entry .tags { margin-top: var(--s-1); }
/* Saved: on the reading list (glasses) and/or bookmarked, at the end of the meta line. */
.saved-marks { display: inline-flex; gap: var(--s-1); margin-left: var(--s-2); vertical-align: -3px; color: var(--accent); }

.book-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--s-4);
  padding: var(--s-4);
  background: var(--surface-warm); border-radius: var(--r-md);
}
.book-actions { grid-column: 1 / -1; display: flex; flex-direction: column; gap: var(--s-3); }
.book-buttons { display: flex; gap: var(--s-2); }
.book-buttons .btn-primary { flex: 1; }
@media (min-width: 600px) { .book-buttons .btn-primary { flex: 0 1 auto; min-width: 160px; } }
.segmented { display: flex; gap: var(--s-1); padding: var(--s-1); background: var(--bg); border-radius: var(--r-sm); align-self: stretch; }
@media (min-width: 600px) { .segmented { align-self: flex-start; } }
.segmented button {
  flex: 1; min-height: var(--control); padding: 0 var(--s-3);
  border: 0; border-radius: var(--r-sm); background: none; color: var(--text-2); cursor: pointer;
  transition: background-color var(--dur-1) var(--ease);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: inset 0 0 0 1px var(--line-strong); }
.book-title { font-family: var(--font-read); font-weight: 500; font-size: var(--t-lg); line-height: var(--lh-2xl); }

.throwback {
  display: flex; flex-direction: column; gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  background: var(--surface-cool); border-radius: var(--r-md);
}
.quote { font-family: var(--font-read); font-style: italic; font-size: var(--t-lg); line-height: var(--lh-lg); }
.quote.note { font-style: normal; }

.feed-end { display: flex; flex-direction: column; align-items: center; gap: var(--s-2); padding: var(--s-6) 0; text-align: center; }

.empty { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-3); padding: var(--s-6) 0; }
.empty h2 { font-family: var(--font-read); font-weight: 500; font-size: var(--t-2xl); line-height: var(--lh-2xl); }

/* ---------- article ---------- */
.backrow { display: flex; align-items: center; margin: var(--s-2) 0 0 calc(-1 * var(--s-3)); }
.article-bar {
  position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top)); z-index: 4;
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 calc(-1 * var(--s-4)); padding: 0 var(--s-2);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.article-tools { display: flex; align-items: center; }
.article-tools .btn-icon[aria-pressed="true"] { color: var(--accent); }
.article-tools .theme-toggle[aria-pressed="true"] { color: var(--text-2); } /* the moon is a state, not a highlight */
.end-block { display: flex; flex-direction: column; gap: var(--s-3); margin-top: var(--s-7); padding-top: var(--s-6); border-top: 1px solid var(--line); }
.end-block .section-title { margin: 0; }
.fulltext:not(:empty) { margin-top: var(--s-7); padding-top: var(--s-6); border-top: 1px solid var(--line); }
.fulltext .meta { margin-bottom: var(--s-5); }
.fail-block { display: flex; flex-direction: column; gap: var(--s-2); }
.fail-block .article-actions { margin-top: var(--s-2); }
.end-block > .btn { align-self: flex-start; }

.popover {
  position: absolute; right: var(--s-2); top: 100%; z-index: 6;
  display: flex; flex-direction: column; gap: var(--s-3);
  width: min(320px, calc(100vw - 2 * var(--s-4))); padding: var(--s-4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
.popover-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.stepper { display: flex; align-items: center; }
.popover-value { min-width: 48px; text-align: center; font-weight: 600; }
.btn-icon:disabled { opacity: .4; cursor: default; }
.popover .segmented { flex: 0 0 auto; }

.reactions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.reaction {
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: var(--control); padding: 0 var(--s-3);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: none; color: var(--text); cursor: pointer;
  transition: background-color var(--dur-1) var(--ease);
}
.reaction[aria-pressed="true"] { background: var(--surface-cool); border-color: var(--accent); font-weight: 700; }
.reaction[aria-pressed="true"] .icon { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .reaction[aria-pressed="true"] .icon { animation: pop var(--dur-2) var(--ease); }
}
@keyframes pop { 50% { transform: scale(1.25); } }

.notes { list-style: none; display: flex; flex-direction: column; gap: var(--s-4); }
.note { display: flex; gap: var(--s-3); align-items: flex-start; }
.note-body { flex: 1; min-width: 0; }
.note-text { white-space: pre-wrap; overflow-wrap: break-word; }
.note-form { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-start; }
.note-form .textarea { flex: 1 1 200px; }
.note-form .btn { margin-left: auto; }
.textarea { min-height: 88px; padding: var(--s-3); line-height: var(--lh-md); resize: vertical; }
.avatar { display: inline-flex; flex-shrink: 0; border-radius: var(--r-full); overflow: hidden; background: var(--surface-cool); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-grid { display: flex; flex-wrap: wrap; gap: var(--s-2); }
/* A fixed, square hit box so the selection ring sits evenly around the avatar. */
.avatar-choice {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--control-lg); height: var(--control-lg); padding: 0; line-height: 0;
  border: 2px solid transparent; border-radius: var(--r-full); background: none; cursor: pointer;
}
.avatar-choice[aria-pressed="true"] { border-color: var(--accent); }
.article-head { display: flex; flex-direction: column; gap: var(--s-3); margin: var(--s-4) 0 var(--s-6); }
.article-title { font-family: var(--font-read); font-weight: 500; font-size: var(--t-2xl); line-height: var(--lh-2xl); }
@media (min-width: 900px) { .article-title { font-size: var(--t-3xl); line-height: var(--lh-3xl); } }
.article-actions { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-top: var(--s-7); }
.article-actions + .article-actions { margin-top: var(--s-3); }
audio { width: 100%; }

.prose { font-family: var(--font-read); font-size: calc(var(--t-xl) * var(--read-scale)); line-height: var(--lh-xl); overflow-wrap: break-word; }
.prose > * + * { margin-top: 1em; }
.prose h2, .prose h3, .prose h4 { font-weight: 500; line-height: var(--lh-2xl); margin-top: 1.5em; }
.prose h2 { font-size: var(--t-2xl); }
.prose h3, .prose h4 { font-size: var(--t-xl); }
.prose ul, .prose ol { padding-left: var(--s-5); }
.prose blockquote { margin-left: var(--s-5); font-style: italic; color: var(--text-2); }
.prose img { display: block; border-radius: var(--r-sm); }
.prose figcaption { font-family: var(--font-ui); font-size: var(--t-sm); color: var(--text-2); margin-top: var(--s-2); }
.prose pre { overflow-x: auto; font-size: var(--t-sm); }
.prose hr { border: 0; text-align: center; }
.prose hr::after { content: "·  ·  ·"; color: var(--text-2); }

/* ---------- reader ---------- */
.reader-bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--s-2);
  height: var(--bar-h); padding: 0 var(--s-3) 0 var(--s-1);
  padding-top: env(safe-area-inset-top); box-sizing: content-box;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.reader-bar .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.reader-bar .time { font-size: var(--t-sm); color: var(--text-2); white-space: nowrap; }
.enso .enso-arc { transition: stroke-dasharray var(--dur-3) var(--ease); }
.book-text { max-width: var(--col); margin: 0 auto; padding: var(--s-6) var(--s-5) var(--s-8); }
.book-text .meta { margin-bottom: var(--s-5); }
.chapter-nav { display: flex; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-7); }

.complete {
  max-width: 440px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: var(--s-5);
  padding: var(--s-8) var(--s-5) var(--s-7); text-align: center;
}
.complete h1 { font-family: var(--font-read); font-weight: 400; font-size: var(--t-3xl); line-height: var(--lh-3xl); }
.complete form { align-self: stretch; display: flex; flex-direction: column; gap: var(--s-2); text-align: left; }
.complete .actions { align-self: stretch; display: flex; flex-direction: column; gap: var(--s-2); margin-top: var(--s-5); }
.status-ok { color: var(--success); }
.status-warn { color: var(--warning); }
@media (prefers-reduced-motion: no-preference) {
  .complete { animation: fade-up var(--dur-3) var(--ease) both; }
}
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- saved ---------- */
.tree { display: block; width: 100%; max-width: 420px; height: auto; margin: 0 auto; }
.week { margin: var(--s-5) 0 var(--s-7); }
.saved-list { display: flex; flex-direction: column; gap: var(--s-6); list-style: none; }
.saved-item { display: flex; flex-direction: column; gap: var(--s-2); }
.saved-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }

/* ---------- library ---------- */
.list { display: flex; flex-direction: column; list-style: none; }
.row { display: flex; align-items: center; gap: var(--s-3); min-height: var(--bar-h); padding: var(--s-2) 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; color: var(--text); text-decoration: none; }
.row-title { font-family: var(--font-read); font-size: var(--t-lg); line-height: var(--lh-2xl); }
.post-row, .list > li > .folder-row { border-bottom: 1px solid var(--line); }
.folder-row { display: flex; align-items: center; gap: var(--s-3); min-height: var(--bar-h); color: var(--text); text-decoration: none; }
.folder-name { flex: 1; min-width: 0; }
.folder-edit { margin-bottom: var(--s-5); gap: var(--s-4); }
.check-row { display: flex; align-items: center; gap: var(--s-3); min-height: var(--control); cursor: pointer; }
.check-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.topic-group { border-bottom: 1px solid var(--line); }
.topic-group summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  min-height: var(--bar-h); cursor: pointer; list-style: none;
}
.topic-group summary::-webkit-details-marker { display: none; }
.topic-group summary::after { content: ""; width: 8px; height: 8px; margin-left: var(--s-2); border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2); transform: rotate(45deg); transition: transform var(--dur-2) var(--ease); }
.topic-group[open] summary::after { transform: rotate(-135deg); }
.topic-group summary .meta { margin-left: auto; }
.topic-group .list { padding-bottom: var(--s-3); }
.book-row + .book-row { margin-top: var(--s-4); }
.row-sub { display: flex; align-items: center; gap: var(--s-3); }
.warn { color: var(--warning); }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: var(--s-7); }
.sheet-form { gap: var(--s-5); }
.plain-fieldset { display: flex; flex-direction: column; margin: 0; padding: 0; border: 0; min-width: 0; }
.plain-fieldset legend { padding: 0; margin-bottom: var(--s-1); }
.add-article { margin-bottom: var(--s-5); }
.fieldset { display: flex; flex-direction: column; gap: var(--s-4); }
.fieldset .section-title { margin-bottom: 0; }
.inline-field { display: flex; gap: var(--s-2); }
.inline-field .input { flex: 1; min-width: 0; }
.input.input-compact { width: auto; min-height: var(--control); }
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field label, .label { font-weight: 600; }
.input, select.input {
  min-height: var(--control-lg); padding: 0 var(--s-3);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); font-size: var(--t-md); color: var(--text);
  width: 100%;
}
.hint { font-size: var(--t-sm); line-height: var(--lh-sm); color: var(--text-2); }
.switch {
  appearance: none; -webkit-appearance: none; flex-shrink: 0;
  position: relative; width: 48px; height: 28px; margin: 8px 0;
  border-radius: var(--r-full); background: var(--line-strong); cursor: pointer;
  transition: background-color var(--dur-2) var(--ease);
}
.switch::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: var(--r-full); background: var(--surface);
  transition: transform var(--dur-2) var(--ease);
}
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(20px); }
.switch:focus-visible { outline-offset: 3px; border-radius: var(--r-full); }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-input:focus-visible + .btn { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- floating bars ---------- */
.selbar, .toast {
  position: fixed; left: 50%; z-index: 20;
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
  bottom: calc(var(--nav-h) + var(--s-4) + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); border-radius: var(--r-md);
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease);
}
body[data-route="read"] .selbar, body[data-route="read"] .toast { bottom: calc(var(--s-5) + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .selbar, .toast { bottom: var(--s-6); } }
.selbar.show, .toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.selbar { padding: var(--s-1); box-shadow: var(--shadow-1); }
.selbar .btn { color: var(--bg); }
.toast { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); box-shadow: var(--shadow-2); max-width: calc(100vw - 2 * var(--s-4)); min-height: var(--control); }
.toast .btn-text { color: var(--surface-cool); }
.toast span { white-space: nowrap; }

/* ---------- sheets and drawer ---------- */
dialog.sheet, dialog.drawer {
  position: fixed; margin: 0; border: 0; padding: var(--s-4);
  max-width: none; max-height: none; overflow: auto;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.sheet {
  inset: auto 0 0 0; width: 100%; max-height: 85vh;
  padding-bottom: calc(var(--s-5) + env(safe-area-inset-bottom));
  border-radius: var(--r-md) var(--r-md) 0 0;
}
@media (min-width: 600px) { .sheet { inset: 0; margin: auto; width: 440px; height: fit-content; border-radius: var(--r-md); } }
.drawer { inset: 0 auto 0 0; width: min(360px, 88vw); height: 100%; padding-top: calc(var(--s-4) + env(safe-area-inset-top)); }
@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: sheet-up var(--dur-3) var(--ease); }
  .drawer[open] { animation: drawer-in var(--dur-3) var(--ease); }
}
@media (prefers-reduced-motion: no-preference) and (min-width: 600px) { .sheet[open] { animation-name: fade-up; } }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes drawer-in { from { transform: translateX(-100%); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s-3); }
.sheet-title { font-family: var(--font-read); font-weight: 500; font-size: var(--t-2xl); line-height: var(--lh-2xl); }
.sheet-body { display: flex; flex-direction: column; gap: var(--s-4); }
.sheet-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-2); }
.drawer-row { display: flex; flex-direction: column; gap: 2px; padding: var(--s-3) 0; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.drawer-title { font-family: var(--font-read); font-size: var(--t-lg); line-height: var(--lh-2xl); }

.topbar-end { display: flex; align-items: center; gap: var(--s-2); }


/* ---------- bonsai (growth) ---------- */
.bonsai { display: block; width: 100%; max-width: 440px; max-height: 50vh; height: auto; margin: 0 auto; }
.stage { display: flex; flex-direction: column; align-items: center; gap: var(--s-2); margin-top: var(--s-3); text-align: center; }
.stage-name { font-family: var(--font-read); font-size: var(--t-2xl); line-height: var(--lh-2xl); }
.progress { width: min(280px, 100%); height: var(--s-2); border-radius: var(--r-full); background: var(--surface-warm); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--r-full); background: var(--accent); }
.stage + .hint { margin: var(--s-5) auto 0; max-width: 440px; text-align: center; }
.stats { margin-top: var(--s-6); text-align: center; align-items: center; }
.stats { display: flex; flex-direction: column; gap: var(--s-3); }
@media (prefers-reduced-motion: no-preference) {
  .bonsai.grew .pad { animation: grow-in var(--dur-3) var(--ease) both; animation-duration: 900ms; }
  .progress-fill { transition: width var(--dur-3) var(--ease); }
}
@keyframes grow-in { from { transform: scale(.7); opacity: .4; } }

/* ---------- daily brief ---------- */
.brief { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-4) var(--s-5); border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); }
.brief-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.brief-title { font-family: var(--font-read); font-weight: 500; font-size: var(--t-2xl); line-height: var(--lh-2xl); }
.brief-list { list-style: none; display: flex; flex-direction: column; }
.brief-list li + li { border-top: 1px solid var(--line); }
.brief-link { display: flex; flex-direction: column; gap: 2px; padding: var(--s-3) 0; min-height: var(--control); color: var(--text); text-decoration: none; }
.brief-item { font-family: var(--font-read); font-size: var(--t-lg); line-height: var(--lh-2xl); }
.brief-list li.is-read .brief-item { color: var(--text-2); }

/* ---------- video ---------- */
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-warm); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-play {
  position: absolute; left: var(--s-3); bottom: var(--s-3); display: flex; align-items: center; justify-content: center;
  width: var(--control); height: var(--control); border-radius: var(--r-full); background: var(--surface); color: var(--text);
}
.thumb-time {
  position: absolute; right: var(--s-3); bottom: var(--s-3); padding: 0 var(--s-2);
  border-radius: var(--r-sm); background: var(--surface); color: var(--text);
  font-size: var(--t-sm); line-height: var(--lh-sm); font-weight: 700; font-variant-numeric: tabular-nums;
}
/* Shorts: tall, and they play right in the feed (one player moves between them, js/shorts.js). */
.short-slot {
  position: relative; align-self: center; aspect-ratio: 9 / 16; height: min(70vh, 560px); max-width: 100%;
  border-radius: var(--r-sm); overflow: hidden; background: var(--surface-warm);
}
.short-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.short-play { display: none; border: 0; padding: 0; cursor: pointer; }
.shorts-on .short-slot { z-index: 1; cursor: pointer; }
.shorts-on .short-play { display: flex; }
.shorts-on .short-slot.is-playing .short-play { display: none; }
.short-layer { position: absolute; z-index: 2; border-radius: var(--r-sm); overflow: hidden; background: #000; }
.short-frame, .short-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.short-sound {
  position: absolute; top: var(--s-2); right: var(--s-2);
  display: flex; align-items: center; justify-content: center;
  width: var(--control); height: var(--control); padding: 0;
  border: 0; border-radius: var(--r-full); background: var(--surface); color: var(--text); cursor: pointer;
}
.player { aspect-ratio: 16 / 9; border-radius: var(--r-sm); overflow: hidden; background: #000; margin-top: var(--s-2); }
.player.is-short { aspect-ratio: 9 / 16; max-height: 70vh; margin-inline: auto; }
.player iframe { width: 100%; height: 100%; border: 0; display: block; }
.video-desc { white-space: pre-line; font-size: calc(var(--t-md) * var(--read-scale)); line-height: var(--lh-md); font-family: var(--font-ui); color: var(--text-2); }

/* ---------- posts: meta row with an action, hidden posts, no system callout on hold ---------- */
.entry-meta-row { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin: calc(-1 * var(--s-2)) 0; }
.entry-meta-row .btn-icon { margin-right: calc(-1 * var(--s-3)); }
/* Holding a post opens its preview, so nothing in a post (or the preview) is selectable. */
.entry[data-post], .entry[data-post] *, .brief-link, dialog.peek, dialog.peek * { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* Swipe a post left: its content slides over and two buttons appear on the right edge. */
.swipe-on .entry[data-post] { touch-action: pan-y; }
.entry.swiping { overflow: hidden; }
.entry.swiping > :not(.swipe-actions) { transform: translateX(var(--dx, 0px)); }
.swipe-actions { position: absolute; right: 0; bottom: 0; z-index: 2; display: flex; width: max(0px, calc(-1 * var(--dx, 0px) - var(--s-2))); border-radius: var(--r-sm); overflow: hidden; }
.entry.swipe-anim > * { transition: transform var(--dur-2) var(--ease), width var(--dur-2) var(--ease); }
.swipe-btn { flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; border: 0; padding: 0; overflow: hidden; cursor: pointer; }
.swipe-later { background: var(--accent); color: var(--accent-ink); }
.swipe-hide { background: var(--surface-warm); color: var(--text); }
.swipe-btn:focus-visible { outline: 2px solid var(--text); outline-offset: -4px; }
.entry-hidden { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: var(--control); padding: 0 var(--s-3); border: 1px dashed var(--line-strong); border-radius: var(--r-sm); }
.entry + .entry-hidden, .entry-hidden + .entry { margin-top: 0; }

/* ---------- long-press preview + actions ---------- */
dialog.peek { border: 0; padding: var(--s-4); margin: auto; max-width: none; max-height: none; background: none; color: var(--text); width: min(640px, 100%); overflow: visible; }
.peek-inner { display: flex; flex-direction: column; gap: var(--s-3); }
@media (min-width: 700px) { .peek-inner { flex-direction: row; align-items: flex-start; } .peek-card { flex: 1; } .peek-menu { width: 240px; } }
.peek-card { display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-5); background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-2); max-height: 60vh; overflow: auto; }
.peek-card .btn { align-self: flex-start; margin-top: var(--s-2); }
.peek-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--r-sm); background: var(--surface-warm); }
.peek-title { font-family: var(--font-read); font-weight: 500; font-size: var(--t-xl); line-height: var(--lh-2xl); }
.peek-excerpt { font-family: var(--font-read); font-size: var(--t-lg); line-height: var(--lh-lg); color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }
.peek-menu { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-2); overflow: hidden; }
.peek-action { display: flex; align-items: center; gap: var(--s-3); min-height: var(--control-lg); padding: 0 var(--s-4); border: 0; background: none; color: var(--text); text-align: left; cursor: pointer; }
.peek-action + .peek-action { border-top: 1px solid var(--line); }
.peek-action:hover, .peek-action:focus-visible { background: var(--surface-cool); }
.peek-action:focus-visible { outline-offset: -2px; }
.peek-action .icon { color: var(--text-2); }
@media (prefers-reduced-motion: no-preference) {
  dialog.peek[open] .peek-card, dialog.peek[open] .peek-menu { animation: peek-in var(--dur-2) var(--ease); }
}
@keyframes peek-in { from { opacity: 0; transform: scale(.96); } }

/* ---------- jump button ---------- */
.jump {
  position: fixed; z-index: 15; display: flex; align-items: center; justify-content: center;
  width: var(--control); height: var(--control); padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--r-full);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-1);
  touch-action: none; cursor: grab;
  transition: left var(--dur-2) var(--ease), right var(--dur-2) var(--ease), top var(--dur-2) var(--ease), opacity var(--dur-2) var(--ease);
}
.jump.dragging { transition: none; cursor: grabbing; opacity: .9; }

/* ---------- pull to refresh (feed) ---------- */
.pull {
  position: fixed; left: 50%; top: calc(var(--bar-h) + env(safe-area-inset-top)); z-index: 4;
  display: flex; align-items: center; justify-content: center;
  width: var(--control); height: var(--control); margin-left: calc(var(--control) / -2);
  border: 1px solid var(--line-strong); border-radius: var(--r-full);
  background: var(--surface); color: var(--text-2); box-shadow: var(--shadow-1);
  opacity: 0; pointer-events: none;
  transform: translateY(calc(var(--pull, 0px) - var(--control)));
}
.pull:not(.show) { transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease); }
.pull.show { opacity: 1; }
.pull .icon { transform: rotate(var(--turn, 0deg)); }
.pull.ready { color: var(--accent); }
.pull.busy .icon { animation: pull-spin 900ms linear infinite; }
@media (prefers-reduced-motion: reduce) { .pull.busy .icon { animation: none; } }
@keyframes pull-spin { to { transform: rotate(360deg); } }
