:root {
  --bg: #f6f5f4;
  --surface: #ffffff;
  --ink: #211922;
  --ink-soft: #5f5c63;
  --line: #e2dfdb;
  --accent: #e60023;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.10);
  --radius: 14px;
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#viewport {
  position: fixed;
  inset: 0;
  cursor: grab;
  /* dots follow the world (position/size set from applyView) */
  background-image: radial-gradient(rgba(0, 0, 0, 0.085) 1.1px, transparent 1.1px);
  background-size: 26px 26px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#viewport.panning { cursor: grabbing; }

#world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* ------------------------------------------------------------------ */
/* Pin card                                                            */
/* ------------------------------------------------------------------ */

.pin {
  /* --scale is set per pin (Ctrl+scroll); defaults to 1 */
  position: absolute;
  width: calc(180px * var(--scale, 1));
  cursor: grab;
}
#world.arranging .pin {
  transition: left 0.5s cubic-bezier(0.22, 0.9, 0.36, 1), top 0.5s cubic-bezier(0.22, 0.9, 0.36, 1);
}
.pin:active { cursor: grabbing; }
.pin.selected .pin-media {
  box-shadow: 0 0 0 3px var(--accent), var(--shadow);
}
/* hovered / selected pin always renders above the others */
.pin:hover,
.pin.selected,
.pin:focus-within {
  z-index: 10;
}

/* Level of detail: zoomed out far, per-pin UI is sub-pixel. Hiding it also
   kills hover flicker (z-index jumps) and big shadow repaints across
   hundreds of pins while panning/zooming. The tooltip hides too — see
   positionTip() (it compares against FAR_ZOOM). */
#world.far .pin-scale,
#world.far .pin-badge { display: none; }
#world.far .pin-media { box-shadow: none; }

.pin-media {
  width: calc(180px * var(--scale, 1));
  flex: none;
  border-radius: var(--radius);
  overflow: hidden;
  background: #eee;
  box-shadow: var(--shadow);
  position: relative;
  /* group border (transparent unless the pin belongs to a group) */
  border: 2px solid transparent;
}
.pin.in-group .pin-media { border-color: var(--group-color, transparent); }
.pin-media img,
.pin-media video {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
  background: #f1f0ef;
}
/* scales with the pin so the video keeps its aspect ratio when resized */
.pin-media video { max-height: calc(340px * var(--scale, 1)); }
.pin-media .media-fallback {
  display: none;
  width: 100%;
  height: auto;
}
.pin-media.video-failed .media-fallback { display: block; }
.pin-media.video-failed video { display: none; }

.pin-scale {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  pointer-events: none;
  display: none;
}
.pin-scale:not(:empty) { display: block; }

.pin-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  pointer-events: none;
}

/* Pin tooltip — screen-space overlay (child of #viewport): constant size on
   screen at any zoom, anchored to the hovered/selected pin by positionTip() */
#pin-tip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 15;
  width: 200px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
  box-shadow: var(--shadow);
}
/* invisible bridge from the pin's media edge into the tooltip so the pointer
   never crosses a dead zone (the tooltip would drop mid-move) */
