/* === FULL PAGE OVERRIDES FOR LOGIC GATES === */
body:has(#logicPage) { overflow: hidden; }
body:has(#logicPage) .pageWrap {
  max-width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  height: calc(100vh - var(--nav-h));
  display: flex;
  flex-direction: column;
}
#logicPage { padding: 0 !important; margin: 0 !important; }

/* === MAIN CONTAINER === */
.lg-container {
  flex: 1; display: flex; flex-direction: column; position: relative;
  width: 100%; height: 100%; overflow: hidden;
}

/* === FIXED HEADER === */
.lg-top-header {
  width: 100%; text-align: center; padding: 8px 20px 8px; 
  background: var(--bg); z-index: 10; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-bottom: 1px solid rgba(255,255,255,0.08); 
}
.lg-title {
  font-family: var(--bit-font); font-size: 32px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text); margin: 0 0 2px 0; line-height: 1;
}
.lg-subtitle {
  color: var(--muted); font-size: 14px; font-family: var(--ui-font);
  font-weight: 500; margin: 0; line-height: 1.2;
}
.lg-subtitle kbd {
  background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px;
  font-family: var(--ui-font); color: #e8e8ee;
}

/* === DYNAMIC CANVAS & CAMERA VIEWPORT === */
.lg-workspace {
  flex: 1; position: relative; width: 100%;
  background-color: transparent; 
  background-image: radial-gradient(rgba(255,255,255,0.15) 1px, transparent 1px);
  background-size: 24px 24px; overflow: hidden;
  cursor: grab; /* Indicates pannable area */
}
.lg-workspace:active { cursor: grabbing; }

.lg-viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  pointer-events: none; /* Let events reach workspace, nodes will re-enable it */
}

/* Zoom UI Controls */
.lg-zoom-controls {
  position: absolute; bottom: 20px; left: 20px; z-index: 100;
  display: flex; gap: 8px;
}
.lg-zoom-btn {
  width: 40px; height: 40px; border-radius: 8px; font-family: var(--ui-font);
  font-size: 22px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.15);
  color: #e8e8ee; cursor: pointer; backdrop-filter: blur(8px); transition: all 0.2s;
}
.lg-zoom-btn:hover { background: rgba(255,255,255,0.1); border-color: #28f07a; color: #28f07a; }

/* Update the SVG layer to sit ON TOP of nodes */
/* Move the wire layer behind the nodes */
.lg-svg-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1; /* Lower than nodes */
  pointer-events: none; 
}

/* Wires */
/* Wires - allow them to be clickable even behind the 'hit area' of ports */
.lg-wire {
    stroke: #ffffff40;
    stroke-width: 6;
    fill: none;
    stroke-linecap: round;
    transition: stroke .1s ease,filter .1s ease,stroke-width .1s ease;
    pointer-events: stroke;
    cursor: pointer;
    z-index: 1;
}
.lg-wire:hover {
    stroke: #fff9;
    stroke-width: 10
}
.lg-wire.active {
    stroke: #28f07a;
    filter: drop-shadow(0 0 6px rgba(40,240,122,.6))
}
.lg-wire.active:hover {
    stroke: #5dff9e
}
.lg-wire.selected {
    stroke: #f55!important;
    stroke-width: 8!important;
    stroke-dasharray: 8 8;
    filter: drop-shadow(0 0 8px rgba(255,85,85,.8))!important;
    animation: wireDash 1s linear infinite
}
@keyframes wireDash {
    to {
        stroke-dashoffset: -16
    }
}
.lg-wire-temp {
    stroke: #fff6;
    stroke-dasharray: 8 8;
    pointer-events: none
}

/* Nodes */
/* Nodes - move them in front of wires */
.lg-node {
  position: absolute;
  z-index: 10; /* Higher than wires */
  pointer-events: auto;
  user-select: none;
}
.lg-node:active { cursor: grabbing; z-index: 20; }
.lg-node.selected { filter: drop-shadow(0 0 10px rgba(255,85,85,0.8)); }

.lg-header {
  font-size: 24px; color: var(--muted); font-family: var(--bit-font); 
  letter-spacing: 2px; pointer-events: none; margin-bottom: 6px;
}

