/* ═══════════════════════════════════════════════════════════════
   Notes — pen on paper.

   Design language: a warm, subtly-textured sheet of paper; every
   piece of text is "ink" in one of six pen colors; chrome is kept
   to hairlines and handwriting. Mobile-first throughout — desktop
   just gets more margin.

   Theming: custom properties on :root are the light (paper) theme;
   html[data-theme="dark"] swaps to slate paper with chalk-bright
   inks. JS resolves the user preference (auto follows the system).
   html[data-style] picks the app style (paper | pro | typewriter) —
   see the "App styles" token blocks below and notes/DEVELOPMENT.md.
   ═══════════════════════════════════════════════════════════════ */

/* ── Fonts (self-hosted, precached by the service worker) ────── */
@font-face {
  font-family: 'Caveat';
  src: url('fonts/caveat-latin-600-normal.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Caveat';
  src: url('fonts/caveat-latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Kalam';
  src: url('fonts/kalam-latin-300-normal.woff2') format('woff2');
  font-weight: 300; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Kalam';
  src: url('fonts/kalam-latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Kalam';
  src: url('fonts/kalam-latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}

/* ── Tokens ───────────────────────────────────────────────────── */
:root {
  --font-hand:  'Caveat', 'Segoe Script', cursive;
  --font-body:  'Kalam', 'Comic Sans MS', cursive;

  --paper:        #f6f1e5;
  --paper-raised: #fdfaf2;
  --paper-sunken: #efe8d8;
  --ink:          #33415e;   /* body text = midnight pen */
  --ink-strong:   #232f4b;
  --muted:        #94896f;
  --hairline:     #ddd3bd;
  --margin-rule:  #e8b4a8;   /* the red margin line of a notebook */
  --shadow:       0 1px 2px rgba(96, 78, 44, .08), 0 6px 24px -12px rgba(96, 78, 44, .35);
  --shadow-lift:  0 2px 4px rgba(96, 78, 44, .10), 0 16px 40px -16px rgba(96, 78, 44, .45);

  --pen-midnight: #33415e;
  --pen-blue:     #1d6ca8;
  --pen-red:      #bc4430;
  --pen-green:    #38754c;
  --pen-violet:   #6d4a9e;
  --pen-amber:    #a8720d;
  --highlight:    rgba(255, 224, 74, .55);

  --danger:       #bc4430;
  --ok:           #38754c;

  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .38 0 0 0 0 .31 0 0 0 0 .18 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");

  --radius: 14px;
  --tap: 44px;             /* minimum touch target */
  --vh: 100dvh;            /* kept in sync with visualViewport by JS */

  /* Style knobs: each app style (html[data-style]) retunes these instead
     of restyling components. --tilt scales every hand-placed rotation
     (0 = perfectly straight); --fs-hand scales the display font, since
     handwriting faces render smaller than typesetting faces at equal rem. */
  --tilt: 1;
  --fs-hand: 1;
  --body-weight: 300;
  --body-size: 17px;
  --rule-style: dashed;      /* horizontal rules in notes */
  --chip-border: dashed;     /* tag chips, choice rows, banners */
  --underline-style: wavy;
  --card-radius: 4px 10px 6px 10px;
  --fab-radius: 22px 50% 50% 50%;
  --ed-h1: 1.9em;
  --ed-h2: 1.55em;
  --ed-h3: 1.28em;
}

html[data-theme='dark'] {
  --paper:        #23222b;
  --paper-raised: #2b2a35;
  --paper-sunken: #1d1c24;
  --ink:          #c6cdec;
  --ink-strong:   #e2e7fa;
  --muted:        #7d7a90;
  --hairline:     #3b3947;
  --margin-rule:  #5c4048;
  --shadow:       0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px -12px rgba(0, 0, 0, .7);
  --shadow-lift:  0 2px 4px rgba(0, 0, 0, .35), 0 16px 40px -16px rgba(0, 0, 0, .8);

  --pen-midnight: #c6cdec;
  --pen-blue:     #74b6ee;
  --pen-red:      #f0907a;
  --pen-green:    #7cc99a;
  --pen-violet:   #b394e8;
  --pen-amber:    #e5b264;
  --highlight:    rgba(255, 224, 74, .28);

  --danger:       #f0907a;
  --ok:           #7cc99a;

  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .8 0 0 0 0 .8 0 0 0 0 .95 0 0 0 .04 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── App styles ───────────────────────────────────────────────────
   html[data-style] retunes the tokens above; components never branch
   on the style themselves. Each style's light block must come AFTER
   html[data-theme='dark'] (equal specificity — order decides), and its
   dark block must redefine every color its light block touches.

   'paper' is the default (the :root values); no block needed. */

/* Professional: quiet system typography, flat neutral surfaces,
   everything squared up and straightened out. */
html[data-style='pro'] {
  --font-hand: system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-body: system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --fs-hand: .78;
  --tilt: 0;
  --body-weight: 400;
  --body-size: 16px;
  --rule-style: solid;
  --chip-border: solid;
  --underline-style: solid;
  --card-radius: 12px;
  --fab-radius: 16px;
  --radius: 12px;
  --noise: none;
  --ed-h1: 1.55em;
  --ed-h2: 1.3em;
  --ed-h3: 1.15em;

  --paper:        #f4f5f7;
  --paper-raised: #ffffff;
  --paper-sunken: #e9ebef;
  --ink:          #333b49;
  --ink-strong:   #16202e;
  --muted:        #71798a;
  --hairline:     #dfe2e8;
  --margin-rule:  transparent;
  --shadow:       0 1px 2px rgba(15, 23, 42, .05), 0 6px 24px -12px rgba(15, 23, 42, .18);
  --shadow-lift:  0 2px 4px rgba(15, 23, 42, .08), 0 16px 40px -16px rgba(15, 23, 42, .3);

  --pen-midnight: #333b49;
  --pen-blue:     #2563eb;
  --pen-red:      #dc2626;
  --pen-green:    #047857;
  --pen-violet:   #7c3aed;
  --pen-amber:    #b45309;
  --highlight:    rgba(253, 224, 71, .5);

  --danger:       #dc2626;
  --ok:           #047857;
}
html[data-style='pro'][data-theme='dark'] {
  --paper:        #16181d;
  --paper-raised: #1f232b;
  --paper-sunken: #101216;
  --ink:          #ccd3e0;
  --ink-strong:   #eef1f8;
  --muted:        #7e8698;
  --hairline:     #343a46;
  --margin-rule:  transparent;
  --shadow:       0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px -12px rgba(0, 0, 0, .7);
  --shadow-lift:  0 2px 4px rgba(0, 0, 0, .35), 0 16px 40px -16px rgba(0, 0, 0, .8);

  --pen-midnight: #ccd3e0;
  --pen-blue:     #6aa9f0;
  --pen-red:      #ef8877;
  --pen-green:    #6fc492;
  --pen-violet:   #ab90e0;
  --pen-amber:    #dfae63;
  --highlight:    rgba(253, 224, 71, .25);

  --danger:       #ef8877;
  --ok:           #6fc492;
}

/* Typewriter: monospaced type on ivory stock, ribbon-red margin,
   square corners — pages come out of the machine straight. */
html[data-style='typewriter'] {
  --font-hand: 'Courier New', Courier, monospace;
  --font-body: 'Courier New', Courier, monospace;
  --fs-hand: .82;
  --tilt: 0;
  --body-weight: 400;
  --body-size: 15.5px;
  --underline-style: solid;
  --card-radius: 3px;
  --fab-radius: 8px;
  --radius: 6px;
  --ed-h1: 1.5em;
  --ed-h2: 1.28em;
  --ed-h3: 1.12em;

  --paper:        #efe9d3;
  --paper-raised: #f9f5e8;
  --paper-sunken: #e5dcc2;
  --ink:          #3a352c;
  --ink-strong:   #262219;
  --muted:        #8d8368;
  --hairline:     #d6cbaa;
  --margin-rule:  #c9553e;
  --shadow:       0 1px 2px rgba(70, 58, 32, .08), 0 6px 24px -12px rgba(70, 58, 32, .35);
  --shadow-lift:  0 2px 4px rgba(70, 58, 32, .10), 0 16px 40px -16px rgba(70, 58, 32, .45);

  --pen-midnight: #3a352c;
  --pen-blue:     #2b5876;
  --pen-red:      #b3392b;
  --pen-green:    #3f6b47;
  --pen-violet:   #64487c;
  --pen-amber:    #96660f;
  --highlight:    rgba(255, 224, 74, .55);

  --danger:       #b3392b;
  --ok:           #3f6b47;
}
html[data-style='typewriter'][data-theme='dark'] {
  --paper:        #201f1a;
  --paper-raised: #292822;
  --paper-sunken: #171612;
  --ink:          #d6d0bd;
  --ink-strong:   #efe9d6;
  --muted:        #8f8974;
  --hairline:     #3d3b30;
  --margin-rule:  #8a4a3c;
  --shadow:       0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px -12px rgba(0, 0, 0, .7);
  --shadow-lift:  0 2px 4px rgba(0, 0, 0, .35), 0 16px 40px -16px rgba(0, 0, 0, .8);

  --pen-midnight: #d6d0bd;
  --pen-blue:     #7fb4d8;
  --pen-red:      #e08a75;
  --pen-green:    #93c39b;
  --pen-violet:   #b39ac9;
  --pen-amber:    #d9b171;
  --highlight:    rgba(255, 224, 74, .28);

  --danger:       #e08a75;
  --ok:           #93c39b;
}

/* ── Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* display styles on components must never beat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--font-body);
  font-weight: var(--body-weight);
  font-size: var(--body-size);
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--paper);
  background-image: var(--noise);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

input, textarea, button, select { font: inherit; color: inherit; }

button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--pen-blue);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--highlight); }
::placeholder { color: var(--muted); opacity: .8; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── App frame: stacked full-screen views ─────────────────────── */
#app {
  height: var(--vh);
  position: relative;
  overflow: hidden;
  max-width: 720px;
  margin: 0 auto;
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
  background-image: var(--noise);
}
.view[hidden] { display: none; }

/* Editor slides over the list like a fresh sheet of paper */
#view-editor {
  box-shadow: -8px 0 32px rgba(0, 0, 0, .12);
  animation: sheet-in .22s ease-out;
}
@keyframes sheet-in {
  from { transform: translateX(6%); opacity: .4; }
  to   { transform: none; opacity: 1; }
}

/* ── Shared bits ──────────────────────────────────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: 12px;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:active { background: var(--paper-sunken); }
.icon-btn.is-on { color: var(--pen-amber); }
.icon-btn svg { width: 22px; height: 22px; }

.hand { font-family: var(--font-hand); font-weight: 700; }

/* Handwritten primary button: an inked, slightly imperfect pill */
.btn-ink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: var(--tap);
  padding: .3rem 1.5rem .45rem;
  border-radius: 999px;
  background: var(--ink-strong);
  color: var(--paper-raised);
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: calc(1.35rem * var(--fs-hand));
  line-height: 1;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, opacity .12s;
}
.btn-ink:active { transform: scale(.97); box-shadow: var(--shadow); }
.btn-ink:disabled { opacity: .5; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: var(--tap);
  padding: .25rem 1rem;
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: calc(1.2rem * var(--fs-hand));
}
.btn-ghost:active { background: var(--paper-sunken); }

/* Text inputs: a pencil rule to write on, not a boxy field */
.field { display: block; margin-bottom: 1.1rem; }
.field > span {
  display: block;
  font-size: .8rem;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: .1rem;
}
.field input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--hairline);
  border-radius: 0;
  padding: .35rem 2px .3rem;
  font-size: 1.05rem;
  transition: border-color .15s;
}
.field input:focus {
  outline: none;
  border-bottom-color: var(--pen-blue);
}

/* ── Auth view ────────────────────────────────────────────────── */
#view-auth {
  justify-content: center;
  padding: 2rem 1.75rem calc(2rem + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.auth-card { max-width: 340px; width: 100%; margin: 0 auto; }
.auth-logo {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: calc(3.4rem * var(--fs-hand));
  line-height: 1;
  margin: 0 0 .25rem;
  color: var(--ink-strong);
  transform: rotate(calc(-2deg * var(--tilt)));
}
.auth-logo .flourish { color: var(--pen-red); }
.auth-sub {
  margin: 0 0 2.2rem;
  color: var(--muted);
  font-size: .95rem;
}
.auth-error {
  color: var(--danger);
  font-size: .9rem;
  min-height: 1.4em;
  margin: .2rem 0 .8rem;
}
.auth-actions { display: flex; flex-direction: column; gap: .4rem; margin-top: 1.4rem; align-items: stretch; }
.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.2rem;
}
.auth-links button {
  color: var(--pen-blue);
  font-size: .9rem;
  min-height: var(--tap);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.auth-note { color: var(--muted); font-size: .85rem; }

/* ── List view ────────────────────────────────────────────────── */
.list-head {
  display: flex;
  align-items: center;
  gap: .25rem;
  padding: calc(.5rem + env(safe-area-inset-top)) .75rem .25rem 1.25rem;
}
.list-head h1 {
  flex: 1;
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: calc(2.6rem * var(--fs-hand));
  line-height: 1.1;
  color: var(--ink-strong);
  transform: rotate(calc(-1.2deg * var(--tilt)));
}

.search-row { padding: .25rem 1.25rem .5rem; display: flex; align-items: center; gap: .5rem; }
.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--paper-raised);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0 1rem;
  min-height: var(--tap);
  box-shadow: var(--shadow);
}
.search-box svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.search-box input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1rem;
  padding: .4rem 0;
}
.search-box .clear-btn { display: none; color: var(--muted); min-width: 32px; min-height: 32px; }
.search-box.has-text .clear-btn { display: inline-flex; }

