/* ============================================================
   Notes - Antinote-inspired minimal notes app
   Plain vanilla CSS. No frameworks, no build step.
   ============================================================ */

:root {
  /* Paper + ink (neutral light-gray paper, gray ink — like Antinote) */
  --paper:        #f6f6f4;   /* light neutral background */
  --dot:          #cfcfca;   /* dot-grid color */
  --ink:          #35383a;   /* main body text (gray) */
  --ink-soft:     #66665e;   /* secondary text */
  --ink-faint:    #9e9d94;   /* placeholder / hints */

  /* THEME ACCENT — keyword line, totals, and math results.
     Change this one value to re-theme the highlight color. */
  --accent:       #e2b714;   /* warm golden yellow */
  --accent-hover: #c9a010;
  --selection:    rgba(226, 183, 20, 0.28);
  --diff-highlight: rgba(32, 168, 130, 0.34);
  --search-hit:   rgba(32, 96, 223, 0.22);
  --find-hit:     rgba(32, 96, 223, 0.12);
  --link:         #2060df;   /* link bar accent */
  --shared-accent: #2060df;
  --shared-surface: rgba(32, 96, 223, 0.09);
  --shared-surface-strong: rgba(32, 96, 223, 0.16);

  /* List + code accents */
  --check-box:    #aeada4;
  --check-done:   var(--accent);
  --done-text:    #9e9d94;
  --comment:      #919187;   /* // and # header lines */
  /* Code syntax — Atom One Light–style tokens (matches reference theme). */
  --code-key:     #a626a4;   /* keywords: import, const, as, if, … */
  --code-fn:      #4078f2;   /* method / function calls: foo( */
  --code-str:     #50a14f;   /* strings */
  --code-num:     #c18401;   /* literals, types, params, globals */
  --code-com:     #a0a1a7;   /* comments */
  --code-sel:     #a34f00;   /* CSS .class / #id selectors */
  --code-prop:    #087e8b;   /* CSS properties, HTML attributes */
  --code-tag:     #c41d7f;   /* HTML / XML tag names */
  --code-hex:     #1a7f4b;   /* CSS hex colors */
  --code-at:      #8b27c7;   /* CSS @rules (@media, @keyframes) */

  /* Math variables — ordered for max contrast (slot 0 vs 1 are far apart on the wheel). */
  --math-var-0: #1a56c4;   /* cobalt */
  --math-var-1: #c44b16;   /* vermillion */
  --math-var-2: #0b7a6e;   /* jade */
  --math-var-3: #7b2cbf;   /* amethyst */
  --math-var-4: #b91c5c;   /* raspberry */
  --math-var-5: #2f6b1f;   /* moss */
  --math-var-6: #0e6e8c;   /* peacock */
  --math-var-7: #6b4c9a;   /* dusk violet */

  /* IBM Plex Mono (Google Fonts) with system mono fallbacks. */
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", "SFMono-Regular", "Menlo",
          "DejaVu Sans Mono", "Roboto Mono", "Consolas", monospace;

  /* Body weight is a touch bolder for readability; accent is bold. */
  --edit-weight: 500;
  --accent-weight: 700;

  /* Shared editor metrics — MUST be identical for textarea + backdrop
     so the caret lines up exactly with the rendered decorations. */
  --edit-font-size: 16px;
  --edit-line-height: 1.6;
  --edit-line-box: calc(var(--edit-font-size) * var(--edit-line-height));
  --edit-pad-top: calc(48px - var(--edit-line-box));
  --edit-pad-bottom: calc(3 * var(--edit-line-box));
  --edit-pad-x: 28px;
  --edit-max-width: 760px;

  /* List mode: checkbox + gap; item text is indented by this amount (via tab). */
  --list-check-size: 15px;
  --list-item-gap: 12px;
  --list-item-indent: calc(var(--list-check-size) + var(--list-item-gap));

  --panel-width: 252px;
  --top-bar-height: 45px;
  --timer-bar-height: 22px;
  --timer-bar-offset: 0px;

  --motion-panel: 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  --motion-note: 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  --motion-fade: 0.26s ease;

  /* Semantic surfaces (theme-aware) */
  --border-subtle:  rgba(0, 0, 0, 0.065);
  --border:         rgba(0, 0, 0, 0.085);
  --border-strong:  rgba(0, 0, 0, 0.105);
  --border-hover:   rgba(0, 0, 0, 0.15);
  --surface-muted:  rgba(0, 0, 0, 0.035);
  --surface-hover:  rgba(0, 0, 0, 0.045);
  --surface-active: rgba(0, 0, 0, 0.055);
  --accent-surface: rgba(200, 153, 15, 0.13);
  --accent-surface-strong: rgba(200, 153, 15, 0.19);
  --accent-ring:    rgba(226, 183, 20, 0.21);
  --overlay:        rgba(0, 0, 0, 0.19);
  --overlay-light:  rgba(0, 0, 0, 0.13);
  --shadow-sm:      0 4px 16px rgba(0, 0, 0, 0.18);
  --shadow-md:      0 8px 28px rgba(0, 0, 0, 0.12);
  --shadow-lg:      0 16px 48px rgba(0, 0, 0, 0.14);
  --shadow-panel:   8px 0 32px rgba(0, 0, 0, 0.12);
  --shadow-up:      0 -8px 32px rgba(0, 0, 0, 0.1);
  --tooltip-bg:     rgba(60, 63, 65, 0.92);
  --tooltip-fg:     #fff;
  --popup-bg:       rgba(255, 255, 255, 0.94);
  --danger:         #b42318;
  --danger-hover:   #9f1f15;
  --danger-surface: rgba(180, 35, 24, 0.09);
  --on-primary:     #fff;
  --code-ink:       #282d38;
  --timer-done-scrim: rgba(0, 0, 0, 0.62);
  --timer-done-blur: 12px;
  --timer-done-fg:  #f8f7f4;
  --timer-done-fg-soft: rgba(248, 247, 244, 0.88);
  --timer-list-ink: #1a1a1a;
  --timer-done-btn-bg: #f8f7f4;
  --timer-done-btn-fg: #2a2c2e;
  --timer-done-btn-hover: #ffffff;
}

