.ac {
  --bg: #f3f5fa;
  --dot: #d6dceb;
  --ink: #1a1d2e;
  --muted: #646a82;
  --line: rgba(210, 216, 234, 0.92);
  --line-strong: rgba(182, 190, 216, 0.95);
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-subtle: #eef1f8;
  --accent: #4338b8;
  --accent-hover: #372da3;
  --accent-soft: #eeecff;
  --accent-border: #c5bef7;
  --op-add: #4f46e5;
  --op-sub: #e11d48;
  --op-int: #0284c7;
  --danger: #a6264e;
  --danger-bg: #fff1f5;
  --shadow-shell: 0 20px 50px rgba(22, 27, 54, 0.08), 0 2px 8px rgba(22, 27, 54, 0.04);
  --shadow-float: 0 10px 28px rgba(22, 27, 54, 0.09), 0 2px 6px rgba(22, 27, 54, 0.04);
  --shadow-popover: 0 16px 38px rgba(20, 24, 52, 0.14), 0 2px 8px rgba(20, 24, 52, 0.06);
  --shadow-canvas: 0 18px 44px rgba(18, 22, 46, 0.14), 0 2px 8px rgba(18, 22, 46, 0.06);
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px 20px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.15px, transparent 1.15px);
  background-size: 20px 20px;
  box-shadow: var(--shadow-shell);
  color: var(--ink);
  font: 13.5px/1.45 "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.ac *, .ac *::before, .ac *::after { box-sizing: border-box; }
.ac [hidden] { display: none !important; }
.ac button, .ac input { font: inherit; }
.ac .ac-card-title, .ac p { margin: 0; }
.ac .ac-card-title { font-family: inherit; letter-spacing: normal; }

/* Buttons & Shared Pills */
.ac-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .1s ease, border-color .1s ease, color .1s ease, box-shadow .1s ease, transform .1s ease;
}
.ac-btn svg, .ac-dock-btn svg, .ac-icon-btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}
.ac button:not(:disabled) { cursor: pointer; }
.ac-btn:not(:disabled):hover, .ac-icon-btn:not(:disabled):hover {
  border-color: var(--accent-border);
  background: var(--surface-solid);
  color: var(--accent);
}
.ac button:not(:disabled):active { transform: translateY(1px); }
.ac button:disabled { opacity: .4; cursor: default; }
.ac :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ac-btn.ac-primary {
  border-color: var(--accent);
  background: linear-gradient(135deg, #4f46e5 0%, var(--accent) 100%);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(67, 56, 184, 0.28);
}
.ac-btn.ac-primary:not(:disabled):hover {
  background: linear-gradient(135deg, #4338ca 0%, var(--accent-hover) 100%);
  border-color: var(--accent-hover);
  color: #fff;
  box-shadow: 0 8px 22px rgba(67, 56, 184, 0.36);
}
.ac-btn.ac-primary:disabled { box-shadow: none; }

/* Minimal Top Bar: Undo/Redo Left, 3 Action Buttons Right */
.ac-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.ac-pill-group {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-float);
}
.ac-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 36px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: background-color .1s ease, color .1s ease;
}
.ac-icon-btn:not(:disabled):hover {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}
.ac-pill-divider {
  width: 1px;
  height: 18px;
  background: var(--line);
  margin: 0 2px;
}
.ac-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ac-topbar .ac-actions { justify-content: flex-end; }
.ac-file { display: none; }

