/* ==========================================================================
   SELF-HOSTED FONTS
   Poppins was previously loaded from fonts.googleapis.com, which meant two
   cross-origin DNS/TLS handshakes before the first pixel of UI chrome could
   paint, and a third-party dependency for a privacy-first product. The four
   weights actually used by this app (300 for "Notes", 500/600 for the
   wordmark, kickers and popover titles) are now served from ./fonts.
   Latin + latin-ext subsets only: the devanagari subset the CDN also shipped
   was pure dead weight for an English-language app.
   ========================================================================== */
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('fonts/poppins-300-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('fonts/poppins-300-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/poppins-400-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/poppins-400-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/poppins-500-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/poppins-500-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/poppins-600-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/poppins-600-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;

  --bg:        #ffffff;
  --surface:   #ffffff;
  --fg:        #101010;
  --fg-soft:   #565656;
  --muted:     #8d8d8d;
  --line:      #e7e7e7;
  --hover:     #f2f2f2;
  --active:    #e9e9e9;
  --accent:    #479ccf;
  --danger:    #d9381e;
  --shadow:    0 10px 30px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
  --shadow-sm: 0 4px 16px rgba(0,0,0,.10);
  --scrim:     rgba(0,0,0,.35);

  --editor-font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  /* UI chrome font. Named once as a token so the brand mark, kickers and
     popover titles cannot drift apart; falls back to the same system stack the
     editor uses if the self-hosted files 404. */
  --ui-font: 'Poppins', ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --editor-fs:   17px;
  --editor-color: #101010;
  --editor-lh:   1.78;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg:        #0b0b0b;
  --surface:   #141414;
  --fg:        #ededed;
  --fg-soft:   #b2b2b2;
  --muted:     #787878;
  --line:      #262626;
  --hover:     #1d1d1d;
  --active:    #242424;
  --shadow:    0 10px 40px rgba(0,0,0,.65), 0 2px 10px rgba(0,0,0,.5);
  --shadow-sm: 0 4px 16px rgba(0,0,0,.55);
  --scrim:     rgba(0,0,0,.65);
  --editor-color: #ededed;
}

/* Before app.js runs there is no data-theme attribute, so the operating system
   preference decides. This is pure CSS on purpose: it avoids the flash of a
   light UI on a dark desktop that a deferred script would cause. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;

    --bg:        #0b0b0b;
    --surface:   #141414;
    --fg:        #ededed;
    --fg-soft:   #b2b2b2;
    --muted:     #787878;
    --line:      #262626;
    --hover:     #1d1d1d;
    --active:    #242424;
    --shadow:    0 10px 40px rgba(0,0,0,.65), 0 2px 10px rgba(0,0,0,.5);
    --shadow-sm: 0 4px 16px rgba(0,0,0,.55);
    --scrim:     rgba(0,0,0,.65);
    --editor-color: #ededed;
  }
}

[data-page="white"] { --bg:#ffffff; --surface:#ffffff; --fg:#101010; --fg-soft:#565656; --muted:#8d8d8d; --line:#e7e7e7; --hover:#f2f2f2; --active:#e9e9e9; --editor-color:#101010; }
[data-page="cream"] { --bg:#faf6ec; --surface:#fffaf0; --fg:#1d1a14; --fg-soft:#5c5548; --muted:#958c78; --line:#e8e0cd; --hover:#f1eada; --active:#e7dfc9; --editor-color:#1d1a14; }
[data-page="sepia"] { --bg:#f0e5d0; --surface:#f7eeda; --fg:#332a1c; --fg-soft:#6b5c42; --muted:#a08f70; --line:#dccfae; --hover:#e8dcc0; --active:#ddcfac; --editor-color:#332a1c; }
[data-page="mist"]  { --bg:#eef1f4; --surface:#f6f8fa; --fg:#1a1f24; --fg-soft:#4e5860; --muted:#86929c; --line:#d7dde3; --hover:#e3e8ed; --active:#d6dce3; --editor-color:#1a1f24; }
[data-page="slate"] { --bg:#1e2429; --surface:#252c32; --fg:#e8ecef; --fg-soft:#b0bac2; --muted:#7a858e; --line:#333b42; --hover:#2b333a; --active:#333c44; --editor-color:#e8ecef; }
[data-page="black"] { --bg:#0a0a0a; --surface:#141414; --fg:#ededed; --fg-soft:#b2b2b2; --muted:#787878; --line:#242424; --hover:#1b1b1b; --active:#232323; --editor-color:#ededed; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  transition: background .3s ease, color .3s ease;
}

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

/* ================= FOCUS ================= */
/* Icon-only buttons had no visible focus ring anywhere in the sheet. Keyboard
   users now get one, and it only appears for keyboard interaction. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}
#editor:focus-visible { outline: none; }
.icon-btn:focus-visible,
.note-item:focus-visible { background: var(--hover); }
.dock-toggle:focus-visible { outline-offset: -4px; }
/* The editor is a scroll container and a programmatic focus target for the skip
   link, so it must not draw a ring when it is not being typed into. */