html[data-theme="dark"] {
  --paper:        #1a1d22;
  --dot:          #2a2e36;
  --ink:          #b8beca;
  --ink-soft:     #a9b1c0;
  --ink-faint:    #7a8290;
  --accent:       #e2b714;
  --accent-hover: #f0c420;
  --selection:    rgba(226, 183, 20, 0.22);
  --diff-highlight: rgba(72, 200, 165, 0.26);
  --search-hit:   rgba(97, 175, 239, 0.22);
  --find-hit:     rgba(97, 175, 239, 0.12);
  --link:         #61afef;
  --shared-accent: #61afef;
  --shared-surface: rgba(97, 175, 239, 0.12);
  --shared-surface-strong: rgba(97, 175, 239, 0.22);
  --check-box:    #666d7a;
  --done-text:    #7a8290;
  --comment:      #888d97;
  --code-ink:     #abb2bf;
  --code-key:     #c678dd;
  --code-fn:      #61afef;
  --code-str:     #98c379;
  --code-num:     #d19a66;
  --code-com:     #5c6370;
  --code-sel:     #e5c07b;
  --code-prop:    #56b6c2;
  --code-tag:     #e06c75;
  --code-hex:     #98c379;
  --code-at:      #c678dd;
  --math-var-0:   #61afef;
  --math-var-1:   #e06c75;
  --math-var-2:   #56b6c2;
  --math-var-3:   #c678dd;
  --math-var-4:   #be5046;
  --math-var-5:   #98c379;
  --math-var-6:   #2bb0b8;
  --math-var-7:   #d19a66;
  --border-subtle:  rgba(255, 255, 255, 0.065);
  --border:         rgba(255, 255, 255, 0.085);
  --border-strong:  rgba(255, 255, 255, 0.105);
  --border-hover:   rgba(255, 255, 255, 0.15);
  --surface-muted:  rgba(255, 255, 255, 0.045);
  --surface-hover:  rgba(255, 255, 255, 0.065);
  --surface-active: rgba(255, 255, 255, 0.085);
  --accent-surface: rgba(226, 183, 20, 0.15);
  --accent-surface-strong: rgba(226, 183, 20, 0.23);
  --accent-ring:    rgba(226, 183, 20, 0.26);
  --overlay:        rgba(0, 0, 0, 0.45);
  --overlay-light:  rgba(0, 0, 0, 0.35);
  --shadow-sm:      0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-md:      0 8px 28px rgba(0, 0, 0, 0.5);
  --shadow-lg:      0 16px 48px rgba(0, 0, 0, 0.55);
  --shadow-panel:   8px 0 32px rgba(0, 0, 0, 0.5);
  --shadow-up:      0 -8px 32px rgba(0, 0, 0, 0.45);
  --tooltip-bg:     rgba(12, 14, 18, 0.97);
  --tooltip-fg:     #eceef1;
  --popup-bg:       rgba(20, 22, 26, 0.98);
  --timer-done-scrim: rgba(0, 0, 0, 0.78);
  --timer-done-blur: 14px;
  --timer-done-fg:  #f0f1f4;
  --timer-done-fg-soft: rgba(240, 241, 244, 0.9);
  --timer-list-ink: #e8e8e6;
  --timer-done-btn-bg: #eef0f3;
  --timer-done-btn-fg: #1a1c1f;
  --timer-done-btn-hover: #ffffff;
  --danger:         #e06c75;
  --danger-hover:   #be5046;
  --danger-surface: rgba(224, 108, 117, 0.13);
  --on-primary:     #14161a;
}

* { box-sizing: border-box; }

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

/* Disable double-tap zoom on mobile (viewport blocks pinch zoom). */
html {
  touch-action: manipulation;
}

body {
  background-color: var(--paper);
  /* Subtle light dot-grid "paper" background */
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: 0 0;
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

.app-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Hide editor chrome until the first note is painted (avoids placeholder flash). */
#app.app-loading .app-body {
  visibility: hidden;
}

.app-splash {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #fff;
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.28s ease-out;
}

#app.app-ready .app-splash {
  opacity: 0;
  pointer-events: none;
}

/* ---------- Notes sidebar ---------- */
.notes-panel {
  flex: 0 0 var(--panel-width);
  width: var(--panel-width);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-right: 1px solid var(--border);
  z-index: 20;
}

#app.panel-closed .notes-panel {
  display: none;
}

.notes-panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  height: var(--top-bar-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.notes-panel-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.notes-panel-head-spacer {
  flex: 1 1 auto;
}

.notes-panel-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  flex: 0 0 auto;
}
.notes-panel-icon-btn:hover,
.notes-panel-icon-btn:focus-visible {
  color: var(--accent);
  background: var(--surface-hover);
  outline: none;
}

.notes-panel-search-wrap {
  flex: 0 0 auto;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border-subtle);
}
.notes-panel-search-wrap[hidden] {
  display: none;
}

.notes-panel-icon-btn[aria-expanded="true"],
.notes-panel-icon-btn.notes-search-active {
  color: var(--accent);
  background: var(--accent-surface);
}

.notes-panel-search {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-muted);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  outline: none;
}
.notes-panel-search::placeholder {
  color: var(--ink-faint);
}
.notes-panel-search:hover {
  border-color: var(--border-hover);
}
.notes-panel-search:focus {
  border-color: var(--accent);
  background: var(--paper);
  box-shadow: 0 0 0 2px var(--accent-ring);
}

.notes-list {
  list-style: none;
  margin: 0;
  padding: 8px 8px 16px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.notes-panel-account-footer {
  flex: 0 0 auto;
  padding: 10px 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--paper);
}