/* Workspace Stage */
.ac-workbench {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}
.ac-workbench[data-advanced="true"] {
  grid-template-columns: minmax(0, 1fr) 232px;
  align-items: start;
}
.ac-canvas-col {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.ac-stage {
  position: relative;
  width: 100%;
  min-height: 300px;
  display: grid;
  place-items: center;
  padding: 8px 190px;
  border-radius: 18px;
  transition: background-color .15s ease, box-shadow .15s ease;
}
.ac-workbench[data-advanced="true"] .ac-stage {
  padding: 8px 10px;
}
.ac-stage[data-dragging="true"] {
  background: rgba(79, 70, 229, 0.08);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.ac-stage canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 465px;
  touch-action: none;
  border-radius: 10px;
  cursor: crosshair;
  box-shadow: var(--shadow-canvas);
  background-color: #f8f9fd;
  background-image: conic-gradient(#e4e7f2 25%, #f8f9fd 0 50%, #e4e7f2 0 75%, #f8f9fd 0);
  background-size: 16px 16px;
}
.ac-stage canvas[data-tool="image"],
.ac-stage canvas[data-tool="preset"] { cursor: move; }
.ac-stage canvas[data-tool="preset"][data-cursor="nwse"] { cursor: nwse-resize; }
.ac-stage canvas[data-tool="preset"][data-cursor="nesw"] { cursor: nesw-resize; }
.ac-stage canvas[data-tool="preset"][data-cursor="ew"] { cursor: ew-resize; }
.ac-stage canvas[data-tool="preset"][data-cursor="ns"] { cursor: ns-resize; }
.ac-stage canvas[data-tool="edit"] { cursor: default; }

/* Contextual Floating Micro-Pill */
.ac-context-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  max-width: 100%;
  min-height: 36px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(14px);
  box-shadow: 0 6px 18px rgba(22, 27, 54, 0.06);
}
.ac-transform,
.ac-pen-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
}
.ac-transform label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
}
.ac-transform input[type="range"] {
  width: min(124px, 26vw);
  accent-color: var(--accent);
  cursor: pointer;
}
.ac-scale-badge {
  min-width: 38px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.ac-btn-mini {
  min-height: 26px;
  padding: 0 10px;
  font-size: 12px;
}
.ac-btn-accent {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.ac-btn-accent:not(:disabled):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}
.ac-hint {
  color: var(--muted);
  font-size: 12.5px;
}
.ac-context-sep {
  width: 1px;
  height: 15px;
  background: var(--line);
}

/* Single Unified Bottom Floating Dock (Simple & Custom Swap Cleanly) */
.ac-dock-wrap {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}
.ac-dock {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 6px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-float);
}
.ac-dock-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.ac-dock-divider {
  width: 1px;
  height: 30px;
  margin: 0 4px;
  background: var(--line);
  flex: none;
}
.ac-dock-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 60px;
  height: 54px;
  padding: 6px 9px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.1;
  white-space: nowrap;
  transition: background-color .1s ease, color .1s ease, border-color .1s ease, box-shadow .1s ease;
}
.ac-dock-btn svg {
  width: 19px;
  height: 19px;
}
.ac-dock-btn:not(:disabled):hover {
  background: var(--surface-subtle);
  color: var(--ink);
}
.ac-dock-btn[aria-pressed="true"],
.ac-dock-btn[aria-expanded="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(67, 56, 184, 0.1);
}

/* Segmented Boolean Pills inside Custom Dock */
.ac-bool-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border-radius: 14px;
  background: var(--surface-subtle);
}
.ac-bool-group .ac-dock-btn {
  min-width: 56px;
  height: 48px;
  padding: 5px 8px;
  border-radius: 11px;
}
.ac-bool-group .ac-dock-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, #4f46e5 0%, var(--accent) 100%);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(67, 56, 184, 0.25);
}
.ac-bool-group .ac-dock-btn[data-op="subtract"][aria-pressed="true"] {
  background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
  border-color: #e11d48;
  box-shadow: 0 4px 12px rgba(225, 29, 72, 0.25);
}
.ac-bool-group .ac-dock-btn[data-op="intersect"][aria-pressed="true"] {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  border-color: #0284c7;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
}

.ac-dock-done {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
  font-weight: 600;
}
.ac-dock-done:not(:disabled):hover {
  background: #e3dfff;
  color: var(--accent-hover);
}

/* Shape Picker Popover above Custom Dock */
.ac-shape-anchor {
  position: relative;
  display: inline-flex;
}
.ac-shape-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 4px;
  padding: 7px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-popover);
}
.ac-shape-popover .ac-dock-btn {
  min-width: 68px;
  height: 52px;
  border-radius: 12px;
}

