/*──────────────────────── RESET + VARIABLES ───────────────────────*/
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --ff-ui: "Inter", system-ui, sans-serif;

    /* Paleta de colores mejorada */
    --c-text: #e8eaf6;
    --c-text-secondary: #b0bec5;
    --c-bg: #0a0e1a;
    --c-bg-secondary: #1a1f2e;
    --c-surface: #1e2430;
    --c-surface-hover: #252b3a;
    
    --c-primary: #64b5f6;
    --c-primary-hover: #42a5f5;
    --c-secondary: #7c4dff;
    --c-accent: #ff6b6b;
    --c-success: #4caf50;
    
    /* Gradientes */
    --gradient-bg: linear-gradient(135deg, #0a0e1a 0%, #1a1f2e 100%);
    --gradient-surface: linear-gradient(145deg, #1e2430 0%, #252b3a 100%);
    --gradient-primary: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
    
    /* Sombras */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(100, 181, 246, 0.3);
    
    /* Bordes */
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    
    --dock-h: 4rem;
}

/*──────────────────────── ESTRUCTURA BÁSICA ───────────────────────*/
html,
body {
    max-height: 100%;
}

body {
    font-family: var(--ff-ui);
    color: var(--c-text);
    background: var(--gradient-bg);
    display: flex;
    flex-direction: column;
    padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    min-height: 100vh;
}

/*──────────────────────── HEADER & FOOTER ─────────────────────────*/
header,
footer {
    text-align: center;
    background: var(--gradient-surface);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

header {
    padding-block: 1rem;
    box-shadow: var(--shadow-sm);
}

header h1 {
    font-size: clamp(1.8rem, 3vw + 1rem, 2.8rem);
    font-weight: 700;
    color: var(--c-primary);
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: clamp(0.9rem, 1.5vw + 0.5rem, 1.2rem);
    color: var(--c-text-secondary);
    font-weight: 400;
    opacity: 0.8;
}

footer {
    padding-block: 0.6rem;
    font-family: "JetBrains Mono", "Courier New", monospace;
    font-size: 0.8rem;
    color: var(--c-text-secondary);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/*──────────────────────── MAIN ────────────────────────────────────*/
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem;
    overflow: auto;
}

/*──────────────────────── CANVAS ──────────────────────────────────*/
canvas {
    width: 100%;
    max-width: 100%;
    height: 70dvh;
    border: none;
    border-radius: var(--border-radius-lg);
    display: block;
    touch-action: none;
    background: var(--gradient-surface);
    box-shadow: var(--shadow-md);
    transition: box-shadow 0.2s ease;
}

canvas:hover {
    box-shadow: var(--shadow-lg);
}

/*──────────────────────── CONTROLES (DOCK MÓVIL) ──────────────────*/
aside {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    height: var(--dock-h);
    padding-inline: 1rem;
    background: rgba(30, 36, 48, 0.9);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.2rem;
    z-index: 10;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
}

fieldset {
    border: none;
    padding: 0;
}

legend {
    display: none;
}

.field-wrapper {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

/*──────────────────────── INPUTS Y BOTONES ────────────────────────*/
input[type="number"],
input[type="color"] {
    width: 3.8rem;
    height: 2.4rem;
    font: inherit;
    color: var(--c-text);
    background: var(--gradient-surface);
    border: 1px solid rgba(100, 181, 246, 0.3);
    border-radius: var(--border-radius-sm);
    padding: 0.3rem 0.5rem;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

input[type="number"]:focus,
input[type="color"]:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.2);
    outline: none;
}

input[type="color"] {
    width: 2.8rem;
    padding: 0;
    cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    border-radius: var(--border-radius-sm);
    overflow: hidden;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: var(--border-radius-sm);
}

button {
    inline-size: 2.4rem;
    block-size: 2.4rem;
    border: none;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

button:hover {
    background: linear-gradient(135deg, #42a5f5 0%, #1e88e5 100%);
}

button:active {
    background: linear-gradient(135deg, #1e88e5 0%, #1565c0 100%);
}

/*──────────────────────── MODOS ≥768 px ───────────────────────────*/
@media (min-width: 768px) {
    body {
        padding-bottom: 0;
    }

    main {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 2.5rem;
        padding: 2rem;
    }

    canvas {
        max-width: 75vw;
        height: 75vh;
    }

    aside {
        position: static;
        height: auto;
        width: auto;
        padding: 1.5rem;
        background: var(--gradient-surface);
        backdrop-filter: none;
        flex-direction: column;
        gap: 1.5rem;
        border-radius: var(--border-radius-lg);
        border: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: var(--shadow-md);
        min-width: 200px;
    }

    legend {
        display: block;
        font-size: 0.9rem;
        font-weight: 600;
        margin-bottom: 0.6rem;
        color: var(--c-primary);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .field-wrapper {
        flex-direction: column;
        gap: 0.5rem;
    }

    input[type="number"],
    input[type="color"] {
        width: 100%;
        height: 2.8rem;
    }

    input[type="color"] {
        width: 100%;
        height: 3rem;
    }

    button {
        inline-size: 2.8rem;
        block-size: 2.8rem;
        font-size: 1.3rem;
    }

    footer {
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        background: var(--gradient-surface);
        backdrop-filter: blur(10px);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
}

/*──────────────────────── ANIMACIONES ─────────────────────────────*/
/* Animaciones reducidas para mejor rendimiento */

/*──────────────────────── ACCESIBILIDAD ───────────────────────────*/
:focus-visible {
    outline: 2px solid var(--c-primary);
    outline-offset: 2px;
}

/* Mejoras para modo oscuro automático */
@media (prefers-color-scheme: dark) {
    :root {
        --c-text: #f5f5f5;
        --c-text-secondary: #b0bec5;
    }
}

/* Scrollbar personalizado */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--c-bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--c-primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--c-primary-hover);
}