/* Bundled fonts — no network requests */
@font-face {
  font-family: 'Inter';
  src: url('fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Inter Tight';
  src: url('fonts/InterTight-Variable.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* Board Grotesk is a project-owner supplied font. */
@font-face {
  font-family: 'BoardGrotesque Sans';
  src: url('fonts/BoardGrotesqueSans-Light.otf') format('opentype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'BoardGrotesque Sans';
  src: url('fonts/BoardGrotesqueSans-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'BoardGrotesque Sans';
  src: url('fonts/BoardGrotesqueSans-Medium.otf') format('opentype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --font-family: 'Inter Tight', sans-serif;
  --font-size: 40px;
  --line-height: 1.6;
  --letter-spacing: 0em;
  --max-width: 1600px;
  --text-color: #DDDAD2;
  --bg-color: #0B0B0D;
  --selection-color: #3D47FF;
  --selection-text-color: #FFFFFF;
  
  /* Panel theming */
  --panel-bg: rgba(11, 11, 13, 0.92);
  --panel-border: rgba(221, 218, 210, 0.2);
  --panel-text: #DDDAD2;
  --panel-text-secondary: rgba(221, 218, 210, 0.6);
  --control-bg: rgba(11, 11, 13, 0.78);
  --control-border: rgba(221, 218, 210, 0.15);
  --control-hover: rgba(221, 218, 210, 0.08);

  /* Shared floating UI */
  --ui-surface: rgba(11, 11, 13, 0.56);
  --ui-surface-strong: rgba(11, 11, 13, 0.72);
  --ui-surface-soft: rgba(11, 11, 13, 0.44);
  --ui-section-surface: rgba(11, 11, 13, 0.34);
  --ui-border: rgba(221, 218, 210, 0.12);
  --ui-border-strong: rgba(221, 218, 210, 0.2);
  --ui-text: rgba(221, 218, 210, 0.88);
  --ui-text-muted: rgba(221, 218, 210, 0.6);
  --ui-hover: rgba(221, 218, 210, 0.08);
  --ui-hover-strong: rgba(221, 218, 210, 0.14);
  --ui-track: rgba(221, 218, 210, 0.12);
  --ui-shadow-soft: 0 18px 42px rgba(0, 0, 0, 0.28);
  --ui-shadow-subtle: 0 10px 24px rgba(0, 0, 0, 0.2);
  --ui-danger-text: #8C4A4A;
  --ui-danger-surface: rgba(172, 92, 92, 0.14);
  --ui-danger-border: rgba(172, 92, 92, 0.24);
}

html, body {
  height: 100%;
  background-color: var(--bg-color);
  color-scheme: dark;
  transition: background-color 0.3s ease;
  overflow: auto;
}

/* Custom Scrollbar - Overlay style */
::-webkit-scrollbar {
  width: 2px;
  height: 2px;
  background: transparent;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 1px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* Firefox scrollbar */
html {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* Board + Editor */
#board {
  width: 100%;
  min-height: 100vh;
  position: relative;
  background-color: var(--bg-color);
  transition: background-color 0.3s ease;
}

#editorShell {
  width: min(100%, var(--max-width));
  position: relative;
  z-index: 1;
}

#editor {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 48px 48px 120px 48px;
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  color: var(--text-color);
  background-color: var(--bg-color);
  outline: none;
  white-space: pre-wrap;
  tab-size: 6;
  -moz-tab-size: 6;
  word-wrap: break-word;
  text-align: left;
  position: relative;
  background-color: transparent;
  transition: color 0.3s ease, background-color 0.3s ease;
}

#editor img {
  display: block;
  inline-size: auto;
  max-inline-size: min(100%, 32em);
  block-size: auto;
  margin-block: 0.75em;
}

#drawingLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

body.drawing-mode #drawingLayer {
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}

body.drawing-mode.eraser-mode #drawingLayer {
  cursor: cell;
}

body.drawing-mode #editor {
  user-select: none;
  -webkit-user-select: none;
  caret-color: transparent;
}

#editor:empty::before {
  content: 'Start writing...';
  color: var(--text-color);
  opacity: 0.35;
  pointer-events: none;
  font-style: italic;
}

/* Text selection styling — selected text auto-inverts to stay readable on any highlight color */
#editor::selection {
  background-color: var(--selection-color);
  color: var(--selection-text-color);
}

#editor *::selection {
  background-color: var(--selection-color);
  color: var(--selection-text-color);
}

/* Controls Container */
.controls-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 3100;
}

.top-right-rail {
  position: fixed;
  top: 24px;
  right: 24px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  z-index: 2500;
}

/* Holds the toolbar and its arrow. Only the arrow occupies space here; the
   toolbar hangs off the left edge so showing and hiding it moves nothing. */
.rail-tools {
  position: relative;
  display: flex;
  align-items: flex-start;
  flex: 0 0 auto;
}

.drawing-toolbar {
  position: absolute;
  top: 0;
  right: calc(100% + 12px);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 16px;
  box-shadow: none;
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
  filter: blur(0);
  transform: translate3d(0, 0, 0);
  transition: opacity 0.26s ease,
              filter 0.34s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.34s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0s linear 0s;
}

/* Collapsed: the tools dissolve out of focus rather than folding shut, drifting
   a little to the right so they read as tucking in behind the arrow. Out of
   flow, so the drift moves nothing else. */
.top-right-rail.tools-collapsed .drawing-toolbar {
  opacity: 0;
  filter: blur(28px);
  transform: translate3d(18px, 0, 0);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.26s ease,
              filter 0.34s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.34s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0s linear 0.34s;
}

