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

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, #1e1e2f, #2a2a4a);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #e0e0e0;
    overflow-x: hidden;
    touch-action: manipulation; /* Recommended for touch interfaces to prevent accidental browser actions */
}

/* --- Navigation Bar Styles (Consistent across all pages) --- */
nav {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    z-index: 10;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    margin-bottom: 20px;
}

a {
    color: #D2D2DA;
    text-decoration: none;
    font-weight: 600;
    font-size: 1em;
    transition: color 0.3s;
}
 
nav a {
    color: #e0e0e0;
    font-size: clamp(0.9rem, 2.2vw, 1.1rem);
    transition: color 0.3s ease, background-color 0.3s ease;
    padding: 8px 15px;
    border-radius: 6px;
    white-space: nowrap;
}

a:hover {
    color: #c0c0c0;
}

nav a:hover, nav a.active {
    color: #FFD140;
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 8px rgba(255, 209, 64, 0.2);
}

footer a {
    color: #AEAEC4;
}

header {
    text-align: center;
    padding: 10px;
    width: 100%;
}

a:active {
    color: #FFD140;
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    max-width: 800px;
    margin: 0 auto;
}

.logo {
    width: clamp(60px, 15vw, 124px);
    height: clamp(60px, 15vw, 124px);
}

.subtitle {
    font-size: clamp(0.7rem, 2vw, 0.9rem);
    color: #a0a0a0;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    margin-bottom: 5px;
}

.intro-text {
    font-size: clamp(0.8rem, 2.5vw, 1rem);
    line-height: 1.2;
    margin: 0;
}

#canvasSection {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 10px;
    flex-grow: 1;
    gap: 10px;
}

#container {
    display: contents;
}

#canvasContainer {
    position: relative;
    width: clamp(250px, 90vw, 800px);
    max-height: calc(100vh - 150px);
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    overflow: hidden;
}

#mandalaCanvas, #cursorCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    cursor: crosshair;
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
    z-index: 5;
}

#sourceCanvas {
    display: none;
}

#cursorCanvas {
    pointer-events: none;
    will-change: transform;
}

#brushNavbar {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: center;
    gap: clamp(3px, 0.8vw, 6px);
    padding: 4px 6px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 0 0 8px 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    max-width: 90%;
    overflow-x: hidden;
    overflow-y: hidden;
    z-index: 20;
    height: 36px;
    opacity: 1;
}

#brushNavbar canvas.brush-preview {
    width: clamp(18px, 3vw, 24px);
    height: clamp(18px, 3vw, 24px);
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid #606060;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, background 0.2s;
    image-rendering: pixelated;
    flex-shrink: 1;
}

#brushNavbar canvas.brush-preview:hover {
    transform: scale(1.15);
    background: rgba(255, 255, 255, 0.4);
    border-color: #808080;
}

#brushNavbar canvas.brush-preview.selected {
    border: 2px solid #FFD140;
    transform: scale(1.15);
    background: rgba(255, 255, 255, 0.4);
}

#customBrushEditorButton {
    font-size: clamp(0.6rem, 1.6vw, 0.7rem);
    background: rgba(255, 255, 255, 0.4);
    color: #c0c0d0;
    border: 1px solid #606060;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s;
    height: clamp(22px, 3.5vw, 28px);
    padding: 0 clamp(5px, 0.8vw, 8px);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    flex-shrink: 1;
}

#customBrushEditorButton:hover {
    background: rgba(255, 255, 255, 0.5);
    color: #e0e0e0;
    transform: scale(1.05) translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

#brushSetToggleButton {
    color: #c0c0d0;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid #606060;
    font-size: clamp(0.6rem, 1.6vw, 0.7rem);
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s;
    margin-right: 6px;
    white-space: nowrap;
    order: -1;
    height: clamp(22px, 3.5vw, 28px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    flex-shrink: 1;
}

#brushSetToggleButton:hover {
    background: rgba(255, 255, 255, 0.5);
    border-color: #808080;
    color: #e0e0e0;
    transform: translateY(-1px);
}

.tooltip {
    position: relative;
}

.tooltip::after {
    display: none !important;
}