.lg-gate-container { position: relative; display: inline-flex; align-items: center; }
.lg-gate-svg { width: 100px; height: 50px; display: block; }
.lg-line-svg { width: 30px; height: 50px; display: block; }

/* Connection Ports */
/* Update ports to sit even higher so they stay clickable */
/* Ports - Ensure the dots are the top-most layer */
.lg-port {
  width: 12px; /* Balanced size */
  height: 12px;
  background: #a9acb8;
  border: 2px solid #1f2027; /* Dark border helps it 'pop' over glowing wires */
  border-radius: 50%;
  position: absolute;
  z-index: 100; /* Absolute top */
  transform: translate(-50%, -50%);
  cursor: crosshair;
}
.lg-port:hover { transform: translate(-50%, -50%) scale(1.3); background: #fff; }
.lg-port.active {
  background: #28f07a;
  box-shadow: 0 0 8px rgba(40,240,122,.45);
}

/* === FLOATING TOOLBOX === */
.toolboxToggle {
  position: absolute; top: 10px; right: 20px; z-index: 90;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  border-radius: 12px; border: 1px solid rgba(255,255,255,.12); background: rgba(0,0,0,.15);
  backdrop-filter: blur(8px); color: rgba(232,232,238,.95); font-family: var(--bit-font);
  font-weight: 800; font-size: 16px; letter-spacing: .12em; text-transform: uppercase; cursor: pointer;
}
.toolboxIcon { font-size: 20px; filter: drop-shadow(0 0 8px rgba(255,105,180,.35)); }
.toolboxToggle:hover { border-color: rgba(255,255,255,.22); }

.lg-toolbox {
  position: absolute; top: 60px; right: 20px; bottom: 20px; width: var(--toolbox-w, 360px);
  z-index: 80; display: flex; flex-direction: column; gap: 16px; transform: translateX(0);
  transition: transform 420ms cubic-bezier(.2,.9,.2,1), opacity 220ms ease;
  overflow-y: auto; pointer-events: auto; padding-right: 6px; 
}
.lg-toolbox::-webkit-scrollbar { width: 6px; }
.lg-toolbox::-webkit-scrollbar-track { background: transparent; }
.lg-toolbox::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.05); border-radius: 10px; transition: background 0.3s; }
.lg-toolbox:hover::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); }
.lg-container.toolboxCollapsed .lg-toolbox { transform: translateX(calc(100% + 40px)); opacity: 0; pointer-events: none; }

.tb-icon-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tb-icon-box {
  background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.15); border-radius: 12px; width: 100%; padding: 12px 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  cursor: grab; transition: background 0.2s, border-color 0.2s;
}
.tb-icon-box:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.3); }
.tb-icon-label { font-family: var(--ui-font); font-size: 11px; font-weight: 800; color: var(--text); letter-spacing: 1px; text-transform: uppercase; }

.tt-summary {
  font-family: var(--ui-font); font-size: 14px; font-weight: 800; color: var(--accent, #28f07a);
  cursor: pointer; user-select: none; outline: none; margin-bottom: 10px; text-transform: uppercase;
}
.tt-table-wrap {
  width: 100%; max-height: 250px; overflow-y: auto; overflow-x: auto;
  border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.2);
}
.tt-table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.tt-table-wrap::-webkit-scrollbar-track { background: transparent; }
.tt-table-wrap::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
.tt-table { width: 100%; border-collapse: collapse; text-align: center; font-family: var(--num-font); font-size: 14px; color: #e8e8ee; }
.tt-table th { position: sticky; top: 0; background: rgba(31,32,39,0.95); padding: 8px 12px; border-bottom: 1px solid rgba(255,255,255,0.15); color: var(--muted); font-family: var(--bit-font); font-weight: normal; }
.tt-table td { padding: 8px 12px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.tt-table .tt-on { color: #28f07a; text-shadow: 0 0 8px rgba(40,240,122,0.5); }


/* Ensure the active-sim class actually changes the color */
.active-sim .slider {
  background-color: rgba(40,240,122,.25) !important; /* Bright Green */
  box-shadow: 0 0 15px rgba(40, 240, 122, 0.5);
}

.active-sim .slider::before {
  transform: translateX(28px) !important;
}