:root {
  --blue: #2196f3;
  --todo-green: #43a047;
  --grey-50: #fafafa;
  --grey-100: #f5f5f5;
  --grey-200: #e5e5e5;
  --grey-300: #d4d4d4;
  --grey-400: #a3a3a3;
  --grey-500: #737373;
  --grey-700: #404040;
  --dark-bg1: #171717;
  --dark-bg2: #262626;
  --dark-hover: #525252;

  --stage-bg: var(--grey-50);
  --paper: #ffffff;
  --ink: #000000;
  --muted: var(--grey-400);

  --editor-font: "Merriweather", Georgia, "Times New Roman", serif;
  --editor-size: 1rem;
  --editor-wrap: pre-wrap;
}

[data-theme="dark"] {
  --stage-bg: var(--dark-bg1);
  --muted: var(--grey-500);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  background-color: var(--stage-bg);
  color: var(--ink);
  font-family: "Inter", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  transition: background-color 300ms ease;
  overflow: hidden;
}

/* Hamburger button — lives in the notebook left margin */
.menu-button {
  position: absolute;
  top: 1.05rem;
  left: calc((3.7rem + 10px - 34px) / 2);
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--grey-400);
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease;
}

.menu-button:hover {
  color: var(--blue);
  background-color: color-mix(in srgb, var(--blue) 12%, transparent);
}

/* Preview switch — under the hamburger, only there when there is a preview */
.preview-toggle {
  position: absolute;
  top: calc(1.05rem + 34px + 0.35rem);
  left: calc((3.7rem + 10px - 26px) / 2);
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--grey-400);
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease;
}

.preview-toggle[hidden] {
  display: none;
}

.preview-toggle:hover {
  color: var(--blue);
  background-color: color-mix(in srgb, var(--blue) 12%, transparent);
}

.preview-toggle[aria-pressed="true"] {
  color: var(--blue);
  background-color: color-mix(in srgb, var(--blue) 12%, transparent);
}

.preview-toggle:focus {
  outline: none;
}

.preview-toggle:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--ink) 28%, transparent);
  outline-offset: 2px;
}

/* Shelves — dots centered vertically in the left margin */
.shelves {
  position: absolute;
  left: calc((3.7rem + 10px) / 2);
  top: 50%;
  translate: -50% -50%;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.3rem;
  border: 1px solid color-mix(in srgb, var(--ink) 5%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 1.5%, var(--paper));
  transition: opacity 200ms ease;
}

.shelf {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shelf-dot {
  position: relative;
  width: 13px;
  height: 13px;
  padding: 0;
  border: 1.5px solid var(--grey-300);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

/* A 13px circle is too small for a fingertip, let alone for a long press.
   Vertically the padding stops just short of the 0.7rem gap, so neighbouring
   dots never steal each other's taps. */
.shelf-dot::after {
  content: "";
  position: absolute;
  inset: -5px -10px;
}

.shelf-dot:hover {
  border-color: var(--blue);
  transform: scale(1.15);
}

.shelf.active .shelf-dot {
  border-color: var(--blue);
  background-color: var(--blue);
}

[data-theme="dark"] .shelf-dot {
  border-color: var(--dark-hover);
}

[data-theme="dark"] .shelf.active .shelf-dot,
[data-theme="dark"] .shelf-dot:hover {
  border-color: var(--blue);
}

.shelf-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  padding: 0;
  border: 1.5px dashed var(--grey-300);
  border-radius: 50%;
  background: transparent;
  color: var(--grey-400);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.shelf-add:hover {
  border-color: var(--blue);
  color: var(--blue);
  transform: scale(1.15);
}

[data-theme="dark"] .shelf-add {
  border-color: var(--dark-hover);
}

/* Hide the shelves while the action menu is open, like the counter */
.paper.menu-open .shelves {
  opacity: 0;
  pointer-events: none;
}

/* Right-click context menu on a shelf dot */
.shelf-menu {
  position: fixed;
  z-index: 60;
  display: flex;
  flex-direction: column;
  min-width: 9rem;
  padding: 0.35rem;
  border-radius: 10px;
  background-color: #ffffff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .shelf-menu {
  background-color: var(--dark-bg2);
  border-color: var(--dark-hover);
  color: var(--grey-50);
}

.shelf-menu .menu-item.confirm {
  color: #e5484d;
}

.shelf-menu .menu-item.confirm:hover {
  color: #e5484d;
  background-color: color-mix(in srgb, #e5484d 12%, transparent);
}

.shelf-menu .menu-item.selected {
  color: var(--blue);
}

.menu-head {
  padding: 0.4rem 0.75rem 0.3rem;
  font: 600 0.68rem/1 "Inter", system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--grey-500);
}

[data-theme="dark"] .menu-head {
  color: var(--grey-400);
}

/* Names the folder you are working in and is the only way into folders. */
.folder-pill {
  position: absolute;
  top: 0.53rem;
  left: 50%;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  max-width: min(11rem, 32%);
  padding: 0.26rem 0.4rem 0.26rem 0.45rem;
  border: none;
  border-radius: 999px;
  background-color: transparent;
  color: var(--muted);
  font: 400 0.72rem/1 "Inter", system-ui, sans-serif;
  translate: -50% 0;
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease, opacity 200ms ease;
}

.folder-pill-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Without hover a plain word reads as a label, so the caret says "menu". */
.folder-pill-caret {
  flex: none;
  width: 11px;
  height: 11px;
  opacity: 0.65;
}

/* With no border of its own left, the pill only draws a shape when touched. */
.folder-pill:hover,
.folder-pill:active {
  background-color: color-mix(in srgb, var(--ink) 5%, transparent);
  color: var(--ink);
}

.folder-pill[hidden] {
  display: none;
}

.paper.menu-open .folder-pill {
  opacity: 0;
  pointer-events: none;
}

/* The folder list is the only part that may grow; the rest stays put. */
.folder-list {
  display: flex;
  flex-direction: column;
  max-height: min(45vh, 18rem);
  overflow-y: auto;
}

.folder-list[hidden] {
  display: none;
}

.folder-search {
  margin: 0.15rem 0.15rem 0.3rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 7px;
  background-color: transparent;
  color: inherit;
  font: 400 0.85rem/1 "Inter", system-ui, sans-serif;
}

.folder-search:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--blue) 55%, transparent);
}