.notes-panel-account-footer .settings-menu-heading {
  margin-bottom: 6px;
}

.notes-panel-account-footer .settings-action-item {
  border-radius: 6px;
}

.notes-panel-account-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 2px 0;
}

.notes-panel-account-footer .notes-panel-settings-link.settings-action-item {
  display: inline-flex;
  align-items: center;
  width: auto;
  flex: 0 1 auto;
  margin-right: auto;
  min-width: 0;
  padding: 6px 8px;
}

.notes-panel-account-footer .notes-panel-settings-link[aria-expanded="true"] {
  color: var(--accent);
  background: var(--accent-surface);
}

.notes-panel-account-actions > .notes-panel-icon-btn {
  flex: 0 0 auto;
}

.notes-panel-account-actions .notes-panel-icon-btn[hidden] {
  display: none;
}

a.notes-panel-icon-btn {
  text-decoration: none;
  box-sizing: border-box;
}

.notes-empty {
  padding: 16px 12px;
  font-size: 12px;
  color: var(--ink-faint);
  text-align: center;
  font-style: italic;
}

.notes-row + .notes-row {
  border-top: 1px solid var(--border-subtle);
}

/* Active card background replaces the divider above/below it. */
.notes-row.active + .notes-row,
.notes-row + .notes-row.active {
  border-top-color: transparent;
}

.notes-item {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  padding: 10px 8px 10px 10px;
  border-radius: 8px;
  background: transparent;
  transition: background var(--motion-fade);
}

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

.notes-item.active {
  background: var(--accent-surface);
}

.notes-item-select {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}

.notes-item-title {
  font-size: var(--edit-font-size);
  font-weight: 500;
  line-height: 1.35;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes-item-mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: calc(var(--edit-font-size) * 0.625);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-active);
  color: var(--ink-soft);
}
.notes-item-mode:empty { display: none; }

.notes-section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  list-style: none;
}
.notes-section-head:first-child {
  padding-top: 8px;
}
.notes-section-head::before {
  content: '';
  width: 3px;
  height: 11px;
  border-radius: 2px;
  flex: 0 0 auto;
}
.notes-section-personal {
  color: var(--ink-soft);
}
.notes-section-personal::before {
  background: var(--accent);
}
.notes-section-shared {
  margin-top: 10px;
  padding-top: 22px;
  color: var(--shared-accent);
}
.notes-section-shared::before {
  background: var(--shared-accent);
}

.notes-row-shared .notes-item.active,
.notes-row-shared.active .notes-item {
  background: var(--shared-surface);
}
.notes-row-shared .notes-item.active:hover {
  background: var(--shared-surface-strong);
}
.notes-row-shared .notes-item.active .notes-item-mode {
  background: var(--surface-active);
  color: var(--ink-soft);
}

.notes-item-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.notes-item-shared-tag {
  font-size: calc(var(--edit-font-size) * 0.625);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--shared-surface);
  color: var(--shared-accent);
}

.notes-item.active .notes-item-mode {
  background: var(--accent-surface-strong);
  color: var(--accent);
}

.notes-item.active .notes-item-shared-tag {
  background: var(--shared-surface-strong);
  color: var(--shared-accent);
}

.notes-panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 15;
  background: var(--overlay);
}

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

@media (max-width: 768px) {
  :root {
    --edit-pad-x: 16px;
    --timer-bar-height: 40px;
  }

  .timer-bar {
    padding: 0 12px;
    gap: 10px;
  }
  .timer-bar-title {
    font-size: 11px;
    max-width: 34%;
  }
  .timer-bar-track {
    height: 4px;
  }
  .timer-bar-label {
    font-size: 12px;
    min-width: 3.6em;
  }
  .timer-done {
    padding: 28px 20px;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }
  .timer-done-ok {
    min-height: 44px;
    min-width: 128px;
    padding: 12px 32px;
    font-size: 16px;
  }

  .notes-panel {
    position: fixed;
    left: calc(-1 * var(--panel-width));
    top: 0;
    bottom: 0;
    width: var(--panel-width);
    max-width: 88vw;
    box-shadow: var(--shadow-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
    transition:
      left var(--motion-panel),
      visibility 0s linear var(--motion-panel);
  }

  #app.panel-open .notes-panel {
    left: 0;
    visibility: visible;
    pointer-events: auto;
    transition:
      left var(--motion-panel),
      visibility 0s;
  }

  /* Transform breaks overflow scrolling on iOS — keep scroll in the list only. */
  .notes-list {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }

  /* Don't let vertical swipes scroll the note behind the open panel. */
  #app.panel-open .app-body,
  #app.panel-open .editor-wrap,
  #app.panel-open #editor {
    overflow: hidden;
    touch-action: none;
  }

  #app.panel-closed .notes-panel {
    display: flex;
  }

  .notes-panel-backdrop {
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
      opacity var(--motion-fade),
      visibility 0s linear var(--motion-fade);
  }

  #app.panel-open .notes-panel-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition:
      opacity var(--motion-fade),
      visibility 0s;
  }

  .notes-panel-backdrop[hidden] {
    display: block;
  }
}

/* Note reveal when switching or loading a note. */
.editor-wrap.note-enter {
  animation: note-enter var(--motion-note) both;
}

.editor-wrap.note-enter-fast {
  animation: note-enter-fast 0.16s both;
}