#main:focus, #main:focus-visible { outline: none; }

/* ================= SKIP LINK ================= */
/* First thing in the tab order, visible only once focused. */
.skip-link {
  position: fixed;
  left: 12px;
  top: -80px;
  z-index: 400;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--ui-font);
  font-size: .78rem;
  font-weight: 500;
  text-decoration: none;
  transition: top .16s ease;
}
.skip-link:focus { top: 12px; }

/* ================= SCROLLBARS ================= */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ================= EDITOR ================= */
main {
  position: relative;
  height: 100dvh;
  min-height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 32px 24px calc(110px + env(safe-area-inset-bottom));
  scrollbar-width: thin;
  background-color: var(--bg);
  background-repeat: repeat;
  background-attachment: fixed;
}

@supports not (height: 100dvh) {
  main { height: 100vh; min-height: 100vh; }
}

main.paper-lines {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--editor-fs) * var(--editor-lh) - 1px),
    var(--line) calc(var(--editor-fs) * var(--editor-lh) - 1px),
    var(--line) calc(var(--editor-fs) * var(--editor-lh))
  );
}
main.paper-dots {
  background-image: radial-gradient(circle, var(--line) 1.1px, transparent 1.2px);
  background-size: 22px 22px;
}
main.paper-grid {
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
}

.editor-wrap {
  width: min(100%, 960px);
  margin: 0 auto;
}

#editor {
  display: block;
  width: 100%;
  min-height: calc(100vh - 200px);
  background: transparent;
  color: var(--editor-color);
  caret-color: var(--editor-color);
  outline: none;
  font-family: var(--editor-font);
  font-size: var(--editor-fs);
  line-height: var(--editor-lh);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

#editor[contenteditable]:empty:before {
  content: attr(data-placeholder);
  color: var(--muted);
  opacity: .7;
  pointer-events: none;
  display: block;
}

#editor blockquote {
  margin: 0 0 0 2px;
  padding-left: 14px;
  border-left: 2px solid var(--line);
  color: var(--fg-soft);
}
#editor pre {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--hover);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-x: auto;
}
#editor code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .95em; }
#editor img { max-width: 100%; height: auto; border-radius: 8px; }
#editor hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
#editor a { color: var(--accent); }

/* ================= PANEL / SIDEBAR ================= */
.scrim {
  position: fixed; inset: 0;
  background: var(--scrim);
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease;
  z-index: 150;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.panel {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 320px; max-width: 88vw;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  transform: translateX(-101%);
  transition: transform .34s cubic-bezier(.32,.72,0,1);
  z-index: 160;
}
.panel.open { transform: none; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 16px 12px 20px;
  flex: none;
}

.panel-title {
  font-family: var(--ui-font);
  font-size: .82rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--fg-soft);
  display: flex; align-items: center; gap: 8px;
}

.panel-count {
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px;
  padding: 0 6px; border-radius: 999px;
  background: var(--hover); color: var(--muted);
  font-size: .68rem; font-weight: 500;
}

