/* =========================================================
   GOOGLE FONT — Roboto (tipografía estándar de Material Design)
========================================================= */

@import url(
    'https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700;900&display=swap'
);


/* =========================================================
   RESET
========================================================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}


/* =========================================================
   MATERIAL DESIGN 3 — DESIGN TOKENS
   (Dark theme, esquema de color derivado del morado original #BB86FC)
========================================================= */

:root {

    /* ---- Color roles (M3 dark scheme) ---- */
    --md-sys-color-primary:              #D0BCFF;
    --md-sys-color-on-primary:           #381E72;
    --md-sys-color-primary-container:    #4F378B;
    --md-sys-color-on-primary-container: #EADDFF;

    --md-sys-color-secondary:            #CCC2DC;
    --md-sys-color-tertiary:             #7BD9C6;

    --md-sys-color-error:                #F2B8B5;
    --md-sys-color-on-error:             #601410;
    --md-sys-color-error-container:      #8C1D18;
    --md-sys-color-on-error-container:   #F9DEDC;

    /* Extended color (no forma parte del set base de M3, pero sigue su convención) */
    --md-sys-color-success:              #A0D9A8;
    --md-sys-color-on-success:           #0B3B12;
    --md-sys-color-success-container:    #1D4B28;

    /* ---- Superficies (neutrales, escala tonal M3) ---- */
    --md-sys-color-surface-dim:            #141218;
    --md-sys-color-surface:                #141218;
    --md-sys-color-surface-bright:         #3B383E;

    --md-sys-color-surface-container-lowest:  #0F0D13;
    --md-sys-color-surface-container-low:     #1D1B20;
    --md-sys-color-surface-container:         #211F26;
    --md-sys-color-surface-container-high:    #2B2930;
    --md-sys-color-surface-container-highest: #36343B;

    --md-sys-color-on-surface:            #E6E0E9;
    --md-sys-color-on-surface-variant:    #CAC4D0;

    --md-sys-color-outline:               #938F99;
    --md-sys-color-outline-variant:       #49454F;

    /* ---- State layer opacities (M3 interaction states) ---- */
    --md-state-hover:    0.08;
    --md-state-focus:    0.12;
    --md-state-pressed:  0.12;

    /* ---- Shape scale (M3 corner radii) ---- */
    --md-shape-xs:   4px;
    --md-shape-sm:   8px;
    --md-shape-md:   12px;
    --md-shape-lg:   16px;
    --md-shape-xl:   28px;
    --md-shape-full: 999px;

    /* ---- Elevation (M3 dark-theme shadow + tonal surface) ---- */
    --md-elevation-0: none;

    --md-elevation-1:
        0 1px 2px rgba(0,0,0,.55),
        0 1px 3px 1px rgba(0,0,0,.35);

    --md-elevation-2:
        0 1px 2px rgba(0,0,0,.55),
        0 2px 6px 2px rgba(0,0,0,.35);

    --md-elevation-3:
        0 1px 3px rgba(0,0,0,.55),
        0 4px 8px 3px rgba(0,0,0,.35);

    --md-elevation-4:
        0 2px 3px rgba(0,0,0,.55),
        0 6px 10px 4px rgba(0,0,0,.35);
}


/* =========================================================
   HTML
========================================================= */

html {
    width: 100%;
    min-height: 100%;

    background: var(--md-sys-color-surface);

    /* Le dice al navegador que use sus controles nativos (select, scrollbar)
       en variante oscura, para que el menú del <select> no se abra en blanco */
    color-scheme: dark;
}


/* =========================================================
   BODY
========================================================= */

body {
    width: 100%;
    min-height: 100vh;

    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;

    padding: 40px 20px 56px;

    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);

    font-family: 'Roboto', Arial, Helvetica, sans-serif;

    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}


/* =========================================================
   HEADER / SEO
========================================================= */

.seo-header {
    width: 100%;
    max-width: 950px;

    margin: 0 auto;
    text-align: center;

    color: var(--md-sys-color-on-surface);
}

/* Chip decorativo — M3 Assist Chip */
.seo-header::before {
    content: "CUBIKAOS LAB";
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    margin-bottom: 14px;
    padding: 0 12px;

    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-shape-full);

    color: var(--md-sys-color-on-primary-container);
    background: var(--md-sys-color-primary-container);

    /* Label Small (M3 type scale) */
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
}


