/* Infinite canvas: dotted paper, cards, arrows. */
.cv-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  outline: none;
  cursor: grab;
  /* every finger on the canvas is ours (pan, pinch, double-tap, long-press: see canvas-view.js);
     a card whose text scrolls (.fixed-h) still scrolls natively, it is its own scroll container */
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none; /* a long-press makes a card, not an iOS callout (a card's text keeps it) */
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1.3px, transparent 1.6px);
  background-size: var(--gs, 24px) var(--gs, 24px);
  background-position: var(--gx, 0) var(--gy, 0);
}
.cv-viewport.panning {
  cursor: grabbing;
}
.cv-world {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}
.cv-edges {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}
.cv-cards {
  position: absolute;
  left: 0;
  top: 0;
}

/* ------------------------------------------------------------------- arrows */
.edge-line {
  fill: none;
  stroke: var(--edge);
  stroke-width: calc(1.7px * var(--ez, 1));
  stroke-linecap: round;
  transition: stroke 0.12s, opacity 0.12s;
}
.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: calc(18px * var(--ez, 1));
  pointer-events: stroke;
  cursor: pointer;
}
.edge:hover .edge-line,
.edge.selected .edge-line {
  stroke: var(--accent);
  stroke-width: calc(2.6px * var(--ez, 1));
}
.edge.active .edge-line {
  stroke: var(--accent);
}
.edge.two-way .edge-line {
  stroke: var(--violet);
}
.edge.two-way.active .edge-line,
.edge.two-way:hover .edge-line {
  stroke: var(--violet);
}
.has-selection .edge:not(.active) .edge-line {
  opacity: 0.3;
}
.mk {
  fill: var(--edge);
}
.mk.hi {
  fill: var(--accent);
}
.rubber {
  fill: none;
  stroke: var(--accent);
  stroke-width: calc(2.2px * var(--ez, 1));
  stroke-dasharray: 7 6;
  pointer-events: none;
}
.two-way-drag .rubber {
  stroke: var(--violet);
}

/* -------------------------------------------------------------------- cards */
.card {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 13px;
  box-shadow: var(--shadow-1);
  cursor: default;
  outline: none;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.card:hover {
  box-shadow: var(--shadow-2);
}
.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-2);
}
.card.dragging {
  box-shadow: var(--shadow-3);
  cursor: grabbing;
}
.card.dragging .card-head {
  cursor: grabbing;
}
.card.drop-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent), 0 0 0 10px var(--accent-soft);
}
.card.pulse {
  animation: pulse 0.9s ease-out;
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 var(--accent);
  }
  100% {
    box-shadow: 0 0 0 18px transparent;
  }
}
.card[data-kind='daily'] {
  background: linear-gradient(var(--amber-soft), var(--surface) 64px) var(--surface);
}
.card[data-kind='daily'].is-today {
  border-color: color-mix(in srgb, var(--amber) 60%, var(--line-2));
}
.card[data-kind='contact'] {
  background: linear-gradient(var(--violet-soft), var(--surface) 64px) var(--surface);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 8px 5px 12px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.card-dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 3px;
  background: var(--accent);
}
.card[data-kind='daily'] .card-dot {
  background: var(--amber);
  border-radius: 50%;
}
.card[data-kind='contact'] .card-dot {
  background: var(--violet);
  border-radius: 50%;
}
.card-title {
  flex: 1;
  min-width: 0;
  font-weight: 650;
  font-size: 14.5px;
  letter-spacing: -0.005em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-sub {
  margin-left: 8px;
  font-weight: 450;
  font-size: 12px;
  color: var(--muted);
}
.card-title-input {
  width: 100%;
  border: 0;
  border-bottom: 2px solid var(--accent);
  outline: 0;
  background: transparent;
  font: inherit;
  font-weight: 650;
  padding: 0 0 1px;
  user-select: text;
}
.card-actions {
  display: flex;
  opacity: 0;
  transition: opacity 0.12s;
}
.card:hover .card-actions,
.card.selected .card-actions {
  opacity: 1;
}
.card-body {
  flex: 1;
  min-height: 0;
  padding: 0 12px 6px 6px;
  -webkit-touch-callout: default; /* a link in a card keeps its iOS callout */
}
.card.fixed-h .card-body {
  overflow: auto;
  overscroll-behavior: contain;
}
.card-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 12px 8px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  margin: 0 10px;
  padding-left: 2px;
}
.card-foot span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.link-btn {
  margin-left: auto;
  border: 0;
  background: none;
  padding: 0;
  font-size: 11.5px;
  color: var(--accent-ink);
}
.link-btn:hover {
  text-decoration: underline;
}

/* edge dots: drag from one to another card to link */
.handle {
  position: absolute;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: crosshair;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.12s, transform 0.12s var(--ease), background 0.1s;
  z-index: 4;
}
.handle::after {
  content: '';
  position: absolute;
  inset: -7px;
}
.handle-t {
  left: 50%;
  top: -8px;
  margin-left: -7.5px;
}
.handle-b {
  left: 50%;
  bottom: -8px;
  margin-left: -7.5px;
}
.handle-l {
  top: 50%;
  left: -8px;
  margin-top: -7.5px;
}
.handle-r {
  top: 50%;
  right: -8px;
  margin-top: -7.5px;
}
.card:hover .handle,
.card.selected .handle {
  opacity: 1;
  transform: scale(1);
}
.handle:hover {
  background: var(--accent);
  transform: scale(1.25) !important;
}
.connecting .card:not(.drop-target) .handle {
  opacity: 0;
}
.connecting,
.connecting .card,
.connecting .card-head {
  cursor: crosshair !important;
}

