/* Case canvas (src/canvas). Night field notebook: a loam desk with a faint dot grid, cards on sandbag,
   stickies in paper colours with the user's words in the serif, manila for selection.
   Every class is prefixed cv- so nothing leaks into panels or the case window. */

.cv {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 320px;
  overflow: hidden;
  background: var(--surface-0);
  color: var(--ink-1);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-ui);
  outline: none;
  isolation: isolate;
}
.cv [hidden] {
  display: none !important;
}
.pn-canvas {
  position: relative;
  height: 100%;
  min-height: 360px;
  padding: 0 !important;
}

/* ---------------------------------------------------------------- stage + world */

.cv-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: default;
  background-image: radial-gradient(circle at 1px 1px, rgba(236, 231, 216, 0.085) 1px, transparent 1.4px);
  background-size: 20px 20px;
}
.cv-stage.no-grid {
  background-image: none;
}
.cv[data-tool="note"] .cv-stage,
.cv[data-tool="text"] .cv-stage,
.cv[data-tool="frame"] .cv-stage,
.cv[data-tool="arrow"] .cv-stage {
  cursor: crosshair;
}
.cv.is-space .cv-stage,
.cv.is-space .cv-node {
  cursor: grab;
}
.cv.is-pan .cv-stage,
.cv.is-pan .cv-node {
  cursor: grabbing;
}
.cv.is-drop .cv-stage {
  box-shadow: inset 0 0 0 2px var(--accent-line);
  background-color: rgba(217, 191, 134, 0.03);
}

.cv-world {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.cv-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
}
.cv-edges {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

/* ---------------------------------------------------------------- edges */

.cv-e-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  stroke-linecap: round;
  pointer-events: stroke;
  cursor: pointer;
}
.cv-e-line {
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
}
.cv-edge.is-sel .cv-e-hit {
  stroke: var(--accent-wash);
}
.cv-edge.is-sel .cv-e-line {
  stroke-width: 2.4;
}
.cv-ghost {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-dasharray: 5 4;
}

.cv-elabel {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 300px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  border: 1px solid color-mix(in srgb, var(--cv-c, var(--rule-3)) 55%, transparent);
  color: var(--ink-1);
  font-size: var(--fs-meta);
  font-weight: var(--fw-medium);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  user-select: none;
}
.cv-elabel.is-empty:not(.is-editing) {
  display: none;
}
.cv-elabel.is-sel,
.cv-elabel.is-editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-wash);
}
.cv-elabel.is-editing {
  overflow: visible;
  cursor: text;
}
.cv-elabel-t {
  display: inline-block;
  min-width: 2ch;
  outline: none;
}
.cv-elabel.is-editing .cv-elabel-t:empty::before {
  content: "Label";
  color: var(--ink-3);
}

/* ---------------------------------------------------------------- nodes (shared) */

.cv-node {
  position: absolute;
  left: 0;
  top: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}
.cv-node.is-sel {
  outline: calc(2px / var(--cv-zoom, 1)) solid var(--accent);
  outline-offset: calc(3px / var(--cv-zoom, 1));
}
.cv-node.is-target {
  outline: calc(2px / var(--cv-zoom, 1)) dashed var(--accent);
  outline-offset: calc(4px / var(--cv-zoom, 1));
}
.cv-edit {
  outline: none;
}
.cv-edit[contenteditable] {
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}
.cv-edit:empty::before {
  content: attr(data-ph);
  color: var(--ink-4);
  pointer-events: none;
}

.cv-handle {
  position: absolute;
  right: -7px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--surface-1);
  border: 1.5px solid var(--accent);
  box-sizing: border-box;
  opacity: 0;
  cursor: crosshair;
  transition: opacity var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
  z-index: 2;
}
.cv-node:hover > .cv-handle,
.cv-node.is-sel > .cv-handle,
.cv[data-tool="arrow"] .cv-handle {
  opacity: 1;
}
.cv-handle:hover {
  transform: scale(1.25);
  background: var(--accent);
}
.cv.is-move .cv-handle,
.cv.is-pan .cv-handle,
.cv-node.is-editing > .cv-handle,
.cv-frame > .cv-handle {
  opacity: 0 !important;
}
.cv-frame:hover > .cv-handle,
.cv-frame.is-sel > .cv-handle {
  opacity: 1 !important;
}
.cv-resize {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--accent);
  border: 2px solid var(--surface-1);
  box-sizing: border-box;
  cursor: nwse-resize;
  display: none;
  z-index: 2;
}
.cv-node.is-sel > .cv-resize {
  display: block;
}
.cv.is-move .cv-resize {
  display: none !important;
}

/* ---------------------------------------------------------------- subject card */