#pin-tip::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12px;
  right: 100%;
}
#pin-tip.tip-flipped::before {
  right: auto;
  left: 100%;
}
.tip-title {
  margin: 0 0 6px;
  font-size: 0.82rem;
  line-height: 1.25;
  font-weight: 650;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tip-meta { font-size: 0.72rem; color: var(--ink-soft); display: grid; gap: 2px; margin-bottom: 8px; }
.tip-meta > div,
.tip-meta > a {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tip-source { color: var(--accent); text-decoration: none; font-weight: 600; }
.tip-source:hover { text-decoration: underline; }
.tip-board, .tip-pinner { color: var(--ink-soft); }

/* group tag inside the tooltip */
.tip-group {
  display: block;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink-soft);
  border: 1px dashed var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 8px;
  max-width: 100%;
  cursor: pointer;
}
.tip-group.has-group {
  border: 1px solid var(--group-color, var(--line));
  color: var(--ink);
  background: color-mix(in srgb, var(--group-color, transparent) 14%, var(--bg));
}

.tip-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.tip-actions button {
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 8px;
  padding: 3px 7px;
  cursor: pointer;
}
.tip-actions button:hover { border-color: var(--accent); color: var(--accent); }
.tip-actions button.danger:hover { background: var(--accent); color: #fff; }
/* two-step delete: the armed button is filled red and says "Sure?" */
.tip-actions button.armed {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ------------------------------------------------------------------ */
/* Toolbar / chrome                                                    */
/* ------------------------------------------------------------------ */

#toolbar {
  position: fixed;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}
#toolbar > * { pointer-events: auto; }
#quad-toggle.on { border-color: var(--accent); color: var(--accent); }

/* ------------------------------------------------------------------ */
/* Quadrant grouping: ⊞ opens a setup panel binding each screen        */
/* quadrant to a group. The divider overlay appears only while a pin   */
/* is being dragged onto the canvas. Quadrants: 0 TL, 1 TR, 2 BL, 3 BR.*/
/* ------------------------------------------------------------------ */

#quad-setup {
  position: fixed;
  top: 54px;
  right: 14px;
  z-index: 14;
  width: 250px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.qs-h {
  margin: 0 0 4px;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
}
.qs-note { margin: 0 0 10px; font-size: 0.72rem; line-height: 1.4; color: var(--ink-soft); }
.qs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 7px;
}
.qs-row:last-child { margin-bottom: 0; }
.quad-select {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 7px;
  padding: 3px 5px;
  max-width: 130px;
  cursor: pointer;
}
.quad-select.has-group {
  border-color: var(--group-color, var(--line));
  background: color-mix(in srgb, var(--group-color, transparent) 14%, var(--bg));
}

/* above the sidebar/toolbar so the quadrants read clearly during a drag
   (pointer-events: none, so it never blocks the drop itself) */
#quad-guide { position: fixed; inset: 0; z-index: 13; pointer-events: none; }
.quad-cell {
  position: absolute;
  width: 50%;
  height: 50%;
  background: var(--quad-bg, rgba(33, 25, 34, 0.15));
  transition: background 0.15s ease;
}
.quad-cell[data-quad="0"] { top: 0; left: 0; border-right: 3px dashed var(--quad-line, rgba(33, 25, 34, 0.6)); border-bottom: 3px dashed var(--quad-line, rgba(33, 25, 34, 0.6)); }
.quad-cell[data-quad="1"] { top: 0; right: 0; border-left: 3px dashed var(--quad-line, rgba(33, 25, 34, 0.6)); border-bottom: 3px dashed var(--quad-line, rgba(33, 25, 34, 0.6)); }
.quad-cell[data-quad="2"] { bottom: 0; left: 0; border-right: 3px dashed var(--quad-line, rgba(33, 25, 34, 0.6)); border-top: 3px dashed var(--quad-line, rgba(33, 25, 34, 0.6)); }
.quad-cell[data-quad="3"] { bottom: 0; right: 0; border-left: 3px dashed var(--quad-line, rgba(33, 25, 34, 0.6)); border-top: 3px dashed var(--quad-line, rgba(33, 25, 34, 0.6)); }
.quad-cell.active { background: rgba(230, 0, 35, 0.18); }
/* group-name chip at each quadrant's center (only shown when bound) */
.quad-tag {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  max-width: 70%;
  padding: 10px 18px;
  background: var(--surface);
  border: 2px solid var(--group-color, var(--line));
  border-radius: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.quad-cell.bound .quad-tag { display: block; }
.quad-group {
  max-width: 220px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* ------------------------------------------------------------------ */
/* Floating sidebar                                                    */
/* ------------------------------------------------------------------ */

#sidebar {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 276px;
  max-height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 12;
  overflow: hidden;
}
#sidebar.collapsed { display: none; }

.sb-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.sb-head .brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.82rem;
  margin-right: auto;
}
.sb-head .pill { font-size: 0.66rem; padding: 4px 9px; }

.sb-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.sb-h {
  margin: 0 0 8px;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
}
.sb-h-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.sb-h-row .sb-h { margin: 0; }

.arrange-row { display: flex; gap: 6px; }
.arrange-btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 650;
  padding: 6px 4px;
  border-radius: 9px;
  cursor: pointer;
}
.arrange-btn:hover { border-color: var(--accent); color: var(--accent); }

.mini-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 6px;
}
.mini-btn:hover { background: rgba(230, 0, 35, 0.08); }

