/* Free canvas */
.canvas-host {
  position: fixed;
  inset: 0;
}

.cv {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: var(--canvas-bg);
  touch-action: none;
  outline: none;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

.cv.has-grid {
  background-image: radial-gradient(circle at 1px 1px, var(--canvas-dot) 1.1px, transparent 1.3px);
}

.cv.is-panning {
  cursor: grabbing;
}

.cv.is-connecting,
.cv.is-connecting .cv-obj {
  cursor: crosshair;
}

.cv.is-dragging iframe,
.cv.is-panning iframe,
body.is-dragging-card iframe {
  pointer-events: none;
}

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

.cv-links {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  color: #888;
  pointer-events: none;
}

.cv-links g {
  pointer-events: auto;
}

.cv-link {
  stroke: currentColor;
  stroke-width: calc(2px / var(--zoom, 1));
  fill: none;
}

.cv-link-hit {
  stroke: transparent;
  stroke-width: calc(16px / var(--zoom, 1));
  fill: none;
  cursor: pointer;
}

.cv-links g.is-selected {
  color: var(--accent-text);
}

.cv-obj {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: box-shadow 150ms ease, opacity 150ms ease;
}

body.dark .cv-obj {
  background: #171717;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.cv-obj:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.cv-obj.is-selected {
  box-shadow: 0 0 0 calc(2px / var(--zoom, 1)) var(--accent-text), 0 4px 16px rgba(0, 0, 0, 0.15);
}

.cv-obj.is-connect-source {
  box-shadow: 0 0 0 calc(3px / var(--zoom, 1)) #888, 0 4px 16px rgba(0, 0, 0, 0.15);
}

.cv-obj.is-drop-target {
  box-shadow: 0 0 0 calc(3px / var(--zoom, 1)) var(--accent-text), 0 8px 24px rgb(var(--accent-rgb) / 0.35);
}

.cv-obj.is-dimmed {
  opacity: 0.25;
}

.cv-resize {
  position: absolute;
  right: calc(-5px / var(--zoom, 1));
  bottom: calc(-5px / var(--zoom, 1));
  width: calc(12px / var(--zoom, 1));
  height: calc(12px / var(--zoom, 1));
  border-radius: 3px;
  background: var(--accent-text);
  border: calc(2px / var(--zoom, 1)) solid #fff;
  cursor: nwse-resize;
  display: none;
}

.cv-obj.is-selected .cv-resize {
  display: block;
}

/* Site */
.cv-site {
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.canvas-site-preview {
  position: relative;
  flex: 1;
  overflow: hidden;
  border-radius: 8px 8px 0 0;
  background: #fff;
}

.canvas-site-preview iframe,
.canvas-site-preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: cover;
}

.cv-shield {
  position: absolute;
  inset: 0;
  cursor: grab;
}

.cv.is-live .cv-shield {
  display: none;
}

.cv-site-foot {
  position: relative;
  flex-shrink: 0;
  height: 84px;
  padding: 14px 18px;
  cursor: grab;
  border-top: 1px solid var(--line);
}

.cv-site-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.cv-site-host {
  font-size: 13px;
  color: var(--faint);
  margin-top: 2px;
}

.cv-site-tags {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.cv-site-tags span {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.cv-site-actions {
  position: absolute;
  right: 14px;
  top: 14px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 150ms ease;
}

.cv-site:hover .cv-site-actions,
.cv-site.is-selected .cv-site-actions {
  opacity: 1;
}

.cv-mini {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  background: var(--chip);
}

.cv-site-title .cv-mini {
  width: 20px;
  height: 20px;
  background: none;
}

.cv-mini:hover {
  color: var(--ink);
  background: var(--chip-hover);
}

.cv-missing {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 20px;
}

/* Note */
.cv-note {
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  border-radius: 4px;
  cursor: grab;
}

body.dark .cv-note {
  background: var(--note-bg);
}

.cv-note-text {
  width: 100%;
  height: 100%;
  padding: 14px 14px;
  font-size: 15px;
  line-height: 1.45;
  color: #2b2b2b;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
}

.cv-note-text[contenteditable='true'] {
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

.cv-note-text:empty::before {
  content: 'Type a note…';
  color: rgba(0, 0, 0, 0.35);
}

.cv-palette {
  position: absolute;
  left: 0;
  top: calc(-38px / var(--zoom, 1));
  display: none;
  gap: calc(6px / var(--zoom, 1));
  padding: calc(5px / var(--zoom, 1));
  border-radius: calc(8px / var(--zoom, 1));
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.08);
  transform-origin: 0 100%;
}

.cv-obj.is-selected .cv-palette {
  display: flex;
}

.cv-palette button {
  width: calc(20px / var(--zoom, 1));
  height: calc(20px / var(--zoom, 1));
  border-radius: 50%;
  border: calc(2px / var(--zoom, 1)) solid;
}

/* Page */
.cv-page {
  display: flex;
  flex-direction: column;
  overflow: visible;
  border: 1px solid #e3e3e6;
}

body.dark .cv-page {
  border-color: #2a2a2a;
}

.cv-page-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fafafa;
  border-radius: 8px 8px 0 0;
  border-bottom: 1px solid #efefef;
  cursor: grab;
  color: #b0b0b5;
}

body.dark .cv-page-head {
  background: #1c1c1c;
  border-color: #262626;
}

.cv-page-title {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  padding: 0;
}

.cv-page-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid #efefef;
  font-size: 10px;
  font-weight: 600;
  color: #555;
}

body.dark .cv-page-tools {
  border-color: #262626;
  color: #bbb;
}

.cv-page-tools span {
  width: 1px;
  height: 14px;
  background: #e6e6e6;
  margin: 0 4px;
}

.cv-page-tools button {
  min-width: 22px;
  height: 22px;
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
}

.cv-page-tools button:hover {
  background: var(--chip);
}

.cv-page-body {
  flex: 1;
  overflow: auto;
  padding: 10px 14px 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
  outline: none;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

.cv-page-body h1 {
  font-size: 22px;
  font-weight: 500;
  margin: 8px 0;
}

.cv-page-body h2 {
  font-size: 19px;
  font-weight: 500;
  margin: 6px 0 10px;
}

.cv-page-body h3 {
  font-size: 16px;
  font-weight: 500;
  margin: 12px 0 6px;
}

.cv-page-body p {
  margin: 0 0 8px;
}

.cv-page-body ul,
.cv-page-body ol {
  margin: 4px 0;
  padding-left: 22px;
}

.cv-page-body ul.checklist {
  list-style: none;
  padding-left: 2px;
}

.cv-page-body ul.checklist > li {
  position: relative;
  padding-left: 24px;
  margin: 3px 0;
}

.cv-page-body ul.checklist > li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 3px;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  border: 1.5px solid #c9c9ce;
  background: #fff;
  cursor: pointer;
}

.cv-page-body ul.checklist > li[data-checked='true'] {
  color: #9a9aa0;
  text-decoration: line-through;
}

.cv-page-body ul.checklist > li[data-checked='true']::before {
  background: var(--accent-text) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.75L9 17.25M9 17.25L19.5 6.75'/%3E%3C/svg%3E") center / 11px no-repeat;
  border-color: var(--accent-text);
}

/* Folder */
.cv-folder {
  background: var(--folder-bg);
  border: 1.5px dashed var(--folder-border);
  border-radius: 10px;
  box-shadow: none;
  cursor: grab;
  overflow: visible;
}

body.dark .cv-folder {
  background: color-mix(in srgb, var(--folder-bg) 14%, #171717);
}

.cv-folder-icon {
  position: absolute;
  top: 12px;
  left: 12px;
}

.cv-folder-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--folder-bg) 70%, #fff 0%);
  border-top: 1px solid color-mix(in srgb, var(--folder-border) 25%, transparent);
  border-radius: 0 0 9px 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cv-folder-name small {
  font-weight: 400;
  color: var(--muted);
  font-size: 11px;
}

.cv-folder-input {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--accent-text);
  border-radius: 4px;
  padding: 2px 4px;
  width: 100%;
  outline: none;
}

