/* Pinny — “Paper” theme: a warm corkboard of sticky notes. */

:root {
  --bg: #f5efe2;
  --bg-dot: #e2d8c4;
  --paper: #fffdf6;
  --border: #d9cdb4;
  --border-strong: #c9ba9e;
  --text: #3d332a;
  --muted: #8a7a64;
  --soft: #6b5c48;
  --red: #b3261e;
  --red-dark: #7a1712;
  --amber: #d97706;
  --amber-deep: #92400e;
  --danger: #c62f28;
  --shadow: rgba(90, 70, 40, 0.22);
  --marker: "Marker Felt", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  --hand: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  --radius: 3px;

  /* Motion. Two curves only: things settle (ease-out) or they land like a note
     dropped on a board (spring). Anything that needs a third curve is probably
     an effect rather than a response. */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.2, 1.5, 0.4, 1);

  /* Chrome surfaces — the board furniture, not the notes. */
  --topbar-bg: rgba(245, 239, 226, 0.94);
  --topbar-border: rgba(217, 205, 180, 0.6);
  --hover: rgba(217, 205, 180, 0.4);
  --field: #fff;                  /* text inputs */
  --btn-bg: #efe6d2;
  --btn-bg-hover: #e9dec5;
  --btn-text: #574a38;
  --scrim: rgba(61, 51, 42, 0.45); /* modal backdrop */
  --red-hover: #9e211a;
  /* Red as a FILL is a different colour from red as text. Dark mode lightens
     --red so it reads on a near-black board, but that same value behind white
     text is 3.7:1 — under the floor. These two are always the background of a
     filled control, and --red stays the ink/border value. */
  --red-fill: #b3261e;          /* white on this: 6.5:1 */
  --red-fill-hover: #9e211a;
  --sticky-filter: none;

  /* Ink: text printed ON a sticky note. The notes stay paper-coloured in
     every theme (they're the whole point of the design), so this must NOT
     follow --text — otherwise dark mode puts pale text on a pale note.
     Redefined inside .card so existing rules need no changes. */
  --ink: #3d332a;
  --ink-soft: #6b5c48;
  --ink-muted: #8a7a64;
  --ink-border: #c9ba9e;
  --ink-hover: rgba(0, 0, 0, 0.07);
  --ink-red: #b3261e;
  --ink-danger: #c62f28;
}

/* Every paper surface — a board note, the login note, the splash note — keeps
   dark ink on a light note in both themes, so the tokens are re-pointed once
   here rather than theme-proofing each rule inside them. */
.card, .login-card, .s-note, .detail-banner {
  --text: var(--ink);
  --soft: var(--ink-soft);
  --muted: var(--ink-muted);
  --border: var(--ink-border);
  --border-strong: var(--ink-border);
  --paper: #fffdf6;
  --field: #fff;
  --red: var(--ink-red);
  --danger: var(--ink-danger);
  --hover: var(--ink-hover);
  color: var(--ink);
  filter: var(--sticky-filter);
}