input[type="color"] {
    width: clamp(30px, 5vw, 40px);
    height: clamp(30px, 5vw, 40px);
    border: none;
    padding: 0;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: transparent;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
    width: 100%;
    height: 100%;
}

input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 50%;
    width: 100%;
    height: 100%;
}

#actionNavbar {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-wrap: nowrap;
    gap: clamp(5px, 1vw, 10px);
    padding: 5px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    max-width: 95%;
    overflow-x: auto;
    z-index: 10;
}

#actionNavbar button, .popup button, .control-group button, sub-controls button {
    padding: clamp(3px, 1vw, 8px) clamp(6px, 2vw, 12px);
    font-size: clamp(0.7rem, 2vw, 0.8rem);
    min-width: clamp(35px, 8vw, 50px);
    border: none;
    cursor: pointer;
    background: #38333F;
    color: #e0e0e0;
    transition: background 0.3s, color 0.3s;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
    border-radius: 5px;
}

#actionNavbar button:hover, .popup button:hover, .control-group button:hover, .sub-controls button:hover {
    background: #494766;
    color: #c0c0c0;
}

/* --- ADDED --- Keyframe animation for the active button flash */
@keyframes active-glow-flash {
    0% {
        box-shadow: 0 0 0 0px rgba(255, 209, 64, 0);
    }
    50% {
        box-shadow: 0 0 8px 2px rgba(255, 209, 64, 0.9);
    }
    100% {
        box-shadow: 0 0 0 0px rgba(255, 209, 64, 0);
    }
}

#actionNavbar #pureSpinToggle.active,
#actionNavbar #startDrawing.active,
#actionNavbar button.active { /* Generic active rule for record button etc. */
    background: #FFD140;
    color: #1e1e2f;
    animation: active-glow-flash 0.6s ease-out;
}

#controls, #controls-left {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    width: clamp(120px, 15vw, 160px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #606060 #2a2a4a;
    z-index: 10;
    flex-shrink: 0;
}

#controls::-webkit-scrollbar, #controls-left::-webkit-scrollbar {
    width: 6px;
}

#controls::-webkit-scrollbar-track, #controls-left::-webkit-scrollbar-track {
    background: #2a2a4a;
}

#controls::-webkit-scrollbar-thumb, #controls-left::-webkit-scrollbar-thumb {
    background: #606060;
    border-radius: 3px;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.control-group label {
    font-size: clamp(0.7rem, 2vw, 0.8rem);
    color: #a0a0a0;
    font-weight: 600;
    text-align: center;
    margin-bottom: 5px;
}

.control-group input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    background: #606060;
    border-radius: 5px;
    height: 5px;
    outline: none;
    cursor: pointer;
    margin: 5px 0;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: #e0e0e0;
    border-radius: 50%;
    cursor: pointer;
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: #e0e0e0;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.control-group select {
    width: 100%;
    padding: 5px;
    background: #38333F;
    color: #e0e0e0;
    border: none;
    border-radius: 5px;
    font-size: clamp(0.7rem, 2vw, 0.8rem);
    cursor: pointer;
}

.control-group span {
    font-size: clamp(0.7rem, 2vw, 0.8rem);
    color: #e0e0e0;
    margin-top: 5px;
    display: inline-block;
    text-align: right;
}

.control-group button.active {
    background: #FFD140;
    color: #1e1e2f;
}

.footer {
    width: 100%;
    padding: 20px;
    text-align: center;
    color: #e0e0e0;
    font-size: clamp(0.8rem, 2vw, 1rem);
    margin-top: auto;
    position: relative;
    z-index: 15;
    max-width: 800px;
}

.footer a {
    color: silver;
    text-decoration: none;
    transition: color 0.3s;
    margin: 0 10px;
}

.sub-controls {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.popup.active {
    display: flex;
    opacity: 1;
}

.popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1;
}

.popup-content {
    position: relative;
    background: linear-gradient(135deg, #1e1e2f, #2a2a4a);
    padding: clamp(20px, 5vw, 30px);
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    color: #e0e0e0;
    text-align: left;
    max-width: clamp(300px, 90vw, 500px);
    max-height: 80vh;
    overflow-y: auto;
    z-index: 2;
    scrollbar-width: thin;
    scrollbar-color: #606060 #2a2a4a;
}

.popup-content::-webkit-scrollbar {
    width: 6px;
}

.popup-content::-webkit-scrollbar-track {
    background: #2a2a4a;
}

.popup-content::-webkit-scrollbar-thumb {
    background: #606060;
    border-radius: 3px;
}

.popup-content h2 {
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    margin-bottom: 15px;
    text-align: center;
}

#undo:disabled, #redo:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#mandalaCanvas {
    touch-action: none;
}

