@import url("https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible+Next:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg: #090b10;
  --bg-2: #11141b;
  --bg-3: #181d26;
  --panel: #0f131c;
  --line: rgba(255, 255, 255, 0.09);
  --line-soft: rgba(255, 255, 255, 0.05);
  --text: #f5f7fb;
  --muted: #a2abbf;
  --muted-2: #79829a;
  --accent: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.12);
  --blue: #7cb7ff;
  --yellow: rgba(255, 219, 87, 0.22);
  --yellow-strong: rgba(130, 180, 255, 0.3);
  --green: #57d187;
  --danger: #ff7878;
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
  --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.12);
  --toolbar-height: 60px;
  --thread-width: 352px;
  --code-bg: #121722;
  --code-border: rgba(255, 255, 255, 0.08);
  --card-bg: #10141d;
  --card-border: rgba(255, 255, 255, 0.08);
  --input-bg: #0b0e15;
  --modal-bg: #0e121b;
  --modal-border: rgba(255, 255, 255, 0.08);
  --editor-bg: #0a0d13;
  --preview-bg: #0a0d13;
  --topbar-bg: #090b10;
  --fab-bg: #e0a86e;
  --fab-text: #101010;
  --fab-hover: #d49a60;
  --author-color: #e0a86e;
  --highlight-layer-bg: transparent;
  --thread-reply-border: rgba(255, 255, 255, 0.08);
  --thread-footer-border: rgba(255, 255, 255, 0.06);
  --hover-bg: rgba(255, 255, 255, 0.08);
  --hljs-text: #f3f3f3;
  --hljs-keyword: #f0c674;
  --hljs-string: #8bdc8b;
  --hljs-comment: #7a7a7a;
  --hljs-number: #ff8a65;
  --hljs-type: #7cc7ff;
  --ambient-1: rgba(124, 183, 255, 0.04);
  --ambient-2: rgba(224, 168, 110, 0.03);
  --ambient-3: rgba(103, 221, 174, 0.02);
  --panel-highlight: rgba(255, 255, 255, 0.03);
  --ui-font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --reading-font: "Atkinson Hyperlegible Next", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --text-reading: #e7ebf5;
  --text-reading-headings: #f5f7fb;
  --panel-content-pad-top: 2rem;
  --panel-content-pad-x: 2.15rem;
  --panel-content-pad-bottom: 8rem;
}

[data-theme="light"] {
  --bg: #f3f0ea;
  --bg-2: #fbf7f1;
  --bg-3: #efe7dc;
  --panel: #fffcf7;
  --line: rgba(22, 26, 36, 0.1);
  --line-soft: rgba(22, 26, 36, 0.05);
  --text: #1a202b;
  --muted: #5f6879;
  --muted-2: #838c9d;
  --accent: #000000;
  --accent-soft: rgba(0, 0, 0, 0.05);
  --blue: #2563eb;
  --yellow: rgba(255, 200, 50, 0.2);
  --yellow-strong: rgba(80, 130, 220, 0.2);
  --green: #22a85a;
  --danger: #dc2626;
  --shadow: 0 10px 28px rgba(61, 52, 39, 0.08);
  --shadow-soft: 0 4px 14px rgba(61, 52, 39, 0.05);
  --code-bg: #f1ece5;
  --code-border: rgba(22, 26, 36, 0.08);
  --card-bg: #fffcf7;
  --card-border: rgba(22, 26, 36, 0.08);
  --input-bg: #ffffff;
  --modal-bg: #fffcf7;
  --modal-border: rgba(22, 26, 36, 0.08);
  --editor-bg: #fffcf7;
  --preview-bg: #fcf8f2;
  --topbar-bg: #f3f0ea;
  --fab-bg: #d4822e;
  --fab-text: #ffffff;
  --fab-hover: #c07528;
  --author-color: #b06820;
  --highlight-layer-bg: transparent;
  --thread-reply-border: rgba(22, 26, 36, 0.08);
  --thread-footer-border: rgba(22, 26, 36, 0.06);
  --hover-bg: rgba(0, 0, 0, 0.06);
  --hljs-text: #1a1a1a;
  --hljs-keyword: #a85d00;
  --hljs-string: #1a7a2e;
  --hljs-comment: #999999;
  --hljs-number: #c74400;
  --hljs-type: #2563eb;
  --ambient-1: rgba(37, 99, 235, 0.03);
  --ambient-2: rgba(212, 130, 46, 0.05);
  --ambient-3: rgba(34, 168, 90, 0.03);
  --panel-highlight: rgba(0, 0, 0, 0.06);
  --text-reading: #2b3341;
  --text-reading-headings: #1a202b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, var(--ambient-1), transparent 28rem),
    radial-gradient(circle at top right, var(--ambient-2), transparent 26rem),
    radial-gradient(circle at 50% 120%, var(--ambient-3), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: var(--ui-font);
}

body { min-height: 100dvh; }
.app-root { position: relative; }

[data-page="editor"], [data-page="editor"] .app-root { height: 100dvh; overflow: hidden; }
[data-page="public"], [data-page="public"] .app-root { height: 100dvh; overflow: hidden; }
[data-page="public"] .app-root { display: flex; flex-direction: column; }
[data-page="public"] .preview-stage { flex: 1; min-height: 0; }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }

button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
button:hover { background: var(--hover-bg); box-shadow: var(--shadow-soft); }
button:active { transform: translateY(1px); }
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
button:focus-visible, .noto-btn-icon:focus-visible, .noto-btn:focus-visible { outline-offset: 1px; }
input:focus-visible, textarea:focus-visible { outline: none; border-color: var(--blue); }
.title-input:focus-visible, .editor-textarea:focus-visible { outline: none; }

button.text-button { border-color: transparent; padding-inline: 0.4rem; border-radius: 8px; }

/* --- Noto web components --- */
noto-icon-button, noto-button { display: inline-flex; }

.noto-btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.noto-btn-icon:hover { background: var(--hover-bg); color: var(--text); box-shadow: var(--shadow-soft); }
.noto-btn-icon:active { transform: scale(0.94); }
.noto-btn-icon--danger:hover { color: var(--danger); }
.noto-btn-icon--md { width: 34px; height: 34px; }
.noto-btn-icon--md svg { width: 16px; height: 16px; }
.noto-btn-icon--sm { width: 24px; height: 24px; }
.noto-btn-icon--sm svg { width: 13px; height: 13px; }

.noto-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; cursor: pointer; font-weight: 600;
  border: 1px solid var(--line); background: transparent; color: var(--text);
}
.noto-btn:hover { background: var(--hover-bg); }
.noto-btn--md { padding: 0.45rem 0.85rem; font-size: 0.88rem; }
.noto-btn--sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.noto-btn--primary { background: var(--accent); color: var(--bg); border-color: transparent; font-weight: 600; }
.noto-btn--primary:hover { opacity: 0.88; background: var(--accent); }
.noto-btn--ghost { border-color: transparent; color: var(--muted); }
.noto-btn--ghost:hover { color: var(--text); background: var(--hover-bg); }
.noto-btn--danger { border-color: transparent; color: var(--danger); }
.noto-btn--danger:hover { background: var(--hover-bg); }
.noto-btn--link { border: 0; padding: 0; color: var(--muted-2); font-size: 0.78rem; background: transparent; }
.noto-btn--link:hover { color: var(--text); background: transparent; }

