/* ============================================================================
   Canvas content: cards (and, in later phases, sections / strokes / notes)
   rendered inside .canvas-world in world coordinates.
   ========================================================================== */

/* ============================================================================
   WORLD ITEMS: positioning contract
   ---------------------------------------------------------------------------
   Every item placed in world coordinates (.canvas-card and its view/highlight
   variants, .canvas-stroke, .canvas-note, .canvas-textbox, .canvas-section,
   .canvas-link__* and .marquee) has `left: 0; top: 0` pinned here and is moved
   by the CSS `translate` property from JS (canvas/domPos.js).

   Why: `left`/`top` are layout properties, so dragging N items wrote 2N
   layout-invalidating values per pointermove. `translate` is a transform — the
   compositor moves the layer and no layout runs.

   Why the individual `translate` property rather than `transform: translate()`:
   CSS Transforms L2 applies `translate`, then `rotate`, then `scale`, then
   `transform`. Several of these items already use `transform: scale()` (cards)
   or `rotate` (strokes), and the link label/tools use `transform` for their
   -50% centering. Keeping the world offset in `translate` reproduces the old
   `left`/`top` geometry exactly: the offset is applied in untransformed space,
   and rotation/scaling still happen about `transform-origin`.

   The `left: 0; top: 0` is load-bearing, not decorative: with auto offsets,
   `position: absolute` falls back to each item's static (in-flow) position, so
   siblings would stack down the page instead of overlaying at the origin.
   ========================================================================== */

/* ---- layers ---------------------------------------------------------------- */

.canvas-sections,
.canvas-strokes,
.canvas-cards,
.canvas-views,
.canvas-highlights,
.canvas-apps,
.canvas-textboxes,
.canvas-notes,
.canvas-connectors,
.canvas-links,
.canvas-link-labels {
  position: absolute;
  top: 0;
  left: 0;
}

/* each layer is its own stacking context so per-element z values can never
   lift a section above cards ("sections always below" comes from layer order) */
.canvas-sections {
  z-index: 0;
}

.canvas-strokes {
  z-index: 1;
}

.canvas-cards {
  z-index: 2;
}

.canvas-views {
  z-index: 2;
}

.canvas-highlights {
  z-index: 2;
}

.canvas-apps {
  z-index: 2;
}

.canvas-textboxes {
  z-index: 3;
}

.canvas-notes {
  z-index: 4;
}

.canvas-connectors {
  z-index: 5;
}

.canvas-links {
  z-index: 6;
}

.canvas-link-labels {
  z-index: 7;
}

/* draw mode: every pointer belongs to stroke capture on the canvas layer */
.canvas-layer.is-tool-stroke .canvas-sections,
.canvas-layer.is-tool-stroke .canvas-strokes,
.canvas-layer.is-tool-stroke .canvas-cards,
.canvas-layer.is-tool-stroke .canvas-views,
.canvas-layer.is-tool-stroke .canvas-highlights,
.canvas-layer.is-tool-stroke .canvas-apps,
.canvas-layer.is-tool-stroke .canvas-textboxes,
.canvas-layer.is-tool-stroke .canvas-notes,
.canvas-layer.is-tool-stroke .canvas-connectors,
.canvas-layer.is-tool-stroke .canvas-links,
.canvas-layer.is-tool-stroke .canvas-link-labels {
  pointer-events: none;
}

/* ---- sections (bottom layer; grid containers for other elements) -------------- */

.canvas-section {
  --section-c: #8a867d;
  position: absolute;
  /* origin pinned; world position comes from `translate` (see WORLD ITEMS note) */
  left: 0;
  top: 0;
  /* the body is transparent to pointer events so marquee/pan work through it;
     the header and resize handles opt back in */
  pointer-events: none;
  background: color-mix(in srgb, var(--section-c) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--section-c) 40%, transparent);
  border-radius: var(--radius-md);
  overflow: visible;
}

.canvas-section.is-selected {
  box-shadow: 0 0 0 1.5px var(--color-ink);
}