.social-links {
    margin-top: 30px;
    text-align: center;
}

.social-links a {
    margin: 0 10px;
    text-decoration: none;
    font-size: 1.1rem;
}

.social-links img {
    width: 28px;
    height: 28px;
    vertical-align: middle;
}

.controls-preset-slots-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    width: 100%;
    max-width: 200px;
    padding: 8px;
    justify-content: center;
    z-index: 15;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.controls-preset-slot {
    width: 100%;
    height: 40px;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.7rem, 2vw, 0.8rem);
    font-weight: bold;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2) inset;
    transition: all 0.15s ease-out;
}

.controls-preset-slot:hover {
    border-color: #909090 !important; 
    background-color: #494766 !important;
    transform: scale(1.05);
}

.controls-preset-slot:active {
    transform: scale(0.97);
    background-color: #2a2a4a !important;
}

.controls-preset-slot.empty {
    background-color: #303030 !important; 
    border: 2px dashed #606060 !important;
    color: #707070 !important;
}

.controls-preset-slot.empty:hover {
    background-color: #383838 !important;
    border-color: #808080 !important;
}

.controls-preset-slot.filled {
    border-style: solid !important;
}

.controls-preset-slot.filled.slot-0 { background-color: #4a4030 !important; border-color: #806040 !important; color: #FFDAB9 !important; }
.controls-preset-slot.filled.slot-1 { background-color: #4a3030 !important; border-color: #804040 !important; color: #FFA07A !important; }
.controls-preset-slot.filled.slot-2 { background-color: #304a30 !important; border-color: #408040 !important; color: #90EE90 !important; }
.controls-preset-slot.filled.slot-3 { background-color: #30304a !important; border-color: #404080 !important; color: #ADD8E6 !important; }

.adjusting {
    border: 2px solid #FFD140;
    transition: border 0.2s;
}

.settings-popup {
    display: none;
}

.settings-popup.active {
    display: flex;
    opacity: 1;
}

/* --- Premium Feature Visibility --- */
.premium-feature-1,
.premium-feature-2 {
    display: none;
}

.premium-feature-1.premium-unlocked,
.premium-feature-2.premium-unlocked {
    display: flex;
}

/* Button style for primary actions, like Quickstart, Donate, etc. */
.primary-action-btn {
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: #FFD140;
    color: #1e1e2f;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.primary-action-btn:hover {
    background: #e6b800;
    transform: translateY(-2px);
}

/* --- Desktop Layout --- */
@media (min-width: 900px) {
    #canvasSection {
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        align-items: flex-start;
        gap: 20px;
        max-width: 1200px;
    }

    #canvasContainer {
        width: clamp(400px, 60vw, 800px);
        height: clamp(400px, 60vw, 800px);
        max-height: calc(100vh - 100px);
        margin: 0;
    }

    #controls {
        width: clamp(120px, 15vw, 160px);
        margin-left: 10px;
        flex-shrink: 0;
    }

    #controls-left {
        display: flex;
        width: clamp(120px, 15vw, 160px);
        margin-right: 10px;
        flex-shrink: 0;
    }
    
    #controls-left .control-group > button.active {
        background-color: #FFD140 !important;
        color: #1e1e2f !important;
    }

    .settings-popup.mobile-only {
        display: none !important;
    }
}
/* Animation for preset slot save/override feedback */
.slot-saved-flash-animation {
    animation: yellowFlash 0.4s ease-in-out;
}

@keyframes yellowFlash {
    0% {
        background-color: #FFD140 !important; /* Bright yellow */
        border-color: #FFD140 !important;
        color: #1e1e2f !important; /* Dark text for contrast */
    }
    50% {
        background-color: #FFE082 !important; /* Slightly lighter yellow */
        border-color: #FFE082 !important;
    }
    100% {
        background-color: inherit !important; /* Revert to original background */
        border-color: inherit !important; /* Revert to original border */
        color: inherit !important; /* Revert to original text color */
    }
}
/* Animation for preset slot save/override feedback */
.slot-saved-flash-animation {
    animation: yellowFlash 0.4s ease-in-out;
}

