.p5js {
    display: grid;
    grid-template-columns: subgrid;
}

.p5js h3 {
    margin-top: 0;
}

#wada-quilt-wrapper {
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
    width: 100%;
    background-color: transparent;
    box-shadow: none;
}



#wada-quilt-wrapper h2 {
    margin-top: 0;
    margin-bottom: 10px;
}

#text-panel {
    grid-column: 1 / 6;
    flex: 1;
    grid-row: 1;
}

#button-panel {
    grid-column: 1 / 6;
    grid-row: 2;
    flex: 1;
    display: flex;
    flex-direction: column;
}

#info-panel {
    grid-column: 1 / 6;
    grid-row: 3;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    box-shadow: none;
    background-color: transparent;
    margin-top: auto;
}

#canvas-panel {
    align-items: center;
    justify-content: flex-start;
    padding-top: 0;
    grid-column: 7 / 13;
    grid-row: 1 / 4;
}

#canvas-info-wrapper {
    display: contents;
}


#intro-paragraph {
    margin-bottom: 20px;
}

#quilt-name {
    font-size: 1.5em;
    font-weight: bold;
    margin-top: 15px;
    /* Margin above text below canvas */
    margin-bottom: 0;
    /* No margin below if it's the last element after canvas */
    text-align: center;
    width: 100%;
    color: #333;
    /* Static color */
}

#wada-quilts-canvas {
    width: 100%;
}

canvas {
    max-width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    display: block;
    object-fit: contain;
}

/* Styles for all buttons, maintaining consistency */
#wada-quilt-wrapper button, #wada-quilt-wrapper select {
    font-family: Haskoy;
    padding: 6px 20px;
    background-color: #ddd;
    /* Consistent padding for all buttons */
    font-size: 1em;
    /* Consistent font size for all buttons */
    margin: 9px 0 0 0;
    /* Vertical margin */
    cursor: pointer;
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s ease, color 0.3s ease;
    /* white-space: normal; */
    /* Allow text to wrap if needed */
    text-align: center;
    /* Center text within buttons */
    width: 100%;
    /* max-width: 260px; */
    /* Consistent max-width for buttons */
    box-sizing: border-box;
    line-height: 1.2;
    height: 34px;
    /* Adjust line height for wrapped text */
}

#wada-quilt-wrapper button:hover {
    background-color: #aaa;
}

#generate-download {
    display: flex;
    gap: 10px;
}

/* Specific overrides for button text fitting */
#wada-quilt-wrapper #generateButton {
    font-size: 20px;
    flex: 6;
    color: var(--dark);
    height: 46px;
}

#generateGridButton,
#downloadButton {
    /* Apply same text size to these two */
    /* font-size: 1.0em; */
}

#generateButton:hover {
    /* background-color: var(--generate-button-hover-bg);
    color: var(--generate-button-hover-color); */
}

/* New wrapper for bottom buttons */
#buttons-panel {
    text-align: center;
    /* margin-bottom: 24px; */
    /* display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    margin-top: auto; Pushes this wrapper to the bottom of text-panel */
}

/* Custom styles for generate grid button */
#generateGridButton {
    /* background-color: var(--generate-grid-button-bg); /* Now dynamic */
    /* color: var(--generate-grid-button-color); Now dynamic */
    /* margin-top: 15px; Space from generate button (if not in wrapper) or other content */
}

#generateGridButton:hover {
    /* background-color: var(--generate-grid-button-hover-bg);
    color: var(--generate-grid-button-hover-color); */
}

/* Styles for color swatch display */
#combination-info {
    /* font-size: 1.1em;
    font-weight: bold;
    margin-bottom: 10px; */
    text-align: center;
    width: 100%;
    margin-top: 10px;
    transition: color 0.5s ease;
    color: #333;
    /* Static color for readability on transparent background */
}

#color-display {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 10px;
    margin-top: 20px;
    width: 100%;
    opacity: 0;
    transition:  0.25s ease;
}

#color-display.active {
    opacity: 1;
}

.color-swatch {
    width: 80%;
    height: 72px;
    /* Smaller swatch size for better fit */
    /* min-height: 50px; */
    /* border: 1px solid #aaa; */
    border-radius: 4px;
    /* box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2); */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 0.8em;
    text-align: center;
    line-height: 1.3;
    padding: 5px;
    /* Adjusted padding */
    box-sizing: border-box;
    white-space: normal;
    /* Allow text to wrap */
    word-break: break-word;
    /* Break long words */
    transition: background-color 0.3s ease, color 0.3s ease;
}

.color-text {
    margin: 2px 0;
    /* Space between name and hex */
}

.mode-toggle {
    display: grid;
    grid-template-columns: 1fr 60px 1fr;
    align-items: center;
    gap: 15px;
    margin: auto;
    width: 100%;
}