/* Adjacent collapse arrow — same glass chrome as the toolbar so the pair reads
   as one control. The chevron flips to point back at whatever it will reveal. */
.rail-collapse-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 54px;
  padding: 0;
  color: var(--ui-text);
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 13px;
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 0.15s ease, background 0.15s ease;
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.rail-collapse-toggle:hover {
  opacity: 1;
  background: var(--ui-surface-strong);
}

.rail-collapse-chevron {
  width: 16px;
  height: 16px;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.top-right-rail.tools-collapsed .rail-collapse-chevron {
  transform: rotate(180deg);
}

.drawing-toolbar.active {
  background: var(--ui-surface-strong);
}

.drawing-toolbar.eraser-active {
  border-color: var(--ui-border-strong);
}

.drawing-toolbar-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
}

.drawing-toolbar-group + .drawing-toolbar-group {
  padding-top: 0;
  border-top: none;
}

.drawing-toolbar-group-actions {
  margin-left: 4px;
  padding-left: 10px;
  border-left: 1px solid var(--ui-border);
}

.drawing-size-control {
  width: 100%;
  display: grid;
  gap: 10px;
}

.drawing-size-toggle {
  position: relative;
  flex-direction: column;
  gap: 4px;
}

.drawing-size-toggle svg {
  width: 16px;
  height: 16px;
}

.drawing-size-toggle-stroke {
  width: 18px;
  height: var(--draw-size-preview-height, 3px);
  border-radius: 999px;
  background: currentColor;
  opacity: 0.9;
  pointer-events: none;
}

.drawing-size-popover {
  position: fixed;
  width: min(232px, calc(100vw - 24px));
  padding: 12px 14px 14px;
  display: grid;
  gap: 14px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 16px;
  box-shadow: var(--ui-shadow-subtle);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px) scale(0.96);
  transition: opacity 0.18s ease, transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0.24s;
  z-index: 3200;
}

.drawing-size-popover.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.drawing-size-popover-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.drawing-size-popover-title {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ui-text);
}

.drawing-size-value {
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  color: var(--text-color);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.drawing-size-slider {
  width: 100%;
  height: 4px;
  margin: 0;
  background: var(--ui-track);
  border-radius: 999px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.drawing-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--text-color);
  border: 2px solid var(--ui-surface-strong);
  box-shadow: 0 0 0 1px var(--ui-border-strong);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.drawing-size-slider::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

.drawing-size-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--text-color);
  border: 2px solid var(--ui-surface-strong);
  box-shadow: 0 0 0 1px var(--ui-border-strong);
  border-radius: 50%;
  cursor: pointer;
}

.drawing-size-slider::-moz-range-track {
  height: 4px;
  background: var(--ui-track);
  border-radius: 999px;
}

.drawing-size-markers {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-top: -2px;
}

.drawing-size-marker {
  flex: 1;
  min-width: 0;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-color);
  transition: background 0.15s ease, opacity 0.15s ease;
  opacity: 0.45;
}

.drawing-size-marker:hover {
  opacity: 0.85;
  background: var(--ui-hover);
}

.drawing-size-marker.active {
  opacity: 1;
  background: var(--ui-hover-strong);
}

.drawing-size-marker-swatch {
  width: 14px;
  height: var(--marker-stroke-height, 8px);
  border-radius: 999px;
  background: currentColor;
  pointer-events: none;
}

.drawing-tool-button {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--ui-text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  opacity: 0.8;
  transition: all 0.15s ease;
}

.drawing-tool-button:hover {
  opacity: 1;
  background: var(--ui-hover);
}

.drawing-tool-button svg {
  width: 18px;
  height: 18px;
}

.drawing-toggle-button .drawing-tool-icon-bulk {
  display: none;
}

.drawing-toggle-button.active .drawing-tool-icon-light {
  display: none;
}

.drawing-toggle-button.active .drawing-tool-icon-bulk {
  display: block;
}

.drawing-tool-button.active,
.drawing-size-button.active {
  opacity: 1;
  background: var(--ui-hover-strong);
  border-color: var(--ui-border);
  box-shadow: none;
  color: var(--text-color);
}

.drawing-tool-button-danger:hover {
  color: var(--ui-danger-text);
  background: var(--ui-danger-surface);
}

.drawing-color-button {
  padding: 0;
}

.drawing-color-preview {
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: var(--text-color);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.52), 0 0 0 1px var(--ui-border);
}

.controls-icon {
  width: 40px;
  height: 40px;
  padding: 10px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  color: var(--ui-text);
  opacity: 0.82;
  cursor: pointer;
  box-shadow: none;
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
  transition: all 0.2s ease;
}

.controls-icon:hover {
  opacity: 1;
  background: var(--ui-surface-strong);
}

.controls-icon svg {
  width: 100%;
  height: 100%;
}

/* Controls Panel */
.controls-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  width: min(280px, calc(100vw - 32px));
  max-height: min(680px, calc(100dvh - 92px));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  display: grid;
  gap: 2px;
  background: var(--ui-surface-strong);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  box-shadow: var(--ui-shadow-subtle);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);

  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transform-origin: bottom right;
  transition: all 0.15s ease;
}

.controls-panel::-webkit-scrollbar {
  width: 4px;
}

.controls-panel::-webkit-scrollbar-thumb {
  background: var(--ui-border-strong);
  border-radius: 999px;
}