.panel-search-wrap { flex: none; padding: 0 16px 10px 20px; }

.panel-search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: .82rem;
}
.panel-search::placeholder { color: var(--muted); }
.panel-search:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.panel-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; }

.panel-empty {
  margin: 18px 12px;
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
}

.panel-foot {
  flex: none; padding: 14px 16px;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
}

.patohq-link {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 10px;
  background: var(--hover); color: var(--fg);
  text-decoration: none; font-size: .8rem; font-weight: 500;
  transition: background .15s ease;
}
.patohq-link:hover { background: var(--active); }
.patohq-link span { display: flex; align-items: center; gap: 6px; }

.legal-links {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding-top: 4px;
}
.legal-btn {
  background: none; border: none; padding: 0;
  color: var(--muted); font-size: .72rem; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}
.legal-btn:hover { color: var(--fg); }

/* ================= ABOUT / FAQ ================= */
/* Server-rendered prose, not generated by app.js: search crawlers and LLM
   agents that do not run scripts need something to read, and the drawer is the
   one place it can live without disturbing the editor. <details> keeps it
   collapsed until opened, so it costs a reader nothing. */
.panel-about {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 2px;
}
.panel-about > summary {
  cursor: pointer;
  padding: 6px 2px;
  font-size: .75rem;
  font-weight: 500;
  color: var(--fg-soft);
  list-style-position: inside;
}
.panel-about > summary:hover { color: var(--fg); }
.panel-about > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.panel-about-body { padding: 2px 2px 10px; }
.panel-about-body h3 {
  margin: 12px 0 4px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--fg);
}
.panel-about-body h3:first-child { margin-top: 4px; }
.panel-about-body p,
.panel-about-body li {
  margin: 0 0 6px;
  font-size: .74rem;
  line-height: 1.5;
  color: var(--fg-soft);
}
.panel-about-body ul { margin: 0 0 8px; padding-left: 18px; }
.panel-about-body a { color: var(--accent); }

.copyright-tag {
  font-size: .65rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.35;
  padding-top: 4px;
}

/* The row itself is not interactive any more: it is a list item holding two
   sibling buttons, so the delete control is no longer nested inside a
   role="button" element. */
.note-item {
  position: relative;
  margin-bottom: 2px;
  border-radius: 12px;
  transition: background .13s ease;
}
.note-item:hover { background: var(--hover); }
.note-item.active { background: var(--active); }

.note-open {
  display: block;
  width: 100%;
  padding: 11px 38px 11px 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.note-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.note-title {
  display: block;
  font-size: .85rem; font-weight: 500; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 3px;
}
.note-date { display: block; font-size: .68rem; color: var(--muted); opacity: .85; }

.note-del {
  position: absolute; top: 50%; right: 8px;
  transform: translateY(-50%);
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: none; border-radius: 8px;
  background: transparent; color: var(--muted);
  cursor: pointer; opacity: 0;
  transition: opacity .15s ease, background .15s ease;
}
.note-del:hover { background: var(--line); color: var(--fg); }

/* Reveal the delete affordance for pointer hover AND keyboard focus, and keep
   it permanently visible on touch devices, where hover never happens. */
@media (hover: hover) {
  .note-item:hover .note-del,
  .note-item:focus-within .note-del { opacity: 1; }
}
@media (hover: none) {
  .note-del { opacity: .75; }
}

.btn-ghost {
  width: 100%; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--fg);
  font: inherit; font-size: .82rem; font-weight: 500;
  cursor: pointer; transition: background .15s ease;
}
.btn-ghost:hover { background: var(--hover); }

/* ================= BOTTOM DOCK ================= */
.dock {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 54px;
  width: 60px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 30px 30px 0 0;
  box-shadow: var(--shadow);
  z-index: 100;
  transition: width .32s cubic-bezier(.32,.72,0,1), height .32s cubic-bezier(.32,.72,0,1), border-radius .32s ease;
}

