/* =========================================================
   UI-V2 LAYER (Phase 1.1 - Modular Premium)
   Scoped to .ui-v2 for safe decoupling.
   Enhances the ORIGINAL 5-panel structure.
   ========================================================= */

@import url("themes/ui-obsidian.css");
@import url("themes/ui-midnight.css");
@import url("themes/ui-emerald.css");
@import url("themes/ui-frost.css");
@import url("themes/ui-sunset.css");
@import url("themes/ui-aurora.css");

/* 0. GLOBAL THEME BACKGROUND INJECTION */
body.theme-obsidian,
body.theme-midnight,
body.theme-emerald,
body.theme-frost,
body.theme-sunset,
body.theme-aurora {
    background: var(--uiv2-bg) !important;
}

body.theme-obsidian #piano-wrapper,
body.theme-midnight #piano-wrapper,
body.theme-emerald #piano-wrapper,
body.theme-frost #piano-wrapper,
body.theme-sunset #piano-wrapper,
body.theme-aurora #piano-wrapper {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

body.theme-obsidian .brand-bar,
body.theme-midnight .brand-bar,
body.theme-emerald .brand-bar,
body.theme-frost .brand-bar,
body.theme-sunset .brand-bar,
body.theme-aurora .brand-bar {
    background: transparent !important;
    border-color: rgba(255, 255, 255, 0.05) !important;
}

/* 1. Global Header Container */
.ui-v2 #top-bar {
    background: var(--uiv2-bg);
    backdrop-filter: blur(var(--uiv2-blur)) saturate(160%);
    -webkit-backdrop-filter: blur(var(--uiv2-blur)) saturate(160%);
    border-bottom: 1px solid var(--uiv2-border);
    padding: 16px 24px;
    box-shadow: 0 4px 35px rgba(0, 0, 0, 0.4);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 2. Grid Optimization */
.ui-v2 .top-grid {
    display: grid;
    grid-template-columns: auto auto 1.5fr 0.8fr 1fr 1.2fr;
    gap: 12px;
    align-items: stretch;
}

/* 3. Panel (Col) Styling */
.ui-v2 .col {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 4px 15px rgba(0, 0, 0, 0.2);
}

/* 4. Improved Typography - RESTORED VISIBILITY */
.ui-v2 .col h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--uiv2-text-h3);
    margin: 0 0 4px 0;
}

.ui-v2 .col label,
.ui-v2 .col span:not(.is-active) {
    font-size: 11px;
    color: var(--uiv2-text-main);
}

/* 5. Unified Button Component Refinement */
.ui-v2 .modes-row button,
.ui-v2 .col button:not(.is-active):not(.custom-select-trigger) {
    background: var(--uiv2-btn-bg) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--uiv2-text-main);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.05),
        0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Specific fix for playback buttons which were hardcoded elsewhere */
.ui-v2 .col.playback button:not(.custom-select-trigger) {
    background: var(--uiv2-btn-bg) !important;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.ui-v2 .modes-row button:hover,
.ui-v2 .col button:not(.is-active):not(.custom-select-trigger):hover {
    background: rgba(255, 255, 255, 0.15) !important;
    border-color: var(--uiv2-accent);
    transform: translateY(-1px);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.1),
        0 6px 15px rgba(0, 0, 0, 0.4);
}

/* FORCE THEME COLORS & STABILITY (ZERO SHIFT) */
body.theme-obsidian #btnPlayer,
body.theme-midnight #btnPlayer,
body.theme-emerald #btnPlayer,
body.theme-frost #btnPlayer,
body.theme-sunset #btnPlayer,
body.theme-aurora #btnPlayer,
.ui-v2 #btnPlayer,
body.theme-obsidian .is-active,
body.theme-midnight .is-active,
body.theme-emerald .is-active,
body.theme-frost .is-active,
body.theme-sunset .is-active,
body.theme-aurora .is-active,
.ui-v2 .modes-row button.is-active,
.ui-v2 .modes-row button[data-active="true"],
.ui-v2 .col button.is-active,
.ui-v2 .col button[data-active="true"] {
    background: var(--uiv2-accent) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #f1f5f9 !important;
    /* Blanco suave para texto activo */
    opacity: 1 !important;
    font-weight: 500 !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3) !important;
    box-shadow:
        0 0 20px var(--uiv2-accent-glow),
        inset 0 1px 2px rgba(255, 255, 255, 0.3) !important;
}

