/* ---
    Global Resets & Typography
--- */
:root {
    --background-color: #0a0a0a;
    --text-color: rgba(255, 255, 255, 1); /* Full opacity for maximum readability */
    --primary-color: #ffffff;
    --secondary-color: rgba(255, 255, 255, 0.85); /* Increased opacity for better readability */
    --font-main: 'Inter', sans-serif;
    --font-serif: 'Lora', serif;
}

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

body {
    background-color: var(--background-color);
    color: var(--text-color);
    font-family: var(--font-main);
    line-height: 1.6;
    overflow: hidden; /* Prevent scrolling during experience */
}

#vanta-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* ---
    Onboarding Experience Styling (Mobile-First)
--- */

#onboarding-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.5s ease-out;
    z-index: 100;
    overflow-y: auto; /* Enable vertical scrolling */
    padding: 20px 0; /* Add padding to ensure content isn't flush with edges */
}

#onboarding-container.hidden {
    opacity: 0;
    pointer-events: none;
}

.onboarding-step {
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    max-width: 90%; /* Use percentage for better flexibility */
    padding: 1rem;
    animation: fadeIn 0.8s ease-in-out;
    margin: auto; /* Center vertically when scrolling */
}

/* First screen (welcome) remains the same size */
#welcome-screen {
    max-width: 90%;
}

/* Disclaimer and preparation screens are narrower on mobile */
#disclaimer-screen, #preparation-screen {
    max-width: 85%;
}

.onboarding-step.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Shift the onboarding content to the right to make room for the sidebar toggle */
.onboarding-content {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    width: 100%; /* Ensure content takes full width of container */
    padding-left: 0; /* Remove the padding that was pushing content */
    position: relative; /* Allow absolute positioning within */
}

.onboarding-title {
    font-family: var(--font-serif);
    font-size: 2rem; /* Reduced for mobile */
    font-weight: 600;
    color: var(--primary-color);
    line-height: 1.2;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9), 0 0 4px rgba(0, 0, 0, 0.5); /* Enhanced shadow for better readability */
    letter-spacing: 0.01em; /* Slightly increased letter spacing */
    margin-top: 10px; /* Add some top margin to prevent overlap with toggle button */
}

.onboarding-subtitle {
    font-family: var(--font-serif);
    font-size: 1.2rem; /* Slightly increased for better readability */
    font-weight: 600;
    color: var(--primary-color);
    margin-top: 0.8rem;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.5); /* Enhanced shadow for better readability */
}

.onboarding-text {
    font-size: 1.05rem; /* Slightly increased for better readability */
    color: var(--text-color);
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.6); /* Enhanced shadow for better readability */
    letter-spacing: 0.02em; /* Increased letter spacing */
    font-weight: 400;
    /* Removed the background I added previously */
}

.onboarding-quote {
    font-family: var(--font-serif);
    font-style: italic;
    color: var(--secondary-color);
    margin-top: 0.8rem;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.5); /* Enhanced shadow for better readability */
    font-weight: 500; /* Increased weight for better visibility */
}

.disclaimer-list, .preparation-list {
    list-style: none;
    text-align: left;
    margin: 0 auto;
    width: 100%; /* Take full available width */
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

/* Smaller font size for lists on mobile */
.disclaimer-list li, .preparation-list li {
    font-size: 1rem; /* Slightly increased for better readability */
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.6); /* Enhanced shadow for better readability */
    /* Removed the background I added previously */
}

.disclaimer-list li::before, .preparation-list li::before {
    content: '→';
    margin-right: 10px;
    color: var(--primary-color);
}

.onboarding-button {
    background: var(--primary-color);
    color: var(--background-color);
    border: 1px solid var(--primary-color);
    padding: 10px 20px; /* Adjusted padding */
    border-radius: 50px;
    font-size: 0.9rem; /* Adjusted font size */
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 1.5rem; /* More space before buttons */
    align-self: center;
}

.onboarding-button:hover {
    background: transparent;
    color: var(--primary-color);
}


/* ---
    Main Dreamachine Interface
--- */

canvas {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#threejs-canvas {
    z-index: 1;
}

.hidden {
    display: none !important;
}

/* ---
    Controls Styling (Mobile-First)
--- */
#controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    width: 90%; /* Use percentage width */
    transform: translateX(-50%);
    background: rgba(20, 20, 20, 0.9); /* Increased opacity for better contrast */
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 15px; /* Adjusted padding */
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.15); /* Increased border opacity */
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column; /* Stack controls vertically on mobile */
    align-items: stretch; /* Stretch items to fill width */
    gap: 15px; /* Space out stacked controls */
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.frequency-buttons-group {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.freq-button {
    flex-grow: 1;
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-color);
    padding: 10px 5px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.freq-button:hover {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.freq-button.active,
.freq-button.active:hover {
    background-color: #ffffff;
    color: #0a0a0a;
    border-color: #ffffff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.control-group {
    display: flex;
    justify-content: space-between; /* Space out label and control */
    align-items: center;
    gap: 10px;
}

.control-group.frequency-slider-group {
    flex-direction: column; /* Stack slider label on top */
    align-items: stretch;
    gap: 8px;
}

.control-group label, .mode-display {
    font-size: 0.9rem;
    color: var(--secondary-color);
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); /* Added shadow for better readability */
}

.control-button {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-color);
    padding: 10px 15px; /* Larger tap target */
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s ease;
}