.dock.open {
  width: min(920px, calc(100vw - 20px));
  height: 58px;
  border-radius: 20px 20px 0 0;
}

.dock-content {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity .15s ease;
}
.dock.open .dock-content {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transition: opacity .22s ease .08s;
}

.brand {
  flex: none;
  display: flex; align-items: center; gap: 7px;
  padding: 0 10px 0 14px;
  user-select: none;
  text-decoration: none;
}
.brand-logo { width: 14px; height: 20px; flex: none; color: var(--fg); display: block; }
.brand-name { font-family: var(--ui-font); font-size: 14px; font-weight: 600; color: var(--fg); line-height: 1; }
.brand-sub { font-family: var(--ui-font); font-size: 14px; font-weight: 300; color: var(--muted); line-height: 1; margin-left: -3px; }

.dock-divider {
  flex: none; width: 1px; height: 22px;
  background: var(--line); margin: 0 6px;
}

.actions-scroll-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.actions-scroll-wrap::before,
.actions-scroll-wrap::after {
  content: '';
  position: absolute; top: 0; bottom: 0; width: 16px;
  pointer-events: none; z-index: 2; opacity: 0;
  transition: opacity .2s ease;
}
.actions-scroll-wrap::before {
  left: 0; background: linear-gradient(to right, var(--surface), transparent);
}
.actions-scroll-wrap::after {
  right: 0; background: linear-gradient(to left, var(--surface), transparent);
}
.actions-scroll-wrap.can-scroll-left::before { opacity: 1; }
.actions-scroll-wrap.can-scroll-right::after { opacity: 1; }

