:root {
  color-scheme: dark;
  --night: #0b0b0f;
  --night-soft: #111117;
  --paper: #f7f4ec;
  --paper-muted: #a8a3af;
  --paper-faint: #918b98;
  --glass: rgba(23, 22, 30, 0.72);
  --glass-strong: rgba(28, 27, 35, 0.94);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --accent: #ff735c;
  --accent-rgb: 255, 115, 92;
  --danger: #ff6b72;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
  --spring: cubic-bezier(0.22, 1.34, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --editor-width: 52rem;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

/* Component display rules must never override the native hidden state. */
[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--night);
}

html {
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
  color: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button,
[contenteditable="true"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 78% 118%, rgba(var(--accent-rgb), 0.09), transparent 38%),
    radial-gradient(circle at 15% -15%, rgba(255, 255, 255, 0.028), transparent 34%),
    var(--night);
  transition: background 600ms var(--ease-out);
}

.app::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.016) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at 50% 42%, #000, transparent 82%);
}

.ambient-glow {
  position: fixed;
  z-index: -1;
  width: 34rem;
  height: 34rem;
  right: -18rem;
  bottom: -20rem;
  border-radius: 50%;
  background: rgba(var(--accent-rgb), 0.13);
  filter: blur(90px);
  transform: translate3d(var(--glow-x, 0), var(--glow-y, 0), 0);
  transition:
    background 500ms var(--ease-out),
    transform 900ms var(--ease-out),
    opacity 300ms ease;
  opacity: 0.8;
  pointer-events: none;
}

.app.is-writing .ambient-glow {
  opacity: 1;
  transform: translate3d(var(--glow-x, 0), var(--glow-y, 0), 0) scale(1.08);
}

/* The resting page only carries the note switcher and new-note affordance. */
.topbar {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  transition: opacity 500ms var(--ease-out);
}

.topbar > * {
  pointer-events: auto;
}

.app.chrome-idle .note-switcher,
.app.chrome-idle .new-note {
  border-color: transparent;
  background: rgba(18, 18, 24, 0.42);
  box-shadow: none;
}

.note-switcher,
.new-note,
.round-button {
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.055);
}

.note-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(310px, calc(100vw - 86px));
  min-height: 42px;
  padding: 7px 9px 7px 11px;
  border-radius: 14px;
  color: var(--paper-muted);
  cursor: pointer;
  transition:
    color 180ms ease,
    background 180ms ease,
    border-color 180ms ease,
    transform 220ms var(--spring);
}

.note-switcher:hover {
  color: var(--paper);
  background: rgba(32, 31, 40, 0.88);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.note-switcher:active {
  transform: scale(0.97);
}

.note-switcher-spark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 15px;
  filter: drop-shadow(0 0 8px rgba(var(--accent-rgb), 0.42));
  transition: transform 350ms var(--spring), color 350ms ease;
}

.note-switcher:hover .note-switcher-spark {
  transform: rotate(18deg) scale(1.14);
}

.note-switcher-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: currentColor;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.note-switcher-count {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--paper-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.new-note,
.round-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 14px;
  color: var(--paper-muted);
  font-size: 23px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  transition:
    color 180ms ease,
    background 180ms ease,
    border-color 180ms ease,
    transform 280ms var(--spring);
}

.new-note:hover,
.round-button:hover {
  color: var(--paper);
  background: rgba(32, 31, 40, 0.9);
  border-color: var(--line-strong);
  transform: rotate(5deg) scale(1.04);
}

.new-note:active,
.round-button:active {
  transform: rotate(0) scale(0.9);
}

.new-note.is-popping {
  animation: new-note-pop 520ms var(--spring);
}

@keyframes new-note-pop {
  0% { transform: scale(1); }
  35% { transform: scale(0.72) rotate(-14deg); color: var(--accent); }
  70% { transform: scale(1.18) rotate(8deg); }
  100% { transform: scale(1); }
}

.workspace {
  position: absolute;
  inset: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

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

.workspace::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border: 3px solid transparent;
  border-radius: 10px;
  background-clip: padding-box;
}

.editor {
  position: relative;
  width: min(var(--editor-width), calc(100% - 8rem));
  min-height: 100%;
  margin: 0 auto;
  padding: clamp(7rem, 15vh, 10rem) 0 9rem;
  outline: none;
  color: var(--paper);
  caret-color: var(--accent);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  font-size: clamp(19px, 1.35vw, 22px);
  font-weight: 450;
  line-height: 1.68;
  letter-spacing: -0.022em;
  overflow-wrap: anywhere;
  hanging-punctuation: first last;
  text-wrap: pretty;
}