.canvas-section.is-ghost {
  border-style: dashed;
}

.canvas-section.is-drop-target {
  border-color: color-mix(in srgb, var(--section-c) 70%, var(--color-ink));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--section-c) 35%, transparent);
}

/* Grid lines: hidden at rest, subtle when selected, clearer while dropping */
.canvas-section__grid {
  position: absolute;
  inset: 46px 0 0 0;
  display: grid;
  grid-template-columns: var(--sg-cols, 160px 160px);
  grid-template-rows: var(--sg-rows, 120px 120px);
  gap: var(--sg-gap, 12px);
  padding: var(--sg-pad, 12px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease;
}

.canvas-section.is-selected .canvas-section__grid {
  opacity: 0.4;
}

.canvas-section.is-drop-target .canvas-section__grid {
  opacity: 0.85;
}

.canvas-section__cell {
  border: 1px dashed color-mix(in srgb, var(--section-c) 45%, transparent);
  border-radius: 4px;
  box-sizing: border-box;
}

.canvas-section__drop-preview {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  border-radius: 4px;
  box-sizing: border-box;
}

.canvas-section__drop-preview.is-cell {
  background: color-mix(in srgb, var(--section-c) 22%, transparent);
  border: 1.5px solid color-mix(in srgb, var(--section-c) 65%, var(--color-ink));
}

.canvas-section__drop-preview.is-insert-col,
.canvas-section__drop-preview.is-insert-row {
  background: color-mix(in srgb, var(--section-c) 80%, var(--color-ink));
  border-radius: 1px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--color-bg) 40%, transparent);
}

.canvas-section__header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 46px;
  padding: 0 var(--space-2) 0 var(--space-3);
  pointer-events: auto;
  background: color-mix(in srgb, var(--section-c) 14%, transparent);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.canvas-section.is-dragging .canvas-section__header {
  cursor: grabbing;
}

.canvas-section__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--color-ink-secondary);
}

.canvas-section__header .inline-name {
  flex: 1;
  min-width: 0;
  height: 38px;
  font-size: var(--text-xl);
}

.canvas-section__handle {
  position: absolute;
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: var(--radius-round);
  background: var(--color-ink);
  border: 2px solid var(--color-bg);
  pointer-events: auto;
  display: none;
  touch-action: none;
}

.canvas-section.is-selected:not(.is-ghost) .canvas-section__handle {
  display: block;
}

.canvas-section__handle[data-dir="nw"] {
  top: -7px;
  left: -7px;
  cursor: nwse-resize;
}

.canvas-section__handle[data-dir="ne"] {
  top: -7px;
  right: -7px;
  cursor: nesw-resize;
}

.canvas-section__handle[data-dir="sw"] {
  bottom: -7px;
  left: -7px;
  cursor: nesw-resize;
}

.canvas-section__handle[data-dir="se"] {
  bottom: -7px;
  right: -7px;
  cursor: nwse-resize;
}

/* section color swatch popover */

.popover--section-colors .section-colors {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2);
  max-width: 180px;
}

.section-colors__swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-round);
  background: var(--swatch-c);
  cursor: pointer;
}

.section-colors__swatch.is-active {
  border-color: var(--color-ink);
}

/* ---- cards on canvas --------------------------------------------------------- */

.canvas-card {
  position: absolute;
  /* origin pinned; world position comes from `translate` (see WORLD ITEMS note) */
  left: 0;
  top: 0;
  transform-origin: 0 0;
  padding: var(--space-3);
  background: var(--color-surface);
  border: var(--border-hairline);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.canvas-card:focus-visible {
  outline: none; /* selection ring below is the affordance */
}

.canvas-card.is-dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-3);
}

.canvas-card.is-selected {
  border-color: var(--color-border-strong);
  box-shadow: 0 0 0 1.5px var(--color-ink), var(--shadow-2);
}

/* fixed-height placements (h > 0) clip here, so the outside toolbar and the
   corner handle stay visible */
.canvas-card__body {
  height: 100%;
  overflow: hidden;
}