@keyframes note-enter {
  from {
    opacity: 0.35;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes note-enter-fast {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .notes-panel,
  .notes-panel-backdrop,
  .editor-wrap,
  .notes-item {
    transition: none !important;
    animation: none !important;
  }
}

/* ---------- Top hint bar ---------- */
#hintbar {
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  height: var(--top-bar-height);
  padding: 0 16px;
  font-size: 12px;
  color: var(--ink-faint);
  user-select: none;
  flex: 0 0 auto;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.hint-cell { white-space: nowrap; }
.hint-spacer { flex: 1 1 auto; }

.collab-bar {
  position: absolute;
  left: max(var(--edit-pad-x), calc((100% - var(--edit-max-width)) / 2));
  right: max(var(--edit-pad-x), calc((100% - var(--edit-max-width)) / 2));
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  pointer-events: none;
  will-change: transform;
}
.collab-bar[hidden] { display: none; }

.collab-bar-fill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  background: var(--paper);
  border-radius: 4px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.collab-label {
  font-size: 12px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

#hint-time { color: var(--ink-soft); }

.nav-loading {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--ink-faint);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: nav-spin 0.65s linear infinite;
  flex: 0 0 auto;
  opacity: 0.85;
}
.nav-loading[hidden] { display: none; }

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

.hint-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  flex: 0 0 auto;
}
.hint-icon-btn:hover,
.hint-icon-btn:focus-visible {
  color: var(--accent);
  background: var(--surface-hover);
  outline: none;
}

/* ---------- Countdown timer bar ---------- */
.timer-bars {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  z-index: 6;
  background: var(--paper);
}
.timer-bars[hidden] { display: none; }

.timer-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  height: var(--timer-bar-height);
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.timer-bars .timer-bar:last-child {
  border-bottom: none;
}

.timer-bar-title {
  flex: 0 1 auto;
  max-width: 28%;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.timer-bar-title[hidden] { display: none; }

.timer-bar-track {
  flex: 1 1 auto;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.timer-bar-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform-origin: right center;
  transform: scaleX(1);
  will-change: transform;
}

.timer-bar-label {
  flex: 0 0 auto;
  min-width: 3.2em;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
  text-align: right;
  user-select: none;
}
.timer-bar.is-paused .timer-bar-fill {
  opacity: 0.45;
}
.timer-bar.is-paused .timer-bar-label {
  color: var(--ink-soft);
}
.timer-bar.is-stopwatch .timer-bar-fill {
  opacity: 0.85;
}
.hint-icon-btn[aria-expanded="true"] {
  color: var(--accent);
  background: var(--accent-surface);
}
.hint-icon-btn-danger:hover,
.hint-icon-btn-danger:focus-visible {
  color: var(--danger);
  background: var(--danger-surface);
}

.hint-icon {
  display: block;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.rates-tooltip {
  position: fixed;
  z-index: 130;
  pointer-events: none;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--tooltip-fg);
  background: var(--tooltip-bg);
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  max-width: calc(100vw - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.rates-tooltip[hidden] { display: none !important; }
.rates-tooltip.rates-tooltip-feedback {
  color: var(--paper);
  background: var(--accent);
  font-weight: 600;
  animation: rates-tooltip-pop 0.35s ease-out;
}
@keyframes rates-tooltip-pop {
  0% { opacity: 0.7; transform: scale(0.94); }
  55% { opacity: 1; transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}

#editor.rates-hover { cursor: pointer; }

/* Mobile prev/next note buttons. */
.mobile-nav {
  display: none;
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 6;
  flex-direction: row;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--paper);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
}
.mobile-nav[hidden] { display: none !important; }

@media (max-width: 768px) {
  .mobile-nav:not([hidden]) {
    display: flex;
  }
}

.mobile-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav-btn:hover,
.mobile-nav-btn:focus-visible {
  color: var(--accent);
  background: var(--surface-hover);
  outline: none;
}
.mobile-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.mobile-nav-icon {
  display: block;
  width: 22px;
  height: 22px;
}

/* ---------- Editor (two stacked layers) ---------- */
.editor-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;          /* allow internal scroll */
  overflow: hidden;
  isolation: isolate;
  transition: opacity var(--motion-note), transform var(--motion-note);
}

/* Dot grid stays pinned to the editor viewport; text/cards scroll above it. */
.editor-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: var(--paper);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: 0 0;
}

/* Both layers share identical box + text metrics. */
#editor,
#backdrop,
#selection-layer {
  position: absolute;
  inset: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  overscroll-behavior: none;

  font-family: var(--mono);
  font-size: var(--edit-font-size);
  font-weight: var(--edit-weight);
  line-height: var(--edit-line-box);
  letter-spacing: 0;
  tab-size: 4;
  -moz-tab-size: 4;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  padding-top: var(--edit-pad-top);
  padding-right: max(var(--edit-pad-x), calc((100% - var(--edit-max-width)) / 2));
  padding-bottom: var(--edit-pad-bottom);
  padding-left: max(var(--edit-pad-x), calc((100% - var(--edit-max-width)) / 2));

  border: 0;
  background: transparent;
}

/* The real input. Text is nearly transparent so the backdrop shows through,
   but the caret stays visible via caret-color. */
#editor {
  z-index: 3;
  resize: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  color: transparent;
  caret-color: var(--ink);
  touch-action: manipulation;
}

/* Selection tint is drawn on #selection-layer (under backdrop text). */
#editor::selection { background: transparent; }
#editor::-moz-selection { background: transparent; }

#editor::placeholder {
  color: var(--ink-faint);
  -webkit-text-fill-color: var(--ink-faint);
}

/* Avoid -webkit-text-fill-color on typed text — iOS mispositions the caret. */
#editor:not(:placeholder-shown) {
  -webkit-text-fill-color: currentColor;
}

/* The visual layer that mirrors the textarea content. */
#backdrop {
  z-index: 2;
  pointer-events: none;
  color: var(--ink);
  /* <pre> has UA top/bottom margin on mobile Safari — zero it so rows match the textarea. */
  margin: 0;
  -webkit-font-smoothing: antialiased;
  /* Only #editor scrolls; backdrop follows via transform (see app.js). */
  overflow: hidden;
}

/* Solid paper behind each line/sentence of text — width follows the words, not the editor. */
.tok-ink-fill {
  background: var(--paper);
  border-radius: 4px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Let the selection tint show cleanly without a paper band behind it. */
#app.has-selection .tok-ink-fill,
#app.has-diff-highlight .tok-ink-fill {
  background: transparent;
}

