﻿/* ========== EXASUB CIRCUIT CREATOR (Light Glass Theme) ========== */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", "Segoe UI", sans-serif;
  background: #f3f6fa;
  overflow: hidden;
}

/* ===== HEADER & BRAND ===== */
header {
  display: block; /* no layout impact */
  background: transparent;
  color: #1a1a1a;
  padding: 0;
  border: none;
}

#brandBanner {
  font-size: 1.8em;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #007aff;
  text-transform: uppercase;
  margin-bottom: 16px;
  user-select: none;
}

/* ===== TOOLBAR ===== */
:root { --toolbar-height: 52px; --toolbar-gap: 16px; }
@supports (bottom: env(safe-area-inset-bottom)) {
  :root { --toolbar-gap: max(16px, env(safe-area-inset-bottom)); }
}
#toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;         /* keep single row */
  overflow-x: auto;          /* allow horizontal scroll instead of wrapping */
  overflow-y: hidden;
  white-space: nowrap;
  align-items: center;
  gap: 2px;
  padding: 3px 6px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px; 
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  position: fixed;
  bottom: var(--toolbar-gap);
  left: 12px;
  right: auto;
  z-index: 1000;
}

/* Floating override: let toolbar be a compact panel that can be moved */
#toolbar.floating { left: 12px; right: auto; bottom: calc(var(--toolbar-gap) + 56px); max-width: 95vw; }

/* Small draggable FAB to open toolbar */
.toolbar-fab {
  position: fixed;
  top: 20px;
  left: 25%;
  transform: translateX(-50%);
  bottom: auto;
  right: auto;
  z-index: 2147483000;
  width: 25px; height: 25px;
  border-radius: 26px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  font-weight: 800;
  cursor: pointer;
}

/* Toolbar dropdown (hamburger menu) */
.toolbar-dropdown {
  position: fixed;
  bottom: calc(var(--toolbar-height) + var(--toolbar-gap)); /* just above bottom toolbar */
  right: 16px; /* align near zoom/right side by default */
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 8px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toolbar-dropdown .row { display:flex; gap:6px; }

/* ===== Windows 98 Minimal Theme ===== */
.theme-win98 { font-family: Tahoma, "MS Sans Serif", system-ui, sans-serif; }
.theme-win98 #toolbar {
  background: #c0c0c0;
  border: 2px solid #ffffff;
  box-shadow: inset -1px -1px #808080, inset 1px 1px #ffffff;
  border-radius: 0;
  gap: 6px;
  padding: 6px;
}
.theme-win98 .tool-group {
  background: #c0c0c0;
  border-radius: 0;
  border: 2px solid #ffffff;
  box-shadow: inset -1px -1px #808080, inset 1px 1px #ffffff;
  gap: 4px;
  padding: 2px 3px;
}
.theme-win98 .tool { display:flex; flex-direction:column; align-items:center; justify-content:center; width:40px; height:40px; border-radius:6px; border:1px solid #e5e7eb; cursor:pointer; background:#f8fafc; box-shadow:none; transition: background .12s ease, color .12s ease, border-color .12s ease; color:#1f2937; }
.theme-win98 .tool:hover { filter: brightness(1.05); }
.theme-win98 .tool:active,
.theme-win98 .tool.active {
  border-color: #808080 #ffffff #ffffff #808080; /* pressed */
  background: #c0c0c0;
  color: #000;
}
.theme-win98 .icon { font-size: 14px; line-height: 1; }
.theme-win98 .label { display: none; }

/* Mini toolbars */
.theme-win98 #inlineTextToolbar,
.theme-win98 #wireToolbar,
.theme-win98 #shapeToolbar,
.theme-win98 #shapesToolbar {
  background: #c0c0c0 !important;
  border: 2px solid #ffffff !important;
  box-shadow: inset -1px -1px #808080, inset 1px 1px #ffffff !important;
  border-radius: 0 !important;
}
.theme-win98 #inlineTextToolbar button,
.theme-win98 #wireToolbar button,
.theme-win98 #shapeToolbar button,
.theme-win98 #shapesToolbar button {
  border: 2px solid;
  border-color: #ffffff #808080 #808080 #ffffff;
  background: #c0c0c0;
  border-radius: 0;
  padding: 2px 4px;
  min-width: 20px;
  height: 20px;
}
.theme-win98 #inlineTextToolbar button:active,
.theme-win98 #wireToolbar button:active,
.theme-win98 #shapeToolbar button:active,
.theme-win98 #shapesToolbar button:active {
  border-color: #808080 #ffffff #ffffff #808080;
}
.theme-win98 #inlineTextToolbar input,
.theme-win98 #wireToolbar input,
.theme-win98 #shapeToolbar input,
.theme-win98 #shapeToolbar select {
  border: 2px solid #ffffff;
  box-shadow: inset -1px -1px #808080, inset 1px 1px #ffffff;
  background: #fff;
  border-radius: 0;
  height: 18px;
}