/* groups */
.group-list { display: grid; gap: 3px; max-height: 150px; overflow-y: auto; }
.sb-empty { font-size: 0.72rem; color: var(--ink-soft); padding: 2px 6px; }
.group-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 9px; }
.group-row:hover { background: var(--bg); }
.group-swatch {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  flex: none;
  position: relative;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.group-swatch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.group-name {
  flex: 1;
  min-width: 0;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.group-name-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 2px 6px;
  outline: none;
}
.group-count { font-size: 0.68rem; font-weight: 600; color: var(--ink-soft); }
.group-del {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.72rem;
  padding: 2px 5px;
  border-radius: 6px;
}
.group-del:hover { color: var(--accent); background: rgba(230, 0, 35, 0.08); }

/* pin list */
.sb-section-pins { flex: 1; min-height: 0; display: flex; flex-direction: column; border-bottom: none; }
.sort-select {
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 7px;
  padding: 3px 4px;
  max-width: 122px;
  cursor: pointer;
}
.pin-list { flex: 1; min-height: 40px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; padding: 0 6px; }
.pin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 9px;
  cursor: pointer;
}
.pin-row:hover { background: var(--bg); }
.pin-row.active { background: rgba(230, 0, 35, 0.07); }
.pin-row-thumb {
  width: 26px;
  height: 26px;
  object-fit: cover;
  border-radius: 7px;
  flex: none;
  background: #eee;
}
.pin-row-title {
  flex: 1;
  min-width: 0;
  font-size: 0.74rem;
  font-weight: 560;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pin-row-group {
  font: inherit;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  padding: 2px 2px;
  max-width: 78px;
  flex: none;
  cursor: pointer;
}

/* collapsed rail */
#sb-rail {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 12;
  width: 40px;
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink-soft);
}
#sb-rail:hover { border-color: var(--accent); }
.rail-chevron { font-size: 1rem; color: var(--ink); line-height: 1; }
.pill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  box-shadow: var(--shadow);
}
.spacer { flex: 1; }
.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn:disabled:hover { border-color: var(--line); color: var(--ink); }
.tb-sep {
  width: 1px;
  height: 18px;
  background: var(--line);
}
.pill-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.pill-btn:hover { border-color: var(--accent); color: var(--accent); }
.dot-pill { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c9c5c1; display: inline-block; }
.dot.ok { background: #16a34a; }
.dot.bad { background: var(--accent); }

/* Empty state */
#empty-state {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  z-index: 5;
  pointer-events: none;
  color: var(--ink-soft);
  padding: 0 24px;
}
#empty-state h1 { color: var(--ink); margin: 0; font-size: 1.5rem; }
#empty-state p { margin: 0; line-height: 1.55; max-width: 420px; }
#empty-state strong { color: var(--ink); }

/* Toast */
#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 999px;
  z-index: 50; /* above the GIF popover veil */
  box-shadow: var(--shadow);
  max-width: 80vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#toast.show { animation: toast-in 2.6s ease forwards; }
/* action button inside a toast (e.g. "Pin removed — Undo") */
.toast-action {
  font: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: transparent;
  color: #fff;
  border-radius: 999px;
  padding: 3px 11px;
  cursor: pointer;
  flex-shrink: 0;
}
.toast-action:hover { background: rgba(255, 255, 255, 0.16); }
/* toasts carrying an action button (e.g. "Pin removed — Undo") stay ~5s */
#toast.with-action.show { animation: toast-in-action 5.2s ease forwards; }
@keyframes toast-in-action {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  4%, 86% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 10px); }
}
@keyframes toast-in {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  8%, 82% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 10px); }
}

.hidden { display: none !important; }

