/* ── PhET Scaling Base ───────────────────────────────────── */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* PhET Stage — scalable container */
#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    overflow: hidden;
    background: #020617;
    /* Maintain full design proportions inside the stage */
    display: flex;
    flex-direction: column;
}

:root {
    --bg-workspace: #0f172a;
    --grid-line: rgba(255, 255, 255, 0.03);
    --gate-bg: #1e293b;
    --gate-border: rgba(255, 255, 255, 0.1);
    --pin-color: #64748b;
    --high-color: #06b6d4;
    --low-color: #475569;
}

body.logic-gates-page {
    background-color: #020617;
    color: #e2e8f0;
    overflow: hidden;
    height: 100%;           /* % not vh inside a scaled stage */
    touch-action: none;
    overscroll-behavior: none;
}

#sim-app {
    padding-top: 80px;
    height: 100%;           /* % not vh */
    width: 100%;
}

.sim-container {
    display: flex;
    height: calc(100% - 100px); /* % not vh */
    margin: 0 10px;
    gap: 10px;
}

/* Palette Styles */
.palette {
    width: 200px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    border: 1px solid var(--gate-border);
    display: flex;
    flex-direction: column;
    padding: 15px;
    z-index: 100;
}

.palette-header {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    margin-bottom: 20px;
}

.scrollable {
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: rgba(6, 182, 212, 0.3) transparent;
}

.scrollable::-webkit-scrollbar {
    width: 4px;
}
.scrollable::-webkit-scrollbar-track {
    background: transparent;
}
.scrollable::-webkit-scrollbar-thumb {
    background: rgba(6, 182, 212, 0.25);
    border-radius: 10px;
}
.scrollable::-webkit-scrollbar-thumb:hover {
    background: var(--high-color);
}

.category-label {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #64748b;
    margin: 15px 0 8px 5px;
    letter-spacing: 0.5px;
}

.gate-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--gate-border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}

.gate-item:hover {
    border-color: var(--high-color);
    background: rgba(6, 182, 212, 0.05);
}

.gate-item span {
    font-size: 0.75rem;
    font-weight: 600;
}

.palette-divider {
    border: none;
    border-top: 1px solid var(--gate-border);
    margin: 15px 0;
}

/* Workspace Styles */
.workspace {
    flex: 1;
    background: var(--bg-workspace);
    border-radius: 16px;
    position: relative;
    overflow: hidden;
    cursor: default;
    border: 1px solid var(--gate-border);
    user-select: none;
    -webkit-user-select: none;
}

.grid-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(var(--grid-line) 1.5px, transparent 1.5px),
        linear-gradient(90deg, var(--grid-line) 1.5px, transparent 1.5px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

.wire-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: visible !important;
}

.wire-hit {
    pointer-events: all;
    cursor: pointer;
}

.wire.selected {
    stroke: #fbbf24 !important;
    stroke-width: 5 !important;
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.6));
}

#transform-layer {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: 10;
}

.component-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.module-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.module-box {
    position: absolute;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    pointer-events: auto;
    cursor: grab;
    transition: border-color 0.2s, background 0.2s;
}

.module-box:hover {
    border-color: var(--high-color);
    background: rgba(6, 182, 212, 0.05);
}

.module-box.selected {
    border-color: #fbbf24;
    border-style: solid;
    background: rgba(251, 191, 36, 0.05);
}

.module-label {
    position: absolute;
    top: -25px;
    left: 10px;
    font-size: 0.8rem;
    font-weight: 800;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
    outline: none;
    cursor: text;
}

.module-resize-handle {
    position: absolute;
    bottom: -5px;
    right: -5px;
    width: 15px;
    height: 15px;
    background: var(--high-color);
    border-radius: 50%;
    cursor: nwse-resize;
    opacity: 0;
    transition: opacity 0.2s;
}

.module-box:hover .module-resize-handle {
    opacity: 1;
}

.gate-instance {
    pointer-events: auto;
}

/* Zoom Controls Style */
.zoom-controls {
    position: absolute;
    bottom: 25px;
    right: 25px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

.zoom-controls button {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    color: #cbd5e1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.zoom-controls button:hover {
    background: var(--high-color);
    color: white;
    transform: translateY(-2px);
}

.zoom-controls .zoom-level {
    font-size: 11px;
    color: #94a3b8;
    text-align: center;
    font-family: monospace;
    margin-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 4px;
}

.workspace-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #475569;
    font-size: 0.8rem;
    pointer-events: none;
}

/* Component Styling in Workspace */
.gate-instance {
    position: absolute;
    background: transparent;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: filter 0.2s, width 0.2s, height 0.2s;
    user-select: none;
}

.gate-instance.selected {
    outline: 2px dashed #fbbf24;
    outline-offset: 8px;
    border-radius: 8px;
    background: rgba(251, 191, 36, 0.1);
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.2);
}

.gate-instance svg {
    width: 100%;
    height: 100%;
    color: #cbd5e1;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

.gate-instance.active svg {
    color: var(--high-color);
    filter: drop-shadow(0 0 12px var(--high-color));
}

.gate-controls {
    position: absolute;
    top: -35px;
    right: -10px;
    display: flex;
    flex-direction: row;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 20;
}

.gate-instance:hover .gate-controls {
    opacity: 1;
}

.ctrl-btn {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--gate-border);
    background: var(--gate-bg);
    color: white;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
}

