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

/* CSS Variables for theming */
:root {
    --bg-color: #f4f4f4;
    --container-bg: #fff;
    --text-color: #333;
    --text-secondary: #666;
    --border-color: #ccc;
    --shadow: rgba(0, 0, 0, 0.1);
    --block-bg: #fafafa;
    --input-bg: #fff;
    --input-border: #ccc;
    --canvas-bg: #fff;
    --canvas-border: #ccc;
}

body {
    font-family: Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Dark Mode */
body.dark-mode {
    --bg-color: #1a1a1a;
    --container-bg: #2d2d2d;
    --text-color: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #444;
    --shadow: rgba(0, 0, 0, 0.3);
    --block-bg: #3a3a3a;
    --input-bg: #404040;
    --input-border: #555;
    --canvas-bg: #2d2d2d;
    --canvas-border: #555;
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--container-bg);
    border: 2px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px var(--shadow);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px var(--shadow);
}

.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.theme-toggle .sun-icon {
    opacity: 1;
    transform: rotate(0deg);
}

.theme-toggle .moon-icon {
    opacity: 0;
    transform: rotate(180deg);
}

body.dark-mode .theme-toggle .sun-icon {
    opacity: 0;
    transform: rotate(180deg);
}

body.dark-mode .theme-toggle .moon-icon {
    opacity: 1;
    transform: rotate(0deg);
}

.theme-toggle svg {
    stroke: var(--text-color);
}

/* Container */
.container {
    width: 95%;
    max-width: 1000px;
    margin: 0 auto;
    background: var(--container-bg);
    padding: 20px;
    box-shadow: 0 0 10px var(--shadow);
    border-radius: 8px;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
}

/* Header Styles */
.site-header {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Modern geometric pattern overlay */
.site-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        linear-gradient(30deg, rgba(255, 255, 255, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.05) 87.5%, rgba(255, 255, 255, 0.05)),
        linear-gradient(150deg, rgba(255, 255, 255, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.05) 87.5%, rgba(255, 255, 255, 0.05)),
        linear-gradient(30deg, rgba(255, 255, 255, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.05) 87.5%, rgba(255, 255, 255, 0.05)),
        linear-gradient(150deg, rgba(255, 255, 255, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.05) 87.5%, rgba(255, 255, 255, 0.05));
    background-size: 80px 140px;
    background-position: 0 0, 0 0, 40px 70px, 40px 70px;
    pointer-events: none;
}

/* Dark mode header */
body.dark-mode .site-header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

body.dark-mode .site-header::before {
    background-image:
        linear-gradient(30deg, rgba(255, 255, 255, 0.02) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.02) 87.5%, rgba(255, 255, 255, 0.02)),
        linear-gradient(150deg, rgba(255, 255, 255, 0.02) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.02) 87.5%, rgba(255, 255, 255, 0.02)),
        linear-gradient(30deg, rgba(255, 255, 255, 0.02) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.02) 87.5%, rgba(255, 255, 255, 0.02)),
        linear-gradient(150deg, rgba(255, 255, 255, 0.02) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.02) 87.5%, rgba(255, 255, 255, 0.02));
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    position: relative;
    z-index: 1;
}

.logo-svg {
    width: 120px;
    height: 120px;
    background: white;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease;
}

.logo-svg:hover {
    transform: rotate(5deg) scale(1.05);
}

.logo-text {
    text-align: left;
}

.site-title {
    font-size: 2.5rem;
    font-weight: bold;
    color: white;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    letter-spacing: -1px;
}

.site-subtitle {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.9);
    margin: 5px 0 0 0;
    font-weight: 300;
}

.site-header .description {
    color: white;
    font-size: 1rem;
    line-height: 1.6;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 15px;
    position: relative;
    z-index: 1;
}

.site-header .description a {
    color: #FFE66D;
    text-decoration: none;
    font-weight: bold;
    border-bottom: 2px solid transparent;
    transition: border-color 0.3s ease;
}

.site-header .description a:hover {
    border-bottom-color: #FFE66D;
}

/* Block Form */
#block-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    padding: 20px;
    background-color: var(--container-bg);
    border-radius: 8px;
    box-shadow: 0 0 10px var(--shadow);
    transition: background-color 0.3s ease;
}

.block-config {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: var(--block-bg);
    padding: 10px;
    border-radius: 6px;
    transition: transform 0.2s, background-color 0.3s ease;
}

.block-config:hover {
    transform: translateY(-5px);
}

.block-config svg {
    width: 40px;
    height: 40px;
    margin-bottom: 5px;
}

.block-config label {
    font-size: 14px;
    margin-bottom: 5px;
    text-align: center;
    color: var(--text-color);
    transition: color 0.3s ease;
}

.block-config input[type="number"] {
    width: 60px;
    padding: 5px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    text-align: center;
    background: var(--input-bg);
    color: var(--text-color);
    transition: all 0.3s ease;
}

/* Grid Configuration */
.grid-config {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background-color: var(--block-bg);
    padding: 10px;
    border-radius: 6px;
    transition: background-color 0.3s ease;
}

.grid-config label {
    font-size: 14px;
    font-weight: bold;
    color: var(--text-color);
    transition: color 0.3s ease;
}

.grid-config input {
    width: 60px;
    padding: 5px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    text-align: center;
    background: var(--input-bg);
    color: var(--text-color);
    transition: all 0.3s ease;
}

/* Buttons */
.buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    grid-column: span 2;
}

.buttons button {
    padding: 10px 20px;
    background-color: #337ab7;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s ease;
    height: 40px;
}