.controls-container.open .controls-panel,
.controls-panel:focus-within {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.controls-container.open .controls-icon,
.controls-container:focus-within .controls-icon {
  opacity: 1;
  background: var(--ui-surface-strong);
}

/* Button reset for controls-icon */
button.controls-icon {
  font: inherit;
}

.controls-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 2px;
}

.controls-panel-heading {
  min-width: 0;
}

.controls-panel-heading h3 {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.controls-close {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--ui-text-muted);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.controls-close svg {
  width: 16px;
  height: 16px;
}

.controls-close:hover {
  color: var(--ui-text);
  background: var(--ui-hover);
}

/* Control Sections */
.control-section {
  margin: 0;
  padding: 8px 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.control-section:first-of-type {
  padding-top: 4px;
}

.section-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 9px;
  font-weight: 500;
  color: var(--ui-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  opacity: 0.7;
}

.control-divider {
  display: none;
}

/* Control Groups */
.control-group {
  margin-bottom: 8px;
  min-width: 0;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.control-row .control-group {
  margin-bottom: 8px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 400;
  color: var(--ui-text);
}

.control-group label span {
  font-weight: 400;
  color: var(--ui-text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 10px;
}

/* Theme Grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.theme-swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-swatch:hover {
  transform: none;
}

.theme-swatch-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 7px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 6px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  box-shadow: none;
  overflow: hidden;
}

.theme-swatch.active .theme-swatch-inner {
  border-color: var(--ui-border-strong);
  box-shadow: inset 0 0 0 1px var(--ui-hover-strong);
}

.theme-swatch.active .theme-swatch-inner::after {
  display: none;
}

.theme-swatch-text {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
}

.theme-swatch-preview {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.theme-swatch-text-regular {
  text-shadow: none;
}

.theme-swatch-highlight {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 18px;
  padding: 2px 6px;
  border-radius: 999px;
}

.theme-swatch-name {
  display: none;
}

/* Color Controls */
.color-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.color-control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.color-control label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 400;
  color: var(--ui-text);
  margin-bottom: 0;
  white-space: nowrap;
  cursor: pointer;
}

.color-input-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.color-control input[type="color"] {
  width: 16px;
  height: 16px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 0 0 1px var(--ui-border-strong);
}

.color-control input[type="color"]:hover {
  transform: scale(1.12);
  box-shadow: 0 0 0 1px var(--ui-text-muted);
}

.color-control input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-control input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.color-hex-input {
  width: 76px;
  padding: 4px 8px;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 10px;
  font-weight: 500;
  color: var(--ui-text);
  text-transform: uppercase;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  outline: none;
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  transition: all 0.15s ease;
}

.color-hex-input:hover {
  background: var(--ui-surface-strong);
}

.color-hex-input:focus {
  background: var(--ui-surface-strong);
  border-color: var(--ui-border-strong);
}

.color-hex-input::placeholder {
  color: var(--ui-text-muted);
}

/* Custom Color Picker Popup - Redesigned */
.color-picker-popup {
  position: fixed;
  width: 220px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 18px;
  box-shadow: var(--ui-shadow-subtle);
  padding: 14px;
  z-index: 3200;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.95);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: visible;
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
}

.color-picker-popup.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.color-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.color-picker-title {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.color-picker-close {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 5px;
  color: var(--ui-text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.color-picker-close svg {
  width: 16px;
  height: 16px;
}

.color-picker-close:hover {
  background: var(--ui-hover);
  color: var(--ui-text);
}

/* 2D Color Area (Saturation-Brightness) */
.color-picker-area {
  position: relative;
  width: 100%;
  height: 140px;
  border-radius: 8px;
  cursor: crosshair;
  overflow: hidden;
  touch-action: none;
  background: linear-gradient(to bottom, transparent, #000),
              linear-gradient(to right, #fff, transparent);
  background-color: #ff0000;
}

.color-picker-cursor {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2), 0 2px 6px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: box-shadow 0.15s ease;
}

/* Hue Slider */
.color-picker-hue-wrap {
  margin-top: 12px;
}

.color-picker-hue {
  width: 100%;
  height: 14px;
  border-radius: 7px;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  background: linear-gradient(to right, 
    hsl(0, 100%, 50%), 
    hsl(60, 100%, 50%), 
    hsl(120, 100%, 50%), 
    hsl(180, 100%, 50%), 
    hsl(240, 100%, 50%), 
    hsl(300, 100%, 50%), 
    hsl(360, 100%, 50%)
  );
  border: none;
  outline: none;
}

.color-picker-hue::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.1);
  transition: transform 0.1s ease;
}

.color-picker-hue::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.color-picker-hue::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.05);
}

/* Footer with Preview & Hex */
.color-picker-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.color-picker-previews {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--ui-border);
}

.color-picker-preview-current,
.color-picker-preview-new {
  width: 28px;
  height: 28px;
}

.color-picker-preview-current {
  opacity: 0.6;
}

.color-picker-hex {
  flex: 1;
  height: 28px;
  padding: 0 10px;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 12px;
  font-weight: 500;
  color: var(--ui-text);
  text-transform: uppercase;
  background: var(--ui-surface-soft);
  border: 1px solid transparent;
  border-radius: 10px;
  outline: none;
  transition: all 0.15s ease;
}

.color-picker-hex:hover {
  background: var(--ui-surface-strong);
}

.color-picker-hex:focus {
  background: var(--ui-surface-strong);
  border-color: var(--ui-border-strong);
}

/* Preset Swatches */
.color-picker-swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--ui-border);
}