/* Zoom buttons */
.theme-win98 .zoom-btn {
  border: 2px solid #ffffff;
  box-shadow: inset -1px -1px #808080, inset 1px 1px #ffffff;
  background: #c0c0c0;
  border-radius: 0;
}

/* Shapes and text boxes keep thin borders to match */
.theme-win98 .textbox,
.theme-win98 .callout,
.theme-win98 .shape {
  border: 2px solid #ffffff;
  box-shadow: inset -1px -1px #808080, inset 1px 1px #ffffff;
  background: #ffffff;
  border-radius: 0;
}

.tool-group { display:flex; align-items:center; gap:4px; padding:0; border:0; background:transparent; border-radius:0; position:relative; }

/* Collapsible groups: when collapsed, hide buttons */
.tool-group.collapsed { padding: 2px 6px; }
.tool-group.collapsed .tool { display:flex; flex-direction:column; align-items:center; justify-content:center; width:40px; height:40px; border-radius:6px; border:1px solid #e5e7eb; cursor:pointer; background:#f8fafc; box-shadow:none; transition: background .12s ease, color .12s ease, border-color .12s ease; color:#1f2937; }
.tool-group.collapsed::after { content: ""; }
.tool-group .group-header { display:none; }

.tool { display:flex; flex-direction:column; align-items:center; justify-content:center; width:40px; height:40px; border-radius:6px; border:1px solid #e5e7eb; cursor:pointer; background:#f8fafc; box-shadow:none; transition: background .12s ease, color .12s ease, border-color .12s ease; color:#1f2937; }
.tool:hover { background: #eef2f7; border-color: #d1d5db; }
.tool.active { background: #2563eb; border-color: #1d4ed8; color: #fff; }
.icon { font-size: 20px; line-height: 1; }
.label {
  font-size: 9px;
  margin-top: 2px;
  display: none; /* hide labels by default to save space */
}
.tool:hover .label { display: block; }

/* ===== COLOR TOOLS ===== */
#colorSection {
  display: flex;
  flex-direction: row; /* compact in one line */
  align-items: center;
  gap: 6px;
}
.color-swatches {
  display: flex;
  gap: 4px; /* tighter spacing */
}
.swatch {
  width: 16px;  /* smaller dots */
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(0,0,0,0.15);
  transition: transform 0.2s;
}
.swatch:hover {
  transform: scale(1.2);
  border-color: #007aff;
}
#wireColor, #wireThickness {
  cursor: pointer;
  accent-color: #007aff;
  border-radius: 8px;
  border: none;
}
/* compact color input as a round swatch */
#wireColor {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #e5e7eb;
  overflow: hidden;
  background: none;
}
#wireColor::-webkit-color-swatch-wrapper { padding: 0; }
#wireColor::-webkit-color-swatch { border: none; border-radius: 50%; }

/* compact thickness slider */
#wireThickness { width: 80px; height: 20px; }

/* optional: youtube embed wrapper */
.youtube-embed { position: absolute; box-sizing: border-box; padding: 12px; border: 1px solid #dde3ee; border-radius: 10px; background: linear-gradient(to bottom, rgba(0,0,0,0.04), rgba(0,0,0,0.02)); cursor: move; }
.youtube-embed.selected { border-color: #2563eb; box-shadow: inset 0 0 0 2px rgba(37,99,235,0.15); }
.youtube-embed .yt-inner { position: absolute; top: 12px; left: 12px; right: 12px; bottom: 12px; cursor: default; }
.youtube-embed .yt-inner iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ===== MAIN LAYOUT ===== */
/* Fill the viewport above the bottom-fixed toolbar */
main { display:flex; position: fixed; top: 0; left: 0; right: 0; bottom: calc(var(--toolbar-height) + var(--toolbar-gap)); padding-top: 0; height: auto; min-height: 0; }

/* ===== PALETTE ===== */
#palette {
  width: 240px;
  flex: 0 0 240px;
  background: #ffffff;
  border-right: 1px solid #e1e4ec;
  overflow-y: auto;
  height: 100%;
  padding: 8px 0 20px 0;
  box-shadow: 3px 0 6px rgba(0,0,0,0.05);
  min-height: 0;
}
/* Slim toggle tab for palette (outside sidebar) */
.palette-tab {
  position: absolute;
  left: 240px; /* aligns with sidebar edge when open */
  top: 50%;
  width: 16px;
  height: 64px;
  background: #007aff;
  color: #fff;
  border-radius: 0 6px 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.2);
  user-select: none;
  z-index: 300;
}
/* Hide old zoom group in toolbar (moved to canvas) */
#zoomTools { display: none !important; }
/* Show Pages group in toolbar */
#pagesTools { display: flex !important; }

/* Scrollable workspace viewport */
#workspace-container {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #fafafa;
  min-width: 0;
  height: 100%;
}
#palette.collapsed {
  flex: 0 0 0 !important;
  width: 0 !important;
  min-width: 0 !important;
  padding: 0 !important;
  border-right: none !important;
  overflow: hidden !important;
}
/* when collapsed, tab will be moved by JS to left:0 */
#palette details {
  margin: 8px;
  border: 1px solid #e1e5ef;
  border-radius: 6px;
  background: #f9fbff;
}
#layersPanel { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
#layersDetails {
  position: static;
  background: transparent;
  border: none;
  box-shadow: none;
}
#layersDetails[open] > summary { cursor: pointer; list-style: none; }
#layersDetails > summary::-webkit-details-marker { display: none; }
#layersDetails > summary { padding: 6px 10px; font-weight: 700; color: #0056d8; background: #eef4ff; border-bottom: 1px solid #e1e5ef; border-radius: 6px; }
.layer-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding: 6px 8px; background: #fff; border: 1px solid #e1e5ef; border-radius: 6px; }
.layer-row label { display: flex; align-items: center; gap: 8px; }
.layer-row input[type="checkbox"] { accent-color: #007aff; transform: scale(1.15); }
#palette summary {
  font-weight: 600;
  padding: 8px 12px;
  background: #eef4ff;
  color: #0056d8;
  cursor: pointer;
  border-bottom: 1px solid #cfd8ea;
  user-select: none;
}
/* Components categories (Blockly-like pills) */
/* Blockly-like vertical category palette */
.comp-cats { display:flex; flex-direction: column; gap:6px; padding:6px 8px; }
.comp-cat-group { display:block; }
.comp-cat { 
  --cat-color: #4c6ef5;
  width: 100%;
  text-align: left;
  border: 1px solid #dbe3f2;
  border-left: 6px solid var(--cat-color);
  background:#f8fbff;
  color:#1f2937;
  padding:8px 10px;
  border-radius:8px;
  font-size:12px;
  cursor:pointer;
  user-select:none;
}
.comp-cat:hover { background:#eef5ff; }
.comp-cat.active { background:#e8f0ff; border-color: var(--cat-color); box-shadow: inset 0 0 0 1px rgba(76,110,245,0.2); }
.comp-items { display:none !important; padding:6px 6px 10px 20px; }
.comp-cat-group.active .comp-items { display:grid !important; }
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  padding: 8px;
}
.thumb {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border: 1px solid #ccd5ea;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.thumb:hover {
  transform: scale(1.08);
  box-shadow: 0 0 10px rgba(0,86,255,0.4);
}
/* === COMPONENT THUMB WITH LABEL === */
.thumb-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin: 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: #333;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.thumb-item:hover {
  transform: translateY(-3px);
}

