$canvas-chrome-bg: var(--prototype-state-map-canvas-bg, var(--tool-chrome-bg));
$canvas-chrome-muted: var(--tool-chrome-surface-muted, #fafafa);
$canvas-border: var(--tool-chrome-border);
$canvas-border-strong: var(--tool-chrome-border-strong);
$canvas-text: var(--tool-chrome-text);
$canvas-text-muted: var(--tool-chrome-text-muted);
$canvas-edge-base: var(--prototype-state-canvas-edge, rgba(0, 0, 0, 0.22));
// Pre-blend to canvas bg so edges stay subtle without semi-transparent layering at corners/arrowheads.
$canvas-edge-color: color-mix(in srgb, $canvas-edge-base 50%, $canvas-chrome-bg);

$wireframe-bg: var(--prototype-state-map-node-surface, var(--tool-chrome-surface));
$wireframe-subtle: var(--prototype-state-map-node-preview-bg, var(--tool-chrome-surface-muted));
$wireframe-border: var(--tool-chrome-border);
$wireframe-border-medium: var(--tool-chrome-border-strong);
$wireframe-footer-bg: var(--prototype-state-map-node-footer-bg, var(--tool-chrome-surface-muted));
$wireframe-footer-border: var(--prototype-state-map-node-footer-border, var(--tool-chrome-border-strong));
$wireframe-footer-text: var(--prototype-state-map-node-footer-text, var(--tool-chrome-text-heading));
$node-corner-radius: 0.5rem;

.page {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: $canvas-chrome-bg;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: $canvas-chrome-bg;
}

.mini {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: visible;
  background: transparent;

  .nodeGroup {
    box-sizing: border-box;
    overflow: hidden;
    height: 168px;
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    background: var(--prototype-state-map-node-surface);
    box-shadow:
      0 1px 2px rgba(0, 0, 0, 0.18),
      0 4px 12px rgba(0, 0, 0, 0.14);
    filter: none;
    transition:
      border-color 0.15s ease,
      box-shadow 0.15s ease;

    @media (hover: hover) and (pointer: fine) {
      &:hover {
        border-color: color-mix(in srgb, var(--tool-chrome-blue) 70%, rgba(255, 255, 255, 0.12));
        box-shadow:
          0 0 0 2px color-mix(in srgb, var(--tool-chrome-blue) 45%, transparent),
          0 0 14px color-mix(in srgb, var(--tool-chrome-blue) 28%, transparent),
          0 4px 16px rgba(0, 0, 0, 0.22);
      }
    }
  }

  .nodeGroupHighlighted {
    z-index: 1;
    border-color: color-mix(in srgb, var(--tool-chrome-blue) 78%, rgba(255, 255, 255, 0.12));
    box-shadow:
      0 0 0 2px color-mix(in srgb, var(--tool-chrome-blue) 52%, transparent),
      0 0 16px color-mix(in srgb, var(--tool-chrome-blue) 34%, transparent),
      0 4px 16px rgba(0, 0, 0, 0.24);
  }

  .nodeGroupSelected {
    z-index: 2;
    // Keep the default mini border; selection ring is drawn via box-shadow
    // so node dimensions stay 220×168 (see PrototypeStateCanvasView).
    border: 1.5px solid rgba(255, 255, 255, 0.1);
  }

  .nodePreview {
    container-type: size;
    height: 168px;
    flex: 1 1 auto;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    background: var(--prototype-state-map-node-preview-bg);
  }

  .nodeLabel {
    display: none;
  }

  .node {
    flex: 1 1 auto;
    height: 168px;
    cursor: pointer;
  }

  .callout {
    justify-content: center;
    min-height: 2.25rem;
    padding: 0.375rem 0.5rem;
    border-radius: 0.875rem;
    overflow: hidden;
    border-color: rgba(0, 0, 0, 0.06);
    background: #ffffff;
  }

  .calloutHint {
    display: none;
  }

  .edge {
    stroke: var(--prototype-mini-edge-color);
    stroke-width: 2.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
  }

  .edgeArrowHead {
    fill: var(--prototype-mini-edge-color);
  }
}

.miniViewport {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  background: color-mix(in srgb, var(--tool-chrome-surface) 10%, transparent);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  border: 1px solid var(--tool-chrome-border);
  border-radius: 0.75rem;
  cursor: grab;
  touch-action: none;
  user-select: none;

  &:active {
    cursor: grabbing;
  }
}

.miniNodeLabel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 0.75rem;
  overflow: hidden;
  font-size: 25.2px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-align: center;
  color: $wireframe-footer-text;
  word-break: break-word;
  hyphens: auto;
}