[data-theme="dark"] .folder-search {
  border-color: rgba(255, 255, 255, 0.16);
}

/* Folder sheets reuse the share sheet's frame */
.folder-input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--grey-200);
  border-radius: 9px;
  background-color: transparent;
  color: inherit;
  font: 400 0.9rem/1.2 "Inter", system-ui, sans-serif;
}

.folder-input:focus {
  outline: none;
  border-color: var(--blue);
}

[data-theme="dark"] .folder-input {
  border-color: var(--dark-hover);
}

.folder-manage + .folder-manage {
  margin-top: 0.55rem;
}

.folder-row,
.folder-confirm {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.folder-row[hidden],
.folder-confirm[hidden] {
  display: none;
}

.folder-del,
.folder-confirm-cancel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.3rem;
  height: 2.3rem;
  flex: none;
  padding: 0;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--grey-400);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.folder-del:hover {
  background-color: color-mix(in srgb, #e5484d 12%, transparent);
  color: #e5484d;
}

.folder-confirm-cancel:hover {
  background-color: var(--grey-100);
  color: var(--ink);
}

[data-theme="dark"] .folder-confirm-cancel:hover {
  background-color: var(--dark-hover);
  color: var(--grey-50);
}

.folder-confirm-btn {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.7rem;
  border: none;
  border-radius: 9px;
  background-color: #e5484d;
  color: #fff;
  font: 600 0.85rem/1.2 "Inter", system-ui, sans-serif;
  text-align: left;
  cursor: pointer;
  transition: filter 150ms ease;
}

.folder-confirm-btn:hover {
  filter: brightness(1.06);
}

/* Ninja Boy easter egg — peeks up in the bottom-left corner */
.ninja {
  position: absolute;
  left: 1px;
  bottom: 40px;
  z-index: 12;
  width: 77px;
  height: 77px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 200ms ease, transform 200ms ease;
}

.menu-button:hover ~ .ninja,
.paper.menu-open .ninja {
  opacity: 1;
  transform: translateY(0);
}

/* Assistant side-panel toggle — outermost top-right corner */
.ai-toggle {
  position: absolute;
  top: calc(0.6rem - 5px);
  right: 0.55rem;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--grey-400);
  opacity: 0.7;
  cursor: pointer;
  transition: color 160ms ease, opacity 160ms ease;
}

.ai-toggle:hover {
  color: var(--ink);
  opacity: 1;
}

/* Share popover */
/* Share sheet — centered modal */
.share-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background-color: rgba(15, 15, 15, 0.12);
  transition: opacity 200ms ease;
}

.share-backdrop[hidden] {
  display: none;
}

.share-sheet {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 60;
  width: 25rem;
  max-width: calc(100vw - 2rem);
  padding: 1.75rem 1.75rem 1.6rem;
  border-radius: 18px;
  background-color: #ffffff;
  color: var(--ink);
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.45);
  translate: -50% -50%;
  transition: opacity 220ms ease, scale 220ms ease;
}

[data-theme="dark"] .share-sheet {
  background-color: var(--dark-bg2);
  color: var(--grey-50);
}

.share-sheet.closed {
  opacity: 0;
  scale: 0.96;
  pointer-events: none;
}

.share-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--grey-400);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.share-close:hover {
  background-color: var(--grey-100);
  color: var(--ink);
}

[data-theme="dark"] .share-close:hover {
  background-color: var(--dark-hover);
  color: var(--grey-50);
}

.share-sheet-title {
  margin: 0 0 0.3rem;
  font: 700 1.3rem/1.2 "Inter", system-ui, sans-serif;
}

.share-sheet-sub {
  margin: 0 0 1.4rem;
  font: 400 0.85rem/1.4 "Inter", system-ui, sans-serif;
  color: var(--muted);
}

.share-field {
  margin-bottom: 1.15rem;
}

.share-field-label {
  display: block;
  margin-bottom: 0.5rem;
  font: 600 0.72rem/1 "Inter", system-ui, sans-serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--grey-500);
}

[data-theme="dark"] .share-field-label {
  color: var(--grey-400);
}

.share-seg {
  display: flex;
  padding: 0.25rem;
  border-radius: 10px;
  background-color: var(--grey-100);
}

[data-theme="dark"] .share-seg {
  background-color: var(--dark-bg1);
}