input, textarea {
  width: 100%; color: var(--text); background: transparent;
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:focus, textarea:focus { border-color: var(--muted); }

.hidden { display: none !important; }
.page-shell { min-height: 100dvh; }
.simple-page { display: grid; place-items: center; }
.simple-page-content { width: min(560px, calc(100vw - 2rem)); }

.auth-shell { display: grid; place-items: center; padding: 2rem; position: relative; }
.auth-theme-toggle { position: absolute; top: 1rem; right: 1rem; }
.auth-layout { width: min(420px, 100%); }
.auth-layout h1 { margin: 0 0 0.8rem; font-size: 2rem; font-weight: 700; }
.auth-hint { margin: 0 0 1.5rem; color: var(--muted); line-height: 1.5; }
.auth-error { margin: 0 0 1rem; color: var(--danger); }
.auth-form { display: grid; gap: 0.75rem; }
.auth-form input { padding: 0.9rem 1rem; background: var(--input-bg); border-radius: 10px; }
.auth-actions { padding-top: 0.4rem; }
.auth-actions button { border-radius: 10px; padding: 0.8rem 1rem; }

.app-root { min-height: 100dvh; overflow: hidden; }

.topbar {
  min-height: var(--toolbar-height);
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.5rem 1rem;
  background: var(--topbar-bg);
  position: sticky; top: 0; z-index: 30; flex-wrap: wrap;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
[data-page="editor"] .topbar, [data-page="public"] .topbar { border-bottom: 1px solid var(--line); box-shadow: none; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.brand-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.brand-name--plain { font-size: 1.02rem; }
.mobile-only { display: none !important; }

.topbar .noto-btn-icon,
.topbar .theme-toggle {
  background: transparent;
  border: 1px solid transparent;
}
.topbar .noto-btn-icon:hover,
.topbar .theme-toggle:hover {
  border-color: var(--line-soft);
  box-shadow: none;
}

.title-input {
  appearance: none; border: 0; padding: 0; background: transparent;
  color: var(--text); font-weight: 650; font-size: 1.14rem;
  letter-spacing: 0.005em;
  font-family: var(--reading-font);
  width: min(40vw, 480px); min-width: 0;
}

.title-input:focus { border: 0; }
.topbar-title { font-size: 1.05rem; font-weight: 700; letter-spacing: 0.01em; }

.status-text, .meta-text, .note-row-meta, .thread-meta,
.empty-state { color: var(--muted); }
.status-text { font-size: 0.8rem; color: var(--muted-2); transition: opacity 600ms ease; }
.status-text.status-fade { opacity: 0; }
.thread-meta { font-size: 0.82rem; color: var(--muted-2); white-space: nowrap; }

.list-page { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.list-page { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
.list-section {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.list-section--notes {
  min-height: calc(100dvh - 7rem);
  background: var(--panel);
}
.list-section--media {
  position: sticky;
  top: calc(var(--toolbar-height) + 1rem);
  background: var(--panel);
}
.list-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}
.list-section-header--hero {
  align-items: center;
  margin-bottom: 0.85rem;
}
.list-section-title { font-size: 0.95rem; font-weight: 600; }
.list-section-subtitle { color: var(--muted); font-size: 0.84rem; margin-top: 0.2rem; line-height: 1.45; max-width: 34rem; }
.list-section-actions { display: flex; align-items: center; gap: 0.5rem; }
.list-search-wrap { display: grid; gap: 0.35rem; margin-bottom: 0.5rem; }
.list-search { padding: 0.85rem 0.95rem; background: var(--input-bg); border-color: var(--line-soft); box-shadow: none; border-radius: 12px; }

.note-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem; padding: 0.85rem 0.95rem; border-radius: 14px; cursor: pointer;
  align-items: center;
  transition: background 160ms ease, border-color 160ms ease;
  border: 1px solid transparent;
  background: transparent;
  margin-left: calc(var(--note-depth, 0) * 1rem);
  position: relative;
}
.note-row:hover { background: var(--hover-bg); border-color: var(--line-soft); }
.note-row::before {
  content: "";
  position: absolute;
  left: calc(-0.65rem - (var(--note-depth, 0) * 0.12rem));
  top: 0.7rem;
  bottom: 0.7rem;
  width: 1px;
  border-radius: 999px;
  background: var(--line);
  opacity: var(--note-rail-opacity, 0);
}
.note-row-content { min-width: 0; }
.note-row-breadcrumbs {
  color: var(--muted-2);
  font-size: 0.73rem;
  letter-spacing: 0.02em;
  margin-bottom: 0.22rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.note-row-title-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}
.note-row-toggle { display: inline-flex; flex: 0 0 auto; }
.note-row-toggle .noto-btn-icon {
  width: 24px;
  height: 24px;
  color: var(--muted-2);
}
.note-row-toggle .noto-btn-icon:hover {
  color: var(--text);
  background: var(--hover-bg);
}
.note-row-toggle-spacer {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}
.note-row-title { font-size: 0.98rem; font-weight: 620; letter-spacing: -0.01em; margin-bottom: 0.15rem; }
.note-row-snippet { color: var(--muted); font-size: 0.88rem; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-row-meta { font-size: 0.78rem; color: var(--muted-2); margin-top: 0.2rem; }
.note-row-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
  font-size: 0.72rem;
  color: var(--muted);
  background: transparent;
}
.note-row-pill--count {
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: rgba(124, 183, 255, 0.38);
  background: rgba(37, 99, 235, 0.14);
  color: #7cb7ff;
  font-size: 0.74rem;
  font-weight: 700;
}
[data-theme="light"] .note-row-pill--count {
  border-color: rgba(37, 99, 235, 0.24);
  background: rgba(37, 99, 235, 0.08);
  color: #2563eb;
}
.note-row-actions {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  opacity: 0.55;
  transition: opacity 160ms ease;
}
.note-row:hover .note-row-actions { opacity: 1; }

.topbar-note-meta { display: grid; gap: 0.2rem; min-width: 0; }
.topbar-note-title-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.child-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.45rem;
  height: 1.45rem;
  padding: 0 0.38rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.16);
  border: 1px solid rgba(124, 183, 255, 0.38);
  color: #7cb7ff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  flex: 0 0 auto;
}
[data-theme="light"] .child-count-badge {
  background: rgba(37, 99, 235, 0.1);
  border-color: rgba(37, 99, 235, 0.24);
  color: #2563eb;
}
.child-count-badge--icon {
  position: absolute;
  top: -0.18rem;
  right: -0.12rem;
  min-width: 0.95rem;
  height: 0.95rem;
  padding: 0 0.2rem;
  font-size: 0.58rem;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}
.note-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  flex-wrap: wrap;
}
.note-breadcrumb-link,
.note-breadcrumb-current,
.note-breadcrumb-sep {
  font-size: 0.74rem;
  line-height: 1;
}
.note-breadcrumb-link {
  border: 0;
  padding: 0;
  color: var(--muted-2);
  background: transparent;
  box-shadow: none;
}
.note-breadcrumb-link:hover {
  color: var(--text);
  background: transparent;
  box-shadow: none;
}
.note-breadcrumb-link.is-static {
  color: var(--muted-2);
}
.note-breadcrumb-current {
  color: var(--muted);
  font-weight: 600;
}
.note-breadcrumb-sep { color: var(--muted-2); }

.subpage-menu-wrap {
  position: relative;
  display: inline-flex;
}
.subpage-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  width: min(320px, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--modal-bg);
  box-shadow: var(--shadow);
  padding: 0.5rem;
  z-index: 110;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.subpage-menu-header {
  padding: 0.35rem 0.35rem 0.45rem;
}
.subpage-menu-title {
  font-size: 0.84rem;
  font-weight: 600;
}
.subpage-menu-meta {
  color: var(--muted-2);
  font-size: 0.74rem;
  margin-top: 0.1rem;
}
.subpage-menu-list {
  display: grid;
  gap: 0.2rem;
  max-height: min(50vh, 320px);
  overflow-y: auto;
  margin-bottom: 0.45rem;
}
.subpage-menu-item {
  display: grid;
  gap: 0.12rem;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  box-shadow: none;
}
.subpage-menu-item:hover {
  background: var(--hover-bg);
  border-color: var(--line-soft);
}
.subpage-menu-item-title {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subpage-menu-item-meta {
  color: var(--muted-2);
  font-size: 0.73rem;
}
.subpage-menu-empty {
  color: var(--muted-2);
  font-size: 0.8rem;
  padding: 0.45rem 0.7rem;
}
.subpage-menu-create {
  width: 100%;
  justify-content: center;
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
}

.mobile-action-menu-wrap {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.25rem;
}
.mobile-action-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: min(320px, calc(100vw - 1rem));
  max-height: calc(100dvh - 1rem);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--modal-bg);
  box-shadow: var(--shadow);
  padding: 0.5rem;
  z-index: 120;
  pointer-events: auto;
}
.mobile-action-list {
  display: grid;
  gap: 0.2rem;
}
.mobile-action-section {
  display: grid;
  gap: 0.2rem;
  padding-top: 0.4rem;
  margin-top: 0.25rem;
  border-top: 1px solid var(--line-soft);
}
.mobile-action-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 0 0.5rem 0.15rem;
}
.mobile-share-access-list {
  display: grid;
  gap: 0.2rem;
}
.mobile-action-item {
  display: grid;
  gap: 0.12rem;
  width: 100%;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  box-shadow: none;
}
.mobile-action-item:hover {
  background: var(--hover-bg);
  border-color: var(--line-soft);
}
.mobile-action-item.is-active {
  border-color: rgba(124, 183, 255, 0.35);
  background: rgba(124, 183, 255, 0.08);
}
.mobile-action-item.is-disabled {
  opacity: 0.45;
}
.mobile-action-item--primary {
  border-color: var(--line-soft);
}
.mobile-action-item-label {
  font-size: 0.88rem;
  font-weight: 600;
}
.mobile-action-item-meta {
  color: var(--muted-2);
  font-size: 0.73rem;
}
.mobile-action-empty {
  color: var(--muted-2);
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
}