.editor:focus-visible {
  outline: none;
}

.editor::selection,
.editor *::selection {
  color: var(--paper);
  background: rgba(var(--accent-rgb), 0.34);
}

body.long-press-armed,
body.long-press-armed * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.editor.is-empty::before {
  content: attr(data-placeholder);
  position: absolute;
  inset-inline-start: 0;
  max-width: 24ch;
  color: rgba(247, 244, 236, 0.54);
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", serif;
  font-size: 1.28em;
  font-style: italic;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: -0.015em;
  pointer-events: none;
  animation: prompt-arrive 650ms var(--ease-out) both;
}

@keyframes prompt-arrive {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.editor.page-enter-next {
  animation: page-enter-next 380ms var(--ease-out);
}

.editor.page-enter-prev {
  animation: page-enter-prev 380ms var(--ease-out);
}

.editor.page-enter-new {
  animation: page-enter-new 520ms var(--spring);
}

@keyframes page-enter-next {
  from { opacity: 0; transform: translateX(18px); filter: blur(3px); }
  to { opacity: 1; transform: translateX(0); filter: blur(0); }
}

@keyframes page-enter-prev {
  from { opacity: 0; transform: translateX(-18px); filter: blur(3px); }
  to { opacity: 1; transform: translateX(0); filter: blur(0); }
}

@keyframes page-enter-new {
  0% { opacity: 0; transform: scale(0.985) translateY(12px); }
  70% { opacity: 1; transform: scale(1.004) translateY(-1px); }
  100% { transform: scale(1) translateY(0); }
}

.gesture-hint {
  position: absolute;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 20px));
  z-index: 4;
  margin: 0;
  padding: 7px 11px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.065);
  border-radius: 999px;
  background: rgba(17, 17, 23, 0.58);
  color: rgba(247, 244, 236, 0.66);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: hint-breathe 3.4s ease-in-out infinite;
  transition: opacity 300ms ease, transform 400ms var(--ease-out);
}

.gesture-hint.is-dismissed {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
}

@keyframes hint-breathe {
  0%, 100% { box-shadow: 0 0 0 rgba(var(--accent-rgb), 0); }
  50% { box-shadow: 0 0 24px rgba(var(--accent-rgb), 0.08); }
}

.touch-hint {
  display: none;
}

.save-warning {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 9px 14px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 107, 114, 0.35);
  border-radius: 999px;
  background: rgba(42, 17, 21, 0.94);
  box-shadow: var(--shadow);
  color: #ffd8da;
  font-size: 12px;
  width: max-content;
  max-width: calc(100vw - 28px);
  white-space: normal;
}

