/* =========================================================================
   Razvan Notes — "Graphite, Warmed"
   Dark-first, single-accent, system-font, zero-build.
   Warm near-black graphite ground · one scarce cyan-teal accent (WCAG AAA)
   · one continuous surface · luminous caret · pressed-paper input wells
   · thumb-zone FAB on touch. Built to stay razor-crisp in Edge app-mode
   and exceptional on Android.
   Every selector app.js depends on is preserved verbatim.
   ========================================================================= */

:root {
  color-scheme: dark;

  /* ---- Surfaces & ink (warm-graphite neutrals) ---- */
  --bg: #0B0D11;
  --surface: #13161C;
  --surface-elevated: #191D25;
  --hover: #1B202A;
  --pressed: #222834;
  --ink: #EAEDF3;
  --ink-bright: #F5F7FB;
  --muted: #8B94A4;
  --faint: #5C6675;
  --line: #242A34;
  --line-soft: rgba(36, 42, 52, 0.6);
  --hairline-top: rgba(255, 255, 255, 0.035);

  /* ---- The one scarce accent (cyan-teal) ---- */
  --accent: #37E0CF;
  --accent-hover: #54E8DA;
  --accent-press: #28C5B5;
  --accent-ink: #03110F;
  --accent-soft: rgba(55, 224, 207, 0.12);
  --accent-softer: rgba(55, 224, 207, 0.07);
  --accent-rail: rgba(55, 224, 207, 0.3);
  --focus-ring: rgba(55, 224, 207, 0.55);
  --caret: #54E8DA;
  --selection-bg: rgba(55, 224, 207, 0.24);
  --selection-ink: #F5F7FB;

  /* ---- Status ---- */
  --positive: #5BE7B0;
  --positive-soft: rgba(91, 231, 176, 0.1);
  --positive-line: rgba(91, 231, 176, 0.3);
  --danger: #FF6B72;
  --danger-soft: rgba(255, 107, 114, 0.12);
  --danger-line: rgba(255, 107, 114, 0.32);

  --scrollbar-thumb: #2C333D;
  --scrollbar-thumb-hover: #3A424E;

  /* ---- Depth (shadows reserved for vault panel + modal only) ---- */
  --shadow-overlay: 0 24px 60px -12px rgba(0, 0, 0, 0.62);
  --shadow-panel: 0 24px 60px -16px rgba(0, 0, 0, 0.55);
  --glow-primary: 0 4px 18px -6px rgba(55, 224, 207, 0.42);
  --glow-rec: 0 0 0 4px rgba(255, 107, 114, 0.16), 0 0 22px -4px rgba(255, 107, 114, 0.45);
  --inset-well: inset 0 1px 2px rgba(0, 0, 0, 0.3);

  /* ---- Radii ---- */
  --r-xs: 6px;
  --r-sm: 8px;
  --r: 10px;
  --r-md: 13px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* ---- Spacing scale ---- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 44px;

  /* ---- Type ---- */
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
  --fs-micro: 11px;
  --fs-meta: 12px;
  --fs-preview: 13px;
  --fs-control: 14px;
  --fs-note-title: 14.5px;
  --fs-body: 16.5px;
  --fs-input: 16px;
  --fs-share-h: 20px;
  --fs-vault-h: 26px;
  --fs-title: 30px;

  --topbar-h: 54px;

  /* ---- Motion ---- */
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --ease-quiet: cubic-bezier(0.22, 0.61, 0.36, 1);
  --t-fast: 110ms;
  --t: 150ms;
  --t-slow: 240ms;

  /* ---- Safe areas ---- */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);

  --measure: 72ch;

  font-family: var(--font-ui);
  font-feature-settings: "cv05" 1, "ss01" 1, "tnum" 1;
}

/* Opt-in light theme — gated behind a class only, never prefers-color-scheme,
   so DARK stays the default on every device (per user choice). */