.share-seg-btn {
  flex: 1;
  padding: 0.5rem 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: 500 0.85rem/1 "Inter", system-ui, sans-serif;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.share-seg-btn.selected {
  background-color: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

[data-theme="dark"] .share-seg-btn.selected {
  background-color: var(--dark-bg2);
  color: var(--grey-50);
}

.share-ttl {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.share-ttl-btn {
  padding: 0.5rem 0;
  border: 1.5px solid var(--grey-200);
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: 500 0.8rem/1 "Inter", system-ui, sans-serif;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease;
}

[data-theme="dark"] .share-ttl-btn {
  border-color: var(--dark-hover);
}

.share-ttl-btn:hover {
  border-color: var(--blue);
}

.share-ttl-btn.selected {
  border-color: var(--blue);
  background-color: color-mix(in srgb, var(--blue) 12%, transparent);
  color: var(--blue);
}

.share-create {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.75rem;
  border: none;
  border-radius: 11px;
  background-color: var(--blue);
  color: #fff;
  font: 600 0.95rem/1 "Inter", system-ui, sans-serif;
  cursor: pointer;
  transition: filter 150ms ease;
}

.share-create:hover {
  filter: brightness(1.06);
}

.share-create:disabled {
  opacity: 0.6;
  cursor: default;
}

.share-result {
  margin-top: 1.25rem;
}

.share-link-row {
  display: flex;
  gap: 0.5rem;
}

.share-link-input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.7rem;
  border: 1.5px solid var(--grey-200);
  border-radius: 10px;
  background-color: var(--grey-50);
  color: inherit;
  font: 400 0.85rem/1.2 "Inter", system-ui, sans-serif;
}

[data-theme="dark"] .share-link-input {
  border-color: var(--dark-hover);
  background-color: var(--dark-bg1);
}

.share-copy-btn {
  flex: none;
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: 10px;
  background-color: var(--blue);
  color: #fff;
  font: 600 0.85rem/1 "Inter", system-ui, sans-serif;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.share-copy-btn.copied {
  background-color: #22a06b;
}

.share-open {
  display: inline-block;
  margin-top: 0.7rem;
  font: 500 0.8rem/1 "Inter", system-ui, sans-serif;
  color: var(--blue);
  text-decoration: none;
}

.share-open:hover {
  text-decoration: underline;
}

.share-pop-status {
  margin-top: 1rem;
  font: 400 0.82rem/1.4 "Inter", system-ui, sans-serif;
  color: var(--muted);
  word-break: break-word;
}

.share-pop-status.error {
  color: #d64545;
}

/* Stage + paper */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  padding: 4px 0 0;
}

.paper {
  position: relative;
  width: var(--paper-width, 1000px);
  max-width: 100%;
  height: calc(100vh - 4px);
  padding: 2.2rem 1rem 3rem 1rem;
  border-radius: 13px 13px 0 0;
  background-color: var(--paper);
  box-shadow: 0 5px 15px 0 rgba(0, 0, 0, 0.05),
    0 5px 15px -5px rgba(25, 28, 33, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.04);
  transition: background-color 300ms ease;
}

/* Notebook red margin line — soft, like a school notebook */
.paper::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(3.7rem + 10px);
  width: 1.5px;
  background-color: rgba(255, 110, 115, 0.2);
  pointer-events: none;
  z-index: 0;
}

/* Punched holes — two perforator holes in the left margin. The stage
   shows through, and an inset shadow gives the paper edge some depth. */
.punch {
  display: none;
  position: absolute;
  left: calc((3.7rem + 10px) / 2);
  translate: -50% -50%;
  z-index: 2;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background-color: var(--stage-bg);
  box-shadow:
    inset 0 2px 3px rgba(0, 0, 0, 0.22),
    inset 0 -1px 2px rgba(0, 0, 0, 0.06),
    0 1px 1px rgba(255, 255, 255, 0.55);
  pointer-events: none;
  transition: background-color 300ms ease;
}

[data-punch="on"] .punch {
  display: block;
}

.punch-a {
  top: calc(50% - 110px);
}

.punch-b {
  top: calc(50% + 110px);
}

[data-theme="dark"] .punch {
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.75),
    inset 0 -1px 2px rgba(0, 0, 0, 0.4),
    0 1px 1px rgba(255, 255, 255, 0.05);
}

/* Drag handles to resize the editor width */
.resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12px;
  z-index: 5;
  cursor: ew-resize;
  touch-action: none;
}

.resizer-left {
  left: -6px;
}

.resizer-right {
  right: -6px;
}

.resizer::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 44px;
  translate: -50% -50%;
  border-radius: 4px;
  background-color: var(--grey-300);
  opacity: 0;
  transition: opacity 160ms ease, background-color 160ms ease;
}

.resizer:hover::before,
.resizer:focus-visible::before,
.paper.resizing .resizer::before {
  opacity: 1;
}

.resizer:hover::before,
.resizer:focus-visible::before {
  background-color: var(--blue);
}

[data-theme="dark"] .resizer::before {
  background-color: var(--dark-hover);
}

.paper.resizing {
  user-select: none;
}

.paper.resizing #editor {
  pointer-events: none;
}

#editor {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  padding: 0 1rem 0 calc(4.2rem + 15px);
  border: none;
  outline: none;
  resize: none;
  background-color: transparent;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--line-h, 27px) - 1px),
    var(--rule-color, color-mix(in srgb, var(--ink) 7%, transparent)) calc(var(--line-h, 27px) - 1px),
    var(--rule-color, color-mix(in srgb, var(--ink) 7%, transparent)) var(--line-h, 27px)
  );
  background-position: 0 var(--rule-offset, -6px);
  background-attachment: local;
  color: var(--ink);
  font-family: var(--editor-font);
  font-size: var(--editor-size);
  font-weight: 300;
  line-height: var(--line-h, 27px);
  white-space: var(--editor-wrap);
  overflow-wrap: break-word;
}

/* Mirror layer behind the textarea: renders the frozen context selection as a
   highlight that survives focus loss (a textarea can't paint its own selection
   once blurred). Geometry is copied from #editor in JS so wrap/scroll/font stay
   aligned. Only the marked span is visible; the rest is transparent scaffolding. */
.editor-highlights {
  position: absolute;
  z-index: 0;
  overflow: hidden;
  margin: 0;
  border: none;
  color: transparent;
  font-weight: 300;
  overflow-wrap: break-word;
  pointer-events: none;
  user-select: none;
}
.editor-highlights[hidden] {
  display: none;
}
.editor-hl-mark {
  border-radius: 2px;
  background-color: color-mix(in srgb, var(--blue, #2f6bff) 26%, transparent);
}

/* Soft fade at the bottom edge, so text melts away as it scrolls off */
#editor,
.preview,
.todo,
.editor-highlights {
  --fade-height: 2.6rem;
  -webkit-mask-image: linear-gradient(
    to bottom,
    #000 calc(100% - var(--fade-height)),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    #000 calc(100% - var(--fade-height)),
    transparent 100%
  );
}

#editor::placeholder {
  color: var(--muted);
}

#editor {
  scrollbar-color: var(--grey-300) transparent;
}

