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

body {
    font-family: 'Orbitron', sans-serif;
    background: linear-gradient(135deg, #0a0a0f 0%, #1a1a2e 50%, #0f0f1a 100%);
    color: #e0e0e0;
    min-height: 100vh;
    overflow: hidden;
    text-transform: uppercase;
}

#toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: rgba(20, 20, 30, 0.95);
    border-bottom: 1px solid #00ffff33;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 60px 0 20px;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: #00ffff;
    text-shadow: 0 0 10px #00ffff55;
    letter-spacing: 2px;
}

.toolbar-btn {
    padding: 10px 18px;
    min-height: 40px;
    background: rgba(0, 255, 255, 0.1);
    border: 1px solid #00ffff55;
    color: #00ffff;
    font-family: 'Orbitron', sans-serif;
    font-size: 11px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.toolbar-btn:hover,
.toolbar-btn:active {
    background: rgba(0, 255, 255, 0.25);
    box-shadow: 0 0 15px #00ffff33;
}

.toolbar-btn:active {
    transform: scale(0.97);
}

.toolbar-btn.danger {
    border-color: #ff555555;
    color: #ff5555;
    background: rgba(255, 85, 85, 0.1);
}

.toolbar-btn.danger:hover {
    background: rgba(255, 85, 85, 0.25);
}

#workspaceSelect {
    padding: 6px 10px;
    background: rgba(30, 30, 40, 0.9);
    border: 1px solid #555;
    color: #e0e0e0;
    font-family: 'Orbitron', sans-serif;
    font-size: 11px;
    border-radius: 4px;
    min-width: 150px;
}

#canvas-container {
    position: fixed;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
}

#connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 5000px;
    height: 5000px;
    pointer-events: none;
    z-index: 10;
}

#connections-svg path {
    pointer-events: stroke;
    cursor: pointer;
    stroke-width: 3;
    touch-action: none;
}

#connections-svg path:hover {
    stroke-width: 6;
}

#modules-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 5000px;
    height: 5000px;
    z-index: 2;
}

.module {
    position: absolute;
    width: 280px;
    background: rgba(25, 25, 35, 0.95);
    border: 2px solid #333;
    border-radius: 8px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
    cursor: grab;
    user-select: none;
    touch-action: none;
    -webkit-user-select: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.module:hover {
    border-color: #00ffff55;
}

.module.selected {
    border-color: #00ffff;
    box-shadow: 0 0 30px #00ffff33;
}

.module.dragging {
    cursor: grabbing;
    opacity: 0.9;
    z-index: 100;
}

/* Fullscreen mode - module expands to fill screen without moving iframe */
.module.module-fullscreen {
    position: fixed !important;
    top: 50px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 50px) !important;
    z-index: 3000 !important;
    border-radius: 0 !important;
    border: none !important;
    cursor: default;
    display: flex !important;
    flex-direction: column !important;
    background: #0a0a0f !important;
}

.module.module-fullscreen .module-header {
    border-radius: 0;
    padding: 12px 20px;
    flex-shrink: 0;
    background: rgba(20, 20, 30, 1);
    border-bottom: 1px solid #333;
    z-index: 10;
}

.module.module-fullscreen .module-preview {
    flex: 1 !important;
    height: auto !important;
    overflow: hidden;
}

/* Reset the zoom/scale transform for fullscreen */
.module.module-fullscreen .module-preview iframe {
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
    transform-origin: center !important;
    pointer-events: auto !important;
}

.module.module-fullscreen .module-preview-overlay {
    display: none !important;
}

.module.module-fullscreen .module-ports {
    display: none !important;
}

.module.module-fullscreen .module-btn.expand {
    display: none !important;
}

.module.module-fullscreen .module-btn.close {
    width: 36px;
    height: 36px;
    font-size: 20px;
    background: rgba(0, 255, 255, 0.2) !important;
    color: #00ffff !important;
}

/* Hide cables and other modules when a module is fullscreen */
#canvas-container:has(.module-fullscreen) #connections-svg {
    display: none !important;
}

#canvas-container:has(.module-fullscreen) .module:not(.module-fullscreen) {
    visibility: hidden;
}

.module-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: linear-gradient(180deg, rgba(40, 40, 55, 1) 0%, rgba(30, 30, 45, 1) 100%);
    border-radius: 6px 6px 0 0;
    border-bottom: 1px solid #444;
}

.module-title {
    font-size: 12px;
    font-weight: 600;
    color: #00ffff;
    letter-spacing: 1px;
}

.module-controls {
    display: flex;
    gap: 8px;
}

.module-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.module-btn.expand {
    background: rgba(0, 255, 255, 0.2);
    color: #00ffff;
}

.module-btn.expand:hover,
.module-btn.expand:active {
    background: rgba(0, 255, 255, 0.4);
}

.module-btn.close {
    background: rgba(255, 85, 85, 0.2);
    color: #ff5555;
}

.module-btn.close:hover,
.module-btn.close:active {
    background: rgba(255, 85, 85, 0.4);
}

.module-preview {
    width: 100%;
    height: 160px;
    background: #111;
    position: relative;
    overflow: hidden;
}