/* Dark mode: the board goes dark, the notes stay paper.
   Keyed only off data-theme, never off prefers-color-scheme directly —
   applyTheme() in app.js resolves the "system" setting to a concrete
   light/dark value and watches for OS changes. One palette, one source of
   truth, and the toggle and the system preference can't disagree. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #17140f;
  --bg-dot: #2b2419;
  --paper: #241f18;
  --border: #3b3328;
  --border-strong: #52483a;
  --text: #ede4d4;
  --muted: #9d9180;
  --soft: #c2b6a2;
  /* Lifted off the light-theme reds: #b3261e on a near-black board fails
     contrast and reads as brown. */
  --red: #e2584d;
  --red-dark: #b3261e;
  --amber: #f0a63c;
  --amber-deep: #f0a63c;
  --danger: #ef6259;
  --shadow: rgba(0, 0, 0, 0.55);

  --topbar-bg: rgba(23, 20, 15, 0.94);
  --topbar-border: rgba(82, 72, 58, 0.55);
  --hover: rgba(255, 255, 255, 0.08);
  --field: #1b1712;
  --btn-bg: #322b22;
  --btn-bg-hover: #3d352a;
  --btn-text: #ede4d4;
  --scrim: rgba(0, 0, 0, 0.62);
  /* Hover must go lighter on a dark board, not darker. */
  --red-hover: #ef6b60;
  /* Deliberately NOT --red: a filled control needs its background dark enough
     to carry white text (5.6:1), while --red stays lifted for use as ink. */
  --red-fill: #c0352b;
  --red-fill-hover: #d04236;
  /* Real sticky notes don't glow in a dark room. Takes the edge off the
     pastels without touching stickyColor() in app.js. */
  --sticky-filter: brightness(0.86) saturate(0.92);

  /* --ink-* deliberately NOT redefined: notes keep dark text on paper. */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1.1px, transparent 1.1px);
  background-size: 22px 22px;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- in-app splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1.1px, transparent 1.1px);
  background-size: 22px 22px;
  transition: opacity 0.4s ease;
}
#splash.bye { opacity: 0; pointer-events: none; }
.s-note {
  position: relative; text-align: center;
  background: #fef3b2;
  padding: 36px 44px 30px;
  border-radius: 3px;
  box-shadow: 4px 8px 26px var(--shadow);
  transform: rotate(-1.5deg);
  animation: s-drop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.s-note::before {
  content: ""; position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  width: 19px; height: 19px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff7d75, #c62f28 65%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
  animation: s-pin 0.3s 0.4s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.s-name {
  font-family: var(--marker); font-size: 38px; color: var(--red);
  letter-spacing: 0.5px; margin-top: 4px;
}
.s-tag {
  font-family: var(--hand); font-size: 13.5px; color: var(--soft); margin-top: 4px;
  animation: s-fade 0.5s 0.5s both;
}
@keyframes s-drop {
  from { transform: translateY(-46px) rotate(-7deg); opacity: 0; }
  to   { transform: translateY(0) rotate(-1.5deg); opacity: 1; }
}
@keyframes s-pin {
  from { transform: translateX(-50%) scale(0); }
  to   { transform: translateX(-50%) scale(1); }
}
@keyframes s-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- login (a sticky note on the board) ---------- */
.login {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1.1px, transparent 1.1px);
  background-size: 22px 22px;
  padding: 24px;
}
.login-card {
  position: relative;
  width: 100%; max-width: 330px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
  background: #fef3b2;
  padding: 34px 26px 26px;
  border-radius: var(--radius);
  box-shadow: 4px 7px 20px var(--shadow);
  transform: rotate(-1.2deg);
}
.login-card::before {
  content: ""; position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  width: 17px; height: 17px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff7d75, #c62f28 65%);
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.35);
}
.login-card h1 {
  margin: 0; font-size: 32px; color: var(--red);
  font-family: var(--marker); letter-spacing: 0.5px;
}
.login-card .tagline {
  margin: 0 0 8px; color: var(--soft); font-size: 14px;
  font-family: var(--hand);
}
.login-card .logo { margin: 0 auto; }
.login-card input {
  background: var(--paper); border: 2px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 12px 14px; font-size: 16px; outline: none;
}
.login-card input:focus { border-color: var(--red); }
.form-error { color: var(--danger); font-size: 13px; font-family: var(--hand); }

/* ---------- top bar ---------- */
/* Search + filter chips travel together. Scrolling down slides the whole
   block out of the way; scrolling up anywhere brings it straight back, so the
   search box is always a short flick away without returning to the top. */
.stickyhead {
  position: sticky; top: 0; z-index: 20;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--topbar-border);
  transition: transform 0.22s ease;
}
body.head-hidden .stickyhead { transform: translateY(-100%); }
/* Logged out, both children are display:none — don't leave a stray hairline
   and a blur panel floating over the login card. */
.stickyhead:has(> .topbar.hidden) {
  background: none; backdrop-filter: none; border-bottom: none;
}
/* Someone navigating by keyboard must never be scrolled to a control they
   can't see, so any focus inside the header cancels the hide. */
.stickyhead:focus-within { transform: none !important; }
@media (prefers-reduced-motion: reduce) {
  .stickyhead { transition: none; }
}

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand {
  display: flex; align-items: center; gap: 7px;
  font-family: var(--marker); font-weight: 700; font-size: 22px; color: var(--red);
}
#search {
  flex: 1; min-width: 0;
  background: var(--paper); border: 2px solid var(--border); color: var(--text);
  border-radius: 14px; padding: 9px 16px; font-size: 15px; outline: none;
  box-shadow: 2px 3px 0 var(--border);
}
#search::placeholder { color: var(--muted); }
#search:focus { border-color: var(--red); }
.icon-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 7px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn svg { display: block; }
.icon-btn:hover { color: var(--text); background: var(--hover); }

