/* ==================== Variables y Temas ==================== */
:root {
    /* Tema Claro (por defecto) */
    --bg-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-secondary: #f8f9fa;
    --surface: rgba(255, 255, 255, 0.95);
    --surface-hover: rgba(255, 255, 255, 0.98);
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --text-muted: #a0aec0;
    --border: rgba(0, 0, 0, 0.1);
    --border-light: rgba(0, 0, 0, 0.05);

    --accent: #667eea;
    --accent-hover: #5a67d8;
    --accent-weak: rgba(102, 126, 234, 0.2);
    --success: #48bb78;
    --danger: #ef4444;
    --warning: #f59e0b;

    /* Dimensiones y espaciado */
    --radius: 16px;
    --radius-sm: 8px;
    --gap: 20px;
    --gap-sm: 12px;

    /* Variables dinámicas */
    --sound-scale: 1;
    --base-font-size: 2rem;
}

/* Tema Oscuro */
[data-theme="dark"] {
    --bg-primary: radial-gradient(1200px 800px at 70% -10%, #0e1a24 0%, #0b1015 60%);
    --bg-secondary: #0b1015;
    --surface: rgba(15, 23, 32, 0.95);
    --surface-hover: rgba(20, 30, 40, 0.98);
    --text-primary: #e5eef6;
    --text-secondary: #9fb3c8;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.1);
    --border-light: rgba(255, 255, 255, 0.05);

    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --accent-weak: rgba(14, 165, 233, 0.2);
}

/* ==================== Reset y Base ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100%;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ==================== Header ==================== */
.app-header {
    background: var(--surface);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-light);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    color: var(--accent);
    filter: drop-shadow(0 2px 4px rgba(102, 126, 234, 0.3));
}

.brand-text h1 {
    font-size: clamp(1.2rem, 2vw, 1.6rem);
    font-weight: 600;
    margin: 0;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

.btn-icon:hover {
    background: var(--accent-weak);
    border-color: var(--accent);
    transform: translateY(-2px);
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 25px;
    font-weight: 500;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.3s ease;
}

.status-dot.active {
    background: var(--success);
    animation: pulse 2s infinite;
    box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.4);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(72, 187, 120, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(72, 187, 120, 0);
    }
}

/* ==================== Contenedor Principal ==================== */
.app-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.container {
    background: var(--surface);
    backdrop-filter: blur(10px);
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    padding: 2rem;
    width: min(95vw, 1200px);
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    transition: all 0.3s ease;
}

.container:hover {
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
}

/* ==================== Sección de Controles ==================== */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
}

.main-controls {
    display: flex;
    gap: var(--gap-sm);
    flex-wrap: wrap;
    justify-content: center;
}

.settings-controls {
    display: flex;
    gap: var(--gap);
    flex-wrap: wrap;
    justify-content: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.select-control {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.select-control:hover {
    border-color: var(--accent);
}

.select-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-weak);
}

input[type="range"] {
    width: 100px;
    accent-color: var(--accent);
}

/* ==================== Botones ==================== */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.5s, height 0.5s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ==================== Display de Texto ==================== */
.display-section {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
}

.text-display-wrapper {
    position: relative;
    background: var(--bg-secondary);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    min-height: 300px;
    transition: all 0.3s ease;
}

.text-display-wrapper.active {
    border-color: var(--accent);
    border-style: solid;
    background: linear-gradient(135deg, var(--accent-weak), transparent);
}

.text-display {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: calc(var(--base-font-size) * var(--sound-scale));
    transition: font-size 150ms cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    line-height: 1.4;
    word-break: break-word;
    position: relative;
}

.final-text {
    color: var(--text-primary);
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.interim-text {
    color: var(--text-secondary);
    font-style: italic;
    opacity: 0.8;
}

.placeholder-text {
    color: var(--text-muted);
    font-style: italic;
    font-size: 1.2rem;
}

.final-text:empty + .interim-text:empty + .placeholder-text {
    display: block;
}

.final-text:not(:empty) ~ .placeholder-text,
.interim-text:not(:empty) ~ .placeholder-text {
    display: none;
}

/* ==================== Indicadores de Volumen ==================== */
.volume-indicators {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--gap);
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-light);
}