/* =========================================================
   H1 — Headline (M3 type scale: Headline Medium/Large)
========================================================= */

.seo-header h1 {
    max-width: 820px;
    margin: 0 auto 12px;

    font-size: clamp(28px, 4vw, 45px);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.25px;

    color: var(--md-sys-color-on-surface);
}


/* =========================================================
   DESCRIPCIÓN — Body Large (M3 type scale)
========================================================= */

.seo-header p {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;

    color: var(--md-sys-color-on-surface-variant);

    font-size: 15px;
    line-height: 1.65;
    letter-spacing: .15px;
}


/* =========================================================
   CONTENEDOR DEL GENERADOR
========================================================= */

.generator-container {
    width: 100%;
    max-width: 1080px;

    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 28px;
}


/* =========================================================
   CONTENEDOR CANVAS
========================================================= */

.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
}


/* =========================================================
   VIDEO 9:16 — Superficie elevada (M3 Elevation Level 3)
========================================================= */

#app {
    width: min(56.25vh, 70vw);
    aspect-ratio: 9 / 16;

    background: var(--md-sys-color-surface-container-lowest);

    overflow: hidden;
    border-radius: var(--md-shape-lg);

    box-shadow: var(--md-elevation-3);
}


/* =========================================================
   CANVAS
========================================================= */

canvas {
    display: block;
    width: 100%;
    height: 100%;

    background: var(--md-sys-color-surface-container-lowest);

    cursor: pointer;
}


/* =========================================================
   PANEL — M3 Elevated Card (surface-container)
========================================================= */

.panel {
    width: 320px;
    flex: 0 0 320px;

    display: flex;
    flex-direction: column;
    gap: 16px;

    padding: 24px;

    color: var(--md-sys-color-on-surface);
    background: var(--md-sys-color-surface-container);

    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-xl);

    box-shadow: var(--md-elevation-1);
}


/* =========================================================
   PANEL HEADER
========================================================= */

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.panel-kicker {
    display: block;
    margin-bottom: 6px;

    color: var(--md-sys-color-primary);

    /* Label Small */
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
}

.panel-header p {
    max-width: 240px;
    margin-top: 6px;

    color: var(--md-sys-color-on-surface-variant);

    font-size: 12px;
    line-height: 1.5;
}

/* Badge — M3 Assist Chip tonal */
.panel-badge {
    flex: 0 0 auto;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 48px;
    height: 28px;
    padding: 0 10px;

    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-full);

    color: var(--md-sys-color-tertiary);
    background: color-mix(in srgb, var(--md-sys-color-tertiary) 14%, transparent);

    font-size: 10px;
    font-weight: 700;
    letter-spacing: .8px;
}


/* =========================================================
   PANEL H2 — Title Large (M3 type scale)
========================================================= */

.panel h2 {
    margin: 0;

    color: var(--md-sys-color-on-surface);

    font-size: 22px;
    font-weight: 500;
    letter-spacing: 0.15px;
}


/* =========================================================
   SECCIÓN DE CONTROLES — M3 Outlined block
========================================================= */

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 14px;

    padding: 16px;

    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-md);

    background: var(--md-sys-color-surface-container-low);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;

    color: var(--md-sys-color-on-surface);

    /* Label Large */
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .1px;
}

.section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 24px;
    height: 22px;

    border-radius: var(--md-shape-xs);

    color: var(--md-sys-color-on-primary-container);
    background: var(--md-sys-color-primary-container);

    font-size: 10px;
    font-weight: 700;
}


/* =========================================================
   GRUPOS
========================================================= */

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}


/* =========================================================
   LABELS — Label Medium (M3 type scale)
========================================================= */

.panel label:not(.fileButton) {
    margin-top: 3px;

    color: var(--md-sys-color-on-surface-variant);

    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.control-hint {
    color: var(--md-sys-color-on-surface-variant);

    font-size: 11px;
    font-weight: 500;
}


/* =========================================================
   SELECT — M3 Outlined Text Field (variante select)
========================================================= */

select {
    width: 100%;

    min-height: 48px;
    padding: 0 40px 0 16px;

    color: var(--md-sys-color-on-surface);
    background-color: var(--md-sys-color-surface-container-highest);

    /* Borde sólido y opaco, sin efecto vidrio/translúcido */
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-xs);

    outline: none;

    font-family: inherit;
    font-size: 14px;
    font-weight: 500;

    cursor: pointer;

    transition:
        border-color .15s ease,
        box-shadow .15s ease,
        background-color .15s ease;
}