/* Yellow selection tint — behind backdrop text, under the textarea. */
#selection-layer {
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}
.selection-layer-inner {
  position: relative;
  width: 100%;
  min-height: 100%;
  will-change: transform;
}
.selection-mirror {
  visibility: hidden;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  pointer-events: none;
}

/* Legacy row mirror (unused — code/list selection uses backdrop rects). */
.selection-mirror-rows .sel-mirror-row {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.selection-highlights {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  pointer-events: none;
}
.sel-rect {
  position: absolute;
  background: var(--selection);
  border-radius: 2px;
  pointer-events: none;
}

/* New content since last visit — teal tint, holds then fades. */
.diff-highlights {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  pointer-events: none;
}
.diff-highlights[hidden] { display: none; }
.diff-rect {
  position: absolute;
  background: var(--diff-highlight);
  border-radius: 2px;
  pointer-events: none;
  opacity: 1;
  transition: opacity 1.5s ease;
}
.diff-highlights.diff-fading .diff-rect {
  opacity: 0;
}

#backdrop code {
  font: inherit;
  display: block;
  margin: 0;
  padding: 0;
  will-change: transform;
}

/* Default (plain/sum/avg/count/math): wrap like prose. */
#editor,
#backdrop,
#backdrop code {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* List: checklist rows use a leading tab (tab-size = checkbox column); comments flush left. */
#app[data-mode="list"] #editor,
#app[data-mode="list"] #backdrop,
#app[data-mode="list"] #backdrop code,
#app[data-mode="list"] #selection-layer,
#app[data-mode="list"] .selection-mirror {
  tab-size: var(--list-item-indent);
  -moz-tab-size: var(--list-item-indent);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

#app[data-mode="list"] #backdrop code {
  padding: 0;
}

/* One backdrop row per note line (wrap grows inside the row). */
#app[data-mode="list"] .li-line {
  display: block;
}

/* Checklist rows: pad past the checkbox column; wraps keep the same inset. */
#app[data-mode="list"] .li-line-item {
  padding-left: var(--list-item-indent);
  box-sizing: border-box;
}

#app[data-mode="list"] .li-line-item > .li-text {
  display: inline;
  padding-left: 0;
}

/* Code: wrap long lines; line numbers align to the first visual row only. */
#app[data-mode="code"] #editor,
#app[data-mode="code"] #backdrop,
#app[data-mode="code"] #backdrop code,
#app[data-mode="code"] #selection-layer,
#app[data-mode="code"] .selection-mirror {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* ---------- Backdrop token styling ---------- */
/* Keyword line (e.g. "sum"), the auto-total line, and math results all share
   the golden-yellow accent + bold. */
.tok-keyword-line { color: var(--accent); font-weight: var(--accent-weight); }
.tok-bible-ref    { color: var(--accent); font-weight: var(--accent-weight); }

/* Bible: verse numbers + tab in the text flow (matches textarea caret grid on wrap). */
#app[data-mode="bible"] #editor,
#app[data-mode="bible"] #backdrop,
#app[data-mode="bible"] #backdrop code,
#app[data-mode="bible"] #selection-layer,
#app[data-mode="bible"] .selection-mirror {
  tab-size: var(--bible-verse-indent, 3ch);
  -moz-tab-size: var(--bible-verse-indent, 3ch);
}

#app[data-mode="bible"] .bible-line,
#app[data-mode="bible"] .bible-verse-line {
  display: block;
}

#app[data-mode="bible"] .bible-line-empty {
  min-height: var(--edit-line-box);
}

#app[data-mode="bible"] .bible-verse-num {
  color: var(--ink-faint);
  font-style: normal;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#app[data-mode="bible"] .bible-verse-text,
#app[data-mode="bible"] .selection-mirror .bible-mirror-verse-text {
  font-style: italic;
}
.tok-result-line  { color: var(--accent); font-weight: var(--accent-weight); }
.tok-math-result  { color: var(--accent); font-weight: var(--accent-weight); }

.tok-timer-line .tok-timer-label,
.tok-timer-line .tok-timer-suffix {
  color: var(--timer-list-ink);
  font-weight: 400;
  font-style: normal;
}
.tok-timer-line .tok-timer-value {
  color: var(--accent);
  font-weight: var(--accent-weight);
}

.tok-math-result[data-currency-conversion].rates-refreshing {
  animation: rates-refreshing-pulse 0.85s ease-in-out infinite;
}
.tok-math-result[data-currency-conversion].rates-refreshed {
  animation: rates-refresh-flash 0.6s ease-out;
}
@keyframes rates-refreshing-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes rates-refresh-flash {
  0% { opacity: 1; filter: brightness(1); }
  25% { opacity: 0.3; filter: brightness(1.35); }
  100% { opacity: 1; filter: brightness(1); }
}
/* Math variables: one hue per name so defs and refs look linked. */
.tok-math-var { font-weight: var(--accent-weight); }
.tok-math-var-0 { color: var(--math-var-0); }
.tok-math-var-1 { color: var(--math-var-1); }
.tok-math-var-2 { color: var(--math-var-2); }
.tok-math-var-3 { color: var(--math-var-3); }
.tok-math-var-4 { color: var(--math-var-4); }
.tok-math-var-5 { color: var(--math-var-5); }
.tok-math-var-6 { color: var(--math-var-6); }
.tok-math-var-7 { color: var(--math-var-7); }
.tok-comment      { color: var(--comment); font-style: italic; }
.tok-search-hit    { background: var(--search-hit); border-radius: 2px; }
.tok-find-hit      { background: var(--find-hit); border-radius: 2px; }
.tok-find-active {
  background: var(--accent);
  color: var(--paper);
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--accent);
}

/* Math mode variable autocomplete */
.math-ac {
  position: absolute;
  z-index: 12;
  min-width: 160px;
  max-width: min(320px, 90vw);
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--paper);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-family: var(--mono);
  font-size: 12px;
  pointer-events: auto;
}
.math-ac[hidden] { display: none; }

