body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background: url('Background.webp') no-repeat center center fixed;
    background-size: cover;
    font-family: 'Varela Round', sans-serif;
    padding: 20px;
    box-sizing: border-box;
}

.glass-panel {
    background: rgba(255, 255, 255, 0.35);
    border-radius: 25px;
    padding: 25px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "title title"
        "clock controls";
    gap: 25px;
    max-width: 850px;
    width: 100%;
    position: relative;
}

.back-button {
    position: absolute;
    top: 15px;
    left: 25px;
    text-decoration: none;
    color: #003366;
    background: rgba(255, 255, 255, 0.3);
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.9em;
    transition: background 0.2s;
    z-index: 10;
}
.back-button:hover {
    background: rgba(255, 255, 255, 0.6);
}

.main-title {
    grid-area: title;
    font-family: 'Audiowide', cursive;
    font-size: 2.5em;
    color: #003366;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.7), 0 0 10px rgba(255, 255, 255, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
    margin: 0 0 10px 0;
    text-align: center;
}

.clock-container {
    grid-area: clock;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 0; /* FIX: Prevent grid blowout */
}
canvas#clockCanvas {
    border-radius: 50%;
    width: 100%;
    max-width: 380px;
    aspect-ratio: 1 / 1;
}
.chord-display {
    position: absolute;
    bottom: 25%;
    font-family: 'Varela Round', sans-serif;
    font-size: 1.2em;
    color: #003366;
    opacity: 0.6;
    text-shadow: 0 1px 2px rgba(255,255,255,0.5);
    pointer-events: none;
}

.controls-container {
    grid-area: controls;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    min-width: 0; /* FIX: Prevent grid blowout */
}

.display-panel {
    background: linear-gradient(145deg, rgba(255,255,255,0.6) 0%, rgba(200,230,255,0.4) 100%);
    border-radius: 15px;
    padding: 10px 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), inset 0 0 8px rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.5);
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    color: #002244;
    text-shadow: 0 1px 2px rgba(255,255,255,0.8);
    text-align: center;
}

#digitalClock {
    font-size: 1.5em;
    letter-spacing: 2px;
}

.freq-panel {
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 1.1em;
    padding: 12px;
    flex-wrap: wrap;
}
.freq-panel > div {
    display: flex;
    align-items: center;
    gap: 8px;
}
.freq-panel .freq-value {
    font-family: 'Roboto Mono', monospace;
    font-weight: 400;
    min-width: 100px;
    text-align: left;
}
.freq-label-h { font-weight: bold; color: #757575; }
.freq-label-m { font-weight: bold; color: #4285F4; }
.freq-label-s { font-weight: bold; color: #E63946; }

.interactive-controls {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.waveform-controls {
    display: flex;
    justify-content: center;
    gap: 5px;
    flex-basis: 60%;
    min-width: 200px;
}
.wave-btn {
    padding: 5px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.5); background: rgba(255, 255, 255, 0.2); color: #003366; cursor: pointer; transition: background 0.2s; font-size: 0.8em; flex-grow: 1;
}
.wave-btn:hover { background: rgba(255, 255, 255, 0.4); }
.wave-btn.active { background: rgba(255, 255, 255, 0.8); box-shadow: 0 0 10px rgba(255,255,255,0.5); font-weight: bold; }

.octave-controls {
    display: flex;
    gap: 5px;
    flex-basis: 35%;
    min-width: 150px;
}
.octave-group {
    display: flex;
    align-items: center;
    gap: 4px;
}
input[type="number"] {
    width: 35px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    color: #003366;
    text-align: center;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9em;
}

.volume-controls {
    display: flex;
    justify-content: space-around;
    align-items: center;
    color: #003366;
    flex-wrap: wrap;
}
.slider-group {
    display: flex;
    align-items: center;
    gap: 5px;
}
input[type="range"] {
    -webkit-appearance: none; width: 70px; height: 7px; background: rgba(255, 255, 255, 0.5); border-radius: 5px; outline: none; box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none; width: 16px; height: 16px; background: white; border-radius: 50%; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.2); margin-top: -4.5px;
}

canvas#oscilloscopeCanvas {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,255,0,0.4), inset 0 0 8px rgba(0,255,0,0.3);
    width: 100%;
    height: 80px;
}

.main-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

#soundToggleButton {
    width: 85px; height: 38px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.5); font-weight: bold; font-size: 1em; cursor: pointer; transition: all 0.2s ease-in-out; box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
#soundToggleButton.on { background: linear-gradient(145deg, rgba(144,238,144,0.8) 0%, rgba(60,179,113,0.7) 100%); color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.3); }
#soundToggleButton.off { background: linear-gradient(145deg, rgba(255,160,122,0.8) 0%, rgba(220,20,60,0.7) 100%); color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.3); }
#soundToggleButton:hover { transform: scale(1.05); }

#syncButton {
    padding: 7px 12px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.5); background: rgba(100, 181, 246, 0.7); color: white; font-weight: bold; cursor: pointer; transition: background 0.2s;
}
#syncButton:hover { background: rgba(66, 165, 245, 1); }

.slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #003366;
    font-weight: bold;
}
#speedSlider {
    width: 100%;
}
.speed-display {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.9em;
    background: rgba(255,255,255,0.3);
    padding: 3px 6px;
    border-radius: 5px;
    min-width: 45px;
    text-align: center;
}

@media (max-width: 700px) {
    body { padding: 10px; }
    .glass-panel {
        grid-template-columns: 1fr;
        grid-template-areas: "title" "clock" "controls";
        max-width: 400px;
        padding: 15px;
    }
    .main-title { font-size: 2em; }
    .clock-container { max-width: 300px; margin: 0 auto; }
    .controls-container { min-width: 0; }
    .main-controls { flex-direction: column; gap: 12px; }
    .slider-container { width: 100%; justify-content: center; }
    .back-button { top: 10px; left: 15px; }
    .freq-panel { flex-direction: column; gap: 5px; align-items: flex-start; }
}

@media (max-width: 420px) {
    .main-title { font-size: 1.8em; }
    .interactive-controls, .volume-controls {
        flex-direction: column;
    }
    .waveform-controls, .octave-controls {
        width: 100%;
        flex-basis: 100%;
    }
    .slider-group {
        width: 100%;
        justify-content: space-between;
    }
}