.tag-row {
  display: flex;
  gap: .45rem;
  overflow-x: auto;
  padding: .15rem 1.25rem .6rem;
  scrollbar-width: none;
}
.tag-row::-webkit-scrollbar { display: none; }
.tag-row:empty { display: none; }
.tag-chip {
  flex-shrink: 0;
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: calc(1.1rem * var(--fs-hand));
  line-height: 1;
  color: var(--muted);
  padding: .5rem .9rem .6rem;
  border-radius: 999px;
  border: 1.5px var(--chip-border) var(--hairline);
  transition: color .15s, border-color .15s, background .15s;
}
.tag-chip.active {
  color: var(--paper-raised);
  background: var(--ink-strong);
  border-color: var(--ink-strong);
  border-style: solid;
}

.note-scroll {
  flex: 1;
  overflow-y: auto;
  padding: .4rem 1rem calc(7rem + env(safe-area-inset-bottom));
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .8rem;
  align-items: start;
}

/* Each note is a small piece of paper, pinned slightly askew */
.note-card {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  background: var(--paper-raised);
  background-image: var(--noise);
  border-radius: var(--card-radius);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
  padding: .7rem .8rem .55rem;
  min-height: 6.4rem;
  text-align: left;
  color: inherit;
  transition: transform .15s, box-shadow .15s;
}
.note-grid > .note-card:nth-child(3n+1) { transform: rotate(calc(-.4deg * var(--tilt))); }
.note-grid > .note-card:nth-child(3n+2) { transform: rotate(calc(.35deg * var(--tilt))); }
.note-grid > .note-card:nth-child(4n+3) { transform: rotate(calc(-.2deg * var(--tilt))); }
.note-card:active { transform: scale(.97); box-shadow: var(--shadow-lift); }