.control-button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.control-button.exit {
    background: rgba(220, 50, 50, 0.7);
}
.control-button.exit:hover {
    background: rgba(220, 50, 50, 1);
}

#hz-value {
    color: var(--primary-color);
    font-weight: 500;
    text-align: right; /* Align to the right in its container */
}

/* Slider Styles */
#freq-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%; /* Full width */
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    outline: none;
    transition: opacity 0.2s;
}

#freq-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px; /* Larger thumb for touch */
    height: 24px; /* Larger thumb for touch */
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
}

#freq-slider::-moz-range-thumb {
    width: 24px; /* Larger thumb for touch */
    height: 24px; /* Larger thumb for touch */
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

/* ---
    Music Player Controls
--- */
.music-control-group {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    /* Remove any styling that makes it look like a container */
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.track-info {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    text-align: center;
    flex-grow: 1;
    color: var(--primary-color);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

/* Music button ripple effect */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 0.7;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

.music-button {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.08));
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--primary-color);
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    position: relative;
    overflow: hidden; /* Important for ripple effect */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    /* Remove any double border appearance */
    outline: none;
}

.music-button::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, transparent 70%);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    border-radius: 20px;
}

.music-button:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.music-button:hover::after {
    opacity: 0.5;
    transform: translate(-50%, -50%) scale(1);
}

/* Enhanced active state with more visible feedback */
.music-button:active {
    transform: translateY(1px);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.1s ease;
}

.music-button:active::after {
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(0.9);
    transition: opacity 0.1s, transform 0.1s;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.6) 0%, transparent 70%);
}

/* Add a ripple animation when clicked */
.music-button.clicked::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150%;
    height: 150%;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    animation: buttonRipple 0.6s ease-out;
}

@keyframes buttonRipple {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0.8;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

/* Hide sidebar toggle during the Dreamachine experience */
#dreamachine-container:not(.hidden) ~ #sidebar-toggle {
    display: none;
}

/* Mobile optimizations for control bar */
@media (max-width: 767px) {
    #controls {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        padding: 15px;
        gap: 15px;
        max-height: none; /* Remove height restriction */
        overflow: visible; /* Allow content to be visible */
    }
    
    .control-group {
        margin: 0;
        flex: 1;
        min-width: 0;
        flex-basis: 40%; /* Set a base width */
        display: flex;
        justify-content: center;
    }
    
    .control-group.frequency-slider-group {
        flex: 2;
        flex-basis: 100%; /* Full width for slider on mobile */
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        order: -1; /* Move to the top */
        margin-bottom: 5px;
    }
    
    .music-control-group {
        flex: 1;
        flex-basis: 45%;
        justify-content: center;
        /* Ensure consistent styling with desktop */
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
    }
    
    .music-button {
        padding: 8px 12px;
        font-size: 0.8rem;
        height: auto;
        width: auto; /* Let it size to content */
        /* Ensure consistent styling with desktop */
        border-radius: 20px;
        background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.08));
    }
    
    /* Removed music note icon for mobile */
    .music-button::before {
        content: "";
        margin: 0;
    }
    
    #freq-slider {
        flex: 1;
        min-width: 0;
    }
    
    #hz-value {
        width: 50px;
        text-align: right;
        font-size: 0.85rem;
        white-space: nowrap;
    }
    
    .control-button {
        height: 30px;
        padding: 0 10px;
        font-size: 0.75rem;
        white-space: nowrap;
    }
}

/* Additional breakpoint for very small screens */
@media (max-width: 380px) {
    #controls {
        padding: 15px;
        gap: 12px;
        width: 95%; /* Slightly wider on very small screens */
    }
    
    .control-group {
        flex-basis: 100%; /* Full width for all controls */
        margin-bottom: 8px;
        justify-content: center;
    }
    
    .control-group.frequency-slider-group {
        margin-bottom: 8px;
    }
    
    .music-control-group, 
    .control-group:not(.frequency-slider-group) {
        justify-content: center;
    }
    
    .music-button {
        width: 100%;
    }
    
    .control-button {
        width: 100%;
    }
    
    #hz-value {
        min-width: 45px;
    }
}