.theme-light {
  color-scheme: light;
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --surface-elevated: #FFFFFF;
  --hover: #EEF1F6;
  --pressed: #E4E9F0;
  --ink: #11151B;
  --ink-bright: #0A0D12;
  --muted: #5A6472;
  --faint: #8A93A2;
  --line: #DCE2EB;
  --line-soft: rgba(220, 226, 235, 0.7);
  --hairline-top: rgba(255, 255, 255, 0.6);
  --accent: #0E8C7F;
  --accent-hover: #0A7568;
  --accent-press: #086256;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(14, 140, 127, 0.1);
  --accent-softer: rgba(14, 140, 127, 0.06);
  --accent-rail: rgba(14, 140, 127, 0.3);
  --focus-ring: rgba(14, 140, 127, 0.55);
  --caret: #0A7568;
  --selection-bg: rgba(14, 140, 127, 0.18);
  --selection-ink: #0A0D12;
  --positive: #0E8C7F;
  --positive-soft: rgba(14, 140, 127, 0.1);
  --positive-line: rgba(14, 140, 127, 0.3);
  --danger: #C8323A;
  --danger-soft: rgba(200, 50, 58, 0.1);
  --danger-line: rgba(200, 50, 58, 0.3);
  --scrollbar-thumb: #C4CCD8;
  --scrollbar-thumb-hover: #A9B3C2;
  --shadow-overlay: 0 24px 60px -12px rgba(17, 24, 39, 0.18);
  --shadow-panel: 0 18px 44px -16px rgba(17, 24, 39, 0.14);
  --inset-well: inset 0 1px 2px rgba(17, 24, 39, 0.06);
}

/* ---------- Base reset (kept compatible with app.js) ---------- */
* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.sprite {
  display: none;
}

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

::selection {
  background: var(--selection-bg);
  color: var(--selection-ink);
}

/* Luminous caret — signature detail. */
#titleInput,
#bodyInput,
.list-input,
#vaultKeyInput,
#searchInput,
#shareValueInput {
  caret-color: var(--caret);
}

/* Crisp keyboard focus over any dark surface; mouse clicks stay ring-free. */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--focus-ring);
}

input:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
}

/* =========================================================================
   App shell
   ========================================================================= */
.app-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

@supports (height: 100dvh) {
  .app-shell {
    min-height: 100dvh;
  }
}

/* =========================================================================
   Topbar — flat, NO blur (the key Edge app-mode crispness decision)
   ========================================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) clamp(12px, 3vw, 28px) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 1px 0 var(--hairline-top);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.brand img {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px var(--accent-softer);
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 680;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Sync status: a quiet mono LED readout ---------- */
.sync-status {
  position: relative;
  min-width: 96px;
  max-width: 168px;
  padding: 5px 10px 5px 22px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--t), background-color var(--t), border-color var(--t);
}

.sync-status::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.sync-status.good {
  color: var(--positive);
  border-color: var(--positive-line);
  background: var(--positive-soft);
}

.sync-status.good::before {
  animation: dot-pulse 1.4s var(--ease-quiet) 1;
}

.sync-status.bad {
  color: var(--danger);
  border-color: var(--danger-line);
  background: var(--danger-soft);
}

/* =========================================================================
   Buttons
   ========================================================================= */
.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: transparent;
  color: var(--muted);
  transition: background-color var(--t-fast), color var(--t-fast),
    border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}

.icon-button.compact {
  width: 34px;
  height: 34px;
  border-radius: var(--r-xs);
}

.icon-button:active {
  background: var(--pressed);
  transform: scale(0.96);
}

.icon-button.primary {
  border-color: color-mix(in srgb, var(--accent) 82%, #000);
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--glow-primary);
}

.icon-button.primary:active {
  background: var(--accent-press);
  transform: scale(0.97);
}

.icon-button.danger {
  color: var(--danger);
}

.icon-button.recording {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: var(--glow-rec);
  animation: rec-breathe 1.6s ease-in-out infinite;
}

.icon-button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* Icon glyph rendering */
.search-field svg,
.icon-button svg,
.mode-button svg,
.vault-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.vault-icon svg {
  width: 22px;
  height: 22px;
  stroke-width: 2;
}

.text-button {
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 82%, #000);
  border-radius: var(--r);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 680;
  letter-spacing: -0.01em;
  box-shadow: var(--glow-primary);
  transition: background-color var(--t-fast), border-color var(--t-fast),
    transform var(--t-fast), box-shadow var(--t-fast);
}

.text-button:active {
  transform: scale(0.97);
  background: var(--accent-press);
}

.text-button.secondary {
  border-color: var(--line);
  background: transparent;
  color: var(--ink);
  box-shadow: none;
}

.text-button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =========================================================================
   Workspace — sidebar + editor as ONE continuous surface
   ========================================================================= */
.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(264px, 27vw, 332px) minmax(0, 1fr);
}

.sidebar {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--line);
}