.volume-bars {
    display: flex;
    gap: 4px;
    height: 30px;
    align-items: flex-end;
}

.volume-bar {
    width: 6px;
    height: 100%;
    background: var(--border);
    border-radius: 3px;
    transition: all 0.15s ease;
    transform-origin: bottom;
}

.volume-bar.active {
    background: linear-gradient(180deg, var(--accent), var(--accent-hover));
    box-shadow: 0 0 8px var(--accent-weak);
}

.volume-bar:nth-child(1) { height: 30%; }
.volume-bar:nth-child(2) { height: 40%; }
.volume-bar:nth-child(3) { height: 50%; }
.volume-bar:nth-child(4) { height: 60%; }
.volume-bar:nth-child(5) { height: 70%; }
.volume-bar:nth-child(6) { height: 80%; }
.volume-bar:nth-child(7) { height: 90%; }
.volume-bar:nth-child(8) { height: 100%; }

.volume-meter {
    flex: 1;
    height: 10px;
    background: var(--border-light);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.meter-bar {
    height: 100%;
    width: 4%;
    background: linear-gradient(90deg, var(--accent-weak), var(--accent));
    transition: width 100ms ease;
    border-radius: 999px;
    box-shadow: 0 0 10px var(--accent-weak);
}

/* ==================== Panel de Información ==================== */
.info-panel {
    display: flex;
    gap: 2rem;
    justify-content: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.info-item span:last-child {
    font-weight: 600;
    color: var(--accent);
}

/* ==================== Sección de Ayuda ==================== */
.help-section {
    margin-top: 1rem;
}

.help-text {
    background: linear-gradient(135deg, var(--accent-weak), transparent);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.help-text ul {
    margin: 0.5rem 0 0 1.5rem;
    padding: 0;
}

.help-text li {
    margin: 0.25rem 0;
}

.error-message {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), transparent);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-left: 4px solid var(--danger);
    color: var(--danger);
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-top: 1rem;
    font-weight: 500;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== Footer ==================== */
.app-footer {
    text-align: center;
    padding: 1.5rem;
    border-top: 1px solid var(--border-light);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ==================== Responsive Design ==================== */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .brand-text h1 {
        font-size: 1.2rem;
    }

    .container {
        padding: 1.5rem;
        gap: 1rem;
    }

    .main-controls {
        width: 100%;
    }

    .btn {
        flex: 1;
        justify-content: center;
    }

    .settings-controls {
        flex-direction: column;
        width: 100%;
    }

    .control-group {
        width: 100%;
        justify-content: space-between;
    }

    .info-panel {
        flex-direction: column;
        gap: 0.5rem;
    }

    .text-display-wrapper {
        padding: 1.5rem;
        min-height: 250px;
    }

    .volume-indicators {
        flex-direction: column;
    }

    .volume-bars {
        width: 100%;
        justify-content: center;
    }

    .volume-meter {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .app-main {
        padding: 1rem;
    }

    .container {
        padding: 1rem;
    }

    .brand-text .subtitle {
        display: none;
    }

    .main-controls {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .text-display {
        font-size: calc((var(--base-font-size) * 0.8) * var(--sound-scale));
        min-height: 150px;
    }

    .help-text {
        font-size: 0.75rem;
    }
}

/* ==================== Animaciones Adicionales ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.container {
    animation: slideUp 0.5s ease;
}

/* ==================== Accesibilidad ==================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible para navegación con teclado */
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Alto contraste */
@media (prefers-contrast: high) {
    :root {
        --border: rgba(0, 0, 0, 0.3);
        --text-primary: #000;
        --surface: #fff;
    }

    [data-theme="dark"] {
        --border: rgba(255, 255, 255, 0.3);
        --text-primary: #fff;
        --surface: #000;
    }
}

/* Print styles */
@media print {
    .app-header,
    .app-footer,
    .controls-section,
    .volume-indicators,
    .info-panel,
    .help-section {
        display: none;
    }

    .text-display {
        font-size: 12pt !important;
        color: black !important;
    }
}
