html, body { margin: 0; height: 100%; font-family: -apple-system, system-ui, sans-serif; color: #222; background: #fafafa; overflow: hidden; overscroll-behavior: none; }
#root { height: 100vh; }

.editor {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.editor img {
  animation: blur-in 280ms ease-out;
}
@keyframes blur-in {
  0%   { filter: blur(10px); opacity: 0; }
  100% { filter: none;       opacity: 1; }
}
.view-fade {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  transition: opacity 120ms ease-out;
}
.view-fade.in { opacity: 1; }
.view-fade.out { opacity: 0; }
.edit-layout {
  display: grid;
  grid-template-columns: 300px 1fr 280px;
  flex: 1;
  min-height: 0;
}
.edit-layout.series-layout { grid-template-columns: 300px 1fr; }
.edit-layout.essay-layout { grid-template-columns: 300px 1fr 300px; }
/* Right objects sidebar reuses the whiteboard sidebar styling. */
.whiteboard-sidebar.essay-objects { min-width: 0; overflow-y: auto; }

.series-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.series-pane .article-header {
  position: static;
  padding: 6px 12px;
  margin: 0;
  width: auto;
  min-width: 0;
  border-bottom: 1px solid #e5e5e5;
  background: #fafafa;
  display: flex;
  gap: 8px;
}
.series-pane .article-header input { flex: 1; }
.series-pane .article-header .preview-link {
  padding: 6px 14px;
  font-size: 0.85rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  color: #222;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  font: inherit;
}
.series-pane .article-header .preview-link:hover { background: #f0f0f0; }
.tab.preview { background: #f5efff; }
.tab.preview.active { background: #6b3fa0; color: #fff; border-color: #6b3fa0; }
.slide-editor {
  flex: 1;
  display: grid;
  grid-template-columns: 110px 1fr;
  min-height: 0;
}
.slides-col {
  border-right: 1px solid #e5e5e5;
  background: #f4f4f4;
  padding: 4px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.slides-empty {
  padding: 40px 12px;
  text-align: center;
  color: #999;
  font-size: 0.8rem;
  border: 2px dashed #ccc;
  border-radius: 4px;
}
.slide-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #ddd;
  border: 1px solid transparent;
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
}
.slide-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slide-thumb.active { border-color: #2563eb; }
.slide-thumb .slide-num {
  position: absolute; top: 1px; left: 2px;
  font-size: 0.6rem; color: #fff;
  background: rgba(0,0,0,0.55);
  padding: 0 3px;
  border-radius: 2px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.slide-thumb .slide-del {
  position: absolute; top: 1px; right: 1px;
  width: 14px; height: 14px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: #fff; border: none; cursor: pointer;
  font-size: 0.7rem; opacity: 0; transition: opacity 0.15s;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.slide-thumb:hover .slide-del { opacity: 1; }
.slide-thumb .slide-del:hover { background: #c00; }

.slide-stage {
  position: relative;
  background: #ECE9D8;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 12px 16px;
  overflow: hidden;
  min-height: 0;
  box-sizing: border-box;
}
.slide-frame {
  background: #fff;
  height: min(100%, 70vh);
  max-width: 100%;
  display: block;
  flex: none;
  overflow: hidden;
}
.slide-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top left;
  display: block;
}
.slide-empty-stage { color: #888; font-size: 0.9rem; }

.series-viewer {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ECE9D8;
  min-height: 0;
}
.series-viewer .slide-stage { flex: 1; }
.series-viewer-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.06), transparent);
  z-index: 2;
  opacity: 0;
  transition: opacity 0.15s;
}
.series-viewer:hover .series-viewer-bar { opacity: 1; }
.series-viewer-bar button {
  background: rgba(255,255,255,0.7);
  border: 1px solid #ccc;
  color: #333;
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.85rem;
}
.series-viewer-bar button:hover { background: #fff; }
.series-viewer-title {
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
  color: #555;
}
.series-scroller {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ECE9D8;
  min-height: 0;
  overflow: hidden;
}
.xmb-row {
  flex: none;
  position: relative;
  overflow: hidden;
  padding: 10px 0 8px;
  background: linear-gradient(to bottom, #d9d4be, #ECE9D8);
  border-bottom: 1px solid #c8c2a8;
  contain: layout paint;
}
.xmb-track {
  display: flex;
  align-items: center;
  gap: 18px;
  will-change: transform;
  transition: transform 280ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.xmb-tile {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  width: 84px;
  margin: 0;
  padding: 0;
}
.xmb-icon {
  width: 64px;
  height: 64px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 1px;
  background: #888;
  border: 2px solid transparent;
  overflow: hidden;
}
.xmb-tile.active .xmb-icon {
  border-color: #fff;
}
.xmb-icon-cell {
  background: #ddd;
  overflow: hidden;
}
.xmb-icon-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.xmb-label {
  font-size: 0.72rem;
  color: #333;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  margin: 0;
  line-height: 1.2;
}
.xmb-tile.active .xmb-label {
  color: #000;
}
/* Carousel viewport: width matches the widest possible slide-frame so each
   series occupies a single, fixed-width column that slides in/out as a
   coherent unit (no ghost-from-nowhere flash). */
.series-carousel {
  flex: 1;
  position: relative;
  overflow: hidden;
  /* widest bucket aspect (16/9) at max-height 80vh, capped to slide max-width
     and to the available viewport width. */
  width: min(900px, calc(80vh * 16 / 9), 100%);
  align-self: flex-start;
  min-height: 0;
}
.series-carousel-track {
  display: flex;
  height: 100%;
  transition: transform 380ms cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: transform;
}
.series-scroller-stage {
  position: relative;             /* be the offsetParent for slide-frames */
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 24px;
  padding: 16px 24px;
  min-height: 0;
  box-sizing: border-box;
}
.series-scroller-stage .slide-frame {
  height: auto;
  width: auto;
  max-width: min(100%, 900px);
  max-height: 80vh;
  flex: none;
  cursor: pointer;
  transition: outline 0.15s;
  outline: 2px solid transparent;
}
.series-scroller-stage .slide-frame.active {
  outline-color: #555;
}

/* ============= Whiteboard ============= */
.whiteboard-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 280px;
  min-height: 0;
  overflow: hidden;
}
.whiteboard-canvas {
  position: relative;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #f3efe0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.08) 1px, transparent 0);
  background-size: 28px 28px;
  cursor: grab;
  filter: blur(var(--wb-blur, 0));
  transition: filter 60ms linear;
}
.whiteboard-canvas.space-pan { cursor: grabbing; }
.whiteboard-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}
.wb-item {
  position: absolute;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  background: #fff;
  border: 1px solid #ccc;
  user-select: none;
  cursor: grab;
}
.wb-item:active { cursor: grabbing; }
.wb-item.selected { outline: 2px solid #2d7cff; outline-offset: 2px; }
.wb-marquee {
  position: absolute;
  border: 1px solid #2d7cff;
  background: rgba(45, 124, 255, 0.12);
  pointer-events: none;
}

/* Text boxes: no card background — just text floating on the canvas. */
.wb-item.wb-item-text {
  background: transparent;
  border: none;
  box-shadow: none;
}
.wb-item.wb-item-text.selected { outline: 1.5px dashed rgba(45, 124, 255, 0.8); }
.wb-text-display {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font: 22px/1.3 -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", system-ui, sans-serif;
  color: #2a1f10;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  cursor: grab;
}
.wb-text-display.empty { color: rgba(42, 31, 16, 0.35); }
.wb-text-edit {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(45, 124, 255, 0.6);
  background: rgba(255, 255, 255, 0.9);
  font: 22px/1.3 -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", system-ui, sans-serif;
  color: #2a1f10;
  resize: none;
  padding: 0;
  margin: 0;
  outline: none;
  cursor: text;
}
.wb-item-text .wb-handle {
  position: absolute;
  width: 10px; height: 10px;
  background: #2d7cff;
  border: 1.5px solid #fff;
  border-radius: 2px;
  z-index: 5;
}
.wb-item-text .wb-handle-tl { left: -5px; top: -5px; cursor: nwse-resize; }
.wb-item-text .wb-handle-tr { right: -5px; top: -5px; cursor: nesw-resize; }
.wb-item-text .wb-handle-bl { left: -5px; bottom: -5px; cursor: nesw-resize; }
.wb-item-text .wb-handle-br { right: -5px; bottom: -5px; cursor: nwse-resize; }

/* Whiteboard editing a doc reuses the whole shell. */
.whiteboard-edit-shell { flex: 1; display: flex; min-height: 0; min-width: 0; }
.whiteboard-edit-shell > .whiteboard-layout { flex: 1; }

/* Vortex transition: the clicked whiteboard item morphs into oblivion while
   the rest of the canvas blurs and fades, then we navigate to its editor. */
.whiteboard-canvas.vortex-active > .whiteboard-world {
  transition: filter 600ms ease, opacity 600ms ease;
  filter: blur(14px) saturate(0.6);
  opacity: 0.4;
}
.wb-item.vortex {
  z-index: 100;
  animation: wb-vortex 600ms cubic-bezier(0.5, 0, 0.85, 0.4) forwards;
  transform-origin: 50% 50%;
  pointer-events: none;
}
@keyframes wb-vortex {
  0%   { transform: scale(1)    rotate(0)      translate(0, 0); filter: blur(0)  saturate(1)   brightness(1);   opacity: 1; }
  35%  { transform: scale(1.25) rotate(280deg) translate(0, 0); filter: blur(2px) saturate(1.2) brightness(1.05); opacity: 1; }
  70%  { transform: scale(0.5)  rotate(700deg) translate(0, 0); filter: blur(8px) saturate(1.5) brightness(1.1);  opacity: 0.8; }
  100% { transform: scale(0)    rotate(1080deg) translate(0, 0); filter: blur(24px) saturate(2)   brightness(1.4);  opacity: 0; }
}

/* Mini whiteboard thumbnail (used in tiles & previews). */
.wb-thumb-board {
  position: relative;
  background: #f3efe0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.06) 1px, transparent 0);
  background-size: 14px 14px;
  overflow: hidden;
}
.wb-thumb-tile {
  position: absolute;
  background: #fff;
  border: 1px solid #ccc;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  overflow: hidden;
}
.wb-thumb-tile img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.wb-thumb-tile-draft {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #d8d3bb 0%, #ECE9D8 100%);
}

/* ============= Notebook ============= */

.notebook-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #2a2421;
}
.notebook-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #1f1a18;
  color: #e8e3d6;
  border-bottom: 1px solid #000;
}
.notebook-bar button {
  background: #3a322e;
  color: #e8e3d6;
  border: 1px solid #000;
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.notebook-bar button:hover:not(:disabled) { background: #4a423e; }
.notebook-bar button:disabled { opacity: 0.35; cursor: default; }
.notebook-bar .nb-add { margin-left: auto; }
.notebook-indicator {
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  color: #d6cdb6;
  font-variant-numeric: tabular-nums;
}

.notebook-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 0;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(255, 240, 210, 0.04), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(0,0,0,0.55), transparent 50%),
    #1d1816;
  perspective: 3200px;
}
/* The book itself: an open spread treated as ONE object — two halves of the
   same sheet, separated only by a soft gutter shadow at the fold. */
.notebook-book {
  position: relative;
  display: flex;
  align-items: stretch;
  height: 100%;
  aspect-ratio: 1.45 / 1;
  max-width: 100%;
  background: #f6efdb;
  border-radius: 4px;
  box-shadow:
    0 1px 0 rgba(255, 230, 200, 0.05) inset,
    0 28px 60px -14px rgba(0,0,0,0.7),
    0 60px 90px -30px rgba(0,0,0,0.55);
  transform: rotateX(6deg);     /* slight forward tilt for depth */
  transform-style: preserve-3d;
  padding: 6px;
}
/* Visible back cover lip + page-edge stack peeking below the spread. */
.notebook-book::before {
  content: "";
  position: absolute;
  left: -6px; right: -6px;
  bottom: -8px;
  height: 14px;
  border-radius: 2px;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.0) 0%, rgba(0,0,0,0.35) 100%),
    repeating-linear-gradient(to bottom,
      #f3eadb 0px, #f3eadb 1px,
      #cdc1a6 1px, #cdc1a6 2px);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.05) inset,
    0 6px 12px rgba(0,0,0,0.45);
  transform: translateZ(-2px);
  z-index: -1;
}
.notebook-book::after {
  /* deeper back board behind the page stack */
  content: "";
  position: absolute;
  left: -10px; right: -10px;
  top: -6px; bottom: -16px;
  border-radius: 4px;
  background: linear-gradient(180deg, #2a1c12 0%, #1c1108 100%);
  box-shadow: 0 14px 30px rgba(0,0,0,0.55);
  transform: translateZ(-6px);
  z-index: -2;
}
/* Page-edge stack: visible bands of paper along the bottom and outer edges,
   suggesting a real book of pages. */
.notebook-book::before {
  content: "";
  position: absolute;
  left: 6px; right: 6px;
  bottom: 4px;
  height: 6px;
  border-radius: 1px;
  background:
    repeating-linear-gradient(to bottom,
      #f3eadb 0px, #f3eadb 1px,
      #d8cdb6 1px, #d8cdb6 2px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.3);
  z-index: 1;
}
.notebook-book::after {
  /* corner sheen along the spine */
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 12px;
  transform: translateX(-50%);
  background: linear-gradient(to right,
    rgba(0,0,0,0.55) 0%,
    rgba(0,0,0,0) 35%,
    rgba(0,0,0,0) 65%,
    rgba(0,0,0,0.55) 100%);
  pointer-events: none;
  z-index: 2;
}
.nb-page {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: #f6efdb;
  /* paper grain via stacked subtle gradients (no SVG dependency). */
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(255,255,255,0.45), rgba(255,255,255,0) 65%),
    radial-gradient(ellipse at 100% 100%, rgba(160,120,60,0.10), rgba(160,120,60,0) 60%),
    radial-gradient(circle at 20% 80%, rgba(80,50,20,0.06), rgba(0,0,0,0) 50%),
    repeating-linear-gradient(132deg, rgba(160,120,60,0.04) 0, rgba(160,120,60,0) 2px, rgba(255,255,255,0.04) 4px, rgba(255,255,255,0) 5px);
  isolation: isolate;
}
.nb-page-l {
  border-radius: 2px 0 0 2px;
  box-shadow:
    inset -28px 0 32px -18px rgba(80, 50, 20, 0.45);
}
.nb-page-r {
  border-radius: 0 2px 2px 0;
  box-shadow:
    inset 28px 0 32px -18px rgba(80, 50, 20, 0.45);
}
.nb-page.hidden-cover {
  background: transparent;
  background-image: none;
  box-shadow: none;
  pointer-events: none;
}
/* Spine = a subtle crease line, not a separator. The two pages sit edge-to-edge. */
.nb-spine {
  width: 0;
  flex: 0 0 0;
  position: relative;
  z-index: 3;
}
.nb-spine::before {
  content: "";
  position: absolute;
  top: -6px; bottom: -6px; left: -1px;
  width: 2px;
  background: linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0.18) 50%, rgba(0,0,0,0) 100%);
  pointer-events: none;
}

.nb-page-blank { width: 100%; height: 100%; }
.nb-page-num {
  position: absolute;
  bottom: 14px;
  font: 11px -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
  color: #8a6b3a;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  z-index: 1;
}
.nb-page-l .nb-page-num { right: 22px; }
.nb-page-r .nb-page-num { left: 22px; }

/* Embossed leather cover with foil-stamped title. */
.nb-page.is-cover {
  background-color: #5a2c14;
  background-image:
    /* leather grain — stacked low-alpha radial bumps */
    radial-gradient(circle at 8% 12%, rgba(255,180,120,0.06) 0px, rgba(0,0,0,0) 6px),
    radial-gradient(circle at 70% 18%, rgba(255,180,120,0.05) 0px, rgba(0,0,0,0) 8px),
    radial-gradient(circle at 30% 65%, rgba(0,0,0,0.20) 0px, rgba(0,0,0,0) 9px),
    radial-gradient(circle at 80% 80%, rgba(0,0,0,0.25) 0px, rgba(0,0,0,0) 12px),
    radial-gradient(circle at 50% 40%, rgba(0,0,0,0.15) 0px, rgba(0,0,0,0) 14px),
    /* coarse pebble texture */
    repeating-radial-gradient(circle at 10% 20%, rgba(255,200,150,0.04), rgba(0,0,0,0.06) 2px, rgba(0,0,0,0) 3px),
    /* base lighting */
    radial-gradient(ellipse at 30% 15%, rgba(255,210,160,0.18), rgba(0,0,0,0) 60%),
    linear-gradient(135deg, #6e3719 0%, #3a1a0a 100%);
  background-blend-mode: overlay, overlay, multiply, multiply, normal, normal, normal, normal;
  color: #f5e0b3;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow:
    inset 0 0 0 8px rgba(0,0,0,0.20),
    inset 0 0 0 9px rgba(255,200,140,0.18),
    inset 0 0 0 11px rgba(0,0,0,0.20),
    inset 12px 0 24px -14px rgba(0,0,0,0.6);
}
.nb-page.is-cover::before {
  /* tooled border ornament */
  content: "";
  position: absolute;
  inset: 24px;
  border: 1.5px solid rgba(255, 210, 150, 0.38);
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.25),
    0 0 0 1px rgba(0,0,0,0.18);
  pointer-events: none;
}
.nb-cover {
  text-align: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}
.nb-cover-title {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
  font-weight: 600;
  font-size: 2.4rem;
  letter-spacing: 0.04em;
  /* faux foil-stamp gradient + emboss */
  background: linear-gradient(180deg, #f8e2a9 0%, #c89b50 50%, #f1d68a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow:
    0 1px 0 rgba(0,0,0,0.45),
    0 0 8px rgba(255,200,120,0.25);
  margin-bottom: 14px;
}
.nb-cover-sub {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
  font-style: normal;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(245,225,180,0.7);
}

/* Two-faced flipping leaf. The book's spine sits at the centre of the spread;
   the flipper covers exactly one half (right for "next", left for "prev")
   and rotates around the spine edge. Both faces (front = old page, back =
   destination page) are rendered, lit by a moving glare highlight, and
   shaded by a soft drop shadow that intensifies at the midpoint. */
.nb-flipper {
  position: absolute;
  top: 6px; bottom: 6px;
  width: calc(50% - 6px);
  perspective: 2400px;
  z-index: 5;
  pointer-events: none;
}
.nb-flipper-next { left: 50%; }
.nb-flipper-prev { right: 50%; }
.nb-flipper-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  will-change: transform;
}
.nb-flipper-next .nb-flipper-inner {
  transform-origin: left center;
  animation: nb-flip-next 500ms cubic-bezier(0.65, 0, 0.35, 1) forwards;
}
.nb-flipper-prev .nb-flipper-inner {
  transform-origin: right center;
  animation: nb-flip-prev 500ms cubic-bezier(0.65, 0, 0.35, 1) forwards;
}
.nb-flipper-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: #f6efdb;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(255,255,255,0.45), rgba(255,255,255,0) 65%),
    radial-gradient(ellipse at 100% 100%, rgba(160,120,60,0.10), rgba(160,120,60,0) 60%);
  box-shadow: 0 8px 22px rgba(0,0,0,0.35);
}
.nb-flipper-front {
  /* old page rendered front-on at start; faces away after 90deg */
}
.nb-flipper-back {
  transform: rotateY(180deg);
}
/* Specular sweep — a moving highlight that mimics light glancing off the
   page as it rotates. The same element on each face animates to produce a
   subtle bright band drifting across at the midpoint. */
.nb-flipper-glare {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(70deg,
    rgba(255,255,255,0)   0%,
    rgba(255,255,255,0)  35%,
    rgba(255,255,255,0.42) 50%,
    rgba(255,255,255,0)  65%,
    rgba(255,255,255,0) 100%);
  background-size: 250% 100%;
  background-position: 100% 0;
  animation: nb-flip-glare 500ms cubic-bezier(0.65, 0, 0.35, 1) forwards;
}
.nb-flipper-prev .nb-flipper-glare { transform: scaleX(-1); }

/* While the leaf rotates around its inner edge, a deep shadow falls onto the
   page beneath it, drifting from the spine toward the outer edge as the
   page lifts. */
.nb-flipper::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 60%;
  pointer-events: none;
  background: linear-gradient(to right, rgba(0,0,0,0.55), rgba(0,0,0,0));
  opacity: 0;
  animation: nb-flip-cast 500ms cubic-bezier(0.65, 0, 0.35, 1) forwards;
}
.nb-flipper-next::after { left: 0; transform-origin: left center; }
.nb-flipper-prev::after { right: 0; background: linear-gradient(to left, rgba(0,0,0,0.55), rgba(0,0,0,0)); }
/* Single keyframe pair → monotonic ease, no per-segment velocity seams. The
   cubic-bezier on the animation handles the entire acceleration curve. */
@keyframes nb-flip-next {
  from { transform: rotateY(0deg); }
  to   { transform: rotateY(-180deg); }
}
@keyframes nb-flip-prev {
  from { transform: rotateY(0deg); }
  to   { transform: rotateY(180deg); }
}
@keyframes nb-flip-glare {
  0%   { background-position: 100% 0; }
  100% { background-position:  -50% 0; }
}
@keyframes nb-flip-cast {
  /* Two-step opacity ramp would jag; use a single sine-like rise with
     opacity 0→1 and rely on a CSS-driven shape via mask-image instead. */
  0%   { opacity: 0; }
  50%  { opacity: 0.5; }
  100% { opacity: 0; }
}

/* Drop cap removal — body sets in plain sans-serif, no first-letter flair. */
.nb-text-line { letter-spacing: 0; }

/* Page content area: we use percent-based positioning so contents reflow with
   page size. */
.nb-page-content {
  position: absolute;
  inset: 36px 28px 36px 28px;
}
.nb-item {
  position: absolute;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.15);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  overflow: hidden;
}
.nb-item img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.nb-text {
  position: absolute;
  color: #2a1f10;
  cursor: grab;
}
.nb-text:active { cursor: grabbing; }
.nb-text.selected { outline: 1.5px dashed rgba(45, 124, 255, 0.7); outline-offset: 2px; }
.nb-text-edit {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(45, 124, 255, 0.6);
  background: rgba(255,255,255,0.85);
  font: 16px/24px -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", system-ui, sans-serif;
  line-height: 26px;
  color: #2a1f10;
  resize: none;
  padding: 0;
  outline: none;
}

.nb-item.selected { outline: 2px solid #2d7cff; outline-offset: 2px; }
.nb-item img, .nb-item .draft-icon {
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  /* No fade-in / no transitions — must be visually stable through page flips */
  transition: none !important;
  animation: none !important;
}

.nb-handle {
  position: absolute;
  width: 12px; height: 12px;
  background: #2d7cff;
  border: 1.5px solid #fff;
  border-radius: 2px;
  z-index: 5;
}
.nb-handle-tl { left: -6px; top: -6px; cursor: nwse-resize; }
.nb-handle-tr { right: -6px; top: -6px; cursor: nesw-resize; }
.nb-handle-bl { left: -6px; bottom: -6px; cursor: nesw-resize; }
.nb-handle-br { right: -6px; bottom: -6px; cursor: nwse-resize; }

/* Layout: book on the left of the screen, library docked to the right. */
.notebook-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 280px;
  min-height: 0;
  overflow: hidden;
}
.notebook-library {
  border-left: 1px solid #000;
  background: #1f1a18;
  color: #d6cdb6;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.notebook-library .wb-side-section h3 { color: #c8b78c; }
.notebook-library .wb-side-empty { color: #8a8166; }
.notebook-library .wb-folder-h {
  background: #2c2522;
  color: #d6cdb6;
  border-color: #000;
}
.notebook-library .wb-folder-h:hover { background: #3a3128; box-shadow: none; }
.notebook-library .wb-folder.open .wb-folder-h { background: #3f352c; color: #fff; border-color: #000; }
.notebook-library .wb-thumb { background: #2a2421; border-color: #000; }
.notebook-library .wb-thumb-label { color: #fff; }
.notebook-library .wb-draft-thumb.series::after { color: #fff; }

.notebook-stage { position: relative; }

/* Body text: clean sans-serif, even leading, no decoration. */
.nb-text-line {
  position: absolute;
  font: 400 16px/24px -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  color: #2a1f10;
  height: 24px;
  line-height: 24px;
  white-space: nowrap;
  display: block;
  pointer-events: none;
  text-rendering: optimizeLegibility;
}
.wb-item img { user-select: none; -webkit-user-drag: none; pointer-events: none; }
.wb-item-inner {
  width: 100%;
  height: 100%;
  overflow: hidden;
  transition: transform 80ms ease-out;
  transform-origin: 50% 50%;
}
/* The content renders at its NATURAL size and is then scaled via transform —
   so the visible item box matches scale × natural, but the inner DOM uses
   real pixel dimensions that the previews can lay out against. */
.wb-item-content {
  transform-origin: 0 0;
  position: relative;
}
.wb-item-content > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.wb-label {
  position: absolute;
  left: 0; right: 0; bottom: -22px;
  text-align: center;
  font-size: 0.75rem;
  color: #444;
  text-shadow: 0 1px 0 #f3efe0;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wb-del {
  position: absolute;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
}
.wb-item:hover .wb-del { display: flex; }
.wb-mode-bar {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  display: none;
  gap: 2px;
  background: rgba(0,0,0,0.65);
  padding: 2px;
  border-radius: 3px;
}
.wb-item:hover .wb-mode-bar { display: flex; }
.wb-mode {
  background: transparent;
  color: #ddd;
  border: 0;
  font-size: 0.7rem;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: 2px;
}
.wb-mode.active { background: #fff; color: #000; }
.wb-missing {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  color: #aaa; font-size: 0.8rem;
}

/* Roll: vertical, full-width, every slide stacked top-to-bottom. */
.wb-roll {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}
.wb-roll img {
  width: 100%;
  height: auto;
  flex: none;
  object-fit: contain;
  display: block;
}
.wb-spiral {
  position: relative;
  width: 100%;
  height: 100%;
  background: #ECE9D8;
}
.wb-spiral img {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  object-fit: cover;
}
.wb-empty {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  color: #888; font-size: 0.8rem;
}

.whiteboard-sidebar {
  border-left: 1px solid #ddd;
  background: #fafafa;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.wb-side-header {
  padding: 4px 2px 12px;
  border-bottom: 1px solid #e5e5e5;
  margin-bottom: 4px;
}
.wb-side-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #222;
  letter-spacing: 0.005em;
}
.wb-side-title-input {
  font-size: 1.05rem;
  font-weight: 600;
  color: #222;
  letter-spacing: 0.005em;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 4px;
  outline: none;
  font-family: inherit;
}
.wb-side-title-input:hover { border-color: #e2e2e2; background: #fff; }
.wb-side-title-input:focus { border-color: #2d7cff; background: #fff; }
.wb-side-sub {
  font-size: 0.74rem;
  color: #888;
  margin-top: 2px;
  line-height: 1.35;
}
.wb-props { display: flex; flex-direction: column; gap: 8px; }
.wb-prop-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wb-prop-key { font-size: 0.78rem; color: #666; }
.wb-prop-val { font-size: 0.78rem; color: #222; font-variant-caps: small-caps; }
.wb-zoom-buttons { display: flex; gap: 4px; }
.wb-zoom-btn {
  background: #fff;
  border: 1px solid #ccc;
  color: #333;
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.wb-zoom-btn:hover { background: #f0f0f0; }
.wb-zoom-btn.active { background: #2d7cff; color: #fff; border-color: #2d7cff; }
.wb-zoom-bar {
  position: absolute;
  left: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,0.92);
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 0.78rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  font-variant-numeric: tabular-nums;
  z-index: 10;
}
.wb-zoom-bar button {
  background: transparent;
  border: 0;
  width: 22px; height: 22px;
  cursor: pointer;
  font-size: 0.95rem;
}
.wb-zoom-bar button:hover { background: rgba(0,0,0,0.06); border-radius: 2px; }
.wb-zoom-bar span { min-width: 42px; text-align: center; color: #555; }
.wb-side-section h3 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #777;
  font-weight: 600;
}
.wb-side-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.wb-side-grid.images {
  grid-template-columns: 1fr;
  gap: 10px;
}
.wb-side-empty { font-size: 0.75rem; color: #999; }
.wb-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #eee;
  border: 1px solid #ccc;
  cursor: grab;
  overflow: hidden;
}
.wb-thumb img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
  pointer-events: none;
}
.wb-thumb-empty { width: 100%; height: 100%; background: #ddd; }
.wb-draft-thumb { aspect-ratio: 1 / 1; }
/* Images section: bigger, cardy, native aspect, easier to grab. */
.wb-side-grid.images .wb-thumb {
  aspect-ratio: auto;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  transition: box-shadow 120ms ease, transform 120ms ease;
}
.wb-side-grid.images .wb-thumb:hover {
  box-shadow: 0 3px 10px rgba(0,0,0,0.14);
  transform: translateY(-1px);
}
.wb-side-grid.images .wb-thumb img {
  height: auto;
  max-height: 240px;
}
.wb-draft-thumb.series::after {
  content: "▭";
  position: absolute;
  top: 2px; right: 4px;
  font-size: 0.6rem;
  color: #fff;
  text-shadow: 0 0 2px rgba(0,0,0,0.7);
}
.wb-thumb-label {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  color: #fff;
  font-size: 0.65rem;
  padding: 8px 4px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wb-side-folders {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wb-folder-h {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: #333;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: background 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.wb-folder-h:hover {
  background: #f6f6f6;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.wb-folder.open .wb-folder-h {
  color: #000;
  border-color: #bbb;
  background: #f0f0ee;
}

.series-viewer-meta {
  position: absolute; bottom: 8px; right: 12px;
  font-size: 0.8rem;
  color: #888;
  font-variant-numeric: tabular-nums;
}

.topbar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid #e5e5e5;
  background: #fff;
  align-items: center;
}
.view-btn {
  height: 32px;
  padding: 0 14px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
}
.view-btn.active { background: #222; color: #fff; border-color: #222; }
.doc-icon { display: inline-block; margin-right: 4px; opacity: 0.8; }

/* Full-colour SVG tab icons — flat mini-illustrations of each view. */
.ico {
  display: inline-block;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-right: 8px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}
.tab .ico { width: 20px; height: 20px; margin-right: 2px; }
.ico-collections { background-image: url("assets/collections.svg"); }
.ico-motifs { background-image: url("assets/motifs.svg"); }
.ico-series { background-image: url("assets/series.svg"); }
.ico-whiteboard { background-image: url("assets/whiteboard.svg"); }
.ico-essays { background-image: url("assets/essays.svg"); }
.ico-new { background-image: url("assets/new.svg"); }
.ico-edit { background-image: url("assets/edit.svg"); }
.ico-preview { background-image: url("assets/preview.svg"); }

.tab {
  height: 32px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 4px 0 12px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  max-width: 200px;
  box-sizing: border-box;
}
.tab:hover { background: #f8f8f8; }
.tab.active { background: #222; color: #fff; border-color: #222; }
.tab.active .tab-close { color: rgba(255,255,255,0.7); }
.tab.active .tab-close:hover { color: #fff; background: rgba(255,255,255,0.15); }
.tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.tab-close {
  background: transparent; border: none; cursor: pointer;
  width: 20px; height: 20px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  color: #999; font-size: 1rem; line-height: 1;
}
.tab-close:hover { background: #eee; color: #c00; }

.sidebar {
  border-right: 1px solid #e5e5e5;
  overflow-y: auto;
  background: #f4f4f4;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar h2 { margin: 0 0 4px; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: #888; font-weight: 600; }
.sidebar select, .sidebar input { width: 100%; padding: 6px 8px; border: 1px solid #ddd; border-radius: 4px; background: #fff; font-size: 0.85rem; box-sizing: border-box; }

.block-btn { width: 100%; padding: 6px; margin-bottom: 4px; cursor: pointer; border: 1px solid #ddd; background: #fff; border-radius: 4px; font-size: 0.85rem; }
.block-btn:hover { background: #f8f8f8; }

.bounds-template {
  border: 2px solid #000;
  background: #fff;
  padding: 10px;
  text-align: center;
  border-radius: 0;
  cursor: grab;
  font-size: 0.8rem;
  color: #222;
  user-select: none;
  font-weight: 600;
}
.bounds-template:active { cursor: grabbing; background: #eee; }

.format-row { display: flex; gap: 6px; }
.format-btn {
  width: 64px;
  height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.65rem;
  color: #555;
  padding: 4px;
  flex: none;
}
.format-btn svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.format-btn .ico { width: 30px; height: 30px; margin: 0; }
.format-btn:hover { background: #f8f8f8; }
.format-btn.active { background: #222; color: #fff; border-color: #222; }
.format-btn.active svg rect[fill="#fff"] { fill: #222; stroke: #fff; }

.thumb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.thumb { width: 100%; aspect-ratio: 1; object-fit: cover; cursor: grab; border-radius: 3px; background: #e5e5e5; display: block; box-sizing: border-box; }
.thumb:active { cursor: grabbing; }
.thumb.previewing { outline: 2px solid #2563eb; outline-offset: -2px; }

.draft-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.draft-list li { display: flex; align-items: center; gap: 4px; }
.draft-list button.draft-name { flex: 1; text-align: left; padding: 4px 6px; background: transparent; border: 1px solid transparent; border-radius: 3px; cursor: pointer; font-size: 0.8rem; }
.draft-list button.draft-name:hover { background: #fff; border-color: #ddd; }
.draft-list button.draft-name.active { background: #fff; border-color: #888; }
.draft-list button.draft-del { background: transparent; border: none; color: #999; cursor: pointer; font-size: 0.9rem; padding: 2px 6px; }
.draft-list button.draft-del:hover { color: #c00; }

.sort-row { display: flex; gap: 4px; }
.sort-btn { flex: 1; padding: 4px 6px; border: 1px solid #ddd; background: #fff; border-radius: 3px; cursor: pointer; font-size: 0.75rem; }
.sort-btn.active { background: #222; color: #fff; border-color: #222; }

.article {
  overflow: auto;
  padding: 24px;
  background: #f3efe0;
}
.article-header {
  display: flex; gap: 8px; align-items: center; margin-bottom: 16px;
  position: sticky; top: 0; left: 0;
  background: #f3efe0; padding: 8px 0; z-index: 10;
  width: max-content; min-width: 100%;
}
.article-header input { flex: 1; padding: 8px 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem; background: #fff; }
.zoom-controls { display: flex; gap: 4px; align-items: center; }
.zoom-controls button {
  padding: 6px 10px; border: 1px solid #ddd; background: #fff; color: #222;
  border-radius: 4px; cursor: pointer; font-size: 0.85rem; min-width: 32px;
}
.zoom-controls button:hover { background: #f0f0f0; }
.zoom-pct {
  font-size: 0.8rem; color: #666;
  width: 60px; text-align: center;
  font-variant-numeric: tabular-nums;
  display: inline-block;
}
.status { font-size: 0.8rem; color: #666; margin-left: 8px; }

.grid-canvas {
  position: relative;
  background-color: #fff;
  background-image:
    linear-gradient(to right, #ececec 1px, transparent 1px),
    linear-gradient(to bottom, #ececec 1px, transparent 1px);
  border: 1px solid #ddd;
  user-select: none;
  touch-action: none;
}

.canvas-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #aaa; font-size: 0.9rem; pointer-events: none;
}

.cell-hint {
  position: absolute;
  background: rgba(37, 99, 235, 0.15);
  border: 1px solid #2563eb;
  pointer-events: none;
  z-index: 1;
}

.gblock {
  position: absolute;
  cursor: move;
  border: 1px solid transparent;
  box-sizing: border-box;
  overflow: hidden;
  background: #ddd;
}
.gblock img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
/* Padded motif: the inset gaps show the canvas through instead of the block bg. */
.gblock.padded { background: transparent; }
.size-tag {
  position: absolute; left: 4px; top: 4px;
  background: rgba(0,0,0,0.65); color: #fff;
  font-size: 0.7rem; font-weight: 600; padding: 2px 5px; border-radius: 3px;
  pointer-events: none; letter-spacing: 0.02em;
}
.gblock:hover { border-color: #999; }
.gblock.selected { border-color: #2563eb; outline: 2px solid #2563eb; outline-offset: -2px; }

.block-x {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,0.6); color: #fff; border: none; cursor: pointer;
  opacity: 0; transition: opacity 0.15s;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; z-index: 3;
}
.gblock:hover .block-x, .gblock.selected .block-x,
.bounds-frame:hover .block-x, .bounds-frame.selected .block-x { opacity: 1; }
.block-x:hover { background: #c00; }

.handle {
  position: absolute; background: #2563eb; opacity: 0; transition: opacity 0.15s;
  z-index: 2;
}
.gblock:hover .handle, .gblock.selected .handle,
.bounds-frame:hover .handle, .bounds-frame.selected .handle { opacity: 0.85; }
.handle-r  { right: -3px; top: 0; bottom: 0; width: 6px; cursor: ew-resize; }
.handle-b  { bottom: -3px; left: 0; right: 0; height: 6px; cursor: ns-resize; }
.handle-br { right: -5px; bottom: -5px; width: 10px; height: 10px; cursor: nwse-resize; border-radius: 2px; }

.bounds-frame {
  position: absolute;
  border: 3px solid #000;
  cursor: move;
  box-sizing: border-box;
  pointer-events: auto;
  z-index: 4;
}
.bounds-frame.selected { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.4); }
.bounds-tag {
  position: absolute; top: -22px; left: 0;
  font-size: 0.7rem; font-weight: 600;
  background: #000; color: #fff; padding: 2px 6px; border-radius: 2px;
  letter-spacing: 0.05em; text-transform: uppercase;
}

.inspector {
  border-left: 1px solid #e5e5e5;
  background: #f4f4f4;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.inspector h2 { margin: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: #444; font-weight: 600; }
.inspector .muted { color: #888; font-size: 0.85rem; margin: 0; }
.inspector .small { font-size: 0.8rem; }
.inspector .field { display: flex; flex-direction: column; gap: 4px; }
.inspector .field label { font-size: 0.75rem; color: #555; font-weight: 600; }
.inspector .field input[type="number"] { padding: 6px 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 0.85rem; }
.preview-shell {
  width: 100%;
  background: #fafafa;
  border: 1px solid #e5e5e5;
  padding: 12px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-preview {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-preview img {
  max-width: 100%;
  max-height: 360px;
  display: block;
  background: #000;
}
.image-preview-close {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,0.65); color: #fff; border: none;
  cursor: pointer; font-size: 0.9rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.image-preview-close:hover { background: #c00; }

.toggle-btn {
  width: 100%; padding: 8px 10px;
  border: 1px solid #222; background: #fff; color: #222;
  border-radius: 4px; cursor: pointer; font-size: 0.85rem;
  font-weight: 500;
}
.toggle-btn:hover { background: #f0f0f0; }
.toggle-btn.active { background: #222; color: #fff; }

.bounds-frame.locked { pointer-events: none; }
.bounds-frame.locked .handle { pointer-events: auto; }

.inspector button.danger {
  padding: 6px 10px; background: #fff; color: #c00;
  border: 1px solid #c00; border-radius: 4px; cursor: pointer;
  font-size: 0.85rem;
}
.inspector button.danger:hover { background: #c00; color: #fff; }

.motifs-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 0;
}
.motifs-side {
  border-right: 1px solid #aaa;
  background: #ECE9D8;
  padding: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: "Tahoma", "Segoe UI", system-ui, sans-serif;
}
.xp-field {
  border-top: 1px solid #7B7B7B;
  border-left: 1px solid #7B7B7B;
  border-right: 1px solid #DFDFDF;
  border-bottom: 1px solid #DFDFDF;
  background: #fff;
  padding: 1px;
}
.motifs-search {
  width: 100%;
  padding: 3px 4px;
  border: none;
  outline: none;
  background: #fff;
  font: 11px Tahoma, "Segoe UI", system-ui, sans-serif;
  box-sizing: border-box;
}
.xp-listbox {
  flex: 1;
  min-height: 0;
  border-top: 1px solid #7B7B7B;
  border-left: 1px solid #7B7B7B;
  border-right: 1px solid #DFDFDF;
  border-bottom: 1px solid #DFDFDF;
  background: #fff;
  overflow-y: auto;
}
.motifs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.motifs-list li {
  padding: 1px 6px;
  cursor: default;
  font: 11px Tahoma, "Segoe UI", system-ui, sans-serif;
  color: #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  line-height: 1.45;
}
.motifs-list li.selected {
  background: #316AC5;
  color: #fff;
}
.motifs-list li.empty { color: #777; padding: 4px 6px; }

.browse {
  overflow-y: auto;
  padding: 1.5rem;
  background: #f3efe0;
}
.collections-frame {
  flex: 1;
  border: none;
  width: 100%;
  background: #f3efe0;
}
.browse-grid {
  column-width: 240px;
  column-gap: 1rem;
}
.draft-card {
  position: relative;
  display: inline-block;
  width: 100%;
  margin: 0 0 1rem;
  break-inside: avoid;
}
.draft-card-open {
  background: #fff;
  border: 1px solid #e4e4dd;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}
.draft-card.selected .draft-card-open {
  outline: 2px solid #316AC5;
  outline-offset: 0;
}

.copy-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 0.85rem;
  z-index: 1000;
  pointer-events: none;
}
.draft-card-del {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,0.6); color: #fff; border: none;
  cursor: pointer; opacity: 0; transition: opacity 0.15s;
  font-size: 0.9rem; z-index: 1;
}
.draft-card:hover .draft-card-del { opacity: 1; }
.draft-card-del:hover { background: #c00; }

.draft-icon {
  background: #fff;
  overflow: hidden;
  position: relative;
  width: var(--icon-w, 280px);
  height: var(--icon-h, 280px);
  max-width: 100%;
}
.draft-card-open .draft-icon { width: 100%; height: auto; aspect-ratio: 1; }
.draft-card-open .draft-icon.framed { width: 100%; height: auto; aspect-ratio: var(--bb-aspect, 1); }
.draft-icon.framed { background: #fff; overflow: hidden; }
.draft-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.draft-icon.empty {
  display: flex; align-items: center; justify-content: center;
  color: #ccc; font-size: 0.8rem; background: #f5f5f5;
}
.draft-icon.split-2, .draft-icon.split-3, .draft-icon.split-4 { display: grid; gap: 0; }
.draft-icon.split-2 { grid-template-columns: 1fr 1fr; }
.draft-icon.split-3 { grid-template-columns: 1fr 1fr; }
.draft-icon.split-3 > div { display: grid; grid-template-rows: 1fr 1fr; gap: 0; }
.draft-icon.split-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.draft-icon.new-icon {
  display: flex; align-items: center; justify-content: center;
  background: #f5f5f5; color: #bbb; font-size: 3rem; font-weight: 200;
  border: 1px dashed #ddd;
}
.new-card:hover .new-icon { background: #eee; color: #888; border-color: #aaa; }

/* ============= Essays (Medium-2014-style writing surface) ============= */

.essay-shell {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background: #f3efe0;
}
/* Export-to-site button, pinned to the top-right of the writing surface. */
.essay-export-btn {
  position: absolute;
  top: 16px;
  right: 20px;
  z-index: 6;
  border: 1px solid #1a8917;
  background: #fff;
  color: #1a8917;
  border-radius: 999px;
  padding: 6px 15px;
  font: 600 12px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  cursor: pointer;
}
.essay-export-btn:hover { background: #1a8917; color: #fff; }
.essay-export-btn:disabled { opacity: 0.6; cursor: default; }
.essay-export-btn.done { border-color: #1a8917; background: #1a8917; color: #fff; }
.essay-export-btn.error { border-color: #c0392b; color: #c0392b; }
/* Centered writing column. Also the positioning context for the floating
   toolbars (so they track the text/images as the page scrolls). */
.essay-page {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 24px 240px;
}
/* Plain Paul-Graham-style title: bold, but no special size, margin or padding —
   it reads as the first bold line of the document. */
.essay-title {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font: 700 15px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #000;
  margin: 0;
  padding: 0;
}
.essay-title::placeholder { color: #bbb; }

/* The ProseMirror editable lives inside .essay-body. */
.essay-body, .essay-body .ProseMirror {
  font: 400 15px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #000;
}
.essay-body .ProseMirror {
  outline: none;
  min-height: 60vh;
  caret-color: #000;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.essay-body .ProseMirror p { margin: 0; }
.essay-body .ProseMirror a { color: #1a8917; text-decoration: underline; }
/* Placeholder for an empty document. */
.essay-ph {
  position: absolute;
  color: #b3b3b3;
  pointer-events: none;
  height: 0;
}

/* --- Image blocks --- */
/* The <img> lives directly in the editable flow (no contenteditable=false
   wrapper) so the cursor moves through it natively. It's a block element, so it
   sits on its own line; margin:0 keeps it flush with the surrounding text. */
.essay-img {
  display: block;
  margin: 0;
  height: auto;
  cursor: pointer;
}
.essay-img-inset { width: 100%; }
.essay-img-wide {
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  width: min(1040px, 90vw);
}
.essay-img-full {
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
}
/* Image figure (NodeView) + embedded object share block/layout behaviour. */
.essay-fig, .essay-embed {
  display: block;
  margin: 0;
  cursor: pointer;
}
.essay-fig > img { display: block; width: 100%; height: auto; }
/* Legend / caption under an embedded image or object. */
.essay-legend {
  margin-top: 0.4rem;
  text-align: center;
  font: 400 12px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #8a8576;
  letter-spacing: 0.02em;
}
.essay-embed-missing {
  padding: 24px;
  text-align: center;
  color: #b3b3b3;
  border: 1px dashed #cbc6b4;
}

/* ProseMirror selected-node outline + drop cursor. */
.essay-img.ProseMirror-selectednode,
.essay-fig.ProseMirror-selectednode,
.essay-embed.ProseMirror-selectednode { outline: 2px solid #1a8917; outline-offset: 2px; }
.essay-dropcursor { background-color: #1a8917 !important; border-radius: 2px; }

.essay-drop-dim {
  position: absolute;
  top: 4px;
  left: 4px;
  background: #1a8917;
  color: #fff;
  font: 600 11px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  padding: 3px 6px;
  border-radius: 3px;
}

/* --- Floating toolbars (selection format bar + image layout bar) --- */
.essay-fmt-bar, .essay-img-bar {
  position: absolute;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: #1a1a1a;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  transform: translate(-50%, calc(-100% - 10px));
  white-space: nowrap;
}
.essay-fmt-bar::after, .essay-img-bar::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 10px; height: 10px;
  background: #1a1a1a;
  transform: translateX(-50%) rotate(45deg);
}
.essay-fmt-btn, .essay-img-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  border-radius: 4px;
  padding: 5px 9px;
  font-size: 0.9rem;
  line-height: 1;
}
.essay-fmt-btn:hover, .essay-img-btn:hover { background: rgba(255,255,255,0.16); }
.essay-fmt-btn.on { background: #1a8917; }
.essay-img-btn.active { background: #1a8917; }
.essay-img-btn.danger:hover { background: #c0392b; }
.essay-fmt-btn.bold { font-weight: 800; }
.essay-fmt-btn.ital { font-style: italic; font-family: Georgia, serif; }
.essay-fmt-btn.under { text-decoration: underline; }
.essay-bar-sep {
  width: 1px;
  align-self: stretch;
  margin: 2px 4px;
  background: rgba(255,255,255,0.22);
}
.essay-link-edit { display: flex; align-items: center; gap: 4px; }
.essay-link-input {
  border: none;
  outline: none;
  background: transparent;
  color: #fff;
  font-size: 0.9rem;
  padding: 4px 6px;
  width: 220px;
}
.essay-link-input::placeholder { color: rgba(255,255,255,0.45); }

/* --- Blog index (essays tab) --- */
.essay-index-shell {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  background: #f3efe0;
}
.essay-index {
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 24px 120px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.essay-index-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}
.essay-index-head h1 {
  margin: 0;
  font: 700 18px/1.3 "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #000;
}
.essay-new-btn {
  border: 1px solid #1a8917;
  background: #fff;
  color: #1a8917;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 0.9rem;
  cursor: pointer;
}
.essay-new-btn:hover { background: #1a8917; color: #fff; }
.essay-index-list { list-style: none; margin: 0; padding: 0; }
.essay-index-row {
  display: flex;
  align-items: baseline;
  gap: 0;
  padding: 11px 0;
  cursor: pointer;
}
.essay-index-title {
  flex: 0 1 auto;
  font: 400 15px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #000;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.essay-index-row:hover .essay-index-title { color: #1a8917; }
.essay-index-dots {
  flex: 1 1 auto;
  align-self: stretch;
  border-bottom: 2px dotted #cfcfcf;
  margin: 0 10px;
  transform: translateY(-5px);
  min-width: 24px;
}
.essay-index-date {
  flex: none;
  color: #9a9a9a;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.essay-index-del {
  flex: none;
  margin-left: 12px;
  border: none;
  background: transparent;
  color: #ccc;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0;
}
.essay-index-row:hover .essay-index-del { opacity: 1; }
.essay-index-del:hover { color: #c0392b; }
.essay-index-empty { color: #aaa; padding: 24px 0; }