.sidebar-tools {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: var(--s-2);
  padding: var(--s-3);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

/* Pressed-paper search well */
.search-field {
  min-width: 0;
  height: 40px;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  box-shadow: var(--inset-well);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.search-field svg {
  flex: 0 0 auto;
  color: var(--muted);
  transition: color var(--t-fast);
}

.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: var(--inset-well), 0 0 0 3px var(--accent-soft);
}

.search-field:focus-within svg {
  color: var(--accent);
}

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

.search-field input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

/* New note — the one saturated control (matches search height on desktop) */
#newNoteBtn {
  width: 44px;
  height: 40px;
}

/* ---------- Notes list ---------- */
.notes-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--s-2);
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.note-item {
  width: 100%;
  display: grid;
  gap: 3px;
  margin-bottom: 2px;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: transparent;
  text-align: left;
  color: inherit;
  transition: background-color var(--t-fast), border-color var(--t-fast),
    box-shadow var(--t), transform var(--t-fast);
  animation: item-in 120ms var(--ease-out);
}

.note-item:active {
  transform: scale(0.99);
}

.note-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-rail);
  box-shadow: inset 2px 0 0 var(--accent);
}

.note-title-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.note-title {
  min-width: 0;
  font-size: var(--fs-note-title);
  font-weight: 540;
  line-height: 1.25;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-item.active .note-title {
  color: var(--ink-bright);
}

.note-pin {
  width: 15px;
  height: 15px;
  display: inline-grid;
  place-items: center;
  color: var(--accent);
  opacity: 0.9;
}

.note-pin svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.note-item.pinned:not(.active) {
  background: var(--accent-softer);
  border-color: var(--line-soft);
}

.note-preview {
  min-width: 0;
  color: var(--muted);
  font-size: var(--fs-preview);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-time {
  margin-top: 2px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1;
}

.empty-list {
  display: grid;
  place-items: center;
  gap: var(--s-3);
  min-height: 200px;
  padding: var(--s-6);
  color: var(--muted);
  font-size: var(--fs-preview);
  text-align: center;
}

.empty-list::before {
  content: "";
  width: 40px;
  height: 40px;
  background: var(--faint);
  opacity: 0.5;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 3h7l5 5v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z'/%3E%3Cpath d='M14 3v5h5'/%3E%3Cpath d='M9 13h6M9 17h4'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 3h7l5 5v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z'/%3E%3Cpath d='M14 3v5h5'/%3E%3Cpath d='M9 13h6M9 17h4'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* =========================================================================
   Editor pane (4-row grid preserved exactly)
   ========================================================================= */
.editor-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--bg);
}

/* Shared 72ch writing measure — applied PER-ELEMENT (no wrapper, contract-safe) */
.editor-top,
.editor-toolbar,
#richEditor,
#bodyInput,
#listEditor {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
}

.editor-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3);
  padding: clamp(16px, 3vw, 30px) clamp(16px, 4vw, 46px) 6px;
}

.back-button {
  display: none;
}

.title-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: var(--fs-title);
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.title-input::placeholder {
  color: var(--faint);
  opacity: 0.7;
}

.pin-note-button.active {
  color: var(--accent);
  border-color: var(--accent-rail);
  background: var(--accent-soft);
}

.sticky-mode-button.active {
  color: var(--accent-ink);
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: var(--glow-primary);
}

.editor-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3);
  padding: 6px clamp(16px, 4vw, 46px) 10px;
  border-bottom: 1px solid var(--line);
}

.mode-toggle,
.format-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.mode-toggle {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}

.mode-button {
  width: 34px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--muted);
  transition: background-color var(--t), color var(--t);
}

.mode-button.active {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

.format-actions.ql-toolbar.ql-snow {
  border: 0;
  padding: 0;
}

.rich-select {
  height: 34px;
}

.ql-snow .ql-picker {
  height: 34px;
  color: var(--muted);
  font-size: var(--fs-control);
}

.ql-snow .ql-picker-label {
  display: inline-flex;
  align-items: center;
  min-width: 72px;
  height: 34px;
  border: 1px solid var(--line) !important;
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--muted);
  padding: 0 28px 0 10px;
}

.ql-snow .ql-picker.ql-expanded .ql-picker-label,
.ql-snow .ql-picker-label:hover {
  color: var(--ink);
  border-color: var(--accent-rail) !important;
}