/* Soft max height for tall natural-height text cards (session expand/collapse). */
.canvas-card.is-height-clamped {
  height: 360px;
}

.canvas-card.is-height-clamped .canvas-card__body {
  height: 100%;
  overflow: hidden;
}

/* Bottom fade + Expand / Collapse control (session-local; does not write h). */
.canvas-card__expand {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: var(--space-1);
  height: 2.75rem;
  padding: 0 0 var(--space-2);
  border: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: linear-gradient(to top, var(--color-surface) 35%, transparent);
  color: var(--color-ink-faint);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  touch-action: manipulation;
}

.canvas-card__expand[hidden] {
  display: none;
}

.canvas-card__expand:hover,
.canvas-card__expand:focus-visible {
  color: var(--color-ink);
}

.canvas-card__expand:focus-visible {
  outline: none;
}

.canvas-card__expand svg {
  flex-shrink: 0;
}

/* Expanded: compact control, no fade (full content is already visible). */
.canvas-card.is-height-expanded .canvas-card__expand {
  position: relative;
  height: auto;
  margin-top: var(--space-2);
  padding: var(--space-1) 0 0;
  background: none;
  border-top: var(--border-hairline);
  border-radius: 0;
}

.canvas-card__title {
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-1);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  overflow-wrap: break-word;
}

.canvas-card__title.is-untitled {
  color: var(--color-ink-faint);
  font-weight: var(--weight-regular);
}

/* A placement whose card/highlight became unreadable -- almost always a revoked
   share. The row survives (revoke fires no FK cascade), so the tile has to say so
   and offer its Remove button rather than rendering blank. */
.canvas-card--unavailable {
  border-style: dashed;
  background: var(--color-surface-sunken, var(--color-surface));
}

.canvas-card__unavailable {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2);
  color: var(--color-ink-faint);
}

.canvas-card__unavailable p {
  margin: 0;
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
}

.canvas-card .card-grid {
  --card-row-min: 44px; /* slightly denser than the board's detail view */
}

/* Board document layout uses 60vh min-heights for the detail pane; on canvas
   those make every note tile huge before any real content. */
.canvas-card .card-grid--document > .card-cell,
.canvas-card .card-grid--document .cell-editor__shell-preview {
  min-height: 0;
}

/* annotatable text stays selectable in view mode (highlight-to-comment);
   the drag handler skips these targets */
.canvas-card .card-cell__value--annotated,
.canvas-card .card-cell__value--annot-wrap {
  user-select: text;
  -webkit-user-select: text;
}

.canvas-card video.asset-media {
  max-height: none; /* the placement, not the viewport, bounds the player */
}

/* mini toolbar: floats beside the item's top-right edge, expands downward
   on hover/focus/selection */

.canvas-card__toolbar,
.canvas-item__toolbar {
  position: absolute;
  top: 0;
  left: calc(100% + var(--space-2));
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: 2px;
  background: var(--color-surface);
  border: var(--border-hairline);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-1);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-fast) var(--ease), visibility var(--dur-fast) var(--ease);
  z-index: 2;
  pointer-events: auto;
}

.canvas-card__toolbar .icon-btn,
.canvas-item__toolbar .icon-btn {
  width: 24px;
  height: 24px;
}

.canvas-item__toolbar-sep {
  display: block;
  width: 16px;
  height: 1px;
  margin: 2px auto;
  background: color-mix(in srgb, var(--color-ink) 12%, transparent);
}

.canvas-color-btn {
  position: relative;
}

.canvas-color-btn--fill::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: var(--radius-round);
  background: var(--swatch-c, var(--color-surface));
  border: 1px solid color-mix(in srgb, var(--color-ink) 35%, transparent);
}

.canvas-color-btn--text {
  font-size: 12px;
  font-weight: var(--weight-semibold);
  line-height: 1;
  color: var(--text-c, var(--color-ink));
}

.canvas-color-btn__a {
  display: block;
  border-bottom: 2px solid currentColor;
  line-height: 1.1;
  padding-bottom: 1px;
}