/* ---------- category chips ---------- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  background: var(--paper); border: 1.5px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 6px 14px; font-size: 13.5px; cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: var(--red-fill); border-color: var(--red-fill); color: #fff; }

/* ---------- grid & sticky-note cards ---------- */
.grid {
  display: grid;
  column-gap: 18px;
  /* Masonry: each card spans as many 4px rows as it needs, so a short note
     doesn't leave dead space under it. The row gap is folded into each span
     by layoutGrid() — a real row-gap would coarsen the vertical resolution to
     4 + 18 = 22px and pad every card with up to 21px of slack. */
  row-gap: 0;
  grid-auto-rows: 4px; /* MASONRY_ROW in app.js must match */
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  align-items: start; /* sticky notes keep their natural height */
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
  max-width: 1200px; margin: 0 auto;
}
.card {
  position: relative;
  --tilt: -0.8deg;
  background: var(--paper); /* overridden per category from app.js */
  border-radius: var(--radius);
  overflow: visible;
  min-width: 0;
  /* Load-bearing for masonry: a stretched card's height would become its own
     span height, growing by the gap on every measurement and spinning the
     ResizeObserver forever. Do not remove. */
  align-self: start;
  cursor: pointer; display: flex; flex-direction: column;
  box-shadow: 3px 5px 14px var(--shadow);
  transform: rotate(var(--tilt));
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.grid .card:nth-child(2n) { --tilt: 0.9deg; }
.grid .card:nth-child(3n) { --tilt: -0.3deg; }
.card:hover {
  transform: rotate(0deg) scale(1.015);
  box-shadow: 5px 8px 22px var(--shadow);
  z-index: 2;
}
.card::before { /* push pin */
  content: ""; position: absolute; top: -7px; left: 50%; transform: translateX(-50%);
  width: 15px; height: 15px; border-radius: 50%; z-index: 3;
  background: radial-gradient(circle at 35% 30%, #ff7d75, #c62f28 65%);
  box-shadow: 0 3px 4px rgba(0, 0, 0, 0.35);
}

/* favourites: golden pin, gently larger */
.card.fav { transform: rotate(var(--tilt)) scale(1.025); box-shadow: 4px 7px 20px var(--shadow); }
.card.fav:hover { transform: rotate(0deg) scale(1.035); }
.card.fav::before {
  background: radial-gradient(circle at 35% 30%, #ffe08a, #d97706 68%);
}

/* text-only notes: your own words, in your own hand */
.card.note-pin .card-title {
  font-family: var(--hand);
  font-size: 17.5px;
  line-height: 1.4;
}

/* ---------- the cover ----------
   The top of a card is now a target of its own: it goes to the page, or opens
   the picture full screen, while the text below it opens the pin. It is an <a>
   or a <button>, so the platform's own affordances come with it — which also
   means the platform's chrome has to be undone here. */
.thumb-wrap {
  position: relative; margin: 16px 13px 0;
  display: block; width: 100%;
  appearance: none; border: 0; background: none; padding: 0;
  font: inherit; color: inherit; text-align: inherit; text-decoration: none;
  cursor: pointer;
  transition: filter 0.16s ease;
  /* The largest target on the card is an image inside a link, so a long press
     aimed at selection would otherwise raise the native "save image" menu. */
  -webkit-touch-callout: none;
  user-select: none; -webkit-user-select: none;
}
.thumb-wrap:hover { filter: brightness(1.04) saturate(1.03); }
.thumb-wrap:active { filter: brightness(0.97); }
/* In selection mode the whole card is one target; a second one inside it would
   fight the long-press — and would navigate on the click that trails it. */
body.selecting .thumb-wrap { pointer-events: none; }
.card-image { /* a photo taped onto the note */
  width: 100%;
  aspect-ratio: 1.91; object-fit: cover; display: block;
  background: #efe9db;
  border: 4px solid #fff;
  box-shadow: 0 2px 8px rgba(90, 70, 40, 0.3);
  box-sizing: border-box;
}

/* The stand-in cover, for a link whose page offered no image. Same frame and
   same geometry as a real photo, so the card reads the same either way: the
   cover is always there, always in the same place, always the way out. */
.thumb-fallback {
  --cover-hue: 40deg;                   /* JS overrides per domain */
  width: 100%; aspect-ratio: 1.91; box-sizing: border-box;
  border: 4px solid #fff;
  box-shadow: 0 2px 8px rgba(90, 70, 40, 0.3);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  overflow: hidden;
  /* A wash of the site's own hue over the paper rather than an opaque fill, so
     it belongs to whatever sticky colour it lands on, in either theme. */
  background:
    linear-gradient(150deg,
      hsl(var(--cover-hue) 45% 55% / 0.22),
      hsl(var(--cover-hue) 45% 45% / 0.09) 62%,
      transparent),
    repeating-linear-gradient(45deg,
      rgba(0, 0, 0, 0.028) 0 6px, transparent 6px 12px),
    #f4eee0;
}
.thumb-fallback-initial {
  font-family: var(--hand); font-size: 30px; line-height: 1;
  font-weight: 700; color: var(--ink-soft);
}
.thumb-fallback-host {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--ink-muted);
  max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  /* A host is a URL fragment: LTR even on an RTL note. */
  direction: ltr; unicode-bidi: isolate;
}

/* Says where the cover goes, on every card and not only on hover — touch has
   no hover to reveal it with. Same family as the play badge below. */
.thumb-badge {
  position: absolute; top: 10px; inset-inline-end: 10px;
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(40, 30, 20, 0.58); color: #fff;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.thumb-badge .icon-out, .thumb-badge .icon-expand { opacity: 0.95; margin: 0; }
.play-badge {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(40, 30, 20, 0.6); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; padding-left: 4px;
  pointer-events: none;
}
.card-body { padding: 14px 15px 12px; display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 0; }
.card-title {
  font-weight: 700; font-size: 15.5px; line-height: 1.35; margin: 2px 0 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere; word-break: break-word;
}
.card-summary {
  color: var(--soft); font-size: 13.5px; line-height: 1.45; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere; word-break: break-word;
}
.card-note {
  font-family: var(--hand);
  font-size: 13px; color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.45);
  /* Logical, not left: on an Arabic note the bar belongs on the right. */
  border-inline-start: 3px solid rgba(0, 0, 0, 0.18);
  padding: 5px 9px;
  border-start-end-radius: 8px; border-end-end-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: break-word;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11.5px; color: var(--muted);
  background: rgba(255, 255, 255, 0.5);
  border: 1px dashed var(--border-strong);
  padding: 2px 8px; border-radius: 4px; cursor: pointer;
}
.tag:hover { color: var(--text); border-style: solid; }
.card-footer {
  margin-top: auto; display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 12px; padding-top: 4px;
}
.badge {
  font-size: 10.5px; padding: 3px 8px; border-radius: 4px; font-weight: 700;
  letter-spacing: 0.4px; text-transform: uppercase;
}
.badge.category { background: rgba(0, 0, 0, 0.08); color: var(--ink-soft); }
.badge.pending { background: rgba(217, 119, 6, 0.14); color: var(--amber-deep); animation: pulse 1.4s infinite; }
.badge.failed { background: rgba(198, 47, 40, 0.12); color: var(--danger); }
.badge.archived { background: rgba(0, 0, 0, 0.06); color: var(--muted); }
@keyframes pulse { 50% { opacity: 0.45; } }
.card-footer .spacer, .modal-actions .spacer, .detail-toolbar .spacer { flex: 1; }
.card-action {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 15px; padding: 2px 6px; border-radius: 6px;
}
.card-action:hover { color: var(--text); background: var(--ink-hover); }
.card-action.star.active { color: var(--amber); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 80px 24px; color: var(--muted); font-family: var(--hand); font-size: 15px; }
.empty-pin { font-size: 40px; margin-bottom: 12px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 30;
  width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(180deg, #c8382e, #9e211a);
  color: #fff; border: none;
  font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 2px 4px rgba(122, 23, 18, 0.35),
    0 8px 22px rgba(90, 70, 40, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.fab:hover {
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 4px 8px rgba(122, 23, 18, 0.35),
    0 12px 28px rgba(90, 70, 40, 0.4);
}
.fab:active {
  transform: translateY(1px) scale(0.96);
  box-shadow:
    inset 0 2px 5px rgba(80, 12, 8, 0.5),
    0 2px 6px rgba(90, 70, 40, 0.3);
}

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--paper); border: 1px solid var(--border);
  border-radius: 18px 18px 0 0; width: 100%; max-width: 560px;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  box-shadow: 0 -8px 34px var(--shadow);
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; }
}
.modal h2 { margin: 0 0 14px; font-size: 20px; font-family: var(--marker); color: var(--red); }
.modal label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.modal .hint { font-weight: 400; opacity: 0.75; }
.modal input, .modal textarea, .modal select {
  width: 100%; margin-top: 5px;
  background: var(--field); border: 2px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 15px; outline: none;
  font-family: inherit; resize: vertical;
}
.modal input:focus, .modal textarea:focus, .modal select:focus { border-color: var(--red); }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }

.btn {
  background: var(--btn-bg); border: 1.5px solid var(--border); color: var(--btn-text);
  border-radius: 10px; padding: 10px 18px; font-size: 15px; cursor: pointer;
}
.btn:hover { background: var(--btn-bg-hover); }
.btn.primary { background: var(--red-fill); border-color: var(--red-fill); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--red-fill-hover); border-color: var(--red-fill-hover); }
.btn.danger { background: none; border-color: rgba(198, 47, 40, 0.55); color: var(--danger); }