select:hover {
    border-color: var(--md-sys-color-outline);
    background-color: var(--md-sys-color-surface-container-highest);
}

select:focus {
    border: 2px solid var(--md-sys-color-primary);
    padding-left: 15px; /* compensa el aumento de grosor del borde */
}

/* ---- Menú desplegable (<option>) ----
   Sin esto, algunos navegadores (Chrome/Edge en Windows) ignoran el tema
   oscuro del <select> y muestran la lista de opciones en blanco. */
select option {
    color: var(--md-sys-color-on-surface);
    background-color: var(--md-sys-color-surface-container-highest);
}

select option:checked,
select option:hover {
    color: var(--md-sys-color-on-primary-container);
    background-color: var(--md-sys-color-primary-container);
}


/* =========================================================
   RANGE — M3 Slider
========================================================= */

input[type="range"] {
    width: 100%;
    height: 4px;
    margin: 10px 0;

    appearance: none;
    -webkit-appearance: none;

    background: var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-full);

    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    width: 20px;
    height: 20px;

    appearance: none;
    -webkit-appearance: none;

    background: var(--md-sys-color-primary);
    border: none;
    border-radius: 50%;

    box-shadow: 0 0 0 8px color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent);

    cursor: pointer;

    transition: box-shadow .15s ease, transform .15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 0 0 12px color-mix(in srgb, var(--md-sys-color-primary) 16%, transparent);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;

    border: none;

    background: var(--md-sys-color-primary);
    border-radius: 50%;

    box-shadow: 0 0 0 8px color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent);

    cursor: pointer;
}


/* =========================================================
   INPUT FILE
========================================================= */

#imageInput {
    display: none;
}


/* =========================================================
   BOTONES + FILE BUTTON — M3 Buttons (base)
========================================================= */

button,
.fileButton {
    position: relative;
    overflow: hidden;

    width: 100%;
    min-height: 48px;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    padding: 12px 16px;

    border: none;
    border-radius: var(--md-shape-full);

    color: var(--md-sys-color-on-surface);

    font-family: inherit;

    /* Label Large (M3 type scale para botones) */
    font-size: 14px;
    font-weight: 500;
    letter-spacing: .1px;
    text-transform: none;
    text-align: center;

    cursor: pointer;

    box-shadow: var(--md-elevation-0);

    transition:
        box-shadow .15s ease,
        transform .10s ease,
        background-color .15s ease,
        border-color .15s ease;
}

button img,
.fileButton img {
    width: 20px;
    height: 20px;

    flex-shrink: 0;
    object-fit: contain;
    pointer-events: none;
}

button span,
.fileButton span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}


/* ---- State layer (M3: capa translúcida sobre el color base, no sombra de neón) ---- */

button::after,
.fileButton::after {
    content: "";
    position: absolute;
    inset: 0;

    background: currentColor;
    opacity: 0;

    pointer-events: none;
    transition: opacity .15s ease;
}

button:hover::after,
.fileButton:hover::after {
    opacity: var(--md-state-hover);
}

button:active::after,
.fileButton:active::after {
    opacity: var(--md-state-pressed);
}

button:active,
.fileButton:active {
    transform: scale(.98);
}


/* =========================================================
   CARGAR PERSONAJE — M3 Filled Button
========================================================= */

.fileButton {
    margin-top: 4px;

    color: var(--md-sys-color-on-primary);
    background: var(--md-sys-color-primary);
}


/* =========================================================
   INVERTIR — M3 Outlined Button
========================================================= */

#reverseBtn {
    color: var(--md-sys-color-on-surface);
    background: transparent;

    border: 1px solid var(--md-sys-color-outline);
}


/* =========================================================
   GENERAR VIDEO — M3 Filled Button (rol de error)
========================================================= */

#recordBtn {
    color: var(--md-sys-color-on-error-container);
    background: var(--md-sys-color-error-container);

    box-shadow: var(--md-elevation-1);
}

#recordBtn:hover {
    box-shadow: var(--md-elevation-2);
}