.math-ac-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  color: var(--ink);
  cursor: pointer;
}
.math-ac-item:hover {
  background: var(--surface-hover);
}
.math-ac-item-hint {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-faint);
  width: 14px;
  text-align: center;
}
.math-ac-item-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Bible mode translation picker (after bible: on line 1) */
.bible-tr-ac {
  position: absolute;
  z-index: 12;
  min-width: 220px;
  max-width: min(360px, 92vw);
  margin: 0;
  padding: 4px 0;
  background: var(--paper);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-family: var(--mono);
  font-size: 12px;
  pointer-events: auto;
}
.bible-tr-ac[hidden] { display: none; }

.bible-tr-ac-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  color: var(--ink);
  cursor: pointer;
}
.bible-tr-ac-item:hover,
.bible-tr-ac-item.selected {
  background: var(--surface-hover);
}
.bible-tr-ac-item-hint {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-faint);
  width: 14px;
  text-align: center;
}
.bible-tr-ac-item-id {
  flex: 0 0 auto;
  font-weight: var(--accent-weight);
  color: var(--accent);
  min-width: 2.5em;
}
.bible-tr-ac-item-desc {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-muted);
}

/* List/code: one block row per note line (wrap grows inside the row). */
#app[data-mode="code"] .code-line {
  display: block;
}

#app[data-mode="code"] .code-line-empty {
  min-height: var(--edit-line-box);
}

.li-done-text { color: var(--done-text); text-decoration: line-through; }

/* Line numbers — code mode (always) and math mode (duplicate variables). */
.line-num-gutter {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow-x: hidden;
  overflow-y: hidden;
  pointer-events: none;
}
.line-num-gutter[hidden] { display: none; }

/* Gutter offset via padding so wrapped lines stay clear of line numbers. */
#app[data-line-nums][data-mode="code"] #editor,
#app[data-line-nums][data-mode="math"] #editor,
#app[data-line-nums][data-mode="code"] #backdrop,
#app[data-line-nums][data-mode="math"] #backdrop,
#app[data-line-nums][data-mode="code"] #selection-layer,
#app[data-line-nums][data-mode="math"] #selection-layer {
  padding-left: calc(max(var(--edit-pad-x), calc((100% - var(--edit-max-width)) / 2)) + var(--line-num-prefix-ch, 4) * 1ch);
}

/* Mode row (+ optional blank) sit flush with the gutter column. */
#app[data-line-nums][data-mode="code"] .code-line-pre-content,
#app[data-line-nums] .selection-mirror-rows .sel-mirror-pre-content {
  position: relative;
  z-index: 5;
  margin-left: calc(-1 * var(--line-num-prefix-ch, 4) * 1ch);
}

/* Line numbers — rows positioned from measured backdrop line rects (app.js). */
.line-num-gutter-inner {
  position: absolute;
  inset: 0;
  left: max(var(--edit-pad-x), calc((100% - var(--edit-max-width)) / 2));
  will-change: transform;
  width: calc(var(--line-num-prefix-ch, 4) * 1ch);
  box-sizing: border-box;
  font-family: var(--mono);
  font-size: var(--edit-font-size);
  font-weight: 500;
  line-height: var(--edit-line-box);
  text-align: left;
  color: var(--ink-faint);
  user-select: none;
  overflow: visible;
  pointer-events: none;
}

.line-num-row {
  position: absolute;
  left: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
}
.line-num-row-dup {
  color: var(--danger);
  font-weight: 700;
}

/* Clickable checkbox overlay — above the textarea in list mode. */
.list-gutter {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.list-gutter-inner {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-sizing: border-box;
  overflow: visible;
  will-change: transform;
}

.li-gutter-row {
  position: absolute;
  /* Absolute children ignore parent padding — match editor inset explicitly. */
  left: max(var(--edit-pad-x), calc((100% - var(--edit-max-width)) / 2));
  width: var(--list-check-size);
  display: flex;
  /* Row height is one line box; center the checkbox on that line. */
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
  pointer-events: none;
}

.li-check-btn {
  position: relative;
  pointer-events: auto;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--list-check-size);
  height: var(--list-check-size);
  padding: 0;
  border: 1.5px solid var(--check-box);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.85;
}

/* Larger invisible tap target on mobile (visual checkbox unchanged). */
@media (max-width: 768px) {
  .li-check-btn::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: var(--edit-line-box);
    max-height: 44px;
    transform: translate(-50%, -50%);
  }
}

.li-check-btn:hover {
  opacity: 1;
  border-color: var(--ink-faint);
}

.li-check-btn.checked {
  background: var(--accent);
  border-color: var(--accent);
  opacity: 1;
}

/* Proportional checkmark — drawn, not a thin glyph. */
.li-check-btn.checked::after {
  content: '';
  display: block;
  width: 4px;
  height: 7px;
  border: solid var(--paper);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* Code mode — token styles follow common editor conventions per language. */
#app[data-mode="code"] #backdrop { color: var(--code-ink); }

.code-key  { color: var(--code-key);  font-weight: 600; }
.code-fn   { color: var(--code-fn); }
.code-str  { color: var(--code-str); }
.code-num  { color: var(--code-num); }
.code-com  { color: var(--code-com);  font-style: italic; }
.code-sel  { color: var(--code-sel);  font-weight: 600; }
.code-prop { color: var(--code-prop); }
.code-tag  { color: var(--code-tag);  font-weight: 700; }
.code-hex  { color: var(--code-hex);  font-weight: 600; }
.code-at   { color: var(--code-at);   font-weight: 600; }

/* ---------- Transient save status ---------- */
.status {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 7;
  font-size: 11px;
  color: var(--ink-faint);
  user-select: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}
.status.show { opacity: 1; }

.history-hint {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%);
  z-index: 110;
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--popup-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  user-select: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.history-hint.show { opacity: 1; }

.math-dup-hint {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%);
  z-index: 110;
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--danger);
  background: var(--popup-bg);
  border: 1px solid var(--danger);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  user-select: none;
  max-width: min(560px, calc(100vw - 32px));
  text-align: center;
  pointer-events: none;
}
.math-dup-hint[hidden] { display: none !important; }