.color-picker-swatch {
  aspect-ratio: 1;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.color-picker-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 1px var(--ui-border-strong);
  z-index: 1;
}

/* Brush-only: revert custom brush color to the current theme's text color */
.color-picker-match-theme {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text);
  background: var(--ui-surface-soft);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.color-picker-match-theme:hover {
  background: var(--ui-hover);
  border-color: var(--ui-border-strong);
}

.color-picker-match-theme[hidden] {
  display: none;
}

/* Save-indicator error state */
.save-indicator.error {
  opacity: 0.85;
  color: #8C4A4A;
}

/* Select */
.control-group select {
  width: 100%;
  padding: 8px 10px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-text);
  background: var(--ui-surface-soft);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  outline: none;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M18 9L12 15L6 9' stroke='%23999' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

.control-group select:hover {
  border-color: var(--ui-border-strong);
  background-color: var(--ui-surface-soft);
}

.control-group select:focus {
  border-color: var(--ui-border-strong);
}

/* Custom Font Dropdown */
.font-dropdown-wrapper {
  position: relative;
  width: 100%;
}

.font-dropdown-trigger {
  width: 100%;
  padding: 8px 10px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-text);
  background: var(--ui-surface-soft);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  outline: none;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.font-dropdown-trigger:hover {
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-soft);
}

.font-dropdown-trigger.open {
  border-color: var(--ui-border-strong);
}

.font-dropdown-preview {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.font-dropdown-arrow {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  margin-left: 6px;
  transition: transform 0.2s ease;
}

.font-dropdown-trigger.open .font-dropdown-arrow {
  transform: rotate(180deg);
}

.font-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 8px;
  background: var(--bg-color);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  box-shadow: var(--ui-shadow-soft);
  z-index: 1500;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all 0.15s ease;
}

.font-dropdown-menu.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.font-dropdown-menu.flip-up {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 8px;
  transform: translateY(4px);
}

.font-dropdown-menu.flip-up.visible {
  transform: translateY(0);
}

.font-dropdown-group {
  padding: 4px 0;
}

.font-dropdown-group:not(:last-child) {
  border-bottom: 1px solid var(--ui-border);
}

.font-dropdown-group-label {
  padding: 6px 10px 4px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 9px;
  font-weight: 600;
  color: var(--ui-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.font-dropdown-option {
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background 0.1s ease;
  text-align: left;
}

.font-dropdown-option:hover {
  background: var(--ui-hover);
}

.font-dropdown-option.selected {
  background: var(--ui-hover-strong);
}

.font-dropdown-option-name {
  font-size: 13px;
  color: var(--ui-text);
  line-height: 1.3;
}

/* Range Slider */
.control-group input[type="range"] {
  width: 100%;
  height: 2px;
  background: var(--ui-track);
  border-radius: 2px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: var(--ui-text);
  border-radius: 50%;
  cursor: pointer;
  transition: none;
}

.control-group input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: var(--ui-text);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

/* Color Picker (legacy - kept for backwards compatibility) */
.control-group input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 3px;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.control-group input[type="color"]:hover {
  border-color: var(--panel-text);
}

.control-group input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 3px;
}

.control-group input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}

.mode-toggle-btn,
.secondary-btn {
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  font: inherit;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-soft);
  color: var(--ui-text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-toggle-btn:hover,
.secondary-btn:hover {
  background: var(--ui-surface-strong);
  border-color: var(--ui-border-strong);
}

.mode-toggle-btn.active {
  color: white;
  background: var(--text-color);
  border-color: transparent;
}

.annotation-actions {
  margin-top: 10px;
}

.annotation-hint {
  margin-top: 8px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 10px;
  line-height: 1.4;
  color: var(--ui-text-muted);
}

/* Local backup controls stay compact so the writing surface remains primary. */
.data-section {
  border-top: 1px solid var(--ui-border);
}

.data-copy,
.data-hint {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--ui-text-muted);
}

.data-copy {
  font-size: 11px;
  line-height: 1.4;
}

.data-hint {
  margin-top: 7px;
  font-size: 10px;
  line-height: 1.45;
}

.data-hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.94em;
}

.data-hint a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.data-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 9px;
}

.data-action {
  min-width: 0;
  white-space: nowrap;
}

.data-action-wide {
  grid-column: 1 / -1;
}

.secondary-btn:disabled,
.drawing-tool-button:disabled,
.add-page-btn:disabled,
.theme-swatch:disabled,
.emoji-option:disabled,
.font-dropdown-trigger:disabled,
.controls-icon:disabled,
.controls-close:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

/* Footer */
.controls-panel-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 6px;
}

/* Reset Button */
.reset-btn {
  appearance: none;
  width: auto;
  padding: 4px 8px;
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 10px;
  font-weight: 500;
  color: var(--ui-text-muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.reset-btn:hover {
  color: var(--ui-text);
  background: var(--ui-hover);
}

.control-disclosure {
  margin: 0;
}

.control-disclosure[open] {
  padding-bottom: 2px;
}

.control-disclosure-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  cursor: pointer;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-text);
}

.control-disclosure-summary::-webkit-details-marker {
  display: none;
}

.control-disclosure-summary::after {
  content: '+';
  font-size: 14px;
  line-height: 1;
  color: var(--ui-text-muted);
}

.control-disclosure[open] .control-disclosure-summary::after {
  content: '−';
}