.miniCalloutLabel {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.15;
  color: $wireframe-footer-text;
  text-align: center;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: $canvas-chrome-bg;
}

.headerTitle {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: $canvas-text;
}

.headerHint {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  color: $canvas-text-muted;
}

.headerActions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.addStateButton {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.625rem;
  border: 1px solid $canvas-border;
  border-radius: 0.375rem;
  background: $canvas-chrome-bg;
  color: $canvas-text-muted;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      background: $canvas-chrome-muted;
      color: $canvas-text;
      border-color: $canvas-border-strong;
    }
  }

  &:focus:not(:focus-visible) {
    outline: none;
  }

  &:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--tool-chrome-blue) 55%, transparent);
    outline-offset: 2px;
  }
}

.closeButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid $canvas-border;
  border-radius: 0.375rem;
  background: $canvas-chrome-bg;
  color: $canvas-text-muted;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      background: $canvas-chrome-muted;
      color: $canvas-text;
    }
  }
}

.canvasViewport {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  background: $canvas-chrome-bg;
}

.canvasLayer {
  position: absolute;
  top: 24px;
  left: 24px;
  transform-origin: 0 0;
}

.edges {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.edge {
  fill: none;
  stroke: $canvas-edge-color;
  stroke-width: 1.5;
}

.edgeArrowHead {
  fill: $canvas-edge-color;
}

.nodeGroup {
  position: absolute;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid $wireframe-border;
  border-radius: $node-corner-radius;
  background: $wireframe-bg;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.nodeGroupSelected {
  z-index: 2;
  border-color: color-mix(in srgb, var(--tool-chrome-blue-deep) 72%, $wireframe-border);
  box-shadow:
    0 0 0 1.5px color-mix(in srgb, var(--tool-chrome-blue-deep) 55%, transparent),
    0 0 12px color-mix(in srgb, var(--tool-chrome-blue-deep) 28%, transparent);
}

.nodeGroupHovered {
  z-index: 3;
}

.node {
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.2s ease;

  &:focus:not(:focus-visible) {
    outline: none;
  }

  &:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--tool-chrome-blue) 55%, transparent);
    outline-offset: -2px;
  }
}

.nodePreview {
  height: 132px;
  overflow: hidden;
  border-radius: $node-corner-radius $node-corner-radius 0 0;
  background: $wireframe-subtle;
  pointer-events: none;

  &:has([data-prototype-wireframe-preview]) {
    background: var(--prototype-wireframe-preview-bg);
  }
}

.nodePreviewContent {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
  border-radius: inherit;
}

.nodeLabel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0 0.75rem;
  border-top: 1px solid $wireframe-footer-border;
  background: $wireframe-footer-bg;
}

.nodeLabelText {
  font-size: 0.75rem;
  font-weight: 600;
  color: $wireframe-footer-text;
}

.calloutTray {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid $wireframe-border;
  background: $wireframe-subtle;
  padding: 8px;
}

.callout {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  width: 100%;
  min-height: 36px;
  padding: 0.25rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  background: $wireframe-bg;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 0.2s ease,
    background-color 0.2s ease;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      border-color: $wireframe-border-medium;
      background: var(--tool-chrome-gray-highlight);
    }
  }

  &:focus:not(:focus-visible) {
    outline: none;
  }

  &:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--tool-chrome-blue) 55%, transparent);
    outline-offset: -2px;
  }
}

.calloutLabel {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.6875rem;
  font-weight: 500;
  color: $wireframe-footer-text;
}

.calloutHint {
  flex-shrink: 0;
  font-size: 0.625rem;
  color: var(--tool-chrome-text-muted);
}
