/* ---------------------------------------------------------------- tokens
   Calm, low-contrast-glare palette. Text still meets WCAG AA. */
:root {
  --bg: #f4f1ec;
  --canvas: #ebe6de;
  --dot: #d3cbbf;
  --surface: #fffdf9;
  --surface-2: #f3efe8;
  --col-bg: #f8f5f0;
  --text: #2a2825;
  --muted: #6b665e;
  --border: #e2dace;
  --rail: #d9d0c2;
  --accent: #46698c;
  --accent-soft: #dfe8f1;
  --accent-ink: #ffffff;
  --danger: #a4473f;
  --highlight: #fff1c2;
  --shadow: 0 1px 2px rgba(60, 50, 30, .06), 0 2px 8px rgba(60, 50, 30, .05);
  --radius: 8px;       /* cards, columns-level boxes */
  --radius-sm: 6px;    /* things inside cards, buttons, inputs */
  --radius-lg: 12px;   /* dialogs */
  --lh: 1.55;
  --top-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #1b1d20; --canvas: #16181a; --dot: #2c3035; --surface: #24272b; --surface-2: #2c3035; --col-bg: #1f2225;
    --text: #e8e4dc; --muted: #a39d93; --border: #353a40; --rail: #3d434a; --accent: #8fb0cf; --accent-soft: #2b3a49;
    --accent-ink: #14202c; --danger: #e08b82; --highlight: #4a4020; --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1d20; --canvas: #16181a; --dot: #2c3035; --surface: #24272b; --surface-2: #2c3035; --col-bg: #1f2225;
  --text: #e8e4dc; --muted: #a39d93; --border: #353a40; --rail: #3d434a; --accent: #8fb0cf; --accent-soft: #2b3a49;
  --accent-ink: #14202c; --danger: #e08b82; --highlight: #4a4020; --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}
:root[data-text="s"] { font-size: 15px; }
:root, :root[data-text="m"] { font-size: 16.5px; }
:root[data-text="l"] { font-size: 18.5px; }
:root[data-text="xl"] { font-size: 21px; }
:root[data-spacing="relaxed"] { --lh: 1.8; letter-spacing: .01em; word-spacing: .06em; }
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after {
  animation-duration: 0s !important; transition-duration: 0s !important; scroll-behavior: auto !important;
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  display: flex; flex-direction: column; background: var(--bg); color: var(--text);
  font: 400 1rem/var(--lh) system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-underline-offset: .15em; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
svg.ico { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  flex: none; height: var(--top-h); display: flex; align-items: center; gap: 12px; padding: 0 12px;
  padding-top: env(safe-area-inset-top); background: var(--bg); border-bottom: 1px solid var(--border); z-index: 5;
}
.hub-name { background: none; border: 0; font-weight: 700; font-size: 1.05rem; padding: 6px 8px; border-radius: var(--radius-sm); white-space: nowrap; }
.hub-name:hover { background: var(--surface-2); }
.nav { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 6px; }
.where { min-width: 0; max-width: 360px; flex: 0 1 360px; display: grid; text-align: center; line-height: 1.25; }
.where strong, .where small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.where small { color: var(--muted); font-size: .78rem; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none; font-size: 1.5rem; line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.me-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px 0 6px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; max-width: 180px;
}
.me-btn > span:only-child { padding-left: 6px; }
.me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.is-offline .where small::after { content: " · offline, showing saved posts"; color: var(--danger); }
@media (max-width: 640px) {
  .topbar { gap: 4px; padding: 0 6px; }
  .hub-name, .me-name { display: none; }
  .me-btn { padding: 0 6px; }
  .nav { justify-content: flex-start; }
}

/* ---------------------------------------------------------------- canvas */
.viewport {
  position: relative; flex: 1; overflow: hidden; touch-action: none; user-select: none;
  background-color: var(--canvas);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1.3px);
}
.viewport.is-dragging { cursor: grabbing; }
.viewport.is-overview { cursor: grab; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }

.column {
  position: absolute; top: 6px; left: var(--x, 0px);
  width: var(--w, 420px); height: calc(var(--col-h) - 6px);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--col-bg); border: 1px solid var(--border); border-bottom: 0; border-radius: 10px 10px 0 0;
  box-shadow: var(--shadow); user-select: text; touch-action: pan-y;
}
@media (max-width: 640px) { .column { top: 6px; height: calc(var(--col-h) - 6px); } }
.is-overview .column { touch-action: none; user-select: none; cursor: pointer; transition: box-shadow .2s; }
.is-overview .column:hover { box-shadow: 0 0 0 6px var(--accent); }
.is-overview .column * { pointer-events: none; }