/* Save Indicator */
.save-indicator {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color);
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.2s ease;
  pointer-events: none;
}

.save-indicator svg {
  width: 16px;
  height: 16px;
}

.save-indicator.visible {
  opacity: 0.35;
  transform: scale(1);
}

.save-indicator .save-indicator-err {
  display: none;
}

.save-indicator.error .save-indicator-ok {
  display: none;
}

.save-indicator.error .save-indicator-err {
  display: inline-block;
}

/* Page Tabs */
.page-tabs {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.page-tabs-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  max-height: min(70vh, calc(100vh - 140px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  padding: 5px;
  border-radius: 16px;
  box-shadow: none;
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
  scrollbar-width: none;
  -ms-overflow-style: none;
  mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
}

.page-tabs-list.is-at-top {
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 12px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 12px), transparent 100%);
}

.page-tabs-list.is-at-bottom {
  mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 100%);
}

.page-tabs-list.is-at-top.is-at-bottom {
  mask-image: none;
  -webkit-mask-image: none;
}

.page-tabs-list::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.page-tab {
  position: relative;
  flex: 0 0 44px;
  box-sizing: border-box;
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  opacity: 0.8;
  overflow: hidden;
}

.page-tab.active::after {
  content: '✎';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 10px;
  font-weight: 700;
  color: var(--ui-text);
  background: color-mix(in srgb, var(--bg-color) 88%, white 12%);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  box-shadow: var(--ui-shadow-subtle);
  opacity: 0;
  transform: translateY(4px) scale(0.92);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.page-tab-emoji {
  font-size: 22px;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  line-height: 1;
  pointer-events: none;
  opacity: 0.7;
  transition: all 0.2s ease;
}

.page-tab:hover .page-tab-emoji,
.page-tab.active .page-tab-emoji {
  opacity: 1;
}

.page-tab:hover {
  opacity: 1;
  background: var(--ui-hover);
}

body.page-reordering .page-tab:hover {
  opacity: 0.8;
  background: transparent;
}

body.page-reordering .page-tab:hover .page-tab-emoji {
  opacity: 0.7;
}

body.page-reordering .page-tab.active:hover {
  opacity: 1;
  background: var(--ui-hover-strong);
}

body.page-reordering .page-tab.active:hover .page-tab-emoji {
  opacity: 1;
}

.page-tab.active {
  opacity: 1;
  background: var(--ui-hover-strong);
  box-shadow: none;
}

.page-tab.active:hover::after,
.page-tab.active:focus-visible::after {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.add-page-btn {
  flex: 0 0 40px;
  box-sizing: border-box;
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  height: 40px;
  min-height: 40px;
  max-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-text);
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  cursor: pointer;
  opacity: 0.82;
  transition: all 0.15s ease;
  box-shadow: none;
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.add-page-btn svg {
  width: 18px;
  height: 18px;
}

.add-page-btn:hover {
  opacity: 1;
  background: var(--ui-surface-strong);
}

/* Page hover preview — a passive card that peeks at a tab's page without
   switching to it. Pointer-events stay off so it can never eat a tab click. */
.page-preview {
  position: fixed;
  top: 12px;
  left: 12px;
  width: 264px;
  max-width: calc(100vw - 24px);
  padding: 12px 14px;
  /* Clips the outgoing copy to the card's rounded edge while the two overlap. */
  overflow: hidden;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  box-shadow: var(--ui-shadow-subtle);
  backdrop-filter: blur(20px) saturate(135%);
  -webkit-backdrop-filter: blur(20px) saturate(135%);
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* No sliding in from the side: the card resolves out of a heavy defocus,
     the same way the drawing tools do. Blur is GPU-composited and only runs
     for the length of the transition, so it stays cheap on a card this size. */
  filter: blur(26px);
  transition: opacity 0.26s ease,
              filter 0.34s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0s linear 0.34s;
  z-index: 90;
}

/* While open the card animates its own left/top/height: hovering along the
   rail moves and reshapes one card instead of replacing it at each tab. */
.page-preview.visible {
  opacity: 1;
  visibility: visible;
  filter: blur(0);
  transition: opacity 0.26s ease,
              filter 0.34s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0s linear 0s,
              top 0.24s cubic-bezier(0.16, 1, 0.3, 1),
              left 0.24s cubic-bezier(0.16, 1, 0.3, 1),
              height 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.page-preview-content,
.page-preview-ghost {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* The outgoing page sits exactly where it was drawn, on top of the incoming
   one, so the two overlap through the change and nothing ever goes blank. */
.page-preview-ghost {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  opacity: 0;
  pointer-events: none;
}

.page-preview-content {
  opacity: 1;
}

.page-preview-content,
.page-preview-ghost {
  transition: opacity 0.22s ease;
}

/* The start of a switch: the copy you were reading is still the one on screen.
   Dropping the class hands it over to the new copy across both transitions. */
.page-preview.is-swapping .page-preview-content {
  opacity: 0;
  transition: none;
}

.page-preview.is-swapping .page-preview-ghost {
  opacity: 1;
  transition: none;
}

.page-preview-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.page-preview-emoji {
  font-size: 16px;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  line-height: 1;
  flex: 0 0 auto;
}

.page-preview-title {
  margin: 0;
  min-width: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ui-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The snippet borrows the note's own font so the peek looks like the page. */
.page-preview-snippet {
  margin: 0;
  font-family: var(--font-family);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-color);
  opacity: 0.72;
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  -webkit-box-orient: vertical;
}

/* The -webkit-box display above outranks the UA rule for [hidden]. */
.page-preview-snippet[hidden] {
  display: none;
}

.page-preview-snippet.is-empty {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  font-style: italic;
  opacity: 0.5;
}

.page-preview-meta {
  margin: 0;
  padding-top: 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--ui-border);
}

.page-preview-meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
}

.page-preview-meta-row dt {
  color: var(--ui-text-muted);
}

.page-preview-meta-row dd {
  margin: 0;
  color: var(--ui-text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Emoji Picker - Tooltip Style */
.emoji-picker {
  position: fixed;
  top: 12px;
  left: 12px;
  width: min(288px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  backdrop-filter: blur(20px) saturate(135%);
  -webkit-backdrop-filter: blur(20px) saturate(135%);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--ui-shadow-subtle);
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(var(--emoji-picker-enter-x, 10px), 8px, 0) scale(0.96);
  transition: opacity 0.18s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0.28s;
  z-index: 100;
}

.emoji-picker[data-placement="left"] {
  --emoji-picker-enter-x: 10px;
  transform-origin: right center;
}

.emoji-picker[data-placement="right"] {
  --emoji-picker-enter-x: -10px;
  transform-origin: left center;
}

.emoji-picker.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate3d(0, 0, 0) scale(1);
  transition-delay: 0s;
}

.emoji-picker-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--ui-border);
}

.emoji-picker-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.emoji-picker-title,
.emoji-picker-hint {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
}

.emoji-picker-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ui-text);
}

