/* ---
    Dark Theme Refresh
    - New color palette
    - Added transitions for smoother interactions
--- */

/* Custom styles for the builder */
body {
    font-family: 'Inter', sans-serif;
    overscroll-behavior: none;
}

#canvas {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #1f2937; /* gray-800 */
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

.panning {
    cursor: grabbing !important;
}

.component {
    position: absolute;
    background: #374151; /* gray-700 */
    border: 1px solid #4b5563; /* gray-600 */
    border-radius: 0.5rem;
    padding: 0.75rem;
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 160px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    user-select: none;
    z-index: 1000;
    transition: box-shadow 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

.component.selected {
    border-color: #60a5fa; /* blue-400 */
    box-shadow: 0 0 0 2px #60a5fa, 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

.component.dragging {
    cursor: grabbing;
    opacity: 0.8;
    z-index: 1001;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    transform: scale(1.02); /* Slightly larger when dragging */
}

/* Spool components are hidden when nested */
.component.nested {
    display: none;
}

/* Delete button */
.delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    background-color: #ef4444; /* red-500 */
    color: #fee2e2; /* red-100 */
    border-radius: 50%;
    border: 2px solid white;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1002;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: background-color 0.2s ease;
}

.component:hover .delete-btn {
    display: flex;
}

.delete-btn:hover {
    background-color: #dc2626; /* red-600 */
}

.component-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #d1d5db; /* gray-300 */
    margin-bottom: 0.5rem;
    text-align: center;
    pointer-events: none;
}

.component-body {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;
}

.ports {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

/* New layout for port + label */
.port-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
}

.port {
    width: 16px;
    height: 16px;
    border: 2px solid #9ca3af; /* gray-400 */
    border-radius: 50%;
    cursor: crosshair;
    position: relative;
    background-color: #4b5563; /* gray-600 */
    transition: all 0.2s ease;
}

.port.input { background-color: #6b7280; } /* gray-500 */
.port.output { background-color: #60a5fa; } /* blue-400 */
.port.selected { border-color: #f87171; border-width: 3px; box-shadow: 0 0 8px rgba(239, 68, 68, 0.7); }

/* --- Special Port Types --- */
.port.spool {
    border-radius: 0.25rem; /* Square */
    background-color: #9ca3af;
    border-color: #4b5563;
}
/* UPDATED: Renamed from .buffer_feed */
.port.port-unbuffered {
    background-color: #f97316; /* Orange */
    border-color: #c2410c;
}
/* --- End Special Port Types --- */

.port-label {
    position: absolute;
    font-size: 0.75rem;
    color: #9ca3af; /* gray-400 */
    pointer-events: none;
    white-space: nowrap;
}

.port.input .port-label { left: 1.5rem; }
.port.output .port-label { right: 1.5rem; }

/* New styles for component slots */
.spool-slot {
    width: 90%;
    margin: 0.5rem auto 0.25rem;
    padding: 0.5rem;
    min-height: 60px;
    border: 2px dashed #4b5563; /* gray-600 */
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: #9ca3af; /* gray-400 */
    background-color: rgba(0,0,0,0.2);
    pointer-events: none; /* Allows drop events to pass to component */
}

.spool-slot.loaded {
    background-color: #1e3a8a; /* blue-900 */
    border-color: #60a5fa; /* blue-400 */
    color: #bfdbfe; /* blue-200 */
    justify-content: space-between;
}

.spool-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    font-size: 0.8rem;
    gap: 0.1rem;
}

.eject-btn {
    background: none;
    border: none;
    color: #bfdbfe; /* blue-200 */
    cursor: pointer;
    padding: 0;
    transition: color 0.2s ease;
}

.eject-btn:hover {
    color: #93c5fd; /* blue-300 */
}

.eject-btn:hover {
    color: #93c5fd; /* blue-300 */
}

.spool-slot {
    pointer-events: auto; /* Allow clicks to pass through to ports underneath */
}

/* New styles for spool properties */
.spool-properties-container {
    width: 100%;
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #4b5563; /* gray-600 */
}

.spool-prop-select {
    width: 50%;
    background-color: #4b5563; /* gray-600 */
    color: #d1d5db; /* gray-300 */
    border: 1px solid #6b7280; /* gray-500 */
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

/* Checkbox toggles */
.toggle-container {
    width: 100%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 0.5rem; 
    margin-top: 0.5rem; 
    padding-top: 0.5rem; 
    border-top: 1px solid #4b5563; /* gray-600 */
}

#connection-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

.connection-line {
    stroke: #60a5fa; /* blue-400 */
    stroke-width: 4px;
    fill: none;
}

/* --- Special Connection Line Types --- */
.conn-spool { stroke: #9ca3af; } /* gray-400 */
/* UPDATED: Renamed from .conn-buffer_feed */
.conn-unbuffered { stroke: #fb923c; } /* orange-400 */
.conn-filament { stroke: #3b82f6; }
/* --- End Special Connection Line Types --- */

.temp-line {
    stroke: #ef4444;
    stroke-width: 4px;
    stroke-dasharray: 5,5;
    fill: none;
}

.component-icon {
    font-size: 1.75rem;
    pointer-events: none;
}

#validation-log {
    font-family: 'Courier New', Courier, monospace;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

/* --- Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000; /* Ensure it's above components */
}

.modal-content {
    padding: 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
}

#load-list li {
    padding: 0.6rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #4b5563; /* gray-600 */
    user-select: none;
    transition: background-color 0.2s ease;
}

#load-list li:last-child {
    border-bottom: none;
}

#load-list li.selected {
    background-color: #2563eb; /* blue-600 */
    color: #eff6ff; /* blue-50 */
}

/* --- Tutorial Styles --- */
.tutorial-highlight {
    position: relative;
    z-index: 5001 !important; /* Ensure it's above the overlay */
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 15px rgba(59, 130, 246, 0.8);
    border-radius: 0.25rem;
}

.tutorial-modal {
    position: absolute;
    z-index: 5002;
    width: 320px;
    padding: 1rem;
    background-color: #1f2937; /* gray-800 */
    border: 1px solid #4b5563; /* gray-600 */
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

.tutorial-btn {
    background-color: #4b5563; /* gray-600 */
    color: #d1d5db; /* gray-300 */
    font-weight: 600;
    padding: 0.4rem 0.8rem;
    border-radius: 0.375rem;
    transition: background-color 0.2s ease;
}

.tutorial-btn:hover {
    background-color: #6b7280; /* gray-500 */
}

.tutorial-btn#tutorial-next {
    background-color: #2563eb; /* blue-600 */
}
.tutorial-btn#tutorial-next:hover {
    background-color: #1d4ed8; /* blue-700 */
}

.shop-icon {
    opacity: 1; /* MODIFIED: Was 0 */
    transition: opacity 0.2s ease-in-out;
    color: #9ca3af; /* gray-400 */
}



.shop-icon:hover {
    color: #60a5fa; /* blue-400 */
}

.macro-mode-button {
    z-index: 2002;
}

.macro-mode-button::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    border-style: solid;
    border-width: 0 48px 48px 0;
    border-color: transparent #22c55e transparent transparent; /* green-500 */
    transition: all 0.3s ease;
    z-index: -1;
    border-bottom-left-radius: 0.5rem;
}

.macro-mode-button:hover::before {
    border-width: 0 56px 56px 0;
}

.macro-btn.active {
    background-color: #a855f7; /* purple-500 */
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
}



.always-on-top {
    z-index: 2001;
}