.ql-snow .ql-picker-options {
  border: 1px solid var(--line) !important;
  border-radius: var(--r-sm);
  background: var(--surface-elevated);
  color: var(--ink);
  box-shadow: var(--shadow-panel);
  padding: 6px;
}

.ql-snow .ql-picker-item {
  border-radius: var(--r-xs);
  padding: 6px 10px;
}

.ql-snow .ql-picker-item:hover,
.ql-snow .ql-picker-item.ql-selected {
  background: var(--accent-soft);
  color: var(--ink-bright);
}

.ql-snow .ql-stroke {
  stroke: currentColor;
}

.ql-snow .ql-fill {
  fill: currentColor;
}

.format-actions.ql-toolbar.ql-snow .icon-button {
  float: none;
  padding: 0;
}

.format-actions.ql-toolbar.ql-snow button.ql-active,
.format-actions.ql-toolbar.ql-snow .ql-picker-label.ql-active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* Subtle grouping divider between heading tools and list tools */
.format-actions #numberBtn {
  position: relative;
  margin-left: 7px;
}

.format-actions #numberBtn::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 50%;
  width: 1px;
  height: 18px;
  margin-top: -9px;
  background: var(--line);
}

.voice-button {
  justify-self: end;
}

/* ---------- Body & list editors ---------- */
.rich-editor {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
  background: transparent;
}

.rich-editor.ql-container.ql-snow {
  border: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
}

.rich-editor .ql-editor {
  min-height: 100%;
  padding: 14px clamp(16px, 4vw, 46px) 48px;
  color: var(--ink);
  font-size: var(--fs-body);
  line-height: 1.7;
  letter-spacing: -0.002em;
  caret-color: var(--caret);
}

.rich-editor .ql-editor:focus {
  outline: 1px solid var(--focus-ring);
  outline-offset: -1px;
}

.rich-editor .ql-editor.ql-blank::before {
  color: var(--faint);
  font-style: normal;
  left: clamp(16px, 4vw, 46px);
  right: clamp(16px, 4vw, 46px);
}

.rich-editor .ql-font-serif {
  font-family: Georgia, "Times New Roman", serif;
}

.rich-editor .ql-font-mono {
  font-family: var(--font-mono);
}

.ql-snow .ql-picker.ql-font .ql-picker-label::before,
.ql-snow .ql-picker.ql-font .ql-picker-item::before {
  content: "Sans";
}

.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="serif"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="serif"]::before {
  content: "Serif";
  font-family: Georgia, "Times New Roman", serif;
}

.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="mono"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="mono"]::before {
  content: "Mono";
  font-family: var(--font-mono);
}

.rich-editor .ql-size-small {
  font-size: 0.85em;
}

.rich-editor .ql-size-large {
  font-size: 1.28em;
}

.rich-editor .ql-size-huge {
  font-size: 1.62em;
}

.rich-editor ol,
.rich-editor ul {
  padding-left: 1.4em;
}

.rich-editor li[data-list="checked"] {
  color: var(--muted);
  text-decoration: line-through;
}

