/* The canvas view (body[data-view=canvas]), its items, notes, groups, handles, toolbar. Owner: canvas. Tokens from style.css only.
   The page does not scroll on a canvas: the centre column is exactly the viewport tall and the canvas stage
   fills what the toolbar and the header leave. Items live in canvas units inside .cv-world (one transform);
   --iz (1 / zoom, set on .cv-world) keeps outlines, badges and radii a constant size on screen. Pictures on
   the canvas keep the grid's badge look (white on translucent black over the image). */

/* ---------- the page around the canvas ---------- */
body[data-view=canvas] .centre { height: 100vh; height: 100dvh; min-height: 0; }
body[data-view=canvas] main { display: flex; flex-direction: column; min-height: 0; padding: 0; }
body[data-view=canvas] .vhead { flex: none; padding: 14px var(--pad) 12px; align-items: center; }
body[data-view=canvas] .vhead h1 { font-size: 22px; }

#canvasView { position: relative; flex: 1; min-height: 0; display: flex; }
#canvasView[hidden] { display: none !important; }

/* ---------- the stage and the world ---------- */
.cv-stage { position: relative; flex: 1; min-width: 0; min-height: 0; overflow: hidden; background: var(--canvas); border-top: 1px solid var(--line);
  touch-action: none; user-select: none; -webkit-user-select: none; outline: none; cursor: default; contain: strict; -webkit-tap-highlight-color: transparent; }
.cv-stage:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-soft); }
.cv-stage.space, .cv-stage.space .cv-item { cursor: grab; }
.cv-stage.panning, .cv-stage.panning .cv-item { cursor: grabbing; }
.cv-stage.drop { box-shadow: inset 0 0 0 2px var(--accent); }
.cv-stage.drop::after { content: "Drop to add to the canvas"; position: absolute; left: 50%; top: 18px; translate: -50% 0; padding: 7px 14px; border-radius: 999px;
  background: var(--accent-strong); color: var(--accent-ink); font-weight: 600; font-size: 12.5px; pointer-events: none; box-shadow: 0 10px 28px rgba(0,0,0,.45); }
.cv-world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; will-change: transform; --iz: 1; }