/* ---------- infinite scroll sentinel ---------- */
#sentinel { height: 1px; }

/* ---------- settings ---------- */
.settings-heading {
  font-size: 15px; color: var(--soft); margin: 18px 0 8px; font-weight: 700;
  font-family: var(--marker);
}
.settings-hint { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.embedding-progress {
  display: block; width: 100%; height: 6px; margin: 0 0 10px;
  border: 0; accent-color: var(--red);
}
.embedding-progress::-webkit-progress-bar { background: var(--btn-bg); border-radius: 3px; }
.embedding-progress::-webkit-progress-value { background: var(--red); border-radius: 3px; }
.embedding-progress::-moz-progress-bar { background: var(--red); border-radius: 3px; }

/* ---------- search progress ----------
   Semantic search costs a round trip to embed the query, so the wait has to be
   visible — otherwise a blank board just looks like the pins disappeared. */
.progress { height: 2px; overflow: hidden; background: none; }
body.busy .progress::after {
  content: ""; display: block; height: 100%; width: 40%;
  background: linear-gradient(90deg, transparent, var(--red), transparent);
  animation: progress-slide 0.9s ease-in-out infinite;
}
@keyframes progress-slide {
  from { transform: translateX(-100%); }
  to   { transform: translateX(350%); }
}
/* Keep the previous results readable underneath rather than clearing them. */
body.busy .grid { opacity: 0.55; transition: opacity 0.15s ease; }
/* Don't announce "nothing matches" while the answer is still in flight. */
body.busy .empty { visibility: hidden; }
@media (prefers-reduced-motion: reduce) {
  body.busy .progress::after { animation: none; width: 100%; opacity: 0.5; }
  body.busy .grid { transition: none; }
}

/* ---------- selection mode & bulk bar ---------- */
body.selecting {
  --toast-bottom: 160px;          /* clear the bar */
}
body.selecting .card {
  cursor: default;
  -webkit-touch-callout: none;    /* no iOS "open link" sheet on long press */
  user-select: none; -webkit-user-select: none;
}
/* Kill the hover lift, which otherwise fights the selected state. */
body.selecting .card:hover { transform: rotate(var(--tilt)); box-shadow: 3px 5px 14px var(--shadow); }
body.selecting .grid { padding-bottom: calc(170px + env(safe-area-inset-bottom)); }

/* Straighten the note rather than outlining it — it reads as picked up off the
   board, and being transform-only it leaves offsetHeight (and so the masonry
   span) completely alone. */
.card.selected {
  transform: rotate(0deg) scale(0.97) !important;
  box-shadow: 0 0 0 3px var(--red), 4px 7px 20px var(--shadow);
}
.card.selected::before {   /* the push pin becomes a tick */
  content: "✓"; width: 22px; height: 22px; top: -11px;
  color: #fff; font-size: 13px; line-height: 22px; text-align: center;
  background: var(--red-fill);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
}

.bulkbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 35;                       /* over the fab (30), under modals (40) */
  background: var(--paper);
  border-top: 1.5px solid var(--border-strong);
  box-shadow: 0 -6px 24px var(--shadow);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
.bulkbar-row { display: flex; align-items: center; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.bulkbar-row::-webkit-scrollbar { display: none; }
.bulkbar .btn { flex: 0 0 auto; }
.bulk-count { font-family: var(--marker); font-weight: 700; color: var(--soft); white-space: nowrap; }
.bulk-all {
  display: block; width: 100%; margin-top: 8px; padding: 7px;
  background: none; border: 1.5px dashed var(--border-strong); border-radius: 10px;
  color: var(--red); font-size: 13.5px; cursor: pointer;
}
/* The card checkbox only makes sense where there's a pointer to hover with;
   touch uses long-press instead. */
@media (hover: hover) {
  /* Sits just outside the card corner, like the push pin — inside it would
     land on top of the first line of the title. */
  .card-select {
    position: absolute; top: -9px; left: -9px; z-index: 4;
    width: 22px; height: 22px; border-radius: 50%;
    border: 2px solid var(--border-strong); background: var(--paper);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
    opacity: 0; transition: opacity 0.12s ease; cursor: pointer;
  }
  .card:hover .card-select { opacity: 1; }
  /* Once selecting, the ✓ pin already says what's picked and the whole card is
     a target, so the extra affordance is just noise. */
  body.selecting .card-select { display: none; }
}

/* ---------- pin detail sheet ----------
   The sheet itself is CHROME, not paper. Adding it to the .card/.login-card/
   .s-note ink list would apply --sticky-filter to the whole sheet including its
   buttons, make it a containing block for fixed-position descendants, and give
   it white inputs while the edit sheet stacked on top stayed dark. The pin's
   identity is carried by the banner instead — and that IS paper (see the ink
   selector list near the top of this file). */
.detail-banner {
  margin: -20px -20px 14px;            /* bleed to the sheet's edges */
  padding: 18px 20px 14px;
  border-radius: 18px 18px 0 0;
  background: var(--paper);            /* overridden per item from JS */
}
@media (min-width: 640px) { .detail-banner { border-radius: 16px 16px 0 0; } }
.detail-banner h2 {
  margin: 0; font-family: var(--marker); font-size: 21px; line-height: 1.3;
  color: var(--ink); overflow-wrap: anywhere; word-break: break-word;
}
.detail-sub {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 7px; font-size: 12px; color: var(--ink-muted);
}
.detail-image {
  display: block; width: 100%; padding: 0; margin: 0 0 12px;
  background: none; border: none; cursor: zoom-in;
}
.detail-image img {
  width: 100%; max-height: 46vh; object-fit: contain; display: block;
  background: #efe9db; border: 5px solid #fff;
  box-shadow: 0 2px 10px rgba(90, 70, 40, 0.3);
}
.detail-summary { margin: 0 0 12px; color: var(--soft); font-size: 14.5px; line-height: 1.5; }
/* Not .card-note: that hardcodes ink for a paper background and would be
   dark-on-dark inside this chrome sheet. */
.detail-note {
  font-family: var(--hand); font-size: 14px; color: var(--soft);
  background: var(--hover); border-inline-start: 3px solid var(--border-strong);
  padding: 8px 11px; margin-bottom: 12px;
  border-start-end-radius: 8px; border-end-end-radius: 8px;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
/* .tag assumes a paper card: a translucent-white pill with dark ink. On this
   chrome sheet that renders light-on-light in dark mode. */
#detail-tags { margin-bottom: 12px; }
#detail-tags .tag {
  background: var(--hover); color: var(--soft); border-color: var(--border-strong);
}
#detail-tags .tag:hover { color: var(--text); }

.detail-text { margin: 12px 0; font-size: 13px; color: var(--muted); }
.detail-text summary { cursor: pointer; color: var(--soft); }
.detail-text p {
  margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 34vh; overflow-y: auto; line-height: 1.5;
}
.detail-meta {
  margin: 14px 0 4px; display: grid; grid-template-columns: auto 1fr;
  gap: 5px 14px; font-size: 13px;
}
.detail-meta dt { color: var(--muted); }
.detail-meta dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
/* The sheet scrolls; the actions must stay reachable without scrolling to the
   bottom of a long page text. Two tiers, not one wrapping row of six: leaving
   for the page is the reason a link was saved, so it gets the full width and
   the only filled button on the sheet. Managing the pin sits under it, quiet.
   The fade stops long page text from appearing to end at the sticky edge. */
.detail-actions {
  position: sticky; bottom: 0; z-index: 1;
  margin-top: 16px;
  padding-top: 12px;
  padding-bottom: 2px;
  display: flex; flex-direction: column; gap: 9px;
  background: var(--paper);
}
.detail-actions::before {
  content: ""; position: absolute; inset-inline: 0; top: -20px; height: 20px;
  background: linear-gradient(to top, var(--paper), transparent);
  pointer-events: none;
}

.btn-open {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px 18px; font-size: 15.5px;
}
.btn-open-host {
  font-weight: 500; opacity: 0.82;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 46%;
}
/* Nudges out along the arrow's own axis, so the icon reads as the motion it
   depicts rather than as a button that wobbles. */
.btn-open .icon-out { transition: translate 0.16s var(--ease-out); }
.btn-open:hover .icon-out { translate: 2px -2px; }

.detail-toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.detail-toolbar .btn { padding: 9px 15px; font-size: 14.5px; }

/* Banner tools: the two things you do TO the pin while reading it, on the pin
   itself rather than filed at the bottom with destructive actions. */
.detail-banner-top {
  display: flex; align-items: flex-start; gap: 10px;
}
.detail-banner-top h2 { flex: 1; min-width: 0; }
.detail-banner-tools {
  display: flex; align-items: center; gap: 2px; flex: 0 0 auto;
  margin: -4px -6px 0 0;
}
.pin-tool {
  background: none; border: none; cursor: pointer;
  color: var(--ink-muted);
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 19px; line-height: 1; padding: 0;
  transition: background 0.14s ease, color 0.14s ease, scale 0.14s var(--ease-out);
}
.pin-tool:hover { background: var(--ink-hover); color: var(--ink); }
.pin-tool:active { scale: 0.9; }
.pin-tool.active { color: var(--amber-deep); }
/* The star is a state change on the pin, so it should feel like one. */
.pin-tool.active { animation: star-pop 0.32s var(--ease-spring); }
@keyframes star-pop {
  40% { scale: 1.32; rotate: -9deg; }
  to  { scale: 1; rotate: 0deg; }
}

/* ---------- filter sheet ---------- */
.filter-section { margin-bottom: 4px; }
.filter-section .settings-heading:first-child { margin-top: 8px; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-chips .chip:disabled { opacity: 0.4; cursor: default; }
.filter-chips .chip.more { border-style: dashed; color: var(--soft); }
.cat-list { list-style: none; margin: 0 0 10px; padding: 0; }
.cat-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 10px;
  margin-bottom: 6px; font-size: 14.5px; background: var(--field);
}
.cat-delete {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 2px 8px; border-radius: 6px;
}
.cat-delete:hover { color: var(--danger); background: rgba(198, 47, 40, 0.08); }
.cat-form { display: flex; gap: 8px; }
.cat-form input {
  flex: 1; background: var(--field); border: 2px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font-size: 14.5px; outline: none;
}
.cat-form input:focus { border-color: var(--red); }
.export-actions { display: flex; gap: 10px; }
.export-actions .btn { text-decoration: none; display: inline-block; }

/* ---------- colour swatches ---------- */
.swatches { display: flex; gap: 9px; margin-top: 7px; flex-wrap: wrap; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--border-strong); cursor: pointer; padding: 0;
  font-size: 12px; color: var(--muted); background: #fff;
}
.swatch.sel { border-color: var(--red); box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.2); }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(43, 35, 26, 0.9);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 93%; max-height: 90%;
  border: 6px solid #fff; background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transform: rotate(-0.6deg);
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  /* Raised while the bulk bar is up, so the two don't stack on top of each
     other — see body.selecting below. */
  bottom: calc(var(--toast-bottom, 94px) + env(safe-area-inset-bottom)); z-index: 45;
  background: #3d332a; border: none; color: #fef3b2;
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  font-family: var(--hand);
  box-shadow: 0 8px 24px rgba(61, 51, 42, 0.45);
}