.empty-state-create { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 3rem 1rem; }
.empty-state-text { color: var(--muted); font-size: 1rem; margin: 0; }
.image-library-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}
.image-library-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}
.image-page-indicator {
  min-width: 4.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted-2);
}
.image-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--card-bg);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
  cursor: zoom-in;
  box-shadow: var(--shadow-soft);
}
.image-card:hover { transform: translateY(-2px); border-color: rgba(124, 183, 255, 0.32); }
.image-card-preview-wrap {
  aspect-ratio: 4 / 3;
  background: var(--input-bg);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.image-card-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 220ms ease, filter 220ms ease;
}
.image-card:hover .image-card-preview { transform: scale(1.035); filter: saturate(1.06); }
.image-card-body {
  padding: 0.65rem;
  display: grid;
  gap: 0.35rem;
}
.image-card-name {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-card-meta {
  color: var(--muted-2);
  font-size: 0.72rem;
}
.image-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}
.modal.uploads-modal {
  width: min(1360px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  display: grid;
  gap: 0.9rem;
}
.uploads-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.uploads-modal .image-library-grid {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.image-lightbox {
  width: min(1120px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
}
.image-lightbox-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.image-lightbox-meta {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 0.3rem;
}
.image-lightbox-frame {
  min-height: 0;
  border-radius: 18px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)),
    var(--input-bg);
  padding: 1rem;
  display: grid;
  place-items: center;
  overflow: auto;
}
.image-lightbox-stage {
  width: 100%;
  min-height: min(70vh, 860px);
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 14px;
  touch-action: none;
  cursor: zoom-in;
}
.image-lightbox-stage.is-zoomed { cursor: grab; }
.image-lightbox-stage.is-dragging { cursor: grabbing; }
.image-lightbox-image {
  display: block;
  max-width: 100%;
  max-height: min(74vh, 980px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  transform-origin: center center;
  transition: transform 120ms ease;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.image-lightbox-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.image-lightbox-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}
.image-lightbox-zoom-value {
  min-width: 3.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}
.image-lightbox-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.settings-modal { width: min(520px, calc(100vw - 2rem)); max-height: calc(100dvh - 4rem); overflow-y: auto; }
.settings-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.settings-title { margin: 0; font-size: 1.1rem; font-weight: 600; }
.agent-modal {
  width: min(640px, calc(100vw - 2rem));
  max-height: calc(100dvh - 4rem);
  display: flex; flex-direction: column;
}
.agent-hint { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.88rem; line-height: 1.24; flex-shrink: 0; }
.agent-instructions {
  background: var(--code-bg); border: 1px solid var(--code-border); border-radius: 10px;
  padding: 0.75rem 1rem; overflow: auto; font-size: 0.8rem; line-height: 0.94;
  margin: 0 0 0.75rem; white-space: pre;
  flex: 1; min-height: 0;
}
.agent-instructions code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
  display: block;
}
.agent-modal noto-button { flex-shrink: 0; }
.settings-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.settings-section-title { margin: 0; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.settings-section--logout {
  margin-top: 1.15rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line-soft);
}
.settings-action-list {
  display: grid;
  gap: 0.45rem;
}
.settings-action-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem;
  padding: 0.8rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line-soft);
  background: var(--panel);
  color: var(--text);
  text-align: left;
  box-shadow: none;
}
.settings-action-row:hover {
  background: var(--hover-bg);
  border-color: var(--line);
}
.settings-action-row--danger {
  color: #ff8b8b;
}
.settings-action-copy {
  display: grid;
  gap: 0.18rem;
}
.settings-action-label {
  font-size: 0.92rem;
  font-weight: 600;
}
.settings-action-meta {
  font-size: 0.8rem;
  color: var(--muted-2);
}
.api-key-row { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.5rem; border-radius: 8px; gap: 0.75rem; }
.api-key-row:hover { background: var(--hover-bg); }
.api-key-info { display: flex; align-items: center; gap: 0.75rem; }
.api-key-label { font-weight: 600; }
.api-key-meta { color: var(--muted-2); font-size: 0.85rem; }
.api-keys-empty { color: var(--muted-2); font-size: 0.9rem; }
.api-key-secret { display: flex; align-items: center; gap: 0.35rem; margin-left: auto; }
.api-key-secret code { font-size: 0.82rem; color: var(--muted); word-break: break-all; }
.icon-action.copy-success { color: var(--green); }
noto-icon-button.copy-success .noto-btn-icon { color: var(--green); }

