:root {
    --primary: #3b82f6;
    --secondary: #64748b;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #eab308;
    --accent: #8b5cf6;
    --background: #1e293b;
    --panel: #334155;
    --muted: #94a3b8;
    --text: #f1f5f9;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    padding: 16px;
    overflow-x: hidden;
}

.app {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--panel);
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.logo {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    border-radius: 50%;
    font-size: 24px;
}

.title-container {
    flex: 1;
}

h1 {
    font-size: 24px;
    margin-bottom: 4px;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.lead {
    color: var(--muted);
    font-size: 14px;
}

.tooltip {
    position: relative;
}

.tooltip-text {
    position: absolute;
    bottom: 100%;
    right: 0;
    width: 250px;
    padding: 12px;
    background: var(--panel);
    border-radius: 8px;
    font-size: 13px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    transform: translateY(10px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 100;
}

.tooltip:hover .tooltip-text {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.btn-primary.pulse {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.main-container {
    display: flex;
    gap: 20px;
}

.panel {
    background: var(--panel);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

aside.panel {
    width: 280px;
    flex-shrink: 0;
}

main.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.map-container {
    position: relative;
    height: 80px;
    margin-bottom: 20px;
}

.map-path {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--secondary);
    transform: translateY(-50%);
    border-radius: 2px;
}

.map-nodes {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.map-node {
    position: absolute;
    width: 40px;
    height: 40px;
    background: var(--secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: all 0.3s;
    z-index: 2;
}

.map-node.active {
    background: var(--primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.4);
    transform: translate(-50%, -50%) scale(1.1);
}

.map-node.completed {
    background: var(--success);
    transform: translate(-50%, -50%) scale(1.1);
}

.map-node.locked {
    background: var(--danger);
    cursor: not-allowed;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.level-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.level-desc {
    color: var(--muted);
    font-size: 14px;
}

.controls {
    display: flex;
    gap: 12px;
}

.component-palette {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    flex-wrap: wrap;
}

.palette-item {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    border-radius: 8px;
    cursor: grab;
    font-size: 24px;
    transition: all 0.2s;
    position: relative;
}

.palette-item:hover {
    background: var(--primary);
    transform: translateY(-2px);
}

.palette-item.dragging {
    opacity: 0.5;
    transform: scale(0.9);
}

.palette-item .component-tooltip {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    pointer-events: none;
}

.palette-item:hover .component-tooltip {
    opacity: 1;
    visibility: visible;
}

.circuit-container {
    position: relative;
    min-height: 500px;
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.circuit-canvas {
    position: relative;
    width: 100%;
    height: 400px;
    order: 1;
}

.drag-over {
    box-shadow: 0 0 0 3px var(--primary) inset;
}

.drag-ghost {
    position: absolute;
    width: 70px;
    height: 70px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    opacity: 0.8;
    z-index: 1000;
    pointer-events: none;
}

#svg {
    width: 100%;
    height: 100%;
}

.current-flow {
    position: absolute;
    top: 0;
    left: 0;
    width: 12px;
    height: 12px;
    background: var(--primary);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
    filter: drop-shadow(0 0 6px var(--primary));
}

.components-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-top: 20px;
    padding: 16px;
    background: var(--panel);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    order: 2;
    z-index: 10;
}

.component {
    padding: 16px;
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.1);
}

.component-label {
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.component-label i {
    font-size: 16px;
    color: var(--primary);
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.slider {
    flex: 1;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: #475569;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.slider-value {
    min-width: 60px;
    text-align: center;
    font-size: 14px;
    background: var(--background);
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 600;
}

.switch-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider-switch {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--secondary);
    border-radius: 28px;
    transition: .4s;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.slider-switch:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: .4s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider-switch {
    background: var(--success);
}

input:checked + .slider-switch:before {
    transform: translateX(32px);
}

.switch-status {
    font-size: 12px;
    font-weight: 600;
    margin-left: 10px;
    color: var(--muted);
}

input:checked + .slider-switch + .switch-status {
    color: var(--success);
}

.status-panel {
    display: flex;
    gap: 20px;
}

.energy-meter, .lamp-status {
    flex: 1;
    padding: 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
}

.meter-bar {
    height: 8px;
    background: var(--secondary);
    border-radius: 4px;
    margin: 8px 0;
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s;
}

.lamp-icon {
    width: 50px;
    height: 50px;
    background: var(--danger);
    border-radius: 50%;
    margin: 8px auto;
    transition: all 0.3s;
}

.lamp-icon.on {
    background: var(--success);
    box-shadow: 0 0 20px var(--success);
}

.lamp-icon.dim {
    background: var(--warning);
    box-shadow: 0 0 10px var(--warning);
}

.lamp-icon.burned {
    background: #000;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

.wire-tool {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    cursor: pointer;
    z-index: 20;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.wire-tool.active {
    background: var(--success);
    box-shadow: 0 0 0 3px var(--accent);
}

.connection-point {
    fill: rgba(255, 255, 255, 0.5);
    stroke: white;
    stroke-width: 1;
    r: 7;
    cursor: crosshair;
}

.connection-point.active {
    fill: var(--primary);
    r: 9;
}

.wire {
    stroke: #f1f5f9;
    stroke-width: 3;
    fill: none;
}

.wire.selected {
    stroke: var(--primary);
    stroke-width: 4;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

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

.modal {
    background: var(--panel);
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.modal-header {
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 16px;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--primary);
}

.modal-content {
    margin-bottom: 24px;
    line-height: 1.6;
}

.level-info-box {
    background: rgba(0,0,0,0.2);
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
    border-left: 4px solid var(--primary);
}

.level-info-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--primary);
}

.fixed-values {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 12px 0;
}

.fixed-value-item {
    background: rgba(0,0,0,0.2);
    padding: 8px;
    border-radius: 6px;
    font-size: 14px;
}

.fixed-value-label {
    color: var(--muted);
    font-size: 12px;
}

.fixed-value {
    font-weight: 600;
}

.connection-mode .circuit-canvas {
    cursor: crosshair;
}

.connection-mode .connection-point {
    cursor: pointer;
}

.circuit-component {
    cursor: move;
}

.circuit-component.moving {
    opacity: 0.7;
}

.current-flow {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--primary);
    border-radius: 50%;
    filter: drop-shadow(0 0 6px var(--primary));
    z-index: 15;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.current-flow.animating {
    opacity: 1;
}

.success-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s;
}

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

.success-modal {
    background: var(--panel);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.success-icon {
    font-size: 70px;
    color: var(--success);
    margin-bottom: 20px;
}

.magnet-control {
    margin-top: 15px;
    padding: 10px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
}

.component-count {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.component-symbol {
    font-size: 32px;
    margin-bottom: 5px;
}

.connection-mode .connection-point:hover,
.connection-point.active {
    fill: var(--primary);
    r: 9;
    stroke: white;
    stroke-width: 2;
}

.component-text {
    fill: white;
    font-size: 12px;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}

.curve-wire {
    stroke: #f1f5f9;
    stroke-width: 3;
    fill: none;
}

.completion-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s;
}

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

.completion-modal {
    background: var(--panel);
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 15px 40px rgba(0,0,0,0.5);
}

.completion-icon {
    font-size: 80px;
    color: var(--success);
    margin-bottom: 20px;
    animation: pulse 2s infinite;
}

.progress-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 5px 10px;
    background: var(--panel);
    border-radius: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.debug-panel {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: rgba(0,0,0,0.7);
    padding: 10px;
    border-radius: 8px;
    font-size: 12px;
    max-width: 300px;
    z-index: 1000;
}