/* ---------- the way out of a pin ----------
   A saved link exists to be opened again, but the domain used to be a dead
   word in the footer and the only real exit was two taps deep in the detail
   sheet. This is that exit, sitting on the note's bottom edge like the strip
   of tape holding it down: dashed rule above it (the perforation), the host,
   and an arrow leaving a box. It is a real <a>, so everything the platform
   already knows how to do with a link keeps working. */
.card-link {
  display: flex; align-items: center; gap: 6px;
  margin: 2px -15px -12px;              /* bleed to the note's edges */
  padding: 9px 15px 10px;
  border-top: 1px dashed var(--border-strong);
  color: var(--ink-soft); text-decoration: none;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.01em;
  border-end-start-radius: var(--radius); border-end-end-radius: var(--radius);
  transition: background 0.16s ease, color 0.16s ease;
}
.card-link-host {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  /* The host is a URL fragment: it stays LTR even on an RTL note. */
  direction: ltr; unicode-bidi: isolate;
}
.card-link .icon-out {
  margin-inline-start: auto; flex: 0 0 auto; opacity: 0.75;
  transition: translate 0.16s var(--ease-out), opacity 0.16s ease;
}
.card-link:hover {
  background: rgba(0, 0, 0, 0.055);
  color: var(--ink);
}
.card-link:hover .icon-out { translate: 2px -2px; opacity: 1; }
.card-link:active { background: rgba(0, 0, 0, 0.09); }
/* In selection mode the whole card is one target; a second one inside it
   would fight the long-press. */