.emoji-picker-hint {
  font-size: 11px;
  line-height: 1.45;
  color: var(--ui-text-muted);
}

/* Page name field */
.emoji-picker-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.emoji-picker-name-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-muted);
}

.emoji-picker-name-input {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  color: var(--ui-text);
  background: var(--ui-surface-soft);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.emoji-picker-name-input::placeholder {
  color: var(--ui-text-muted);
  opacity: 0.7;
}

.emoji-picker-name-input:focus {
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-strong);
}

.emoji-picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.emoji-picker-action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  white-space: nowrap;
  background: var(--ui-surface-soft);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  color: var(--ui-text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.emoji-picker-action:hover {
  background: var(--ui-hover);
}

.emoji-picker-action-danger {
  color: var(--ui-danger-text);
  background: color-mix(in srgb, var(--ui-surface-soft) 78%, rgba(172, 92, 92, 0.22));
  border-color: var(--ui-danger-border);
}

.emoji-picker-action-danger:hover {
  background: color-mix(in srgb, var(--ui-surface-strong) 70%, rgba(172, 92, 92, 0.28));
}

.emoji-picker-action:disabled {
  opacity: 0.34;
  cursor: not-allowed;
}

.emoji-picker-action:disabled:hover {
  background: var(--ui-surface-soft);
  color: var(--ui-text);
}

.delete-confirm-popover {
  position: fixed;
  width: min(244px, calc(100vw - 24px));
  padding: 12px;
  background: color-mix(in srgb, var(--ui-surface-strong) 76%, rgba(172, 92, 92, 0.28));
  border: 1px solid var(--ui-danger-border);
  border-radius: 12px;
  box-shadow: var(--ui-shadow-subtle);
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px) scale(0.96);
  transition: opacity 0.18s ease, transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0.24s;
  z-index: 120;
}

.delete-confirm-popover::before {
  display: none;
}

.delete-confirm-popover[hidden] {
  display: none;
}

.delete-confirm-popover.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.delete-confirm-title {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--ui-danger-text);
}

.delete-confirm-text {
  margin: 6px 0 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  line-height: 1.45;
  color: color-mix(in srgb, var(--ui-danger-text) 75%, white 25%);
}