/* Pin entrance animation */
@keyframes pin-drop {
  0% { opacity: 0; transform: scale(0.6) translateY(-14px); }
  60% { opacity: 1; transform: scale(1.04) translateY(2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.pin.drop-in .pin-media { animation: pin-drop 0.3s ease; }

/* ------------------------------------------------------------------ */
/* Focus mode ("open bigger")                                          */
/* ------------------------------------------------------------------ */

/* dim everything except the focused pin */
#world.focusing .pin { transition: opacity 0.25s ease; }
#world.focusing .pin:not(.focused) { opacity: 0.12; pointer-events: none; }
#world.focusing .pin.focused { z-index: 12; }
/* pins just pinned from the related panel stay visible over the blur */
#world.focusing .pin.rel-keep { opacity: 1; z-index: 3; }

/* blurred dark veil over the viewport (sized in world px, tracks the view) */
#focus-backdrop {
  position: absolute;
  z-index: 1;
  display: none;
  background: rgba(12, 9, 14, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#world.focusing #focus-backdrop { display: block; }
.pin.focused .pin-media { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }

/* dark backdrop + dim the chrome while focused */
#viewport { transition: background-color 0.35s ease; }
body.focus-mode #viewport { background-color: #1b151c; }
#sidebar, #sb-rail, #toolbar { transition: opacity 0.35s ease; }
body.focus-mode #sidebar,
body.focus-mode #sb-rail,
body.focus-mode #toolbar { opacity: 0; pointer-events: none; }

.focus-exit {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.focus-exit:hover { border-color: var(--accent); color: var(--accent); }
.focus-exit .kbd {
  font-size: 0.66rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--ink-soft);
}

/* Focus overlays: screen-space cards (children of #viewport) positioned in
   JS around the focused pin. Wide: info card beside the pin, the related
   section inside it. Narrow: info card on top, related container under the
   pin. The masonry is CSS multi-column; the cards scroll. */
.focus-card {
  position: fixed;
  z-index: 25;
  background: rgba(26, 21, 29, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  transition: opacity 0.25s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}
.focus-card.ready { opacity: 1; }
.focus-card::-webkit-scrollbar { width: 8px; }
.focus-card::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); border-radius: 4px; }

/* pin info header inside the card */
.fc-head { padding: 13px 15px 8px; }
.fc-title { margin: 0 0 7px; font-size: 15px; line-height: 1.3; font-weight: 700; }
.fc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 7px;
  row-gap: 1px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.55;
}
.fc-meta a { color: #ff7a90; text-decoration: none; font-weight: 600; }
.fc-meta a:hover { text-decoration: underline; }
.fc-meta .sep { color: rgba(255, 255, 255, 0.3); }
.fc-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 3px 15px 13px; }
.fc-actions button,
.fc-actions .fc-group {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  padding: 4px 9px;
  cursor: pointer;
}
.fc-actions button:hover { border-color: rgba(255, 255, 255, 0.45); color: #fff; }
.fc-actions button.danger:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.fc-actions button.armed {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  animation: armed-pulse 1.1s ease-in-out infinite;
}
@keyframes armed-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}
.fc-actions .fc-group { max-width: 100%; }
.fc-actions .fc-group.has-group {
  border-color: var(--group-color, rgba(255, 255, 255, 0.4));
  background: color-mix(in srgb, var(--group-color, transparent) 22%, rgba(255, 255, 255, 0.05));
}
.fc-actions .danger { margin-left: auto; }
.fc-div { height: 1px; background: rgba(255, 255, 255, 0.09); margin: 2px 15px; }

/* related section (inside the card on wide screens, in the container
   under the pin on narrow screens) */
.rel-sec { padding: 10px 14px 14px; }
.rel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}
.rel-h { font-size: 13px; font-weight: 700; color: #fff; }
.rel-hint { font-size: 11px; color: rgba(255, 255, 255, 0.72); }
.rel-note,
.rel-loading {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.5;
  padding: 12px 2px;
}

/* masonry: CSS multi-column — cards flow and the grid reflows itself as
   images load */
.rel-grid { column-width: 130px; column-gap: 10px; }
.rel-grid.two-col { columns: 2; }
.rel-card {
  display: inline-block;
  width: 100%;
  position: relative;
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  margin: 0 0 10px;
  border-radius: 0.65em;
  overflow: hidden;
  background: #eee;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.rel-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 12px 28px rgba(0, 0, 0, 0.20);
}
.rel-card img { display: block; width: 100%; height: auto; }
.rel-card-ov {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1.4em 0.55em 0.55em;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 0;
  transition: opacity 0.15s ease;
}
.rel-card:hover .rel-card-ov { opacity: 1; }
.rel-card-title {
  color: #fff;
  font-size: 0.72em;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rel-pin-btn {
  margin-top: 0.45em;
  width: 100%;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.72em;
  font-weight: 700;
  padding: 0.4em 0;
  cursor: pointer;
}
.rel-pin-btn:hover { filter: brightness(1.1); }
.rel-chip {
  position: absolute;
  top: 0.45em;
  left: 0.45em;
  display: none;
  background: #16a34a;
  color: #fff;
  font-size: 0.6em;
  font-weight: 700;
  padding: 0.25em 0.65em;
  border-radius: 999px;
}
.rel-card.pinned .rel-chip { display: block; }
.rel-card.pinned .rel-pin-btn { background: #fff; color: #16a34a; }
.rel-card.adding { opacity: 0.6; pointer-events: none; }
.rel-video {
  position: absolute;
  top: 0.45em;
  right: 0.45em;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.6em;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.25em 0.6em;
  border-radius: 999px;
}

/* detail view (replaces the masonry grid inside the related section) */
.rel-detail {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 0.8em;
  color: #fff;
  padding: 0.6em 0.8em 0.8em;
}
.rel-back {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font: inherit;
  font-size: 0.75em;
  font-weight: 650;
  cursor: pointer;
  padding: 0.2em 0.5em;
  margin-left: -0.5em;
  border-radius: 6px;
}
.rel-back:hover { color: var(--accent); background: rgba(230, 0, 35, 0.06); }
.rel-detail img {
  display: block;
  width: 100%;
  max-height: 15em;
  object-fit: cover;
  border-radius: 0.5em;
  margin: 0.3em 0 0.55em;
  background: #eee;
}
.rel-d-title { margin: 0 0 0.4em; font-size: 1.05em; line-height: 1.3; }
.rel-d-desc {
  margin: 0 0 0.5em;
  font-size: 0.8em;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.45;
  white-space: pre-line;
  max-height: 7em;
  overflow-y: auto;
}
.rel-d-meta { font-size: 0.72em; color: rgba(255, 255, 255, 0.72); margin-bottom: 0.7em; }
.rel-d-meta a { color: var(--accent); text-decoration: none; font-weight: 600; }
.rel-d-actions { display: flex; align-items: center; gap: 0.6em; }
.rel-d-pin {
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.82em;
  font-weight: 700;
  padding: 0.55em 1.1em;
  cursor: pointer;
}
.rel-d-pin:hover { filter: brightness(1.1); }
.rel-d-pin.pinned { background: #e8f5ec; color: #16a34a; }
.rel-d-open { font-size: 0.78em; font-weight: 650; color: rgba(255, 255, 255, 0.8); text-decoration: none; }
.rel-d-open:hover { color: var(--accent); }

/* ------------------------------------------------------------------ */
/* GIF export: preview popover + busy state on the small action buttons */
/* ------------------------------------------------------------------ */

.tip-actions button.busy,
.fc-actions button.busy {
  opacity: 0.45;
  pointer-events: none;
}

.gif-pop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(33, 25, 34, 0.38);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: gif-pop-in 0.16s ease;
  padding: 24px;
}
@keyframes gif-pop-in { from { opacity: 0; } to { opacity: 1; } }

.gif-card {
  width: min(440px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: gif-card-in 0.18s ease;
}
@keyframes gif-card-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.gif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.gif-title {
  font-weight: 650;
  font-size: 0.85rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gif-close {
  font: inherit;
  font-size: 0.72rem;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.gif-close:hover { border-color: var(--accent); color: var(--accent); }

/* checkerboard backdrop so transparent GIFs read clearly */
.gif-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  padding: 14px;
  background-color: #f0eeeb;
  background-image: conic-gradient(#e7e4e0 25%, #f4f2ef 0 50%, #e7e4e0 0 75%, #f4f2ef 0);
  background-size: 16px 16px;
}
.gif-img {
  max-width: 100%;
  max-height: 52vh;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
}
.gif-loading {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
  padding: 26px 12px;
  line-height: 1.5;
}
.gif-loading.error { color: var(--accent); }

.gif-stats {
  padding: 9px 14px 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.gif-actions {
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
}
.gif-actions button,
.gif-actions a {
  flex: 1;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
.gif-actions button:hover:not(:disabled),
.gif-actions a:hover { border-color: var(--accent); color: var(--accent); }
.gif-actions button:disabled { opacity: 0.45; pointer-events: none; }

/* ------------------------------------------------------------------ */
/* Dark theme — flips the palette. No explicit choice: board light,     */
/* gallery dark (applyTheme).                                          */
/* ------------------------------------------------------------------ */

body.dark {
  --bg: #131014;
  --surface: #1e1a20;
  --ink: #f1eef2;
  --ink-soft: #a29da6;
  --line: #342e37;
  --quad-bg: rgba(255, 255, 255, 0.08);
  --quad-line: rgba(255, 255, 255, 0.45);
}
body.dark #viewport {
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1.1px, transparent 1.1px);
}

/* ------------------------------------------------------------------ */
/* Gallery view (▦): scrollable masonry grid + filter chips            */
/* ------------------------------------------------------------------ */

#gallery {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}
.g-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.g-title {
  font-weight: 750;
  font-size: 0.95rem;
  margin-right: 4px;
  white-space: nowrap;
}
.g-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.g-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
.g-chip i { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.g-chip-n { color: var(--ink-soft); font-weight: 500; }
.g-chip:hover { border-color: var(--accent); }
.g-chip.active { border-color: var(--accent); color: var(--accent); }
.g-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  grid-auto-rows: 8px;
  column-gap: 14px;
}
.g-tile {
  position: relative;
  grid-row-end: span 30; /* placeholder until the image measures (sizeTile) */
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  cursor: zoom-in;
}
.g-tile img { display: block; width: 100%; }
.g-tile:hover { outline: 2px solid var(--accent); }
.g-tile.in-group { outline: 3px solid var(--group-color); }
.g-vid {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
}
.g-empty {
  color: var(--ink-soft);
  padding: 48px 12px;
  text-align: center;
}

/* ------------------------------------------------------------------ */
/* Lightbox: full-page pin view + carousel + actions (always dark)     */
/* ------------------------------------------------------------------ */

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: #0e0b0f;
  color: #f1eef2;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lb-top {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  flex: 0 0 auto;
}
.lb-title {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-src {
  color: #9b95a0;
  font-size: 0.78rem;
  text-decoration: none;
  white-space: nowrap;
}
.lb-src:hover { color: var(--accent); }
#lb-close {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
  color: #fff;
}
.lb-stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 70px;
}
.lb-stage img,
.lb-stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.lb-arrow {
  position: absolute;
  top: 45%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.lb-arrow:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.lb-arrow:disabled { opacity: 0.25; cursor: default; }
#lb-prev { left: 14px; }
#lb-next { right: 14px; }
.lb-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  padding: 12px 10px 4px;
  flex: 0 0 auto;
}
.lb-actions button {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  color: #e9e6ea;
  border-radius: 999px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
  padding: 0.45em 1em;
  cursor: pointer;
}
.lb-actions button:hover { border-color: rgba(255, 255, 255, 0.5); color: #fff; }
.lb-actions button.danger:hover,
.lb-actions button.armed { background: var(--accent); border-color: var(--accent); color: #fff; }
.lb-actions button.busy { opacity: 0.45; pointer-events: none; }
/* group buttons: the ⊞ quadrant bindings, tinted with the group color */
.lb-actions button.lb-group { border-color: var(--group-color); }
.lb-actions button.lb-group kbd {
  font: inherit;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 5px;
  padding: 1px 6px;
  margin-right: 3px;
}
.lb-actions button.lb-group.active {
  background: var(--group-color);
  color: #fff;
}
.lb-actions button.lb-group.active kbd { background: rgba(0, 0, 0, 0.25); }
/* the pin's group color frames the full-view media */
.lb-stage .in-group { outline: 3px solid var(--group-color); outline-offset: 6px; }
.lb-strip {
  width: min(80vw, 1100px);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 4px 18px;
  flex: 0 0 auto;
  scrollbar-width: thin;
}
.lb-thumb {
  flex: 0 0 auto;
  width: 100px;
  height: 66px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 7px;
  overflow: hidden;
  background: none;
  cursor: pointer;
  opacity: 0.5;
}
.lb-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lb-thumb:hover { opacity: 0.9; }
.lb-thumb.current { border-color: var(--accent); opacity: 1; }

/* ------------------------------------------------------------------ */
/* Auth screen (login / create account)                                 */
/* ------------------------------------------------------------------ */

#auth {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
#auth.hidden { display: none; }
.auth-card {
  width: min(340px, calc(100vw - 40px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.auth-card h1 { margin: 0; font-size: 1.3rem; }
.auth-sub { margin: 0; color: var(--ink-soft); font-size: 0.85rem; }
#auth-form { display: flex; flex-direction: column; gap: 10px; width: 100%; }
#auth-form input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
#auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.auth-submit {
  font: inherit;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px;
  cursor: pointer;
}
.auth-submit:hover { background: #c0081f; }
.auth-submit:disabled { opacity: 0.6; cursor: default; }
.auth-error { min-height: 1.1em; margin: 0; color: var(--accent); font-size: 0.82rem; font-weight: 600; }
.auth-switch {
  font: inherit;
  font-size: 0.82rem;
  background: none;
  border: none;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}
.auth-switch:hover { color: var(--accent); }

/* ------------------------------------------------------------------ */
/* Canvases + account section (sidebar)                                 */
/* ------------------------------------------------------------------ */

.who {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.canvas-row { display: flex; align-items: center; gap: 4px; }
.canvas-select {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 5px 6px;
  cursor: pointer;
}
.account-row { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.account-row .mini-btn { flex: 1; }