.body-input {
  min-width: 0;
  min-height: 0;
  padding: 14px clamp(16px, 4vw, 46px) 48px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-size: var(--fs-body);
  line-height: 1.7;
  letter-spacing: -0.002em;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.list-editor {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px clamp(16px, 4vw, 46px) 48px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.list-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 36px;
  align-items: center;
  gap: var(--s-3);
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}

.list-row:last-child {
  border-bottom: 0;
}

.list-check {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin: 0;
  justify-self: center;
  border: 1.5px solid var(--faint);
  border-radius: var(--r-xs);
  background: transparent;
  display: grid;
  place-content: center;
  transition: background-color var(--t), border-color var(--t);
}

.list-check:checked {
  background-color: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2303110F' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 14px;
  animation: check-pop 180ms var(--ease-out);
}

.list-input {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: var(--fs-input);
  line-height: 1.45;
}

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

.list-row.done {
  opacity: 0.7;
  transition: opacity var(--t);
}

.list-delete {
  opacity: 0.4;
  transition: opacity var(--t-fast), background-color var(--t-fast), color var(--t-fast);
}

.body-input::placeholder,
.search-field input::placeholder,
.list-input::placeholder {
  color: var(--faint);
}

/* ---------- Editor footer (full-width chrome, not capped) ---------- */
.editor-footer {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 8px clamp(16px, 4vw, 46px) calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
}

#noteMeta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Sticky note mode — a calm, one-note surface for keeping the app around
   ========================================================================= */
.sticky-mode-body {
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  background: #2D2F34;
}

.app-shell.sticky-mode {
  width: 100vw;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  border-inline: 0;
  background: #2D2F34;
  box-shadow: none;
}

.app-shell.sticky-mode .topbar,
.app-shell.sticky-mode .sidebar,
.app-shell.sticky-mode .editor-footer {
  display: none;
}

.app-shell.sticky-mode .workspace {
  min-height: 100vh;
  min-height: 100svh;
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.sticky-mode .editor-pane {
  grid-template-rows: auto auto minmax(0, 1fr);
  background:
    linear-gradient(180deg, #FFC928 0 38px, transparent 38px),
    #2D2F34;
}

.app-shell.sticky-mode .editor-top,
.app-shell.sticky-mode .editor-toolbar,
.app-shell.sticky-mode #richEditor,
.app-shell.sticky-mode #bodyInput,
.app-shell.sticky-mode #listEditor {
  max-width: none;
}

.app-shell.sticky-mode .editor-top {
  grid-template-columns: minmax(0, 1fr) 36px 36px;
  min-height: 78px;
  padding: 48px 12px 4px;
  gap: 6px;
}

.app-shell.sticky-mode .back-button {
  display: none;
}

.app-shell.sticky-mode .title-input {
  color: #F7F8FA;
  font-size: 19px;
  line-height: 1.18;
  font-weight: 760;
  letter-spacing: 0;
}

.app-shell.sticky-mode .pin-note-button,
.app-shell.sticky-mode .sticky-mode-button {
  width: 34px;
  height: 34px;
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  color: #D7DADF;
}

.app-shell.sticky-mode .sticky-mode-button.active {
  background: rgba(255, 201, 40, 0.96);
  border-color: rgba(255, 201, 40, 0.96);
  color: #211800;
  box-shadow: none;
}

.app-shell.sticky-mode .editor-toolbar {
  grid-template-columns: auto minmax(0, 1fr) 40px;
  padding: 2px 12px 8px;
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.app-shell.sticky-mode .mode-toggle {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
}

.app-shell.sticky-mode .format-actions {
  justify-content: flex-start;
  opacity: 0.62;
  overflow: hidden;
}

.app-shell.sticky-mode .format-actions .ql-picker,
.app-shell.sticky-mode .format-actions #boldBtn,
.app-shell.sticky-mode .format-actions #italicBtn,
.app-shell.sticky-mode .format-actions #underlineBtn,
.app-shell.sticky-mode .format-actions #headingBtn,
.app-shell.sticky-mode .format-actions #clearFormatBtn {
  display: none;
}

.app-shell.sticky-mode .format-actions #numberBtn::before {
  display: none;
}

.app-shell.sticky-mode .rich-editor .ql-editor,
.app-shell.sticky-mode .body-input {
  padding: 14px 16px 28px;
  color: #F2F4F8;
  font-size: 17px;
  line-height: 1.56;
  letter-spacing: 0;
}

.app-shell.sticky-mode .rich-editor .ql-editor:focus {
  outline: none;
}

.app-shell.sticky-mode .rich-editor li[data-list="checked"] {
  color: #AEB4BF;
}

.app-shell.sticky-mode .list-editor {
  padding: 8px 12px 28px;
}

.app-shell.sticky-mode .list-row {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.app-shell.sticky-mode .list-input {
  color: #F2F4F8;
  font-size: 17px;
}

.app-shell.sticky-mode .list-delete {
  opacity: 0;
}

.app-shell.sticky-mode .list-row:hover .list-delete,
.app-shell.sticky-mode .list-delete:focus-visible {
  opacity: 1;
}

/* =========================================================================
   Vault screen
   ========================================================================= */
.vault-screen {
  min-height: calc(100vh - var(--topbar-h));
  min-height: calc(100svh - var(--topbar-h));
  display: grid;
  place-items: center;
  padding: calc(var(--s-6) + var(--safe-top)) calc(var(--s-6) + var(--safe-right))
    calc(var(--s-6) + var(--safe-bottom)) calc(var(--s-6) + var(--safe-left));
}

@supports (height: 100dvh) {
  .vault-screen {
    min-height: calc(100dvh - var(--topbar-h));
  }
}

.vault-panel {
  width: min(100%, 420px);
  display: grid;
  gap: var(--s-5);
  padding: 30px 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-panel), inset 0 1px 0 var(--hairline-top);
  animation: panel-rise var(--t-slow) var(--ease-quiet);
}

.vault-icon {
  position: relative;
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  color: var(--accent);
}

.vault-icon::after {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: var(--r-lg);
  background: radial-gradient(circle at center, var(--accent-soft), transparent 68%);
  z-index: -1;
}

.vault-panel h2 {
  margin: 0;
  font-size: var(--fs-vault-h);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink-bright);
}