.actions-scroll {
  flex: 1 1 auto;
  height: 100%;
  display: flex;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.actions-scroll::-webkit-scrollbar { display: none; }

.actions {
  display: flex; align-items: center; gap: 2px;
  padding-right: 12px;
  white-space: nowrap;
}

.sep {
  flex: none; width: 1px; height: 20px;
  background: var(--line); margin: 0 4px;
}

.icon-btn {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: none; border-radius: 10px;
  background: transparent;
  color: var(--fg-soft);
  cursor: pointer;
  transition: background .14s ease, color .14s ease;
  position: relative;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn:active { background: var(--active); }
.icon-btn svg { width: 17px; height: 17px; display: block; }
.icon-btn[aria-pressed="true"],
.icon-btn[aria-expanded="true"] { background: var(--active); color: var(--fg); }

.glyph { font-size: 13px; font-weight: 600; line-height: 1; }
.glyph-bold { font-weight: 700; }
.glyph-italic { font-style: italic; }
.glyph-underline { text-decoration: underline; }
.glyph-strike { text-decoration: line-through; }
.glyph-serif { font-family: Georgia, serif; }

.color-dot {
  display: inline-block;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--editor-color);
  border: 1px solid var(--line);
}

.dock-toggle {
  flex: none;
  width: 60px; height: 54px;
  display: grid; place-items: center;
  border: none; border-radius: 30px 30px 0 0;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background .15s ease;
}
.dock.open .dock-toggle {
  width: 52px; height: 58px;
  border-radius: 0 20px 0 0;
}
.dock-toggle:hover { background: var(--hover); }
.dock-toggle .i-logo { display: block; width: 14px; height: 20px; }
.dock-toggle .i-close { display: none; width: 18px; height: 18px; }

.dock.open .dock-toggle .i-logo { display: none; }
.dock.open .dock-toggle .i-close { display: block; }

/* Theme toggle glyphs: the moon means "switch to dark", the sun means "switch
   to light", and exactly one of them is ever painted. The rules are written
   default-first (moon visible) rather than as two mirrored hides, because the
   default theme is "system", which leaves [data-theme] off the root entirely —
   that matched neither hide rule and rendered both glyphs at once. The media
   query below covers the same pre-JS / system case on a dark device. */
.icon-btn .i-moon { display: block; }
.icon-btn .i-sun { display: none; }
[data-theme="dark"] .icon-btn .i-moon { display: none; }
[data-theme="dark"] .icon-btn .i-sun { display: block; }
[data-theme="light"] .icon-btn .i-moon { display: block; }
[data-theme="light"] .icon-btn .i-sun { display: none; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .icon-btn .i-moon { display: none; }
  html:not([data-theme]) .icon-btn .i-sun { display: block; }
}

/* ================= TOOLTIP ================= */
.tooltip-layer {
  position: fixed; top: 0; left: 0;
  pointer-events: none; z-index: 300;
}
.tooltip-bubble {
  position: absolute;
  background: var(--fg); color: var(--bg);
  padding: 5px 9px; border-radius: 6px;
  font-size: 11px; font-weight: 500;
  white-space: nowrap; box-shadow: var(--shadow-sm);
  opacity: 0; transform: translateY(4px);
  transition: opacity .15s ease, transform .15s ease;
}
.tooltip-bubble.visible { opacity: 1; transform: translateY(0); }

/* ================= POPOVER ================= */
.popover {
  position: fixed;
  display: block;
  min-width: 190px;
  max-width: min(300px, calc(100vw - 24px));
  max-height: min(45vh, 360px);
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transform: scale(.96);
  transition: opacity .16s ease, transform .16s ease;
  scrollbar-width: thin;
}
.popover.open { opacity: 1; pointer-events: auto; transform: none; }

.pop-title {
  padding: 8px 10px 4px;
  font-family: var(--ui-font);
  font-size: .68rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
}

.pop-item {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border: none; border-radius: 8px;
  background: transparent; color: var(--fg);
  font: inherit; font-size: .84rem; text-align: left;
  cursor: pointer; transition: background .12s ease;
}
.pop-item:hover { background: var(--hover); }
.pop-item[aria-current="true"] { background: var(--active); font-weight: 600; }
.pop-item[aria-current="true"]::after {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex: none; margin-left: 10px;
}

.pop-sep { height: 1px; background: var(--line); margin: 6px 8px; }

.pop-hint {
  margin: 2px 8px 6px;
  font-size: .68rem;
  line-height: 1.4;
  color: var(--muted);
}

.swatch-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; padding: 4px 6px 6px;
}
.swatch {
  aspect-ratio: 1 / 1; border-radius: 8px; border: 1px solid var(--line);
  cursor: pointer; padding: 0;
}
/* "Default" inherits the page theme instead of freezing a hex value, so text
   never becomes invisible after a theme switch. */
.swatch-default {
  background:
    linear-gradient(135deg, var(--fg) 0 50%, transparent 50% 100%),
    var(--surface);
}

/* ================= MODALS & TOAST ================= */
.modal-scrim {
  position: fixed; inset: 0; background: var(--scrim);
  opacity: 0; pointer-events: none; transition: opacity .25s ease;
  z-index: 400; display: grid; place-items: center; padding: 20px;
}
.modal-scrim.open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; width: min(100%, 540px); max-height: 80vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
  transform: scale(.95); transition: transform .25s ease;
}
.modal-scrim.open .modal { transform: none; }

.modal-head {
  padding: 18px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 600; color: var(--fg); margin: 0; }
.modal-body { padding: 20px; overflow-y: auto; font-size: .88rem; line-height: 1.6; color: var(--fg-soft); }
.modal-body h4 { color: var(--fg); margin: 16px 0 6px; font-size: .95rem; }
.modal-body h4:first-child { margin-top: 0; }
.modal-body p { margin: 0 0 10px; }
.modal-body a { color: var(--accent); }

.toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-10px);
  display: flex; align-items: center; gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 8px 16px; border-radius: 999px;
  background: var(--fg); color: var(--bg);
  font-size: .78rem; font-weight: 500; box-shadow: var(--shadow-sm);
  opacity: 0; pointer-events: none; z-index: 350;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.toast-action {
  border: none; border-radius: 999px;
  padding: 4px 10px;
  background: var(--bg); color: var(--fg);
  font: inherit; font-weight: 600; cursor: pointer;
}