.buttons button:hover {
    background-color: #286090;
}

#reset-btn {
    background-color: #f44336;
}

#reset-btn:hover {
    background-color: #c62828;
}

/* Solution and Summary Container */
.solution-summary-container {
    display: flex;
    flex-direction: row;
    gap: 20px;
    margin-top: 20px;
    width: 100%;
    max-width: 1000px;
    justify-content: center;
    flex-wrap: nowrap; /* Prevent wrapping on desktop */
}

.solution-display {
    flex: 1; /* Allow the solution box to grow */
    max-width: 75%; /* Restrict the solution box to a maximum of 75% of the container width */
    min-width: 50%; /* Ensure it doesn't shrink below 50% */
}

.summary-display {
    flex: 1; /* Allow the summary box to grow */
    max-width: 30%; /* Restrict the summary box to a maximum of 40% of the container width */
    min-width: 25%; /* Ensure it doesn't shrink below 25% */
}

#solution-canvas {
    display: block;
    margin: 0 auto;
    background-color: var(--canvas-bg);
    border: 2px solid var(--canvas-border);
    border-radius: 8px;
    transition: all 0.3s ease;
}

#solution-info {
    text-align: center;
    margin-bottom: 20px;
    font-size: 18px;
    color: var(--text-color);
    transition: color 0.3s ease;
}

/* Modal Styling */
.modal {
    display: none; /* Hide modal by default */
    position: fixed; /* Stay in place */
    z-index: 1000; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: hidden; /* Disable scroll */
    background-color: rgba(0, 0, 0, 0.5); /* Black with opacity */
}

.modal-content {
    background-color: var(--container-bg);
    margin: 15% auto; /* Centered vertically and horizontally */
    padding: 20px;
    border: 1px solid var(--border-color);
    width: 80%;
    max-width: 300px;
    border-radius: 8px;
    text-align: center;
    position: relative;
    color: var(--text-color);
    transition: all 0.3s ease;
}

#countdown-timer {
    font-size: 24px;
    font-weight: bold;
    margin-top: 10px;
    color: var(--text-color);
}

/* Footer Styles */
.site-footer {
    text-align: center;
    padding: 20px;
    margin-top: 20px;
}

.site-footer small {
    color: var(--text-secondary);
    line-height: 1.6;
    transition: color 0.3s ease;
}

.site-footer a {
    color: #337ab7;
    text-decoration: none;
    transition: color 0.3s ease;
}

.site-footer a:hover {
    text-decoration: underline;
}

body.dark-mode .site-footer a {
    color: #5da3ff;
}

/* Mobile Design (Specific Changes for Screens < 800px) */
@media (max-width: 800px) {
    .solution-summary-container {
        flex-direction: column; /* Stack elements vertically */
        gap: 20px; /* Add space between stacked elements */
        flex-wrap: wrap; /* Allow wrapping on mobile */
    }

    .solution-display, .summary-display {
        max-width: 100%; /* Full width for both boxes */
        min-width: 100%; /* Both boxes take up full width */
    }

    #block-form {
        grid-template-columns: repeat(2, 1fr); /* 2 blocks per row */
        gap: 15px; /* Add space between blocks */
    }

    .block-config {
        flex-direction: column; /* Stack SVG, label, and input vertically */
        align-items: center; /* Center the block content */
        padding: 10px; /* Add padding for better touch usability */
        border: 1px solid #ddd; /* Light border for better distinction */
        border-radius: 6px;
        background-color: #fff;
    }

    .block-config svg {
        width: 40px; /* Keep the SVG large for visibility */
        height: 40px;
        margin-bottom: 5px; /* Space between SVG and label */
    }

    .block-config label {
        font-size: 14px; /* Larger font for better readability */
        margin-bottom: 5px;
        text-align: center;
    }

    .block-config input[type="number"] {
        width: 60px; /* Larger input for easier interaction */
        font-size: 16px; /* Increase font size for better visibility */
        padding: 5px;
        text-align: center;
        border: 1px solid #ccc;
        border-radius: 4px;
    }

    .buttons {
        flex-direction: column; /* Stack buttons vertically */
        gap: 15px; /* Add space between buttons */
        margin-top: 20px; /* Add margin for separation */
    }

    .buttons button {
        width: 100%; /* Full-width buttons */
        padding: 15px; /* Larger padding for easier tapping */
        font-size: 16px; /* Increase font size for readability */
        border-radius: 6px; /* Rounded buttons */
    }

    #solution-canvas {
        width: 100%; /* Full width for the canvas */
        height: auto; /* Maintain aspect ratio */
    }

    #solution-info {
        font-size: 14px; /* Adjust text size */
    }

    #summary-text {
        font-size: 14px; /* Adjust text size */
        line-height: 1.5; /* Improve readability */
    }

    .description {
        font-size: 14px; /* Ensure description text is readable */
        text-align: justify;
        margin-bottom: 15px;
    }

    /* Header Mobile Styles */
    .site-header {
        padding: 20px 15px;
    }

    .logo-container {
        flex-direction: column;
        gap: 15px;
    }

    .logo-svg {
        width: 100px;
        height: 100px;
    }

    .logo-text {
        text-align: center;
    }

    .site-title {
        font-size: 1.8rem;
    }

    .site-subtitle {
        font-size: 0.95rem;
    }

    .site-header .description {
        font-size: 0.9rem;
        text-align: center;
    }

    /* Theme toggle mobile positioning */
    .theme-toggle {
        top: 15px;
        right: 15px;
        width: 45px;
        height: 45px;
    }
}