#wada-quilt-wrapper button.mode-option {
    background: none;
    border: none;
    width: 100%;
    font: inherit;
    cursor: pointer;
    color: var(--dark);
    background-color: #ddd;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#wada-quilt-wrapper button.mode-option:hover {
    background-color: #aaa;
}

#wada-quilt-wrapper button.mode-option.active {
    background-color: var(--dark);
    color: var(--light);
    font-weight: 500;
}

.toggle-track {
    position: relative;
    width: 60px;
    height: 32px;
    border-radius: 80px;
    background: var(--dark);
    cursor: pointer;
}

.toggle-thumb {
    margin-top: 4px;
    margin-left: 4px;

    width: 24px;
    height: 24px;

    border-radius: 50%;
    background: var(--light);

    transition:
        transform 0.25s ease,
        background-color 0.25s ease;
}

.mode-toggle.grid .toggle-thumb {
    transform: translateX(28px);
}

.mode-toggle.grid .toggle-track {
    background: var(--dark);
}

.mode-option {
    transition:
        color 0.25s ease,
        opacity 0.25s ease;
}

#grid-options-wrapper {
    width: 0%;
    /* display: none; */
    /* gap: 15px; */
    margin: auto;
    margin-right: 0px;
    overflow: hidden;
    opacity: 0;

    transition:
        margin-right 0.3s ease,
        width 0.3s ease,
        opacity 0.3s ease;
}

#options-download-wrapper {
    display: flex;
}

#grid-options-wrapper select {
    /* max-height: 0; */
    /* margin: auto; */
    overflow: hidden;
    /* width: 100%; */
    background-color: #ddd;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#grid-options-wrapper select:hover {
    background-color: #aaa;
}

#grid-options-wrapper.grid-mode {
    display: flex;
    margin-right: 15px;
    /* max-height: 100px; */
    width: 75%;
    opacity: 1;
}

#grid-options-wrapper select.grid-mode {
    /* max-height: 100px; */
    opacity: 1;
}

#wada-quilt-wrapper #downloadButton {
    width: 100%;
    transition:
        /* margin-right 0.3s ease, */
        width 0.3s ease
        /* opacity 0.3s ease; */
}

#wada-quilt-wrapper #downloadButton.grid-mode {
    width: 25%;
}

@media (max-width: 900px) {
    #canvas-info-wrapper {
        display: initial;
        grid-column: 7 / 13;
        grid-row: 1 / 4;
    }

    #button-panel {
        grid-row: 2 / 3;
        gap: 12px;
        /* align-self: flex-end; */
    }
}

@media (max-width: 800px) {

    #canvas-info-wrapper {
        display: contents;
    }

    #text-panel,
    #canvas-panel,
    #info-panel {
        /* Include info-panel for mobile stacking */
        width: 100%;
        margin-bottom: var(--gutter_size);
        /* max-width: 600px; */
        /* padding: 15px; */
        /* Re-introduce some padding for mobile panels */
        box-shadow: none;
        align-items: center;
        /* Center content within panels on mobile */
        min-height: auto;
        grid-column: 1 / -1;
        /* Remove fixed min-height for mobile */
    }

    #control-panel {
        display: contents;
    }

    #text-panel {
        grid-area: top;
    }
    #canvas-panel {
        grid-area: middle1;
    }
    #button-panel {
        grid-area: middle2;
        gap: 4px;
        margin-bottom: 20px;
    }
    #info-panel {
        grid-area: bottom;
    }


    #wada-quilt-wrapper {
        grid-template-areas: 
            "top"
            "middle2"
            "middle1"
            "bottom";
    }

    h1,
    #intro-paragraph,
    #generateButton,
    #generateGridButton,
    #downloadButton,
    #combination-info {
        /* Include combination-info */
        /* text-align: center; */
        /* align-self: center; */
        /* max-width: 90%; */
    }

    #intro-paragraph {
        margin-bottom: 0;
    }

    #generateButton,
    #generateGridButton,
    #downloadButton {
        /* margin-top: 15px; */
        /* Add margin when stacked on mobile */
    }

    #buttons-panel {
        /* margin-top: 20px; */
        /* Add some space when stacked on mobile */
        /* align-items: center; */
        margin: 30px 0;
        text-align: center;
        /* display: flex; */
        gap: 10px;
        /* Center buttons within wrapper on mobile */
    }

    #color-display {
        flex-direction: row;
        /* Display swatches in a row on mobile */
        /* flex-wrap: wrap; */
        justify-content: center;
        gap: 10px;
        /* Smaller gap for mobile */
        /* width: auto; */
        /* Allow content to dictate width */
    }

    .color-swatch {
        /* width: 90px;  */
        height: 78px;
        /* font-size: 0.7em; */
        /* padding: 5px; */
    }
}