.col-head {
  flex: none; position: relative; min-height: 96px; padding: 14px 14px 10px; display: flex; flex-direction: column; justify-content: flex-end;
  background-size: cover; background-position: center; cursor: grab; touch-action: pan-y;
}
.col-title { margin: 0; font-size: 1.3rem; line-height: 1.2; overflow-wrap: anywhere; }
.col-meta { font-size: .8rem; opacity: .85; margin-top: 4px; }
.col-meta a, .col-head a { color: inherit; }
.col-origin {
  position: absolute; top: 10px; left: 12px; display: inline-flex; align-items: center; gap: 6px; max-width: calc(100% - 24px);
  padding: 3px 10px 3px 8px; border-radius: 99px; font-size: .78rem; text-decoration: none;
  background: rgba(0, 0, 0, .22); color: #fff !important; backdrop-filter: blur(4px);
}
.col-origin span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-origin:hover { background: rgba(0, 0, 0, .35); }

.col-scroll {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 8px 40vh; touch-action: pan-y;
  scrollbar-width: thin; scrollbar-color: var(--rail) transparent;
}
.col-scroll:focus { outline: none; }
.is-overview .col-scroll { overflow: hidden; }
.col-end { text-align: center; color: var(--muted); font-size: .85rem; margin: 20px 0; }
.col-more { height: 1px; }

.compose-bar {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 8px;
  border: 1px dashed var(--rail); border-radius: var(--radius); background: var(--surface); color: var(--muted); text-align: left;
}
.compose-bar:hover { border-color: var(--accent); color: var(--text); }

