/* ===========================================================
   warq — app shell, Quick board, Library
   =========================================================== */

* { box-sizing: border-box; }

/* The UA's [hidden] rule is display:none at the lowest specificity, so any
   component rule that sets display would silently beat it. Everything in
   this app toggles visibility via .hidden = true, so make it win. */
[hidden] { display: none !important; }

/* Announced, never drawn. Not `display:none` and not `visibility:hidden` —
   both remove the node from the accessibility tree, which is the one thing
   this class exists to avoid. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

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

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }

.dim { color: var(--fg-dim); }

/* ---------- shell ---------- */

.app {
  display: grid;
  grid-template-rows: auto var(--topbar-h) 1fr;
  height: 100dvh;
  position: relative;
}

/* Rows are assigned explicitly. A display:none grid child takes up no row,
   so leaving placement implicit meant that hiding the alert handed the
   topbar's 44px row to .main and collapsed the whole app. */
.save-alert { grid-row: 1; }
.select-bar { grid-row: 1; }
.topbar     { grid-row: 2; }
.main       { grid-row: 3; }
.bottombar  { grid-row: 4; }

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.wordmark {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  padding: 0 4px;
  flex: 0 0 auto;
  cursor: default;
  user-select: none;
}

.search-wrap {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .search-icon {
  position: absolute;
  left: 8px;
  width: 15px; height: 15px;
  color: var(--fg-dim);
  pointer-events: none;
}
#search-input {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 0 28px 0 28px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); background: var(--bg-elev); }
#search-input::-webkit-search-cancel-button { display: none; }
.search-clear { position: absolute; right: 2px; }

/* ---------- buttons ---------- */

.icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--fg); }
.icon-btn:active { background: var(--bg-active); }
.icon-btn:active { background: var(--bg-active); }
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn.sm svg { width: 16px; height: 16px; }

.btn, .btn-ghost {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn { background: var(--accent); color: var(--accent-fg); }
.btn:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; color: var(--fg-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--fg); }

.text-link {
  border: 0; background: none; padding: 0;
  color: var(--accent); font: inherit; font-size: 13px; cursor: pointer;
}
.text-link:hover { text-decoration: underline; }

/* theme icon swap */
#theme-btn .icon-moon { display: none; }
:root[data-theme="dark"] #theme-btn .icon-sun { display: none; }
:root[data-theme="dark"] #theme-btn .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-btn .icon-sun { display: none; }
  :root:not([data-theme="light"]) #theme-btn .icon-moon { display: block; }
}

/* ---------- panes ---------- */

.main { position: relative; overflow: hidden; }

.pane {
  position: absolute;
  inset: 0;
  display: flex;
  min-width: 0;
}
.pane[hidden] { display: none; }

.pane-scroll {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--pad);
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.pane-scroll::-webkit-scrollbar { width: 8px; }
.pane-scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin: 12px 2px 6px;
}
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.row-between .section-label { margin-bottom: 6px; }

.empty {
  text-align: center;
  padding: 34px 18px;
  color: var(--fg-muted);
  font-size: 13px;
}
.empty p { margin: 4px 0; }
.search-hint { margin-top: 10px !important; line-height: 2; }
.search-hint code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 5px;
  white-space: nowrap;
}

/* ===========================================================
   QUICK — Google Keep style
   =========================================================== */

.composer {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  padding: 8px 10px;
  margin-bottom: 12px;
  transition: box-shadow .15s ease;
}
.composer[data-open="true"] { box-shadow: var(--shadow-2); }

.composer-title, .composer-body {
  width: 100%;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  outline: none;
  padding: 3px 0;
  resize: none;
}
.composer-title { font-weight: 600; font-size: 14px; }
.composer-body { font-size: 13.5px; max-height: 40vh; overflow-y: auto; }
.composer-title::placeholder, .composer-body::placeholder { color: var(--fg-dim); }

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.composer-buttons { display: flex; gap: 4px; margin-left: auto; }

.swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.swatch {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  cursor: pointer;
  padding: 0;
}
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Masonry via CSS columns. column-width (not column-count) so the board
   packs against its own column's width — it shares the content area with
   the editor, and viewport media queries can't see that. */
.card-grid {
  columns: 230px;
  column-gap: var(--gap);
}

.card {
  break-inside: avoid;
  page-break-inside: avoid;
  display: block;
  width: 100%;
  text-align: left;
  margin: 0 0 var(--gap);
  padding: 10px 11px;
  border: 1px solid var(--card-line, var(--line));
  border-radius: var(--r);
  background: var(--card-bg, var(--bg-elev));
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  position: relative;
  box-shadow: var(--shadow-1);
}
.card:hover { box-shadow: var(--shadow-2); }
.card-title {
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 3px;
  overflow-wrap: anywhere;
}
.card-body {
  font-size: 13px;
  color: var(--fg-muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 9;
  line-clamp: 9;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.card-time { font-size: 11px; color: var(--fg-dim); margin-right: auto; }

.card-actions {
  position: absolute;
  top: 4px; right: 4px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .12s ease;
}
.card:hover .card-actions,
.card:focus-within .card-actions { opacity: 1; }
.card-actions .icon-btn { width: 24px; height: 24px; background: var(--card-bg, var(--bg-elev)); }
.card-actions .icon-btn svg { width: 14px; height: 14px; }
.card.pinned .card-actions { opacity: 1; }
.card.pinned .pin-btn { color: var(--accent); }
@media (hover: none) { .card-actions { opacity: 1; } }

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--fg-muted);
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.search-scopes { margin-bottom: 10px; }

/* matched terms in search results */
mark {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 1px;
  font-weight: 600;
}
.note-row-title mark { color: inherit; background: var(--accent-soft); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { background: var(--bg-hover); color: var(--fg); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ===========================================================
   LIBRARY — Evernote style
   =========================================================== */

.library { display: flex; align-items: stretch; }

.lib-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
}
.lib-col[hidden] { display: none; }

.lib-col-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  min-height: 36px;
}
.lib-col-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: auto;
}

/* wide: columns side by side */
@media (min-width: 860px) {
  .lib-notebooks { flex: 0 0 210px; border-right: 1px solid var(--line); background: var(--bg-elev); }
  .lib-notes     { flex: 0 0 290px; border-right: 1px solid var(--line); }
  .lib-board     { flex: 1 1 auto; }
  .lib-editor    { flex: 1 1 auto; }

  /* With the Inbox board showing, the board is the main surface and the
     editor becomes the side panel — the reverse of a notebook's list. */
  .lib-board:not([hidden]) ~ .lib-editor {
    flex: 0 0 clamp(340px, 42%, 560px);
    border-left: 1px solid var(--line);
  }
}

.lib-static-list { display: flex; flex-direction: column; gap: 1px; }