#editor::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

#editor::-webkit-scrollbar-track {
  background: transparent;
}

#editor::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 8px;
  background-clip: content-box;
  background-color: var(--grey-300);
}

[data-theme="dark"] #editor {
  scrollbar-color: var(--dark-hover) transparent;
}

[data-theme="dark"] #editor::-webkit-scrollbar-thumb {
  background-color: var(--dark-hover);
}

/* Rendered markdown preview — occupies the same box as the editor */
.preview {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  padding: 0 1rem 3rem calc(4.2rem + 15px);
  overflow-y: auto;
  color: var(--ink);
  font-family: var(--reading-font);
  font-size: var(--editor-size);
  font-weight: 300;
  line-height: 1.7;
  overflow-wrap: break-word;
  scrollbar-color: var(--grey-300) transparent;
}

.preview[hidden] {
  display: none;
}

.preview::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.preview::-webkit-scrollbar-track {
  background: transparent;
}

.preview::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 8px;
  background-clip: content-box;
  background-color: var(--grey-300);
}

[data-theme="dark"] .preview {
  scrollbar-color: var(--dark-hover) transparent;
}

[data-theme="dark"] .preview::-webkit-scrollbar-thumb {
  background-color: var(--dark-hover);
}

.preview > :first-child {
  margin-top: 0;
}

/* Nudge shown above the rendered markdown when "##Kop" misses its space */
.md-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 1.4rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background-color: color-mix(in srgb, var(--blue) 10%, transparent);
  color: var(--muted);
  font: 300 0.78rem/1.4 "Inter", system-ui, sans-serif;
}

.md-hint-fix,
.md-hint-ignore {
  padding: 0;
  border: none;
  background: transparent;
  color: var(--blue);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* Dismissing is the quieter of the two answers, so it reads quieter too */
.md-hint-ignore {
  color: var(--muted);
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
  font-family: var(--reading-font);
  font-weight: 600;
  line-height: 1.3;
  margin: 1.6em 0 0.6em;
}

.preview h1 { font-size: 1.8em; }
.preview h2 { font-size: 1.5em; }
.preview h3 { font-size: 1.25em; }

.preview p,
.preview ul,
.preview ol,
.preview blockquote,
.preview table {
  margin: 0 0 1em;
}

.preview a {
  color: var(--blue);
  text-decoration: underline;
}

.preview code {
  font-family: var(--code-font-family);
  font-size: 0.9em;
  padding: 0.15em 0.4em;
  border-radius: 5px;
  background-color: color-mix(in srgb, var(--ink) 8%, transparent);
}

.preview pre {
  margin: 0 0 1em;
  padding: 0.9rem 1rem;
  border-radius: 10px;
  overflow-x: auto;
  background-color: color-mix(in srgb, var(--ink) 6%, transparent);
}

.preview pre code {
  padding: 0;
  background: transparent;
}

.preview blockquote {
  padding-left: 1rem;
  border-left: 3px solid var(--grey-300);
  color: var(--grey-500);
}

[data-theme="dark"] .preview blockquote {
  border-left-color: var(--dark-hover);
}

.preview hr {
  border: none;
  border-top: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  margin: 1.6em 0;
}

.preview img {
  max-width: 100%;
  height: auto;
}

.preview table {
  border-collapse: collapse;
}

.preview th,
.preview td {
  padding: 0.4em 0.8em;
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
}

/* JSON tree preview — collapsible, colored */
.preview.json-preview {
  --jt-key: #2b6cb0;
  --jt-string: #2f855a;
  --jt-number: #b7791f;
  --jt-boolean: #805ad5;
  --jt-null: #718096;
  font-family: var(--code-font-family);
  font-size: 0.9em;
  line-height: 1.55;
}

[data-theme="dark"] .preview.json-preview {
  --jt-key: #63b3ed;
  --jt-string: #68d391;
  --jt-number: #f6ad55;
  --jt-boolean: #b794f4;
  --jt-null: #a0aec0;
}

.jt-row {
  white-space: pre-wrap;
  word-break: break-word;
}

.jt-children {
  margin-left: 0.55em;
  padding-left: 1.3em;
  border-left: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
}

.jt-toggle {
  display: inline-block;
  width: 1.1em;
  margin-left: -1.1em;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.jt-toggle:hover {
  color: var(--ink);
}

.jt-node.collapsed > .jt-children,
.jt-node.collapsed > .jt-foot {
  display: none;
}

.jt-collapsed-only {
  display: none;
}

.jt-node.collapsed > .jt-head .jt-collapsed-only {
  display: inline;
}

.jt-count {
  color: var(--muted);
  font-style: italic;
  opacity: 0.75;
}

.jt-key { color: var(--jt-key); }
.jt-string { color: var(--jt-string); }
.jt-number { color: var(--jt-number); }
.jt-boolean { color: var(--jt-boolean); }
.jt-null { color: var(--jt-null); }
.jt-punc { color: var(--muted); }

/* Todo mode — a live, editable list that replaces the textarea. Rows keep the
   ruled grid of the paper (line-height is exactly one rule, no margins).
   --todo-gutter is the margin line measured from the paper's content box, so the
   dots hang just past the red line; --todo-dot-x is that small gap and
   --todo-indent the strip the dots get, both the same at every width. */
.todo {
  --todo-gutter: calc(2.7rem + 10px);
  --todo-dot-x: 0.65rem;
  --todo-indent: 2rem;
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  padding: 0 1rem 3rem var(--todo-gutter);
  overflow-y: auto;
  color: var(--ink);
  font-family: var(--editor-font);
  font-size: var(--editor-size);
  font-weight: 300;
  line-height: var(--line-h, 27px);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--line-h, 27px) - 1px),
    var(--rule-color, color-mix(in srgb, var(--ink) 7%, transparent)) calc(var(--line-h, 27px) - 1px),
    var(--rule-color, color-mix(in srgb, var(--ink) 7%, transparent)) var(--line-h, 27px)
  );
  background-position: 0 var(--rule-offset, -6px);
  background-attachment: local;
  scrollbar-color: var(--grey-300) transparent;
}

