/* ================================================================ fonts */
@font-face {
  font-family: "Inter Var"; src: url("assets/fonts/inter.woff2") format("woff2");
  font-weight: 100 900; font-display: swap;
}
/* Handwriting fonts for the AI notes preview (finished pages carry their own copy). */
@font-face { font-family: "Caveat"; src: url("assets/fonts/caveat-bold.woff2") format("woff2"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Patrick Hand"; src: url("assets/fonts/patrick-hand.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Permanent Marker"; src: url("assets/fonts/permanent-marker.woff2") format("woff2"); font-display: swap; }
@font-face {
  font-family: "Fraunces Var"; src: url("assets/fonts/fraunces.woff2") format("woff2");
  font-weight: 100 900; font-display: swap;
}

/* ================================================================ tokens */
:root {
  --font-ui: "Inter Var", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces Var", "Iowan Old Style", "New York", Georgia, serif;

  --bg: #ffffff;
  --desk: #ffffff;
  --desk-dot: rgba(30, 60, 120, 0.09);
  --surface: #ffffff;
  --skel: rgba(120, 130, 150, 0.14); --skel-shine: rgba(255, 255, 255, 0.6);
  --surface-2: #f3f6fb;
  --surface-3: #e7ecf5;
  --glass: rgba(255, 255, 255, 0.88);
  --glass-solid: rgba(255, 255, 255, 0.96);
  --border: rgba(25, 50, 100, 0.12);
  --border-strong: rgba(25, 50, 100, 0.2);
  --text: #141c2e;
  --muted: #5c6880;
  --faint: #9aa4b8;
  --accent: #0f62ea;
  --accent-2: #0c50c4;
  --accent-soft: #e8f1ff;
  --accent-ink: #fff;
  --danger: #c93a2f;
  --ok: #2f8a57;
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);

  --shadow-xs: 0 1px 1px rgba(20, 40, 90, 0.05);
  --shadow-sm: 0 1px 2px rgba(20, 40, 90, 0.06), 0 2px 8px rgba(20, 40, 90, 0.06);
  --shadow: 0 1px 2px rgba(20, 40, 90, 0.06), 0 8px 24px rgba(20, 40, 90, 0.1);
  --shadow-lg: 0 2px 6px rgba(20, 40, 90, 0.08), 0 24px 60px rgba(20, 40, 90, 0.18);
  --page-shadow: 0 0 0 1px rgba(20, 40, 90, 0.05), 0 2px 4px rgba(20, 40, 90, 0.05), 0 12px 32px rgba(20, 40, 90, 0.1);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 26px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ink-touch: none;
  --top-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e131c; --desk: #0a0e15; --desk-dot: rgba(200, 220, 255, 0.05);
    --skel: rgba(160, 175, 200, 0.1); --skel-shine: rgba(255, 255, 255, 0.07);
    --surface: #161d2a; --surface-2: #202937; --surface-3: #2b3546; --glass: rgba(22, 29, 42, 0.8); --glass-solid: rgba(22, 29, 42, 0.96);
    --border: rgba(200, 220, 255, 0.09); --border-strong: rgba(200, 220, 255, 0.16);
    --text: #edf2fb; --muted: #9fadc4; --faint: #69768c;
    --accent: #67a6ff; --accent-2: #8cbcff; --accent-soft: #14294c; --accent-ink: #04142b;
    --danger: #ff6b5e; --ok: #5fcf8d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.4), 0 28px 70px rgba(0, 0, 0, 0.55);
    --page-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 14px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e131c; --desk: #0a0e15; --desk-dot: rgba(200, 220, 255, 0.05);
  --skel: rgba(160, 175, 200, 0.1); --skel-shine: rgba(255, 255, 255, 0.07);
  --surface: #161d2a; --surface-2: #202937; --surface-3: #2b3546; --glass: rgba(22, 29, 42, 0.8); --glass-solid: rgba(22, 29, 42, 0.96);
  --border: rgba(200, 220, 255, 0.09); --border-strong: rgba(200, 220, 255, 0.16);
  --text: #edf2fb; --muted: #9fadc4; --faint: #69768c;
  --accent: #67a6ff; --accent-2: #8cbcff; --accent-soft: #14294c; --accent-ink: #04142b;
  --danger: #ff6b5e; --ok: #5fcf8d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.4), 0 28px 70px rgba(0, 0, 0, 0.55);
  --page-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 14px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ================================================================ base */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 var(--font-ui);
  font-feature-settings: "cv11", "ss01";
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: 0.32; cursor: default; }
:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }
.display { font-family: var(--font-display); font-optical-sizing: auto; font-variation-settings: "SOFT" 50, "WONK" 0; letter-spacing: -0.01em; }
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.primary {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent));
  color: var(--accent-ink); padding: 10px 18px; border-radius: 999px; font-weight: 600; letter-spacing: -0.005em;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 1px 2px color-mix(in srgb, var(--accent) 35%, transparent), 0 6px 16px color-mix(in srgb, var(--accent) 28%, transparent);
  transition: transform 0.18s var(--spring), box-shadow 0.2s var(--ease), filter 0.2s;
}
.primary .i { width: 18px; height: 18px; stroke-width: 2.2; }
.primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.primary:active { transform: translateY(0) scale(0.98); }
.ghost {
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface);
  white-space: nowrap; font-weight: 550; transition: background 0.15s;
}
.ghost:hover { background: var(--surface-2); }
.icon-btn {
  min-width: 38px; height: 38px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center;
  gap: 4px; color: var(--text); transition: background 0.15s, transform 0.15s var(--spring), color 0.15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }
.icon-btn:active:not(:disabled) { transform: scale(0.94); }
.icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.chip-btn {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px 5px 7px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--text);
}
.chip-btn .i { width: 15px; height: 15px; stroke-width: 2.2; }
.chip-btn:hover { background: var(--surface-3); }
.select {
  appearance: none; padding: 9px 34px 9px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7890' stroke-width='2.5' stroke-linecap='round'><path d='m6 9 6 6 6-6'/></svg>") no-repeat right 13px center;
  font-size: 14px; cursor: pointer;
}
.switch {
  appearance: none; width: 38px; height: 23px; border-radius: 99px; background: var(--surface-3); position: relative;
  cursor: pointer; transition: background 0.2s var(--ease); flex: none; margin: 0;
}
.switch::after {
  content: ""; position: absolute; left: 2.5px; top: 2.5px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.25s var(--spring);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(15px); }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; flex: none; }
.grow { flex: 1; }