.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  height: calc(100dvh - var(--toolbar-height)); overflow: hidden;
}
.editor-pane {
  border-right: 1px solid var(--line);
  background: var(--editor-bg);
  overflow: hidden;
  display: flex; flex-direction: column; position: relative;
}

.editor-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.editor-scroll-content {
  position: relative;
  min-height: 100%;
}

.editor-textarea {
  width: 100%; min-height: 100%; height: auto;
  padding: var(--panel-content-pad-top) var(--panel-content-pad-x) var(--panel-content-pad-bottom); border: 0; border-radius: 0; resize: none;
  background: transparent; color: var(--text);
  font-size: 1.04rem; line-height: 1.42;
  letter-spacing: 0.01em; word-spacing: 0.04em;
  font-family: var(--reading-font);
  word-wrap: break-word; overflow-wrap: break-word; white-space: pre-wrap; overflow-x: hidden;
  overflow: hidden;
  text-rendering: optimizeLegibility;
  box-sizing: border-box;
  display: block;
}
.editor-textarea:focus { border: 0; }

.editor-subpages {
  padding: 0 var(--panel-content-pad-x) var(--panel-content-pad-bottom);
}
.editor-subpages .preview-subpages {
  max-width: 860px;
  margin: 0 auto;
}

.editor-toolbar {
  display: flex; align-items: center; gap: 0.15rem;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--line);
  background: var(--editor-bg);
  flex-wrap: wrap;
  position: sticky; top: 0; z-index: 5;
}
.editor-toolbar .noto-btn-icon { color: var(--muted); }
.editor-toolbar .noto-btn-icon:hover { color: var(--text); background: var(--hover-bg); }
.editor-toolbar-divider {
  width: 1px; height: 18px; background: var(--line); margin: 0 0.35rem;
}

.view-mode-switch {
  display: inline-flex; align-items: center;
  padding: 2px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--input-bg); gap: 2px;
}
.view-mode-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 28px; padding: 0;
  background: transparent; color: var(--muted);
  border: 0; border-radius: 8px; cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.view-mode-btn:hover { color: var(--text); background: var(--hover-bg); }
.view-mode-btn.is-active { background: var(--bg-3); color: var(--text); }
[data-theme="light"] .view-mode-btn.is-active { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

@media (min-width: 981px) {
  .workspace.mode-edit { grid-template-columns: 1fr; }
  .workspace.mode-edit .preview-stage { display: none; }
  .workspace.mode-read { grid-template-columns: 1fr; }
  .workspace.mode-read .editor-pane { display: none; }
}
@media (max-width: 980px) {
  .desktop-only { display: none !important; }
}

.preview-stage {
  height: 100%;
  background: var(--preview-bg);
  overflow: hidden; position: relative;
}

.preview-controls {
  position: absolute; top: 0.5rem; right: 0.5rem; z-index: 10;
  display: flex; gap: 0.35rem;
}
.preview-controls .noto-btn { backdrop-filter: blur(6px); }

.preview-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.preview-canvas { position: relative; min-height: 100%; }
.preview-content {
  max-width: 860px; min-height: 100%; margin: 0 auto;
  padding: var(--panel-content-pad-top) var(--panel-content-pad-x) var(--panel-content-pad-bottom);
}
.preview-stage.public .preview-content { max-width: 920px; }
.preview-subpages {
  margin-top: 2.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}
.preview-subpages-header {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.8rem;
}
.preview-subpages-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.preview-subpages-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--panel-soft);
  text-decoration: none;
  color: inherit;
}
.preview-subpages-link:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.preview-subpages-link-title {
  font-weight: 600;
}
.preview-subpages-link-meta {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.markdown-body {
  color: var(--text-reading);
  line-height: 1.42;
  letter-spacing: 0.008em;
  word-spacing: 0.04em;
  font-size: 1.03rem;
  font-family: var(--reading-font);
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  text-rendering: optimizeLegibility;
}
.markdown-body > :first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin: 2rem 0 0.95rem;
  line-height: 1.24;
  letter-spacing: 0.008em;
  color: var(--text-reading-headings);
}
.markdown-body h1 { font-size: 2.15rem; }
.markdown-body h2 { font-size: 1.68rem; }
.markdown-body p, .markdown-body ul, .markdown-body ol,
.markdown-body pre, .markdown-body blockquote, .markdown-body table { margin: 0 0 0.82rem; }
.markdown-body ul, .markdown-body ol { padding-left: 1.6rem; }
.markdown-body li + li { margin-top: 0.22rem; }
.markdown-body li input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: auto;
  width: 1rem;
  height: 1rem;
  margin-right: 0.55rem;
  vertical-align: middle;
  flex: 0 0 auto;
  border: 1.5px solid var(--muted-2);
  border-radius: 0.25rem;
  background: transparent;
  display: inline-grid;
  place-content: center;
  position: relative;
}
.markdown-body li input[type="checkbox"]:checked {
  border-color: var(--blue);
  background: transparent;
}
.markdown-body li input[type="checkbox"]:checked::after {
  content: "";
  width: 0.3rem;
  height: 0.55rem;
  border-right: 2px solid var(--blue);
  border-bottom: 2px solid var(--blue);
  transform: rotate(45deg) translate(-0.02rem, -0.03rem);
}
.markdown-body li input[type="checkbox"]:disabled {
  opacity: 1;
}
.markdown-body li:has(> input[type="checkbox"]) {
  list-style: none;
  margin-left: -1.4rem;
  padding-left: 1.4rem;
}
.markdown-body code {
  font-family: "SFMono-Regular", ui-monospace, Menlo, Monaco, Consolas, monospace;
  font-size: 0.95em; background: var(--code-bg); padding: 0.15rem 0.3rem; border-radius: 6px;
}
.markdown-body pre {
  background: var(--code-bg); border: 1px solid var(--code-border); border-radius: 14px;
  padding: 0.85rem 1rem; overflow-x: auto; max-width: 100%; font-size: 0.85rem;
}
.markdown-body pre code { background: transparent; padding: 0; border-radius: 0; font-size: inherit; }
.markdown-body blockquote {
  margin-left: 0;
  padding: 0.2rem 0 0.2rem 1rem;
  border-left: 2px solid var(--line);
  color: var(--muted);
}
.markdown-body table { width: 100%; border-collapse: collapse; }
.markdown-body th, .markdown-body td { border: 1px solid var(--line); padding: 0.55rem 0.7rem; text-align: left; }
.markdown-body a { color: var(--blue); }
.markdown-body img { max-width: 100%; height: auto; }