.todo[hidden] {
  display: none;
}

.todo::-webkit-scrollbar {
  width: 10px;
}

.todo::-webkit-scrollbar-track {
  background: transparent;
}

.todo::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 8px;
  background-clip: content-box;
  background-color: var(--grey-300);
}

[data-theme="dark"] .todo {
  scrollbar-color: var(--dark-hover) transparent;
}

[data-theme="dark"] .todo::-webkit-scrollbar-thumb {
  background-color: var(--dark-hover);
}

.todo-row {
  position: relative;
  padding-left: var(--todo-indent);
}

.todo-row.sub {
  padding-left: calc(var(--todo-indent) + 2rem);
}

.todo-text {
  min-height: var(--line-h, 27px);
  outline: none;
  white-space: var(--editor-wrap);
  overflow-wrap: break-word;
}

.todo-row.done .todo-text {
  color: var(--muted);
  text-decoration: line-through;
}

.todo-text:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.todo-dot {
  position: absolute;
  top: calc((var(--line-h, 27px) - 1.05rem) / 2);
  left: var(--todo-dot-x);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  padding: 0;
  border: 1.5px solid var(--grey-300);
  border-radius: 50%;
  background-color: transparent;
  color: transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.todo-row.sub .todo-dot {
  top: calc((var(--line-h, 27px) - 0.85rem) / 2);
  left: calc(var(--todo-indent) + var(--todo-dot-x) + 0.1rem);
  width: 0.85rem;
  height: 0.85rem;
}

.todo-dot svg {
  width: 70%;
  height: 70%;
}

.todo-dot:hover {
  border-color: var(--blue);
}

.todo-row.done .todo-dot {
  border-color: var(--blue);
  background-color: var(--blue);
  color: #ffffff;
}

/* A task being worked on: filled, but without the check mark, so it never
   reads as finished at a glance. */
.todo-row.busy .todo-dot {
  border-color: var(--todo-green);
  background-color: var(--todo-green);
}

.todo-row.busy .todo-dot svg {
  display: none;
}

/* A blank line is spacing between groups, not a task */
.todo-row.spacer .todo-dot {
  display: none;
}

/* The dot's menu leads with the three states, each carrying the very dot it
   will put on the line, so the choice reads the same as the result. */
.todo-state {
  gap: 0.55rem;
}

.todo-state.selected {
  font-weight: 600;
}

.todo-state-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 1.05rem;
  height: 1.05rem;
  border: 1.5px solid var(--grey-300);
  border-radius: 50%;
  color: #ffffff;
}

.todo-state-dot svg {
  width: 70%;
  height: 70%;
}

.todo-state[data-state="busy"] .todo-state-dot {
  border-color: var(--todo-green);
  background-color: var(--todo-green);
}

.todo-state[data-state="done"] .todo-state-dot {
  border-color: var(--blue);
  background-color: var(--blue);
}

/* The main task repeated above a lifted sub-task: context only, so it carries
   no dot and cannot be edited there. */
.todo-caption {
  min-height: var(--line-h, 27px);
  padding-left: var(--todo-indent);
  color: var(--muted);
  user-select: none;
}

/* Divider between the open block and the completed block. Exactly one rule
   high, so every row below it stays on the ruled grid. */
.todo-sep {
  display: flex;
  align-items: center;
  height: var(--line-h, 27px);
  padding-left: var(--todo-indent);
}

.todo-sep::before {
  content: "";
  flex: 1;
  height: 1px;
  background-color: color-mix(in srgb, var(--ink) 16%, transparent);
}

/* Frozen Assistant context inside the list. The CSS Custom Highlight API
   paints the range without touching the editable content. */
::highlight(texty-ctx) {
  background-color: color-mix(in srgb, var(--blue, #2f6bff) 26%, transparent);
}

.counter {
  position: absolute;
  left: 0;
  bottom: 0.9rem;
  width: calc(3.7rem + 10px);
  user-select: none;
  transition: opacity 200ms ease;
}

.menu-button:hover ~ .counter,
.paper.menu-open .counter {
  opacity: 0;
}

.counter-line {
  margin: 0;
  color: var(--grey-300);
  font-family: "Courier Prime", monospace;
  font-size: 0.9rem;
  line-height: 1.35;
  text-align: center;
}

/* Build version — quiet link to the commit history */
.build-version {
  position: fixed;
  right: 0.7rem;
  bottom: 0.55rem;
  z-index: 15;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font: 300 0.68rem/1 "Inter", system-ui, sans-serif;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 200ms ease, color 200ms ease;
}

.build-version:focus {
  outline: none;
}

.build-version:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--ink) 28%, transparent);
  outline-offset: 3px;
  border-radius: 4px;
}

.build-version:hover {
  opacity: 0.9;
  color: var(--ink);
}

.build-version[hidden] {
  display: none;
}

/* Overlay behind menu */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  background-color: transparent;
}

.overlay[hidden] {
  display: none;
}

/* Hamburger action menu */
.menu {
  position: absolute;
  top: 3.2rem;
  left: 0.2rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 15rem;
  padding: 0.5rem;
  border-radius: 10px;
  background-color: #ffffff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.12);
  transition: opacity 220ms ease, translate 220ms ease;
}

[data-theme="dark"] .menu {
  background-color: var(--dark-bg2);
  border-color: var(--dark-hover);
  color: var(--grey-50);
}