/* Unified Floating Right Inspector Card (Preview + Minimal Contour Layers) */
.ac-side-stack {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 176px;
  z-index: 4;
}
.ac-workbench[data-advanced="true"] .ac-side-stack {
  position: static;
  width: 100%;
}
.ac-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-float);
  overflow: hidden;
}
.ac-card-section {
  padding: 10px 11px 11px;
}
.ac-card-section + .ac-card-section {
  border-top: 1px solid var(--line);
}
.ac-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}
.ac-card-head .ac-card-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}
.ac-proof {
  display: grid;
  place-items: center;
  height: 124px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background-color: #f9faff;
  background-image: conic-gradient(#e6e9f3 25%, #f9faff 0 50%, #e6e9f3 0 75%, #f9faff 0);
  background-size: 14px 14px;
  overflow: hidden;
}
.ac-proof canvas {
  max-width: calc(100% - 14px);
  max-height: 110px;
}

/* Minimal Header Micro-Actions & Layer List */
.ac-head-tools {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.ac-chip-btn {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-solid);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  transition: border-color .1s ease, color .1s ease, background-color .1s ease;
}
.ac-chip-btn:not(:disabled):hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
}
.ac-paths {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
  max-height: 230px;
  overflow: auto;
}
.ac-layer-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 3px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.72);
  transition: background-color .1s ease, border-color .1s ease, opacity .1s ease;
}
.ac-layer-row[data-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}
.ac-layer-row[data-dragging="true"] {
  opacity: .45;
  border-style: dashed;
  border-color: var(--accent-border);
}
.ac-layer-row[data-drop="before"]::before,
.ac-layer-row[data-drop="after"]::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  height: 2px;
  border-radius: 999px;
  background: var(--accent);
  pointer-events: none;
  z-index: 2;
}
.ac-layer-row[data-drop="before"]::before { top: -3px; }
.ac-layer-row[data-drop="after"]::after { bottom: -3px; }
.ac-layer-grip {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 24px;
  border-radius: 6px;
  color: var(--muted);
  opacity: .45;
  cursor: grab;
  touch-action: none;
  flex: none;
  transition: opacity .1s ease, color .1s ease;
}
.ac-layer-grip svg {
  width: 12px;
  height: 12px;
}
.ac-layer-row:hover .ac-layer-grip,
.ac-layer-row[data-selected="true"] .ac-layer-grip {
  opacity: .9;
  color: var(--ink);
}
.ac-layer-grip:active { cursor: grabbing; }
.ac-layer-select {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.ac-layer-row[data-selected="true"] .ac-layer-select {
  color: var(--accent);
  font-weight: 600;
}
.ac-op-badge {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  flex: none;
}
.ac-op-badge[data-op="add"] { background: var(--op-add); }
.ac-op-badge[data-op="subtract"] { background: var(--op-sub); }
.ac-op-badge[data-op="intersect"] { background: var(--op-int); }
.ac-layer-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ac-layer-tools {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  flex: none;
}
.ac-layer-act {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity .1s ease, background-color .1s ease, color .1s ease;
}
.ac-layer-act svg {
  width: 12px;
  height: 12px;
}
.ac-layer-row:hover .ac-layer-act,
.ac-layer-row[data-selected="true"] .ac-layer-act,
.ac-layer-row:focus-within .ac-layer-act {
  opacity: .85;
}
.ac-layer-act:disabled {
  opacity: .2 !important;
  cursor: default;
}
.ac-layer-row:not(:hover):not([data-selected="true"]):not(:focus-within) .ac-layer-act:disabled {
  opacity: 0 !important;
}
.ac-layer-act:not(:disabled):hover {
  opacity: 1;
  background: var(--accent-soft);
  color: var(--accent);
}
.ac-layer-remove {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  flex: none;
  opacity: .6;
  transition: opacity .1s ease, background-color .1s ease, color .1s ease;
}
.ac-layer-row:hover .ac-layer-remove,
.ac-layer-row[data-selected="true"] .ac-layer-remove,
.ac-layer-remove:focus-visible {
  opacity: 1;
}
.ac-layer-remove:hover {
  background: var(--danger-bg);
  color: var(--danger);
}
@media (hover: none) {
  .ac-layer-act { opacity: .8; }
  .ac-layer-grip { opacity: .8; }
}
.ac-empty-layers {
  padding: 14px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* Status Pill (Collapsed cleanly when empty) */
.ac-status {
  margin: 10px auto 0 !important;
  width: fit-content;
  max-width: 100%;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(22, 27, 54, 0.06);
}
.ac-status:empty { display: none; }
.ac-status[data-error="true"] {
  border-color: rgba(166, 38, 78, 0.25);
  background: var(--danger-bg);
  color: var(--danger);
}

/* Medium Desktop */
@media (max-width: 1040px) {
  .ac-stage { padding: 6px 180px 6px 12px; }
  .ac-stage canvas { max-height: 410px; }
  .ac-dock-btn { min-width: 54px; padding: 6px 7px; }
}

/* Tablet / Narrow Split */
@media (max-width: 900px) {
  .ac {
    margin: 8px auto;
    padding: 14px;
    border-radius: 20px;
  }
  .ac-workbench[data-advanced="true"] {
    grid-template-columns: minmax(0, 1fr);
  }
  .ac-stage { padding: 4px 0; }
  .ac-side-stack {
    position: static;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
  }
  .ac-workbench[data-advanced="false"] .ac-card-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
  }
  .ac-workbench[data-advanced="false"] .ac-card-head {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 0;
  }
  .ac-workbench[data-advanced="false"] .ac-proof {
    width: 78px;
    height: 62px;
    border-radius: 10px;
  }
  .ac-workbench[data-advanced="false"] .ac-proof canvas {
    max-width: 68px;
    max-height: 54px;
  }
}

/* Mobile Layout (390px and below) */
@media (max-width: 640px) {
  .ac {
    margin: 0 auto;
    padding: 12px 10px 14px;
    border-radius: 16px;
  }
  .ac-topbar {
    gap: 5px;
    margin-bottom: 10px;
    flex-wrap: nowrap;
  }
  .ac-topbar .ac-actions {
    gap: 4px;
    flex-wrap: nowrap;
  }
  .ac-btn {
    min-height: 32px;
    padding: 0 8px;
    font-size: 11.5px;
    gap: 4px;
  }
  .ac-topbar .ac-btn svg { display: none; }
  .ac-icon-btn {
    min-width: 28px;
    height: 28px;
    padding: 0 5px;
  }
  .ac-icon-btn span { display: none; }
  .ac-stage { min-height: 210px; }
  .ac-stage canvas { max-height: 360px; }
  .ac-context-pill {
    width: 100%;
    border-radius: 16px;
    padding: 7px 10px;
    gap: 6px 10px;
  }
  .ac-context-sep { display: none; }
  .ac-dock {
    display: flex;
    flex-direction: column;
    width: 100%;
    border-radius: 18px;
    padding: 6px;
    gap: 5px;
  }
  .ac-dock-divider { display: none; }
  .ac-dock-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 4px;
  }
  .ac-dock-modes-simple {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding-top: 5px;
    border-top: 1px solid var(--line);
  }
  .ac-bool-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    padding: 3px;
  }
  .ac-shape-anchor {
    width: 100%;
  }
  .ac-dock-btn {
    flex-direction: row;
    min-width: 0;
    width: 100%;
    height: 42px;
    padding: 0 6px;
    gap: 5px;
    border-radius: 12px;
    font-size: 12px;
  }
  .ac-bool-group .ac-dock-btn {
    height: 38px;
    border-radius: 10px;
  }
  .ac-dock-btn svg {
    width: 16px;
    height: 16px;
  }
  .ac-shape-popover {
    left: 0;
    transform: none;
    grid-template-columns: repeat(2, minmax(84px, 1fr));
  }
}

@media (max-width: 440px) {
  .ac { padding: 10px 8px 14px; }
  .ac-topbar .ac-btn { padding: 0 7px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .ac-btn, .ac-dock-btn, .ac-icon-btn, .ac-stage, .ac-layer-row, .ac-layer-act, .ac-layer-grip, .ac-layer-remove, .ac-chip-btn {
    transition: none;
  }
}