body:has(#math-dup-hint:not([hidden])) .history-hint.show {
  bottom: 88px;
}

.tok-math-var-dup {
  color: var(--danger);
  font-weight: var(--accent-weight);
  background: var(--danger-surface);
  border-radius: 2px;
}

#editor.link-hover,
#editor.math-var-hover { cursor: pointer; }

.link-tooltip {
  position: fixed;
  z-index: 120;
  pointer-events: none;
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--tooltip-fg);
  background: var(--tooltip-bg);
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  max-width: calc(100vw - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-tooltip[hidden] { display: none; }

/* ---------- Note options menu (⋮) ---------- */
.note-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: transparent;
}
.note-menu-backdrop[hidden],
.note-menu[hidden] {
  display: none;
}

.note-menu {
  position: fixed;
  z-index: 111;
  min-width: 140px;
  margin: 0;
  padding: 4px 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow-md);
  font-family: var(--mono);
  font-size: 12px;
}

.settings-menu {
  position: fixed;
  z-index: 111;
  min-width: 200px;
  max-height: min(70vh, 320px);
  margin: 0;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow-md);
  font-family: var(--mono);
  font-size: 13px;
  overflow-y: auto;
}
.settings-menu[hidden] {
  display: none;
}

#notes-panel-menu,
#settings-menu,
#note-menu {
  max-height: none;
  overflow-y: visible;
}

.notes-panel-guest-hint {
  margin: 0 0 8px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--ink-faint);
  letter-spacing: normal;
  text-transform: none;
}

.notes-panel-login-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 6px;
}

.notes-panel-login-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.04);
}

.notes-panel-login-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-ring);
}

.notes-panel-login-btn {
  margin-top: 2px;
}

.notes-panel-login-error {
  margin: 6px 10px 0;
  font-size: 11px;
  color: var(--danger);
  letter-spacing: normal;
  text-transform: none;
}

.notes-panel-login-error[hidden] {
  display: none;
}

.settings-menu-section + .settings-menu-section {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.settings-action-item {
  display: block;
  width: 100%;
  margin: 0;
  padding: 9px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.settings-action-item:hover,
.settings-action-item:focus-visible {
  background: var(--surface-hover);
  outline: none;
}

.settings-action-item:disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

a.settings-action-item {
  text-decoration: none;
  box-sizing: border-box;
}

.settings-menu-user {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--ink-soft);
}

.settings-menu-heading {
  margin: 0;
  padding: 4px 10px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.settings-font-size {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 6px 6px;
}

.settings-font-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 32px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.settings-font-btn:hover,
.settings-font-btn:focus-visible {
  background: var(--surface-hover);
  outline: none;
}
.settings-font-btn:disabled {
  opacity: 0.4;
  cursor: default;
  background: transparent;
}

.settings-font-label {
  flex: 1 1 auto;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.theme-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 9px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.theme-menu-item:hover,
.theme-menu-item:focus-visible {
  background: var(--surface-hover);
  outline: none;
}
.theme-menu-item[aria-checked="true"] {
  background: var(--accent-surface);
  font-weight: 600;
}
.theme-menu-item[aria-checked="true"]:hover,
.theme-menu-item[aria-checked="true"]:focus-visible {
  background: var(--accent-surface-strong);
}

.theme-menu-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--list-check-size);
  height: var(--list-check-size);
  flex: 0 0 var(--list-check-size);
  border: 1.5px solid var(--check-box);
  border-radius: 50%;
  background: transparent;
  box-sizing: border-box;
  opacity: 0.85;
}
.theme-menu-item[aria-checked="true"] .theme-menu-mark {
  background: transparent;
  border-color: var(--accent);
  opacity: 1;
}
.theme-menu-item[aria-checked="true"] .theme-menu-mark::after {
  content: '';
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.theme-menu-label {
  flex: 1 1 auto;
  line-height: 1.2;
}

.note-menu-item {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 14px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.note-menu-item:hover,
.note-menu-item:focus-visible {
  background: var(--surface-hover);
  outline: none;
}
.note-menu-item-danger,
.settings-action-item.note-menu-item-danger {
  color: var(--danger);
}
.note-menu-item-danger:hover,
.note-menu-item-danger:focus-visible,
.settings-action-item.note-menu-item-danger:hover,
.settings-action-item.note-menu-item-danger:focus-visible {
  background: var(--danger-surface);
}

/* ---------- Find / replace bar ---------- */
.find-bar {
  position: fixed;
  top: calc(var(--top-bar-height) + var(--timer-bar-offset, 0px) + 8px);
  right: 16px;
  z-index: 105;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: min(360px, calc(100vw - 32px));
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow-md);
  font-family: var(--mono);
  font-size: 12px;
}
.find-bar[hidden] { display: none; }

.find-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.find-bar-row[hidden] {
  display: none;
}

.find-bar-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  outline: none;
}
.find-bar-input::placeholder { color: var(--ink-faint); }
.find-bar-input::selection {
  background: var(--accent);
  color: var(--paper);
}
.find-bar-input::-moz-selection {
  background: var(--accent);
  color: var(--paper);
}
.find-bar-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-surface);
}

.find-bar-status {
  flex: 0 0 auto;
  min-width: 4.5em;
  font-size: 11px;
  color: var(--ink-faint);
  text-align: right;
  white-space: nowrap;
}

.find-bar-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
}
.find-bar-icon-btn:hover,
.find-bar-icon-btn:focus-visible {
  color: var(--accent);
  background: var(--surface-hover);
  outline: none;
}

.find-bar-icon {
  display: block;
  width: 14px;
  height: 14px;
}