.note-card .nc-title {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: calc(1.45rem * var(--fs-hand));
  line-height: 1.12;
  color: var(--nc-ink, var(--ink-strong));
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-hyphens: auto;
  hyphens: auto;
  -webkit-hyphenate-limit-before: 6;
  -webkit-hyphenate-limit-after: 4;
  hyphenate-limit-chars: 12 6 4;
}
/* Card preview: the note's real markup, six lines of it. Only long
   words hyphenate (auto-hyphenation otherwise splits words that fit
   fine on the next line just to even out the rag — too busy at card
   width); overflow-wrap stays as the safety net for unhyphenatable
   strings (URLs, ids). */
.note-card .nc-preview {
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-hyphens: auto;
  hyphens: auto;
  -webkit-hyphenate-limit-before: 6;
  -webkit-hyphenate-limit-after: 4;
  hyphenate-limit-chars: 12 6 4;
  font-size: .8rem;
  line-height: 1.5;
  color: var(--ink);
  opacity: .8;
}
.note-card .nc-preview p,
.note-card .nc-preview h1,
.note-card .nc-preview h2,
.note-card .nc-preview h3,
.note-card .nc-preview ol,
.note-card .nc-preview ul {
  margin: 0;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
}
.note-card .nc-preview h1,
.note-card .nc-preview h2,
.note-card .nc-preview h3 {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.15em;
}
.note-card .nc-preview li {
  list-style: none;
  position: relative;
  padding-left: 1.05rem;
}
.note-card .nc-preview li::before {
  position: absolute;
  left: 0;
  color: var(--muted);
}
.note-card .nc-preview li[data-list='bullet']::before    { content: '•'; }
.note-card .nc-preview li[data-list='ordered']           { counter-increment: nc-ol; }
.note-card .nc-preview li[data-list='ordered']::before   { content: counter(nc-ol) '.'; font-size: .85em; top: .1em; }
.note-card .nc-preview ol { counter-reset: nc-ol; }
.note-card .nc-preview li[data-list='unchecked']::before { content: '☐'; }
.note-card .nc-preview li[data-list='checked']::before   { content: '☑'; color: var(--ok); }
.note-card .nc-preview li[data-list='checked'] {
  color: var(--muted);
  text-decoration: line-through;
}
/* the editor-only fold marks mean nothing on a card */
.note-card .nc-preview .ql-ui { display: none; }
.note-card .nc-foot {
  margin-top: auto;
  padding-top: .35rem;
  display: flex;
  align-items: baseline;
  gap: .5rem;
  min-width: 0;
}
.note-card .nc-tags {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: calc(.95rem * var(--fs-hand));
  color: var(--pen-blue);
}
.note-card .nc-date {
  flex-shrink: 0;
  font-size: .68rem;
  color: var(--muted);
}
.note-card .nc-pin {
  position: absolute;
  top: -7px;
  right: 10px;
  width: 17px;
  height: 17px;
  color: var(--pen-amber);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.25));
}
.note-card { position: relative; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 4.5rem 2rem;
}
.empty-state .hand { font-size: calc(1.9rem * var(--fs-hand)); color: var(--ink); display: block; transform: rotate(calc(-1.5deg * var(--tilt))); }
.empty-state p { font-size: .95rem; }
.empty-state svg { width: 54px; height: 54px; opacity: .5; margin-bottom: .75rem; }