/* Marquee, crumbs, hint */
.cv-marquee {
  position: absolute;
  border: 1px solid var(--accent-text);
  background: rgb(var(--accent-rgb) / 0.12);
  pointer-events: none;
}

.cv-crumbs {
  position: absolute;
  top: 24px;
  left: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05);
  font-size: 14px;
  color: var(--muted);
  z-index: 5;
}

body.dark .cv-crumbs {
  background: rgba(28, 28, 28, 0.95);
}

.cv-crumb {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--ink);
}

.cv-crumb:hover,
.cv-crumb.is-drop-target {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.cv-crumb.is-current {
  font-weight: 600;
}

.cv-hint {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 10px;
  background: #1f1f21;
  color: #fff;
  font-size: 13px;
  z-index: 5;
}

/* Zoom toolbar */
.cv-toolbar {
  position: absolute;
  top: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.03);
  z-index: 5;
  backdrop-filter: blur(8px);
}

body.dark .cv-toolbar {
  background: rgba(28, 28, 28, 0.95);
}

.cv-beta {
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-display);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 13.5px;
  margin-right: 4px;
}

.cv-tb {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #4a4a4f;
}

body.dark .cv-tb {
  color: #d0d0d4;
}

.cv-tb:hover {
  background: var(--chip);
}

.cv-tb:disabled {
  color: #c4c4c8;
  cursor: default;
  background: none;
}

body.dark .cv-tb:disabled {
  color: #4a4a4f;
}

.cv-tb.is-on {
  color: var(--ink);
}

.cv-tb.cv-live {
  color: #9a9aa0;
}

.cv-tb.cv-live.is-on {
  background: #e3f2e3;
  color: #43a047;
}

body.dark .cv-tb.cv-live.is-on {
  background: #17301a;
}

.cv-zoom-label {
  min-width: 56px;
  height: 36px;
  font-size: 14.5px;
  color: #4a4a4f;
  border-radius: 8px;
}

body.dark .cv-zoom-label {
  color: #d0d0d4;
}

.cv-zoom-label:hover {
  background: var(--chip);
}

.cv-tb-sep {
  width: 1px;
  height: 26px;
  background: #e6e6e8;
  margin: 0 6px;
}

body.dark .cv-tb-sep {
  background: #2e2e2e;
}

/* Drag ghost (library reorder) */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 300;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #1f1f21;
  color: #fff;
  font-size: 13px;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 768px) {
  .cv-toolbar {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 8px;
    left: 8px;
    justify-content: space-between;
    padding: 5px 6px;
    gap: 0;
    overflow-x: auto;
  }
  .cv-beta,
  .cv-tb-sep {
    display: none;
  }
  .cv-tb {
    width: 34px;
    height: 34px;
  }
  .cv-crumbs {
    top: calc(64px + env(safe-area-inset-top, 0px));
    left: 8px;
  }
  .cv-site-actions {
    opacity: 1;
  }
}