/* ================= STATUS CHIP ================= */
.status-chip {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 90;
  max-width: min(60vw, 340px);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: .68rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}
.status-chip.warn { color: var(--danger); border-color: var(--danger); }

/* ================= LOCAL STORAGE NOTICE ================= */
.cookie-banner {
  position: fixed; bottom: 20px; left: 20px;
  max-width: 340px; padding: 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); z-index: 250;
  transform: translateY(120%); transition: transform .35s cubic-bezier(.32,.72,0,1);
}
.cookie-banner.show { transform: translateY(0); }
.cookie-banner p { margin: 0 0 12px; font-size: .78rem; color: var(--fg-soft); line-height: 1.45; }
.cookie-banner strong { color: var(--fg); }
.cookie-banner-btns { display: flex; gap: 8px; }
.cookie-banner button {
  flex: 1; padding: 7px; border-radius: 8px; border: 1px solid var(--line);
  font-size: .75rem; font-weight: 500; cursor: pointer; background: transparent; color: var(--fg);
}
.cookie-banner button:hover { background: var(--hover); }
.cookie-banner button.primary { background: var(--fg); color: var(--bg); border: none; }

/* ================= NOSCRIPT ================= */
.noscript-note {
  position: fixed; inset: auto 16px 16px;
  z-index: 500;
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.noscript-note h2 { margin: 0 0 6px; font-size: .95rem; color: var(--fg); }
.noscript-note p { margin: 0; font-size: .85rem; line-height: 1.5; color: var(--fg-soft); }

/* ================= MOBILE RESPONSIVE ================= */
@media (max-width: 640px) {
  main { padding: 20px 16px calc(90px + env(safe-area-inset-bottom)); }

  /* The dock deliberately keeps its desktop geometry on phones: a narrow,
     centred tab that expands into a rounded, floating bar, inset from both
     screen edges. Stretching it edge to edge with square corners made it read
     as a different control from the desktop one, and parked the toolbar
     buttons under the bezel. Nothing here overrides .dock/.dock-content/
     .dock-toggle sizing any more — the base rules already do the right thing. */

  .brand-name, .brand-sub, .dock-divider { display: none !important; }
  .brand { padding: 0 4px 0 8px; }

  /* Touch devices never hover: keep the delete button visible. */
  .note-del { opacity: .75; }

  .cookie-banner { left: 12px; right: 12px; max-width: none; bottom: 64px; }
  .status-chip { left: 12px; bottom: 62px; font-size: .64rem; }
}

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

/* ================= PRINT ================= */
@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  body { color: #000; }

  .dock,
  .panel,
  .scrim,
  .popover,
  .toast,
  .tooltip-layer,
  .status-chip,
  .cookie-banner,
  .modal-scrim,
  .noscript-note { display: none !important; }

  main {
    height: auto; min-height: 0; overflow: visible;
    padding: 0;
    background-image: none !important;
    background-color: #fff !important;
  }
  #editor { color: #000; min-height: 0; }
  #editor[contenteditable]:empty:before { content: none; }
}

/* ================= 404 ================= */
/* Lives here rather than in an inline <style> block so the Content-Security-
   Policy can stay free of 'unsafe-inline'. */
.notfound {
  max-width: 620px;
  margin: 0 auto;
  padding: 16vh 24px 60px;
  text-align: center;
}
.notfound .code {
  font-family: var(--ui-font);
  font-size: 3.4rem;
  font-weight: 600;
  letter-spacing: -.03em;
  margin: 0 0 6px;
  color: var(--fg);
}
.notfound h1 {
  font-size: 1.25rem;
  margin: 0 0 12px;
  color: var(--fg);
}
.notfound p {
  margin: 0 auto 24px;
  max-width: 44ch;
  color: var(--fg-soft);
  line-height: 1.6;
}
.notfound .cta {
  display: inline-block;
  padding: 11px 20px;
  border-radius: 10px;
  background: var(--fg);
  color: var(--bg);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 600;
}