/* Floating "new note" pen button */
.fab {
  position: absolute;
  right: 1.25rem;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border-radius: var(--fab-radius);
  background: var(--ink-strong);
  color: var(--paper-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lift);
  transform: rotate(calc(-4deg * var(--tilt)));
  transition: transform .15s;
  z-index: 5;
}
.fab:active { transform: rotate(calc(-4deg * var(--tilt))) scale(.93); }
.fab svg { width: 26px; height: 26px; }

/* Sync status: a small inked footnote in the header */
.sync-dot {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-height: var(--tap);
  padding: 0 .5rem;
  font-size: .78rem;
  color: var(--muted);
}
.sync-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  transition: background .3s;
}
.sync-dot[data-state='pending']::before { background: var(--pen-amber); }
.sync-dot[data-state='offline']::before { background: var(--muted); }
.sync-dot[data-state='error']::before   { background: var(--danger); }

/* ── Editor view ──────────────────────────────────────────────── */
.ed-top {
  display: flex;
  align-items: center;
  gap: .15rem;
  padding: calc(.35rem + env(safe-area-inset-top)) .5rem .15rem;
}
.ed-top .spacer { flex: 1; }

/* Text-size stepper in the top bar */
.ed-zoom { display: inline-flex; align-items: center; }
.ed-zoom .icon-btn { min-width: 38px; }
.ed-zoom button:disabled { opacity: .35; }
.ed-status {
  font-size: .75rem;
  color: var(--muted);
  padding: 0 .35rem;
  transition: opacity .3s;
}