.col-preview { padding: 8px; display: grid; gap: 6px; }
.mini-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: .9rem; }
.mini-card p { margin: 2px 0 0; color: var(--muted); }
.mini-card small { color: var(--accent); }
.mini-empty { text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- avatars */
.avatar { flex: none; border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; font-weight: 700; background: var(--surface-2); }
.avatar-sm { width: 28px; height: 28px; font-size: .7rem; }
.avatar-md { width: 40px; height: 40px; font-size: .9rem; }
.avatar-xl { width: 92px; height: 92px; font-size: 2rem; border: 4px solid var(--surface); }

/* ---------------------------------------------------------------- cards & threads */
.thread { margin-bottom: 8px; }
.replies .thread { margin: 6px 0 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px 4px; box-shadow: var(--shadow);
}
.card.is-reply { padding: 8px 10px 2px; box-shadow: none; }
.card.is-deleted { background: transparent; box-shadow: none; border-style: dashed; }
.card-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-author { display: flex; align-items: center; gap: 8px; min-width: 0; color: inherit; text-decoration: none; }
.card-author:hover .card-name { text-decoration: underline; }
.card-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-handle { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-time { margin-left: auto; color: var(--muted); font-size: .8rem; white-space: nowrap; text-decoration: none; }
.card-time:hover { text-decoration: underline; }
.card-text { margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-text.is-question { font-weight: 650; font-size: 1.05rem; }
.card-removed { margin: 8px 0 10px; color: var(--muted); font-style: italic; }
.card-actions { display: flex; flex-wrap: wrap; gap: 0; margin: 2px -6px 0; }
.act {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 4px 8px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--muted); font-size: .88rem;
}
.act:hover { background: var(--surface-2); color: var(--text); }
.act-danger:hover { color: var(--danger); }
.card.is-highlight { animation: highlight 2.4s ease-out; }
@keyframes highlight { 0%, 40% { background: var(--highlight); box-shadow: 0 0 0 3px var(--accent); } 100% { background: var(--surface); } }
:root[data-motion="reduce"] .card.is-highlight { box-shadow: 0 0 0 3px var(--accent); animation: none !important; }

.replies { margin-left: 2px; padding-left: 8px; border-left: 2px solid var(--rail); }
.thread.depth-2 > .replies, .thread.depth-3 > .replies { margin-left: 0; padding-left: 0; border-left: 0; }
.card-replyto { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.replies-toggle {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 0 2px; padding: 4px 8px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--accent); font-size: .85rem; font-weight: 600;
}
.replies-toggle:hover { background: var(--accent-soft); }
.replies-toggle .ico { transition: transform .2s; }
.replies-hidden > .replies { display: none; }
.replies-hidden > .replies-toggle .ico { transform: rotate(-90deg); }

.collapse-btn { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); order: -1; margin-left: -6px; }
.collapse-btn:hover { background: var(--surface-2); color: var(--text); }
.collapse-btn .ico { transition: transform .2s; }
.card-snippet { display: none; color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.is-collapsed > .card { padding-bottom: 10px; }
.is-collapsed > .card > :not(.card-head), .is-collapsed > .replies { display: none; }
.is-collapsed > .card .card-snippet { display: block; }
.is-collapsed > .card .card-handle, .is-collapsed > .card .card-time { display: none; }
.is-collapsed > .card .collapse-btn .ico { transform: rotate(-90deg); }

/* ---------------------------------------------------------------- attachments */
.link-card {
  display: block; margin: 6px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden;
  color: inherit; text-decoration: none; background: var(--surface-2);
}
.link-card:hover { border-color: var(--accent); }
.link-img { display: block; width: 100%; aspect-ratio: 1.91 / 1; object-fit: cover; background: var(--border); }
.link-meta { display: grid; gap: 2px; padding: 10px 12px; }
.link-site { color: var(--muted); font-size: .78rem; text-transform: lowercase; }
.link-title { line-height: 1.3; overflow-wrap: anywhere; }
.link-desc { color: var(--muted); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.img-grid { display: grid; gap: 4px; margin: 8px 0; border-radius: var(--radius-sm); overflow: hidden; grid-template-columns: 1fr 1fr; }
.img-grid.n1 { grid-template-columns: 1fr; }
.img-grid.n3 .img-btn:first-child { grid-column: span 2; }
.img-btn { padding: 0; border: 0; background: var(--surface-2); display: block; cursor: zoom-in; }
.img-btn img { display: block; width: 100%; height: 100%; aspect-ratio: 1; object-fit: cover; }
.img-grid.n1 img { height: auto; max-height: 70vh; object-fit: contain; aspect-ratio: auto; }
.img-grid.n3 .img-btn:first-child img { aspect-ratio: 2 / 1; }

.video, .embed { display: block; width: 100%; aspect-ratio: 16 / 9; margin: 8px 0; border-radius: var(--radius-sm); background: #111; overflow: hidden; }
.embed iframe { width: 100%; height: 100%; border: 0; display: block; }
.embed-btn { position: relative; width: 100%; height: 100%; padding: 0; border: 0; background: #1d1f22; color: #fff; display: block; }
.embed-btn img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .85; }
.embed-play { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, .6); }
.embed-play svg { width: 26px; height: 26px; fill: #fff; stroke: none; margin-left: 3px; }
.embed-label { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 12px 10px; text-align: left; display: grid; font-weight: 600; background: linear-gradient(transparent, rgba(0, 0, 0, .75)); }
.embed-label small { font-weight: 400; opacity: .85; }

.poll { display: grid; gap: 6px; margin: 8px 0; }
.poll-opt {
  position: relative; overflow: hidden; display: flex; justify-content: space-between; gap: 10px; align-items: center;
  min-height: 42px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); text-align: left;
}
.poll-opt::before { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--pct); background: var(--accent-soft); transition: width .4s; }
.poll-opt > * { position: relative; }
.poll-opt:hover { border-color: var(--accent); }
.poll-opt[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 650; }
.poll-pct { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.poll-foot { margin: 2px 0 0; color: var(--muted); font-size: .8rem; }

.col-link {
  display: flex; flex-direction: column; margin: 6px 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  text-decoration: none; color: inherit; background: var(--surface-2);
}
.col-link:hover { border-color: var(--accent); }
.col-link-band { height: 56px; background-size: cover; background-position: center; }
.col-link-body { display: grid; gap: 2px; padding: 10px 12px 12px; }
.col-link-kicker { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.col-link-title { font-size: 1.05rem; }
.col-link-go { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; font-size: .9rem; }
.col-link.is-missing { padding: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- dialogs */
.dlg {
  width: min(580px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 18px; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.dlg::backdrop { background: rgba(20, 18, 15, .45); }
.dlg[open] { animation: dlg-in .18s ease-out; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(12px); } }
@media (max-width: 640px) {
  .dlg { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92dvh; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
}
.dlg-small { width: min(420px, calc(100vw - 24px)); }
.dlg-close { position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border: 0; border-radius: var(--radius-sm); background: none; font-size: 1.6rem; line-height: 1; color: var(--muted); z-index: 2; }
.dlg-close:hover { background: var(--surface-2); color: var(--text); }
.dlg-title { margin: 0 40px 14px 0; font-size: 1.2rem; }
.dlg-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 16px; }
.dlg-foot .muted { margin-right: auto; }
.confirm-msg { margin: 8px 40px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-weight: 600;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn-small { min-height: 36px; padding: 5px 12px; font-size: .9rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { color: var(--danger); }
.btn-primary.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.file-btn { cursor: pointer; }
.file-btn:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: inherit; line-height: var(--lh);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 5rem; }
.field { display: grid; gap: 4px; margin: 12px 0; }
.field-label { font-weight: 600; font-size: .9rem; display: block; margin-top: 10px; }
.field .field-label { margin-top: 0; }
.field-hint { color: var(--muted); font-size: .8rem; }
.form-status { min-height: 1.4em; margin: 10px 0 0; color: var(--muted); font-size: .9rem; }
.form-status.is-error { color: var(--danger); }
.check { display: flex; align-items: center; gap: 10px; margin: 16px 0 0; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.kind-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.kind-tab { padding: 6px 12px; border: 1px solid var(--border); border-radius: 99px; background: var(--surface-2); font-size: .9rem; min-height: 36px; }
.kind-tab[aria-checked="true"], .kind-tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.compose-text { margin-bottom: 4px; }
.compose-section { margin-top: 10px; }
.compose-quote { margin: 0 0 14px; padding: 8px 12px; border-left: 3px solid var(--rail); color: var(--muted); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.compose-preview:not(:empty) { margin-top: 8px; }
.compose-images { display: grid; gap: 10px; margin-bottom: 10px; }
.compose-image { display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; align-items: center; }
.compose-image img { width: 72px; height: 72px; object-fit: cover; border-radius: var(--radius-sm); }
.poll-edit { display: grid; gap: 8px; margin-bottom: 8px; }
.poll-edit-row { display: flex; gap: 8px; }
.compose-colhead { border-radius: var(--radius); margin-bottom: 4px; cursor: default; min-height: 90px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border); padding: 0; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent); }

.setting { border: 0; padding: 0; margin: 16px 0 0; }
.setting legend { font-weight: 650; margin-bottom: 6px; padding: 0; }
.setting p { margin: 0 0 8px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; }
.seg-opt span { display: inline-block; padding: 6px 14px; border: 1px solid var(--border); border-radius: 99px; background: var(--surface-2); cursor: pointer; }
.seg-opt input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg-opt input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* profile */
.dlg-profile { padding: 0; width: min(620px, calc(100vw - 24px)); }
@media (max-width: 640px) { .dlg-profile { padding: 0 0 env(safe-area-inset-bottom); } }
.dlg-profile .dlg-close { background: rgba(0, 0, 0, .3); color: #fff; }
.profile-hero { height: 170px; background-size: cover; background-position: center; }
.profile-head { display: flex; align-items: flex-end; gap: 14px; padding: 0 20px; margin-top: -46px; }
.profile-head > div { flex: 1; min-width: 0; padding-bottom: 4px; }
.profile-head .btn { margin-bottom: 8px; }
.profile-name { margin: 0; font-size: 1.35rem; line-height: 1.2; overflow-wrap: anywhere; }
.profile-head p { margin: 2px 0 0; font-size: .9rem; }
.profile-bio { padding: 0 20px; margin: 14px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.profile-edit { padding: 22px 20px 20px; }
.token-box { margin: 16px 20px 0; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.token-box summary { cursor: pointer; font-weight: 600; }
.token-box p { margin: 8px 0; }
.profile-activity { padding: 6px 20px 22px; }
.profile-activity h3 { font-size: 1rem; margin: 18px 0 8px; }
.activity { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.activity-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: inherit; text-decoration: none; background: var(--surface);
}
.activity-item:hover { border-color: var(--accent); }
.activity-when { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.activity-snippet { grid-column: 1 / -1; color: var(--muted); font-size: .88rem; }

/* lightbox */
.dlg-lightbox { width: auto; max-width: 96vw; padding: 0; background: transparent; border: 0; box-shadow: none; }
.dlg-lightbox .dlg-close { background: rgba(0, 0, 0, .5); color: #fff; }
.dlg-lightbox::backdrop { background: rgba(0, 0, 0, .85); }
.lightbox { margin: 0; }
.lightbox img { display: block; max-width: 96vw; max-height: 86dvh; object-fit: contain; border-radius: var(--radius-sm); cursor: zoom-out; }
.lightbox figcaption { color: #eee; text-align: center; padding: 10px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 50;
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: var(--radius); background: var(--text); color: var(--bg);
  font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- admin */
.badge {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 99px; vertical-align: middle;
  background: var(--accent-soft); color: var(--accent); font-size: .72rem; font-weight: 700; letter-spacing: .03em;
}
a.btn { text-decoration: none; color: inherit; }
.dlg-admin { width: min(820px, calc(100vw - 24px)); }
@media (max-width: 640px) { .dlg-admin { width: 100vw; } }
.admin-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.admin-stat { display: grid; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.admin-stat strong { font-size: 1.3rem; line-height: 1.2; }
.admin-stat span { color: var(--muted); font-size: .8rem; }
@media (max-width: 480px) { .admin-summary { grid-template-columns: repeat(2, 1fr); } }
.admin-search { margin-bottom: 10px; }
.admin-list { display: grid; gap: 6px; min-height: 200px; align-content: start; }
.admin-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.admin-swatch { flex: none; width: 40px; height: 40px; border-radius: var(--radius-sm); background-size: cover; background-position: center; }
.admin-main { flex: 1; min-width: 0; display: grid; }
.admin-title { font-weight: 650; color: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.admin-title:hover, .admin-title a:hover { text-decoration: underline; }
.admin-title a { color: inherit; text-decoration: none; }
.admin-meta { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-actions { flex: none; display: flex; gap: 6px; }

/* ---------------------------------------------------------------- pins */
.col-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; }
.col-tool, .col-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border: 0; border-radius: 99px;
  background: rgba(0, 0, 0, .22); color: #fff; font-size: .78rem; font-weight: 600; backdrop-filter: blur(4px);
}
.col-tool:not(.col-pin) { width: 30px; padding: 0; justify-content: center; }
.col-tool:hover:not(:disabled) { background: rgba(0, 0, 0, .38); }
.col-pin[aria-pressed="true"], .col-pin[aria-pressed="true"]:hover:not(:disabled) { background: rgba(255, 255, 255, .92); color: #1d1c1a; }
.col-pin[aria-pressed="true"] svg { fill: currentColor; }
.col-head:has(.col-tools) .col-origin { max-width: calc(100% - 150px); }
.is-overview .col-tools { display: none; }

/* ---------------------------------------------------------------- references */
.ref-card {
  display: grid; gap: 4px; margin: 8px 0; padding: 10px 12px; border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); background: var(--surface-2); color: inherit; text-decoration: none; font-size: .92rem;
}
a.ref-card:hover { border-color: var(--accent); }
.ref-card.is-missing { display: flex; align-items: center; gap: 8px; color: var(--muted); font-style: italic; border-left-color: var(--rail); }
.ref-where { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .78rem; min-width: 0; }
.ref-where strong { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-dot { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.ref-author { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.ref-author .avatar-sm { width: 22px; height: 22px; font-size: .6rem; }
.ref-body { display: flex; gap: 10px; align-items: flex-start; overflow-wrap: anywhere; }
.ref-body img { flex: none; width: 56px; height: 56px; object-fit: cover; border-radius: 6px; }
.backlinks-box { margin: 0 0 6px; }
.backlinks-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; margin-left: -8px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--accent); font-size: .82rem; font-weight: 600; }
.backlinks-toggle:hover { background: var(--accent-soft); }
.backlinks { margin: 4px 0 6px; padding-left: 20px; font-size: .88rem; }
.compose-ref { margin-top: 12px; display: grid; gap: 8px; justify-items: start; }
.compose-ref .ref-card { width: 100%; margin: 0; }
.dlg-picker { width: min(620px, calc(100vw - 24px)); }
.ref-picker-list { display: grid; gap: 6px; margin-top: 10px; }
.ref-option { display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; border-radius: var(--radius-sm); }
.ref-option .ref-card { margin: 0; }
.ref-option:hover .ref-card, .ref-option:focus-visible .ref-card { border-color: var(--accent); }
.picked { display: flex; align-items: center; max-width: 240px; min-width: 0; border: 1px solid var(--accent); border-radius: 99px; background: var(--accent-soft); }
.picked-go { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 4px 4px 4px 10px; color: var(--accent); text-decoration: none; font-size: .82rem; font-weight: 600; }
.picked-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picked-clear { border: 0; background: none; color: var(--accent); font-size: 1.2rem; line-height: 1; padding: 2px 10px 4px 4px; }
@media (max-width: 960px) { .picked-text { display: none; } .picked-go { padding-right: 2px; } }

/* ---------------------------------------------------------------- reactions, more-menu, edits */
.card-edited { color: var(--muted); font-size: .8rem; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 2px; }
.react-chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 30px; padding: 2px 9px; border: 1px solid var(--border);
  border-radius: 99px; background: var(--surface-2); font-size: .9rem;
}
.react-chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.react-chip:hover { border-color: var(--accent); }
.react-n { font-size: .8rem; font-weight: 600; color: var(--muted); }
.react-chip[aria-pressed="true"] .react-n { color: var(--accent); }
.react-picker, .card-more { display: flex; flex-wrap: wrap; gap: 2px; margin: 0 -6px 4px; padding: 4px; border-radius: var(--radius-sm); background: var(--surface-2); }
.react-opt { width: 38px; height: 38px; border: 0; border-radius: var(--radius-sm); background: none; font-size: 1.2rem; }
.react-opt:hover { background: var(--accent-soft); }
.act[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }

/* ---------------------------------------------------------------- notifications */
.bell { position: relative; }
.bell-count {
  position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
}
.notif-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.notif {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: inherit; text-decoration: none;
}
.notif:hover { border-color: var(--accent); }
.notif.is-new { border-left: 3px solid var(--accent); background: var(--accent-soft); }
.notif-what { min-width: 0; }
.notif-when { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.notif-snippet { grid-column: 2 / -1; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- tokens & moderation */
.token-show { display: block; width: 100%; padding: 10px 12px; margin: 10px 0; border: 1px dashed var(--accent); border-radius: var(--radius-sm);
  background: var(--surface-2); font: .85rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; user-select: all; }
.badge.badge-warn { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.admin-row.is-removed { opacity: .92; border-style: dashed; }
.admin-body { color: var(--text); font-size: .88rem; overflow-wrap: anywhere; white-space: pre-wrap; max-height: 5.5em; overflow: hidden; }
.admin-actions { flex-wrap: wrap; justify-content: flex-end; }
.suspended-note { margin: 0; padding: 8px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-weight: 600; }
.admin-section { margin: 10px 0 2px; font-size: .9rem; color: var(--muted); }
.dlg-notifs { width: min(560px, calc(100vw - 24px)); }

/* ---------------------------------------------------------------- rows & archive */
.column { top: calc(var(--row, 0) * var(--row-pitch, 0px) + 6px); }
.row-label {
  position: absolute; left: 0; top: 0; white-space: nowrap; pointer-events: none;
  font-size: 56px; font-weight: 700; color: var(--muted); opacity: .8;
}
.world:not(.is-overview) .row-label { display: none; }
.is-overview .column.is-archived { opacity: .85; }
.badge.badge-muted { background: var(--surface-2); color: var(--muted); }
.archive-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: 99px; background: var(--surface); font-size: .85rem; font-weight: 600; white-space: nowrap;
}
.archive-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.archive-btn:hover { border-color: var(--accent); }
.archive-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
@media (max-width: 640px) { .archive-btn { padding: 0 8px; } .archive-btn span { display: none; } }

/* ---------------------------------------------------------------- phones: tighter, flatter */
@media (max-width: 640px) {
  :root { --radius: 6px; --radius-sm: 5px; --radius-lg: 10px; }
  .column { top: calc(var(--row, 0) * var(--row-pitch, 0px) + 4px); height: calc(var(--col-h) - 4px); border-radius: 6px 6px 0 0; }
  .col-scroll { padding: 4px 4px 40vh; }
  .compose-bar { margin-bottom: 4px; padding: 6px 10px; }
  .thread { margin-bottom: 6px; }
  .card { padding: 8px 10px 2px; }
  .card-actions { margin: 2px -4px 0; }
  .act { padding: 4px 6px; gap: 4px; }
  /* Replies: no card box, just a thin rail — keeps nearly the full width for the text. */
  .replies { margin-left: 0; padding-left: 6px; border-left-width: 2px; }
  .replies .thread { margin: 0; }
  .replies .thread + .thread { border-top: 1px solid var(--border); }
  .card.is-reply { border: 0; border-radius: 0; background: transparent; box-shadow: none; padding: 6px 2px 0 2px; }
  .card.is-reply .card-handle { display: none; }
  .collapse-btn { width: 26px; height: 28px; margin-left: -4px; }
  .replies-toggle { margin: 2px 0 0; }

  /* Column header shrinks to 40% while scrolling down (--collapse goes 0 → 1 with the scroll). */
  .column > .col-head {
    --c: var(--collapse, 0);
    min-height: 0; height: calc(96px - 57.6px * var(--c));
    padding: calc(12px - 6px * var(--c)) 12px calc(8px - 3px * var(--c));
    overflow: hidden;
  }
  .column > .col-head .col-title {
    font-size: calc(1.3rem - .25rem * var(--c));
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    padding-right: calc(110px * var(--c));
  }
  .column > .col-head .col-meta { opacity: calc(1 - 2.5 * var(--c)); max-height: calc(1.6em - 1.6em * var(--c)); overflow: hidden; }
  .column > .col-head .col-origin { opacity: calc(1 - 2.5 * var(--c)); }
  .column > .col-head .col-tools { top: calc(8px - 3px * var(--c)); right: 8px; }
  .column > .col-head .col-tool, .column > .col-head .col-chip { height: calc(30px - 4px * var(--c)); }
}

/* The focused column (desktop): the one the top bar, arrow keys and "n" refer to. */
@media (min-width: 641px) {
  .world:not(.is-overview) .column.is-focused { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
}

/* ---------------------------------------------------------------- column resize (desktop) */
.col-resize {
  position: absolute; top: 0; right: 0; bottom: 0; width: 8px; z-index: 3; cursor: col-resize; touch-action: none;
}
.col-resize::after {
  content: ""; position: absolute; top: 0; bottom: 0; right: 2px; width: 3px; border-radius: 2px;
  background: var(--accent); opacity: 0; transition: opacity .15s;
}
.col-resize:hover::after, body.is-resizing .col-resize::after { opacity: .6; }
body.is-resizing, body.is-resizing * { cursor: col-resize !important; user-select: none !important; }
@media (max-width: 640px) { .col-resize { display: none; } }
.is-overview .col-resize { display: none; }

/* While a sideways swipe is in progress the column must not scroll too (the browser would take over). */
.is-swiping .col-scroll { overflow-y: hidden; }

/* Zoomed-out snapshot of a column (see preview.js) */
.col-shot { flex: 1; background-color: var(--col-bg); background-repeat: no-repeat; background-size: 100% auto; }

/* ---------------------------------------------------------------- inline composer */
.inline-composer {
  margin: 0 0 8px; padding: 10px 12px 8px; border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft);
}
.inline-composer.is-reply { margin: 6px 0 4px; }
.compose-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: .9rem; }
.compose-head strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-close { width: 32px; height: 32px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); font-size: 1.4rem; line-height: 1; }
.compose-close:hover { background: var(--surface-2); color: var(--text); }
.inline-composer .kind-tabs { gap: 4px; margin-bottom: 8px; }
.inline-composer .kind-tab { min-height: 30px; padding: 3px 10px; font-size: .82rem; }
.inline-composer .compose-text { min-height: 4.5rem; }
.compose-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.compose-foot .muted { margin-right: auto; }
@media (max-width: 640px) { .compose-foot .muted { display: none; } .inline-composer { padding: 8px; } }

/* ---------------------------------------------------------------- calendar panel */
/* The panel sits beside the canvas; the canvas simply gets narrower (it re-measures itself). */
.stage { position: relative; flex: 1; min-height: 0; display: flex; }
.stage > .viewport { flex: 1; min-width: 0; }
.calendar {
  --cal-w: 200px;                                 /* ≈ 30% of a standard column; not resizable */
  flex: none; width: var(--cal-w); display: flex; flex-direction: column; min-height: 0;
  background: var(--bg); border-right: 1px solid var(--border); z-index: 4;
}
.calendar.is-collapsed { --cal-w: 44px; align-items: center; }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 8px 8px 6px 12px; }
.cal-head strong { font-size: .9rem; }
.cal-toggle { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); }
.cal-toggle:hover { color: var(--text); border-color: var(--accent); }
.calendar.is-collapsed .cal-toggle { margin: 8px 0 6px; }
.cal-list { flex: 1; overflow-y: auto; padding: 0 8px 24px; display: grid; gap: 6px; align-content: start; scrollbar-width: thin; }
.cal-day { margin: 8px 2px 0; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.cal-past-head { margin-top: 16px; }
.cal-empty { margin: 6px 4px; color: var(--muted); font-size: .8rem; }
.cal-entry {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end; gap: 1px; width: 100%;
  max-height: calc((var(--cal-w) - 16px) * 2 / 3);  /* never taller than 2/3 of the panel width */
  padding: 6px 8px; border: 0; border-radius: var(--radius-sm); overflow: hidden; text-align: left; font-size: .8rem;
}
.cal-entry.has-image { min-height: calc((var(--cal-w) - 16px) * 2 / 3); }
.cal-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .9; }
.cal-entry.has-image::before { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, rgba(0,0,0,.55)); z-index: 1; }
.cal-entry.has-image > span { position: relative; z-index: 2; color: #fff; }
.cal-meta { font-size: .7rem; font-weight: 700; opacity: .85; }
.cal-title { font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cal-entry.is-past { opacity: .55; }
.cal-entry:hover, .cal-marker:hover { filter: brightness(1.06); box-shadow: 0 0 0 2px var(--accent); }
.cal-strip { flex: 1; overflow-y: auto; display: grid; gap: 4px; align-content: start; padding: 0 0 16px; scrollbar-width: none; }
.cal-marker { width: 32px; height: 32px; border: 0; border-radius: var(--radius-sm); font-size: .8rem; font-weight: 700; }
/* Pulse: the background brightens and settles, like a gentle heartbeat. */
@keyframes cal-pulse {
  0%, 100% { filter: none; box-shadow: 0 0 0 0 transparent; }
  30% { filter: brightness(1.35) saturate(1.2); box-shadow: 0 0 0 3px var(--accent-soft); }
  60% { filter: brightness(1.1); }
}
.is-pulsing { animation: cal-pulse 1.4s ease-in-out 2; }
:root[data-motion="reduce"] .is-pulsing { animation: none !important; box-shadow: 0 0 0 3px var(--accent); }
/* Phones: collapsed by default; expanded it slides over the canvas instead of squeezing it. */
@media (max-width: 640px) {
  .calendar { position: absolute; left: 0; top: 0; bottom: 0; }
  .calendar.is-collapsed { --cal-w: 36px; }
  .cal-marker { width: 28px; height: 28px; }
  .calendar:not(.is-collapsed) { --cal-w: min(220px, 70vw); box-shadow: 4px 0 16px rgba(0,0,0,.18); }
  .stage > .viewport { margin-left: 36px; }
}

/* The date on a post card */
.card-date {
  display: flex; align-items: center; gap: 6px; margin: 6px 0; padding: 5px 8px; border-radius: var(--radius-sm);
  border-left: 4px solid var(--date-color); background: var(--surface-2); font-size: .82rem; font-weight: 600;
}
.card-date .ico { color: var(--date-color); }
.card-date-title { font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.event-when { align-items: flex-end; }
.event-when .field { flex: 1; min-width: 120px; margin: 8px 0; }
