  @import "./component.css";
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: 'DM Sans', sans-serif; background: #f0f0f0; overflow: hidden; height: 100vh; display: flex; flex-direction: column; user-select: none; }

  /* TOP NAV */
  #topnav {
    height: 44px; background: #fff; border-bottom: 1px solid #ddd;
    display: flex; align-items: center; padding: 0 12px; gap: 10px; z-index: 100; flex-shrink: 0;
  }
  .tinkercad-logo { display: flex; align-items: center; gap: 6px; }
  .logo-tile { width: 13px; height: 13px; font-size: 7px; font-weight: 700; display: flex; align-items: center; justify-content: center; color: #fff; }
  .brand-mark { display: none; }
  .brand-name {
    display: flex; flex-direction: column; line-height: 1.05;
    letter-spacing: -.01em;
  }
  .brand-name .top { font-size: 12px; font-weight: 800; color: #0f172a; }
  .brand-name .sub { font-size: 10px; font-weight: 600; color: #64748b; }
  .project-name { font-size: 13px; font-weight: 500; color: #222; margin-left: 0; }
  .saved-badge { font-size: 11px; color: #888; margin-left: auto; }
  /* Space between brand (KiwisCad) and editable project title */
  .project-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; margin-left: 32px; }
  #proj-save-status { color: #64748b; font-size: 11px; flex-shrink: 0; }

  /* VIEW CONTROLS TOP RIGHT */
  .view-controls { display: flex; align-items: center; gap: 2px; margin-left: 10px; }
  .view-btn {
    width: 32px; height: 32px; border-radius: 6px; border: none; background: transparent;
    cursor: pointer; display: flex; align-items: center; justify-content: center; color: #555;
    transition: background .15s;
  }
  .view-btn:hover { background: #f0f0f0; }
  .view-btn.active { background: #1a73e8; color: #fff; }

  /* ACTION BUTTONS */
  .action-btn {
    display: flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 6px;
    border: 1.5px solid #ccc; background: #fff; font-size: 12px; font-weight: 500;
    cursor: pointer; color: #333; transition: all .15s;
  }
  .action-btn:hover { background: #f5f5f5; border-color: #bbb; }
  .action-btn.sim { background: #1ca24c; border-color: #1ca24c; color: #fff; }
  .action-btn.sim:hover { background: #188f43; }
  .action-btn.sim.running { background: #e53935; border-color: #e53935; }
  .action-btn.sim.loading { background: #f59e0b; border-color: #f59e0b; }
  .sim-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,.45);
    border-top-color: #fff;
    border-radius: 50%;
    display: inline-block;
    animation: sim-spin .8s linear infinite;
  }
  @keyframes sim-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }

  /* TOOLBAR */
  #toolbar {
    height: 42px; background: #fff; border-bottom: 1px solid #ddd;
    display: flex; align-items: center; padding: 0 10px; gap: 2px; z-index: 99; flex-shrink: 0;
  }
  .tool-btn {
    width: 32px; height: 32px; border-radius: 5px; border: none; background: transparent;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: #555; font-size: 14px; transition: background .15s; position: relative;
  }
  .tool-btn:hover { background: #f0f0f0; }
  .tool-btn.active { background: #e8f0fe; color: #1a73e8; }
  .tool-btn:disabled { opacity: .35; cursor: not-allowed; }
  .tool-sep { width: 1px; height: 22px; background: #ddd; margin: 0 4px; }

  /* COLOR PICKER BUTTON */
  .color-pick { display: flex; align-items: center; gap: 3px; padding: 4px 8px; border-radius: 5px; border: 1.5px solid #ccc; background: #fff; cursor: pointer; font-size: 11px; color: #333; }
  .color-dot { width: 14px; height: 14px; border-radius: 3px; background: #22c55e; border: 1px solid #bbb; }
  .line-pick { display: flex; align-items: center; gap: 3px; padding: 4px 8px; border-radius: 5px; border: 1.5px solid #ccc; background: #fff; cursor: pointer; font-size: 11px; color: #333; }

  /* MAIN LAYOUT */
  #main { display: flex; flex: 1; overflow: hidden; }

  /* CANVAS AREA */
  #canvas-wrap {
    flex: 1; background: #e8e8e8; position: relative; overflow: hidden;
    background-image: radial-gradient(circle, #ccc 1px, transparent 1px);
    background-size: 24px 24px;
    cursor: default;
    /* Avoid the browser treating drags as scroll/navigation so pan/zoom stay on the canvas. */
    touch-action: none;
  }
  #canvas-wrap.panning { cursor: grab; }
  #canvas-wrap.panning:active { cursor: grabbing; }

  /* World layer: stable compositing while panning/zooming */
  #canvas {
    transform-origin: 0 0;
    backface-visibility: hidden;
  }
  #canvas-wrap.viewport-interacting #canvas {
    will-change: transform;
  }
  /* Reduce paint cost on animated parts while the viewport is transforming */
  #canvas-wrap.viewport-interacting .comp {
    pointer-events: none;
  }

  /* ZOOM CONTROLS */
  #zoom-controls {
    position: absolute; bottom: 16px; right: 16px; z-index: 52;
    display: flex; flex-direction: column; gap: 6px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.08);
    max-width: 148px;
  }
  #zoom-controls .zoom-row {
    display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 4px;
  }
  .zoom-btn {
    min-width: 32px; height: 32px; padding: 0 6px; background: #fff; border: 1px solid #d1d5db; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 17px;
    font-weight: 600;
    color: #334155; transition: background .15s, border-color .15s;
  }
  .zoom-btn:hover { background: #f8fafc; border-color: #94a3b8; }
  .zoom-btn.zoom-pct { min-width: 52px; font-size: 11px; font-weight: 700; letter-spacing: -0.02em; }
  #zoom-controls .zoom-btn.has-tip { position: relative; }
  #zoom-controls .zoom-btn .tooltip {
    bottom: calc(100% + 8px); font-size: 10px; white-space: nowrap;
  }
  .zoom-slider-label {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); border: 0;
  }
  #zoom-slider {
    width: 100%; height: 6px; cursor: pointer; accent-color: #2563eb;
  }
  .zoom-hint {
    margin: 0; font-size: 9px; line-height: 1.35; color: #64748b; max-width: 130px;
  }
  .zoom-hint kbd {
    display: inline-block; padding: 1px 4px; font-size: 8px; font-family: inherit;
    background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 3px; color: #475569;
  }

  /* WIRE */
  #wire-svg {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    overflow: visible;
    z-index: 6;
    pointer-events: none;
  }
  #wire-hit-svg {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    overflow: visible;
    z-index: 25;
    pointer-events: none;
  }
  #wire-svg path.wire-path-visual {
    pointer-events: none;
    transition: filter 0.14s ease, stroke-width 0.14s ease;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  #wire-hit-svg path.wire-hit-path {
    pointer-events: stroke;
    cursor: pointer;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  #wire-svg path.wire-path-visual.wire-hover {
    filter: drop-shadow(0 0 5px rgba(59, 130, 246, 0.9)) drop-shadow(0 0 14px rgba(59, 130, 246, 0.55));
    stroke-width: 4.8px !important;
    stroke-opacity: 1 !important;
  }
  #wire-svg #temp-wire { pointer-events: none; cursor: default; }

  /* RIGHT SIDEBAR */
  #sidebar {
    --comp-scale: 1;
    width: 180px; background: #fff; border-left: 1px solid #ddd;
    display: flex; flex-direction: column; flex-shrink: 0; z-index: 50;
    position: relative;
  }
  #sidebar-resizer {
    position: absolute;
    left: -3px;
    top: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 52;
    background: transparent;
  }
  #sidebar-resizer:hover {
    background: rgba(26, 115, 232, 0.12);
  }
  #sidebar-header {
    padding: 8px 10px 6px; border-bottom: 1px solid #eee;
    display: flex; align-items: center; justify-content: space-between;
  }
  .sidebar-title { font-size: 11px; font-weight: 600; color: #333; text-transform: uppercase; letter-spacing: .05em; }
  .category-dropdown {
    position: relative;
    margin-top: 4px;
  }
  .category-dropdown-trigger {
    width: 100%;
    border: 1px solid #d6dbe3;
    border-radius: 7px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    color: #1f2937;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
  }
  .category-dropdown-trigger:hover { border-color: #bfc7d2; background: #fff; }
  .category-dropdown.open .category-dropdown-trigger {
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.14);
    background: #fff;
  }
  .category-dropdown-trigger svg {
    width: 12px;
    height: 12px;
    color: #64748b;
    transition: transform .16s ease;
  }
  .category-dropdown.open .category-dropdown-trigger svg { transform: rotate(180deg); }
  .category-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #d8e0ea;
    border-radius: 10px;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.22);
    padding: 5px;
    max-height: 220px;
    overflow: auto;
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
    transform-origin: top center;
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease;
    z-index: 70;
  }
  .category-dropdown.open .category-dropdown-menu {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
  .category-dropdown-item {
    width: 100%;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #334155;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    padding: 8px 10px;
    cursor: pointer;
    display: block;
    transition: background .12s ease, color .12s ease;
  }
  .category-dropdown-item:hover { background: #f1f5f9; color: #0f172a; }
  .category-dropdown-item.active {
    background: #dbeafe;
    color: #1d4ed8;
  }
  #search-wrap { padding: 6px 8px; border-bottom: 1px solid #eee; position: relative; }
  #comp-search {
    width: 100%; padding: 5px 26px 5px 8px; border: 1px solid #ddd; border-radius: 5px;
    font-size: 11px; outline: none; background: #fafafa; color: #333;
  }
  #comp-search:focus { border-color: #1a73e8; background: #fff; }
  .search-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: #999; font-size: 12px; }

  #comp-grid { flex: 1; overflow-y: auto; padding: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: calc(5px * var(--comp-scale)); align-content: start; }
  #comp-grid::-webkit-scrollbar { width: 4px; }
  #comp-grid::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

  .comp-card {
    border: 1px solid #eee; border-radius: 6px; padding: calc(6px * var(--comp-scale)) calc(4px * var(--comp-scale)); text-align: center;
    cursor: grab; background: #fff; transition: all .15s; display: flex; flex-direction: column; align-items: center; gap: 3px;
    min-height: calc(74px * var(--comp-scale));
  }
  .comp-card:hover { border-color: #1a73e8; background: #f0f6ff; }
  .comp-card:active { cursor: grabbing; }
  .comp-card svg,
  .comp-card img { width: calc(36px * var(--comp-scale)); height: calc(36px * var(--comp-scale)); object-fit: contain; }
  .comp-card-name { font-size: calc(9.5px * var(--comp-scale)); color: #444; font-weight: 500; line-height: 1.2; text-align: center; }

  /* SIDEBAR TOGGLE */
  #sidebar-toggle {
    position: absolute; right: 180px; top: 50%; transform: translateY(-50%);
    width: 16px; height: 40px; background: #fff; border: 1px solid #ddd;
    border-right: none; border-radius: 4px 0 0 4px; cursor: pointer; z-index: 51;
    display: flex; align-items: center; justify-content: center; color: #888; font-size: 10px;
  }

  /* TOOLTIP */
  .tooltip {
    position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: #222; color: #fff; font-size: 10px; padding: 3px 7px; border-radius: 4px;
    white-space: nowrap; pointer-events: none; opacity: 0; transition: none; z-index: 999;
  }
  .tool-btn:hover .tooltip { opacity: 1; }
  .has-tip { position: relative; }
  .has-tip:hover .tooltip { opacity: 1; }
  /* Standardize custom tooltips to render below controls. */
  #topnav .view-btn.has-tip .tooltip,
  #toolbar .tool-btn .tooltip,
  #toolbar .color-pick.has-tip .tooltip,
  #toolbar .line-pick.has-tip .tooltip,
  #zoom-controls .zoom-btn.has-tip .tooltip,
  #sidebar .view-btn.has-tip .tooltip {
    top: calc(100% + 6px);
    bottom: auto;
  }
  /* Prevent clipping for the first toolbar button tooltip near left edge. */
  #tool-select .tooltip {
    left: 0;
    transform: none;
  }
  /* Keep top action button tooltips visible under the nav bar. */
  #topnav .action-btn.has-tip .tooltip {
    top: calc(100% + 6px);
    bottom: auto;
  }

  /* SIMPLE POPOVER MENUS */
  .mini-menu {
    position: fixed;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.14);
    overflow: hidden;
    z-index: 400;
    min-width: 180px;
    display: none;
  }
  .mini-menu .item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    font-size: 12px;
    color: #222;
    cursor: pointer;
    user-select: none;
  }
  .mini-menu .item:hover { background: #f5f5f5; }
  .mini-menu .sep { height: 1px; background: #eee; }

  /* TINKERCAD-LIKE POPOVERS (Wire type / Wire color) */
  .tc-pop {
    position: fixed;
    width: 178px;
    background: #fff;
    border: 1px solid #dde3ea;
    border-radius: 5px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
    z-index: 450;
    display: none;
    padding: 5px 0;
  }
  .tc-pop .tc-title {
    font-size: 10px;
    letter-spacing: .08em;
    font-weight: 700;
    color: #334155;
    padding: 5px 11px 6px;
  }
  .tc-pop .tc-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    cursor: pointer;
    user-select: none;
    color: #0f172a;
    font-size: 13px;
    line-height: 1.15;
  }
  .tc-pop .tc-item:hover { background: #f6f8fb; }
  .tc-pop .tc-item.active { color: #3b82f6; font-weight: 700; }
  .tc-pop .tc-icon {
    width: 26px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .tc-pop .tc-icon svg { width: 22px; height: 15px; }
  .tc-pop .tc-swatch {
    width: 20px; height: 20px;
    border-radius: 5px;
    border: 1px solid rgba(15, 23, 42, .12);
    flex-shrink: 0;
  }

  /* Wire type: slightly wider than color for row labels */
  #wiretype-pop { width: 186px; padding: 5px 0; }

  /* Compact Wire Color dropdown */
  #wirecolor-pop { width: 148px; padding: 4px 0; }
  #wirecolor-pop .tc-title { padding: 4px 9px 5px; font-size: 9px; }
  #wirecolor-pop .tc-item { padding: 4px 9px; gap: 6px; font-size: 12px; }
  #wirecolor-pop .tc-swatch { width: 17px; height: 17px; border-radius: 4px; }

  /* SIDEBAR LIST MODE */
  #comp-grid.list-mode { grid-template-columns: 1fr; }
  #comp-grid.list-mode .comp-card { flex-direction: row; justify-content: flex-start; padding: calc(7px * var(--comp-scale)) calc(8px * var(--comp-scale)); gap: calc(8px * var(--comp-scale)); min-height: auto; }
  #comp-grid.list-mode .comp-card svg,
  #comp-grid.list-mode .comp-card img { width: calc(26px * var(--comp-scale)); height: calc(26px * var(--comp-scale)); }
  #comp-grid.list-mode .comp-card-name { font-size: calc(11px * var(--comp-scale)); text-align: left; }

  /* CANVAS NOTES (Tinkercad-style callouts) */
  #notes-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 40;
  }
  .canvas-note {
    position: absolute;
    pointer-events: auto;
    user-select: none;
    touch-action: none;
  }
  .canvas-note.selected .canvas-note-bubble {
    box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.35), 0 8px 24px rgba(15, 23, 42, 0.12);
  }
  .canvas-note:not(.expanded) .canvas-note-bubble,
  .canvas-note:not(.expanded) .canvas-note-tail {
    display: none;
  }
  .canvas-note-tail {
    position: absolute;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 1;
  }
  .canvas-note-tail.tail-up {
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 11px solid #5B8DEF;
    transform: translateX(-50%);
  }
  .canvas-note-tail.tail-up::after {
    content: '';
    position: absolute;
    left: -7px;
    top: 2px;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 9px solid #fff;
  }
  .canvas-note-tail.tail-down {
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 11px solid #5B8DEF;
    transform: translateX(-50%);
  }
  .canvas-note-tail.tail-down::after {
    content: '';
    position: absolute;
    left: -7px;
    top: -11px;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 9px solid #fff;
  }
  .canvas-note-tail.tail-left {
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
    border-right: 11px solid #5B8DEF;
    transform: translateY(-50%);
  }
  .canvas-note-tail.tail-left::after {
    content: '';
    position: absolute;
    left: 2px;
    top: -7px;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-right: 9px solid #fff;
  }
  .canvas-note-tail.tail-right {
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
    border-left: 11px solid #5B8DEF;
    transform: translateY(-50%);
  }
  .canvas-note-tail.tail-right::after {
    content: '';
    position: absolute;
    left: -11px;
    top: -7px;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 9px solid #fff;
  }
  .canvas-note-tail.tail-svg {
    overflow: visible;
  }
  .canvas-note-bubble {
    position: absolute;
    box-sizing: border-box;
    width: auto;
    min-width: 0;
    max-width: 280px;
    background: #fff;
    border: 2px solid #5B8DEF;
    border-radius: 12px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
    z-index: 2;
    cursor: grab;
  }
  .canvas-note-bubble:active { cursor: grabbing; }
  .canvas-note-text {
    display: block;
    box-sizing: border-box;
    width: auto;
    min-width: 0;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.55;
    color: #0f172a;
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    pointer-events: auto;
  }
  .canvas-note-text:empty::before {
    content: 'Write your note here.';
    color: #94a3b8;
    white-space: nowrap;
  }
  .canvas-note-anchor-group {
    position: absolute;
    transform: translate(-50%, -50%);
    cursor: pointer;
    z-index: 3;
  }
  .canvas-note-anchor-group:active { cursor: grabbing; }
  .canvas-note-anchor-badge {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 2px solid #5B8DEF;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
    pointer-events: auto;
    cursor: pointer;
    transform: translate(-50%, -50%);
  }
  .canvas-note-anchor-note-icon {
    width: 24px;
    height: 24px;
    color: #1e293b;
    pointer-events: none;
  }
  .canvas-note-anchor {
    position: relative;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #1e293b;
    box-shadow: 0 0 0 6px rgba(91, 141, 239, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .canvas-note-anchor-minus {
    display: block;
    width: 8px;
    height: 2px;
    background: #1e293b;
    border-radius: 1px;
    pointer-events: none;
  }
  #canvas-wrap.notes-tool-active { cursor: crosshair; }

  /* ICON SIZING (GLOBAL) */
  #topnav svg { width: 16px; height: 16px; }
  #topnav .view-btn svg { width: 18px; height: 18px; }
  #toolbar .tool-btn svg { width: 18px; height: 18px; }
  #toolbar .color-pick svg { width: 16px; height: 16px; }
  #toolbar .line-pick svg { width: 22px; height: 12px; }
  #zoom-controls .zoom-btn svg { width: 16px; height: 16px; }
  #ctx-menu svg.ctx-icon { width: 16px; height: 16px; flex-shrink: 0; }
  #sidebar-header .view-btn svg { width: 14px; height: 14px; }

  /* CONTEXT MENU */
  #ctx-menu {
    position: fixed; background: #fff; border: 1px solid #ddd; border-radius: 7px;
    box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 600; min-width: 140px; overflow: hidden;
    display: none;
  }
  #ctx-menu[data-target="wire"] { min-width: 188px; }
  .ctx-item {
    padding: 7px 14px; font-size: 12px; cursor: pointer; color: #333;
    display: flex; align-items: center; gap: 8px;
  }
  .ctx-item:hover { background: #f5f5f5; }
  .ctx-item.danger { color: #e53935; }
  .ctx-sep { height: 1px; background: #eee; }
  #ctx-menu[data-target="wire"] .ctx-wire-skip { display: none; }
  #ctx-menu[data-target="component"] .ctx-wire-only { display: none; }
  .ctx-menu-label {
    padding: 6px 14px 4px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
    user-select: none;
  }
  .ctx-wire-color-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    padding: 4px 10px 10px;
  }
  .ctx-color-swatch {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 5px;
    cursor: pointer;
    box-sizing: border-box;
  }
  .ctx-color-swatch:hover { border-color: #94a3b8; transform: scale(1.06); }
  .ctx-color-swatch.active { border-color: #1a73e8; box-shadow: 0 0 0 1px #1a73e8; }

  /* CODE PANEL */
  #code-modal #code-resize-handle {
    position: absolute;
    top: 0;
    right: -6px;
    width: 14px;
    height: 100%;
    cursor: ew-resize;
    z-index: 9999;
    touch-action: none;
    pointer-events: auto;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.14) 100%);
  }
  #code-modal #code-resize-handle:hover,
  #code-modal #code-resize-handle.dragging {
    background: linear-gradient(90deg, transparent 0%, rgba(59,130,246,0.45) 100%);
  }
  #code-modal .code-panel-toolbar {
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
    min-height: 40px;
    background: #2d2d2d;
    border-bottom: 1px solid #3d3d3d;
    min-width: 0;
    overflow: hidden;
    position: relative;
    padding-right: 74px;
  }
  #code-modal .code-panel-tab {
    flex: 1 1 0;
    padding: 10px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    color: #888;
    background: transparent;
    border-bottom: 2px solid transparent;
    box-sizing: border-box;
    user-select: none;
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #code-modal .code-panel-tab:hover {
    color: #bbb;
  }
  #code-modal .code-panel-tab.is-active {
    color: #fff;
    background: #1e1e1e;
    border-bottom-color: #1a73e8;
  }
  #code-modal .code-panel-header-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 8px 0 10px;
    border-left: 1px solid #3d3d3d;
    background: #2d2d2d;
    z-index: 2;
  }
  #code-modal .code-panel-copy {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    align-self: center;
    color: #9ca3af;
    background: #383838;
    border: 1px solid #4a4a4a;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
  }
  #code-modal .code-panel-copy:hover {
    color: #e5e7eb;
    background: #454545;
    border-color: #5a5a5a;
  }
  #code-modal .code-panel-copy:active {
    background: #505050;
  }
  #code-modal .code-panel-copy svg {
    display: block;
    width: 14px;
    height: 14px;
  }
  #code-modal .code-panel-copy .code-panel-copy-label {
    display: none;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1;
    white-space: nowrap;
  }
  #code-modal .code-panel-copy.is-copied {
    width: auto;
    min-width: 26px;
    padding: 0 8px;
    color: #4ade80;
    border-color: #22c55e;
    background: #1a2e22;
  }
  #code-modal .code-panel-copy.is-copied .code-panel-copy-icon {
    display: none;
  }
  #code-modal .code-panel-copy.is-copied .code-panel-copy-label {
    display: block;
  }
  #code-modal .code-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    align-self: center;
    color: #ef4444;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 17px;
    line-height: 1;
    font-weight: 600;
    padding: 0;
    transition: color 0.12s ease, background 0.12s ease, transform 0.12s ease;
  }
  @media (max-width: 900px) {
    #code-modal .code-panel-tab {
      font-size: 10px;
      padding: 10px 6px;
    }
    #code-modal .code-panel-header-actions {
      gap: 4px;
      padding: 0 6px 0 8px;
    }
  }
  #code-modal .code-panel-close:hover {
    color: #f87171;
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.25);
    transform: scale(1.05);
  }
  #code-modal #monaco-container {
    flex: 1;
    min-height: 0;
    position: relative;
    background: #1e1e1e;
    overflow: hidden;
  }

  /* SELECTION BOX */
  #sel-box {
    position: absolute; border: 1.5px dashed #1a73e8; background: rgba(26,115,232,.06);
    pointer-events: none; display: none; z-index: 10;
  }

  /* PROPERTIES PANEL (inspector card) */
  #props-panel {
    position: absolute; top: 12px; right: 0;
    width: 220px; max-width: 220px;
    background: #fff;
    border: 2px solid #3b82c4;
    border-radius: 7px;
    box-shadow: 0 5px 16px rgba(15, 23, 42, 0.11);
    padding: 0;
    overflow: hidden;
    font-size: 11px;
    display: none;
    z-index: 100;
  }
  .props-panel-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    background: linear-gradient(180deg, #4f9ae8 0%, #3d86d9 100%);
    color: #fff;
    padding: 8px 10px;
  }
  .props-panel-head h3 {
    margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .props-help-btn {
    flex-shrink: 0;
    width: 20px; height: 20px; border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.9);
    background: transparent; color: #fff;
    font-size: 11px; font-weight: 700; cursor: pointer;
    line-height: 1; display: flex; align-items: center; justify-content: center;
    padding: 0;
  }
  .props-help-btn:hover { background: rgba(255, 255, 255, 0.18); }
  .props-panel-body { padding: 8px 10px 10px; background: #fff; }
  .props-field {
    display: flex; align-items: stretch;
    border: 1px solid #c7dbf4;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
  }
  .props-field-tag {
    flex: 0 0 auto;
    min-width: 64px;
    max-width: 82px;
    background: linear-gradient(180deg, #5c9fd8 0%, #4a8fd0 100%);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 6px 8px;
    display: flex; align-items: center;
  }
  .props-field-input {
    flex: 1;
    border: none;
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 600;
    color: #2563eb;
    outline: none;
    min-width: 0;
    background: #fff;
    font-family: inherit;
  }
  .props-field-input:focus { background: #f8fafc; }
  .props-field-input.props-input-sm { max-width: 62px; font-weight: 600; }
  .props-field-input.props-rotation-input { max-width: 50px; font-weight: 600; }
  .props-rotate-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; flex: 1; min-width: 0; }
  .props-rot-btn {
    flex: 0 0 auto; width: 26px; height: 24px; padding: 0; border: 1px solid #cbd5e1; border-radius: 5px;
    background: #f1f5f9; color: #334155; cursor: pointer; display: flex; align-items: center; justify-content: center;
  }
  .props-rot-btn:hover { background: #e2e8f0; }
  .props-rot-btn svg { width: 14px; height: 14px; }
  .props-field-color-row { align-items: center; gap: 0; }
  .props-field-color-row .props-field-input-color {
    flex: 0 0 40px;
    width: 40px; height: 34px;
    padding: 2px; border: none; cursor: pointer;
    background: #fff;
  }
  .props-field-color-row .props-field-input.props-hex-field {
    font-family: ui-monospace, monospace;
    font-size: 11px;
    text-transform: uppercase;
  }
  .props-field-led-color { align-items: stretch; }
  .props-field-led-color .props-field-tag {
    align-self: stretch;
    display: flex;
    align-items: center;
  }
  .props-led-color-cell {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
  }
  .props-led-color-top {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
  }
  .props-led-swatch {
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 2px solid #94a3b8;
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.5);
  }
  .props-led-color-caption {
    font-size: 11px;
    font-weight: 600;
    color: #334155;
    padding: 0 10px 8px;
    letter-spacing: 0.02em;
  }
  .props-led-color-caption .props-led-hex-part {
    font-family: ui-monospace, monospace;
    text-transform: uppercase;
    color: #64748b;
    font-weight: 600;
  }

  /* TOAST */
  #toast {
    position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%);
    background: #222; color: #fff; padding: 7px 16px; border-radius: 20px; font-size: 12px;
    opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 500; white-space: nowrap;
  }

  /* TOP VIEW MODES */
  body.view-schematic #canvas-wrap {
    background: #f3f4f6;
    background-image: none;
  }

  body.view-schematic #canvas { z-index: 2; }
  body.view-schematic .comp svg { filter: grayscale(1) contrast(1.05) brightness(.92); }
  body.view-schematic #wire-svg .wire-path-visual { stroke: #1a2744 !important; stroke-width: 1.4 !important; stroke-dasharray: none !important; }
  body.view-schematic #wire-svg path.wire-path-visual.wire-hover { stroke-width: 2.5px !important; filter: drop-shadow(0 0 5px rgba(96, 165, 250, 0.55)); }
  body.view-schematic #wire-svg circle { fill: #1a2744 !important; }

  #component-list-view {
    position: absolute; inset: 16px 16px 16px 16px;
    background: #fff;
    border: 1px solid #dbe1ea;
    border-radius: 10px;
    box-shadow: 0 8px 26px rgba(15,23,42,.10);
    z-index: 220;
    display: none;
    overflow: hidden;
  }
  #component-list-view .head {
    padding: 12px 14px;
    font-size: 13px; font-weight: 700; color: #0f172a;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
  }
  #component-list-view .body {
    height: calc(100% - 46px);
    overflow: auto;
    background: #fff;
  }
  #component-list-view table { width: 100%; border-collapse: collapse; font-size: 12px; }
  #component-list-view th, #component-list-view td { padding: 9px 12px; border-bottom: 1px solid #eef2f7; text-align: left; color: #334155; }
  #component-list-view th { position: sticky; top: 0; background: #fff; font-size: 11px; letter-spacing: .02em; color: #64748b; }

  /* SIM INDICATOR */
  #sim-bar {
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: linear-gradient(90deg, #1ca24c, #4ade80, #1ca24c);
    background-size: 200% 100%;
    animation: simrun 1.5s linear infinite;
    display: none; z-index: 200;
  }
  @keyframes simrun { 0%{background-position:0%} 100%{background-position:200%} }