.ed-title {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: calc(2.15rem * var(--fs-hand));
  line-height: 1.15;
  color: var(--note-ink, var(--ink-strong));
  padding: 0 1.4rem .1rem;
}

.ed-tagline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem;
  padding: 0 1.4rem .35rem;
  min-height: 1.6rem;
}
.ed-tagline:empty { display: none; }
.ed-tag {
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: calc(1.05rem * var(--fs-hand));
  line-height: 1;
  color: var(--pen-blue);
  padding: .35rem .1rem;
}

/* The writing surface: paper with a red margin rule */
.ed-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.ed-body::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 1.05rem;
  width: 1.5px;
  background: var(--margin-rule);
  opacity: .55;
  pointer-events: none;
}

/* ── Quill: strip the library look, keep only the writing ────── */
.ed-body .ql-container {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-body);
  font-weight: var(--body-weight);
  font-size: 1.06rem;
  line-height: 1.62;
  color: var(--note-ink, var(--ink));
}
.ed-body .ql-editor {
  padding: .2rem 1.4rem 40vh;  /* generous tail so the caret never hugs the toolbar */
  min-height: 100%;
  caret-color: var(--note-ink, var(--ink));
}
.ed-body .ql-editor.ql-blank::before {
  color: var(--muted);
  font-style: normal;
  left: 1.4rem;
  right: 1.4rem;
}