.card-resize {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  opacity: 0;
  background: linear-gradient(135deg, transparent 0 50%, var(--line-2) 50% 56%, transparent 56% 66%, var(--line-2) 66% 72%, transparent 72%);
  border-bottom-right-radius: 12px;
  transition: opacity 0.12s;
}
.card:hover .card-resize,
.card.selected .card-resize {
  opacity: 1;
}

/* zoomed far out: show only titles, big enough to read */
.lod .card-body,
.lod .card-foot,
.lod .card-actions,
.lod .handle,
.lod .card-resize {
  display: none;
}
.lod .card {
  height: auto !important;
  min-height: 0 !important;
}
.lod .card-head {
  padding: 14px 16px;
}
/* titles stay ~13px on screen however far you zoom out */
.lod .card-title {
  font-size: calc(14.5px * min(6, 0.9 / var(--z, 1)));
  white-space: normal;
  line-height: 1.2;
}
.lod .card-sub {
  display: none;
}
.lod .card-dot {
  width: calc(9px * min(6, 0.9 / var(--z, 1)));
  height: calc(9px * min(6, 0.9 / var(--z, 1)));
}
.lod .card {
  border-radius: calc(13px * min(6, 0.9 / var(--z, 1)));
  border-width: calc(1px * min(6, 0.9 / var(--z, 1)));
}

/* ---------------------------------------------------------------- controls */
.cv-controls {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 11px;
  box-shadow: var(--shadow-2);
  cursor: default;
}
.cv-controls .sep {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--line-2);
}
.zoom-label {
  min-width: 48px;
  height: 32px;
  border: 0;
  background: none;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.zoom-label:hover {
  background: var(--line);
}
.cv-hint {
  position: absolute;
  left: 50%;
  top: 14px;
  z-index: 4;
  transform: translateX(-50%);
  padding: 7px 14px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.6s;
}
.cv-hint.fade {
  opacity: 0;
}
@media (max-width: 860px) {
  .cv-hint {
    display: none;
  }
}

/* ------------------------------------------------------------------- touch */
@media (pointer: coarse) {
  /* holding a finger on empty space makes a card: it must not start a text selection instead.
     A card's text stays selectable, and text boxes must say so: iOS will not type into a box that
     inherits -webkit-user-select: none. */
  .cv-viewport {
    -webkit-user-select: none;
    user-select: none;
  }
  .cv-viewport .card-body,
  .cv-viewport input,
  .cv-viewport textarea {
    -webkit-user-select: text;
    user-select: text;
  }
  /* A card's dots, resize corner and buttons work once it is selected (tap its title). A tap on another
     card must not hit a button nobody can see, and the :hover a tap leaves behind must not show dots. */
  .card:not(.selected) .handle,
  .card:not(.selected) .card-resize,
  .card:not(.selected) .card-actions {
    opacity: 0;
    pointer-events: none;
  }
  /* Finger-sized targets. --ez is 1/zoom (1 to 3.2), so 30px * --ez is at least 30px on screen at every zoom
     where dots show. A dot's ::after is laid out in its padding box: 11px (15px less a 2px border on each
     side, border-box), whose middle is 5.5px in. It reaches 30px * --ez out from the dot's middle and
     15px * --ez to either side, but no further into the card than the dot itself (which stays above the
     title): on a selected card a finger on the title still moves or renames the card, it starts no arrow. */
  .handle-t::after {
    inset: calc(5.5px - 30px * var(--ez, 1)) calc(5.5px - 15px * var(--ez, 1)) 0;
  }
  .handle-b::after {
    inset: 0 calc(5.5px - 15px * var(--ez, 1)) calc(5.5px - 30px * var(--ez, 1));
  }
  .handle-l::after {
    inset: calc(5.5px - 15px * var(--ez, 1)) 0 calc(5.5px - 15px * var(--ez, 1)) calc(5.5px - 30px * var(--ez, 1));
  }
  .handle-r::after {
    inset: calc(5.5px - 15px * var(--ez, 1)) calc(5.5px - 30px * var(--ez, 1)) calc(5.5px - 15px * var(--ez, 1)) 0;
  }
  .card-resize::after {
    content: '';
    position: absolute;
    inset: calc(-6px * var(--ez, 1)) calc(-16px * var(--ez, 1)) calc(-16px * var(--ez, 1)) calc(-6px * var(--ez, 1));
  }
  .edge-hit {
    stroke-width: calc(24px * var(--ez, 1));
  }
  .card-actions .icon-btn.sm {
    width: 34px;
    height: 34px;
    margin: -4px 0; /* bigger to tap, same head height */
  }
  /* iOS zooms the whole page into a text box whose font is under 16px when it gets focus: the title box
     and a card's bullets (the box they are typed in inherits their size) are 16px here, as the
     Outliner's page is in css/editor.css */
  .card-title-input,
  .card-body .outline-card {
    font-size: 16px;
  }
}
