* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    font-size: 11.2px; /* 70% of default 16px */
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.1em; /* 70% of 3em */
    margin-bottom: 7px; /* 70% of 10px */
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
}

.main-content {
    display: flex;
    gap: 20px;
    min-height: calc(100vh - 200px);
}

/* Layer Palette */
.layer-palette {
    width: 175px; /* Reduced by 30% from 250px */
    background: white;
    border-radius: 12px;
    padding: 14px; /* Reduced by 30% from 20px */
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    overflow-y: auto;
    max-height: calc(100vh - 28px); /* Adjusted for new padding */
}

.layer-palette h2 {
    font-size: 1.5em;
    margin-bottom: 20px;
    color: #667eea;
}

.palette-section {
    margin-bottom: 25px;
}

.palette-section h3 {
    font-size: 1em;
    color: #666;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    margin-bottom: 8px;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s;
}

.layer-item:hover {
    background: #e9ecef;
    border-color: #667eea;
    transform: translateX(5px);
}

.layer-item:active {
    cursor: grabbing;
}

.layer-icon {
    font-size: 1.05em;
}

.layer-name {
    font-weight: 500;
    color: #333;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e9ecef;
}

.stats {
    display: flex;
    gap: 30px;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.5em;
    font-weight: 700;
    color: #667eea;
}

.gpu-select {
    font-size: 0.9em;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    max-width: 200px;
}

.gpu-select:focus {
    outline: none;
    border-color: #667eea;
}

.canvas-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    background: #f8f9fa;
    border-radius: 6px;
}

#zoom-level {
    font-weight: 600;
    min-width: 50px;
    text-align: center;
    color: #667eea;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    padding: 6px 12px;
    font-size: 0.9em;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(108, 117, 125, 0.4);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    color: #333;
    cursor: pointer;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    transition: background 0.2s;
}

.toggle-label:hover {
    background: #e9ecef;
}

.toggle-label input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95em;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.4);
}

/* Canvas */
.canvas-container {
    flex: 1;
    position: relative;
    background: #f8f9fa;
    border: 3px dashed #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    min-height: 500px;
}

.canvas {
    width: 100%;
    height: 100%;
    position: relative;
    min-height: 500px;
    overflow: hidden;
    transform-origin: 0 0;
    transition: transform 0.1s ease-out;
    z-index: 0; /* ensure SVG connections (z-index:1) render above canvas background */
}

.connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* Invisible spacer used to create a large virtual panning area without affecting layout */
.virtual-canvas-spacer {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
    z-index: -1;
}

.canvas.drag-over {
    background: #e7f3ff;
}

.canvas-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #adb5bd;
    font-size: 1.2em;
    text-align: center;
    padding: 20px;
}

/* Network Nodes */
.network-node {
    position: absolute;
    background: white;
    border: 3px solid #dee2e6;
    border-radius: 8.4px; /* 70% of 12px */
    padding: 10.5px; /* 70% of 15px */
    cursor: move;
    transition: all 0.2s;
    min-width: 140px; /* 70% of 200px */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 2;
    user-select: none;
}

.network-node:hover {
    border-color: #667eea;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
}

.network-node.dragging {
    opacity: 0.8;
    cursor: grabbing;
}

.network-node.high-params {
    border-color: #ffc107;
    background: #fff8e1;
}

.network-node.error {
    border-color: #dc3545;
    background: #ffe6e6;
}

.node-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 7px; /* 70% of 10px */
    padding-bottom: 5.6px; /* 70% of 8px */
    border-bottom: 2px solid #e9ecef;
}

.node-title {
    display: flex;
    align-items: center;
    gap: 5.6px; /* 70% of 8px */
    flex: 1;
}

.minimize-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 1.2em;
    color: #667eea;
    transition: transform 0.2s;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.minimize-btn:hover {
    transform: scale(1.2);
}

.network-node.minimized .node-body {
    display: none;
}

.network-node.minimized .error-message {
    display: none;
}

/* Ghost node style for fast dragging preview */
.node-ghost {
    position: absolute;
    z-index: 1000;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    transform: translateZ(0);
    transition: transform 0s;
    will-change: transform;
}

.node-ghost .param-input,
.node-ghost .node-action-btn,
.node-ghost .minimize-btn {
    pointer-events: none;
}

/* Lightweight ghost header style */
.node-ghost-light {
    padding: 6px 8px;
    background: #eef2ff;
    border-radius: 6px;
    color: #333;
}

/* Full ghost used when dragging existing nodes */
.full-ghost {
    background: #fff;
    border-radius: 8px;
    padding: 8px;
    color: #333;
    overflow: hidden;
}