.vault-form {
  display: grid;
  gap: var(--s-2);
}

.vault-form label {
  color: var(--muted);
  font-size: var(--fs-micro);
  font-weight: 540;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.vault-note {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-meta);
  text-align: center;
}

.key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-2);
}

/* ---------- Pressed-paper input wells (vault + share) ---------- */
.key-row input,
.share-field input {
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs-input);
  box-shadow: var(--inset-well);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.key-row input:focus-visible,
.share-field input:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--inset-well), 0 0 0 3px var(--accent-soft);
}

/* =========================================================================
   Share overlay (the only blur in the app — modal focus)
   ========================================================================= */
.share-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(6, 8, 11, 0.66);
  -webkit-backdrop-filter: blur(4px) saturate(120%);
  backdrop-filter: blur(4px) saturate(120%);
  animation: fade-in var(--t) var(--ease-quiet);
}

.share-panel {
  width: min(100%, 460px);
  display: grid;
  gap: var(--s-3);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-overlay), inset 0 1px 0 var(--hairline-top);
  animation: panel-pop var(--t) var(--ease-quiet);
}

.share-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.share-panel h2 {
  margin: 0;
  font-size: var(--fs-share-h);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink-bright);
}

.share-field {
  display: grid;
  gap: 7px;
}

.share-field span {
  color: var(--muted);
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.share-field input {
  font-family: var(--font-mono);
  font-size: var(--fs-control);
}

#copyShareValueBtn {
  width: 100%;
}

/* =========================================================================
   Scrollbars (WebKit)
   ========================================================================= */
.notes-list::-webkit-scrollbar,
.rich-editor::-webkit-scrollbar,
.list-editor::-webkit-scrollbar,
.body-input::-webkit-scrollbar {
  width: 10px;
}

.notes-list::-webkit-scrollbar-track,
.rich-editor::-webkit-scrollbar-track,
.list-editor::-webkit-scrollbar-track,
.body-input::-webkit-scrollbar-track {
  background: transparent;
}

.notes-list::-webkit-scrollbar-thumb,
.rich-editor::-webkit-scrollbar-thumb,
.list-editor::-webkit-scrollbar-thumb,
.body-input::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--r-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

/* =========================================================================
   Keyframes
   ========================================================================= */
@keyframes dot-pulse {
  0% { transform: scale(1); opacity: 0.85; }
  40% { transform: scale(1.5); opacity: 1; }
  100% { transform: scale(1); opacity: 0.85; }
}

@keyframes rec-breathe {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 107, 114, 0.1), 0 0 14px -6px rgba(255, 107, 114, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(255, 107, 114, 0.18), 0 0 26px -4px rgba(255, 107, 114, 0.55); }
}

@keyframes check-pop {
  0% { transform: scale(0.8); }
  55% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes item-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes panel-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* #refreshBtn spins while a sync is in flight (class set by enhancements.js) */
.icon-button.is-busy svg {
  animation: spin 600ms linear infinite;
  transform-origin: center;
}

/* =========================================================================
   Hover states — gated so they never stick on touch devices
   ========================================================================= */
@media (hover: hover) {
  .icon-button:hover {
    background: var(--hover);
    color: var(--ink);
    border-color: var(--line);
  }

  .icon-button.primary:hover {
    background: var(--accent-hover);
    color: var(--accent-ink);
    border-color: color-mix(in srgb, var(--accent) 82%, #000);
    transform: translateY(-1px);
  }

  .icon-button.danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
  }

  .text-button:hover {
    background: var(--accent-hover);
  }

  .text-button.secondary:hover {
    background: var(--hover);
    border-color: var(--accent-rail);
  }

  .note-item:hover {
    background: var(--hover);
  }

  .mode-button:hover:not(.active) {
    color: var(--ink);
  }

  .format-actions .icon-button:hover {
    background: var(--hover);
    color: var(--ink);
  }

  .voice-button:hover:not(.recording) {
    background: var(--accent-soft);
    color: var(--accent);
  }

  .list-row:hover .list-delete,
  .list-delete:focus-visible {
    opacity: 1;
  }

  .list-delete:hover {
    background: var(--danger-soft);
  }

  .notes-list::-webkit-scrollbar-thumb:hover,
  .rich-editor::-webkit-scrollbar-thumb:hover,
  .list-editor::-webkit-scrollbar-thumb:hover,
  .body-input::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
  }
}