/* Override for Frost theme active text contrast */
body.theme-frost .is-active,
body.theme-frost #btnPlayer {
    color: #f1f5f9 !important;
}

/* Panel spacing and layout */
.ui-v2 #btnPlayer {
    padding-left: 24px !important;
    padding-right: 24px !important;
}

.ui-v2 .training-grid-2x2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.ui-v2 .training-grid-2x2 button {
    width: 100%;
    margin: 0;
}

/* Select and inputs refined */
.ui-v2 select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--uiv2-text-main);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

body.theme-frost .ui-v2 select,
body.theme-frost #modal-root .settings-row select {
    background: rgba(0, 0, 0, 0.05);
    /* Limpio, sin gradiente raro */
    border-color: rgba(0, 0, 0, 0.15);
    color: var(--uiv2-text-main);
}

/* Playback Control Accents */
.ui-v2 #btnStop {
    background: var(--uiv2-btn-bg);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    box-sizing: border-box;
}

/* 8. Settings Modal - Theme Aware & High Contrast */
#modal-root .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 11000;
}

/* Re-use the theme background and text for the modal card */
#modal-root .modal-card {
    background: var(--uiv2-bg) !important;
    backdrop-filter: blur(var(--uiv2-blur)) saturate(180%) !important;
    -webkit-backdrop-filter: blur(var(--uiv2-blur)) saturate(180%) !important;
    border: 1px solid var(--uiv2-border) !important;
    color: var(--uiv2-text-main) !important;
    padding: 24px 32px;
    border-radius: 16px;
    width: 380px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6) !important;
    opacity: 1;
    transform: none;
    animation: modal-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Ensure closing animation completely overrides and triggers cleanup */
#modal-root .modal-card.closing {
    animation: modalSmoothOut 0.18s cubic-bezier(0.4, 0.2, 0.2, 1) forwards !important;
}

#modal-root .modal-overlay.closing {
    animation: overlayFadeOut 0.18s ease forwards !important;
}

@keyframes modal-pop {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#modal-root .modal-card h2 {
    margin: 0 0 24px 0;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--uiv2-text-main) !important;
    letter-spacing: -0.5px;
    text-align: center;
}

.modal-overlay .settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-overlay .settings-row:last-child {
    border-bottom: none;
}

/* Frost theme specific row border */
body.theme-frost .modal-overlay .settings-row {
    border-bottom-color: rgba(0, 0, 0, 0.05);
}

body.theme-frost .modal-overlay .settings-row:last-child {
    border-bottom: none;
}

.modal-overlay .settings-row span {
    font-size: 14px;
    color: var(--uiv2-text-main) !important;
    flex: 1;
    font-weight: 500;
}

/* Standardized sizes for modal elements */
.modal-overlay .settings-row select,
.modal-overlay .settings-row input[type="range"],
.modal-overlay .settings-row .settings-action-btn,
.modal-overlay .settings-row button {
    width: 160px !important;
    height: 36px !important;
    box-sizing: border-box;
    flex-shrink: 0;
}

/* Volume slider in modal */
.modal-overlay .settings-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    height: 4px;
    outline: none;
    cursor: pointer;
    overflow: hidden;
}

body.theme-frost .modal-overlay .settings-row input[type="range"] {
    background: rgba(0, 0, 0, 0.05);
}

.modal-overlay .settings-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--uiv2-accent) !important;
    cursor: pointer;
    margin-top: -6px;
    border: none;
    box-shadow: -160px 0 0 160px var(--uiv2-accent) !important;
}

/* Toggles refined */
.modal-overlay .switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.modal-overlay .switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.modal-overlay .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.2);
    transition: .3s;
    border-radius: 24px;
}

.modal-overlay .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.modal-overlay input:checked+.slider {
    background-color: var(--uiv2-accent);
}

.modal-overlay input:checked+.slider:before {
    transform: translateX(20px);
}