.menu.closed {
  opacity: 0;
  translate: 0 -14px;
  pointer-events: none;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-family: "Inter", sans-serif;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.menu-item:hover {
  background-color: color-mix(in srgb, var(--blue) 14%, transparent);
  color: var(--ink);
}

.menu-item[hidden] {
  display: none;
}

/* "Switch to.." and its Text / Code / Markdown submenu */
.menu-sub {
  position: relative;
  display: flex;
  flex-direction: column;
}

.menu-parent {
  justify-content: space-between;
  gap: 1rem;
}

.menu-parent-caret {
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  transition: rotate 140ms ease;
}

.menu-sub.open .menu-parent-caret {
  rotate: 90deg;
}

.menu-flyout {
  position: absolute;
  top: -0.5rem;
  left: 100%;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-width: 10rem;
  margin-left: 0.35rem;
  padding: 0.5rem;
  border-radius: 10px;
  background-color: #ffffff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .menu-flyout {
  background-color: var(--dark-bg2);
  border-color: var(--dark-hover);
  color: var(--grey-50);
}

.menu-flyout[hidden] {
  display: none;
}

.menu-flyout .menu-item.selected {
  color: var(--blue);
}

.menu-sep {
  height: 1px;
  margin: 0.35rem 0.4rem;
  background-color: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .menu-sep {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Modern settings modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background-color: transparent;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 50;
  width: 30rem;
  max-width: calc(100vw - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: 2.25rem;
  border-radius: 16px;
  background-color: #ffffff;
  color: #171717;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.4);
  translate: -50% -50%;
  transition: opacity 220ms ease, scale 220ms ease;
}

[data-theme="dark"] .modal {
  background-color: var(--dark-bg2);
  color: var(--grey-50);
}

.modal.closed {
  opacity: 0;
  scale: 0.96;
  pointer-events: none;
}

.modal-title {
  margin: 0 0 1.25rem;
  font-size: 1.6rem;
  font-weight: 700;
}

.modal-tabs {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.6rem;
  border-bottom: 1px solid var(--grey-200);
}

[data-theme="dark"] .modal-tabs {
  border-bottom-color: var(--dark-hover);
}

.modal-tab {
  margin-bottom: -1px;
  padding: 0 0.15rem 0.55rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--grey-500);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease;
}

[data-theme="dark"] .modal-tab {
  color: var(--grey-400);
}

.modal-tab:hover {
  color: inherit;
}

.modal-tab.selected {
  color: inherit;
  border-bottom-color: var(--blue);
}

/* Stack both panes in the same grid cell so the dialog keeps the height
   of the tallest pane and never jumps when switching tabs */
.modal-panes {
  display: grid;
}

.modal-pane {
  grid-area: 1 / 1;
  min-width: 0;
}

.modal-pane[hidden] {
  display: block;
  visibility: hidden;
  pointer-events: none;
}

.field {
  margin-bottom: 1.5rem;
}

.field-label {
  display: block;
  margin-bottom: 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--grey-500);
}

[data-theme="dark"] .field-label {
  color: var(--grey-400);
}

.choice-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.choice {
  padding: 0.8rem 1rem;
  border: 1.5px solid var(--grey-200);
  border-radius: 10px;
  background-color: transparent;
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease;
}

[data-theme="dark"] .choice {
  border-color: var(--dark-hover);
}

.choice:hover {
  border-color: var(--blue);
}

.choice.selected {
  border-color: var(--blue);
  background-color: color-mix(in srgb, var(--blue) 10%, transparent);
}

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 0.25rem;
  border-radius: 10px;
  background-color: var(--grey-100);
}

[data-theme="dark"] .segmented {
  background-color: var(--dark-bg1);
}

.segment {
  padding: 0.5rem 1.6rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.segment.selected {
  background-color: var(--blue);
  color: #fff;
}

.bg-slider {
  width: 100%;
  height: 1.6rem;
  margin: 0;
  padding: 0;
  border-radius: 999px;
  border: 1.5px solid var(--grey-200);
  background: linear-gradient(to right, #ffffff, #ffe5b8);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

[data-theme="dark"] .bg-slider {
  border-color: var(--dark-hover);
}

.bg-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background-color: #ffffff;
  border: 2px solid var(--blue);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.bg-slider::-moz-range-thumb {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background-color: #ffffff;
  border: 2px solid var(--blue);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.window-color {
  width: 100%;
  height: 2.4rem;
  margin: 0;
  padding: 0.2rem;
  border-radius: 10px;
  border: 1.5px solid var(--grey-200);
  background: transparent;
  cursor: pointer;
}

[data-theme="dark"] .window-color {
  border-color: var(--dark-hover);
}

.window-color::-webkit-color-swatch-wrapper {
  padding: 0;
}

.window-color::-webkit-color-swatch {
  border: none;
  border-radius: 7px;
}

.window-color::-moz-color-swatch {
  border: none;
  border-radius: 7px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 2rem;
}

.ok-button {
  min-width: 5.5rem;
  padding: 0.6rem 1.4rem;
  border: none;
  border-radius: 10px;
  background-color: var(--blue);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 150ms ease;
}

.ok-button:hover {
  filter: brightness(1.06);
}

/* ------------------------------------------------------------------ */
/* Shared link view — isolated, read-only                             */
/* ------------------------------------------------------------------ */
body.shared-view .ai-toggle,
body.shared-view .shelves,
body.shared-view .folder-pill,
body.shared-view .menu-item[data-action="link"],
body.shared-view .menu-item[data-action="manage"],
body.shared-view .menu-item[data-action="new"] {
  display: none;
}

.menu-item[data-action="import"] {
  display: none;
}

body.shared-view .menu-item[data-action="import"] {
  display: flex;
}

.shared-gone {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
}

.shared-gone-text {
  margin: 0;
  color: var(--muted);
  font: 300 1.05rem/1.5 "Inter", system-ui, sans-serif;
}

.shared-gone-link {
  padding: 0.55rem 1.3rem;
  border-radius: 999px;
  background-color: var(--blue);
  color: #fff;
  font: 500 0.9rem/1 "Inter", system-ui, sans-serif;
  text-decoration: none;
  transition: filter 150ms ease;
}

.shared-gone-link:hover {
  filter: brightness(1.06);
}

/* ------------------------------------------------------------------ */
/* ChatGPT-style AI side panel                                        */
/* ------------------------------------------------------------------ */
:root {
  --ai-width: min(38vw, 460px);
}

.ai-panel {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  width: var(--ai-width);
  flex-direction: column;
  background-color: var(--stage-bg);
  border-left: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
  transition: background-color 300ms ease;
}

[data-ai="on"] .ai-panel {
  display: flex;
}

/* Make room so the centered paper sits left of the panel */
[data-ai="on"] .stage {
  padding-right: var(--ai-width);
}

/* Dim backdrop behind the centred overlay (only shown in that mode) */
.ai-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 39;
  background-color: rgba(15, 15, 15, 0.18);
}

.ai-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  flex: 0 0 auto;
}

.ai-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

.ai-head-actions {
  display: flex;
  gap: 0.15rem;
}

.ai-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--grey-500);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.ai-icon-btn:hover {
  background-color: color-mix(in srgb, var(--ink) 7%, transparent);
  color: var(--ink);
}

.ai-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.ai-empty {
  margin: auto;
  color: var(--muted);
  font-size: 1.05rem;
  text-align: center;
}

.ai-icon-btn[aria-pressed="true"] {
  background-color: color-mix(in srgb, var(--ink) 9%, transparent);
  color: var(--ink);
}

/* History popover — floats above the chat so it never blends into the message list */
.ai-history-pop {
  position: absolute;
  inset: 0;
  z-index: 46;
}

.ai-history-pop[hidden] {
  display: none;
}

.ai-history-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(15, 15, 15, 0.18);
}