/* ---
    Sidebar Styles
--- */
#sidebar {
    position: fixed;
    top: 0;
    left: 0; /* Changed from -320px to 0 */
    width: 300px;
    height: 100%;
    background: rgba(10, 10, 10, 0.97);
    backdrop-filter: blur(10px);
    z-index: 1000;
    transition: transform 0.3s ease;
    overflow-y: auto;
    padding: 20px;
    box-shadow: 3px 0 15px rgba(0, 0, 0, 0.5);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    transform: translateX(-100%); /* Move it off-screen with transform instead */
}

#sidebar.active {
    transform: translateX(0); /* Bring it fully on screen */
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 30px; /* Add padding to prevent overlap with close button */
}

.sidebar-section {
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 10px 0;
    transition: all 0.2s ease;
}

.sidebar-header:hover {
    color: var(--primary-color);
}

.sidebar-header h3 {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    color: var(--primary-color);
    margin: 0;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.sidebar-header i {
    color: var(--secondary-color);
    transition: transform 0.3s ease;
}

.sidebar-header.active i {
    transform: rotate(180deg);
}

.sidebar-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding-left: 10px;
    padding-bottom: 0;
    opacity: 0;
}

.sidebar-body.active {
    max-height: 100vh; /* Use viewport height to ensure content is not cut off */
    padding-bottom: 15px;
    opacity: 1;
}

.sidebar-body p {
    color: var(--text-color);
    font-size: 0.95rem;
    line-height: 1.6;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    margin-top: 10px;
}

/* Position the sidebar toggle absolutely so it doesn't affect layout flow */
#sidebar-toggle {
    position: fixed;
    top: 15px; /* Moved slightly higher */
    left: 15px; /* Moved slightly left */
    background: rgba(20, 20, 20, 0.7); /* Darker background for better contrast */
    border: 1px solid rgba(255, 255, 255, 0.2); /* Subtle border */
    color: var(--text-color);
    width: 36px; /* Slightly smaller */
    height: 36px; /* Slightly smaller */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 200; /* Lower z-index than sidebar */
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    -webkit-tap-highlight-color: transparent; /* Better touch experience on mobile */
    touch-action: manipulation; /* Improve touch response */
}

#sidebar.active ~ #sidebar-toggle {
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none; /* Make button unclickable when hidden */
}

#sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
}

#sidebar-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    color: var(--secondary-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    -webkit-tap-highlight-color: transparent; /* Better touch experience on mobile */
    touch-action: manipulation; /* Improve touch response */
}

/* Remove exit message */
#exit-message {
    display: none !important;
}

/* ---
    Desktop and Tablet Enhancements
--- */
@media (min-width: 768px) {
    #onboarding-container {
        overflow-y: hidden; /* Disable scrolling on larger screens */
        padding: 0; /* Remove padding on desktop */
    }
    
    .onboarding-step {
        max-width: 600px;
        padding: 2rem;
    }
    
    /* Reset all screens to same width on desktop */
    #welcome-screen, #disclaimer-screen, #preparation-screen {
        max-width: 600px;
    }

    .onboarding-title {
        font-size: 2.7rem; /* Increased size for better visibility */
    }

    .onboarding-subtitle {
        font-size: 1.3rem; /* Increased size */
    }

    .onboarding-text {
        font-size: 1.15rem; /* Increased size */
    }
    
    .disclaimer-list li, .preparation-list li {
        font-size: 1.1rem; /* Restore font size on desktop */
    }
    
    .onboarding-button {
        padding: 12px 24px;
        font-size: 1rem;
        margin-top: 0.8rem; /* Less space needed on desktop */
    }

    #controls {
        flex-direction: row; /* Horizontal layout on larger screens */
        width: auto; /* Auto width based on content */
        align-items: center;
        gap: 30px;
        bottom: 30px;
        padding: 15px 25px;
    }

    .control-group.frequency-slider-group {
        flex-direction: row; /* Back to horizontal */
        align-items: center;
        gap: 10px;
    }

    #freq-slider {
        width: 120px; /* Restore original width */
    }

    #hz-value {
       min-width: 60px;
    }

    .music-control-group {
        width: auto;
        justify-content: center;
    }
    
    .track-info {
        min-width: 150px;
        font-size: 1rem;
    }
    
    #sidebar {
        width: 350px;
        transform: translateX(-100%); /* Ensure it's fully off-screen on desktop too */
    }
    
    #sidebar.active {
        transform: translateX(0); /* Ensure it's fully visible on desktop */
    }
    
    .sidebar-header h3 {
        font-size: 1.3rem;
    }
    
    .sidebar-body p {
        font-size: 1rem;
    }

    /* Adjust sidebar toggle for larger screens */
    #sidebar-toggle {
        top: 25px;
        left: 25px;
        width: 40px; /* Back to original size */
        height: 40px; /* Back to original size */
        background: rgba(255, 255, 255, 0.15); /* Original background */
    }
    
    /* Remove extra padding on larger screens where there's more space */
    .onboarding-content {
        padding-left: 0;
    }
    
    .onboarding-title {
        margin-top: 0; /* Remove top margin on desktop */
    }
} 