@keyframes yellowFlash {
    0% {
        background-color: #FFD140 !important; /* Bright yellow */
        border-color: #FFD140 !important;
        color: #1e1e2f !important; /* Dark text for contrast */
    }
    50% {
        background-color: #FFE082 !important; /* Slightly lighter yellow */
        border-color: #FFE082 !important;
    }
    100% {
        background-color: inherit !important; /* Revert to original background */
        border-color: inherit !important; /* Revert to original border */
        color: inherit !important; /* Revert to original text color */
    }
}
/* --- Mobile Layout --- */
@media (max-width: 1181px) {
    #controls-left {
        display: none !important;
    }

    #controls .mobile-only {
        display: flex !important;
    }

    .settings-popup:not(.active) {
        display: none !important;
    }
}
/* =================================================== */
/* ==   Universal Button Color Correction Snippet   == */
/* =================================================== */

/* This snippet resets the default and active colors for all toggle buttons 
   on desktop and mobile to fix color inconsistencies. */

/* --- Default (Inactive) State --- */
/* Targets main toggles (Echo, Glow, Halo) and nested toggles (Echo Scaling). */
#controls-left .control-group > button,
#controls-left .sub-controls > button,
#mobile-panel-effects .control-group > button,
#mobile-panel-effects .sub-controls > button {
    background-color: #38333F !important; /* Standard dark button color */
    color: #e0e0e0 !important;
    border-color: transparent !important; 
}

/* --- Active State --- */
/* Targets the same buttons but only when they have the .active class. */
#controls-left .control-group > button.active,
#controls-left .sub-controls > button.active,
#mobile-panel-effects .control-group > button.active,
#mobile-panel-effects .sub-controls > button.active {
    background-color: #FFD140 !important; /* Consistent gold active color */
    color: #1e1e2f !important;
}

/* NEW RULE TO FIX CENTERING */
.sub-controls > * {
    align-self: center;
}
/* --- Video Preview Popup Enhancements --- */

/* Make the popup content a flex column */
.popup-content.video-popup-content {
    display: flex;
    flex-direction: column;
}

/* Allow the video to shrink and constrain its height */
.popup-content.video-popup-content video {
    flex-shrink: 1; /* Allows the video to shrink to fit available space */
    min-height: 0;  /* Prevents flexbox overflow issues */
    max-height: 55vh; /* Limits video height to 55% of the viewport height */
    object-fit: contain; /* Ensures video scales correctly without cropping */
    background-color: #111;
    border-radius: 8px;
}

/* Make the instructions area scrollable if needed */
.popup-content.video-popup-content #saveInstructions {
    flex-shrink: 1; /* Allows this section to shrink */
    overflow-y: auto; /* Adds a scrollbar only if content overflows */
    margin-top: 10px;
    padding: 8px;
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
}

/* Ensure the action buttons never shrink or get pushed off-screen */
.popup-content.video-popup-content .video-popup-actions {
    flex-shrink: 0;
    margin-top: 15px;
}
#controls-left .sub-controls {
    display: flex !important;
}


/* Premium Gallery Styles */
.premium-gallery {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    max-width: 800px;
    margin: 0 auto;
}

.premium-gallery figure {
    margin: 0;
    text-align: center;
}

.premium-gallery img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border: 1px solid #ccc;
    border-radius: 5px;
    transition: transform 0.2s;
}

.premium-gallery img:hover {
    transform: scale(1.05);
}

.premium-gallery figcaption {
    font-size: clamp(0.7rem, 2vw, 0.8rem);
    color: #a0a0a0;
    margin-top: 5px;
}

/* Ensure responsiveness aligns with desktop/mobile layouts */
@media (min-width: 900px) {
    .premium-gallery {
        max-width: 1200px;
    }
}

@media (max-width: 1181px) {
    .premium-gallery {
        padding: 5px;
        gap: 5px;
    }

    .premium-gallery img {
        width: 80px;
        height: 80px;
    }
}