.section-colors__swatch--text {
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: var(--weight-semibold);
  color: var(--swatch-c);
  background: var(--color-surface-raised, var(--color-surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-ink) 18%, transparent);
}

.section-colors__swatch--text span {
  border-bottom: 2px solid currentColor;
  line-height: 1.1;
}

.canvas-card:hover .canvas-card__toolbar,
.canvas-card:focus-within .canvas-card__toolbar,
.canvas-card.is-selected .canvas-card__toolbar,
.canvas-note:hover .canvas-item__toolbar,
.canvas-note:focus-within .canvas-item__toolbar,
.canvas-note.is-selected .canvas-item__toolbar,
.canvas-textbox:hover .canvas-item__toolbar,
.canvas-textbox:focus-within .canvas-item__toolbar,
.canvas-textbox.is-selected .canvas-item__toolbar,
.canvas-section:hover .canvas-item__toolbar,
.canvas-section:focus-within .canvas-item__toolbar,
.canvas-section.is-selected .canvas-item__toolbar,
.canvas-stroke:hover .canvas-item__toolbar,
.canvas-stroke:focus-within .canvas-item__toolbar,
.canvas-stroke.is-selected .canvas-item__toolbar {
  opacity: 1;
  visibility: visible;
}

.canvas-card.is-dragging .canvas-card__toolbar,
.canvas-note.is-editing .canvas-item__toolbar,
.canvas-note.is-dragging .canvas-item__toolbar,
.canvas-textbox.is-editing .canvas-item__toolbar,
.canvas-textbox.is-dragging .canvas-item__toolbar,
.canvas-section.is-dragging .canvas-item__toolbar,
.canvas-stroke.is-dragging .canvas-item__toolbar {
  opacity: 0;
  visibility: hidden;
}

.canvas-card.is-dragging .canvas-card__expand {
  pointer-events: none;
}

/* resize handle: bottom-right dot, drag = uniform scale */

.canvas-card__handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-round);
  background: var(--color-ink);
  border: 2px solid var(--color-bg);
  cursor: nwse-resize;
  display: none;
  touch-action: none;
}

/* only for a sole selection — group resize isn't a thing */
.canvas-card.is-selected.is-solo .canvas-card__handle {
  display: block;
}

/* views + highlights + apps reuse .canvas-card chrome */
.canvas-view:hover .canvas-card__toolbar,
.canvas-view:focus-within .canvas-card__toolbar,
.canvas-view.is-selected .canvas-card__toolbar,
.canvas-highlight:hover .canvas-card__toolbar,
.canvas-highlight:focus-within .canvas-card__toolbar,
.canvas-highlight.is-selected .canvas-card__toolbar,
.canvas-app:hover .canvas-card__toolbar,
.canvas-app:focus-within .canvas-card__toolbar,
.canvas-app.is-selected .canvas-card__toolbar {
  opacity: 1;
  visibility: visible;
}

.canvas-view.is-dragging .canvas-card__toolbar,
.canvas-highlight.is-dragging .canvas-card__toolbar,
.canvas-app.is-dragging .canvas-card__toolbar {
  opacity: 0;
  visibility: hidden;
}

.canvas-view.is-selected.is-solo .canvas-card__handle,
.canvas-highlight.is-selected.is-solo .canvas-card__handle,
.canvas-app.is-selected.is-solo .canvas-card__handle {
  display: block;
}

.canvas-view .view-grid {
  pointer-events: none; /* board interactions stay on the board; canvas is display */
}

/* ---- apps (live sandboxed frames; docs/apps-plan.md P5) ------------------------ */

.canvas-app__body {
  display: flex;
  flex-direction: column;
}

.canvas-app__title {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-shrink: 0;
}

.canvas-app__meta {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  color: var(--color-ink-faint);
  white-space: nowrap;
}

.canvas-app__window {
  flex: 1;
  min-height: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
}