.find-bar-text-btn {
  flex: 0 0 auto;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.find-bar-text-btn:hover,
.find-bar-text-btn:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-surface);
  outline: none;
}

.find-bar-replace-row .find-bar-input {
  flex: 1 1 auto;
}

/* ---------- Timer finished overlay ---------- */
.timer-done-backdrop {
  position: fixed;
  inset: 0;
  z-index: 190;
  background: var(--timer-done-scrim);
  -webkit-backdrop-filter: blur(var(--timer-done-blur));
  backdrop-filter: blur(var(--timer-done-blur));
  animation: timer-done-fade-in 0.35s ease-out;
}
.timer-done-backdrop[hidden],
.timer-done[hidden] {
  display: none;
}

.timer-done {
  position: fixed;
  inset: 0;
  z-index: 191;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 24px;
  text-align: center;
  font-family: var(--mono);
  pointer-events: none;
  animation: timer-done-fade-in 0.35s ease-out;
}
.timer-done > * {
  pointer-events: auto;
}

.timer-done-title {
  margin: 0;
  font-size: clamp(2.4rem, 12vw, 4.5rem);
  font-weight: var(--accent-weight);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--accent);
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.45);
  animation: timer-done-pulse 1.1s ease-in-out infinite alternate;
}

.timer-done-message {
  margin: 0;
  max-width: 20em;
  font-size: clamp(1rem, 4.5vw, 1.35rem);
  font-weight: 500;
  line-height: 1.4;
  color: var(--timer-done-fg-soft);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.35);
}

.timer-done-ok {
  margin-top: 12px;
  padding: 11px 28px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: var(--timer-done-btn-bg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--timer-done-btn-fg);
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}
.timer-done-ok:hover,
.timer-done-ok:focus,
.timer-done-ok:focus-visible {
  background: var(--timer-done-btn-hover);
  color: var(--timer-done-btn-fg);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@keyframes timer-done-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes timer-done-pulse {
  from { transform: scale(1); opacity: 1; }
  to { transform: scale(1.04); opacity: 0.88; }
}

/* ---------- Delete note confirmation ---------- */
.delete-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: var(--overlay);
}
.delete-dialog-backdrop[hidden],
.delete-dialog[hidden] {
  display: none;
}

.delete-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 121;
  width: min(360px, calc(100vw - 32px));
  padding: 20px 20px 16px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-family: var(--mono);
}

.delete-dialog-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.delete-dialog-message {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.delete-dialog-message strong {
  font-weight: 600;
  color: var(--ink);
}

.delete-dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.delete-dialog-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.delete-dialog-btn:hover,
.delete-dialog-btn:focus-visible {
  background: var(--surface-hover);
  outline: none;
}
.delete-dialog-btn-danger {
  color: var(--on-primary);
  background: var(--danger);
  border-color: var(--danger);
}
.delete-dialog-btn-danger:hover,
.delete-dialog-btn-danger:focus-visible {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

/* ---------- Share dialog ---------- */
.share-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 121;
  width: min(400px, calc(100vw - 32px));
  padding: 20px 20px 16px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-family: var(--mono);
}
.share-dialog[hidden] { display: none; }

.share-dialog-title {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.share-dialog-hint {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.share-dialog-label {
  display: block;
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.share-dialog-details-wrap[hidden],
.share-dialog-manage-wrap[hidden] {
  display: none;
}

.share-dialog-owner-block {
  margin: 0 0 14px;
}

.share-dialog-owner-name {
  margin: 0;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-muted);
}

.share-dialog-list-wrap {
  margin: 0 0 14px;
}
.share-dialog-list-wrap[hidden] {
  display: none;
}

.share-dialog-list-readonly .share-dialog-list-item {
  padding-right: 12px;
}

.share-dialog-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-muted);
  overflow: hidden;
}

.share-dialog-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
}
.share-dialog-list-item:last-child {
  border-bottom: none;
}

.share-dialog-list-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-dialog-list-remove {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-faint);
  cursor: pointer;
}
.share-dialog-list-remove:hover,
.share-dialog-list-remove:focus-visible {
  color: var(--danger);
  background: var(--danger-surface);
  outline: none;
}

.share-dialog-add-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin: 0 0 10px;
}
.share-dialog-add-row .share-dialog-input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  margin: 0;
}

.share-dialog-input {
  box-sizing: border-box;
  width: 100%;
  margin: 0 0 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}
.share-dialog-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-surface);
}

.share-dialog-error {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--danger);
}
.share-dialog-error[hidden] { display: none; }

.share-dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.share-dialog-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.share-dialog-btn:not(.share-dialog-btn-primary):hover,
.share-dialog-btn:not(.share-dialog-btn-primary):focus-visible {
  background: var(--surface-hover);
  outline: none;
}
.share-dialog-btn-primary {
  color: var(--on-primary);
  background: var(--accent);
  border-color: var(--accent);
}
.share-dialog-btn-primary:hover,
.share-dialog-btn-primary:focus-visible {
  color: var(--on-primary);
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  outline: none;
}
.share-dialog-btn-add {
  flex: 0 0 auto;
  align-self: stretch;
  padding-left: 14px;
  padding-right: 14px;
}

/* ---------- Mode picker (slash command) ---------- */
.mode-picker-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99;
  background: var(--overlay-light);
}
.mode-picker-backdrop[hidden],
.mode-picker[hidden] {
  display: none;
}

.mode-picker {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  width: min(320px, calc(100vw - 32px));
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 12px 0 8px;
  font-family: var(--mono);
}

.mode-picker-title {
  margin: 0 0 6px;
  padding: 0 16px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--border-subtle);
}

.mode-picker-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

.mode-picker-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
}

.mode-picker-item:hover,
.mode-picker-item.selected {
  background: var(--surface-hover);
}

.mode-picker-item .mode-name {
  display: block;
  color: var(--accent);
  font-weight: var(--accent-weight);
}

.mode-picker-item .mode-desc {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-soft);
}