body.selecting .card-link { pointer-events: none; }

/* ---------- infinite scroll feedback ----------
   The sentinel fires a screen early, so on a Pi over home broadband the page
   before this existed simply stopped growing with no explanation. */
.more {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 4px 24px 34px;
  color: var(--muted); font-family: var(--hand); font-size: 13.5px;
}
.more-pins { display: flex; gap: 5px; }
.more-pins i {
  width: 9px; height: 9px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff7d75, #c62f28 65%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.28);
  animation: pin-drop 0.9s var(--ease-out) infinite;
}
.more-pins i:nth-child(2) { animation-delay: 0.12s; }
.more-pins i:nth-child(3) { animation-delay: 0.24s; }
/* Pins being pushed in, not dots pulsing: they come down and stop. */
@keyframes pin-drop {
  0%       { translate: 0 -7px; opacity: 0; scale: 0.7; }
  35%, 70% { translate: 0 0;    opacity: 1; scale: 1; }
  100%     { translate: 0 0;    opacity: 0; scale: 1; }
}

/* The end of a finite board deserves to be marked; an infinite list that just
   stops reads as a list that broke. */
.board-end {
  display: flex; align-items: center; justify-content: center;
  padding: 0 24px 40px;
}
.board-end span {
  display: block; width: 46px; height: 1px;
  background: var(--border-strong); opacity: 0.7;
}