.save-warning button {
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  background: #ffd8da;
  color: #351014;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

/* Marking menu: transplanted from master as one interaction unit. */
.marking-menu {
  --marking-spring: cubic-bezier(0.32, 0.72, 0, 1);
  position: fixed;
  z-index: 10000;
  width: 220px;
  height: 220px;
  opacity: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: opacity 140ms var(--ease-standard);
  will-change: opacity;
}

.marking-menu.active {
  opacity: 1;
  pointer-events: none;
}

.marking-menu.sticky,
.marking-menu.in-submenu {
  pointer-events: auto;
}

.marking-menu .marking-guide {
  pointer-events: none;
}

.marking-menu.sticky .marking-item:not(.slot-hidden),
.marking-menu.in-submenu .marking-item:not(.slot-hidden),
.marking-menu.active .marking-origin {
  pointer-events: auto;
}

.marking-guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.guide-ring {
  fill: none;
  stroke: rgba(255, 255, 255, 0.055);
  stroke-width: 1;
  stroke-dasharray: 2 4;
}

.guide-deadzone {
  fill: rgba(255, 255, 255, 0.02);
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1;
  transition: fill 220ms var(--ease-standard), stroke 220ms var(--ease-standard);
}

.marking-menu.in-deadzone .guide-deadzone {
  fill: rgba(255, 69, 58, 0.12);
  stroke: rgba(255, 69, 58, 0.4);
}

.marking-menu.in-submenu .guide-deadzone {
  fill: rgba(var(--accent-rgb), 0.08);
  stroke: rgba(var(--accent-rgb), 0.28);
}

.marking-menu.in-submenu.in-deadzone .guide-deadzone {
  fill: rgba(var(--accent-rgb), 0.22);
  stroke: rgba(var(--accent-rgb), 0.7);
}

.guide-line {
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.marking-menu.sticky .guide-line {
  opacity: 0;
}

.marking-origin {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 8px;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
  color: transparent;
  cursor: pointer;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition:
    width 280ms var(--marking-spring),
    height 280ms var(--marking-spring),
    background 220ms var(--ease-standard),
    color 220ms var(--ease-standard),
    box-shadow 220ms var(--ease-standard),
    transform 220ms var(--ease-standard);
}

.marking-origin svg {
  width: 14px;
  height: 14px;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.4);
  transition: opacity 200ms var(--ease-standard), transform 300ms var(--marking-spring);
}

.marking-menu.in-deadzone:not(.in-submenu) .marking-origin {
  background: #ff453a;
  box-shadow: 0 0 16px rgba(255, 69, 58, 0.6);
  transform: translate(-50%, -50%) scale(1.4);
}

.marking-menu.in-submenu .marking-origin {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(var(--accent-rgb), 0.35);
  background: rgba(var(--accent-rgb), 0.14);
  box-shadow:
    0 0 0 3px rgba(var(--accent-rgb), 0.08),
    0 0 14px rgba(var(--accent-rgb), 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
}

.marking-menu.in-submenu .marking-origin::before {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
}

.marking-menu.in-submenu .marking-origin svg {
  opacity: 0.85;
  transform: scale(1);
}

.marking-menu.in-submenu.in-deadzone .marking-origin {
  border-color: rgba(var(--accent-rgb), 0.85);
  background: rgba(var(--accent-rgb), 0.35);
  box-shadow:
    0 0 0 4px rgba(var(--accent-rgb), 0.18),
    0 0 22px rgba(var(--accent-rgb), 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transform: translate(-50%, -50%) scale(1.18);
}

.marking-menu.in-submenu.in-deadzone .marking-origin svg {
  opacity: 1;
  transform: scale(1.05);
}

.marking-origin.flash-back {
  animation: origin-flash-back 420ms var(--ease-out);
}

@keyframes origin-flash-back {
  0% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.55), 0 0 24px rgba(var(--accent-rgb), 0.7); }
  60% { box-shadow: 0 0 0 18px rgba(var(--accent-rgb), 0), 0 0 8px rgba(var(--accent-rgb), 0.2); }
  100% { box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.08), 0 0 14px rgba(var(--accent-rgb), 0.25); }
}

.marking-origin::after {
  content: "Back";
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(var(--accent-rgb), 0.9);
  box-shadow: 0 4px 12px rgba(var(--accent-rgb), 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 180ms var(--ease-standard), transform 240ms var(--marking-spring);
}

.marking-menu.in-submenu.in-deadzone .marking-origin::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.marking-items {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.marking-item {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15), 0 8px 28px rgba(0, 0, 0, 0.28);
  color: #111;
  cursor: pointer;
  opacity: 1;
  pointer-events: none;
  transform: translate3d(var(--x, 0px), var(--y, 0px), 0) scale(1);
  transition:
    transform 280ms var(--marking-spring),
    opacity 180ms var(--ease-standard),
    background 180ms var(--ease-standard),
    box-shadow 220ms var(--ease-standard);
  will-change: transform, opacity;
}

.marking-item.slot-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate3d(var(--x, 0px), var(--y, 0px), 0) scale(0.4);
}

.marking-item.sector-active:not(.slot-hidden),
.marking-item:focus-visible:not(.slot-hidden) {
  z-index: 5;
  background: #fff;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.2),
    0 16px 44px rgba(0, 0, 0, 0.36),
    0 0 0 3px rgba(255, 255, 255, 0.15);
  outline: none;
  transform: translate3d(var(--x, 0px), var(--y, 0px), 0) scale(1.18);
}

.marking-item svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #111;
  stroke-width: 1.8;
  pointer-events: none;
}

.marking-item .item-glyph,
.marking-item .item-label {
  color: #111;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: -0.01em;
  pointer-events: none;
}

.marking-item.sector-active .item-glyph,
.marking-item.sector-active .item-label {
  font-size: 12px;
}