/* ================================================================ library */
.view { height: 100%; }
#library { overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
/* While a sheet is open, only the sheet scrolls: wheel and touch never reach the shelf behind it. */
html:has(dialog[open]), body:has(dialog[open]), body:has(dialog[open]) #library { overflow: hidden; }
.lib-top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  justify-content: space-between; padding: 14px clamp(16px, 4vw, 48px);
  padding-top: max(14px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent; transition: border-color 0.2s;
}
.lib-top.scrolled { border-bottom-color: var(--border); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { border-radius: 9px; box-shadow: var(--shadow-sm); }
.brand-name { font-family: var(--font-display); font-weight: 650; font-size: 22px; letter-spacing: -0.02em; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); letter-spacing: 0.01em;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.badge.cloud { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.badge.cloud::before { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.lib-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 40px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted); transition: box-shadow 0.2s, border-color 0.2s;
}
.search:focus-within { border-color: color-mix(in srgb, var(--accent) 50%, transparent); box-shadow: var(--focus); }
.search .i { width: 17px; height: 17px; }
.search input {
  border: 0; outline: 0; background: none; width: 200px; color: var(--text); font-size: 14px;
  /* Safari/iPad draws its own rounded field for type=search inside our pill; drop it so only the pill shows. */
  -webkit-appearance: none; appearance: none; border-radius: 0; box-shadow: none; padding: 0; min-width: 0;
}
.search input:focus, .search input:focus-visible { outline: none; box-shadow: none; }
.search input::-webkit-search-decoration { -webkit-appearance: none; }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

.lib-hero { padding: 28px clamp(16px, 4vw, 48px) 6px; animation: rise 0.6s var(--ease) both; }
.eyebrow { margin: 0 0 4px; font-size: 12px; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.lib-hero h1 { margin: 0; font-size: clamp(32px, 4.4vw, 46px); line-height: 1.05; font-weight: 560; }
.lib-hero h1 em { font-style: italic; color: var(--accent); font-weight: 480; }
.lib-stats { margin: 8px 0 0; color: var(--muted); font-size: 14.5px; }

.notebook-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 36px clamp(18px, 2.4vw, 32px);
  padding: 30px clamp(16px, 4vw, 48px) 80px;
}
.nb-card { display: flex; flex-direction: column; gap: 12px; min-width: 0; animation: rise 0.55s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms); }
/* Cover art is 512×640 with a transparent margin; .cover-art shows just the notebook (392×612). */
.cover-art { position: relative; display: block; aspect-ratio: 392 / 612; container-type: inline-size; }
.cover-art > img { position: absolute; left: -15.31%; top: -2.29%; width: 130.61%; max-width: none; height: auto; display: block; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.nb-cover {
  position: relative; display: block; width: 100%; border-radius: 6px;
  transform-origin: 30% 100%; transition: transform 0.35s var(--spring), filter 0.3s var(--ease);
  filter: drop-shadow(0 2px 2px rgba(20, 30, 60, 0.12)) drop-shadow(0 10px 14px rgba(20, 30, 60, 0.14));
}
.nb-cover:hover { transform: translateY(-6px) rotate(-1.2deg); filter: drop-shadow(0 4px 4px rgba(20, 30, 60, 0.12)) drop-shadow(0 22px 26px rgba(20, 30, 60, 0.2)); }
.nb-cover:active { transform: translateY(-2px) scale(0.985); }
.cover-label {
  position: absolute; left: 17%; right: 28%; top: 14%; padding: 5cqw 5.5cqw 5.5cqw; border-radius: 4px;
  background: linear-gradient(180deg, #fffcf5, #f3ecdf); color: #2a241d; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18), inset 0 0 0 1px rgba(0, 0, 0, 0.04);
  font-family: var(--font-display); font-weight: 560; font-size: 7.4cqw; line-height: 1.2; text-align: left;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow-wrap: break-word; hyphens: auto;
}
.cover-label::after { content: ""; display: block; height: 1px; margin-top: 4cqw; background: repeating-linear-gradient(90deg, #cfc4b1 0 5px, transparent 5px 9px); }
/* Kraft cover: write on its printed label instead of adding a sticker. */
.cover-label.plate {
  left: 29.1%; right: auto; width: 33.9%; top: 23.4%; height: 14.1%; padding: 1cqw 2.5cqw; background: none; box-shadow: none;
  display: flex; align-items: center; justify-content: center; text-align: center; color: #4b3a26; line-height: 1.12; font-size: 5.6cqw;
}
.cover-label.plate::after { display: none; }
.nb-pages-tab {
  position: absolute; right: 9%; bottom: 7%; font-size: 11px; font-weight: 650; color: rgba(255, 255, 255, 0.85);
  letter-spacing: 0.04em; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}
.nb-meta { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; padding: 0 2px; }
.nb-meta > div { min-width: 0; }
.nb-title-text { font-weight: 620; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-sub { font-size: 12.5px; color: var(--muted); }
.nb-more { min-width: 30px; height: 30px; margin-top: -3px; color: var(--muted); }

.nb-new {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; aspect-ratio: 392 / 612;
  border-radius: 10px 18px 18px 10px; border: 1.5px dashed var(--border-strong); color: var(--muted); font-weight: 600; font-size: 14px;
  background: repeating-linear-gradient(180deg, transparent 0 27px, var(--border) 27px 28px);
  transition: border-color 0.2s, color 0.2s, transform 0.3s var(--spring), background-color 0.2s;
}
.nb-new .plus {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--surface);
  box-shadow: var(--shadow-sm); color: var(--accent); transition: transform 0.35s var(--spring);
}
.nb-new .plus .i { width: 24px; height: 24px; stroke-width: 2.2; }
.nb-new:hover { border-color: var(--accent); color: var(--accent); background-color: color-mix(in srgb, var(--accent) 4%, transparent); transform: translateY(-4px); }
.nb-new:hover .plus { transform: rotate(90deg) scale(1.06); }

.empty { text-align: center; padding: 40px 16px 80px; color: var(--muted); animation: rise 0.6s var(--ease) both; }
.empty h2 { color: var(--text); font-size: 30px; margin: 22px 0 6px; font-weight: 560; }
.empty p { max-width: 380px; margin: 0 auto 22px; }
.empty-art { position: relative; height: 190px; width: 260px; margin: 0 auto; }
.empty-art img { position: absolute; width: 150px; left: 55px; top: 0; filter: drop-shadow(0 12px 18px rgba(20, 30, 60, 0.2)); transition: transform 0.5s var(--spring); }
.empty-art img:nth-child(1) { transform: rotate(-14deg) translate(-56px, 10px); }
.empty-art img:nth-child(2) { transform: rotate(9deg) translate(56px, 6px); }
.empty-art img:nth-child(3) { transform: rotate(-2deg); }
.empty:hover .empty-art img:nth-child(1) { transform: rotate(-18deg) translate(-70px, 8px); }
.empty:hover .empty-art img:nth-child(2) { transform: rotate(13deg) translate(70px, 4px); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ================================================================ editor chrome */
/* The editor is pinned to the (visual) viewport so the top bar never scrolls away, even with the keyboard open. */
#editor { touch-action: pan-x pan-y; display: flex; flex-direction: column; overflow: hidden; position: fixed; left: 0; right: 0; top: 0; height: 100vh; height: 100dvh; background: var(--desk); }
html:has(body.in-editor), body.in-editor { overflow: hidden; overscroll-behavior: none; }
.ed-top {
  position: relative; z-index: 15; flex: none; display: flex; align-items: center; gap: 8px; min-height: var(--top-h);
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  /* No backdrop blur over the pages: it is re-blurred on every scroll, zoom and pen frame, which
     is costly on iPad, and the bar is nearly opaque anyway. */
  background: var(--glass-solid);
  border-bottom: 1px solid var(--border);
}
.ed-left, .ed-right { display: flex; align-items: center; gap: 2px; min-width: 0; }
.ed-left { flex: 1 1 0; }
.ed-right { flex: 1 1 0; justify-content: flex-end; }
.back-btn { padding: 0 10px 0 4px; color: var(--accent); font-weight: 600; }
.back-btn .i { width: 22px; height: 22px; stroke-width: 2.2; }
.title-stack { display: flex; flex-direction: column; min-width: 0; margin-left: 4px; }
.nb-title {
  border: 0; background: transparent; font-family: var(--font-display); font-weight: 600; font-size: 18px; padding: 1px 6px;
  border-radius: 7px; min-width: 60px; width: 260px; max-width: 30vw; letter-spacing: -0.01em; text-overflow: ellipsis;
}
.nb-title:hover, .nb-title:focus { outline: none; background: var(--surface-2); }
.save-status { font-size: 11.5px; color: var(--muted); padding: 0 6px; display: inline-flex; align-items: center; gap: 4px; }
.save-status.ok::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.save-status.err { color: var(--danger); }
.ed-center {
  display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 14px; background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}
.tool-btn { min-width: 38px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--text); transition: background 0.15s, color 0.15s, transform 0.15s var(--spring); }
.tool-btn:hover { background: var(--surface); }
.tool-btn:active { transform: scale(0.92); }
.tool-btn.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.insert-compact { display: none; }
.zoom { display: flex; align-items: center; border-radius: 11px; margin-right: 4px; }
.zoom .icon-btn { height: 34px; min-width: 32px; }
.zoom .i { width: 17px; height: 17px; }
.zoom-label { font-size: 12.5px; font-weight: 600; min-width: 46px; height: 30px; border-radius: 8px; font-variant-numeric: tabular-nums; color: var(--muted); }
.zoom-label:hover { background: var(--surface-2); color: var(--text); }

/* ---------------------------------------------------------------- format bar */
/* Pinned under the top bar while typing; with text selected it floats just above (or, on touch,
   below) the selection. See placeFormatBar in app.js. */
.format-bar {
  position: absolute; z-index: 20; left: 50%; top: calc(var(--top-h) + 10px); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 4px; padding: 5px; background: var(--surface); color: var(--text);
  max-width: calc(100vw - 16px); border-radius: 14px; box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  animation: pop 0.22s var(--spring);
}
.format-bar.floating { transition: left 0.12s var(--ease), top 0.12s var(--ease); }
.format-bar.selecting { visibility: hidden; }
.fmt-row { display: flex; gap: 2px; align-items: center; overflow-x: auto; scrollbar-width: none; }
.fmt-row::-webkit-scrollbar { display: none; }
.format-bar .sep { flex: none; width: 1px; height: 20px; margin: 0 3px; background: var(--border); }
.format-bar button { flex: none; min-width: 34px; height: 34px; border-radius: 9px; font-size: 15px; display: inline-grid; place-items: center; color: inherit; }
.format-bar button:hover { background: var(--surface-2); }
.format-bar button.on { background: var(--accent-soft); color: var(--accent); }
.format-bar button sup, .format-bar button sub { font-size: 9px; }
.format-bar .i { width: 18px; height: 18px; }
.format-bar svg.i[viewBox] { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.format-bar select { flex: none; height: 32px; border-radius: 9px; border: 0; background: var(--surface-2); color: inherit; padding: 0 8px; font-size: 13px; }
.format-bar .serif-i { font-family: var(--font-display); font-style: italic; font-weight: 600; }
.fmt-a { display: inline-flex; flex-direction: column; align-items: center; font-weight: 700; line-height: 1; gap: 2px; }
.fmt-swatch { width: 16px; height: 3px; border-radius: 2px; background: #1f2937; }
.fmt-clear { font-weight: 600; } .fmt-clear small { font-size: 9px; }
.format-bar .hl { background: #fde68a; color: #1f2937; padding: 0 4px; border-radius: 4px; font-weight: 600; }
.fmt-sub { display: flex; align-items: center; gap: 6px; padding: 4px 4px 2px; border-top: 1px solid var(--border); }
.fmt-sub[hidden] { display: none; }
.fmt-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.fmt-swatches button { min-width: 0; width: 24px; height: 24px; padding: 0; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
.fmt-swatches button:hover { background-color: inherit; transform: scale(1.12); }
.fmt-swatches button.none { background: linear-gradient(135deg, transparent 45%, var(--danger) 45% 55%, transparent 55%), var(--surface); }
.fmt-color { width: 28px; height: 28px; display: grid; place-items: center; cursor: pointer; }
.fmt-color input { width: 24px; height: 24px; border: 0; padding: 0; border-radius: 50%; background: none; cursor: pointer; }
.fmt-color input::-webkit-color-swatch-wrapper { padding: 0; }
.fmt-color input::-webkit-color-swatch { border: 0; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(0.97); } }

/* ---------------------------------------------------------------- sidebar + pages */
.ed-body { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 188px; flex: none; border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto;
  animation: slide-in 0.28s var(--ease);
}
@keyframes slide-in { from { transform: translateX(-24px); opacity: 0; } }
.sidebar-head {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 8px 18px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); background: var(--surface);
}
.page-thumbs { display: flex; flex-direction: column; gap: 16px; padding: 6px 18px 24px; }
.thumb { cursor: pointer; }
.thumb canvas {
  width: 100%; aspect-ratio: 136 / 176; height: auto; border-radius: 6px; display: block; background: #fff;
  box-shadow: 0 0 0 1px var(--border), var(--shadow-xs); transition: box-shadow 0.2s, transform 0.2s var(--spring);
}
.thumb:hover canvas { transform: translateY(-2px); box-shadow: 0 0 0 1px var(--border), var(--shadow-sm); }
.thumb.current canvas { box-shadow: 0 0 0 2.5px var(--accent), var(--shadow-sm); }
.thumb-row { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); padding-top: 6px; }
.thumb.current .thumb-row { color: var(--accent); font-weight: 600; }
.thumb-more { padding: 0 7px; border-radius: 6px; font-size: 16px; line-height: 1.3; color: var(--muted); }
.thumb-more:hover { background: var(--surface-2); }

.scroller {
  flex: 1; overflow: auto; overscroll-behavior: contain; position: relative;
  background-color: var(--desk); background-image: radial-gradient(var(--desk-dot) 1px, transparent 1.2px); background-size: 22px 22px;
}
.pages { display: flex; flex-direction: column; align-items: center; gap: 34px; padding: 32px 16px 190px; width: max-content; min-width: 100%; }
.page-wrap { position: relative; flex: none; animation: page-in 0.45s var(--ease) both; }
@keyframes page-in { from { opacity: 0; transform: translateY(14px); } }
/* Only the first pages animate in; animating every page of a long notebook at once made opening it stutter. */
.page-wrap:nth-child(n+4) { animation: none; }
.page {
  position: absolute; left: 0; top: 0; width: 816px; height: 1056px; transform-origin: 0 0;
  background-size: 100% 100%; box-shadow: var(--page-shadow); border-radius: 3px; overflow: hidden;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.page-label {
  position: absolute; left: 50%; bottom: -26px; transform: translateX(-50%); font-size: 11.5px; font-weight: 600; color: var(--faint);
  letter-spacing: 0.06em; font-variant-numeric: tabular-nums;
}
.ink {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; touch-action: var(--ink-touch);
}
/* Only pages with images or text under the ink blend it (see markBlend in editor.js): blending
   a big canvas costs every scroll and zoom frame on iPad, and over bare paper it looks the same. */
.page.blend:not(.dark-paper) .ink { mix-blend-mode: multiply; }
/* The stroke being drawn (and other moving marks) sit on a shared overlay above the page's ink. */
.ink-live { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }
/* No long-press loupe, callout or text selection while writing on the page. */
.page-wrap { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.page-wrap .item [contenteditable] { -webkit-user-select: text; user-select: text; }
.items { position: absolute; inset: 0; z-index: 1; }
body[data-tool=text] .ink { pointer-events: none; }
body[data-tool=text] .items { cursor: text; }
body:not([data-tool=text]) .items { pointer-events: none; }
body[data-tool=eraser] .ink { cursor: none; }
body[data-tool=select] .ink { cursor: default; }
body[data-tool=select] .ink.over-item { cursor: move; }
/* The AI pointer: an arrow with a spark. */
body[data-tool=ai] .ink { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 26 26'><path d='M3 2 15 8l-5.4 1.6L7.2 15z' fill='%23111' stroke='white' stroke-width='1.4' stroke-linejoin='round'/><path d='M19 12.5l1 2.6 2.6 1-2.6 1-1 2.6-1-2.6-2.6-1 2.6-1z' fill='%237c3aed' stroke='white' stroke-width='1'/></svg>") 3 2, crosshair; }
body[data-tool=ai] .ink.over-item { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 26 26'><path d='M3 2 15 8l-5.4 1.6L7.2 15z' fill='%237c3aed' stroke='white' stroke-width='1.4' stroke-linejoin='round'/><path d='M19 12.5l1 2.6 2.6 1-2.6 1-1 2.6-1-2.6-2.6-1 2.6-1z' fill='%237c3aed' stroke='white' stroke-width='1'/></svg>") 3 2, pointer; }
.tool-btn.ai-pointer.active { color: #7c3aed; background: color-mix(in srgb, #7c3aed 14%, transparent); }
body[data-tool=select] .ink:is([data-corner=nw], [data-corner=se]) { cursor: nwse-resize; }
body[data-tool=select] .ink:is([data-corner=ne], [data-corner=sw]) { cursor: nesw-resize; }
body[data-tool=hand] .ink { cursor: grab; }
body.panning .ink { cursor: grabbing; }
.ink { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16'><circle cx='8' cy='8' r='2.5' fill='%2326221d' stroke='white' stroke-width='1.5'/></svg>") 8 8, crosshair; }

/* ---------------------------------------------------------------- typed content */
.item { position: absolute; min-width: 60px; border-radius: 6px; }
.item-body { font-size: 18px; line-height: 32px; }
/* --tf/--tl come from the page's ruling (see textMetrics in editor.js). */
.item-text .item-body { font-size: var(--tf, 18px); line-height: var(--tl, 32px); }
.item-text [contenteditable] { min-height: var(--tl, 32px); }
.item [contenteditable] { outline: none; min-height: 32px; overflow-wrap: anywhere; }
/* No focus ring around the line being typed (the app-wide :focus-visible ring is for buttons and fields). */
.item [contenteditable]:focus, .item [contenteditable]:focus-visible { outline: none; box-shadow: none; }
.item .rich ul, .item .rich ol { margin: 0; padding-left: 28px; }
.item .rich font[size="6"] { font-weight: 700; }
body[data-tool=text] .item:hover, .item.editing, .item.picked { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 45%, transparent); }
.item.selected { box-shadow: 0 0 0 2px var(--accent); }
.item-bar {
  position: absolute; left: -1px; bottom: 100%; margin-bottom: 6px; display: none; gap: 2px; align-items: center;
  padding: 3px; background: var(--surface); color: var(--text); border-radius: 10px; box-shadow: var(--shadow), 0 0 0 1px var(--border);
  white-space: nowrap; font: 600 12px/1 var(--font-ui);
}
body[data-tool=text] .item:hover .item-bar, .item.editing .item-bar, .item.picked .item-bar { display: flex; animation: fade 0.15s; }
/* Anything in an item that isn't text (an image, a sticky's margin, a table border) grabs the whole item. */
body[data-tool=text] .item { cursor: move; }
body[data-tool=text] :is(.item-image, .item-sticky) { touch-action: none; }
body[data-tool=text] .item [contenteditable] { cursor: text; }
body.dragging-item, body.dragging-item * { cursor: grabbing !important; user-select: none; }
.item.dragging { box-shadow: 0 0 0 2px var(--accent), 0 14px 30px -10px rgba(0, 0, 0, 0.35); z-index: 2; }
.item-bar button { padding: 6px 8px; border-radius: 7px; }
.item-bar button:hover { background: var(--surface-2); }
.item-bar .del { color: var(--danger); }
.item-bar .dot { width: 18px; height: 18px; padding: 0; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
.drag-handle { cursor: grab; width: 30px; height: 26px; border-radius: 7px; display: inline-grid; place-items: center; touch-action: none; color: var(--muted); }
.drag-handle:hover { background: var(--surface-2); color: var(--accent); }
.drag-handle .i { width: 17px; height: 17px; }
.resize-handle {
  position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); display: none; cursor: nwse-resize; touch-action: none;
}
body[data-tool=text] .item:hover .resize-handle, .item.editing .resize-handle, .item.picked .resize-handle { display: block; }
/* With the lasso, a picture, video or link card selected on its own can be sized from its corners. */
body[data-tool=select] :is(.item-image, .item-video, .item-link).selected .resize-handle { display: block; }
.item.bar-below .item-bar { bottom: auto; top: 100%; margin: 12px 0 0; }
.resize-handle.corner-nw { right: auto; bottom: auto; left: -7px; top: -7px; }
.resize-handle.corner-ne { bottom: auto; top: -7px; cursor: nesw-resize; }
.resize-handle.corner-sw { right: auto; left: -7px; cursor: nesw-resize; }
/* The bar sits above the item, so the top corners are reached below it. */
.item-image .item-bar, .item-video .item-bar, .item-link .item-bar { margin-bottom: 12px; }
/* Text is written straight on the paper: never a box around it, only the small bar on hover. */
body[data-tool=text] .item-text:hover, .item-text:is(.editing, .picked) { box-shadow: none; outline: none; }
.item-text.editing:not(:hover) .item-bar, .item-text.editing .resize-handle { display: none; }
body[data-tool=text] :is(.item.picked, .item.editing) { touch-action: none; }
@media (pointer: coarse) {
  .resize-handle { width: 22px; height: 22px; right: -11px; bottom: -11px; }
  .resize-handle.corner-nw { left: -11px; top: -11px; }
  .resize-handle.corner-ne { top: -11px; }
  .resize-handle.corner-sw { left: -11px; }
}
@keyframes fade { from { opacity: 0; } }

.item-sticky { padding: 14px 16px; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08), 0 10px 22px -6px rgba(0, 0, 0, 0.22); color: #1f2937; border-radius: 3px 3px 14px 3px; }
.item-sticky .item-body { font-size: 16px; line-height: 24px; height: 100%; overflow: hidden; }
.item-sticky .rich { min-height: 100%; }

.checklist { display: flex; flex-direction: column; }
.chk-row { display: flex; align-items: flex-start; gap: 10px; }
.chk-row input {
  appearance: none; width: 19px; height: 19px; margin: 6.5px 0 0; flex: none; pointer-events: auto; cursor: pointer;
  border: 1.75px solid currentColor; border-radius: 6px; opacity: 0.55; transition: background 0.15s, opacity 0.15s;
  display: grid; place-items: center;
}
.chk-row input:checked { background: var(--accent); border-color: var(--accent); opacity: 1; }
.chk-row input:checked::after { content: ""; width: 9px; height: 5px; border: solid #fff; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.chk-text { flex: 1; }
.chk-row.done .chk-text { text-decoration: line-through; opacity: 0.5; }
.items .chk-row input { pointer-events: auto; }

.item-table table { border-collapse: collapse; width: 100%; table-layout: fixed; background: color-mix(in srgb, currentColor 3%, transparent); }
.item-table td, .item-table .cell {
  display: table-cell; border: 1.25px solid color-mix(in srgb, currentColor 28%, transparent); padding: 2px 8px;
  vertical-align: top; font-size: 16px; line-height: 28px;
}
.item-table table.has-header tr:first-child .cell { font-weight: 650; background: color-mix(in srgb, currentColor 7%, transparent); }
.item-image img { display: block; width: 100%; height: auto; border-radius: 6px; user-select: none; }
.video-frame { position: relative; border-radius: 10px; overflow: hidden; background: #000; }
.video-frame video { display: block; width: 100%; height: auto; }
.video-frame.embed { aspect-ratio: 16 / 9; }
.video-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.video-shield { position: absolute; inset: 0; }
.video-frame:not(.embed) .video-shield { bottom: 44px; } /* the video's own controls stay usable */
.item-video.picked .video-shield { display: none; }
body.read-only .item-video { pointer-events: auto; }
body.read-only .video-shield { display: none; }
/* Something dragged over the pages from another app. */
#scroller.drop-over .page-wrap { outline: 2px dashed color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 6px; }

/* Links in typed text, and the preview card a pasted link becomes. */
.item .rich a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
body[data-tool=text] .item-link { touch-action: none; }
.link-card {
  display: block; overflow: hidden; border-radius: 12px; background: #fff; color: #1f2937; user-select: none;
  border: 1px solid rgba(15, 23, 42, 0.12); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 20px -12px rgba(15, 23, 42, 0.3);
}
.link-img { display: block; width: 100%; aspect-ratio: 1.91 / 1; object-fit: cover; background: #f1f5f9; border-bottom: 1px solid rgba(15, 23, 42, 0.08); }
.link-meta { padding: 10px 14px 12px; display: grid; gap: 3px; font-family: var(--font-ui); }
.link-title { font: 650 15px/1.35 var(--font-ui); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.link-desc { font: 400 13px/1.4 var(--font-ui); color: #475569; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-site { font: 500 12px/1.3 var(--font-ui); color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-card.loading .link-title { color: #94a3b8; }
.link-card.loading::before { content: ""; display: block; aspect-ratio: 1.91 / 1; background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%) 0 0 / 200% 100%; animation: link-shimmer 1.2s linear infinite; }
@keyframes link-shimmer { to { background-position: -200% 0; } }
body.read-only .item-link { pointer-events: auto; cursor: pointer; }

.sel-menu {
  position: absolute; z-index: 5; display: flex; gap: 2px; align-items: center; padding: 4px; background: #141c2e;
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); animation: fade 0.15s;
}
.sel-menu button { color: #fff; padding: 7px 12px; border-radius: 8px; font: 600 13px/1 var(--font-ui); }
.sel-menu button:hover { background: rgba(255, 255, 255, 0.12); }
.sel-menu input { width: 26px; height: 26px; border: 0; padding: 0; background: none; cursor: pointer; }
.sel-menu-ai { background: linear-gradient(135deg, #4c1d95, #6d28d9); }

/* ================================================================ tool palette */
.palette {
  position: absolute; z-index: 18; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: flex-end; gap: 4px; padding: 0 10px; height: 100px; max-width: calc(100vw - 24px);
  background: var(--glass-solid); /* no backdrop blur, see .ed-top */
  border-radius: 999px; padding: 0 16px; box-shadow: var(--shadow-lg), 0 0 0 1px var(--border), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  animation: palette-in 0.5s var(--spring) both 0.1s; --art-w: 53px; --pal-in: 0 30px;
}
@keyframes palette-in { from { opacity: 0; translate: var(--pal-in); } }
.pal-group { display: flex; align-items: center; gap: 4px; height: 100%; padding: 0 6px; }
.pal-group + .pal-tray, .pal-tray + .pal-group, .pal-group + .pal-group { border-left: 1px solid var(--border); }
.pal-history { gap: 8px; padding-left: 4px; padding-right: 10px; }
.pal-icon {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text);
  transition: background 0.15s, transform 0.15s var(--spring), opacity 0.2s;
}
.pal-icon .i { width: 19px; height: 19px; stroke-width: 2; }
.pal-icon:disabled { opacity: 0.45; color: var(--faint); }
.pal-icon:hover:not(:disabled) { background: var(--surface-3); }
.pal-icon:active:not(:disabled) { transform: scale(0.9); }
.pal-icon.active, .pal-icon.active:hover:not(:disabled) { background: var(--accent); color: #fff; }

.pal-tray {
  display: flex; align-items: flex-end; gap: 2px; height: 100%; padding: 0 8px; overflow: hidden;
  /* tools are cut off at the bottom edge, as if standing in a tray */
  -webkit-mask-image: linear-gradient(180deg, #000 82%, transparent 100%); mask-image: linear-gradient(180deg, #000 82%, transparent 100%);
}
.ptool {
  position: relative; width: 50px; height: 100%; flex: none; display: flex; justify-content: center;
  transition: filter 0.2s;
}
.ptool-art {
  position: absolute; top: 16px; width: var(--art-w); aspect-ratio: 88 / 500; transition: transform 0.38s var(--spring);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.14)) drop-shadow(2px 0 4px rgba(0, 0, 0, 0.06));
}
.ptool-art img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.ptool-tint {
  position: absolute; inset: 0; isolation: isolate;
  -webkit-mask: var(--tip) 0 0 / 100% 100% no-repeat; mask: var(--tip) 0 0 / 100% 100% no-repeat;
  background: var(--ink, #222); transition: background-color 0.25s;
}
.ptool-tint img { mix-blend-mode: multiply; }
.ptool-num {
  position: absolute; left: 0; right: 0; top: 71px; text-align: center; font: 600 9px/1 var(--font-ui); color: #8e8e93;
  letter-spacing: 0.02em; font-variant-numeric: tabular-nums; opacity: 0; transition: opacity 0.25s;
}
.ptool.active .ptool-num { opacity: 1; }
.ptool:hover .ptool-art { transform: translateY(-5px); }
.ptool.active .ptool-art { transform: translateY(-16px); }
.ptool:active .ptool-art { transform: translateY(-12px) scale(0.98); }
.ptool.active::after {
  content: ""; position: absolute; bottom: 7px; left: 50%; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%;
  background: var(--accent); animation: fade 0.3s;
}
.ptool:focus-visible { box-shadow: none; }
.ptool:focus-visible .ptool-art { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }
.ptool.toggle-on .ptool-art { transform: translateY(-16px); }
.ptool-tray-sep { width: 1px; align-self: center; height: 44px; background: var(--border); margin: 0 4px; }

.pal-colors {
  display: grid; grid-template-rows: repeat(2, 30px); grid-auto-flow: column; grid-auto-columns: 30px; gap: 8px 10px;
  align-content: center; padding: 0 14px; transition: opacity 0.25s;
}
.pal-colors .swatches { display: contents; }
.palette[data-ink="false"] .pal-colors, .palette[data-ink="false"] .pal-size .size-dot { opacity: 0.35; }
.swatches { display: flex; gap: 6px; }

/* ---------------------------------------------------------------- moving the palette */
.pal-grip {
  align-self: center; flex: none; width: 20px; height: 46px; margin: 0 -2px 0 -8px; border-radius: 10px; display: grid; place-items: center;
  color: var(--faint); cursor: grab; touch-action: none; transition: background 0.15s, color 0.15s;
}
.pal-grip span { width: 6px; height: 20px; background: radial-gradient(circle, currentColor 1.3px, transparent 1.7px) 0 0 / 6px 7px; }
.pal-grip:hover { background: var(--surface-2); color: var(--muted); }
.palette.moving { cursor: grabbing; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28), 0 0 0 1px var(--border); opacity: 0.94; }
.palette.moving .pal-grip { cursor: grabbing; color: var(--accent); }
.dock-hint {
  position: absolute; z-index: 17; border-radius: 28px; pointer-events: none; transition: all 0.25s var(--ease);
  background: color-mix(in srgb, var(--accent) 12%, transparent); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent);
}
.dock-hint[data-dock=bottom] { left: 50%; width: min(760px, calc(100% - 24px)); translate: -50% 0; bottom: max(12px, env(safe-area-inset-bottom)); height: 108px; border-radius: 999px; }
.dock-hint[data-dock=left], .dock-hint[data-dock=right] { top: calc(var(--top-h) + 14px); bottom: 14px; width: 108px; border-radius: 54px; }
.dock-hint[data-dock=left] { left: 10px; }
.dock-hint[data-dock=right] { right: 10px; }

/* Docked to a side, the palette stands upright and the tools point at the page. */
.palette:is([data-dock=left], [data-dock=right]) {
  flex-direction: column; align-items: stretch; width: 100px; height: auto; max-width: none; max-height: calc(100% - var(--top-h) - 28px);
  top: calc(50% + var(--top-h) / 2); bottom: auto; transform: translateY(-50%); padding: 14px 0; border-radius: 50px;
  overflow-y: auto; overflow-x: hidden; scrollbar-width: none; --art-h: calc(var(--art-w) * 500 / 88);
  /* iPad WebKit sometimes drops the painted contents of a rounded scrolling layer (the palette then
     shows as an empty white pill). Its own composited layer, and no masks inside it, avoid that. */
  transform: translate3d(0, -50%, 0); will-change: transform; isolation: isolate;
}
.palette:is([data-dock=left], [data-dock=right])::-webkit-scrollbar { display: none; }
.palette[data-dock=left] { left: max(14px, env(safe-area-inset-left)); --pal-in: -30px 0; }
.palette[data-dock=right] { left: auto; right: max(14px, env(safe-area-inset-right)); --pal-in: 30px 0; }
.palette:is([data-dock=left], [data-dock=right]) .pal-grip { width: 46px; height: 20px; margin: -4px auto 2px; }
.palette:is([data-dock=left], [data-dock=right]) .pal-grip span { width: 20px; height: 6px; background-size: 7px 6px; }
.palette:is([data-dock=left], [data-dock=right]) .pal-group { flex-direction: column; height: auto; padding: 12px 0; flex: none; }
.palette:is([data-dock=left], [data-dock=right]) :is(.pal-group + .pal-tray, .pal-tray + .pal-group, .pal-group + .pal-group) { border-left: 0; border-top: 1px solid var(--border); }
.palette:is([data-dock=left], [data-dock=right]) .pal-history { gap: 6px; }
.palette:is([data-dock=left], [data-dock=right]) .pal-icon { width: 38px; height: 38px; }
.palette:is([data-dock=left], [data-dock=right]) .pal-tray { flex-direction: column; align-items: stretch; height: auto; flex: none; padding: 6px 0; }
.palette:is([data-dock=left], [data-dock=right]) .pal-tray { -webkit-mask-image: none; mask-image: none; }
.palette:is([data-dock=left], [data-dock=right]) .ptool { width: 100%; height: 40px; }
.palette:is([data-dock=left], [data-dock=right]) .ptool-art { top: calc(50% - var(--art-h) / 2); }
.palette[data-dock=left] .ptool-art { left: calc(100% - 16px - var(--art-h) / 2 - var(--art-w) / 2); transform: rotate(90deg); }
.palette[data-dock=left] .ptool:hover .ptool-art { transform: translateX(5px) rotate(90deg); }
.palette[data-dock=left] :is(.ptool.active, .ptool.toggle-on) .ptool-art { transform: translateX(16px) rotate(90deg); }
.palette[data-dock=left] .ptool:active .ptool-art { transform: translateX(12px) rotate(90deg) scale(0.98); }
.palette[data-dock=right] .ptool-art { left: calc(16px + var(--art-h) / 2 - var(--art-w) / 2); transform: rotate(-90deg); }
.palette[data-dock=right] .ptool:hover .ptool-art { transform: translateX(-5px) rotate(-90deg); }
.palette[data-dock=right] :is(.ptool.active, .ptool.toggle-on) .ptool-art { transform: translateX(-16px) rotate(-90deg); }
.palette[data-dock=right] .ptool:active .ptool-art { transform: translateX(-12px) rotate(-90deg) scale(0.98); }
.palette:is([data-dock=left], [data-dock=right]) .ptool.active::after { top: 50%; bottom: auto; margin: -2.5px 0 0; }
.palette[data-dock=left] .ptool.active::after { left: 7px; }
.palette[data-dock=right] .ptool.active::after { left: auto; right: 7px; }
.palette:is([data-dock=left], [data-dock=right]) .ptool-tray-sep { width: 44px; height: 1px; margin: 4px auto; }
.palette:is([data-dock=left], [data-dock=right]) .pal-colors {
  grid-template-rows: none; grid-auto-flow: row; grid-template-columns: repeat(3, 24px); grid-auto-rows: 24px; gap: 8px 6px;
  justify-content: center; padding: 12px 0;
}
.palette:is([data-dock=left], [data-dock=right]) .pal-colors :is(.swatch, .custom-color) { width: 24px; height: 24px; }
.palette:is([data-dock=left], [data-dock=right]) .ring-fill { width: 14px; height: 14px; }
.palette:is([data-dock=left], [data-dock=right]) .pal-size { align-items: center; }
/* Keep the pages clear of a side palette. */
#editor[data-dock=left] .pages { padding-left: 132px; }
#editor[data-dock=right] .pages { padding-right: 132px; }
#editor:is([data-dock=left], [data-dock=right]) .pages { padding-bottom: 80px; }
body.in-editor:has(#editor:is([data-dock=left], [data-dock=right])) .toast { bottom: 28px; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; position: relative; flex: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); transition: transform 0.25s var(--spring);
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { transform: scale(1.06); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12), 0 0 0 2.5px var(--surface), 0 0 0 4.5px color-mix(in srgb, var(--sw) 72%, var(--text)); }
.swatch.light.active { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2), 0 0 0 2.5px var(--surface), 0 0 0 4.5px var(--border-strong); }
.custom-color { position: relative; width: 30px; height: 30px; cursor: pointer; flex: none; border-radius: 50%; }
.ring {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none; display: grid; place-items: center;
  background: conic-gradient(from 0deg, #ff5f57, #ffbd2e, #f8e71c, #28c840, #36c5f0, #5b6cff, #c86dd7, #ff5f57);
  transition: transform 0.25s var(--spring);
}
.ring-fill { width: 18px; height: 18px; border-radius: 50%; background: var(--surface); box-shadow: 0 0 0 2px var(--surface); }
.custom-color.active .ring-fill { background: var(--custom, var(--surface)); }
.custom-color:hover .ring { transform: rotate(40deg) scale(1.06); }
.swatches-grid { display: grid; grid-template-columns: repeat(5, 30px); gap: 12px; padding: 4px; }

.size-btn { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); transition: background 0.15s, transform 0.2s var(--spring); }
.size-btn:hover { background: var(--surface-3); }
.size-btn:active { transform: scale(0.94); }
.size-btn.open { background: var(--accent-soft); }
.size-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dot, var(--text)); opacity: var(--dot-a, 1); transition: width 0.2s var(--spring), height 0.2s var(--spring), opacity 0.2s; box-shadow: 0 0 0 1px var(--border-strong); }

/* ---------------------------------------------------------------- popovers */
.popover {
  position: absolute; z-index: 30; background: var(--surface); border-radius: var(--r-lg); padding: 14px;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border); animation: pop-up 0.24s var(--spring);
  transform-origin: bottom center;
}
@keyframes pop-up { from { opacity: 0; transform: translateY(8px) scale(0.96); } }
.tool-options { width: 280px; display: flex; flex-direction: column; gap: 12px; }
.to-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 650; font-family: var(--font-display); font-size: 17px; }
.to-value { font: 600 12px var(--font-ui); color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.to-preview { width: 100%; height: 56px; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 1px var(--border); }
:root[data-theme="dark"] .to-preview { background: #fbfaf7; }
.sizes { display: flex; gap: 6px; }
.size {
  flex: 1; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2);
  transition: background 0.15s, box-shadow 0.15s;
}
.size span { background: var(--text); border-radius: 50%; display: block; }
.size:hover { background: var(--surface-3); }
.size.active { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.size.active span { background: var(--accent); }
.slider-row { display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.slider-row:not(#opacity-row) { grid-template-columns: 58px 1fr; }
input[type=range] { appearance: none; height: 28px; background: none; width: 100%; cursor: pointer; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 99px; background: linear-gradient(90deg, var(--accent) var(--p, 50%), var(--surface-3) var(--p, 50%)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 99px; background: var(--surface-3); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 0 0.5px rgba(0, 0, 0, 0.1); transition: transform 0.2s var(--spring); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); }
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.15); }

.segmented { display: flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--surface-2); }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 7px 10px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background 0.2s, color 0.2s, box-shadow 0.2s; white-space: nowrap; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + span { box-shadow: var(--focus); }

/* Paper-style colour mixer: thick gradient tracks for hue, saturation and brightness. */
.mixer { width: 300px; display: flex; flex-direction: column; gap: 12px; }
.mix-head { display: flex; align-items: center; gap: 12px; }
.mix-preview { width: 46px; height: 46px; border-radius: 50%; background: var(--mix); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12), 0 4px 12px color-mix(in srgb, var(--mix) 40%, transparent); flex: none; transition: background 0.1s; }
.mix-hex { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; height: 38px; padding: 0 12px; border-radius: 11px; background: var(--surface-2); font: 600 15px var(--font-ui); color: var(--muted); }
.mix-hex input { flex: 1; width: 100%; min-width: 0; border: 0; outline: 0; background: none; font: inherit; color: var(--text); text-transform: uppercase; letter-spacing: 0.06em; }
.mix-row { display: flex; align-items: center; gap: 10px; }
.mix-val { width: 28px; text-align: right; font: 600 12px var(--font-ui); color: var(--muted); font-variant-numeric: tabular-nums; }
input[type=range].mix { height: 30px; flex: 1; min-width: 0; border-radius: 99px; }
input[type=range].mix::-webkit-slider-runnable-track { height: 28px; border-radius: 99px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); background: var(--track); }
input[type=range].mix::-moz-range-track { height: 28px; border-radius: 99px; background: var(--track); }
input[type=range].mix::-moz-range-progress { background: transparent; }
input[type=range].mix::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: 1px; border: 3px solid #fff; background: transparent; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(0, 0, 0, 0.1); }
input[type=range].mix::-moz-range-thumb { width: 20px; height: 20px; border: 3px solid #fff; background: transparent; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); }
.mix.hue { --track: linear-gradient(90deg, #f00, #ff0 16.6%, #0f0 33.3%, #0ff 50%, #00f 66.6%, #f0f 83.3%, #f00); }
.mix.sat { --track: linear-gradient(90deg, var(--sat0), var(--sat1)); }
.mix.bri { --track: linear-gradient(90deg, #000, var(--bri1)); }
.mix-recent-wrap { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; font-size: 12px; font-weight: 600; color: var(--muted); }
.mix-recent { display: flex; gap: 8px; flex-wrap: wrap; }
.mix-recent .swatch { width: 24px; height: 24px; }

.more-pop { width: 290px; display: flex; flex-direction: column; gap: 10px; }
.row-toggle { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; cursor: pointer; padding: 4px 2px; }
.row-toggle span { flex: 1; }
.row-label { font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.row-hint { font-size: 12px; color: var(--muted); line-height: 1.6; border-top: 1px solid var(--border); padding-top: 10px; }

/* ================================================================ ruler */
.ruler {
  position: fixed; z-index: 12; left: 0; top: 0; width: 980px; height: 92px; margin: -46px 0 0 -490px;
  border-radius: 10px; background: color-mix(in srgb, var(--surface) 50%, transparent);
  box-shadow: 0 0 0 1px var(--border-strong), 0 10px 30px rgba(0, 0, 0, 0.18); cursor: grab; touch-action: none;
  user-select: none; animation: fade 0.25s;
}
.ruler:active { cursor: grabbing; }
.ruler-ticks {
  position: absolute; inset: 0; border-radius: inherit; opacity: 0.75;
  background:
    repeating-linear-gradient(90deg, var(--text) 0 1px, transparent 1px 100px) 0 0 / 100% 22px no-repeat,
    repeating-linear-gradient(90deg, var(--text) 0 1px, transparent 1px 50px) 0 0 / 100% 14px no-repeat,
    repeating-linear-gradient(90deg, var(--text) 0 1px, transparent 1px 10px) 0 0 / 100% 8px no-repeat,
    repeating-linear-gradient(90deg, var(--text) 0 1px, transparent 1px 100px) 0 100% / 100% 22px no-repeat,
    repeating-linear-gradient(90deg, var(--text) 0 1px, transparent 1px 10px) 0 100% / 100% 8px no-repeat;
  background-position-x: 40px;
}
.ruler-angle {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font: 650 15px var(--font-ui); font-variant-numeric: tabular-nums;
  padding: 4px 12px; border-radius: 99px; background: var(--surface); box-shadow: var(--shadow-sm); pointer-events: none;
}
.ruler-knob {
  position: absolute; top: 50%; width: 26px; height: 26px; margin-top: -13px; border-radius: 50%; background: var(--surface);
  box-shadow: var(--shadow-sm), inset 0 0 0 2px var(--accent); cursor: alias;
}
.ruler-knob.start { left: 10px; }
.ruler-knob.end { right: 10px; }

/* ================================================================ dialogs, menus, gallery */
.dialog {
  border: 0; border-radius: var(--r-xl); padding: 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border); max-height: min(92vh, 900px); max-width: calc(100vw - 24px);
  overflow: hidden; overscroll-behavior: contain;
}
/* The sheet is a column: header and footer stay put, the body between them is the one scroller. */
.dialog[open] { display: flex; flex-direction: column; animation: sheet-in 0.35s var(--spring); }
.dialog::backdrop { background: rgba(28, 20, 12, 0.38); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade 0.25s; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(18px) scale(0.97); } }
/* Basis auto, not `flex: 1`: where a phone's web view takes the 0 basis literally, the form is 0 tall and so is the sheet. */
.dialog form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.dialog :is(.nb-sheet-body, .nb-setup .cover-picker, .gal-grid, .cover-picker.large) { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 8px 26px; }
.sheet-head h2 { margin: 0; font-size: 26px; font-weight: 580; }
.sheet-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 22px 18px; border-top: 1px solid var(--border); }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field > span { font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.field input[name=title] {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-size: 16px;
  font-family: var(--font-display); font-weight: 500; transition: border-color 0.2s, box-shadow 0.2s;
}
.field input[name=title]:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: var(--focus); }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; font-weight: 550; cursor: pointer; }

.nb-sheet { width: min(1240px, calc(100vw - 24px)); }
.tpl-sheet { width: min(1180px, calc(100vw - 24px)); }
.cover-sheet { width: min(820px, calc(100vw - 24px)); }
.nb-sheet[open], .tpl-sheet[open] { height: min(94vh, 1000px); }
/* Wide screens: setup on the left, templates on the right, and only the template grid scrolls. */
.nb-sheet-body {
  display: grid; grid-template-columns: 260px 1fr; grid-template-rows: minmax(0, 1fr); gap: 26px; padding: 8px 26px 0;
  flex: 1; min-height: 0; overflow: hidden;
}
.nb-setup { display: flex; flex-direction: column; gap: 18px; min-height: 0; overflow: hidden; padding-bottom: 18px; }
/* The preview and title stay fixed; only the cover grid below them scrolls. */
.nb-setup > .cover-preview, .nb-setup > label.field { flex: none; }
.nb-setup > .field:last-child { flex: 1 1 auto; min-height: 0; }
.nb-setup .cover-picker { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 6px 4px 12px; align-content: start; scrollbar-width: thin; }
.nb-gallery-wrap { min-height: 0; }
.nb-gallery-wrap .gallery { flex: 1; }
.cover-preview { width: 150px; align-self: center; filter: drop-shadow(0 14px 20px rgba(20, 30, 60, 0.22)); transition: transform 0.4s var(--spring); }
.cover-preview.bump { animation: bump 0.45s var(--spring); }
@keyframes bump { 40% { transform: rotate(-2.5deg) scale(1.03); } }
.cover-picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px 8px; padding-bottom: 8px; }
.cover-picker.large { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 22px 18px; padding: 8px 26px 22px; flex: 1; min-height: 0; overflow-y: auto; }
.cover-opt { position: relative; cursor: pointer; border-radius: 6px; }
.cover-opt input { position: absolute; opacity: 0; pointer-events: none; }
.cover-opt .cover-art { transition: transform 0.25s var(--spring); filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15)); }
.cover-opt:hover .cover-art { transform: translateY(-3px); }
.cover-opt:has(input:checked) .cover-art { transform: translateY(-4px); }
.cover-opt:has(input:checked)::after {
  content: ""; position: absolute; left: 50%; bottom: -8px; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--accent);
}
.cover-opt input:focus-visible + .cover-art { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
/* "Your image": an empty notebook outline until a picture is picked. */
.cover-own-add {
  position: absolute; inset: 0 0 0 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 1.5px dashed var(--border-strong); border-radius: 4px 8px 8px 4px; background: var(--surface-2);
  color: var(--muted); font: 600 10.5px/1.2 var(--font-ui); text-align: center;
}
.cover-own-add .i { width: 22px; height: 22px; }
.cover-own .cover-art { filter: none; }
.cover-own.has-picture .cover-art { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15)); }
.cover-own.has-picture .cover-own-add { display: none; }
.cover-own:not(.has-picture) img { visibility: hidden; }

.gallery { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.tpl-sheet .gallery { padding: 4px 26px 0; overflow: hidden; flex: 1; }
.gallery .gal-grid { flex: 1; }
.gal-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.gal-bar .search { height: 38px; flex: 1 1 200px; background: var(--surface-2); border-color: transparent; }
.gal-bar .search input { width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 7px 13px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--muted);
  transition: background 0.2s, color 0.2s, transform 0.2s var(--spring); white-space: nowrap;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--text); color: var(--surface); }
.chip .n { opacity: 0.55; margin-left: 4px; font-weight: 500; }
.papers { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.papers .lbl { font-size: 12px; color: var(--muted); font-weight: 600; margin-right: 2px; }
.paper-opt { width: 26px; height: 26px; border-radius: 50%; cursor: pointer; position: relative; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18); transition: transform 0.2s var(--spring); }
.paper-opt input { position: absolute; opacity: 0; pointer-events: none; }
.paper-opt:hover { transform: scale(1.08); }
.paper-opt:has(input:checked) { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18), 0 0 0 2.5px var(--surface), 0 0 0 4.5px var(--accent); }
.gal-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 26px 20px; overflow-y: auto;
  padding: 6px 4px 18px; min-height: 240px; align-content: start;
}

.gal-section { grid-column: 1 / -1; font-family: var(--font-display); font-size: 18px; font-weight: 580; margin: 8px 0 -6px; }
.gal-section:first-child { margin-top: 0; }
.tpl { display: flex; flex-direction: column; gap: 7px; cursor: pointer; position: relative; animation: fade 0.3s both; }
.tpl input { position: absolute; opacity: 0; pointer-events: none; }
.tpl-preview {
  width: 100%; aspect-ratio: 816 / 1056; border-radius: 6px; display: block; background: #fff;
  box-shadow: 0 0 0 1px var(--border), var(--shadow-sm); transition: transform 0.25s var(--spring), box-shadow 0.2s;
}
.tpl:hover .tpl-preview { transform: translateY(-3px); box-shadow: 0 0 0 1px var(--border), var(--shadow); }
.tpl input:checked ~ .tpl-preview { box-shadow: 0 0 0 2.5px var(--accent), var(--shadow); transform: translateY(-3px); }
.tpl input:focus-visible ~ .tpl-preview { box-shadow: 0 0 0 2.5px var(--accent), var(--focus); }
.tpl-variants { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin-top: -2px; }
.tpl-variant {
  font-size: 11px; line-height: 1; padding: 4px 7px; border-radius: 99px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; cursor: pointer;
}
.tpl-variant:hover { color: var(--text); border-color: var(--border-strong, var(--border)); }
.tpl-variant.active { color: var(--accent); background: var(--accent-soft); border-color: transparent; font-weight: 650; }
.tpl-name { font-size: 12.5px; font-weight: 550; line-height: 1.25; text-align: center; color: var(--muted); }
.tpl input:checked ~ .tpl-name { color: var(--accent); font-weight: 650; }
.tpl-check {
  position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; opacity: 0; transform: scale(0.5); transition: opacity 0.2s, transform 0.3s var(--spring);
}
.tpl-check .i { width: 13px; height: 13px; stroke-width: 3; }
.tpl input:checked ~ .tpl-check { opacity: 1; transform: none; }
.gal-empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

.menu {
  position: fixed; z-index: 50; min-width: 200px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  padding: 6px; display: flex; flex-direction: column; animation: pop-up 0.2s var(--spring); transform-origin: top left;
}
.menu button { text-align: left; padding: 9px 12px; border-radius: 9px; font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.menu button .i { width: 18px; height: 18px; color: var(--muted); }
.menu button:hover { background: var(--surface-2); }
.menu .danger, .menu .danger .i { color: var(--danger); }
.menu hr { border: 0; height: 1px; background: var(--border); margin: 5px 6px; }
.toast {
  position: fixed; left: 50%; bottom: 128px; transform: translateX(-50%); z-index: 60; background: #141c2e;
  color: #fff; padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 550;
  max-width: calc(100vw - 32px); animation: toast-in 0.35s var(--spring);
}
.toast { bottom: 28px; }
body.in-editor .toast { bottom: 128px; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px) scale(0.95); } }

/* ================================================================ responsive */
@media (max-width: 1180px) {
  .back-btn span { display: none; }
  .back-btn { padding: 0; }
  .nb-title { width: 200px; }
}
@media (max-width: 980px) {
  .ed-center { display: none; }
  .insert-compact { display: inline-flex; }
  .zoom { display: none; }
  .palette { gap: 0; padding: 0 6px; }
  .ptool { width: 42px; }
  .palette { --art-w: 46px; }
  .ptool-num { top: 62px; }
  .palette { padding: 0 10px; }
}
@media (max-width: 760px) {
  .pal-colors { display: flex; align-items: center; gap: 8px; }
  .pal-colors .swatch:not(.active) { display: none; }
  .pal-colors .swatches:not(:has(.active)) .swatch:first-child { display: block; }
}
@media (max-width: 900px) {
  /* Narrow screens: one column, and the whole body scrolls as one (no scroller inside a scroller). */
  .nb-sheet[open] { height: auto; }
  .nb-sheet-body { display: block; overflow-y: auto; padding-bottom: 18px; }
  .nb-setup { display: grid; grid-template-columns: 130px 1fr; gap: 10px 18px; align-items: start; overflow: visible; margin-bottom: 18px; }
  .nb-setup .cover-picker { overflow: visible; padding: 6px 0 8px; }
  .nb-setup { grid-template-columns: 110px 1fr; align-items: center; }
  .cover-preview { width: 110px; }
  .nb-setup > .field:last-child { grid-column: 1 / -1; }
  .cover-picker { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  .nb-gallery-wrap .gal-grid { overflow: visible; min-height: 0; }
}
@media (max-width: 700px) {
  .lib-top { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  .lib-actions { width: 100%; }
  .search { flex: 1 1 100%; order: 5; }
  .search input { width: 100%; }
  .lib-actions .select { flex: 1; }
  #new-notebook span { display: none; }
  #new-notebook { padding: 10px 12px; }
  .notebook-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 28px 18px; }
  .title-stack { flex: 1; min-width: 0; }
  .nb-title { width: 100%; max-width: none; font-size: 16px; }
  .ed-top { gap: 2px; padding-left: 6px; padding-right: 6px; }
  .ed-right { flex: none; }
  .ed-right #page-template { display: none; }
  .dialog { max-height: 94vh; border-radius: 22px; }
  .sheet-head { padding: 14px 14px 6px 18px; }
  .nb-sheet-body, .tpl-sheet .gallery { padding-left: 16px; padding-right: 16px; }
  .cover-picker.large { grid-template-columns: repeat(2, 1fr); }
  .gal-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px 12px; }
  [data-dock=bottom] .tool-options { left: 12px !important; right: 12px; width: auto; }
}
@media (pointer: coarse) {
  .icon-btn { min-width: 42px; height: 42px; }
  .thumb-more, .nb-more { min-width: 36px; height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ================================================================ print / PDF */
@media print {
  @page { size: 816px 1056px; margin: 0; }
  body { background: #fff; }
  #library, .ed-top, .palette, .popover, .ruler, .format-bar, .sidebar, .page-label, .item-bar, .resize-handle, .sel-menu, .toast, .menu { display: none !important; }
  #editor, .ed-body, .scroller { display: block !important; overflow: visible !important; height: auto !important; background: none !important; }
  .pages { padding: 0; gap: 0; display: block; width: auto; }
  .page-wrap { width: 816px !important; height: 1056px !important; break-after: page; animation: none; }
  .page { transform: none !important; box-shadow: none; border-radius: 0; }
  .item { box-shadow: none !important; }
}

/* ================================================================ landing (signed out) */
.landing { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
body:has(dialog[open]) .landing { overflow: hidden; }
.landing .ghost { display: inline-flex; align-items: center; gap: 7px; justify-content: center; }
.big { padding: 13px 22px; font-size: 15.5px; }
.big .i { width: 18px; height: 18px; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.link:hover { text-decoration-color: currentColor; }

.land-nav {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(16px, 4vw, 48px); padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid transparent; transition: border-color 0.2s;
}
.land-nav.scrolled { border-bottom-color: var(--border); }
.land-links { display: flex; gap: 4px; }
.land-links button { padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 550; color: var(--muted); transition: color 0.15s, background 0.15s; }
.land-links button:hover { color: var(--text); background: var(--surface-2); }
.land-nav-actions { display: flex; align-items: center; gap: 8px; }

.land-hero {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: clamp(24px, 4vw, 64px); align-items: center;
  max-width: 1140px; margin: 0 auto; padding: clamp(28px, 6vw, 72px) clamp(16px, 4vw, 48px) clamp(40px, 6vw, 80px);
}
.hero-copy { animation: rise 0.7s var(--ease) both; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 13px 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.pill-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); animation: ping 2.2s infinite; }
@keyframes ping { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.land-hero h1 { margin: 18px 0 16px; font-size: clamp(40px, 6vw, 72px); line-height: 1.02; font-weight: 560; letter-spacing: -0.025em; }
.land-hero h1 em { font-style: italic; font-weight: 450; color: var(--accent); }
.hero-lede { margin: 0; max-width: 520px; font-size: clamp(16px, 1.6vw, 18.5px); line-height: 1.55; color: var(--muted); }
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.hero-fine { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 16px 0 0; font-size: 13.5px; color: var(--muted); }
.hero-fine .i { width: 15px; height: 15px; color: var(--ok); stroke-width: 2.4; }
.hero-fine > span { opacity: 0.5; margin: 0 2px; }

.hero-art { position: relative; aspect-ratio: 1400 / 1080; animation: rise 0.9s 0.1s var(--ease) both; }
.device { position: absolute; background: #1b1917; box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.06); }
.device img { display: block; width: 100%; height: auto; }
.device.tablet { left: 0; right: 0; top: 4%; padding: 2.1%; border-radius: clamp(16px, 2.4vw, 30px); transform: rotate(-1.5deg); }
.device.tablet img { border-radius: clamp(8px, 1.2vw, 14px); }
.device.phone { width: 26%; right: -2%; bottom: -6%; padding: 1.2%; border-radius: clamp(14px, 2vw, 28px); transform: rotate(4deg); }
.device.phone img { border-radius: clamp(10px, 1.5vw, 22px); }
.float-cover { position: absolute; width: 22%; filter: drop-shadow(0 18px 24px rgba(20, 30, 60, 0.28)); z-index: 1; }
.fc-1 { left: -9%; bottom: -4%; transform: rotate(-12deg); animation: bob 7s ease-in-out infinite; }
.fc-2 { right: 6%; top: -9%; width: 15%; transform: rotate(10deg); animation: bob 8s 1s ease-in-out infinite reverse; z-index: 0; }
@keyframes bob { 50% { translate: 0 -10px; } }

.land-section { max-width: 1140px; margin: 0 auto; padding: clamp(48px, 7vw, 96px) clamp(16px, 4vw, 48px); }
.land-h2 { margin: 0 0 14px; font-size: clamp(30px, 4.2vw, 48px); line-height: 1.06; font-weight: 560; letter-spacing: -0.02em; }
.land-sub { margin: 0; color: var(--muted); font-size: 16.5px; line-height: 1.55; max-width: 560px; }
.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 36px; }
.feature {
  padding: 22px 22px 20px; border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
  transition: transform 0.3s var(--spring), box-shadow 0.3s var(--ease);
}
.feature:hover { transform: translateY(-3px); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.feature h3 { margin: 14px 0 6px; font-size: 16.5px; font-weight: 650; letter-spacing: -0.01em; }
.feature p { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.5; }
.f-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.f-icon .i { width: 22px; height: 22px; }
.showcase { margin: 40px 0 0; border-radius: var(--r-xl); overflow: hidden; box-shadow: var(--shadow-lg), 0 0 0 1px var(--border); }
.showcase img { display: block; width: 100%; height: auto; }

.install-section { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: clamp(24px, 4vw, 56px); align-items: start; }
.install-card { padding: 22px; border-radius: var(--r-xl); background: var(--surface); box-shadow: var(--shadow), 0 0 0 1px var(--border); }

.pricing { display: flex; justify-content: center; }
.price-card {
  width: min(520px, 100%); text-align: center; padding: clamp(28px, 4vw, 44px); border-radius: var(--r-xl);
  background: radial-gradient(120% 80% at 50% 0%, var(--accent-soft), var(--surface) 70%); box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
}
.price { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 6px 0 22px; }
.price .amount { font-size: 64px; font-weight: 600; line-height: 1; letter-spacing: -0.03em; }
.price .per { color: var(--muted); font-weight: 550; }
.price-list { list-style: none; padding: 0; margin: 0 auto 26px; display: grid; gap: 10px; text-align: left; width: fit-content; }
.price-list li { display: flex; gap: 10px; align-items: center; font-size: 15px; }
.price-list .i { width: 18px; height: 18px; color: var(--ok); stroke-width: 2.4; }
.price-card .hero-fine { justify-content: center; }

.land-foot {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: center; color: var(--muted); font-size: 13.5px;
  max-width: 1140px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 48px) max(28px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border);
}
.land-foot .brand { gap: 8px; font-family: var(--font-display); font-weight: 650; color: var(--text); font-size: 16px; }

@media (max-width: 900px) {
  .land-hero, .install-section { grid-template-columns: 1fr; }
  .hero-art { margin: 10px 4% 20px 8%; }
  .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .land-links { display: none; }
}
@media (max-width: 560px) {
  .feature-grid { grid-template-columns: 1fr; }
  .land-nav .ghost[data-auth] { display: none; }
  .hero-cta > * { flex: 1 1 100%; }
  .land-nav-cta { padding: 9px 15px; }
}

/* ================================================================ install guide */
.ig { display: flex; flex-direction: column; gap: 18px; }
.ig-tabs { align-self: stretch; }
.ig-pane { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 20px; align-items: start; }
.ig-pane:not([data-platform="ios"]) { grid-template-columns: 1fr; }
.ig-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; counter-reset: step; }
.ig-steps li { position: relative; padding-left: 42px; counter-increment: step; }
.ig-steps li::before {
  content: counter(step); position: absolute; left: 0; top: -2px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13.5px;
}
.ig-steps b { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 650; font-size: 15px; }
.ig-steps p b { display: inline; }
.ig-steps p { margin: 3px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.key {
  display: inline-grid; place-items: center; width: 28px; height: 26px; border-radius: 7px; vertical-align: middle;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border-strong), 0 1px 0 var(--border-strong); color: #2f7cf6;
}
.key .i { width: 16px; height: 16px; stroke-width: 2; }
.ig-native { align-self: flex-start; }
.ig-done { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ok); font-weight: 600; }
.ig-done .i { stroke-width: 2.4; }

/* A small mock of Safari's share sheet, with "Add to Home Screen" highlighted. */
.ig-mock { border-radius: 18px; background: var(--surface-2); padding: 10px; box-shadow: inset 0 0 0 1px var(--border); font-size: 12.5px; user-select: none; }
.mock-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.mock-url { flex: 1; padding: 6px 10px; border-radius: 9px; background: var(--surface); color: var(--muted); text-align: center; font-weight: 550; }
.mock-share { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; color: #2f7cf6; background: var(--surface); animation: pulse 1.8s infinite; }
.mock-share .i { width: 17px; height: 17px; stroke-width: 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47, 124, 246, 0.45); } 70%, 100% { box-shadow: 0 0 0 8px rgba(47, 124, 246, 0); } }
.mock-sheet { border-radius: 12px; background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm); }
.mock-app { display: flex; gap: 8px; align-items: center; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.mock-app img { width: 28px; height: 28px; border-radius: 7px; }
.mock-app div { display: flex; flex-direction: column; line-height: 1.2; }
.mock-app span { color: var(--muted); font-size: 11px; }
.mock-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.mock-row:last-child { border-bottom: 0; }
.mock-row .i { width: 15px; height: 15px; color: var(--muted); }
.mock-row.hl { background: color-mix(in srgb, #2f7cf6 13%, transparent); color: #2f7cf6; font-weight: 650; }
.mock-row.hl .i { color: #2f7cf6; }

.install-sheet { width: min(640px, calc(100vw - 24px)); }
.install-body { padding: 4px 26px 24px; overflow-y: auto; }
@media (max-width: 560px) {
  .ig-pane { grid-template-columns: 1fr; }
  .ig-mock { max-width: 260px; }
  .ig-tabs span { padding: 7px 6px; font-size: 12.5px; }
}

/* Floating hint on iPad/iPhone Safari pointing at the Share button. */
.ios-hint {
  position: fixed; z-index: 40; display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 12px; border-radius: 18px;
  background: var(--glass); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border); font-size: 13.5px; max-width: calc(100vw - 24px); animation: pop-up 0.4s var(--spring);
}
.ios-hint img { border-radius: 10px; flex: none; }
.ios-hint > div { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.ios-hint > div > span { color: var(--muted); display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.ios-hint > div .i { width: 15px; height: 15px; color: #2f7cf6; stroke-width: 2; }
.ios-hint [data-more] { font-size: 13px; font-weight: 650; color: var(--accent); padding: 0 8px; }
.ios-hint [data-dismiss] { min-width: 30px; height: 30px; color: var(--muted); }
.ios-hint [data-dismiss] .i { width: 16px; height: 16px; }
.ios-hint::after { content: ""; position: absolute; width: 14px; height: 14px; background: inherit; transform: rotate(45deg); box-shadow: 0 0 0 1px var(--border); clip-path: polygon(0 0, 100% 0, 0 100%); }
/* iPad: the Share button is at the top right of Safari. */
.ios-hint.top { top: max(12px, env(safe-area-inset-top)); right: 16px; }
.ios-hint.top::after { top: -7px; right: 34px; }
/* iPhone: it's in the bottom toolbar. */
.ios-hint.bottom { bottom: max(14px, env(safe-area-inset-bottom)); left: 12px; right: 12px; margin: 0 auto; width: fit-content; }
.ios-hint.bottom::after { bottom: -7px; left: calc(50% - 7px); transform: rotate(225deg); }

/* ================================================================ sign in */
.auth-sheet { width: min(440px, calc(100vw - 24px)); }
.auth-sheet .sheet-head { padding-bottom: 0; }
.auth-body { display: flex; flex-direction: column; gap: 14px; padding: 6px 26px 26px; overflow-y: auto; }
.auth-sub { margin: 0; color: var(--muted); font-size: 14.5px; }
.auth-sub:empty { display: none; }
.google-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px; border-radius: 999px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--border-strong), var(--shadow-xs); font-weight: 600; transition: background 0.15s, transform 0.15s var(--spring);
}
.google-btn:hover { background: var(--surface-2); }
.apple-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px; margin-bottom: 10px; border-radius: 999px;
  background: #000; color: #fff; font-weight: 600; transition: transform 0.15s var(--spring);
}
.apple-btn:active { transform: scale(0.98); }
.apple-btn .i { width: 19px; height: 19px; }
.apple-btn[aria-busy="true"] { opacity: 0.7; pointer-events: none; }
:root[data-theme="dark"] .apple-btn { background: #fff; color: #000; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .apple-btn { background: #fff; color: #000; } }
.ob-auth-card .apple-btn { min-height: 50px; font-size: 16px; margin-bottom: 0; display: inline-flex; }
.google-btn:active { transform: scale(0.98); }
.google-btn .i { width: 19px; height: 19px; }
.or { display: flex; align-items: center; gap: 12px; margin: 14px 0; color: var(--faint); font-size: 12.5px; font-weight: 600; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-sheet .field input {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-size: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.auth-sheet .field input:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: var(--focus); }
.auth-sheet .forgot { align-self: flex-end; margin-top: -6px; font-size: 13px; }
.auth-sheet .back { align-self: center; }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-submit[aria-busy="true"] { opacity: 0.7; pointer-events: none; }
.auth-error { margin: 0; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; font-weight: 550; color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.auth-fine { display: flex; gap: 8px; align-items: flex-start; margin: 0; color: var(--muted); font-size: 12.5px; }
.auth-fine .i { width: 15px; height: 15px; margin-top: 1px; }
.auth-done { align-items: center; text-align: center; padding-top: 10px; }
.auth-done h3 { margin: 0; font-size: 24px; font-weight: 580; }
.auth-done p { margin: 0; color: var(--muted); }
.sent-icon { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.sent-icon .i { width: 28px; height: 28px; }

/* Account button in the library header. */
.avatar-btn {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; overflow: hidden; flex: none;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 70%, #f5b971), var(--accent)); color: #fff; font-weight: 700; font-size: 14.5px;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--border-strong); transition: transform 0.2s var(--spring);
}
.avatar-btn:hover { transform: scale(1.05); }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }
.menu-head { padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: flex; flex-direction: column; min-width: 0; }
.menu-head b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-head span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================================================================ AI notes */
.ai-btn { display: inline-flex; align-items: center; gap: 6px; width: auto !important; padding: 0 12px 0 10px !important; font: 650 13px/1 var(--font-ui); color: #fff !important;
  background: linear-gradient(120deg, #ff5a5f, #ff9f1c 35%, #8338ec 70%, #3a86ff) !important; border-radius: 99px !important; box-shadow: 0 4px 14px -6px rgba(131, 56, 236, 0.7); }
.ai-btn:hover { filter: brightness(1.06) saturate(1.1); }
.ai-btn .i { stroke: #fff; }
@media (max-width: 1100px) { .ai-btn span { display: none; } .ai-btn { padding: 0 !important; width: 36px !important; justify-content: center; } }
.ai-sheet { width: min(520px, calc(100vw - 24px)); }
.ai-sheet .sheet-head { padding-bottom: 0; }
.ai-body { display: flex; flex-direction: column; gap: 16px; padding: 8px 26px 20px; overflow-y: auto; }
.ai-mode { margin-bottom: 2px; }
.ai-sub[hidden], .ai-body [data-mode][hidden] { display: none; }
.ai-sub { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.45; }
.ai-sheet .field i { text-transform: none; letter-spacing: 0; font-weight: 500; font-style: normal; opacity: 0.8; }
.ai-sheet .field :is(input, textarea) {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font: inherit; font-size: 16px; resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s; color: var(--text);
}
.ai-sheet .field :is(input, textarea):focus { outline: none; border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: var(--focus); }
.ai-ideas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -6px; }
.ai-ideas button { padding: 6px 11px; border-radius: 99px; background: var(--surface-2); font-size: 12.5px; font-weight: 600; color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }
.ai-ideas button:hover { color: var(--text); background: var(--surface-3); }
.ai-sheet .segmented span { padding: 8px 6px; }
.ai-styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ai-styles input { position: absolute; opacity: 0; pointer-events: none; }
.ai-styles span { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 9px; border-radius: 12px; cursor: pointer;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); font-size: 12.5px; font-weight: 650; color: var(--muted); transition: box-shadow 0.15s, color 0.15s; }
.ai-styles b { font: 400 19px/1 "Permanent Marker", var(--font-ui); color: #1a1a1a; padding: 2px 6px; border-radius: 4px; }
.ai-styles input:checked + span { box-shadow: inset 0 0 0 2px var(--accent); color: var(--text); }
.ai-styles input:focus-visible + span { box-shadow: inset 0 0 0 2px var(--accent), var(--focus); }
.ai-fill { align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.ai-fill input { margin-top: 2px; flex: none; }
.ai-fill small { display: block; margin-top: 2px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.ai-working { align-items: center; text-align: center; padding: 18px 30px 24px; gap: 10px; }
.ai-preview-wrap { position: relative; display: grid; place-items: center; }
.ai-preview { width: min(300px, 62vw); aspect-ratio: 816 / 1056; background: #fff; border-radius: 6px; overflow: hidden;
  box-shadow: 0 0 0 1px var(--border), var(--shadow); animation: fade 0.3s; }
.ai-preview { background-size: 100% 100%; }
.ai-preview svg { display: block; width: 100%; height: 100%; }
.ai-preview:not([hidden]) + .ai-pencil { position: absolute; right: -14px; bottom: -14px; width: 44px; height: 44px; }
.ai-preview:not([hidden]) + .ai-pencil .i { width: 22px; height: 22px; }
.ai-working h3 { margin: 6px 0 0; font-size: 22px; }
.ai-working p { margin: 0; color: var(--muted); font-size: 14.5px; max-width: 34ch; }
.ai-pencil { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(from 0deg, #ff5a5f, #ffd23f, #2ec4b6, #3a86ff, #8338ec, #ff5a5f); animation: ai-spin 2.4s linear infinite; }
.ai-pencil .i { width: 34px; height: 34px; stroke: #fff; stroke-width: 2; animation: ai-spin 2.4s linear infinite reverse; }
@keyframes ai-spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .ai-pencil, .ai-pencil .i { animation: none; } }
.ai-sheet.busy #ai-go { opacity: 0.5; pointer-events: none; }
/* A full-page AI drawing sits behind ink and typed items and never catches the pointer. */
.item-ai { pointer-events: none; }
.item-ai img { border-radius: 0; }

/* Planner dates row in the template gallery */
.gal-dates { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px; border-radius: 12px; background: var(--accent-soft); animation: fade 0.25s both; }
.gal-dates[hidden] { display: none; }
.gal-dates .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.gal-dates .seg { display: flex; gap: 4px; flex-wrap: wrap; }
.gal-dates .seg > * {
  font-size: 12.5px; font-weight: 600; padding: 6px 11px; border-radius: 99px; background: var(--surface); color: var(--muted);
  box-shadow: 0 0 0 1px var(--border); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.gal-dates .seg > *:hover { color: var(--text); }
.gal-dates .seg > .active { background: var(--accent); color: #fff; box-shadow: none; }
.gal-dates .seg-pick .i { width: 15px; height: 15px; }
.gal-dates .seg-pick input { border: 0; background: transparent; color: inherit; font: inherit; padding: 0; width: 118px; }
.gal-dates .seg-pick.active input { color-scheme: dark; }
.gal-period { font-size: 12.5px; font-weight: 600; color: var(--accent); }
body.pinching #pages { will-change: transform; }

/* Shown over the editor while a notebook opens: a placeholder page until the first pages are drawn. */
.editor-loading {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 32px 16px; overflow: hidden; font-size: 14px; font-weight: 600; color: var(--muted);
  background-color: var(--desk); background-image: radial-gradient(var(--desk-dot) 1px, transparent 1.2px); background-size: 22px 22px;
}
.editor-loading[hidden] { display: none; }
.ed-skel-page {
  width: min(816px, 100%); aspect-ratio: 816 / 1056; max-height: calc(100% - 64px); flex: none;
  display: flex; flex-direction: column; gap: 22px; padding: 9% 8%; border-radius: 3px;
  background: var(--surface, #fff); box-shadow: var(--page-shadow); animation: fade 0.25s var(--ease) both;
}
.ed-skel-line, .nb-skel-line, .nb-skel-cover { position: relative; overflow: hidden; background: var(--skel); }
.ed-skel-line { display: block; height: 12px; border-radius: 6px; width: 100%; }
.ed-skel-line.w85 { width: 85%; } .ed-skel-line.w70 { width: 70%; } .ed-skel-line.w60 { width: 60%; } .ed-skel-line.w40 { width: 40%; }
.ed-skel-line::after, .nb-skel-line::after, .nb-skel-cover::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--skel-shine), transparent); animation: shimmer 1.3s ease-in-out infinite;
}
.ed-skel-status { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-radius: 999px; background: var(--surface, #fff); box-shadow: 0 4px 18px rgba(20, 30, 60, 0.12); animation: fade 0.2s 0.3s both; }
.ed-skel-status .spinner { width: 18px; height: 18px; border-width: 2px; }
@keyframes shimmer { to { transform: translateX(100%); } }

/* Library: placeholder cards on the very first load; later renders skip the entrance animation. */
.nb-skel { pointer-events: none; }
.nb-skel-cover { width: 100%; border-radius: 6px; }
.nb-skel-line { height: 12px; border-radius: 6px; width: 75%; }
.nb-skel-line.short { width: 45%; margin-top: -4px; }
.notebook-grid.no-anim .nb-card, .pages.no-anim .page-wrap { animation: none; }
@media (prefers-reduced-motion: reduce) { .ed-skel-line::after, .nb-skel-line::after, .nb-skel-cover::after { animation: none; } }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- plans & billing */
.plan-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; text-align: left; }
.plan-card {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 18px 18px 16px; border-radius: var(--r-lg, 16px);
  background: var(--surface); box-shadow: 0 0 0 1px var(--border);
}
.plan-card.featured { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent), var(--shadow); }
.plan-card h3 { margin: 0; font-size: 15px; font-weight: 650; }
.plan-price { display: flex; align-items: baseline; gap: 6px; }
.plan-price b { font-size: 36px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; }
.plan-price span { color: var(--muted); font-weight: 550; font-size: 14px; }
.plan-card ul { list-style: none; padding: 0; margin: 0 0 4px; display: grid; gap: 7px; flex: 1; }
.plan-card li { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; line-height: 1.35; }
.plan-card li .i { width: 16px; height: 16px; color: var(--ok); stroke-width: 2.4; margin-top: 1px; }
.plan-card.current { box-shadow: 0 0 0 2px var(--ok); }
.plan-current { align-self: flex-start; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ok); }
.billing-sheet { width: min(640px, 96vw); }
.billing-body { display: flex; flex-direction: column; gap: 16px; padding: 4px 26px 24px; overflow: auto; overscroll-behavior: contain; }
.billing-status { margin: 0; font-size: 15px; line-height: 1.45; }
.billing-status b { font-weight: 650; }
.billing-fine { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.app-only { display: none !important; }
.app-only-inline { display: none; }
html.native-app .app-only-inline { display: inline; }
html.native-app .web-only { display: none; }
.app-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
html.native-app #app-pro:not([hidden]) { display: flex !important; }
#app-plans { flex: 1 1 100%; padding-block: 13px; font-size: 16px; }
#billing-manage { align-self: flex-start; }
.danger-zone summary { margin: 0; font-size: 15px; font-weight: 650; }
.danger-zone input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit;
}
.danger-zone input:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: var(--focus); }
.danger-zone { padding-top: 14px; border-top: 1px solid var(--border); }
.danger-zone summary { cursor: pointer; color: var(--danger); }
.danger-zone p { color: var(--muted); font-size: 14px; line-height: 1.45; }
.danger-zone .field { margin-bottom: 12px; }
.danger-btn { padding: 10px 18px; border-radius: 999px; background: var(--danger); color: #fff; font-weight: 600; }
.danger-btn:disabled { opacity: 0.45; cursor: not-allowed; }
@media (max-width: 560px) {
  .plan-grid { grid-template-columns: 1fr; }
  .billing-body { padding: 4px 18px 20px; }
}

/* Inside the iPhone/iPad app (mobile/ adds .native-app before the page loads): the app is
   already installed, so hide the "Add to Home Screen" install guides, hints and buttons, and
   the web pricing section. Browsers never get this class, so the web app is unchanged. */
html.native-app [data-install],
html.native-app [data-scroll="install"],
html.native-app [data-scroll="pricing"],
html.native-app #install,
html.native-app #pricing,
html.native-app #ios-hint,
html.native-app .buy-only { display: none !important; }
html.native-app .app-only:not([hidden]) { display: flex !important; }

/* ================================================================ sheets above the keyboard */
.keyboard-open .dialog[open] {
  position: fixed; top: calc(var(--vv-top, 0px) + env(safe-area-inset-top) + 6px); bottom: auto; margin: 0 auto;
  max-height: calc(var(--vv-h, 100vh) - env(safe-area-inset-top) - 12px);
}
.keyboard-open .dialog[open] { animation: none; }
.auth-sheet form { min-height: 0; }
/* See keepSheetVisible in welcome.js. */
.dialog.sheet-fallback { height: min(720px, 92vh); }
.dialog.sheet-fallback > * { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.auth-body { min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.auth-submit[aria-busy="true"], .google-btn[aria-busy="true"] { opacity: 0.7; pointer-events: none; }
.auth-fine > span { display: block; }
@media (pointer: coarse) { .dialog .icon-btn:focus-visible { box-shadow: none; } }
.auth-sheet .field input { width: 100%; -webkit-appearance: none; appearance: none; color: var(--text); }

/* ================================================================ app: welcome slides */
.ob {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; overflow: hidden; color: var(--text);
  background: radial-gradient(120% 70% at 50% 0%, var(--ob-tint, var(--accent-soft)), transparent 75%), var(--bg);
  transition: background 0.5s;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ob { background: radial-gradient(120% 70% at 50% 0%, color-mix(in srgb, var(--ob-tint, #333) 22%, transparent), transparent 75%), var(--bg); }
}
.ob-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; min-height: 52px; flex: none; }
.ob-brand { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-weight: 650; font-size: 18px; }
.ob-brand img { border-radius: 8px; }
.ob-skip { padding: 8px 12px; font-weight: 600; font-size: 15px; color: var(--muted); border-radius: 999px; }
.ob-track { flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.ob-track::-webkit-scrollbar { display: none; }
.ob-slide { flex: 0 0 100%; width: 100%; min-width: 0; scroll-snap-align: center; scroll-snap-stop: always; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(14px, 3.5vh, 36px); padding: 0 24px; }
.ob-art { position: relative; flex: 1; min-height: 0; width: 100%; max-width: 460px; max-height: 440px; display: flex; align-items: center; justify-content: center; }
.ob-copy { flex: none; text-align: center; max-width: 480px; padding-bottom: 4px; }
.ob-copy h2, .ob-auth-card h2 { margin: 0 0 10px; font-size: clamp(29px, 7.6vw, 42px); line-height: 1.08; font-weight: 560; letter-spacing: -0.01em; }
.ob-copy em, .ob-auth-card em { font-style: italic; font-weight: 480; color: var(--accent); }
.ob-copy p, .ob-auth-card p { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.45; }
.ob-copy > * { opacity: 0; transform: translateY(14px); transition: opacity 0.5s var(--ease), transform 0.5s var(--ease); }
.ob-slide.on .ob-copy > * { opacity: 1; transform: none; }
.ob-slide.on .ob-copy > p { transition-delay: 0.08s; }
.ob-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px 18px; width: 100%; max-width: 560px; margin: 0 auto; }
.ob-dots { display: flex; gap: 7px; }
.ob-dots span { width: 7px; height: 7px; border-radius: 99px; background: var(--border-strong); transition: width 0.3s var(--ease), background 0.3s; }
.ob-dots span.on { width: 22px; background: var(--accent); }
#ob-next { display: inline-flex; align-items: center; gap: 8px; min-width: 132px; justify-content: center; }
.ob.at-auth .ob-foot, .ob.at-auth .ob-skip { visibility: hidden; }
.ob.at-auth .ob-foot { height: 0; padding: 0; }
.ob.auth-only .ob-slide:not(.ob-auth) { display: none; }
.ob.auth-only .ob-track { overflow: hidden; }

.ob-paper { position: relative; background: #ffffff; color: #141c2e; border-radius: 14px; box-shadow: 0 1px 2px rgba(20, 40, 90, 0.08), 0 18px 44px rgba(20, 40, 90, 0.18); background-size: cover; background-position: top left; }

/* covers */
.ob-art-covers img { position: absolute; height: min(100%, 300px); width: auto; filter: drop-shadow(0 18px 24px rgba(20, 40, 90, 0.28)); transition: transform 0.9s var(--spring), opacity 0.5s; opacity: 0; }
.ob-art-covers img:nth-child(1) { transform: translateX(-10%) rotate(-4deg) scale(0.86); }
.ob-art-covers img:nth-child(2) { transform: translateX(10%) rotate(4deg) scale(0.86); }
.ob-art-covers img:nth-child(3) { transform: translateY(10px) scale(0.9); }
.ob-slide.on .ob-art-covers img { opacity: 1; }
.ob-slide.on .ob-art-covers img:nth-child(1) { transform: translateX(-30%) rotate(-11deg) scale(0.86); }
.ob-slide.on .ob-art-covers img:nth-child(2) { transform: translateX(30%) rotate(11deg) scale(0.86); }
.ob-slide.on .ob-art-covers img:nth-child(3) { transform: none; }

/* pens */
.ob-art-pens { flex-direction: column; gap: 0; justify-content: flex-end; }
.ob-ink { width: min(86%, 340px); padding: 10px 14px 34px; }
.ob-ink svg { display: block; width: 100%; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.ob-ink .w1 { stroke: #2456d6; stroke-width: 3.4; stroke-dasharray: 560; stroke-dashoffset: 560; }
.ob-ink .w2 { stroke: #d93a2f; stroke-width: 3; stroke-dasharray: 260; stroke-dashoffset: 260; }
.ob-ink .hl { stroke: #fde047; stroke-width: 22; opacity: 0.75; stroke-dasharray: 150; stroke-dashoffset: 150; }
.ob-slide.on .ob-ink .hl { animation: ob-draw 0.7s 0.2s var(--ease) forwards; }
.ob-slide.on .ob-ink .w1 { animation: ob-draw 1.5s 0.35s ease-out forwards; }
.ob-slide.on .ob-ink .w2 { animation: ob-draw 0.8s 1.5s ease-out forwards; }
@keyframes ob-draw { to { stroke-dashoffset: 0; } }
.ob-tray { position: relative; display: flex; justify-content: center; gap: 0; margin-top: -30px; height: clamp(120px, 24vh, 190px); overflow: hidden; }
.ob-tray img { height: 100%; width: auto; transform: translateY(70%); transition: transform 0.7s var(--spring); margin: 0 -3px; }
.ob-slide.on .ob-tray img { transform: translateY(12%); }
.ob-slide.on .ob-tray img:nth-child(2) { transition-delay: 0.05s; transform: translateY(26%); }
.ob-slide.on .ob-tray img:nth-child(3) { transition-delay: 0.1s; transform: translateY(16%); }
.ob-slide.on .ob-tray img:nth-child(4) { transition-delay: 0.15s; transform: translateY(30%); }
.ob-slide.on .ob-tray img:nth-child(5) { transition-delay: 0.2s; transform: translateY(18%); }
.ob-slide.on .ob-tray img:nth-child(6) { transition-delay: 0.25s; transform: translateY(28%); }
.ob-slide.on .ob-tray img:nth-child(7) { transition-delay: 0.3s; transform: translateY(20%); }

/* templates */
.ob-page { position: absolute; height: min(82%, 300px); aspect-ratio: 816 / 1056; background-color: #fff; background-size: cover; border-radius: 7px; box-shadow: 0 1px 2px rgba(20, 40, 90, 0.1), 0 12px 28px rgba(20, 40, 90, 0.2); transition: transform 0.8s var(--spring); }
.ob-page:nth-child(1) { z-index: 1; }
.ob-page:nth-child(2) { z-index: 2; }
.ob-page:nth-child(3) { z-index: 5; }
.ob-page:nth-child(4) { z-index: 4; }
.ob-page:nth-child(5) { z-index: 3; }
.ob-slide.on .ob-page:nth-child(1) { transform: translateX(-74%) rotate(-12deg) scale(0.8); }
.ob-slide.on .ob-page:nth-child(2) { transform: translateX(-38%) rotate(-6deg) scale(0.9); }
.ob-slide.on .ob-page:nth-child(4) { transform: translateX(38%) rotate(6deg) scale(0.9); }
.ob-slide.on .ob-page:nth-child(5) { transform: translateX(74%) rotate(12deg) scale(0.8); }

/* AI notes */
.ob-sketch { width: min(86%, 330px); padding: 20px 20px 18px; text-align: center; transform: rotate(-1.5deg) scale(0.94); transition: transform 0.7s var(--spring); }
.ob-slide.on .ob-sketch { transform: rotate(-1.5deg); }
.ob-sketch b { display: inline-block; font-family: "Permanent Marker", cursive; font-weight: 400; font-size: clamp(24px, 6.4vw, 30px); background: linear-gradient(transparent 58%, #ffd23f 58% 92%, transparent 92%); padding: 0 6px; }
.ob-sketch i { display: block; margin-top: 2px; font-family: "Caveat", cursive; font-style: normal; font-size: 23px; font-weight: 700; color: #1e3a8a; }
.ob-sketch svg { display: block; width: 100%; margin-top: 8px; fill: none; stroke: #141c2e; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.ob-sketch .dr { stroke-dasharray: 340; stroke-dashoffset: 340; }
.ob-sketch .blue { stroke: #2456d6; }
.ob-sketch .red { stroke: #d93a2f; }
.ob-slide.on .ob-sketch .dr { animation: ob-draw 1.5s 0.25s ease-out forwards; }
.ob-spark { position: absolute; top: -18px; right: -14px; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: #fff; box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 45%, transparent); }
.ob-sketch .ob-spark svg { width: 24px; height: 24px; margin: 0; stroke: #fff; stroke-width: 1.75; }
.ob-slide.on .ob-spark { animation: ob-pop 0.7s 0.3s var(--spring) both; }
@keyframes ob-pop { from { transform: scale(0) rotate(-40deg); } }

/* lasso, ruler, sticky */
.ob-markup { width: min(88%, 340px); height: min(92%, 300px); overflow: hidden; background-color: #fff; }
.ob-markup .lasso { position: absolute; left: 7%; top: 8%; width: 66%; fill: color-mix(in srgb, var(--accent) 10%, transparent); stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 5; }
.ob-word { position: absolute; left: 20%; top: 20%; font-family: "Caveat", cursive; font-size: 34px; font-weight: 700; color: #2456d6; }
.ob-slide.on .ob-word { animation: ob-float 3s ease-in-out infinite; }
@keyframes ob-float { 50% { transform: translate(5px, -4px); } }
.ob-sticky { position: absolute; right: 7%; top: 12%; padding: 10px 12px; background: #fef08a; font-family: "Patrick Hand", cursive; font-size: 19px; line-height: 1.15; color: #141c2e; border-radius: 3px 3px 12px 3px; transform: rotate(5deg); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2); }
.ob-ruler { position: absolute; left: -8%; right: -8%; bottom: 17%; height: 42px; background: rgba(240, 240, 235, 0.92); border-block: 1px solid rgba(0, 0, 0, 0.18); transform: rotate(-9deg); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.16); }
.ob-ruler i { position: absolute; inset: 0 0 auto; height: 14px; background: repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.45) 0 1px, transparent 1px 12px); }

/* share */
.ob-sharedoc { height: min(88%, 300px); aspect-ratio: 816 / 1056; padding: 24% 12% 0; background-color: #fff; display: flex; flex-direction: column; gap: 9%; transform: rotate(-3deg); }
.ob-scribble { display: block; height: 7px; width: 90%; border-radius: 9px; background: #2456d6; opacity: 0.75; }
.ob-scribble.s { width: 60%; background: #d93a2f; }
.ob-chip { position: absolute; display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; border-radius: 999px; font-weight: 650; font-size: 15px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); opacity: 0; transform: scale(0.8); transition: opacity 0.4s, transform 0.6s var(--spring); }
.ob-chip .i { width: 18px; height: 18px; color: var(--accent); }
.ob-chip.c1 { left: 4%; top: 14%; }
.ob-chip.c2 { right: 3%; top: 38%; }
.ob-chip.c3 { left: 6%; bottom: 12%; }
.ob-slide.on .ob-chip { opacity: 1; transform: none; }
.ob-slide.on .ob-chip.c2 { transition-delay: 0.12s; }
.ob-slide.on .ob-chip.c3 { transition-delay: 0.24s; }

/* sign in */
.ob-auth { justify-content: center; overflow-y: auto; }
.ob-auth-card { display: flex; flex-direction: column; align-items: stretch; gap: 12px; width: 100%; max-width: 400px; text-align: center; padding: 12px 0 24px; margin: auto 0; }
.ob-logo { align-self: center; border-radius: 19px; box-shadow: var(--shadow); margin-bottom: 8px; }
.ob-auth-card p { margin-bottom: 14px; }
.ob-auth-card .google-btn, .ob-auth-card .primary { min-height: 50px; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; }
.ob-auth-card .link { align-self: center; padding: 6px; }
.ob-guest { align-self: center; padding: 12px 22px; font-weight: 600; font-size: 15.5px; color: var(--muted); border-radius: 999px; }
.ob-guest:active { background: var(--surface-2); }
.ob-auth-card small { color: var(--faint); font-size: 12.5px; line-height: 1.4; }

/* Short screens (a phone on its side): art beside the words. */
@media (max-height: 520px) {
  .ob-slide:not(.ob-auth) { flex-direction: row; padding: 0 32px; gap: 28px; }
  .ob-slide:not(.ob-auth) .ob-art { height: 100%; flex: 1; }
  .ob-slide:not(.ob-auth) .ob-copy { flex: 1; text-align: left; }
  .ob-top { min-height: 40px; padding: 6px 20px; }
  .ob-foot { padding: 6px 24px 8px; }
  .ob-tray { height: 90px; }
}
@media (prefers-reduced-motion: reduce) {
  .ob *, .ob-slide.on * { animation-duration: 0.01ms !important; animation-delay: 0s !important; transition-duration: 0.01ms !important; transition-delay: 0s !important; }
}

/* ================================================================ guests */
.guest-banner { display: flex; align-items: center; gap: 12px; margin: 16px clamp(16px, 4vw, 48px) 0; padding: 12px 10px 12px 14px; border-radius: var(--r-lg); background: var(--accent-soft); color: var(--text); }
.guest-banner p { flex: 1; margin: 0; font-size: 14px; line-height: 1.35; }
.gb-icon { flex: none; color: var(--accent); display: grid; place-items: center; }
.guest-banner .primary { flex: none; padding: 8px 14px; }
.guest-banner .icon-btn { flex: none; }
.nudge-sheet { width: min(400px, calc(100vw - 24px)); }
.nudge-body { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 24px 18px; text-align: center; }
.nudge-body h2 { margin: 6px 0 0; font-size: 26px; font-weight: 580; }
.nudge-body p { margin: 0 0 10px; color: var(--muted); line-height: 1.45; }
.nudge-body .primary { width: 100%; }

/* ================================================================ share */
.share-sheet { width: min(480px, calc(100vw - 24px)); }
.share-head { min-width: 0; }
#share-name { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px; }
.share-body { display: flex; flex-direction: column; gap: 22px; padding: 8px 24px 24px; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.share-body section { display: flex; flex-direction: column; gap: 10px; }
.share-body h3 { margin: 0; font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.share-sheet form.share-row { display: flex; flex-direction: row; flex: none; gap: 8px; }
.share-sheet .sheet-head { padding-left: 24px; }
.share-row input { flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 16px; -webkit-appearance: none; appearance: none; }
.share-row input:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: var(--focus); }
.share-row .primary { flex: none; padding: 0 18px; }
.share-row .primary[aria-busy="true"] { opacity: 0.7; pointer-events: none; }
.share-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.share-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.share-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.share-who b { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-who small { color: var(--muted); font-size: 12.5px; }
.share-tell { flex: none; padding: 7px 11px; font-size: 13px; font-weight: 600; text-decoration: none; color: var(--text); border-radius: 999px; border: 1px solid var(--border-strong); }
.export-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.export-btn { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 16px 8px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.export-btn .i { width: 24px; height: 24px; color: var(--accent); margin-bottom: 3px; }
.export-btn b { font-size: 15px; font-weight: 650; }
.export-btn small { color: var(--muted); font-size: 12px; }
.export-btn:active { background: var(--surface-2); }
.export-btn:disabled { opacity: 0.55; }
.export-btn[aria-busy="true"] { opacity: 1; border-color: var(--accent); }

/* ================================================================ view-only notebooks */
.read-only :is(#palette, .ed-center, #insert-menu, #page-template, #add-page, #sidebar-add, .thumb-more) { display: none !important; }
.read-only .nb-title { pointer-events: none; }

/* ================================================================ shared with you */
.shared-section { padding: 26px 0 40px; }
.shared-section h2 { margin: 0 clamp(16px, 4vw, 48px) 2px; font-size: 24px; font-weight: 560; }

.menu { max-width: calc(100vw - 16px); }

/* ================================================================ screens fit their width */
/* Nothing on a screen slides or bounces sideways. Tilted covers and shadows can poke past the edge,
   which would otherwise make the whole screen scrollable. Sideways scrolling is left only where it's
   the point: the welcome slides, and a page zoomed in wider than the screen (neither bounces). */
html, body { overflow-x: hidden; overscroll-behavior-x: none; }
#library { overflow-x: hidden; overflow-y: auto; overscroll-behavior-x: none; touch-action: pan-y pinch-zoom; }
.ob-track, .scroller { overscroll-behavior-x: none; }
.ob-auth, .auth-body, .share-body, .nudge-body { overflow-x: hidden; touch-action: pan-y; }
.ob-auth { touch-action: pan-x pan-y; }

/* ================================================================ phone toolbar */
.kbd-done { display: none; }
/* Phones: a fixed toolbar that nothing inside can scroll. Every tool has its own slot in one
   full-width row, with the controls in a row below, and it stays at the bottom (no dragging). */
@media (max-width: 700px) {
  .palette[data-dock=bottom] {
    left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); transform: none; max-width: none; height: auto;
    display: grid; grid-template-columns: auto 1fr auto; gap: 0; padding: 0 8px; border-radius: 26px;
    overflow: hidden; touch-action: none; animation-name: fade; --art-w: 40px;
  }
  .palette .pal-grip, .palette .ptool-tray-sep { display: none; }
  .palette .pal-tray { grid-column: 1 / -1; grid-row: 2; height: 72px; padding: 0; gap: 0; border-left: 0; border-top: 1px solid var(--border); }
  .palette .ptool { flex: 1 1 0; width: auto; min-width: 0; }
  .palette .ptool-num { top: 52px; }
  .palette .ptool.active::after { bottom: 2px; }
  .palette .pal-group { grid-row: 1; height: 52px; border-left: 0; padding: 0 2px; }
  .palette .pal-history { gap: 6px; padding-right: 10px; }
  .palette .pal-icon { width: 38px; height: 38px; }
  .palette .pal-colors { justify-content: center; padding: 0 8px; }
  .palette .size-btn { width: 40px; height: 40px; border-radius: 12px; }
  /* While typing, the keyboard needs the room and the note should stay visible. */
  .keyboard-open .palette { display: none; }
  .keyboard-open .kbd-done {
    display: inline-flex; position: fixed; z-index: 30; right: 12px; padding: 8px 16px;
    top: calc(var(--vv-top, 0px) + var(--vv-h, 100vh) - 50px);
  }
}

.billing-notice { margin: 0; padding: 10px 12px; border-radius: 12px; font-weight: 550; font-size: 14px; background: var(--accent-soft); color: var(--text); }

/* ================================================================ settings page */
#settings-page { overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
.set-top { justify-content: flex-start; flex-wrap: nowrap; }
.set-top h1 { margin: 0; font-size: 24px; font-weight: 580; }
.set-wrap { max-width: 680px; margin: 0 auto; padding: 8px 20px calc(48px + env(safe-area-inset-bottom)); animation: rise 0.5s var(--ease) both; }
.set-profile { display: flex; align-items: center; gap: 14px; padding: 8px 2px 20px; min-width: 0; }
.set-profile > div { display: flex; flex-direction: column; min-width: 0; }
.set-profile b { font-size: 18px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-profile div span { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-avatar { width: 56px; height: 56px; font-size: 20px; }
.set-avatar:hover { transform: none; }

.set-plan {
  padding: 20px; border-radius: var(--r-lg); box-shadow: 0 0 0 1px var(--border), var(--shadow-sm);
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%);
}
.set-plan.pro { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent), var(--shadow-sm); }
.set-plan-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.set-plan-head .eyebrow { margin: 0 0 2px; }
.set-plan-head h2 { margin: 0; font-size: 30px; line-height: 1.1; font-weight: 580; }
.set-plan-head button { flex: none; }
.set-plan-detail { margin: 10px 0 0; color: var(--muted); font-size: 14.5px; line-height: 1.45; }
.set-meters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.set-meters:not(:empty) { margin-top: 16px; }
.set-meter-label { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.set-meter-label b { color: var(--text); font-weight: 650; white-space: nowrap; }
.set-bar { height: 7px; margin-top: 7px; border-radius: 99px; background: color-mix(in srgb, var(--text) 10%, transparent); overflow: hidden; }
.set-bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.4s var(--ease); }
.set-bar i.full { background: var(--danger); }

.set-title { margin: 26px 2px 8px; font-size: 13px; font-weight: 650; letter-spacing: 0.02em; color: var(--muted); }
.set-group { border-radius: var(--r-lg); background: var(--surface); box-shadow: 0 0 0 1px var(--border); overflow: hidden; }
.set-line {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; min-height: 56px;
  padding: 12px 16px; text-align: left; color: var(--text); text-decoration: none; font: inherit;
}
.set-line + .set-line { border-top: 1px solid var(--border); }
.set-line[hidden] + .set-line { border-top: 0; }
.set-line > span { min-width: 0; }
.set-line b { display: block; font-size: 15px; font-weight: 600; }
.set-line small { display: block; margin-top: 1px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.set-line .segmented { flex: none; }
.set-line .i { flex: none; width: 18px; height: 18px; color: var(--muted); }
label.set-line { cursor: pointer; }
.set-link { cursor: pointer; }
.set-link:hover { background: var(--surface-2); }
.set-link.danger b { color: var(--danger); }
@media (max-width: 700px) { .set-dock-row { display: none; } }
@media (max-width: 520px) {
  .set-meters { grid-template-columns: minmax(0, 1fr); }
  .set-line:has(.segmented) { flex-direction: column; align-items: stretch; gap: 10px; }
  .set-plan-head button { width: 100%; }
}

/* ================================================================ plan sheet artwork */
.billing-sheet { position: relative; }
.billing-close { position: absolute; top: 12px; right: 12px; z-index: 2; background: color-mix(in srgb, var(--surface) 75%, transparent); }
.billing-body { --sheet-pad: 26px; padding-top: 0; }
.pro-hero {
  position: relative; isolation: isolate;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none;
  margin: 0 calc(-1 * var(--sheet-pad)); padding: 24px calc(var(--sheet-pad) - 8px) 20px var(--sheet-pad); overflow: hidden;
  background:
    radial-gradient(circle at 78% 30%, color-mix(in srgb, #ffd23f 38%, transparent), transparent 52%),
    radial-gradient(circle at 4% 100%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 42%),
    linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--accent-soft) 35%, var(--surface)));
}
.pro-doodles { position: absolute; inset: 0; z-index: -1; width: 100%; height: 100%; fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0.28; }
.pro-doodles circle { fill: var(--accent); stroke: none; }
.pro-hero-text { flex: 1; min-width: 0; }
.pro-hero h2 { margin: 0; font-size: clamp(28px, 5vw, 36px); line-height: 1.08; font-weight: 560; letter-spacing: -0.01em; }
.pro-hero h2 em {
  font-style: italic; font-weight: 480; color: var(--accent); padding-bottom: 0.14em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 12' preserveAspectRatio='none'%3E%3Cpath d='M2 8c20-5 34-5 50-3s30 2 46-2' fill='none' stroke='%23f2b92c' stroke-width='3.4' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") no-repeat left bottom / 100% 0.3em;
}
.pro-hero p { margin: 10px 0 0; color: var(--muted); font-size: 15px; line-height: 1.4; }
.pro-art { position: relative; flex: none; width: 278px; height: 186px; }
.pro-glow { position: absolute; left: 30px; right: 10px; bottom: -6px; height: 26px; border-radius: 50%; background: rgba(20, 40, 90, 0.2); filter: blur(12px); }
.pro-cover { position: absolute; top: 12px; height: 138px; width: auto; filter: drop-shadow(0 10px 14px rgba(20, 40, 90, 0.28)); }
.pro-cover.c0 { left: 8px; top: 20px; transform: rotate(-17deg); }
.pro-cover.c1 { left: 40px; top: 10px; transform: rotate(-8deg); }
.pro-cover.c2 { left: 80px; top: 2px; transform: rotate(1deg); }
.pro-paper {
  position: absolute; right: 26px; bottom: 6px; width: 152px; padding: 10px 10px 8px; border-radius: 9px; text-align: center; transform: rotate(4deg);
  background: #ffffff; color: #141c2e; box-shadow: 0 1px 2px rgba(20, 40, 90, 0.1), 0 14px 28px rgba(20, 40, 90, 0.26);
}
.pro-paper b { display: inline-block; font-family: "Permanent Marker", cursive; font-weight: 400; font-size: 14px; line-height: 1.2; white-space: nowrap; background: linear-gradient(transparent 58%, #ffd23f 58% 92%, transparent 92%); padding: 0 3px; }
.pro-paper svg { display: block; width: 100%; margin-top: 3px; fill: none; stroke: #141c2e; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.pro-paper .blue { stroke: #2456d6; }
.pro-paper .red { stroke: #d93a2f; }
.pro-paper .sun { fill: #ffd23f; }
.pro-paper i { display: block; font-family: "Caveat", cursive; font-style: normal; font-size: 13px; font-weight: 700; color: #1e3a8a; white-space: nowrap; }
.billing-sheet[open] .pro-paper .dr { stroke-dasharray: 340; stroke-dashoffset: 340; animation: ob-draw 1.4s 0.2s ease-out forwards; }
.pro-pen { position: absolute; right: 0; top: 30px; height: 112px; width: auto; transform: rotate(22deg); filter: drop-shadow(0 6px 8px rgba(20, 40, 90, 0.3)); }
.pro-sticky {
  position: absolute; left: 0; bottom: 8px; padding: 7px 11px 8px 9px; transform: rotate(-6deg); border-radius: 2px 2px 12px 2px;
  background: linear-gradient(160deg, #ffe88f, #ffd95e); color: #4a3a12; font-family: "Caveat", cursive; font-size: 17px; font-weight: 700; line-height: 1; white-space: nowrap;
  box-shadow: 0 8px 14px rgba(20, 40, 90, 0.24);
}
.pro-sticky b { font-family: inherit; font-size: 22px; font-weight: 700; vertical-align: -1px; }
.pro-spark { position: absolute; left: 86px; top: 34px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: #fff; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 45%, transparent); }
.pro-spark .i { width: 20px; height: 20px; }
.pro-twinkle { position: absolute; fill: #f2b92c; }
.pro-twinkle.t1 { left: 6px; top: 6px; width: 18px; height: 18px; }
.pro-twinkle.t2 { right: 62px; top: 0; width: 14px; height: 14px; fill: var(--accent); }
.pro-twinkle.t3 { left: 118px; bottom: 0; width: 12px; height: 12px; }
.billing-sheet[open] .pro-twinkle { animation: pro-twinkle 2.8s ease-in-out infinite; }
.billing-sheet[open] .pro-twinkle.t2 { animation-delay: 0.9s; }
.billing-sheet[open] .pro-twinkle.t3 { animation-delay: 1.8s; }
.billing-sheet[open] .pro-sticky { animation: pro-float 4.5s ease-in-out infinite; }
@keyframes pro-twinkle { 0%, 100% { transform: scale(0.75) rotate(0deg); opacity: 0.6; } 50% { transform: scale(1.1) rotate(18deg); opacity: 1; } }
@keyframes pro-float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }
.billing-status { color: var(--muted); font-size: 14.5px; }
.billing-sheet.deleting .pro-art,
.billing-sheet.deleting .pro-doodles,
.billing-sheet.deleting .billing-body > :not(.pro-hero, .danger-zone, .auth-error) { display: none !important; }
.billing-sheet.deleting .danger-zone { padding-top: 0; border-top: 0; }
.billing-sheet.deleting .danger-zone summary { display: none; }
@media (max-width: 560px) {
  .billing-body { --sheet-pad: 18px; }
  .pro-hero { flex-direction: column-reverse; align-items: stretch; text-align: center; gap: 14px; padding: 22px var(--sheet-pad) 18px; }
  .pro-art { align-self: center; }
  .pro-doodles { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .billing-sheet[open] .pro-paper .dr { animation: none; stroke-dashoffset: 0; }
  .billing-sheet[open] .pro-twinkle, .billing-sheet[open] .pro-sticky { animation: none; }
}

/* ------------------------------------------------------------------ book view (js/book.js)
   Tapping a notebook opens it as a book to flip through. --pw/--ph are one page's size. */
.book-view {
  --pw: 300px; --ph: 388px; --page-r: 10px;
  position: fixed; inset: 0; z-index: 45; display: flex; flex-direction: column; align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  background: #3b4461; color: #fff;
  opacity: 0; transition: opacity 0.22s var(--ease); touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.book-view.shown { opacity: 1; }
.book-view[hidden] { display: none; }
.book-btn {
  display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 999px;
  background: #fff; color: #1f2430; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18), 0 10px 24px -8px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s var(--spring), opacity 0.2s;
}
.book-btn:hover:not(:disabled) { transform: translateY(-2px); }
.book-btn:active:not(:disabled) { transform: scale(0.94); }
.book-btn:disabled { opacity: 0; pointer-events: none; }
.book-btn .i { width: 21px; height: 21px; stroke-width: 2; }
.book-close { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 16px; background: rgba(255, 255, 255, 0.16); color: #fff; box-shadow: none; }
.book-head { text-align: center; margin-top: clamp(8px, 4vh, 40px); max-width: min(560px, calc(100% - 120px)); }
.book-title { margin: 0; font-family: var(--font-display); font-size: clamp(26px, 4.2vw, 40px); font-weight: 600; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-sub { margin: 6px 0 0; display: inline-flex; gap: 6px; align-items: center; font-size: 14px; font-weight: 600; opacity: 0.75; }
.book-sub .i { width: 16px; height: 16px; }
.book-stage { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; gap: 24px; perspective: 2400px; touch-action: pan-y; }
.book-nav.prev .i { transform: none; }
.book-nav.next .i { transform: scaleX(-1); }
.book {
  position: relative; width: calc(var(--pw) * 2); height: var(--ph); flex: none;
  transform-style: preserve-3d; transition: transform 0.55s var(--ease);
}
/* A filter would flatten the 3D leaves, so the shadow lives on a plain layer underneath. */
.book::before {
  content: ""; position: absolute; top: 4%; bottom: -2%; left: 4%; right: 4%; border-radius: 20px;
  background: rgba(10, 14, 30, 0.38); filter: blur(22px); transform: translateZ(-1px); transition: left 0.55s var(--ease);
}
.book[data-state=closed]::before { left: 52%; }
.book-back {
  position: absolute; left: 50%; top: 0; width: var(--pw); height: 100%; border-radius: 0 var(--page-r) var(--page-r) 0;
  background: #f4f2ec;
}
.leaf {
  position: absolute; left: 50%; top: 0; width: var(--pw); height: 100%;
  transform-origin: 0 50%; transform-style: preserve-3d; transition: transform 0.55s cubic-bezier(0.45, 0.05, 0.25, 1);
}
.leaf.lifting { will-change: transform; }
/* Shut, only the cover shows: the pages behind it hide once it has swung closed. */
.book[data-state=closed] :is(.leaf ~ .leaf, .book-back) { visibility: hidden; transition: transform 0.55s, visibility 0s 0.5s; }
.leaf:not(.turned) .face.front:not(.cover) { box-shadow: -1px 0 3px rgba(10, 14, 30, 0.12); }
.face {
  position: absolute; inset: 0; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: #fbfaf7; border-radius: 0 var(--page-r) var(--page-r) 0; cursor: pointer;
}
.face.back { transform: rotateY(180deg); border-radius: var(--page-r) 0 0 var(--page-r); }
.face canvas { display: block; width: 100%; height: 100%; }
/* Shade toward the spine, so two pages read as a spread. */
.face::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgba(0, 0, 0, 0.13), rgba(0, 0, 0, 0.03) 7%, transparent 16%); }
.face.back::after { background: linear-gradient(270deg, rgba(0, 0, 0, 0.13), rgba(0, 0, 0, 0.03) 7%, transparent 16%); }
/* Just the cover art: no fill or shading around it. */
.face.cover { background: none; }
.face.cover::after { content: none; }
.face.cover { border-radius: 0 calc(var(--page-r) * 0.6) calc(var(--page-r) * 0.6) 0; }
/* Zoomed so the face shows only the opaque part of the art (image x 78–434, from y 38, the same
   for every cover): its transparent edges would let the page behind show through as it turns. */
.face.cover .cover-art { width: 110.11%; margin-left: -5.06%; margin-top: -6.74%; }
.face.blank { background: #f4f2ec; cursor: default; }
.folio { position: absolute; bottom: 8px; right: 12px; font: 600 11px/1 var(--font-ui); color: rgba(0, 0, 0, 0.35); }
.face.back .folio { right: auto; left: 12px; }
.book-where { margin: 6px 0 14px; min-height: 18px; font-size: 13px; font-weight: 600; opacity: 0.75; }
.book-actions { display: flex; gap: 14px; align-items: center; }
.book-open { width: auto; padding: 0 22px 0 18px; gap: 8px; display: inline-flex; font-weight: 650; font-size: 15px; }
@media (max-width: 639px) {
  .book-stage { gap: 0; }
  .book-nav { display: none; }
  .book-view { --page-r: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .book-view, .book, .leaf { transition: none; }
}

/* ================================================================ imported files & study tools */
/* A page of an imported PDF or image lies under everything, like an AI notes drawing. */
.item-doc { pointer-events: none; }
.item-doc img { border-radius: 0; }
.page-source { margin-left: 8px; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 600; letter-spacing: 0; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }
.lib-import { display: inline-flex; align-items: center; gap: 7px; }
@media (max-width: 760px) { .lib-import span { display: none; } .lib-import { padding: 10px 12px; } }
body.file-over #pages, body.file-over .notebook-grid { outline: 3px dashed color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -10px; border-radius: 16px; }

/* Lasso round part of a page with nothing to pick up: the area, for Explain, Ask, Highlight and markers. */
.sel-area { position: absolute; z-index: 4; pointer-events: none; border: 2px dashed var(--accent); border-radius: 8px; background: color-mix(in srgb, var(--accent) 7%, transparent); animation: fade 0.15s; }
.sel-menu .sel-ai { background: linear-gradient(135deg, #7c3aed, #2563eb); }
.sel-menu .sel-ai:hover { background: linear-gradient(135deg, #6d28d9, #1d4ed8); }
.sel-marks { display: inline-flex; gap: 0; margin-left: 2px; padding-left: 4px; border-left: 1px solid rgba(255, 255, 255, 0.18); }
.sel-marks button { padding: 6px 6px; font-size: 15px; }

/* AI notes from Explain and Ask: a sticky with a small ✨ tab, joined to its passage. */
.item-note::before {
  content: "✨ AI"; position: absolute; top: -10px; right: 10px; padding: 2px 7px; border-radius: 99px; font: 700 10.5px/1.4 var(--font-ui);
  background: #1f2937; color: #fff; letter-spacing: 0.02em; pointer-events: none;
}
.note-ask::before { content: "💬 AI"; }
.item-note .item-body { font-size: 14.5px; line-height: 21px; overflow-y: auto; }
.item-note .rich ul { padding-left: 18px; }
.note-link { position: absolute; overflow: visible; pointer-events: none; }
.note-link rect { fill: color-mix(in srgb, #facc15 12%, transparent); stroke: #b45309; stroke-width: 1.5; stroke-dasharray: 5 4; opacity: 0.75; }
.note-ask .note-link rect { fill: color-mix(in srgb, #60a5fa 12%, transparent); stroke: #1d4ed8; }
.note-link line { stroke: #b45309; stroke-width: 1.5; stroke-dasharray: 4 3; opacity: 0.8; }
.note-link circle { fill: #b45309; }
.note-ask .note-link :is(line) { stroke: #1d4ed8; }
.note-ask .note-link circle { fill: #1d4ed8; }
.item-note.thinking .rich { animation: thinking 1.2s ease-in-out infinite alternate; }
@keyframes thinking { from { opacity: 0.45; } to { opacity: 1; } }
.item-bar .note-btn { font-weight: 650; color: #6d28d9; }

/* Markers: ⭐ ❓ ⚠️ ✅ in the margin. */
.item-mark { min-width: 0; width: 36px; height: 36px; display: grid; place-items: center; }
.item-mark .item-body { font-size: 26px; line-height: 36px; text-align: center; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2)); }
.item-mark .resize-handle { display: none !important; }

/* Marks panel in the sidebar. */
.side-tabs { display: inline-flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--surface-2); }
.side-tabs button { padding: 5px 9px; border-radius: 7px; font: 700 11px/1 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.side-tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }
.marks-list { display: flex; flex-direction: column; gap: 4px; padding: 6px 10px 24px; }
.marks-page { margin: 10px 6px 2px; font-size: 11px; font-weight: 700; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mark-row { display: flex; gap: 8px; align-items: flex-start; text-align: left; padding: 7px 8px; border-radius: 9px; font-size: 12.5px; line-height: 1.35; color: var(--text); }
.mark-row:hover { background: var(--surface-2); }
.mark-row-icon { flex: none; font-size: 14px; line-height: 1.2; }
.mark-row-text { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.mark-row-text b { font-weight: 650; margin-right: 3px; }
.marks-empty { padding: 12px 8px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.spot-flash { position: absolute; left: 0; right: 0; height: 60px; z-index: 4; pointer-events: none; background: color-mix(in srgb, var(--accent) 18%, transparent); animation: spot 1.6s ease-out forwards; }
@keyframes spot { 0%, 40% { opacity: 1; } to { opacity: 0; } }

/* New notebook: start from a file. */
.nb-file i { text-transform: none; letter-spacing: 0; font-weight: 500; font-style: normal; opacity: 0.8; }
.nb-file-btn { display: flex; align-items: center; gap: 9px; width: 100%; padding: 11px 12px; border-radius: 12px; border: 1.5px dashed var(--border); color: var(--muted); font-weight: 600; font-size: 13.5px; text-align: left; }
.nb-file-btn:hover { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, transparent); }
.nb-file-chip { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 9%, var(--surface)); color: var(--text); font-weight: 600; font-size: 13.5px; }
.nb-file-chip span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-file-btn[hidden], .nb-file-chip[hidden] { display: none; }

/* Import progress. */
.import-sheet { width: min(420px, calc(100vw - 24px)); }
.import-body { display: flex; flex-direction: column; gap: 10px; padding: 4px 26px 8px; }
.import-name { margin: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.import-bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width 0.25s; }

.ask-sheet { width: min(480px, calc(100vw - 24px)); }
.ask-body { display: flex; flex-direction: column; gap: 14px; padding: 4px 26px 12px; }
.ask-sheet textarea { width: 100%; resize: vertical; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.ask-sheet textarea:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: var(--focus); }
.export-notes { margin: 4px 0 10px; font-size: 13.5px; }
@media print { .note-link, .item-note::before, .sel-area { display: none !important; } }
.sidebar-head:has(.side-tabs) { padding: 12px 8px 8px 10px; gap: 6px; }
.side-tabs button { padding: 5px 7px; }
.sidebar-head #sidebar-add { padding: 6px; }