/* ---------- motion ----------
   One authored moment: a pin arrives on the board. Everything else is a
   response to touch, kept short enough to feel like the surface reacting
   rather than like an animation being played at you. */
.card-in {
  animation: card-in 0.42s var(--ease-out) both;
  animation-delay: var(--in-delay, 0ms);
}
/* `translate`/`scale`, never `transform`: .card already owns transform for its
   tilt (and :hover, .fav and .selected all rewrite it). The individual
   properties compose with it instead of fighting over the same declaration. */
@keyframes card-in {
  from { opacity: 0; translate: 0 14px; scale: 0.97; }
  to   { opacity: 1; translate: 0 0;    scale: 1; }
}

/* Sheets rise from the edge they're docked to. Authored as an animation, not a
   transition, because these open from display:none and a transition would need
   @starting-style to have anything to run from. */
.modal-backdrop:not(.hidden), .lightbox:not(.hidden) {
  animation: scrim-in 0.2s ease both;
}
.modal-backdrop:not(.hidden) > .modal {
  animation: sheet-up 0.34s var(--ease-out) both;
}
.lightbox:not(.hidden) img { animation: lightbox-in 0.3s var(--ease-spring) both; }
@keyframes scrim-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up {
  from { translate: 0 22px; opacity: 0; }
  to   { translate: 0 0;    opacity: 1; }
}
@keyframes lightbox-in {
  from { scale: 0.94; opacity: 0; }
  to   { scale: 1;    opacity: 1; }
}
/* Centred on a wide screen it's a dialog, not a sheet: it should grow in place
   rather than slide up from a bottom edge it no longer has. */