.delete-confirm-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.delete-confirm-cancel,
.delete-confirm-delete {
  flex: 1;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.delete-confirm-cancel {
  color: var(--ui-text);
  background: var(--ui-surface-soft);
}

.delete-confirm-cancel:hover {
  background: var(--ui-hover);
}

.delete-confirm-delete {
  color: #fff;
  background: rgba(140, 74, 74, 0.88);
  border-color: transparent;
}

.delete-confirm-delete:hover {
  background: rgba(140, 74, 74, 0.96);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
}

.emoji-option {
  width: 100%;
  min-height: 34px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.1s ease;
  opacity: 0.8;
}

.emoji-option:hover {
  background: var(--ui-hover);
  transform: scale(1.15);
  opacity: 1;
}

.emoji-option.selected,
.emoji-option[aria-pressed="true"] {
  background: var(--ui-hover-strong);
  box-shadow: inset 0 0 0 1px var(--ui-border-strong);
  opacity: 1;
}

.emoji-option.selected:hover,
.emoji-option[aria-pressed="true"]:hover {
  background: var(--ui-hover-strong);
}

.emoji-option:active {
  transform: scale(0.9);
}

body.is-scrolling .page-tab,
body.is-scrolling .add-page-btn,
body.is-scrolling .controls-icon,
body.is-scrolling .controls-close,
body.is-scrolling .drawing-tool-button,
body.is-scrolling .drawing-size-marker,
body.is-scrolling .emoji-picker-action,
body.is-scrolling .emoji-option,
body.is-scrolling .delete-confirm-cancel,
body.is-scrolling .delete-confirm-delete {
  pointer-events: none;
}

body.is-scrolling .drawing-tool-button:hover,
body.is-scrolling .drawing-size-marker:hover,
body.is-scrolling .controls-icon:hover,
body.is-scrolling .controls-close:hover,
body.is-scrolling .page-tab:hover,
body.is-scrolling .add-page-btn:hover,
body.is-scrolling .emoji-picker-action:hover,
body.is-scrolling .emoji-option:hover {
  background: transparent;
  transform: none;
}

body.is-scrolling .page-tab:hover {
  opacity: 0.8;
}

body.is-scrolling .page-tab.active,
body.is-scrolling .page-tab.active:hover {
  opacity: 1;
  background: var(--ui-hover-strong);
}

body.is-scrolling .page-tab:hover .page-tab-emoji {
  opacity: 0.7;
}

body.is-scrolling .page-tab.active .page-tab-emoji,
body.is-scrolling .page-tab.active:hover .page-tab-emoji {
  opacity: 1;
}

body.is-scrolling .page-tab.active::after {
  opacity: 0;
  transform: translateY(4px) scale(0.92);
}

body.is-scrolling .add-page-btn:hover,
body.is-scrolling .controls-icon:hover,
body.is-scrolling .drawing-tool-button:hover {
  opacity: inherit;
}

.drawing-tool-button:focus-visible,
.rail-collapse-toggle:focus-visible,
.drawing-size-marker:focus-visible,
.controls-icon:focus-visible,
.controls-close:focus-visible,
.add-page-btn:focus-visible,
.page-tab:focus-visible,
.emoji-picker-action:focus-visible,
.delete-confirm-cancel:focus-visible,
.delete-confirm-delete:focus-visible,
.reset-btn:focus-visible,
.font-dropdown-trigger:focus-visible,
.control-group select:focus-visible,
.color-hex-input:focus-visible,
.color-picker-hex:focus-visible,
.color-picker-close:focus-visible,
.emoji-option:focus-visible,
.secondary-btn:focus-visible,
.backup-dialog button:focus-visible {
  outline: 2px solid var(--ui-border-strong);
  outline-offset: 2px;
}

.workspace-mode-notice,
.app-status,
.update-ready-notice {
  position: fixed;
  z-index: 20;
  max-width: min(360px, calc(100vw - 32px));
  padding: 9px 11px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 10px;
  background: var(--ui-surface-strong);
  box-shadow: var(--ui-shadow-subtle);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ui-text);
}

.workspace-mode-notice {
  right: 24px;
  bottom: 78px;
}

.app-status {
  left: 24px;
  bottom: 24px;
}

.app-status[data-kind="error"] {
  color: var(--ui-danger-text);
  border-color: var(--ui-danger-border);
  background: color-mix(in srgb, var(--ui-danger-surface) 78%, var(--ui-surface-strong));
}

.update-ready-notice {
  right: 80px;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 9px;
}

.update-ready-notice[hidden] {
  display: none;
}

.update-ready-notice button {
  appearance: none;
  padding: 4px 7px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 6px;
  background: var(--ui-surface-soft);
  color: inherit;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.update-ready-notice button:hover {
  background: var(--ui-surface-strong);
}

.backup-dialog {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.24);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.backup-dialog[hidden] {
  display: none;
}

.backup-dialog-surface {
  width: min(390px, 100%);
  padding: 20px;
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  background: var(--ui-surface-strong);
  box-shadow: var(--ui-shadow-soft);
  color: var(--ui-text);
}

.backup-dialog-eyebrow {
  margin: 0 0 5px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ui-text-muted);
}

.backup-dialog h2 {
  margin: 0;
  font-family: 'Inter Tight', system-ui, sans-serif;
  font-size: 21px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.backup-dialog p:not(.backup-dialog-eyebrow) {
  margin: 9px 0 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ui-text-muted);
}

.backup-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* Publish dialog */
#publishDialog .backup-dialog-surface {
  width: min(460px, 100%);
}

.publish-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  color: var(--ui-text);
  cursor: pointer;
}

.publish-option[hidden] {
  display: none;
}

.publish-option input {
  accent-color: var(--selection-color);
  cursor: pointer;
}

.publish-link-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.publish-link-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 8px;
  background: var(--ui-surface-soft);
  color: var(--ui-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
}

/* .secondary-btn is full-width by default in the settings panel; beside the
   link field it should only be as wide as its label. */
.publish-link-row .secondary-btn {
  flex: 0 0 auto;
  width: auto;
  white-space: nowrap;
}

.publish-size {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
}

.backup-dialog p.publish-size {
  margin-top: 8px;
}

.publish-size[data-tier='very-long'] {
  color: var(--text-color);
}

body.workspace-readonly #editor {
  cursor: default;
}

body.workspace-readonly #drawingLayer {
  pointer-events: none;
}

.legal-page-body {
  min-height: 100%;
  padding: 64px 24px;
  background: var(--bg-color);
}

.legal-page {
  width: min(680px, 100%);
  margin: 0 auto;
  color: var(--text-color);
}

.legal-back,
.legal-eyebrow,
.legal-page p,
.legal-page h2 {
  font-family: system-ui, -apple-system, sans-serif;
}

.legal-back {
  display: inline-block;
  margin-bottom: 36px;
  color: inherit;
  font-size: 13px;
  text-underline-offset: 3px;
}

.legal-eyebrow {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.65;
}