.nb-row, .smart-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.nb-row:hover, .smart-row:hover { background: var(--bg-hover); }
.nb-row.active, .smart-row.active { background: var(--accent-soft); color: var(--accent); }
.nb-row svg, .smart-row svg { width: 15px; height: 15px; flex: 0 0 auto; color: var(--fg-dim); }
.nb-row.active svg, .smart-row.active svg { color: var(--accent); }
.nb-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-count { font-size: 11px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.nb-row .nb-menu { opacity: 0; width: 22px; height: 22px; }
.nb-row:hover .nb-menu { opacity: 1; }
@media (hover: none) { .nb-row .nb-menu { opacity: 1; } }

/* note list rows (tree-aware) */
.note-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  padding: 8px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.note-row:hover { background: var(--bg-hover); }
.note-row.active { background: var(--accent-soft); }
.note-row-main { flex: 1 1 auto; min-width: 0; }
.note-row-title { display: flex; align-items: center; gap: 4px; }
.note-row-title > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-pin { display: inline-flex; flex: 0 0 auto; color: var(--accent); }
.row-pin svg { width: 12px; height: 12px; }
.note-row-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-row-sub {
  font-size: 11.5px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.twisty {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--fg-dim);
  margin-top: 1px;
}
.twisty svg { width: 12px; height: 12px; transition: transform .12s ease; }
.twisty[aria-expanded="true"] svg { transform: rotate(90deg); }
.twisty.placeholder { visibility: hidden; }

/* ---------- editor ---------- */

.editor-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  min-height: 36px;
}
.breadcrumb {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11.5px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumb .crumb { color: var(--fg-muted); cursor: pointer; }
.breadcrumb .crumb:hover { color: var(--accent); text-decoration: underline; }
.editor-head-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.save-state { font-size: 11px; color: var(--fg-dim); white-space: nowrap; }

/* The note is a sheet of Letter-width paper, and the text keeps its own
   measure centred inside it — so the page looks like a page while the line
   length stays in the readable band. The scroller itself stays full width,
   so the scrollbar belongs to the column rather than to the paper. */
.editor-scroll { padding: 16px 14px 60px; }

.page {
  max-width: var(--page-w);
  margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  padding: 30px 24px 44px;
  min-height: calc(100% - 16px);
}

/* The measure is applied to the contents, not as padding on the page: a
   percentage padding resolves against the *parent's* width, not the page's
   own, so it would drift with the window instead of holding at the margin
   Letter implies. Centring each child keeps it exact. */
.page > * {
  max-width: var(--measure);
  margin-inline: auto;
}

.editor-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.title-input {
  /* an input is inline-level, and auto margins only centre block boxes —
     without this the title alone hugs the left edge of the page */
  display: block;
  width: 100%;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  outline: none;
  padding: 0 0 4px;
}
.title-input::placeholder { color: var(--fg-dim); }

.meta-row {
  display: flex;
  gap: 6px;
  /* auto, not 0 — the shorthand would otherwise cancel the page centring */
  margin: 6px auto 10px;
  flex-wrap: wrap;
}
.meta-select, .meta-tags {
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--fg-muted);
  font: inherit;
  font-size: 12px;
  padding: 0 10px;
  outline: none;
  min-width: 0;
}
.meta-select { flex: 0 0 auto; max-width: 50%; }
.meta-tags { flex: 1 1 120px; }
.meta-select:focus, .meta-tags:focus { border-color: var(--accent); color: var(--fg); }

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.word-count { font-size: 11px; color: var(--fg-dim); }

/* ---------- writing ----------
   Focus is not a mode anyone turns on. While you are actually typing the
   surrounding columns drop back to a whisper, and the moment you reach for
   the mouse or leave the note they return. Nothing moves, nothing collapses,
   there is no state to escape from — the only thing that changes is where
   the eye is drawn. */

.lib-notebooks, .lib-notes, .lib-board {
  transition: opacity .5s ease, filter .5s ease;
}
body.is-writing .lib-notebooks,
body.is-writing .lib-notes,
body.is-writing .lib-board {
  opacity: .22;
  filter: saturate(0.5);
}
/* still fully clickable — clicking is one of the things that restores it */

@media (prefers-reduced-motion: reduce) {
  .lib-notebooks, .lib-notes, .lib-board { transition: none; }
}
/* anyone who has asked the OS for more contrast should not have any of it
   quietly taken away */
@media (prefers-contrast: more) {
  body.is-writing .lib-notebooks,
  body.is-writing .lib-notes,
  body.is-writing .lib-board { opacity: 1; filter: none; }
}

/* ---------- FAB ---------- */

.fab {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: var(--shadow-2);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 20;
}
.fab:hover { filter: brightness(1.07); }
.fab svg { width: 22px; height: 22px; }
.fab[hidden] { display: none; }

/* ---------- bottom bar ----------
   Narrow panes only. The back arrow lives in the top-left, which is the
   worst place to reach one-handed, so on a phone-width pane every routine
   action moves down here and the FAB steps aside. */

.bottombar { display: none; }

.bb-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 50px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg-dim);
  font: inherit;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bb-btn svg { width: 20px; height: 20px; }