/* Mermaid diagrams */
.mermaid-wrap { position: relative; margin: 0 0 1rem; overflow: hidden; border: 1px solid var(--code-border); border-radius: 14px; background: var(--code-bg); user-select: none; }
.mermaid-viewport { overflow: hidden; }
.mermaid-viewport pre.mermaid { margin: 0; border: none; padding: 1.5rem 1rem 1rem; display: flex; justify-content: center; transition: transform 0.15s ease; transform-origin: 0 0; }
.mermaid-toolbar { position: absolute; bottom: 0.5rem; right: 0.5rem; display: grid; grid-template-columns: repeat(3, 32px); grid-template-rows: repeat(3, 32px); gap: 3px; z-index: 1; opacity: 0; pointer-events: none; transition: opacity 0.15s; }
.mermaid-wrap:hover .mermaid-toolbar { opacity: 1; pointer-events: auto; }
.mermaid-toolbar button { background: var(--bg-3); color: var(--text); border: 1px solid var(--code-border); border-radius: 8px; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.mermaid-toolbar button:hover { background: var(--line); }

.hljs { color: var(--hljs-text); background: transparent; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-name, .hljs-literal { color: var(--hljs-keyword); }
.hljs-string, .hljs-title, .hljs-section, .hljs-attribute { color: var(--hljs-string); }
.hljs-comment, .hljs-quote { color: var(--hljs-comment); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hljs-number); }
.hljs-variable, .hljs-template-variable, .hljs-type { color: var(--hljs-type); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* --- Cursor overlay for remote cursors --- */
.cursor-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none; overflow: hidden; z-index: 2;
}
.remote-selection-rect {
  position: absolute;
  pointer-events: none;
  border: 1px solid transparent;
  border-radius: 0.3rem;
}
.remote-cursor { position: absolute; pointer-events: none; }
.remote-cursor-caret { width: 2px; border-radius: 1px; }
.remote-cursor-label {
  position: absolute; bottom: 100%; left: -1px;
  font-size: 10px; line-height: 1; padding: 2px 5px;
  border-radius: 3px 3px 3px 0; white-space: nowrap;
  color: #fff; font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-weight: 600; opacity: 0.9;
}

/* --- Textarea mirror (hidden, for caret position measurement) --- */
.textarea-mirror { position: absolute !important; visibility: hidden !important; overflow: hidden !important; pointer-events: none !important; z-index: -1; top: 0; left: 0; }

/* --- Share popover --- */
.share-popover-wrap { position: relative; display: inline-flex; }
.share-popover {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 100;
  background: var(--modal-bg); border: 1px solid var(--modal-border);
  border-radius: 10px; padding: 0.75rem; min-width: 300px;
  box-shadow: var(--shadow);
}
.share-popover-row { display: flex; align-items: center; gap: 0.5rem; }
.share-popover-row select {
  flex: 1; padding: 0.4rem 0.5rem; border-radius: 6px;
  border: 1px solid var(--line); background: var(--input-bg); color: var(--text);
  font: inherit; font-size: 0.85rem;
}
.share-popover-row button { padding: 0.4rem 0.7rem; font-size: 0.82rem; border-radius: 6px; white-space: nowrap; }
.share-copy-disabled { opacity: 0.35; cursor: default; }
.share-copy-disabled:hover { background: transparent; }

/* --- Disconnected banner --- */
.editor-disconnected {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  padding: 0.4rem 0.75rem; text-align: center;
  background: var(--danger); color: #fff; font-size: 0.82rem; font-weight: 600;
}

/* --- Highlight layer: always pointer-events:none, purely visual --- */
.highlight-layer { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.anchor-highlight {
  position: absolute; background: var(--yellow); border: 0; padding: 0;
  border-radius: 5px; pointer-events: none;
}
.anchor-highlight.active { background: var(--yellow-strong); }

/* --- Selection bubble: only desktop >= 980 --- */
.selection-bubble {
  position: absolute; z-index: 8; padding: 0.45rem 0.8rem;
  border: none; border-radius: 999px;
  background: var(--fab-bg); color: var(--fab-text); font-weight: 600;
  box-shadow: 0 4px 16px rgba(224, 168, 110, 0.35);
}
.selection-bubble:hover { background: var(--fab-hover); }

/* --- Comment FAB: shown via JS when bubble can't show --- */
.comment-fab {
  display: none; z-index: 8;
  padding: 0.45rem 0.8rem; border-radius: 999px;
  font-size: 0.88rem; font-weight: 600;
  align-items: center; justify-content: center; gap: 0.35rem;
  border: none; background: var(--fab-bg); color: var(--fab-text);
  box-shadow: 0 4px 16px rgba(224, 168, 110, 0.35);
}
.comment-fab:hover { background: var(--fab-hover); }

/* --- Thread rail: hidden by default, shown only on public desktop wide --- */
.thread-rail {
  position: absolute; top: 0; right: 0; width: var(--thread-width);
  min-height: 100%; padding: 2.5rem 0.55rem 1.25rem 0; display: none;
}

.thread-card {
  position: absolute; right: 0.5rem; width: calc(var(--thread-width) - 6px);
  background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 10px;
  padding: 0.55rem 0.75rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
  font-size: 0.92rem;
}
.thread-card.active { border-color: var(--muted); }
.thread-card.resolved { opacity: 0.7; }

.modal-actions, .thread-footer, .thread-message-actions {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}

.thread-author { font-weight: 600; margin: 0; color: var(--author-color); font-size: inherit; }

.thread-tree { display: grid; gap: 0.45rem; }
.thread-node { margin-left: calc(var(--depth, 0) * 0.8rem); }
.thread-body {
  white-space: pre-wrap;
  line-height: 1.18;
  letter-spacing: 0.008em;
  font-family: var(--reading-font);
  margin-top: 0.08rem;
}
.thread-message-root { margin-top: 0; }
.thread-message-reply { padding-left: 0.55rem; border-left: 1px solid var(--thread-reply-border); }

.thread-message-head { display: flex; flex-wrap: wrap; margin-bottom: 0.04rem; align-items: center; gap: 0.3rem; }
.thread-message-actions {
  margin-left: auto; gap: 0; flex-wrap: nowrap;
  opacity: 0.45; transition: opacity 100ms ease;
}
.thread-message:hover .thread-message-actions { opacity: 1; }

.thread-footer { margin-top: 0.3rem; padding-top: 0.25rem; border-top: 1px solid var(--thread-footer-border); gap: 0.35rem; }

.compact { width: min(480px, calc(100vw - 2rem)); padding: 0.85rem !important; }
.compact textarea, .compact input { min-height: 0; background: var(--input-bg); border: 1px solid var(--line); }
.compact textarea { min-height: 100px; padding: 0.75rem 0.85rem; border-radius: 10px; }
.compact .modal-actions { margin-top: 0.6rem; gap: 0.5rem; }
.compact .modal-actions button { font-size: 0.92rem; }
.compact .field + .field, .compact .field + .modal-actions { margin-top: 0.5rem; }


.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: grid; place-items: center; z-index: 100; padding: 1rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.modal {
  width: min(460px, calc(100vw - 2rem)); background: var(--modal-bg);
  border: 1px solid var(--modal-border); border-radius: 20px; box-shadow: var(--shadow); padding: 1rem;
}
.modal h2 { margin: 0 0 0.2rem; font-size: 1rem; }
.modal p { margin: 0 0 0.65rem; color: var(--muted); line-height: 1.18; }
.modal input, .modal textarea { background: var(--input-bg); padding: 0.72rem 0.82rem; }
.modal textarea { min-height: 88px; resize: vertical; }
.modal .field + .field, .modal .field + .modal-actions { margin-top: 0.55rem; }

.thread-modal { padding: 0.75rem !important; position: relative; max-height: calc(100dvh - 2rem); overflow-y: auto; }
.thread-modal-close-wrap {
  position: absolute; top: 0.45rem; right: 0.45rem; z-index: 2;
}
.thread-modal-body { padding-right: 1.5rem; }
.inline-error { color: var(--danger); margin-top: 0.65rem; }
.public-page-topbar .topbar-title-subtle { color: var(--muted); font-size: 0.95rem; }

/* --- Wide public desktop: show rail --- */
@media (min-width: 1200px) {
  .preview-stage.public .thread-rail { display: block; }
  .preview-stage.public .preview-canvas { padding-right: calc(var(--thread-width) + 20px); }
}

/* --- Preview button (editor narrow only, in topbar) --- */
#previewFab { display: none !important; }

.preview-close-btn {
  display: none; position: sticky; top: 0; right: 0; z-index: 12;
  margin-left: auto;
}

/* --- Narrow / mobile --- */
@media (max-width: 980px) {
  .list-page { grid-template-columns: 1fr; }
  .list-section { padding: 0.85rem; }
  .list-section--notes { min-height: auto; }
  .list-section--media { position: static; }
  .list-section-hero { max-width: none; font-size: 2.2rem; }
  .image-library-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .image-lightbox { width: calc(100vw - 1rem); padding: 0.8rem; }
  .image-lightbox-frame { padding: 0.6rem; }
  .image-lightbox-stage { min-height: min(58vh, 620px); }
  .workspace { grid-template-columns: 1fr; }
  .editor-pane { border-right: 0; border-bottom: none; }

  /* Hide preview by default in editor, show when toggled */
  .workspace .preview-stage {
    position: fixed; inset: 0; z-index: 40;
    transform: translateX(100%);
    transition: transform 250ms ease;
    min-height: 100dvh; height: 100dvh;
  }
  .workspace .preview-stage.preview-open {
    transform: translateX(0);
  }
  .workspace .preview-stage .preview-close-btn { display: inline-flex; }
  #previewFab { display: inline-flex !important; }

  /* Editor takes full height */
  .editor-scroll { flex: 1; }

  .preview-scroll, .preview-stage { height: 100dvh; min-height: 100dvh; }
  .preview-scroll { height: 100%; }
  .preview-canvas { padding-right: 0; }
  .preview-content, .preview-stage.public .preview-content {
    width: auto; max-width: none;
    padding: var(--panel-content-pad-top) var(--panel-content-pad-x) var(--panel-content-pad-bottom);
  }
.md-block { display: block; }
  .thread-rail { display: none !important; }
  .selection-bubble { display: none !important; }
  .topbar-desktop { display: none !important; }

  /* Public page doesn't need the fab/close, preview is always visible */
  .preview-stage.public { position: static; transform: none; min-height: auto; height: auto; }
  .preview-stage.public .preview-close-btn { display: none; }
}

/* --- Mobile polish / safe areas / PWA --- */
@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    padding-top: max(0.4rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  .editor-toolbar {
    padding-left: max(0.65rem, env(safe-area-inset-left));
    padding-right: max(0.65rem, env(safe-area-inset-right));
  }
  .editor-textarea {
    padding-left: max(var(--panel-content-pad-x), env(safe-area-inset-left));
    padding-right: max(var(--panel-content-pad-x), env(safe-area-inset-right));
    padding-bottom: max(var(--panel-content-pad-bottom), env(safe-area-inset-bottom));
  }
  .editor-subpages {
    padding-left: max(var(--panel-content-pad-x), env(safe-area-inset-left));
    padding-right: max(var(--panel-content-pad-x), env(safe-area-inset-right));
    padding-bottom: max(var(--panel-content-pad-bottom), env(safe-area-inset-bottom));
  }
  .preview-content {
    padding-left: max(var(--panel-content-pad-x), env(safe-area-inset-left));
    padding-right: max(var(--panel-content-pad-x), env(safe-area-inset-right));
    padding-bottom: max(var(--panel-content-pad-bottom), env(safe-area-inset-bottom));
  }
}

@media (max-width: 980px) {
  :root {
    --panel-content-pad-top: 1.3rem;
    --panel-content-pad-x: 1.15rem;
    --panel-content-pad-bottom: 6rem;
  }
  html, body { overscroll-behavior-y: auto; }
  .mobile-only { display: inline-flex !important; }
  .note-actions-bar { display: none !important; }
  .editor-toolbar { padding: 0.5rem 0.65rem; gap: 0.25rem; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .editor-toolbar::-webkit-scrollbar { display: none; }
  .editor-toolbar .noto-btn-icon { flex-shrink: 0; }
  .editor-toolbar .noto-btn-icon--sm button { width: 34px; height: 34px; }
  .image-lightbox-toolbar { align-items: stretch; }
  .image-lightbox-zoom-controls, .image-lightbox-actions { width: 100%; justify-content: center; }
  .note-row { margin-left: calc(var(--note-depth, 0) * 0.5rem); }
  .note-row::before { left: -0.3rem; }
  .topbar {
    gap: 0.35rem;
    padding: 0.45rem 0.7rem;
    align-items: center;
  }
  .topbar-left {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
  }
  .topbar-right {
    margin-left: auto;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
  }
  .topbar-note-meta {
    flex: 1 1 auto;
    min-width: 0;
  }
  .topbar-note-title-row {
    flex-wrap: nowrap;
    min-width: 0;
    justify-content: space-between;
  }
  .topbar-title {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .title-input {
    font-size: 1.04rem;
    min-width: 0;
    width: auto;
    flex: 1 1 auto;
  }
  .mobile-action-menu {
    right: auto;
    width: min(320px, calc(100vw - 1rem));
  }
  .editor-textarea { font-size: 16px; }
  .editor-subpages { padding: 0 var(--panel-content-pad-x) var(--panel-content-pad-bottom); }
  .topbar-left, .topbar-right { gap: 0.25rem; }
  .subpage-menu {
    right: -0.2rem;
    width: min(300px, calc(100vw - 1rem));
  }
  input, textarea, select { font-size: 16px; }
  .modal { max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem); }
}

@media (display-mode: standalone) {
  body { user-select: none; -webkit-user-select: none; }
  .editor-textarea, .markdown-body, input, .thread-body, .thread-message-body { user-select: text; -webkit-user-select: text; }
}