.marking-item.color-swatch {
  border: 2.5px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.25),
    0 8px 24px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.marking-item.sector-active.color-swatch {
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.3),
    0 16px 40px rgba(0, 0, 0, 0.5),
    0 0 0 3px rgba(255, 255, 255, 0.4),
    inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.marking-item::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: -26px;
  left: 50%;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(30, 30, 30, 0.85);
  color: rgba(255, 255, 255, 0.9);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 150ms var(--ease-standard);
}

.marking-item.sector-active::after,
.marking-item:focus-visible::after {
  opacity: 1;
}

.marking-item[data-tooltip=""]::after {
  display: none;
}

.marking-ripple {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(var(--accent-rgb), 0.65);
  border-radius: 50%;
  pointer-events: none;
  animation: marking-ripple-out 500ms var(--ease-out) forwards;
}

@keyframes marking-ripple-out {
  to {
    opacity: 0;
    transform: scale(1.65);
  }
}

.app.radial-open .topbar,
.app.radial-open .gesture-hint {
  opacity: 0;
  pointer-events: none;
}

/* Library lives off the canvas and can afford more structure and color. */
.library-dialog {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--paper);
  overflow: hidden;
}

.library-dialog::backdrop {
  background: rgba(4, 4, 7, 0.68);
  backdrop-filter: blur(14px) saturate(80%);
  -webkit-backdrop-filter: blur(14px) saturate(80%);
}

.library-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  padding:
    max(24px, env(safe-area-inset-top))
    max(22px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom))
    max(22px, env(safe-area-inset-left));
  border-right: 1px solid var(--line);
  background:
    radial-gradient(circle at 0 0, rgba(var(--accent-rgb), 0.15), transparent 34%),
    rgba(14, 14, 19, 0.97);
  box-shadow: 30px 0 90px rgba(0, 0, 0, 0.46);
  animation: library-enter 420ms var(--ease-out);
}

@keyframes library-enter {
  from { opacity: 0; transform: translateX(-28px); }
  to { opacity: 1; transform: translateX(0); }
}

.library-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.library-eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.library-header h1 {
  margin: 0;
  font-family: "Iowan Old Style", "Baskerville", Georgia, serif;
  font-size: 34px;
  font-weight: 500;
  letter-spacing: -0.035em;
}

.round-button {
  width: 40px;
  height: 40px;
  font-size: 19px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 14px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--paper-faint);
  transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.search-field:focus-within {
  border-color: rgba(var(--accent-rgb), 0.56);
  background: rgba(255, 255, 255, 0.065);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.search-field > span[aria-hidden="true"] {
  font-size: 21px;
  line-height: 1;
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--paper);
  font-size: 15px;
}

.search-field input::placeholder {
  color: var(--paper-faint);
  opacity: 1;
}

.library-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 0 -6px;
  padding: 2px 6px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.library-empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  color: var(--paper-faint);
  font-family: "Iowan Old Style", "Baskerville", Georgia, serif;
  font-size: 17px;
  font-style: italic;
  text-align: center;
}

.note-row {
  position: relative;
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  margin-bottom: 5px;
  padding: 8px 8px 8px 12px;
  border: 1px solid transparent;
  border-radius: 15px;
  background: transparent;
  color: var(--paper-muted);
  transition: background 170ms ease, border-color 170ms ease, transform 200ms var(--spring);
}

.note-row:hover {
  border-color: rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.045);
  transform: translateX(2px);
}

.note-row.is-active {
  border-color: rgba(var(--row-accent-rgb), 0.2);
  background: rgba(var(--row-accent-rgb), 0.09);
}

.note-row-spark {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--row-accent);
  box-shadow: 0 0 12px rgba(var(--row-accent-rgb), 0.46);
}