.bb-btn:hover { color: var(--fg-muted); }
.bb-btn:active { background: var(--bg-hover); }
.bb-btn.active { color: var(--accent); }
.bb-btn:disabled { opacity: .3; cursor: default; }
.bb-btn:disabled:hover { color: var(--fg-dim); background: none; }

@media (max-width: 859px) {
  .app { grid-template-rows: auto var(--topbar-h) 1fr auto; }
  .bottombar {
    display: flex;
    align-items: stretch;
    background: var(--bg-elev);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  /* the bar's New button replaces it */
  .fab { display: none; }
}

/* ---------- selection ---------- */

.select-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--accent);
  color: var(--accent-fg);
  min-height: 40px;
}
.select-bar[hidden] { display: none; }
.select-bar .icon-btn { color: var(--accent-fg); }
.select-bar .icon-btn:hover { background: rgba(255, 255, 255, .18); }

.select-count {
  font-size: 13px;
  font-weight: 600;
  margin-right: auto;
  white-space: nowrap;
}

.select-act {
  flex: 0 0 auto;
  height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .45);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--accent-fg);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.select-act:hover { background: rgba(255, 255, 255, .18); }

/* a selected item, on either surface */
.card.selected,
.note-row.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.note-row.selected { background: var(--accent-soft); }

/* while selecting, the per-card buttons are just misclicks waiting */
body.is-selecting .card-actions { display: none; }

/* ---------- swipe ----------
   The label sits just outside the element's leading edge, so translating
   the card reveals it in the gap it leaves behind — no wrapper element,
   no measuring, and nothing inserted into the DOM mid-gesture. */

.swiping {
  position: relative;
  z-index: 2;
  transition: none !important;
  user-select: none;
}

[data-swipe]::after {
  content: attr(data-swipe-label);
  position: absolute;
  top: 0;
  bottom: 0;
  width: 140px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-radius: var(--r);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  opacity: .55;
  transition: opacity .12s ease;
}
/* swiping right uncovers the left side, and the other way round */
[data-swipe="right"]::after {
  right: 100%;
  margin-right: 6px;
  justify-content: flex-end;
  background: var(--accent);
}
[data-swipe="left"]::after {
  left: 100%;
  margin-left: 6px;
  justify-content: flex-start;
  background: var(--danger);
}
/* full strength once releasing would actually do it */
.swipe-armed[data-swipe]::after { opacity: 1; }

/* ---------- reordering ---------- */

.insert-line {
  position: fixed;
  z-index: 480;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
  box-shadow: 0 0 0 1px var(--bg);
}
.insert-line::before {
  content: "";
  position: absolute;
  left: -3px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- drag to file ---------- */

body.is-dragging,
body.is-dragging * {
  user-select: none;
  -webkit-user-select: none;
}
body.is-dragging { cursor: grabbing; }

.drag-ghost {
  position: fixed;
  z-index: 500;
  /* the pointer sits at the element's origin; nudge the label clear of it */
  transform: translate(12px, 12px);
  pointer-events: none;
  max-width: 220px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  box-shadow: var(--shadow-2);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: .95;
}

.drag-source { opacity: .4; }

.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--r-sm);
}
.nb-row.drop-target,
.smart-row.drop-target,
.note-row.drop-target { background: var(--accent-soft); }

/* the list background is a target too, so it needs a visible bounds */
#note-list.drop-target { outline-offset: -3px; }

/* ---------- save failure ----------
   Loud, persistent, and not dismissible while it applies: this is the one
   state where quietly carrying on would mean losing someone's writing. */