.cv-subject {
  padding: 10px 12px;
  border-radius: var(--radius-panel);
  background: var(--surface-2);
  border: 1px solid var(--rule-2);
  box-shadow: var(--elev-1);
}
.cv-subject.has-stripe {
  border-left: 3px solid var(--cv-c);
  padding-left: 10px;
}
.cv-subject:hover {
  border-color: var(--rule-3);
}
.cv-subject.has-stripe:hover {
  border-left-color: var(--cv-c);
}
.cv-s-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.cv-s-logo {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-3);
  display: grid;
  place-items: center;
}
.cv-subject[data-subject="x"] .cv-s-logo,
.cv-subject[data-subject="wallet"] .cv-s-logo {
  border-radius: 50%;
}
.cv-s-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}
.cv-s-mono {
  font-size: var(--fs-meta);
  font-weight: var(--fw-strong);
  color: var(--ink-2);
  line-height: 1;
}
.cv-s-id {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.cv-s-label {
  font-size: 15px;
  font-weight: var(--fw-strong);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cv-s-sub {
  font-size: var(--fs-micro);
  color: var(--ink-3);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.cv-s-kind {
  flex: none;
  align-self: flex-start;
  color: var(--ink-3);
  display: inline-flex;
}
.cv-s-note {
  margin-top: 8px;
  font-family: var(--font-voice);
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink-1);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
.cv-s-note.is-empty {
  display: none;
}
.cv-node.is-editing .cv-s-note {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}
.cv-s-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.cv-s-facts {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: var(--fs-meta);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
.cv-s-fact {
  color: var(--ink-2);
}
.cv-s-fact.is-up {
  color: var(--up);
}
.cv-s-fact.is-down {
  color: var(--down);
}
.cv-s-angle {
  color: var(--cv-c, var(--ink-3));
  font-weight: var(--fw-medium);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cv-s-expand {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px 0 7px;
  border-radius: var(--radius-control);
  border: 1px solid var(--rule-2);
  background: var(--surface-3);
  color: var(--ink-2);
  font: var(--fw-medium) var(--fs-meta) / 1 var(--font-ui);
  cursor: pointer;
}
.cv-s-expand:hover {
  color: var(--ink-1);
  border-color: var(--rule-3);
}

/* ---------------------------------------------------------------- sticky note */

.cv-note {
  padding: 14px 16px 16px;
  border-radius: 3px 3px 3px 14px;
  background: var(--cv-bg, #e8d6a6);
  color: #241f12;
  box-shadow: 0 10px 22px -12px rgba(6, 7, 3, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.cv-note-t {
  font-family: var(--font-voice);
  font-size: var(--fs-lead);
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-height: 1.45em;
}
.cv-note .cv-edit:empty::before {
  content: "Type a note";
  color: rgba(36, 31, 18, 0.45);
}
.cv-note.is-sel {
  outline-offset: calc(4px / var(--cv-zoom, 1));
}

/* ---------------------------------------------------------------- free text */

.cv-text {
  width: max-content;
  max-width: 720px;
  padding: 2px 4px;
  min-width: 24px;
}
.cv-text-t {
  font-family: var(--font-voice);
  font-size: 22px;
  line-height: 1.3;
  font-weight: 500;
  color: var(--cv-c, var(--ink-1));
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-height: 1.3em;
}

/* ---------------------------------------------------------------- frame */

.cv-frame {
  border-radius: var(--radius-panel);
  border: 1px solid color-mix(in srgb, var(--cv-c, #8d8b7d) 55%, transparent);
  background: var(--cv-bg, rgba(141, 139, 125, 0.07));
}
.cv-f-title {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 100%;
  box-sizing: border-box;
  padding: 9px 14px;
  display: flex;
}
.cv-f-t {
  font-size: var(--fs-body);
  font-weight: var(--fw-strong);
  line-height: 1.3;
  color: var(--cv-c, var(--ink-2));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 3ch;
}
.cv-frame.is-sel {
  outline-offset: calc(2px / var(--cv-zoom, 1));
}

/* ---------------------------------------------------------------- image */

.cv-image {
  border-radius: var(--radius-media);
  overflow: hidden;
  background: var(--surface-sunk);
  box-shadow: var(--elev-1);
}
.cv-image.is-sel,
.cv-image:hover {
  overflow: visible;
}
.cv-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--radius-media);
  pointer-events: none;
}
.cv-image.is-broken {
  min-height: 80px;
  border: 1px dashed var(--rule-3);
}
.cv-image.is-broken::after {
  content: "Image not found in evidence";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink-3);
  font-size: var(--fs-meta);
}

/* ---------------------------------------------------------------- marquee, frame preview, empty */

.cv-marquee {
  position: absolute;
  border: 1px solid var(--accent-line);
  background: var(--accent-wash);
  pointer-events: none;
}
.cv-preview {
  position: absolute;
  left: 0;
  top: 0;
  border: 1.5px dashed var(--accent);
  border-radius: var(--radius-panel);
  background: var(--accent-wash);
  pointer-events: none;
}
.cv-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--ink-3);
  pointer-events: none;
}
.cv-empty p {
  margin: 0;
  max-width: 48ch;
  font-size: var(--fs-body);
  color: var(--ink-2);
}
.cv-empty .cv-empty-2 {
  color: var(--ink-3);
  font-size: var(--fs-meta);
}

/* ---------------------------------------------------------------- toolbar, zoom, context bar */

.cv-toolbar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
  z-index: 10;
}
.cv-group,
.cv-zoom,
.cv-ctx {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  background: var(--surface-1);
  box-shadow: var(--elev-2);
  pointer-events: auto;
}
.cv-btn {
  height: 30px;
  min-width: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
  font: var(--fw-medium) var(--fs-meta) / 1 var(--font-ui);
  cursor: pointer;
  transition: background var(--dur-1), color var(--dur-1);
}
.cv-btn .ico {
  stroke-width: var(--icon-stroke);
}
.cv-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--ink-1);
}
.cv-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.cv-btn[aria-pressed="true"] {
  background: var(--accent-wash);
  color: var(--accent);
}
.cv-btn-l {
  padding: 0 10px 0 8px;
}
.cv-btn.cv-danger:hover {
  color: var(--danger);
}
.cv-sep {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--rule-2);
}

.cv-zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 10;
}
.cv-zl {
  min-width: 48px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
  font: var(--fw-medium) var(--fs-meta) / 1 var(--font-ui);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.cv-zl:hover {
  background: var(--surface-3);
  color: var(--ink-1);
}
.cv-status {
  padding: 0 8px;
  font-size: var(--fs-micro);
  color: var(--ink-3);
  white-space: nowrap;
}
.cv-status:empty {
  display: none;
}

.cv-ctx {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 12;
  white-space: nowrap;
}
.cv-sw {
  width: 20px;
  height: 20px;
  margin: 0 1px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgba(6, 7, 3, 0.35);
  cursor: pointer;
}
.cv-sw.is-on {
  box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 3.5px var(--accent);
}
.cv-sw:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.cv-sw-clear {
  min-width: 24px;
  height: 24px;
}

/* ---------------------------------------------------------------- popovers */

.cv-pop {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 20;
  min-width: 260px;
  max-width: min(420px, calc(100% - 16px));
  max-height: min(440px, calc(100% - 16px));
  overflow: auto;
  padding: 10px;
  border-radius: var(--radius-panel);
  background: var(--surface-1);
  box-shadow: var(--elev-2);
}
.cv-pop-h {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: var(--fs-body);
  color: var(--ink-1);
}
.cv-pop-h .ico {
  color: var(--ink-3);
}
.cv-grow {
  flex: 1;
}
.cv-pop-note {
  margin: 2px 0 8px;
  font-size: var(--fs-meta);
  line-height: 1.45;
  color: var(--ink-3);
}
.cv-pop-note.is-warn {
  color: var(--caution-ink);
}
.cv-pop-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}
.cv-picker {
  width: 300px;
}
.cv-picker-img {
  width: 380px;
}
.cv-pick-q {
  box-sizing: border-box;
  width: 100%;
  height: 30px;
  margin-bottom: 6px;
  padding: 0 10px;
  border-radius: var(--radius-control);
  border: 1px solid var(--rule-2);
  background: var(--surface-2);
  color: var(--ink-1);
  font: var(--fs-body) var(--font-ui);
}
.cv-pick-q:focus {
  outline: none;
  border-color: var(--accent-line);
}
.cv-pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-1);
  font: var(--fs-body) var(--font-ui);
  text-align: left;
  cursor: pointer;
}
.cv-pick-row .ico {
  color: var(--ink-3);
  flex: none;
}
.cv-pick-row:hover,
.cv-pick-row:focus-visible {
  outline: none;
  background: var(--surface-3);
}
.cv-pick-l {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cv-pick-k {
  flex: none;
  font-size: var(--fs-micro);
  color: var(--ink-3);
}
.cv-ev-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.cv-ev {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--rule-1);
  border-radius: var(--radius-control);
  background: var(--surface-sunk);
  color: var(--ink-2);
  font: var(--fs-micro) var(--font-ui);
  cursor: pointer;
}
.cv-ev:hover {
  border-color: var(--accent-line);
}
.cv-ev-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-inner);
  background: var(--surface-2);
}
.cv-ev-n {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

/* wallet chooser */
.cv-wallet {
  width: 390px;
}
.cv-w-list {
  display: flex;
  flex-direction: column;
}
.cv-w-row {
  display: grid;
  grid-template-columns: 16px 92px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 6px;
  font-size: var(--fs-meta);
  cursor: pointer;
}
.cv-w-row:hover {
  background: var(--surface-3);
}
.cv-w-row input {
  margin: 0;
  accent-color: var(--manila);
}
.cv-w-addr {
  font-family: var(--font-code);
  color: var(--ink-2);
}
.cv-w-flows {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-variant-numeric: tabular-nums;
}
.cv-w-flow.is-out {
  color: var(--series-5);
}
.cv-w-flow.is-in {
  color: var(--info);
}
.cv-w-on {
  font-size: var(--fs-micro);
  color: var(--ink-3);
}

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

.cv-toast {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 30;
  max-width: min(440px, calc(100% - 24px));
  padding: 8px 12px;
  border-radius: var(--radius-control);
  background: var(--surface-3);
  color: var(--ink-1);
  font-size: var(--fs-meta);
  box-shadow: var(--elev-2);
}
.cv-toast.is-warn {
  border-left: 3px solid var(--caution);
}