.thumb-item img.thumb {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border: 1px solid #ccd5ea;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.thumb-item span {
  margin-top: 4px;
  font-size: 11px;
  color: #444;
}

/* Search highlight animation */
.comp-hit { animation: compFlash 1.2s ease 1; }
@keyframes compFlash { 0%{ box-shadow: 0 0 0 0 rgba(37,99,235,0.0);} 30%{ box-shadow: 0 0 0 4px rgba(37,99,235,0.35);} 100%{ box-shadow: 0 0 0 0 rgba(37,99,235,0.0);} }

#addCustomBtn {
  display: block;
  width: calc(100% - 20px);
  margin: 10px;
  padding: 8px;
  background: linear-gradient(90deg, #007aff, #009cff);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  transition: transform 0.2s;
}
#addCustomBtn:hover {
  transform: scale(1.04);
}

/* ===== WORKSPACE ===== */
#workspace {
  flex: 1;
  position: relative;
  background: #f8faff;
  background-image:
    linear-gradient(to right, rgba(0,0,0,0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0,0,0,0.05) 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: hidden;
  z-index: 1;
}

/* Text label enhancements */
.text-label { padding: 4px 6px; background: #ffffffcc; border: 1px solid #e3e7f0; border-radius: 6px; }
.text-label.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; white-space: pre; }
.text-label .tl-gutter { position: absolute; left: 0; top: 0; bottom: 0; width: 32px; color: #8b949e; text-align: right; padding: 4px 6px 4px 4px; border-right: 1px solid #e1e4ec; background: #f7f9fc; display: none; line-height: 1.4; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; white-space: pre; }
.text-label.with-lines .tl-gutter { display: block; }
.text-label .tl-body { display: block; outline: none; min-width: 40px; min-height: 20px; }
.text-label.with-lines .tl-body { margin-left: 38px; }

/* Rich Text Box */
.textbox { position:absolute; background:transparent; border:1px solid #d9e0ef; border-radius:8px; box-shadow:0 2px 8px rgba(0,0,0,0.08); padding:6px; min-width:140px; min-height:60px; }
.textbox, .callout { z-index: 30; }
.textbox.code-theme-dark { background:#0d1117; color:#c9d1d9; border-color:#30363d; }
.textbox.code-theme-light { background:#ffffff; color:#111; }
.textbox .tb-body { min-height:40px; outline:none; line-height:1.4; white-space:pre; }
.textbox pre { white-space: pre-wrap; margin: 0; padding: 0; background: transparent; }
/* Keep Prism blocks unpadded inside TextBox; weâ€™ll pad the container instead */
.textbox pre[class*="language-"] { overflow: auto; }
/* Leave Prism's own padding/background intact; only adjust gutter offset when in code mode */
/* Plain text: no extra top offset */
.textbox.with-lines .tb-gutter { padding-top: 0; }
/* Code mode (Prism pre has ~1em top padding): nudge gutter to match */
.textbox.code.with-lines .tb-gutter { padding-top: 1em; }
/* Ensure highlighted code inherits the same metrics as body when showing line numbers */
.textbox.with-lines pre, .textbox.with-lines pre code { line-height: inherit; font-size: inherit; font-family: inherit; }
.textbox.with-lines pre, .textbox.with-lines pre code { line-height: inherit; font-size: inherit; font-family: inherit; }
.textbox .tb-gutter { position:absolute; left:0; top:0; bottom:0; width:32px; color:#8b949e; text-align:right; padding:4px 6px 4px 4px; border-right:1px solid #e1e4ec; background:#f7f9fc; display:none; line-height:1.4; font-size:12px; font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; white-space:pre; }
.textbox.with-lines .tb-gutter { display:block; }
.textbox.with-lines .tb-body { margin-left:38px; }

/* Callout */
.callout { position:absolute; background:#fff; border:1px solid #d9e0ef; border-radius:10px; box-shadow:0 2px 8px rgba(0,0,0,0.08); padding:8px; min-width:160px; min-height:70px; }
.callout .co-body { outline:none; min-height:40px; line-height:1.4; }
.callout .co-tail { position:absolute; width:0; height:0; border:10px solid transparent; border-top-color:#d9e0ef; bottom:-20px; left:24px; }
.callout { --tail-fill:#fff; }
.callout .co-tail::after { content:''; position:absolute; left:-9px; top:-11px; border:9px solid transparent; border-top-color:var(--tail-fill); }

/* ===== WIRES & COMPONENTS ===== */
#wires {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 20;
  pointer-events: none;
}
#wires line { pointer-events: stroke; }
#wires polyline { pointer-events: stroke; }
#wires path { pointer-events: stroke; }

.component {
  position: absolute;
  cursor: move;
  user-select: none;
  touch-action: none;
  z-index: 10;
  border: 1px dashed transparent;
  transition: transform 0.1s ease;
}
.component.dragging { opacity: 0.8; transform: scale(1.05); }
.component.selected { border-color: #007aff; }
.component.selected-group { border-color: #2f9e44; }
.tool:disabled { opacity: 0.45; cursor: not-allowed; }

/* Extra polygon shapes */
.shape.polygon.triangle { clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.shape.polygon.parallelogram { clip-path: polygon(20% 0, 100% 0, 80% 100%, 0 100%); }
.shape.polygon.hexagon { clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }

/* ===== RESIZE HANDLES ===== */
.resize-handle {
  width: 10px;
  height: 10px;
  background: #007aff;
  border: 1px solid #fff;
  position: absolute;
  z-index: 999;
  border-radius: 2px;
  box-shadow: 0 0 3px rgba(0,0,0,0.3);
}
.resize-handle.nw { cursor: nw-resize; }
.resize-handle.ne { cursor: ne-resize; }
.resize-handle.sw { cursor: sw-resize; }
.resize-handle.se { cursor: se-resize; }
.wire-point-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #0a84ff;
  box-shadow: 0 0 0 1px rgba(10,132,255,0.15);
  z-index: 1000;
  cursor: grab;
}
.wire-point-handle:active { cursor: grabbing; }

/* Crop overlay styling */
#cropOverlay {
  box-sizing: border-box;
}
/* ===== WATERMARK INSIDE WORKSPACE ===== */
#watermark {
  position: absolute;
  bottom: 20px;
  right: 25px;
  font-size: 32px;
  font-weight: 800;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.07);
  letter-spacing: 1px;
  font-family: "Inter", "Segoe UI", sans-serif;
  pointer-events: none;
  user-select: none;
  z-index: 0;
  animation: watermarkGlow 8s ease-in-out infinite alternate;
}

@keyframes watermarkGlow {
  0% { color: rgba(0, 0, 0, 0.07); }
  100% { color: rgba(0, 122, 255, 0.1); }
}
/* ===== WATERMARK FIX ===== */
#workspace {
  position: relative;
  background-color: #fafafa;
  background-image: linear-gradient(0deg, #e0e0e0 1px, transparent 1px),
                    linear-gradient(90deg, #e0e0e0 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: hidden;
}

#watermark {
  position: absolute;
  bottom: 25px;
  right: 30px;
  font-size: 34px;
  font-weight: 800;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.07);
  font-family: "Inter", "Segoe UI", sans-serif;
  pointer-events: none;
  user-select: none;
  z-index: 50; /* Ã°Å¸â€˜Ë† Forces it above SVG wires and components */
  animation: watermarkGlow 8s ease-in-out infinite alternate;
}

@keyframes watermarkGlow {
  0%   { color: rgba(0, 0, 0, 0.07); }
  100% { color: rgba(0, 122, 255, 0.12); }
}
/* ===== BRAND OVERLAY WATERMARK ===== */
#brandOverlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-25deg);
  font-size: 90px;
  color: rgba(0, 0, 0, 0.06);
  font-weight: 900;
  letter-spacing: 5px;
  text-transform: uppercase;
  font-family: "Inter", "Segoe UI", "Arial Black", sans-serif;
  pointer-events: none;
  user-select: none;
  z-index: 5;
  white-space: nowrap;
  mix-blend-mode: multiply;
  opacity: 0.6;
}
@keyframes watermarkFloat {
  0% { transform: translate(-50%, -50%) rotate(-25deg) scale(1); opacity: 0.6; }
  100% { transform: translate(-50%, -50%) rotate(-25deg) scale(1.05); opacity: 0.55; }
}

#brandOverlay {
  animation: watermarkFloat 6s ease-in-out infinite alternate;
}

/* ===== WORKSPACE ZOOM AND SCROLL ===== */
#workspace {
  position: relative;
  width: 2000px;   /* large virtual canvas */
  height: 1400px;
  background-color: #fafafa;
  background-image: linear-gradient(0deg, #e0e0e0 1px, transparent 1px),
                    linear-gradient(90deg, #e0e0e0 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: visible;
  transform-origin: 0 0;
  transition: transform 0.2s ease;
}

/* Hide grid when toggled off */
#workspace.no-grid { background-image: none !important; }

/* Full-viewport workspace; floating toolbar overlays content */
main { display:flex; position: fixed; top: 0; left: 0; right: 0; bottom: 0; padding-top: 0; height: auto; }

#palette {
  width: 240px;
  background: #fff;
  border-right: 1px solid #e1e4ec;
  overflow-y: auto;
}

/* Ã°Å¸â€˜â€¡ Viewport scrolls and zooms only the workspace */
#viewport {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #fafafa;
}


/* === TOOLBAR COMPACT MODE === */
#toolbar {
  gap: 4px;
  padding: 4px 6px;
  transform: none;
  transform-origin: top center;
}

/* Flatten toolbar groups so all tools line up together */
#toolbar .tool-group { display: contents; padding: 0; gap: 0; }

/* Add '|' separators between all toolbar children */
#toolbar > * { position: relative; display: inline-flex; align-items: center; }
#toolbar > * + *::before { content: '|'; color: #9ca3af; margin: 0 2px; font-weight: 600; }

.tool { display:flex; flex-direction:column; align-items:center; justify-content:center; width:32px; height:32px; border-radius:6px; border:1px solid #e5e7eb; cursor:pointer; background:#f8fafc; box-shadow:none; transition: background .12s ease, color .12s ease, border-color .12s ease; color:#1f2937; }

.icon { font-size: 18px; line-height: 1; }

.label {
  font-size: 10px;
  margin-top: 2px;
}
@media (max-width: 1200px) {
  #toolbar { transform: none; }
}
@media (max-width: 900px) {
  #toolbar { transform: none; }
}
#penLayer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 30; /* above wires and components for visibility */
  pointer-events: none; /* temporarily disabled */
}

/* Visual cursor for draggable eraser */
#eraserCursor {
  position: absolute;
  width: 32px;
  height: 32px;
  border: 2px solid #c0392b;
  border-radius: 50%;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 0 6px rgba(0,0,0,0.2);
  display: none;
}
/* Floating vertical zoom buttons */
.zoom-fab {
  position: fixed;
  right: 16px;
  left: auto;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 500;
  opacity: 0.5;
  transition: opacity 0.2s ease;
}
.zoom-fab:hover { opacity: 1; }
.zoom-btn {
  width: 36px;
  height: 36px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: none;
  cursor: pointer;
  font-weight: 700;
}
.zoom-btn:active { transform: translateY(1px); }