.save-alert {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}
.save-alert[hidden] { display: none; }
.save-alert-btn {
  margin-left: auto;
  flex: 0 0 auto;
  height: 26px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: var(--r-sm);
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.save-alert-btn:hover { background: rgba(255, 255, 255, .16); }

.save-state.failed { color: var(--danger); font-weight: 600; }

/* ---------- selection toolbar ---------- */

.sel-bar {
  position: fixed;
  z-index: 450;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 3px;
  border-radius: var(--r);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
}
.sel-bar[hidden] { display: none; }

.sel-btn {
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--fg-muted);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.sel-btn:hover { background: var(--bg-hover); color: var(--fg); }
.sel-btn.active { background: var(--accent-soft); color: var(--accent); }
.sel-btn svg { width: 15px; height: 15px; }

.sel-sep {
  width: 1px;
  align-self: stretch;
  margin: 3px 3px;
  background: var(--line);
}

/* ---------- popover ---------- */

.popover-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: transparent;
}
.popover-backdrop[hidden] { display: none; }
.popover {
  position: absolute;
  min-width: 180px;
  max-width: min(280px, 92vw);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-2);
  padding: 4px;
}
.pop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.pop-item:hover { background: var(--bg-hover); }
.pop-item.danger { color: var(--danger); }
.pop-item svg { width: 15px; height: 15px; color: var(--fg-dim); }
.pop-item.danger svg { color: var(--danger); }
.pop-sep { height: 1px; background: var(--line); margin: 4px 2px; }
.pop-label { font-size: 11px; color: var(--fg-dim); padding: 6px 9px 3px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.pop-swatches { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 9px 8px; }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 14, 20, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 340px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: 16px;
}
.modal h2 { margin: 0 0 10px; font-size: 15px; }
.modal input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 14px; }

/* ---------- print ----------
   The sheet is Letter-sized on screen, so Ctrl+P may as well produce the
   document it already looks like: chrome gone, paper edges gone, real
   page margins. */

@page { size: letter; margin: 1in; }

@media print {
  .topbar, .bottombar, .fab, .toast,
  .lib-notebooks, .lib-notes, .lib-board,
  .editor-head, .meta-row, .editor-footer, #backlinks-wrap { display: none !important; }

  html, body { height: auto; overflow: visible; background: #fff; color: #000; }
  .app { display: block; height: auto; }
  .main, .pane, .library, .lib-col, .pane-scroll, .editor-scroll {
    position: static;
    display: block;
    overflow: visible;
    height: auto;
    padding: 0;
  }
  .lib-editor[hidden] { display: block !important; }

  .page {
    max-width: none;
    border: 0;
    box-shadow: none;
    background: none;
    padding: 0;
    min-height: 0;
  }
  .page #block-editor { margin-left: 0; padding-left: 0; }
  .be-drag-handle { display: none !important; }
  .title-input { font-size: 22pt; border: 0; }
}

/* ---------- shortcuts sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(10, 14, 20, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
}
.sheet-backdrop[hidden] { display: none; }

.keys-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.keys-head {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.keys-head h2 { margin: 0; font-size: 15px; flex: 1 1 auto; }
/* opened from the menu, it should still teach you the key */
.head-key {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 6px;
  color: var(--fg-muted);
}

.keys-body {
  overflow-y: auto;
  padding: 6px 14px 16px;
  columns: 240px;
  column-gap: 28px;
}
.keys-group { break-inside: avoid; margin-top: 12px; }
.keys-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
  font-size: 13px;
}
.keys-row span { flex: 1 1 auto; color: var(--fg-muted); }
.keys-row kbd {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--fg);
  white-space: nowrap;
}

/* the pending half of a chord, so g does not feel like nothing happened */
.chord-hint {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 300;
  padding: 7px 14px;
  border-radius: var(--r-sm);
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 12px;
  box-shadow: var(--shadow-2);
}
.chord-hint[hidden] { display: none; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 300;
  max-width: min(360px, 92vw);
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 12.5px;
  box-shadow: var(--shadow-2);
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast[hidden] { display: none; }
.toast button {
  border: 0; background: none; padding: 0;
  color: var(--bg); font: inherit; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}

/* ---------- narrow-pane polish (Opera sidebar ≈ 320–460px) ---------- */

@media (max-width: 560px) {
  .wordmark { display: none; }
  .editor-scroll { padding: 0; }
  .title-input { font-size: 18px; }

  /* a sheet inside a phone-width pane is just wasted edges */
  .page {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: none;
    padding: 12px 12px 56px;
    min-height: 0;
  }
}