.legal-page h1 {
  max-width: 13ch;
  margin: 0;
  font-family: 'Inter Tight', system-ui, sans-serif;
  font-size: clamp(38px, 8vw, 64px);
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.legal-page h2 {
  margin: 38px 0 8px;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.legal-page p:not(.legal-eyebrow) {
  max-width: 62ch;
  margin: 14px 0 0;
  font-size: 16px;
  line-height: 1.65;
}

/* Responsive */
@media (max-width: 768px) {
  #editor {
    padding: 48px 24px 100px 24px;
  }

  .top-right-rail {
    flex-direction: column;
    align-items: flex-end;
    right: 16px;
    top: 16px;
    gap: 10px;
  }

  /* The toolbar keeps hanging to the left of its arrow here too — stacking it
     above would push it off the top of the screen — it just wraps to fit. */
  .drawing-toolbar {
    right: calc(100% + 10px);
    width: max-content;
    max-width: min(100vw - 104px, 236px);
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
    padding: 5px;
  }

   .drawing-toolbar-group {
    gap: 2px;
  }

  .drawing-toolbar-group-actions {
    margin-left: 2px;
    padding-left: 6px;
  }

  .drawing-tool-button {
    width: 36px;
    height: 36px;
  }
  
  .controls-container {
    bottom: 20px;
    right: 20px;
  }
  
  .controls-panel {
    width: min(280px, calc(100vw - 32px));
    padding: 12px;
  }
  
  .theme-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  
  .color-controls {
    gap: 5px;
  }

  .page-tabs-list {
    padding: 3px;
    border-radius: 12px;
  }
  
  .page-tab {
    flex: 0 0 40px;
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    border-radius: 9px;
  }

  .page-tab-emoji {
    font-size: 20px;
  }

  .add-page-btn {
    flex: 0 0 40px;
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
  }
  
  .emoji-picker {
    width: min(280px, calc(100vw - 24px));
    padding: 14px;
  }

  .page-preview {
    width: min(240px, calc(100vw - 32px));
    padding: 11px 12px;
  }
  
  .emoji-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
  }
  
  .emoji-option {
    width: 40px;
    height: 40px;
    padding: 5px;
  }
  
  .word-count {
    bottom: 26px;
    right: 66px;
  }

  .workspace-mode-notice,
  .update-ready-notice {
    right: 16px;
    bottom: 72px;
  }

  .app-status {
    left: 16px;
    bottom: 16px;
  }
}

/* Word/Character Count */
.word-count {
  position: fixed;
  bottom: 30px;
  right: 70px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-color);
  opacity: 0.3;
  pointer-events: none;
  transition: opacity 0.2s ease;
  font-variant-numeric: tabular-nums;
}

.word-count.is-empty {
  opacity: 0;
}

/* Drag and Drop Styling */
.page-tab.dragging {
  opacity: 0.5;
  transform: scale(0.95);
}

.page-tab.drag-over {
  border: 2px dashed var(--text-color);
  opacity: 0.7;
}

/* Print Styles */
@media print {
  body {
    background: white !important;
  }
  
  #editor {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    min-height: auto !important;
    color: black !important;
    background: white !important;
  }
  
  .controls-container,
  .top-right-rail,
  .save-indicator,
  .word-count,
  .emoji-picker {
    display: none !important;
  }
}

/* --- Published note reader (read.html) ------------------------------------
   Reuses the editor's bundled fonts and colour variables so a published note
   looks the way it did in the editor that made it. */
.reader-body {
  background-color: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  transition: background-color 0.3s ease;
}

.reader-board {
  position: relative;
  width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  background-color: var(--bg-color);
}

.reader-shell {
  width: min(100%, var(--max-width));
  position: relative;
  z-index: 1;
  padding: 48px 48px 120px 48px;
}

.reader-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 28px;
}

/* An explicit display value would otherwise beat the hidden attribute and
   leave an empty title row (or a full-height error panel) in the layout. */
.reader-header[hidden],
.reader-state[hidden] {
  display: none;
}

.reader-emoji {
  font-size: 20px;
  line-height: 1;
}

.reader-title {
  font-family: var(--font-family);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-color);
}

.reader-meta {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--ui-text-muted);
  margin-left: auto;
}

.reader-content {
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  color: var(--text-color);
  white-space: pre-wrap;
  word-wrap: break-word;
  tab-size: 6;
  -moz-tab-size: 6;
}

.reader-content img {
  display: block;
  inline-size: auto;
  max-inline-size: min(100%, 32em);
  block-size: auto;
  margin-block: 0.75em;
}

.reader-drawings {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 2;
  pointer-events: none;
}

.reader-footer {
  position: fixed;
  right: 20px;
  bottom: 16px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  z-index: 3;
}

.reader-footer a {
  color: var(--ui-text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  background: var(--bg-color);
}

.reader-footer a:hover {
  color: var(--text-color);
}

.reader-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.reader-state-surface {
  max-width: 44ch;
  text-align: center;
  font-family: 'Inter', sans-serif;
}

.reader-state-eyebrow {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ui-text-muted);
  margin-bottom: 10px;
}

.reader-state-surface h1 {
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 10px;
  color: var(--text-color);
}

.reader-state-surface p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ui-text-muted);
}

.reader-state-action {
  display: inline-block;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-color);
  text-decoration: none;
  padding: 8px 14px;
  border: 1px solid var(--ui-border);
  border-radius: 999px;
}

/* The reader's padding is set in src/ui/reader.js from the width the note was
   published at rather than from the viewer's screen, because it is part of
   where the strokes sit relative to the first line. These values only apply
   before that runs. */

@media print {
  .reader-footer,
  .reader-state {
    display: none !important;
  }

  .reader-shell {
    padding: 0 !important;
  }
}