/* =========================================================================
   Touch / coarse pointer — promote every target to >=44px,
   make destructive actions always reachable (no hover-only).
   Gated by POINTER, not width, so hybrid touch laptops behave too.
   ========================================================================= */
@media (pointer: coarse), (hover: none) {
  .icon-button {
    width: 44px;
    height: 44px;
  }

  .icon-button.compact {
    width: 44px;
    height: 44px;
  }

  .mode-button {
    width: 44px;
    height: 44px;
  }

  .text-button {
    min-height: 44px;
  }

  .search-field {
    height: 44px;
  }

  #newNoteBtn {
    width: 48px;
    height: 44px;
  }

  .list-row {
    grid-template-columns: 30px minmax(0, 1fr) 44px;
  }

  .list-delete {
    opacity: 1;
  }
}

/* =========================================================================
   Mobile — single-pane model (PRESERVED) + density + thumb-zone FAB
   ========================================================================= */
@media (max-width: 760px) {
  :root {
    --topbar-h: 52px;
  }

  .brand h1 {
    font-size: 15px;
  }

  .sync-status {
    min-width: 70px;
    max-width: 116px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .app-shell.is-editing .sidebar {
    display: none;
  }

  .app-shell:not(.is-editing) .editor-pane {
    display: none;
  }

  /* Incoming editor fades in (the visible pane only — never the display swap) */
  .app-shell.is-editing .editor-pane {
    animation: pane-enter var(--t) var(--ease-quiet);
  }

  .sidebar {
    border-right: 0;
  }

  /* Search fills the row; the + button becomes a floating thumb-zone FAB */
  .sidebar-tools {
    grid-template-columns: minmax(0, 1fr);
  }

  .notes-list {
    padding-bottom: calc(var(--s-2) + var(--safe-bottom) + 80px);
  }

  .app-shell:not(.is-editing) #newNoteBtn {
    position: fixed;
    right: calc(16px + var(--safe-right));
    bottom: calc(20px + var(--safe-bottom));
    width: 56px;
    height: 56px;
    border-radius: var(--r-pill);
    z-index: 15;
    box-shadow: var(--glow-primary), 0 8px 24px -6px rgba(0, 0, 0, 0.5);
  }

  .app-shell:not(.is-editing) #newNoteBtn svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
  }

  .editor-top {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    padding: 10px 14px 4px;
  }

  .back-button {
    display: inline-grid;
  }

  .title-input {
    font-size: clamp(22px, 6vw, 30px);
  }

  .editor-toolbar {
    grid-template-columns: auto minmax(0, 1fr) 44px;
    padding: 6px 14px 10px;
  }

  /* Only the toolbar's format cluster scrolls horizontally — page never does */
  .format-actions {
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
  }

  .format-actions::-webkit-scrollbar {
    display: none;
  }

  .body-input {
    font-size: var(--fs-input);
    padding: 12px 16px 40px;
  }

  .rich-editor .ql-editor {
    font-size: var(--fs-input);
    padding: 12px 16px 40px;
  }

  .list-editor {
    padding: 6px 16px 40px;
  }

  .vault-panel {
    padding: 26px 22px;
  }
}

/* Phones: drop the wordmark (icon persists) and tighten the action cluster so
   the four topbar controls + status pill never clip, even at 44px touch size. */
@media (max-width: 480px) {
  .brand h1 {
    display: none;
  }

  .top-actions {
    gap: 4px;
  }

  .sync-status {
    min-width: 0;
    max-width: 96px;
  }
}

/* =========================================================================
   Ultrawide refinement
   ========================================================================= */
@media (min-width: 1480px) {
  .editor-top,
  .editor-toolbar,
  #richEditor,
  #bodyInput,
  #listEditor {
    max-width: 74ch;
  }
}

/* =========================================================================
   Reduced motion — collapse everything to instant / opacity-only
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .icon-button.recording {
    animation: none;
  }
}