.color-swatch { width:22px;height:22px;border-radius:4px;cursor:pointer;transition:transform .1s; }
.color-swatch:hover { transform:scale(1.15); }

/* ===== TABLET / MOBILE RESPONSIVE ===== */
@media (max-width: 1024px) {
  #sidebar { width: 160px; }
  .project-name-row { margin-left: 16px; }
  #sidebar-toggle { right: 160px; }
  .action-btn {
    padding: 6px 8px;
    font-size: 0;
    gap: 4px;
  }
  .action-btn svg { width: 14px; height: 14px; }
  #sim-label { display: none; }
}

@media (min-width: 768px) and (max-width: 1024px) {
  #topnav {
    height: 48px;
    padding: 0 14px;
  }
  #sidebar {
    width: 200px;
  }
  #sidebar-toggle {
    right: 200px;
  }
  #code-modal {
    width: min(72vw, 560px) !important;
    max-width: 560px !important;
  }
  #props-panel {
    width: min(280px, 38vw) !important;
    max-width: 320px !important;
  }
  #zoom-controls {
    bottom: 16px;
    right: 16px;
  }
}

@media (max-width: 768px) {
  #topnav {
    height: 40px;
    padding: 0 8px;
    gap: 6px;
  }
  .brand-name .sub { display: none; }
  .project-name-row { margin-left: 12px; gap: 4px; }
  .project-name { font-size: 12px; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #proj-save-status { display: none; }
  .view-controls .view-btn:not(.active) { display: none; }
  .view-btn { width: 28px; height: 28px; }
  #toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 6px;
  }
  #toolbar::-webkit-scrollbar { display: none; }
  .tool-btn { width: 28px; height: 28px; flex-shrink: 0; }
  .tool-btn svg { width: 16px; height: 16px; }
  #tool-label { display: none; }
  #sidebar {
    position: fixed !important;
    right: 0;
    top: 82px;
    bottom: 0;
    width: min(280px, 85vw) !important;
    z-index: 200;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  }
  #sidebar-toggle {
    position: fixed !important;
    right: 12px !important;
    bottom: 72px !important;
    top: auto !important;
    transform: none !important;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid #ddd;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    font-size: 14px;
    z-index: 201;
    background: #fff;
  }
  #props-panel {
    position: fixed;
    top: auto !important;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    max-width: none !important;
    border-radius: 12px 12px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  #zoom-controls {
    bottom: 12px;
    right: 12px;
    padding: 6px 8px;
    max-width: 130px;
  }
  .zoom-btn {
    min-width: 28px;
    height: 28px;
    font-size: 15px;
  }
  .zoom-btn.zoom-pct { min-width: 44px; font-size: 10px; }
  #code-modal {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    flex: none !important;
    max-width: none !important;
    z-index: 500 !important;
    border-right: none !important;
  }
  #code-modal #code-resize-handle { display: none; }
}