.canvas-app__frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  /* display-only by default: the tile drags like any placement; the toolbar's
     interact toggle flips the frame live for the session */
  pointer-events: none;
}

.canvas-app.is-interactive .canvas-app__frame {
  pointer-events: auto;
}

.canvas-app.is-interactive .canvas-card__toolbar [data-interact] {
  color: var(--color-ink);
  background: var(--color-surface-sunken, var(--color-bg));
}

.canvas-highlight__comment {
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-1);
  font-size: var(--text-sm);
  color: var(--color-ink-secondary);
  line-height: var(--leading-normal);
}

.canvas-highlight__preview {
  width: 100%;
  min-height: 80px;
}

.canvas-highlight__preview .hl-tile__preview {
  display: block;
  width: 100%;
}

/* ---- strokes (freehand drawing; one svg per stroke) ---------------------------- */

.canvas-stroke {
  position: absolute;
  /* origin pinned; world position comes from `translate` (see WORLD ITEMS note) */
  left: 0;
  top: 0;
  cursor: grab;
  touch-action: none;
  border-radius: 2px;
}

.canvas-stroke svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none; /* the div's bbox is the hit target */
}

.canvas-stroke.is-dragging {
  cursor: grabbing;
}

.canvas-stroke.is-selected {
  box-shadow: 0 0 0 1.5px var(--color-ink);
}

/* live preview while drawing: world-space svg, path in world coords */
.canvas-stroke-preview {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

/* resize handle: bottom-right dot, drag = uniform scale (like cards) */
.canvas-stroke__handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: var(--radius-round);
  background: var(--color-ink);
  border: 2px solid var(--color-bg);
  cursor: nwse-resize;
  display: none;
  touch-action: none;
}

.canvas-stroke.is-selected.is-solo .canvas-stroke__handle {
  display: block;
}

/* rotate handle: dot floating above the top edge, drag = rotate about center */
.canvas-stroke__rotate {
  position: absolute;
  top: -26px;
  left: calc(50% - 7px);
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: var(--radius-round);
  background: var(--color-surface);
  border: 2px solid var(--color-ink);
  cursor: grab;
  display: none;
  touch-action: none;
}

/* tether between the handle and the stroke's top edge */
.canvas-stroke__rotate::after {
  content: "";
  position: absolute;
  left: calc(50% - 0.5px);
  top: 100%;
  width: 1px;
  height: 10px;
  background: var(--color-ink);
}

.canvas-stroke.is-selected.is-solo .canvas-stroke__rotate {
  display: block;
}

/* draw config popover (color / size / pressure) */

.popover--draw .draw-config {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

.draw-config__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.draw-config__sizes {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.draw-config__size {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--radius-round);
  background: none;
  cursor: pointer;
}

.draw-config__size:hover {
  background: var(--color-hover);
}

.draw-config__size.is-active {
  background: var(--color-active);
}

.draw-config__size i {
  width: var(--dot);
  height: var(--dot);
  border-radius: var(--radius-round);
  background: var(--color-ink);
}

.draw-config__pressure {
  margin-left: auto;
  height: 26px;
  padding: 0 var(--space-3);
  border: var(--border-hairline);
  border-radius: var(--radius-pill);
  background: none;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-ink-secondary);
  cursor: pointer;
}

.draw-config__pressure.is-active {
  background: var(--color-ink);
  border-color: var(--color-ink);
  color: var(--color-bg);
}

/* ---- notes (yellow stickies) ---------------------------------------------------- */

.canvas-note {
  --note-c: #f5e6a8;
  position: absolute;
  /* origin pinned; world position comes from `translate` (see WORLD ITEMS note) */
  left: 0;
  top: 0;
  padding: var(--space-3);
  background: var(--note-c);
  border: 1px solid color-mix(in srgb, var(--color-ink) 12%, var(--note-c));
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.canvas-note.is-dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-3);
}

.canvas-note.is-selected {
  box-shadow: 0 0 0 1.5px var(--color-ink), var(--shadow-2);
}

.canvas-note.is-editing {
  cursor: default;
}

