:root {
  --blue: #2196f3;
  --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);
}

/* Markdown view tabs (Edit / Preview) — quiet pills near the top margin */
.view-tabs {
  position: absolute;
  top: 0.55rem;
  left: calc(3.7rem + 10px + 0.8rem);
  z-index: 15;
  display: inline-flex;
  gap: 0.3rem;
}

.view-tabs[hidden] {
  display: none;
}

.view-tab {
  padding: 0.3rem 0.72rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 300 0.72rem/1 "Inter", system-ui, sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease;
}

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

.view-tab.active {
  color: var(--ink);
  background-color: color-mix(in srgb, var(--ink) 8%, transparent);
}

.view-tab:focus {
  outline: none;
}

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

/* 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 {
  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;
}

.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);
}

/* 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);
}

/* Share button — top-right inside the paper's top margin */
.share-button {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--grey-400);
  opacity: 0.7;
  cursor: pointer;
  transition: color 150ms ease, opacity 150ms ease;
}

.share-button:hover {
  color: var(--ink);
  opacity: 1;
}

.share-button .icon-check {
  display: none;
}

.share-button.copied {
  color: #2e9e5b;
}

.share-button.copied .icon-share {
  display: none;
}

.share-button.copied .icon-check {
  display: block;
}

/* 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;
  display: flex;
  justify-content: center;
  padding: 2rem 0 0;
}

.paper {
  position: relative;
  width: var(--paper-width, 1000px);
  max-width: 100%;
  height: calc(100vh - 2rem);
  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;
}

/* Soft fade at the bottom edge, so text melts away as it scrolls off */
#editor,
.preview {
  --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;
}

.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); }

.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-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 .share-button,
body.shared-view .shelves,
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);
}

/* ------------------------------------------------------------------ */
/* Mobile / small screens                                             */
/* ------------------------------------------------------------------ */
@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;
  }

  .view-tabs {
    top: 0.62rem;
    left: 3.05rem;
  }

  .share-button {
    top: 0.55rem;
    right: 0.5rem;
    width: 34px;
    height: 34px;
  }

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

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

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

  .ninja {
    display: none;
  }

  .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;
  }

  /* 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 {
    font-size: 16px;
  }
}