.note-row-main {
  min-width: 0;
  padding: 5px 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.note-row-title,
.note-row-preview,
.note-row-time {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-row-title {
  margin-bottom: 4px;
  color: var(--paper);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.note-row-preview {
  color: var(--paper-faint);
  font-family: "Iowan Old Style", "Baskerville", Georgia, serif;
  font-size: 12px;
  font-style: italic;
}

.note-row-time {
  margin-top: 4px;
  color: rgba(247, 244, 236, 0.56);
  font-size: 10px;
}

.note-row-delete {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--paper-faint);
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, color 150ms ease, background 150ms ease;
}

.note-row:hover .note-row-delete,
.note-row:focus-within .note-row-delete {
  opacity: 1;
}

.note-row-delete:hover,
.note-row-delete:focus-visible {
  background: rgba(255, 107, 114, 0.12);
  color: #ff9ca1;
}

.library-new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 46px;
  margin-top: 4px;
  border: 1px dashed rgba(var(--accent-rgb), 0.34);
  border-radius: 14px;
  background: rgba(var(--accent-rgb), 0.055);
  color: var(--paper-muted);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, transform 200ms var(--spring);
}

.library-new span:first-child {
  color: var(--accent);
  font-size: 19px;
  font-weight: 300;
}

.library-new:hover {
  background: rgba(var(--accent-rgb), 0.11);
  color: var(--paper);
  transform: translateY(-1px);
}

.library-footer {
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.library-footer p {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 12px;
  color: var(--paper-faint);
  font-size: 11px;
}

.local-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #55dbb0;
  box-shadow: 0 0 8px rgba(85, 219, 176, 0.5);
}

.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.library-actions button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--paper-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}

.library-actions button:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.07);
  color: var(--paper);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 18px));
  z-index: 140;
  display: flex;
  align-items: center;
  gap: 11px;
  max-width: min(420px, calc(100vw - 28px));
  padding: 10px 11px 10px 14px;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  color: var(--paper-muted);
  font-size: 12px;
  animation: toast-in 340ms var(--spring);
}

/* The onboarding hint and status toast share the bottom-center lane. */
body:has(.toast:not([hidden])) .gesture-hint {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.toast button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(var(--accent-rgb), 0.3);
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.14);
  color: var(--paper);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.toast .toast-dismiss {
  display: grid;
  place-items: center;
  width: 30px;
  min-width: 30px;
  height: 30px;
  padding: 0 0 2px;
  border-color: transparent;
  background: transparent;
  color: var(--paper-faint);
  font-size: 17px;
}

.toast .toast-dismiss:hover,
.toast .toast-dismiss:focus-visible {
  background: rgba(255, 255, 255, 0.07);
  color: var(--paper);
}

@media (pointer: coarse) {
  .desktop-hint { display: none; }
  .touch-hint { display: inline; }

  .note-row-delete {
    opacity: 1;
  }
}

@media (max-width: 700px) {
  .topbar {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
  }

  .note-switcher,
  .new-note {
    min-height: 44px;
  }

  .note-switcher {
    max-width: calc(100vw - 74px);
    border-radius: 15px;
  }

  .new-note {
    width: 44px;
    height: 44px;
    border-radius: 15px;
  }

  .editor {
    width: calc(100% - 2.5rem);
    padding: 6.4rem 0 8.5rem;
    font-size: 18px;
    line-height: 1.65;
  }

  .editor.is-empty::before {
    max-width: 18ch;
    font-size: 1.18em;
  }

  .gesture-hint {
    max-width: calc(100vw - 28px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .library-panel {
    top: auto;
    width: 100%;
    height: min(88dvh, 760px);
    border-top: 1px solid var(--line);
    border-right: 0;
    border-radius: 24px 24px 0 0;
    animation-name: library-enter-mobile;
  }

  @keyframes library-enter-mobile {
    from { opacity: 0; transform: translateY(34px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .library-header h1 {
    font-size: 30px;
  }

  .search-field input {
    font-size: 16px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .editor {
    padding-top: 5.2rem;
  }

  .gesture-hint {
    display: none;
  }

  .library-panel {
    height: 100%;
    border-radius: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .library-header,
  .search-field,
  .library-new,
  .library-footer {
    flex-shrink: 0;
  }

  .library-list {
    flex: 0 0 auto;
    min-height: 160px;
    overflow: visible;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --paper-muted: #d1ced7;
    --paper-faint: #a6a1ad;
    --line: rgba(255, 255, 255, 0.22);
    --line-strong: rgba(255, 255, 255, 0.42);
  }

  .editor.is-empty::before {
    color: rgba(247, 244, 236, 0.52);
  }
}

@media (forced-colors: active) {
  :root {
    --accent: Highlight;
  }

  .ambient-glow,
  .app::before,
  .marking-guide {
    display: none;
  }

  .note-switcher,
  .new-note,
  .round-button,
  .marking-item,
  .marking-origin,
  .library-panel,
  .search-field,
  .library-new,
  .library-actions button {
    border: 1px solid ButtonText;
  }
}