@keyframes note-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-accent) 0%, transparent), var(--shadow-1);
  }
  30% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--color-accent) 45%, transparent), var(--shadow-2);
  }
}

.canvas-note.is-pulse {
  animation: note-pulse 1.2s var(--ease);
}

.canvas-note__text {
  width: 100%;
  height: 100%;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-ink);
}

.canvas-note__input {
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  background: none;
  resize: none;
  outline: none;
  font: inherit;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-ink);
}

/* connector spawn nodes at the edge midpoints (hover / selected / touch-select) */

.canvas-note__node {
  position: absolute;
  width: 12px;
  height: 12px;
  padding: 0;
  border-radius: var(--radius-round);
  background: var(--color-surface);
  border: 1.5px solid var(--color-ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease);
  cursor: crosshair;
  touch-action: none;
}

.canvas-note:hover .canvas-note__node,
.canvas-note.is-selected .canvas-note__node {
  opacity: 1;
  pointer-events: auto;
}

.canvas-note.is-dragging .canvas-note__node,
.canvas-note.is-editing .canvas-note__node {
  opacity: 0;
  pointer-events: none;
}

.canvas-note__node[data-side="n"] {
  top: -6px;
  left: calc(50% - 6px);
}

.canvas-note__node[data-side="s"] {
  bottom: -6px;
  left: calc(50% - 6px);
}

.canvas-note__node[data-side="w"] {
  left: -6px;
  top: calc(50% - 6px);
}

.canvas-note__node[data-side="e"] {
  right: -6px;
  top: calc(50% - 6px);
}

/* resize handle */

.canvas-note__handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: var(--radius-round);
  background: var(--color-ink);
  border: 2px solid var(--color-bg);
  cursor: nwse-resize;
  display: none;
  touch-action: none;
}

.canvas-note.is-selected.is-solo:not(.is-editing) .canvas-note__handle {
  display: block;
}

/* ---- connectors (shared SVG overlay, world coords) -------------------------------- */

.canvas-connectors {
  overflow: visible;
  pointer-events: none; /* connector parts opt back in */
}

.canvas-connector__line {
  stroke: #e8c84a;
  stroke-width: 2.5;
}

.canvas-connector__hit {
  stroke: transparent;
  stroke-width: 12;
  pointer-events: stroke;
  cursor: pointer;
}

.canvas-connector__end {
  fill: var(--color-surface);
  stroke: #e8c84a;
  stroke-width: 2;
  pointer-events: auto;
  cursor: move;
  touch-action: none;
}

.canvas-connector.is-selected .canvas-connector__line {
  stroke: #d4a80f;
  stroke-width: 3;
}

.canvas-connector.is-selected .canvas-connector__end {
  stroke: #d4a80f;
}

/* × affordance at the midpoint, shown when the connector is selected */

.canvas-connector__x {
  display: none;
  pointer-events: auto;
  cursor: pointer;
}

.canvas-connector.is-selected .canvas-connector__x {
  display: block;
}

.canvas-connector__x circle {
  fill: var(--color-surface);
  stroke: var(--color-ink);
  stroke-width: 1;
}

.canvas-connector__x path {
  stroke: var(--color-ink);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.canvas-connector.is-pending .canvas-connector__line {
  stroke-dasharray: 4 3;
}

/* ---- notes panel (View Notes, under the toolbar) ----------------------------------- */

.popover--notes .notes-panel {
  min-width: 220px;
  max-width: 300px;
  max-height: 50vh;
  overflow-y: auto;
  padding: var(--space-1);
}

.notes-panel__empty {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-ink-faint);
}

.notes-panel__row {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  text-align: left;
  cursor: pointer;
}

.notes-panel__row:hover {
  background: var(--color-hover);
}

.notes-panel__preview {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-ink);
}

.notes-panel__preview.is-empty {
  color: var(--color-ink-faint);
}

/* ---- text boxes (shaped text containers) ------------------------------------------ */