.ai-history-card {
  position: absolute;
  top: 3.4rem;
  left: 0.6rem;
  right: 0.6rem;
  bottom: 0.6rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 14px;
  background-color: var(--paper);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .ai-history-card {
  background-color: var(--dark-bg2);
  border-color: var(--dark-hover);
}

.ai-history-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.5rem 0.5rem 0.85rem;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
}

.ai-history-heading {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.ai-history {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5rem 0.6rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-history-item {
  display: flex;
  align-items: stretch;
  gap: 2px;
  border-radius: 10px;
}

.ai-history-item:hover {
  background-color: color-mix(in srgb, var(--ink) 5%, transparent);
}

.ai-history-item.active {
  background-color: color-mix(in srgb, var(--ink) 7%, transparent);
}

.ai-history-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.55rem 0.65rem;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  border-radius: 10px;
}

.ai-history-title {
  font-size: 0.9rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-history-meta {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-history-del {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  border: none;
  background: transparent;
  color: var(--grey-500);
  cursor: pointer;
  border-radius: 10px;
  opacity: 0;
  transition: opacity 150ms ease, color 150ms ease, background-color 150ms ease;
}

.ai-history-item:hover .ai-history-del,
.ai-history-item.active .ai-history-del {
  opacity: 1;
}

.ai-history-del:hover {
  color: var(--ink);
  background-color: color-mix(in srgb, var(--ink) 8%, transparent);
}

@media (hover: none) {
  .ai-history-del {
    opacity: 1;
  }
}

.ai-msg {
  max-width: 100%;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-msg.user {
  align-self: flex-end;
  max-width: 85%;
  padding: 0.55rem 0.85rem;
  border-radius: 18px;
  background-color: color-mix(in srgb, var(--ink) 6%, transparent);
}

.ai-msg.assistant {
  align-self: flex-start;
}

.ai-msg.md {
  white-space: normal;
}

.ai-msg.md > *:first-child {
  margin-top: 0;
}

.ai-msg.md > *:last-child {
  margin-bottom: 0;
}

.ai-msg.md p {
  margin: 0 0 0.6rem;
}

.ai-msg.md ul,
.ai-msg.md ol {
  margin: 0 0 0.6rem;
  padding-left: 1.25rem;
}

.ai-msg.md li {
  margin: 0.15rem 0;
}

.ai-msg.md h1,
.ai-msg.md h2,
.ai-msg.md h3,
.ai-msg.md h4 {
  margin: 0.8rem 0 0.4rem;
  font-weight: 600;
  line-height: 1.3;
}

.ai-msg.md h1 { font-size: 1.15rem; }
.ai-msg.md h2 { font-size: 1.08rem; }
.ai-msg.md h3 { font-size: 1rem; }
.ai-msg.md h4 { font-size: 0.95rem; }

.ai-msg.md a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-msg.md code {
  font-family: "SF Mono", ui-monospace, "Menlo", monospace;
  font-size: 0.85em;
  padding: 0.1rem 0.3rem;
  border-radius: 5px;
  background-color: color-mix(in srgb, var(--ink) 7%, transparent);
}

.ai-msg.md pre {
  margin: 0 0 0.6rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  background-color: color-mix(in srgb, var(--ink) 6%, transparent);
  overflow-x: auto;
}

.ai-msg.md pre code {
  padding: 0;
  background: none;
  font-size: 0.85em;
}

.ai-msg.md blockquote {
  margin: 0 0 0.6rem;
  padding-left: 0.8rem;
  border-left: 2px solid color-mix(in srgb, var(--ink) 18%, transparent);
  color: var(--muted);
}

.ai-msg.md strong { font-weight: 600; }

.ai-msg.md hr {
  border: none;
  border-top: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  margin: 0.8rem 0;
}

.ai-msg .ai-cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  vertical-align: text-bottom;
  background-color: var(--ink);
  opacity: 0.6;
  animation: ai-blink 1s steps(1) infinite;
}

@keyframes ai-blink {
  50% { opacity: 0; }
}

/* API-key entry (Settings › Assistant) */
.field-hint {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
}

.ai-key-row {
  display: flex;
  gap: 0.4rem;
}

.ai-key-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid color-mix(in srgb, var(--ink) 14%, transparent);
  border-radius: 9px;
  background-color: var(--paper);
  color: var(--ink);
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
}

.ai-key-input:focus {
  outline: none;
  border-color: var(--blue);
}

.ai-key-save {
  flex: 0 0 auto;
  padding: 0.5rem 0.9rem;
  border: none;
  border-radius: 9px;
  background-color: var(--blue);
  color: #fff;
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.ai-key-save.saved {
  background-color: var(--green, #2e7d32);
}

.ai-key-get {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
}

.ai-key-get:hover {
  color: var(--blue);
}

/* Composer */
/* Frozen selection shown as the context that gets sent with each message */
.ai-ctx {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.5rem 1rem 0;
  padding: 0.35rem 0.4rem 0.35rem 0.6rem;
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 12px;
  background-color: color-mix(in srgb, var(--ink) 4%, transparent);
  font-size: 0.8rem;
}

.ai-ctx[hidden] {
  display: none;
}

.ai-ctx-icon {
  flex: 0 0 auto;
  color: var(--grey-500);
}

.ai-ctx-label {
  flex: 0 0 auto;
  color: var(--muted);
}

.ai-ctx-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  opacity: 0.85;
}

.ai-ctx-remove {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--grey-500);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.ai-ctx-remove:hover {
  background-color: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
}

.ai-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  margin: 0.5rem 1rem 1rem;
  padding: 0.4rem 0.4rem 0.4rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 24px;
  background-color: var(--paper);
  transition: border-color 150ms ease;
}

.ai-composer:focus-within {
  border-color: color-mix(in srgb, var(--ink) 24%, transparent);
}

.ai-input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 160px;
  padding: 0.35rem 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-family: "Inter", sans-serif;
  font-size: 0.92rem;
  line-height: 1.5;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ai-input::-webkit-scrollbar {
  display: none;
}

.ai-send {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background-color: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: opacity 150ms ease;
}

.ai-send:disabled {
  opacity: 0.35;
  cursor: default;
}

[data-ai="on"] .build-version {
  right: calc(var(--ai-width) + 0.7rem);
}

/* ------------------------------------------------------------------ */
/* Mobile / small screens                                             */
/* ------------------------------------------------------------------ */
/* Not enough room to dock on the right → float the panel centred over the
   paper instead of squeezing it. */
@media (min-width: 701px) and (max-width: 1150px) {
  [data-ai="on"] .stage {
    padding-right: 0;
  }

  [data-ai="on"] .ai-backdrop {
    display: block;
  }

  .ai-panel {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
    width: min(440px, calc(100vw - 3rem));
    height: min(78vh, 700px);
    border: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
    overflow: hidden;
  }

  [data-ai="on"] .build-version {
    right: 0.7rem;
  }
}

@media (max-width: 700px) {
  .stage {
    padding: 0;
  }

  .paper {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: 2.6rem 0.4rem calc(1.2rem + env(safe-area-inset-bottom)) 0.4rem;
    border-radius: 0;
    box-shadow: none;
  }

  /* Narrower notebook gutter to reclaim horizontal space */
  .paper::before {
    left: 2.6rem;
  }

  .punch {
    left: 1.3rem;
    width: 15px;
    height: 15px;
  }

  .menu-button {
    top: 0.5rem;
    left: 0.3rem;
  }

  .shelves {
    left: 1.3rem;
  }

  .counter {
    width: 2.6rem;
  }

  .preview-toggle {
    top: calc(0.5rem + 34px + 0.35rem);
    left: calc(0.3rem + 4px);
  }

  .ai-toggle {
    top: 0.55rem;
    right: 0.4rem;
    width: 34px;
    height: 34px;
  }

  #editor {
    padding: 0 0.7rem 0 3.05rem;
  }

  .preview {
    padding: 0 0.7rem 2rem 3.05rem;
  }

  /* The notebook gutter is narrower here, so the dots follow it inwards. */
  .todo {
    --todo-gutter: 2.2rem;
    padding-right: 0.7rem;
  }

  /* No width dragging and no easter egg on phones */
  .resizer {
    display: none;
  }

  .ninja {
    display: none;
  }

  /* Full-screen panel on phones; it overlays the paper */
  :root {
    --ai-width: 100vw;
  }

  [data-ai="on"] .stage {
    padding-right: 0;
  }

  .ai-panel {
    border-left: none;
  }

  [data-ai="on"] .build-version {
    right: 0.7rem;
  }

  .counter {
    bottom: 0.7rem;
    width: 2.6rem;
    overflow: visible;
  }

  /* Right-align against the margin so wide numbers spill into the empty
     left edge instead of overlapping the text */
  .counter-line {
    padding-right: 0.3rem;
    font-size: 0.7rem;
    text-align: right;
    white-space: nowrap;
  }

  .menu {
    top: 2.7rem;
    left: 0.3rem;
    right: 0.3rem;
    min-width: 0;
  }

  .menu-item {
    padding: 0.8rem 0.75rem;
    font-size: 0.95rem;
  }

  /* No room for a flyout next to a full-width menu — unfold in place */
  .menu-flyout {
    position: static;
    min-width: 0;
    margin: 0 0 0.2rem 0.9rem;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  /* Settings + share sheets fill most of the screen and scroll if tall */
  .modal,
  .share-sheet {
    width: calc(100vw - 1.4rem);
    max-width: calc(100vw - 1.4rem);
    max-height: calc(100dvh - 1.4rem);
    overflow-y: auto;
    padding: 1.5rem 1.25rem 1.3rem;
    border-radius: 16px;
  }

  .modal-title {
    margin-bottom: 1.25rem;
    font-size: 1.35rem;
  }

  /* 16px inputs prevent iOS from zooming on focus */
  .share-link-input,
  .folder-input,
  .folder-search {
    font-size: 16px;
  }

  /* Nothing shares the top bar with the pill any more, so it can stay in the
     middle; only the width has to give way to the toggle on either side. */
  .folder-pill {
    max-width: 42%;
  }
}