.ed-body .ql-editor h1,
.ed-body .ql-editor h2,
.ed-body .ql-editor h3 {
  font-family: var(--font-hand);
  font-weight: 700;
  line-height: 1.15;
  margin: .5em 0 .15em;
}
.ed-body .ql-editor h1 { font-size: var(--ed-h1); }
.ed-body .ql-editor h2 { font-size: var(--ed-h2); }
.ed-body .ql-editor h3 { font-size: var(--ed-h3); }

/* Fold arrow: every heading can collapse what's under it. The arrow is a
   ::before inside the heading's tap zone (editor.js listens for taps on
   the heading's leading 48px — keep that in sync with this width). */
.ed-body .ql-editor h1::before,
.ed-body .ql-editor h2::before,
.ed-body .ql-editor h3::before {
  content: '▾';
  display: inline-block;
  min-width: 40px;
  margin-left: -.1em;
  font-size: .72em;
  vertical-align: .12em;
  color: var(--muted);
  opacity: .7;
}
.ed-body .ql-editor h1.ql-collapsed-on::before,
.ed-body .ql-editor h2.ql-collapsed-on::before,
.ed-body .ql-editor h3.ql-collapsed-on::before {
  content: '▸';
  opacity: 1;
  color: var(--note-ink, var(--ink));
}
/* A folded heading hints there's more written under it */
.ed-body .ql-editor .ql-collapsed-on::after {
  content: ' …';
  color: var(--muted);
}
.ed-body .ql-editor .nc-hide { display: none; }