#recordBtn:disabled {
    opacity: 1;
    color: var(--md-sys-color-on-surface);
    cursor: wait;

    background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, var(--md-sys-color-surface-container-high));
    box-shadow: var(--md-elevation-0);
}

#recordBtn.is-loading img {
    display: none;
}

#recordBtn.is-loading::before {
    content: "";
    position: relative;
    z-index: 1;

    width: 18px;
    height: 18px;
    flex: 0 0 18px;

    border: 2px solid color-mix(in srgb, var(--md-sys-color-on-surface) 30%, transparent);
    border-top-color: var(--md-sys-color-on-surface);
    border-radius: 50%;

    animation: md-spin .75s linear infinite;
}

#recordBtn.is-loading span {
    position: relative;
    z-index: 1;
}


/* =========================================================
   DESCARGAR VIDEO — M3 Filled Button (rol de éxito, color extendido)
========================================================= */

#downloadBtn {
    display: none;

    color: var(--md-sys-color-on-success);
    background: var(--md-sys-color-success);
}


/* =========================================================
   BOTONES DESACTIVADOS
========================================================= */

button:disabled {
    opacity: .38;
    cursor: default;

    box-shadow: none;
    transform: none;
}

button:disabled::after {
    opacity: 0 !important;
}


/* =========================================================
   ESTADO — M3 tonal surface con indicador lateral
========================================================= */

#status {
    min-height: 48px;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;

    padding: 12px 14px;

    color: var(--md-sys-color-on-surface-variant);
    background: var(--md-sys-color-surface-container-low);

    border: 1px solid var(--md-sys-color-outline-variant);
    border-left: 3px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-sm);

    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
    text-align: center;

    transition: border-color .2s ease, color .2s ease, background-color .2s ease;
}

.status-loader {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;

    border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;

    animation: md-spin .72s linear infinite;
}

.status-message {
    display: inline-flex;
    align-items: center;
}


/* =========================================================
   ESTADO GRABANDO — rol de error
========================================================= */

#status.recording {
    color: var(--md-sys-color-error);

    background: color-mix(in srgb, var(--md-sys-color-error) 10%, var(--md-sys-color-surface-container-low));
    border-color: color-mix(in srgb, var(--md-sys-color-error) 30%, transparent);
    border-left-color: var(--md-sys-color-error);
}


/* =========================================================
   ESTADO LISTO — rol de éxito
========================================================= */

#status.ready {
    color: var(--md-sys-color-success);

    background: color-mix(in srgb, var(--md-sys-color-success) 10%, var(--md-sys-color-surface-container-low));
    border-color: color-mix(in srgb, var(--md-sys-color-success) 30%, transparent);
    border-left-color: var(--md-sys-color-success);
}


/* =========================================================
   ANIMACIONES
========================================================= */

@keyframes md-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
    }
}


/* =========================================================
   TABLET
========================================================= */

@media (max-width: 900px) {

    .generator-container {
        gap: 24px;
    }

    .panel {
        width: 300px;
        flex-basis: 300px;
    }
}


/* =========================================================
   MÓVIL
========================================================= */

@media (max-width: 800px) {

    body {
        padding: 28px 12px 44px;
        gap: 24px;
    }

    /* HEADER */

    .seo-header {
        padding: 0 8px;
    }

    .seo-header h1 {
        font-size: clamp(25px, 8vw, 32px);
    }

    .seo-header p {
        font-size: 14px;
        line-height: 1.55;
    }

    /* GENERADOR */

    .generator-container {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }

    /* CANVAS */

    .canvas-container {
        width: 100%;
    }

    #app {
        width: min(100%, 52vh);
    }

    /* PANEL */

    .panel {
        width: min(100%, 440px);
        flex: none;
        padding: 20px;
        border-radius: var(--md-shape-lg);
    }

    .panel-section {
        padding: 14px;
    }
}


/* =========================================================
   MÓVILES PEQUEÑOS
========================================================= */

@media (max-width: 420px) {

    body {
        padding-left: 10px;
        padding-right: 10px;
    }

    .seo-header h1 {
        font-size: 25px;
        letter-spacing: -.4px;
    }

    .seo-header p {
        font-size: 13px;
    }

    .panel-header p {
        font-size: 11px;
    }

    .panel-badge {
        display: none;
    }

    .panel {
        padding: 18px;
        border-radius: var(--md-shape-md);
    }

    button,
    .fileButton {
        font-size: 13px;
    }
}