.ctrl-btn:hover {
    background: var(--high-color);
    border-color: var(--high-color);
}

.gate-label {
    position: absolute;
    bottom: -20px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #64748b;
    white-space: nowrap;
}

.gate-instance i {
    color: #475569;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.gate-instance.active i {
    color: var(--high-color);
    filter: drop-shadow(0 0 15px var(--high-color));
}

.gate-instance.active i.fa-lightbulb {
    color: #fbbf24;
    filter: drop-shadow(0 0 20px #fbbf24) drop-shadow(0 0 40px rgba(251, 191, 36, 0.3));
}

.gate-label {
    display: none;
    /* Hide text labels in favor of signs */
}

/* Input/Output Pins */
.pin {
    width: 12px;
    height: 12px;
    background: var(--pin-color);
    border-radius: 50%;
    position: absolute;
    cursor: crosshair;
    transition: 0.2s;
    border: 2px solid var(--gate-bg);
}

.pin:hover {
    transform: scale(1.3);
    background: white;
}

.pin-value {
    position: absolute;
    font-size: 0.6rem;
    font-weight: 800;
    color: white;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.5);
    padding: 1px 4px;
    border-radius: 4px;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
}

.pin.input {
    left: -2px;
}

.pin.output {
    right: -2px;
}

.pin.high {
    background: var(--high-color);
    box-shadow: 0 0 10px var(--high-color);
}

.switch-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.var-label {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 800;
    font-size: 1.2rem;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.3s;
    user-select: none;
    line-height: 1;
}

.gate-instance.active .var-label {
    color: var(--high-color);
    text-shadow: 0 0 10px var(--high-color);
}

.var-label:hover {
    color: white;
    transform: scale(1.1);
}

/* Variable & Display Special Styling */
.gate-instance.type-VARIABLE .gate-visual {
    width: 40px;
    height: 40px;
    background: rgba(6, 182, 212, 0.05);
    border: 2px solid var(--high-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 900;
    color: var(--high-color);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.2);
    transition: all 0.3s;
}

.var-symbol {
    outline: none;
    cursor: text;
    padding: 0 5px;
    min-width: 20px;
    text-align: center;
}

.var-symbol:focus {
    color: white;
    text-shadow: 0 0 10px var(--high-color);
}

.gate-instance.type-DISPLAY {
    min-width: 120px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.gate-instance.type-DISPLAY .gate-visual {
    width: 90%;
    height: 90%;
    background: #020617;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
}

.type-DISPLAY .pin {
    width: 8px;
    height: 8px;
    background: #f472b6;
    border-radius: 2px;
}

.expression-text {
    font-family: 'Space Grotesk', monospace;
    font-size: 0.85rem;
    color: #06b6d4;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.var-preview {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--high-color);
}

.display-preview {
    font-size: 1.2rem;
    color: #94a3b8;
}

/* Specific Gate Visuals */
.gate-preview {
    width: 60px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
}

.gate-preview svg {
    width: 100%;
    height: 100%;
}

/* Control Panel */
.control-panel {
    width: 220px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    border: 1px solid var(--gate-border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.section-title {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #64748b;
}

.stats-box {
    background: rgba(255, 255, 255, 0.02);
    padding: 12px;
    border-radius: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 5px;
}

.btn-action {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-action.danger {
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
}

.presets-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.preset-btn {
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.2);
    color: var(--high-color);
    padding: 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

/* Combinational Logic List Styles */
.combinational-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.comb-item {
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.comb-trigger {
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.comb-trigger:hover {
    color: var(--high-color);
    background: rgba(6, 182, 212, 0.05);
}

.comb-item.active .comb-trigger {
    color: var(--high-color);
    background: rgba(6, 182, 212, 0.1);
}

.comb-item.active .comb-trigger i {
    transform: rotate(180deg);
}

.comb-options {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 0 10px;
}

.comb-item.active .comb-options {
    max-height: 200px;
    padding: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.solo-btn {
    width: 100%;
    text-align: left;
    margin-bottom: 0;
}

/* Nav refinements */
nav {
    background: rgba(2, 6, 23, 0.8) !important;
    backdrop-filter: blur(16px);
}

/* Truth Table Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content.truth-table-content {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 32px;
    width: 90%;
    max-width: 800px;
    max-height: 85%;
    position: relative;
    transform: translateY(20px);
    transition: transform 0.3s;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.modal-overlay.active .truth-table-content {
    transform: translateY(0);
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.close-modal:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.modal-header {
    margin-bottom: 24px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-header p {
    color: #64748b;
    margin: 4px 0 0 0;
    font-size: 0.9rem;
}

.table-wrapper {
    overflow-y: auto;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.2);
}

table#truth-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Space Grotesk', monospace;
    font-size: 0.95rem;
}

#truth-table th {
    background: rgba(255, 255, 255, 0.03);
    padding: 14px;
    text-align: center;
    color: #94a3b8;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 1px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.05);
}

#truth-table td {
    padding: 12px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.val-0 {
    color: #f87171;
    font-weight: 500;
}

.val-1 {
    color: #4ade80;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(74, 222, 128, 0.3);
}

#truth-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

#truth-table th.output-header {
    color: #06b6d4;
    background: rgba(6, 182, 212, 0.05);
}