.module-preview iframe {
    width: 400%;
    height: 400%;
    border: none;
    transform: scale(0.25);
    transform-origin: top left;
    pointer-events: none;
}

.module-preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    transition: background 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.module-preview-overlay:hover,
.module-preview-overlay:active {
    background: rgba(0, 255, 255, 0.1);
}

.module-preview-overlay:hover::after {
    content: 'Click to expand';
    color: #00ffff;
    font-size: 11px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 4px;
}

.module-ports {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(20, 20, 30, 0.8);
    border-radius: 0 0 6px 6px;
}

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

.port-group-label {
    font-size: 9px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.port {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: crosshair;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    padding: 4px 0;
}

.port.input {
    flex-direction: row;
}

.port.output {
    flex-direction: row-reverse;
}

.port-dot {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    border-radius: 50%;
    border: 3px solid #666;
    background: #222;
    transition: all 0.15s;
    cursor: crosshair;
    position: relative;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.port-dot::before {
    content: '';
    position: absolute;
    top: -12px;
    left: -12px;
    right: -12px;
    bottom: -12px;
    border-radius: 50%;
}

.port-dot.midi-in {
    border-color: #ff00ff;
}

.port-dot.midi-out {
    border-color: #00ff88;
}

.port-dot:hover, .port-dot.active {
    transform: scale(1.3);
    box-shadow: 0 0 10px currentColor;
}

.port-dot.midi-in:hover, .port-dot.midi-in.active {
    background: #ff00ff;
    box-shadow: 0 0 15px #ff00ff;
}

.port-dot.midi-out:hover, .port-dot.midi-out.active {
    background: #00ff88;
    box-shadow: 0 0 15px #00ff88;
}

.port-dot.midi-in.connected {
    background: #ff00ff;
    box-shadow: 0 0 12px #ff00ff, 0 0 4px #ff00ff inset;
}

.port-dot.midi-out.connected {
    background: #00ff88;
    box-shadow: 0 0 12px #00ff88, 0 0 4px #00ff88 inset;
}

.port-dot.connecting {
    animation: pulse 0.5s ease-in-out infinite;
}

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

.port-label {
    font-size: 10px;
    color: #aaa;
}

#module-palette {
    position: fixed;
    top: 60px;
    left: 20px;
    width: 300px;
    max-height: 70vh;
    background: rgba(25, 25, 35, 0.98);
    border: 1px solid #00ffff44;
    border-radius: 8px;
    z-index: 500;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.palette-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    background: rgba(0, 255, 255, 0.1);
    border-bottom: 1px solid #00ffff33;
    font-size: 13px;
    font-weight: 600;
    color: #00ffff;
}

.palette-header button {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    min-width: 40px;
    min-height: 40px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.palette-header button:hover,
.palette-header button:active {
    color: #fff;
}

#palette-apps {
    padding: 10px;
    max-height: calc(70vh - 50px);
    overflow-y: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.palette-app {
    padding: 14px 12px;
    min-height: 48px;
    background: rgba(40, 40, 55, 0.8);
    border: 1px solid #444;
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.palette-app:hover,
.palette-app:active {
    background: rgba(0, 255, 255, 0.15);
    border-color: #00ffff55;
}

.palette-app:active {
    transform: scale(0.97);
}

.palette-app-name {
    font-size: 11px;
    font-weight: 600;
    color: #e0e0e0;
    margin-bottom: 4px;
}

.palette-app-type {
    font-size: 9px;
    color: #888;
    text-transform: uppercase;
}

#fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(20, 20, 30, 1);
    border-bottom: 1px solid #333;
}

#modal-title {
    font-size: 14px;
    font-weight: 600;
    color: #00ffff;
}

#closeModalBtn {
    width: 32px;
    height: 32px;
    background: rgba(255, 85, 85, 0.2);
    border: 1px solid #ff555555;
    border-radius: 4px;
    color: #ff5555;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#closeModalBtn:hover {
    background: rgba(255, 85, 85, 0.4);
}

#modal-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#modal-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

#context-menu {
    position: fixed;
    background: rgba(25, 25, 35, 0.98);
    border: 1px solid #444;
    border-radius: 6px;
    min-width: 160px;
    z-index: 3000;
    overflow: hidden;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
}

.context-item {
    padding: 10px 15px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.context-item:hover {
    background: rgba(0, 255, 255, 0.15);
}

.context-item.danger {
    color: #ff5555;
}

.context-item.danger:hover {
    background: rgba(255, 85, 85, 0.15);
}

.hidden {
    display: none !important;
}

.connection-line {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
}

.connection-line.midi {
    stroke: url(#midiGradient);
}

.connection-line:hover {
    stroke-width: 5;
    filter: drop-shadow(0 0 8px #00ffff);
}

.connection-line.active {
    stroke-width: 5;
    filter: drop-shadow(0 0 12px #00ffff) drop-shadow(0 0 6px #ff00ff);
    animation: flowAnimation 0.3s linear infinite;
}

@keyframes flowAnimation {
    from { stroke-dashoffset: 15; }
    to { stroke-dashoffset: 0; }
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(20, 20, 30, 0.5);
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}