@media (min-width: 640px) {
  @keyframes sheet-up {
    from { translate: 0 10px; scale: 0.985; opacity: 0; }
    to   { translate: 0 0;    scale: 1;     opacity: 1; }
  }
}

/* The pin coming off the board when you pick it up. */
.card.selected { transition: box-shadow 0.15s ease; }

.chip { transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease, scale 0.12s var(--ease-out); }
.chip:active { scale: 0.95; }
.btn { transition: background 0.14s ease, border-color 0.14s ease, scale 0.12s var(--ease-out); }
.btn:active { scale: 0.975; }
.tag { transition: color 0.14s ease, border-style 0.14s ease, background 0.14s ease; }
.card-action { transition: color 0.14s ease, background 0.14s ease, scale 0.14s var(--ease-out); }
.card-action:active { scale: 0.86; }
.icon-btn { transition: color 0.14s ease, background 0.14s ease; }

/* ---------- browser surfaces ----------
   The parts nobody draws still carry the design: a default blue selection or a
   platform focus ring on a corkboard is the seam that gives away the template. */
::selection { background: rgba(179, 38, 30, 0.22); color: inherit; }
:root[data-theme="dark"] ::selection { background: rgba(226, 88, 77, 0.3); }
.card ::selection { background: rgba(179, 38, 30, 0.18); }

input, textarea, select { caret-color: var(--red); }

:where(button, a, [tabindex], input, textarea, select, summary):focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
  border-radius: 6px;
}
/* The pin already reads as focused when it straightens; a rectangle around a
   rotated note would be off-axis with it. */
.card:focus-visible { outline-offset: 4px; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 99px;
  border: 3px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* One switch for the whole motion layer. Feedback that is only motion (the
   loader) degrades to a static state rather than disappearing. */
@media (prefers-reduced-motion: reduce) {
  .card-in, .modal-backdrop:not(.hidden), .modal-backdrop:not(.hidden) > .modal,
  .lightbox:not(.hidden), .lightbox:not(.hidden) img, .pin-tool.active {
    animation: none;
  }
  .more-pins i { animation: none; opacity: 1; }
  .card-link, .card-link .icon-out, .btn-open .icon-out, .thumb-wrap,
  .chip, .btn, .tag, .card-action, .icon-btn, .pin-tool {
    transition: none;
  }
  .chip:active, .btn:active, .card-action:active, .pin-tool:active { scale: 1; }
}

/* ---------- scroll lock ----------
   While a sheet covers the board, the board must not move: a flick aimed at
   the sheet used to scroll the pins behind it, so dismissing the sheet left
   you somewhere you never navigated to. `overflow: hidden` alone doesn't hold
   on iOS, so the body is pinned and offset by the scroll position it had;
   setScrollLock() in app.js restores it on the way out. */
body.scroll-locked {
  position: fixed;
  inset-inline: 0;
  width: 100%;
  overflow: hidden;
}
/* Reserve the scrollbar's width permanently so pinning the body can't shift
   the whole board sideways on a pointer platform. No-op where scrollbars
   already overlay the content, which is every phone. */
html { scrollbar-gutter: stable; }

/* Stops a flick that reaches the end of the sheet's own scroll from chaining
   out to whatever is behind it. */
.modal, .detail-text p { overscroll-behavior: contain; }