/* Make draggable elements touch friendly */
.component, .text-label { touch-action: none; }

/* Floating Properties FAB */
.props-fab {
  display: none; /* hide FAB per user feedback */
}

/* ===== Examples Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 2200; display: flex; align-items: center; justify-content: center; }
.examples-panel { width: min(1000px, 92vw); height: min(620px, 84vh); background:#fff; border:1px solid #e5e7eb; border-radius: 10px; box-shadow: 0 12px 28px rgba(0,0,0,0.25); display:flex; flex-direction: column; overflow:hidden; }
.examples-header { display:flex; align-items:center; justify-content: space-between; padding:10px 12px; border-bottom:1px solid #e5e7eb; font-weight:800; color:#334155; }
.examples-header button { border:1px solid #e5e7eb; background:#fff; border-radius:6px; padding:4px 8px; cursor:pointer; }
.examples-body { flex:1; display:grid; grid-template-columns: 220px 1fr 340px; min-height:0; }
.examples-left { border-right:1px solid #e5e7eb; padding:8px; overflow:auto; }
.examples-right { padding:8px; overflow:auto; display:flex; flex-direction:column; gap:6px; }
.examples-details { border-left:1px solid #e5e7eb; padding:10px; overflow:auto; background:#fafafa; }
.examples-details h3 { margin:6px 0 8px 0; font-size:16px; color:#1f2937; }
.examples-details .ex-thumb { width:100%; max-height:180px; object-fit:contain; border:1px solid #e5e7eb; border-radius:8px; background:#fff; }
.examples-details .ex-section { margin-top:10px; }
.examples-details .ex-links { display:flex; flex-direction:column; gap:6px; }
.examples-details .ex-links a { color:#2563eb; text-decoration:none; font-size:13px; }
.examples-details .ex-links a:hover { text-decoration:underline; }
.examples-details .ex-actions { margin-top:12px; }
.examples-details .ex-actions button { border:1px solid #e5e7eb; background:#fff; border-radius:6px; padding:6px 10px; cursor:pointer; }
.ex-cat { display:block; width:100%; text-align:left; border:1px solid #e5e7eb; border-left:6px solid #2563eb; background:#f8fbff; color:#1f2937; border-radius:8px; padding:8px; margin-bottom:8px; cursor:pointer; }
.ex-cat.active { background:#e8f0ff; }
.ex-card { border:1px solid #e5e7eb; border-radius:6px; padding:6px 8px; background:#fff; cursor:pointer; display:flex; align-items:center; justify-content:space-between; gap:8px; }
.ex-card img { display:none; }
.ex-card span { font-size:13px; color:#334155; text-align:left; flex:1; }

/* Simple syntax highlight tokens */
.tok-kw { color: #015cc8; font-weight: 600; }
.tok-str { color: #a31515; }
.tok-cmt { color: #6a737d; font-style: italic; }
.tok-num { color: #098658; }

/* ===== TEXT LABELS ===== */
.text-label {
  position: absolute;
  z-index: 30;
  color: #111;
  font-weight: 600;
  cursor: move;
  user-select: none;
  white-space: pre; /* preserve spaces/newlines if added */
  touch-action: none;
}
.text-label.editing {
  cursor: text;
  user-select: text;
  outline: 1px dashed #007aff;
  background: rgba(255,255,255,0.6);
  border-radius: 4px;
  padding: 2px 4px;
}
/* Floating Properties Panel */
.floating-panel {
  position: fixed;
  right: 12px;
  bottom: 80px;
  width: 300px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  overflow: hidden;
  z-index: 1200;
}
.floating-panel.collapsed .panel-body { display: none; }
.floating-panel[aria-hidden="true"] { display: none; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: #007aff;
  color: #fff;
  font-weight: 700;
}
.panel-actions button { border: none; background: transparent; color: #fff; cursor: pointer; }
.panel-body { padding: 10px; overflow: auto; }
.prop-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.prop-row label { width: 48px; font-size: 12px; color: #333; }
.prop-row input[type="number"], .prop-row input[type="color"], .prop-row textarea { flex: 1; }
.shape { position:absolute; /* default border removed to avoid box around polygons */ background: transparent; border-radius: 4px; }
.shape.polygon { border: none; background: transparent; border-radius: 0; }
.shape.polygon svg { width: 100%; height: 100%; display: block; }
.shape.ellipse { border-radius: 50%; }
#inlineTextToolbar, #wireToolbar, #shapeToolbar {
  background: #fff !important;
  border: 1px solid #e5e7eb !important;
  border-radius: 8px !important;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06) !important;
}
#inlineTextToolbar button, #wireToolbar button, #shapeToolbar button,
#shapesToolbar button {
  border: 1px solid #e5e7eb;
  background: #f8fafc;
  border-radius: 6px;
  padding: 4px 6px;
  cursor: pointer;
}
#inlineTextToolbar button:hover, #wireToolbar button:hover, #shapeToolbar button:hover,
#shapesToolbar button:hover { background: #eef2f7; }
#inlineTextToolbar input, #wireToolbar input, #shapeToolbar input, #shapeToolbar select { border: 1px solid #e5e7eb; border-radius: 6px; }
/* Global layout variables for bottom toolbar and safe areas */
:root {
  --toolbar-height: 52px;  /* visual height of bottom toolbar */
  --toolbar-gap: 16px;     /* default lift above OS nav bar */
}
@supports (bottom: env(safe-area-inset-bottom)) {
  :root { --toolbar-gap: max(16px, env(safe-area-inset-bottom)); }
}
.examples-cta {
  position: fixed;
  top: 18px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  z-index: 2147482500;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  color: #1f2937;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.18);
}
@media (max-width: 640px){ .examples-cta { top: 56px; left: 50%; right: auto; transform: translateX(-50%); padding: 4px 8px; font-size: 11px; } }

/* ===== CIRCUIT + BLOCKLY SPLIT VIEW ===== */
#editorShell {
  position: fixed;
  inset: 0;
  display: flex;
}

.editor-split {
  --splitter-size: 10px;
  --blockly-width: 0px;
  --blockly-min: 320px;
  flex: 1;
  min-width: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane-header {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid #dbe3f2;
  background: linear-gradient(180deg, #ffffff 0%, #f3f7ff 100%);
  flex-shrink: 0;
}

.pane-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #1e3a5f;
  text-transform: uppercase;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pane-action {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #cdd8eb;
  border-radius: 8px;
  background: #fff;
  color: #1f2937;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.pane-action:hover {
  background: #eef4ff;
  border-color: #aac1e8;
}

.pane-action-close {
  color: #a61b1b;
}

.pane-circuit {
  flex: 1 1 auto;
  width: calc(100% - var(--blockly-width));
  border-right: 1px solid #dbe3f2;
  background: #f8fbff;
}

.pane-circuit #workspace-container {
  height: calc(100% - 42px);
}

.pane-blockly {
  width: var(--blockly-width);
  flex: 0 0 var(--blockly-width);
  background: #f5f8fc;
  border-left: 1px solid #dbe3f2;
  overflow: hidden;
}

.blockly-frame-shell {
  flex: 1;
  min-height: 0;
  background: linear-gradient(180deg, #f8fbff 0%, #edf4ff 100%);
}

.blockly-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #fff;
}

.splitter-handle {
  width: var(--splitter-size);
  flex: 0 0 var(--splitter-size);
  position: relative;
  background: linear-gradient(180deg, #eef3fb 0%, #dce7f7 100%);
  cursor: col-resize;
  border-left: 1px solid #d1ddf0;
  border-right: 1px solid #d1ddf0;
  touch-action: none;
}

.splitter-handle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 44px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: repeating-linear-gradient(to bottom, #7d95b8 0, #7d95b8 4px, transparent 4px, transparent 8px);
  opacity: 0.85;
}

.blockly-dock-toggle {
  position: fixed;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  z-index: 2147483300;
  width: 38px;
  height: 88px;
  border: 1px solid #b7c8e4;
  border-radius: 18px 0 0 18px;
  background: linear-gradient(180deg, #ffffff 0%, #dfeafb 100%);
  color: #1d4f91;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(25, 56, 99, 0.18);
}

body.is-resizing-split {
  cursor: col-resize;
}

body.is-resizing-split * {
  cursor: col-resize !important;
}


.editor-split[data-pane-mode="split"] .pane-blockly {
  display: flex;
}

.editor-split[data-pane-mode="split"] .splitter-handle {
  display: block;
}

.editor-split[data-pane-mode="circuit"] .pane-blockly,
.editor-split[data-pane-mode="circuit"] .splitter-handle {
  display: none;
}

.editor-split[data-pane-mode="blockly"] .pane-circuit {
  flex: 0 0 0;
  width: 0;
  border-right: 0;
  overflow: hidden;
}

.editor-split[data-pane-mode="blockly"] .pane-blockly {
  display: flex;
  width: 100%;
  flex-basis: 100%;
  border-left: 0;
}

.editor-split[data-pane-mode="blockly"] .splitter-handle {
  display: none;
}


.editor-split[data-pane-mode="split"] .pane-circuit,
.editor-split[data-pane-mode="blockly"] .pane-blockly {
  box-shadow: inset 0 0 0 1px rgba(160, 184, 220, 0.18);
}

@media (max-width: 900px) {
  .editor-split {
    --blockly-min: 260px;
  }

  .blockly-dock-toggle {
    width: 34px;
    height: 74px;
  }
}

@media (max-width: 720px) {
  .pane-header {
    padding: 0 8px;
  }

  .pane-action {
    padding: 0 8px;
    font-size: 11px;
  }

  .editor-split[data-pane-mode="split"] .pane-circuit {
    display: none;
  }

  .editor-split[data-pane-mode="split"] .splitter-handle {
    display: none;
  }

  .editor-split[data-pane-mode="split"] .pane-blockly {
    width: 100%;
    flex-basis: 100%;
    border-left: 0;
  }


}



