/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    color: #ffffff;
    overflow-x: hidden;
    /* Responsive height based on environment */
    height: 450px; /* Default iframe height */
    width: 100%;
}

/* Detect if running in new tab vs iframe */
@media (min-height: 500px) {
    body {
        height: 90vh;
    }
}

#synth-container {
    width: 100%;
    height: 100%;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

/* Tooltip styles */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    max-width: 250px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    border: 1px solid #444;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tooltip.show {
    opacity: 1;
}

/* Module base styles */
.module {
    background: linear-gradient(145deg, #2a2a3e, #1f1f32);
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #444;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

.module:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.module h3 {
    color: #00d4ff;
    font-size: 14px;
    margin-bottom: 8px;
    text-align: center;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

/* Layout sections */
.top-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    height: auto;
}

.middle-section {
    height: auto;
}

.bottom-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    height: auto;
}

.keyboard-section,
.visualizer-section {
    height: auto;
}

/* Control group styles */
.control-group {
    margin-bottom: 8px;
}

.control-group label {
    display: block;
    font-size: 11px;
    color: #ccc;
    margin-bottom: 4px;
    font-weight: bold;
}

.control-group input[type="range"] {
    width: 100%;
    height: 20px;
    background: #333;
    border-radius: 10px;
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: linear-gradient(45deg, #00d4ff, #0099cc);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: linear-gradient(45deg, #00d4ff, #0099cc);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.control-group span {
    display: block;
    font-size: 10px;
    color: #00d4ff;
    text-align: center;
    margin-top: 2px;
    font-weight: bold;
}

/* Button styles */
.wave-btn, .filter-btn {
    background: linear-gradient(145deg, #3a3a4e, #2a2a3e);
    border: 1px solid #555;
    color: white;
    padding: 6px 8px;
    margin: 2px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.2s;
    min-height: 28px;
    flex: 1;
}

.wave-btn:hover, .filter-btn:hover {
    background: linear-gradient(145deg, #4a4a5e, #3a3a4e);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.wave-btn.active, .filter-btn.active {
    background: linear-gradient(145deg, #00d4ff, #0099cc);
    color: #000;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.4);
}

.waveform-selector, .filter-type {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

/* Play button */
.play-button {
    width: 100%;
    padding: 12px;
    background: linear-gradient(145deg, #ff6b6b, #ee5a52);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.play-button:hover {
    background: linear-gradient(145deg, #ff5252, #e53935);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
}

.play-button.playing {
    background: linear-gradient(145deg, #4caf50, #45a049);
}

/* LFO specific styles */
.lfo-destination {
    margin-top: 8px;
}

.lfo-destination select {
    width: 100%;
    padding: 6px;
    background: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 11px;
}

/* Envelope visual */
.envelope-visual {
    margin-bottom: 8px;
    text-align: center;
}

#envelope-canvas {
    background: #1a1a2e;
    border: 1px solid #444;
    border-radius: 4px;
    width: 100%;
    height: 60px;
}

/* ADSR controls */
.adsr-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

/* Keyboard styles */
.keyboard {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 60px;
    position: relative;
    margin-top: 8px;
}

.key {
    cursor: pointer;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    user-select: none;
    transition: all 0.1s;
    border-radius: 0 0 4px 4px;
}

.key.white {
    width: 30px;
    height: 50px;
    background: linear-gradient(to bottom, #ffffff, #f0f0f0);
    border: 1px solid #ccc;
    color: #333;
    z-index: 1;
    padding-bottom: 4px;
}

.key.black {
    width: 20px;
    height: 30px;
    background: linear-gradient(to bottom, #333, #111);
    border: 1px solid #000;
    color: white;
    position: absolute;
    z-index: 2;
    margin-left: -10px;
    padding-bottom: 2px;
}

.key:hover {
    transform: translateY(2px);
}

.key.active {
    transform: translateY(4px);
}

.key.white.active {
    background: linear-gradient(to bottom, #e0e0e0, #d0d0d0);
}

.key.black.active {
    background: linear-gradient(to bottom, #555, #333);
}

/* Position black keys */
.key.black:nth-of-type(2) { left: 22px; }
.key.black:nth-of-type(4) { left: 52px; }
.key.black:nth-of-type(7) { left: 112px; }
.key.black:nth-of-type(9) { left: 142px; }
.key.black:nth-of-type(11) { left: 172px; }

/* Waveform visualizer */
#waveform-canvas {
    width: 100%;
    height: 60px;
    background: #1a1a2e;
    border: 1px solid #444;
    border-radius: 4px;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    #synth-container {
        padding: 4px;
        gap: 6px;
    }
    
    .module {
        padding: 8px;
    }
    
    .top-section,
    .bottom-section {
        grid-template-columns: 1fr;
    }
    
    .adsr-controls {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .key.white {
        width: 25px;
        height: 45px;
    }
    
    .key.black {
        width: 18px;
        height: 28px;
        margin-left: -9px;
    }
    
    .wave-btn, .filter-btn {
        padding: 8px 6px;
        font-size: 9px;
    }
}

/* Touch-friendly sizing */
@media (pointer: coarse) {
    .key {
        min-height: 44px;
    }
    
    .wave-btn, .filter-btn {
        min-height: 44px;
        padding: 8px;
    }
    
    .play-button {
        min-height: 44px;
        padding: 12px;
    }
    
    input[type="range"] {
        height: 30px;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
}