.canvas-textbox {
  position: absolute;
  /* origin pinned; world position comes from `translate` (see WORLD ITEMS note) */
  left: 0;
  top: 0;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.canvas-textbox.is-dragging {
  cursor: grabbing;
}

.canvas-textbox.is-selected {
  outline: 1.5px solid var(--color-ink);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.canvas-textbox.is-editing {
  cursor: default;
}

.canvas-textbox.is-ghost {
  border: 1px dashed var(--color-ink-secondary);
  border-radius: var(--radius-md);
}

.canvas-textbox__shape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.canvas-textbox__bg {
  fill-opacity: 1;
  stroke-width: 1.5;
}

.canvas-textbox__text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--space-3);
  overflow: hidden;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-ink);
}

/* triangles hold their text low, where the shape is widest */
.canvas-textbox[data-shape="triangle"] .canvas-textbox__text,
.canvas-textbox[data-shape="triangle"] .canvas-textbox__input {
  padding-top: 45%;
}

.canvas-textbox[data-shape="ellipse"] .canvas-textbox__text,
.canvas-textbox[data-shape="ellipse"] .canvas-textbox__input {
  padding: 15%;
}

.canvas-textbox__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: var(--space-3);
  border: none;
  background: none;
  resize: none;
  outline: none;
  font: inherit;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  text-align: center;
  color: var(--color-ink);
}

/* corner resize handles (same look as sections) */
.canvas-textbox__handle {
  position: absolute;
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: var(--radius-round);
  background: var(--color-ink);
  border: 2px solid var(--color-bg);
  display: none;
  touch-action: none;
}

.canvas-textbox.is-selected.is-solo:not(.is-editing) .canvas-textbox__handle {
  display: block;
}

.canvas-textbox__handle[data-dir="nw"] {
  top: -7px;
  left: -7px;
  cursor: nwse-resize;
}

.canvas-textbox__handle[data-dir="ne"] {
  top: -7px;
  right: -7px;
  cursor: nesw-resize;
}

.canvas-textbox__handle[data-dir="sw"] {
  bottom: -7px;
  left: -7px;
  cursor: nesw-resize;
}

.canvas-textbox__handle[data-dir="se"] {
  bottom: -7px;
  right: -7px;
  cursor: nwse-resize;
}

/* shape / connector-style dropdown (toolbar) */

.popover--shapes .shape-menu {
  display: flex;
  flex-direction: column;
  min-width: 150px;
  padding: var(--space-1);
}

.shape-menu__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-size: var(--text-sm);
  color: var(--color-ink);
  text-align: left;
  cursor: pointer;
}

.shape-menu__row:hover {
  background: var(--color-hover);
}

.shape-menu__row.is-active {
  background: var(--color-active);
}

/* ---- links (first-class connector elements; SVG overlay + HTML labels) ---------- */

.canvas-links {
  overflow: visible;
  pointer-events: none; /* link parts opt back in */
}

.canvas-link-labels {
  pointer-events: none;
}

.canvas-link__path {
  fill: none;
  stroke: var(--color-ink-secondary);
  stroke-width: 1.5;
  color: var(--color-ink-secondary); /* arrow markers use context-stroke / currentColor */
}

.canvas-link__path.is-pending {
  stroke-dasharray: 4 3;
}

.canvas-link__hit {
  fill: none;
  stroke: transparent;
  stroke-width: 12;
  pointer-events: stroke;
  cursor: pointer;
}

.canvas-link.is-selected .canvas-link__path {
  stroke: var(--color-ink);
  stroke-width: 2;
  color: var(--color-ink);
}

.canvas-link__end {
  fill: var(--color-surface);
  stroke: var(--color-ink);
  stroke-width: 1.5;
  pointer-events: auto;
  cursor: move;
  touch-action: none;
  display: none;
}

.canvas-link.is-selected .canvas-link__end {
  display: block;
}