/* ---------- items ---------- */
.cv-item { position: absolute; left: 0; top: 0; transform-origin: 50% 50%; box-sizing: border-box; contain: layout style; }
.cv-pic { position: absolute; inset: 0; overflow: hidden; background: var(--ph); border-radius: min(calc(3px * var(--iz)), 4%); }
.cv-item.cropped .cv-pic { border-radius: 0; }
.cv-lo, .cv-hi, .cv-video { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; max-width: none; object-fit: fill; opacity: 0; transition: opacity .2s; pointer-events: none; }
.cv-lo.ld, .cv-hi.ld, .cv-video.on { opacity: 1; }
.cv-video { object-fit: cover; background: transparent; }
.cv-item.nopic .cv-pic { background: var(--panel); }
.cv-item.sel { outline: calc(2px * var(--iz)) solid var(--accent); outline-offset: calc(1px * var(--iz)); }
.cv-item.hov:not(.sel) { outline: calc(1px * var(--iz)) solid var(--faint); }
.cv-badge { position: absolute; left: calc(6px * var(--iz)); top: calc(6px * var(--iz)); display: inline-flex; align-items: center; gap: calc(4px * var(--iz));
  padding: 0 calc(6px * var(--iz)); height: calc(18px * var(--iz)); border-radius: calc(6px * var(--iz)); font: 600 calc(10.5px * var(--iz))/1 var(--font);
  background: rgba(0,0,0,.65); color: #fff; white-space: nowrap; pointer-events: none; }
.cv-badge.warn { color: var(--warn); }
.cv-badge.play { left: auto; top: auto; right: calc(6px * var(--iz)); bottom: calc(6px * var(--iz)); font-weight: 500; font-variant-numeric: tabular-nums; }
.cv-badge .ic { width: calc(10px * var(--iz)); height: calc(10px * var(--iz)); fill: currentColor; stroke: none; }
.cv-item.t-video.hov .cv-badge.play { opacity: 0; transition: opacity .16s; }

/* PureRef group frames: tinted rectangles behind their members (the colour is the group's own) */
.cv-gframe { position: absolute; left: 0; top: 0; border-radius: calc(4px * var(--iz)); pointer-events: none; }

/* notes (PureRef text): text, size, colour and background come from the note itself */
.cv-item.t-note { color: var(--text); line-height: 1.25; }
.cv-note { position: absolute; inset: 0; padding: .12em .2em; white-space: pre-wrap; overflow-wrap: anywhere; overflow: visible; pointer-events: none; font-variant-emoji: text; }
.cv-item.t-note.has-bg { border-radius: calc(4px * var(--iz)); }
.cv-item.t-note.editing .cv-note { visibility: hidden; }
.cv-edit { position: absolute; left: 0; top: 0; width: 100%; min-height: 100%; margin: 0; padding: .12em .2em; border: 0; outline: calc(2px * var(--iz)) solid var(--accent);
  border-radius: calc(3px * var(--iz)); background: rgba(0,0,0,.25); color: inherit; font: inherit; line-height: inherit; text-align: inherit; resize: none; overflow: hidden;
  white-space: pre-wrap; overflow-wrap: anywhere; cursor: text; user-select: text; -webkit-user-select: text; }

/* folder, board and canvas cards (sizes in em: 1em = 16 canvas units at scale 1) */
.cv-item.t-folder, .cv-item.t-board, .cv-item.t-canvas { display: flex; flex-direction: column; color: var(--text); }
.cv-cover { width: 100%; aspect-ratio: 1; flex: none; display: grid; grid-template: 1fr / 1fr; gap: .125em; border-radius: .625em; overflow: hidden; background: var(--mosaic); }
.cv-cover.n0 { place-items: center; background: var(--panel); }
.cv-cover.n2 { grid-template-columns: 1fr 1fr; }
.cv-cover.n3, .cv-cover.n4 { grid-template: 1fr 1fr / 1fr 1fr; }
.cv-cover.n3 img:first-child { grid-row: span 2; }
.cv-cover img { width: 100%; height: 100%; min-height: 0; display: block; object-fit: cover; background: var(--ph); opacity: 0; transition: opacity .2s; }
.cv-cover img.ld { opacity: 1; }
.cv-cover-ic { width: 3.5em; height: 3.5em; color: var(--dim); stroke-width: 1.1; }
.cv-cap { flex: 1; min-height: 0; padding: .6em .125em 0; display: flex; flex-direction: column; gap: .15em; overflow: hidden; }
.cv-cap-name { display: flex; align-items: center; gap: .4em; font-weight: 600; font-size: 1.05em; line-height: 1.3; min-width: 0; }
.cv-cap-name span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-cap-ic { width: .95em; height: .95em; color: var(--faint); stroke-width: 1.7; }
.cv-cap-meta { color: var(--muted); font-size: .85em; line-height: 1.3; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-item.t-folder.sel, .cv-item.t-board.sel, .cv-item.t-canvas.sel { outline: none; }
.cv-item.t-folder.sel .cv-cover, .cv-item.t-board.sel .cv-cover, .cv-item.t-canvas.sel .cv-cover { outline: calc(2px * var(--iz)) solid var(--accent); outline-offset: calc(1px * var(--iz)); }
.cv-item.t-folder.sel .cv-cap-ic, .cv-item.t-board.sel .cv-cap-ic, .cv-item.t-canvas.sel .cv-cap-ic { color: var(--accent-icon); }
.cv-item.gone { opacity: .55; }
.cv-item.gone .cv-cap-name { color: var(--muted); }

/* light backgrounds (a PureRef board's own colour): captions stay readable */
.cv-stage.light .cv-cap-name, .cv-stage.light .cv-item.t-folder, .cv-stage.light .cv-item.t-board, .cv-stage.light .cv-item.t-canvas { color: var(--bg); }
.cv-stage.light .cv-cap-meta { color: var(--dim); }

/* ---------- overlay: selection frame, handles, rubber band, guides, group labels (screen pixels) ---------- */
.cv-overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.cv-selbox { position: absolute; left: 0; top: 0; border: 1px solid var(--accent); border-radius: 2px; pointer-events: none; }
.cv-handle { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 3px; background: var(--text); border: 1.5px solid var(--accent);
  pointer-events: auto; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.cv-handle.nw { left: 0; top: 0; cursor: nwse-resize; }
.cv-handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.cv-handle.sw { left: 0; top: 100%; cursor: nesw-resize; }
.cv-handle.se { left: 100%; top: 100%; cursor: nwse-resize; }
.cv-selbox.small .cv-handle.nw, .cv-selbox.small .cv-handle.ne, .cv-selbox.small .cv-handle.sw { display: none; }
.cv-selbox.locked .cv-handle { display: none; }
.cv-band { position: absolute; left: 0; top: 0; border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 2px; }
.cv-guides { position: absolute; inset: 0; }
.cv-guide { position: absolute; left: 0; top: 0; background: var(--warn); }
.cv-guide.x { width: 1px; }
.cv-guide.y { height: 1px; }
.cv-glabels { position: absolute; inset: 0; }
.cv-glabel { position: absolute; left: 0; top: 0; padding: 1px 7px; border-radius: 6px; font-size: 11.5px; font-weight: 600; line-height: 17px; color: var(--text-2);
  background: rgba(20, 21, 23, .78); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- HUD: zoom (bottom left), hints (bottom right) ---------- */
.cv-hud { position: absolute; left: 12px; bottom: 12px; z-index: 2; display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 10px;
  background: rgba(23, 24, 27, .92); border: 1px solid var(--line-2); box-shadow: 0 10px 28px rgba(0,0,0,.4); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.cv-hud-btn { height: 28px; min-width: 28px; display: inline-grid; place-items: center; padding: 0 6px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 12px; font-variant-numeric: tabular-nums; }
.cv-hud-btn:hover { background: var(--raised); color: var(--text); }
.cv-zoom { min-width: 58px; color: var(--text-2); font-weight: 500; }
.cv-hud-sep { width: 1px; height: 16px; margin: 0 3px; background: var(--line-3); }
.cv-hints { position: absolute; right: 12px; bottom: 12px; z-index: 1; display: flex; gap: 14px; padding: 6px 12px; border-radius: 999px;
  background: rgba(23, 24, 27, .82); border: 1px solid var(--line-2); color: var(--faint); font-size: 11.5px; pointer-events: none;
  transition: opacity .25s; }
.cv-hints.gone { opacity: 0; visibility: hidden; transition: opacity .25s, visibility 0s .25s; }

/* ---------- empty, loading, missing ---------- */
.cv-empty { position: absolute; left: 50%; top: 50%; translate: -50% -50%; z-index: 2; width: min(400px, calc(100% - 32px)); display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 26px 22px 22px; text-align: center; background: var(--pane); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.45); }
.cv-empty-ic { width: 40px; height: 40px; color: var(--accent-icon); stroke-width: 1.3; margin-bottom: 4px; }
.cv-empty-title { font-size: 15px; font-weight: 650; }
.cv-empty-text { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.cv-empty-btn { margin-top: 8px; }
.cv-status { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); background: var(--sunk); }
.cv-status.missing .ic.big { color: var(--dim); }

/* ---------- header tools ---------- */
.cv-tools { display: flex; align-items: center; gap: 8px; }
.cv-tgroup { display: flex; gap: 4px; }
.cv-tb:disabled { opacity: .4; cursor: default; background: transparent; }
.cv-tb:not(:has(span)) { width: 34px; padding: 0; justify-content: center; }

/* ---------- the "Add to canvas" picker and the inspector ---------- */
.cv-pick-link { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; cursor: pointer; padding: 2px 2px 0; }
.cv-pick-link input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.cv-ins-k { color: var(--faint); font-size: 11.5px; margin-bottom: -10px; }
.cv-ins-links { display: flex; flex-wrap: wrap; gap: 6px; }
.cv-ins-chip { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; text-decoration: none; }
.cv-ins-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv-ins-note { padding: 10px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line-2); color: var(--text-2); white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 160px; overflow-y: auto; font-size: 12.5px; line-height: 1.45; }
.cv-ins-row { display: flex; align-items: center; gap: 8px; }
.cv-ins-row .cv-sq { width: 40px; flex: none; padding: 0; }
.cv-ins-val { flex: 1; text-align: center; color: var(--text-2); font-variant-numeric: tabular-nums; }
.cv-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.cv-swatch { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 1px solid var(--line-3); background: var(--sw, transparent); cursor: pointer; }
.cv-swatch.none { background: linear-gradient(135deg, transparent 45%, var(--danger) 45%, var(--danger) 55%, transparent 55%); }
.cv-swatch.on { box-shadow: 0 0 0 2px var(--pane), 0 0 0 4px var(--accent); }
.cv-ins-seg { align-self: flex-start; }
.cv-ins-seg button { width: auto; padding: 0 10px; font-size: 12px; }

/* ---------- touch screens and phones: viewing, pan, pinch, tap to view, move ---------- */
#canvasView.touch .cv-hints { display: none; }
#canvasView.touch .cv-hud-btn { height: 44px; min-width: 44px; border-radius: 10px; }
#canvasView.touch .cv-zoom { min-width: 64px; }
@media (hover: none), (pointer: coarse) {
  .cv-edit-tools { display: none; }
}
@media (max-width: 767px) {
  body[data-view=canvas] main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  body[data-view=canvas] .vhead { padding: 0; }
  /* phones view the canvas: the zoom buttons are on it, editing is on the computer */
  body[data-view=canvas] .vtools { padding: 0; }
  .cv-tools { display: none !important; }
  body[data-view=canvas] .prow { padding: 2px var(--pad) 8px; }
  .cv-stage { border-top: 1px solid var(--line); }
  .cv-hud { left: 10px; bottom: 36px; }   /* clear of the bottom bar's round find button */
  .cv-edit-tools, .cv-hints { display: none; }
  .cv-tools .tb-btn { height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .cv-lo, .cv-hi, .cv-video, .cv-cover img { transition: none; }
}