.zoom-a { font-size: .95rem; font-weight: 400; }
.zoom-a-big { font-size: 1.2rem; }
.zoom-pct {
  min-width: 3.1rem;
  text-align: center;
  font-size: .82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tb-btn:disabled { opacity: .35; }

.ed-body .ql-editor strong { font-weight: 700; }
.ed-body .ql-editor u {
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  text-decoration-style: var(--underline-style);
}
.ed-body .ql-editor s { text-decoration-thickness: 2px; }

/* Horizontal rule: a drawn divider across the page */
.ed-body .ql-editor hr {
  border: none;
  border-top: 2px var(--rule-style) var(--hairline);
  margin: .9em 0;
}
.note-card .nc-preview hr {
  border: none;
  border-top: 1px var(--rule-style) var(--hairline);
  margin: .3em 0;
}

/* Pen runs + highlighter: classes, so dark mode re-inks them. The doubled
   selectors out-rank quill.core.css's own .ql-editor .ql-color-* defaults. */
.ql-color-midnight, .ql-editor .ql-color-midnight { color: var(--pen-midnight); }
.ql-color-blue,     .ql-editor .ql-color-blue     { color: var(--pen-blue); }
.ql-color-red,      .ql-editor .ql-color-red      { color: var(--pen-red); }
.ql-color-green,    .ql-editor .ql-color-green    { color: var(--pen-green); }
.ql-color-violet,   .ql-editor .ql-color-violet   { color: var(--pen-violet); }
.ql-color-amber,    .ql-editor .ql-color-amber    { color: var(--pen-amber); }
.ql-bg-yellow, .ql-editor .ql-bg-yellow {
  background: var(--highlight);
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  padding: 0 1px;
}

/* Checklists: hand-drawn checkboxes, inked-out when done */
.ed-body .ql-editor li[data-list='checked'],
.ed-body .ql-editor li[data-list='unchecked'] { position: relative; }
.ed-body .ql-editor li[data-list='checked'] > .ql-ui,
.ed-body .ql-editor li[data-list='unchecked'] > .ql-ui {
  cursor: pointer;
  font-size: 1.05em;
}
.ed-body .ql-editor li[data-list='checked'] {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

/* Quill 2 renders list markers via ::before on .ql-ui */
.ed-body .ql-editor li[data-list='unchecked'] > .ql-ui::before { content: '☐'; }
.ed-body .ql-editor li[data-list='checked'] > .ql-ui::before   { content: '☑'; color: var(--ok); }

/* ── Bottom toolbar: rides the keyboard ───────────────────────── */
.ed-toolbar {
  flex-shrink: 0;
  background: var(--paper-raised);
  background-image: var(--noise);
  border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
  position: relative;
  z-index: 6;
}
.tb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .15rem .4rem;
  gap: .1rem;
}
.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 40px;
  max-width: 62px;
  min-height: 46px;
  border-radius: 10px;
  color: var(--muted);
  font-family: var(--font-body);
  font-weight: 400;
  transition: background .12s, color .12s;
}
.tb-btn svg { width: 21px; height: 21px; }
.tb-btn:active { background: var(--paper-sunken); }
.tb-btn.is-on { color: var(--note-ink, var(--pen-blue)); background: var(--paper-sunken); }

/* Current pen indicator: an ink drop */
.tb-pen-dot {
  width: 20px;
  height: 20px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--current-pen, var(--pen-midnight));
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .18);
}

/* Trays that expand upward from the toolbar */
.tb-tray {
  display: none;
  border-bottom: 1px solid var(--hairline);
  padding: .55rem .75rem;
}
.tb-tray.open { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }

.pen-swatch {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.pen-swatch .drop {
  width: 26px;
  height: 26px;
  border-radius: 50% 50% 50% 5px;
  transform: rotate(-45deg);
  background: var(--swatch);
  box-shadow: inset 0 -3px 4px rgba(0, 0, 0, .2);
  transition: transform .12s;
}
.pen-swatch:active .drop { transform: rotate(-45deg) scale(.88); }
.pen-swatch.selected { background: var(--paper-sunken); }
.pen-swatch.selected::after {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1.5px var(--chip-border) var(--muted);
  border-radius: 12px;
}

.hl-swatch {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hl-swatch .bar {
  width: 26px;
  height: 14px;
  border-radius: 3px;
  background: var(--swatch);
  transform: rotate(-2deg);
}
.hl-swatch.selected { background: var(--paper-sunken); }

.tray-label {
  width: 100%;
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .1rem;
}
.tray-sep { width: 1px; height: 30px; background: var(--hairline); margin: 0 .35rem; }

/* ── Bottom sheets (menus, dialogs) ───────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 12, .35);
  z-index: 20;
  animation: fade-in .18s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }
.sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  z-index: 21;
  background: var(--paper-raised);
  background-image: var(--noise);
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--hairline);
  border-bottom: none;
  box-shadow: var(--shadow-lift);
  padding: .4rem 1.25rem calc(1rem + env(safe-area-inset-bottom));
  max-height: 85vh;
  overflow-y: auto;
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateX(-50%) translateY(40px); opacity: .5; } }
.sheet::before {
  content: '';
  display: block;
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: var(--hairline);
  margin: .35rem auto .75rem;
}
.sheet h2 {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: calc(1.7rem * var(--fs-hand));
  margin: 0 0 .6rem;
  color: var(--ink-strong);
}
.sheet-item {
  display: flex;
  align-items: center;
  gap: .8rem;
  width: 100%;
  min-height: 52px;
  padding: .2rem .25rem;
  border-radius: 12px;
  font-size: 1rem;
  text-align: left;
  color: var(--ink);
}
.sheet-item:active { background: var(--paper-sunken); }
.sheet-item svg { width: 21px; height: 21px; color: var(--muted); flex-shrink: 0; }
.sheet-item.danger, .sheet-item.danger svg { color: var(--danger); }
.sheet-item .sub { display: block; font-size: .8rem; color: var(--muted); }
.sheet .sheet-note { color: var(--muted); font-size: .85rem; }

.sheet-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1rem; }

/* Tag editing inside the note menu sheet */
.sheet .tag-edit {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  align-items: center;
  padding: .3rem 0 .5rem;
}
.sheet .tag-edit .tag-chip.removable::after { content: ' ×'; }
.sheet .tag-edit input {
  flex: 1;
  min-width: 110px;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--hairline);
  outline: none;
  padding: .3rem 2px;
  font-size: 1rem;
}

/* Theme choice rows */
.choice-row { display: flex; gap: .5rem; padding: .25rem 0 .6rem; }
.choice-row button {
  flex: 1;
  min-height: var(--tap);
  border: 1.5px var(--chip-border) var(--hairline);
  border-radius: 12px;
  color: var(--muted);
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: calc(1.15rem * var(--fs-hand));
  padding: .2rem .3rem;
}
.choice-row button.active {
  color: var(--paper-raised);
  background: var(--ink-strong);
  border-color: var(--ink-strong);
  border-style: solid;
}

/* Toasts: a scribbled margin note */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) rotate(calc(-1deg * var(--tilt)));
  background: var(--ink-strong);
  color: var(--paper-raised);
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: calc(1.15rem * var(--fs-hand));
  line-height: 1.2;
  padding: .55rem 1.2rem .65rem;
  border-radius: 999px;
  box-shadow: var(--shadow-lift);
  z-index: 30;
  animation: toast-in .2s ease-out;
  max-width: min(85vw, 420px);
  text-align: center;
}
.toast .toast-action {
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  margin-left: .6rem;
  min-height: var(--tap);
}
@keyframes toast-in { from { transform: translateX(-50%) translateY(14px) rotate(calc(-1deg * var(--tilt))); opacity: 0; } }

/* Trash view reuses the list; banner explains where you are */
.trash-banner {
  margin: 0 1.25rem .6rem;
  padding: .6rem .9rem;
  border: 1.5px var(--chip-border) var(--hairline);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: .88rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.trash-banner button { color: var(--danger); font-weight: 400; min-height: var(--tap); text-decoration: underline; text-underline-offset: 3px; }

/* Update-available pill (new service worker waiting) */
.update-pill {
  position: absolute;
  top: calc(.6rem + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: var(--pen-blue);
  color: #fff;
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: calc(1.05rem * var(--fs-hand));
  padding: .45rem 1.1rem .55rem;
  border-radius: 999px;
  box-shadow: var(--shadow-lift);
}

/* Desktop niceties: the phone layout, given air */
@media (min-width: 721px) {
  #app { box-shadow: 0 0 60px rgba(0, 0, 0, .1); }
  .note-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