/* snap-target highlight while dragging an endpoint */
.canvas-link__target {
  fill: none;
  stroke: var(--color-accent, var(--color-ink));
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

/* label: midpoint pill; input appears in place while editing */
.canvas-link__label {
  position: absolute;
  /* origin pinned; world position comes from `translate` (see WORLD ITEMS note) */
  left: 0;
  top: 0;
  /* world position comes from the `translate` property (canvas/links.js);
     the centering offset lives here so the two compose. */
  transform: translate(-50%, -50%);
  max-width: 220px;
  padding: 2px var(--space-2);
  background: var(--color-bg);
  border: var(--border-hairline);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  color: var(--color-ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.canvas-link__label.is-selected {
  border-color: var(--color-ink);
  color: var(--color-ink);
}

.canvas-link__label-input {
  position: absolute;
  /* origin pinned; world position comes from `translate` (see WORLD ITEMS note) */
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  width: 140px;
  height: 26px;
  font-size: var(--text-xs);
  text-align: center;
  pointer-events: auto;
}

/* tools: trash while selected; style/arrows only when solo-selected */
.canvas-link__tools {
  position: absolute;
  /* origin pinned; world position comes from `translate` (see WORLD ITEMS note) */
  left: 0;
  top: 0;
  transform: translate(-50%, 14px);
  display: none;
  gap: var(--space-1);
  padding: 2px;
  background: var(--color-surface);
  border: var(--border-hairline);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-1);
  pointer-events: auto;
}

.canvas-link__tools.is-visible {
  display: flex;
}

.canvas-link__tools .icon-btn {
  width: 24px;
  height: 24px;
}

.canvas-link__tools .icon-btn.is-active {
  background: var(--color-ink);
  color: var(--color-bg);
}

.canvas-link__tools-sep {
  width: 1px;
  align-self: stretch;
  margin: 2px 1px;
  background: var(--color-border, color-mix(in srgb, var(--color-ink) 12%, transparent));
}

/* multi-select: only trash stays visible */
.canvas-link__tools:not(.is-solo) [data-style],
.canvas-link__tools:not(.is-solo) [data-arrow],
.canvas-link__tools:not(.is-solo) .canvas-link__tools-sep {
  display: none;
}

/* ---- marquee (screen-space selection rect, appended to .canvas-layer) --------- */

.marquee {
  position: absolute;
  /* origin pinned; position comes from `translate` (see WORLD ITEMS note). The
     marquee lives in the layer, not the world, so its coords are screen-space —
     but the same layout-vs-compositor reasoning applies per pointermove. */
  left: 0;
  top: 0;
  border: 1px solid var(--color-ink);
  background: color-mix(in srgb, var(--color-ink) 8%, transparent);
  border-radius: 2px;
  pointer-events: none;
}

/* ---- empty state hint ------------------------------------------------------------ */

.canvas-empty-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  margin: 0;
  font-size: var(--text-md);
  color: var(--color-ink-faint);
  text-align: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- board -> canvas drag ghost -------------------------------------------------- */

.canvas-drag-ghost {
  position: fixed;
  z-index: var(--z-toast);
  translate: -50% -40%;
  pointer-events: none;
  opacity: 0.85;
  box-shadow: var(--shadow-3);
}

/* ---- realtime: remote cursors + gesture ghosts ------------------------------------ */

/* screen-space overlay (sibling of .canvas-world): cursors keep a constant
   size at any zoom; positions are re-projected on every viewport change */
.canvas-cursors {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.canvas-cursor {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: flex-start;
  will-change: transform;
}

.canvas-cursor svg {
  display: block;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.25));
}

.canvas-cursor__name {
  margin: 12px 0 0 -2px;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

/* world-space overlay for in-flight remote gestures (drags, live strokes);
   transient only — cleared when the commit event lands */
.canvas-ghosts {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 8; /* above every content layer */
  pointer-events: none;
}

.canvas-ghost {
  position: absolute;
  top: 0;
  left: 0;
  border: 1.5px dashed var(--ghost-color, var(--color-ink-faint));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--ghost-color, transparent) 6%, transparent);
  will-change: transform;
}

.canvas-ghost-stroke {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  opacity: 0.65;
}