/* Utility class used to temporarily disable transitions on nodes
   (used during drag/compaction to avoid animated jumps and keep
   wires synchronised with final positions) */
.no-transition {
    transition: none !important;
}

/* Disable port transitions while dragging to prevent transient
   transparency/flicker when ports update. Toggled via JS
   by adding/removing `no-transition-ports` on `document.body`. */
.no-transition-ports .port {
    transition: none !important;
}

.node.dragging {
    opacity: 0.4;
}
.node-icon {
    font-size: 1.5em;
}

.node-name {
    font-size: 1em;
    font-weight: 600;
    color: #333;
}

.node-actions {
    display: flex;
    gap: 5px;
}

.node-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    padding: 2px 5px;
    border-radius: 4px;
    transition: background 0.2s;
}

.node-action-btn:hover {
    background: #e9ecef;
}

.node-params {
    font-size: 0.85em;
    font-weight: 600;
    color: #667eea;
    text-align: center;
    padding: 3px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.node-params .params-line {
    display: block;
}

.node-params .flops-line {
    display: block;
    color: #28a745;
    font-size: 0.9em;
}

.node-params.high {
    color: #ff6b6b;
}

.node-body {
    margin: 10px 0;
}

.param-input-group {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.param-label {
    font-size: 0.85em;
    color: #666;
    min-width: 80px;
    font-weight: 500;
}

.param-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.85em;
    transition: border-color 0.2s;
    cursor: ns-resize;
}

/* Static parameter display used inside drag ghost — styled to match inputs */
.param-static {
    display: inline-block;
    min-width: 48px;
    padding: 4px 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.85em;
    background: white;
    color: #333;
    text-align: left; /* match normal inputs */
    box-sizing: border-box;
}

.param-static-checkbox {
    width: 16px;
    height: 16px;
    margin: 0 4px;
    vertical-align: middle;
}

.param-input:hover {
    border-color: #667eea;
    background: #f8f9ff;
}

.param-input:focus {
    outline: none;
    border-color: #667eea;
    cursor: text;
}

.param-input.error {
    border-color: #dc3545;
    background: #ffe6e6;
}

.param-checkbox {
    width: auto;
}

/* Node Ports */
.node-ports {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
}

.port-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.port {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 3px solid #667eea;
    background: white;
    cursor: crosshair;
    transition: all 0.2s;
    position: relative;
    pointer-events: all;
    z-index: 100;
}

.port:hover {
    background: #667eea;
    transform: scale(1.4);
    border-color: #2196F3;
}

.port.connected {
    background: #667eea;
}

.port.output {
    border-color: #28a745;
}

.port.output:hover,
.port.output.connected {
    background: #28a745;
}

.port.input {
    border-color: #007bff;
}

.port.input:hover,
.port.input.connected {
    background: #007bff;
}

.port-label {
    font-size: 0.7em;
    color: #666;
    text-align: center;
    margin-top: 2px;
}

/* Connection Lines */
.connection-line {
    fill: none;
    stroke: #667eea;
    stroke-width: 3;
    pointer-events: stroke;
    cursor: pointer;
    transition: stroke-width 0.2s;
}

.connection-line:hover {
    stroke: #5568d3;
    stroke-width: 4;
}

.connection-line.temp {
    stroke: #adb5bd;
    stroke-dasharray: 5, 5;
}

.connection-line.preview {
    stroke: #667eea;
    stroke-dasharray: 8, 4;
    stroke-width: 2;
    opacity: 0.7;
}

.connection-line.error {
    stroke: #dc3545;
}

.error-message {
    font-size: 0.75em;
    color: #dc3545;
    margin-top: 5px;
    padding: 5px;
    background: #ffe6e6;
    border-radius: 4px;
}

/* Layer Connector - Remove old sequential connector */
.layer-connector {
    display: none;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

.export-modal-content {
    max-width: 800px;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #e9ecef;
}

.modal-header h3 {
    color: #667eea;
    font-size: 1.5em;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: #adb5bd;
    transition: color 0.2s;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #667eea;
}

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px;
    border-top: 2px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-hint {
    font-size: 0.85em;
    color: #6c757d;
    margin-top: 5px;
}

/* Code Export */
#export-code {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .layer-palette {
        width: 100%;
        max-height: 300px;
    }

    .canvas-header {
        flex-direction: column;
        gap: 15px;
    }

    .stats {
        width: 100%;
        justify-content: space-around;
    }

    .canvas-actions {
        width: 100%;
    }

    .canvas-actions .btn {
        flex: 1;
    }
}
