/* Breakpoints */
:root {
    --phone-max: 640px;
    --tablet-min: 641px;
    --tablet-max: 1024px;
    --desktop-min: 1025px;
}

/* Base styles (mobile-first) */
:root {
    /* Sistema de colores */
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --border-color: #e5e7eb;
    
    /* Tipografía */
    --font-main: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    
    /* Espaciado */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    
    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Variables responsivas */
    --mobile-padding: 12px;
    --mobile-font-size: 15px;
    --mobile-button-padding: 12px 16px;
    --mobile-border-radius: 10px;
    --mobile-margin: 8px;
    
    /* Transiciones */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
}

.search-container {
    margin: 0.5rem auto;
    position: relative;
    width: 100%;
    padding: 0 0.8rem;
    box-sizing: border-box;
}

#searchInput {
    width: 100%;
    padding: 8px 15px;
    font-size: 15px;
    border: 1.5px solid #e0e0e0;
    border-radius: 20px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    font-family: 'Roboto', sans-serif;
    background-color: #fff;
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

#searchInput:focus {
    outline: none;
    border-color: #4a90e2;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
    transform: translateY(-1px);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 15px;
    right: 15px;
    background: white;
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 15px 15px;
    max-height: 70vh;
    overflow-y: auto;
    z-index: 1001;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
    display: none;
    margin-top: 5px;
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
    -webkit-overflow-scrolling: touch;
}

/* Estilos para la barra de desplazamiento */
.search-results::-webkit-scrollbar {
    width: 8px;
}

.search-results::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 0 0 15px 0;
}

.search-results::-webkit-scrollbar-thumb {
    background-color: #c1c1c1;
    border-radius: 4px;
}

.search-results.visible {
    display: block;
    animation: fadeIn 0.2s ease-in-out;
}

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

.search-category {
    padding: 10px 20px;
    background-color: #f8f9fa;
    color: #4a4a4a;
    font-weight: 600;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.search-result-item {
    padding: 12px 25px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f5f5f5;
    display: flex;
    align-items: center;
    font-size: 1em;
    color: #333;
    position: relative;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background-color: #f0f7ff;
    transform: translateX(5px);
}

.search-result-item::before {
    content: '→';
    margin-right: 10px;
    color: #4a90e2;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.search-result-item:hover::before {
    opacity: 1;
}

/* Estilos para pantallas pequeñas */
@media (max-width: 768px) {
    .search-container {
        margin: 15px 20px;
        max-width: 100%;
    }
    
    #searchInput {
        padding: 12px 20px;
        font-size: 15px;
    }
    
    .search-results {
        max-height: 60vh;
    }
    
    .search-result-item {
        padding: 12px 20px;
    }
}

/* Estilos para el contador de resultados */
.search-results-count {
    padding: 8px 20px;
    font-size: 0.85em;
    color: #666;
    background-color: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    text-align: right;
}

/* Estilos para el mensaje de búsqueda vacía */
.search-no-results {
    padding: 20px;
    text-align: center;
    color: #666;
    font-style: italic;
}

/* Estilos para el contador de resultados */
.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.search-results-clear {
    background: none;
    border: none;
    color: #4a90e2;
    cursor: pointer;
    font-size: 0.85em;
    padding: 4px 8px;
    border-radius: 4px;
}

.search-results-clear:hover {
    background-color: rgba(74, 144, 226, 0.1);
}

/* Efecto de carga */
.search-loading {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.search-loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #4a90e2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.search-result-item.highlighted {
    background-color: #f0f7ff;
}

.search-result-item .title {
    font-weight: 500;
    color: var(--text-color);
}

.search-result-item .category {
    font-size: 0.85em;
    color: var(--light-text);
    margin-top: 3px;
}

/* Reset y estilos generales */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

:root {
    --primary-color: #3498db;
    --success-color: #2ecc71;
    --danger-color: #e74c3c;
    --text-color: #2c3e50;
    --light-text: #7f8c8d;
    --bg-color: #f5f7fa;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    --transition: all 0.2s ease;
    --content-width: 1400px;
    --ad-width: 200px;
    --gap: 15px;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Page Layout */
.page-wrapper {
    display: flex;
    max-width: var(--content-width);
    margin: 0 auto;
    width: 100%;
    padding: 20px;
    gap: var(--gap);
}

/* Header */
/* Estilos para el encabezado */
.header-container {
    text-align: center;
    margin: 0 0 10px 0;
    padding: 5px 0 0;
    position: relative;
    overflow: hidden;
}

.title-wrapper {
    position: relative;
    z-index: 1;
    max-width: 800px;
    margin: 0 auto;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(74, 144, 226, 0.08);
}

.main-title {
    font-size: 2rem;
    color: #2c3e50;
    margin: 0 0 5px 0;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #3498db, #2ecc71);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    position: relative;
    display: inline-block;
    line-height: 1.2;
}

.main-title::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 2px;
    background: linear-gradient(90deg, #3498db, #2ecc71);
    border-radius: 2px;
}

.subtitle {
    color: #7f8c8d;
    font-size: 0.95rem;
    margin: 0 0 10px 0;
    font-weight: 400;
    line-height: 1.3;
}

.instructions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px 15px;
    margin: 0 0 15px 0;
    padding: 8px 0;
}

.instruction {
    display: inline-flex;
    align-items: center;
    font-size: 0.85rem;
    color: #4a5568;
    background: linear-gradient(135deg, #f7fafc, #edf2f7);
    padding: 6px 14px 6px 10px;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.instruction:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
    background: linear-gradient(135deg, #edf2f7, #e2e8f0);
}

.instruction::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: linear-gradient(135deg, #4299e1, #3182ce);
    border-radius: 50%;
    margin-right: 8px;
    position: relative;
    box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.2);
}

.instruction:nth-child(1)::before { background: linear-gradient(135deg, #48bb78, #38a169); box-shadow: 0 0 0 2px rgba(72, 187, 120, 0.2); }
.instruction:nth-child(2)::before { background: linear-gradient(135deg, #4299e1, #3182ce); box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.2); }
.instruction:nth-child(3)::before { background: linear-gradient(135deg, #ed8936, #dd6b20); box-shadow: 0 0 0 2px rgba(237, 137, 54, 0.2); }

.title-decoration {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 8px;
}

.math-symbol {
    font-size: 1.2rem;
    color: #3498db;
    opacity: 0.7;
    transition: all 0.3s ease;
    animation: float 3s ease-in-out infinite;
}

.math-symbol:nth-child(1) { animation-delay: 0s; color: #3498db; }
.math-symbol:nth-child(2) { animation-delay: 0.2s; color: #e74c3c; }
.math-symbol:nth-child(3) { animation-delay: 0.4s; color: #2ecc71; }
.math-symbol:nth-child(4) { animation-delay: 0.6s; color: #f39c12; }
.math-symbol:nth-child(5) { animation-delay: 0.8s; color: #9b59b6; }

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Efecto de partículas decorativas */
.header-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 20% 30%, rgba(52, 152, 219, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 80% 70%, rgba(46, 204, 113, 0.08) 0%, transparent 50%);
    z-index: 0;
    pointer-events: none;
}

/* Contenedor de controles de operación */
.operation-controls {
    display: flex;
    gap: 8px;
    margin: 8px 0 0;
    flex-wrap: wrap;
    align-items: center;
}

/* Estilos responsivos para los controles */
@media (max-width: 768px) {
    .operation-controls {
        display: flex;
        justify-content: center; /* Centra los elementos horizontalmente */
        align-items: center;
        gap: 0.8rem;
        padding: 0.5rem 1rem;
        margin: 0.5rem auto; /* Centra el contenedor */
        max-width: 400px; /* Ancho máximo para evitar que se estire demasiado */
        width: 100%;
        box-sizing: border-box;
    }
    
    .operation-controls > * {
        margin: 0;
        height: 44px; /* Altura táctil estándar para móviles */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .new-problem-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 0 1rem;
        font-size: 0.9rem;
        font-weight: 600;
        color: white;
        background: var(--primary-color);
        border: none;
        border-radius: 5px;
        cursor: pointer;
        transition: all 0.2s ease;
        flex: 2; /* Ocupa el doble de espacio que el botón de racha */
        min-width: 0; /* Permite que el botón se encoja si es necesario */
        white-space: nowrap;
    }
    
    .streak-counter {
        display: flex !important;
        align-items: center;
        justify-content: center;
        gap: 0.3rem;
        padding: 0 0.8rem;
        font-size: 0.75rem;
        background: rgba(79, 70, 229, 0.1);
        border-radius: 5px;
        color: #4f46e5;
        border: 1px solid rgba(79, 70, 229, 0.2);
        height: 44px;
        box-sizing: border-box;
        flex: 1; /* Ocupa la mitad de espacio que el botón principal */
        min-width: 60px; /* Ancho mínimo para asegurar visibilidad */
    }
    
    .streak-icon {
        font-size: 1rem;
    }
    
    .streak-count {
        font-weight: 700;
    }
    
    .streak-text {
        display: none; /* Ocultamos el texto en móviles para ahorrar espacio */
    }
    
    /* Asegurar que el icono y el número se vean bien */
    .streak-icon {
        font-size: 1.1rem;
        line-height: 1;
    }
    
    .streak-count {
        font-weight: 700;
        font-size: 0.9rem;
        line-height: 1;
    }
}

/* Contador de racha */
.streak-counter {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff8e8e 100%);
    padding: 0.4rem 0.9rem;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85em;
    font-weight: 600;
    color: white;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(255, 107, 107, 0.2);
    position: relative;
    overflow: hidden;
    height: 36px;
    margin-left: auto;
}

.streak-counter::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: rgba(255, 255, 255, 0.4);
}

.streak-counter.visible {
    animation: streakPop 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

.streak-icon {
    font-size: 1.1em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.streak-count {
    font-weight: 700;
    font-size: 1.1em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.streak-text {
    font-size: 0.9em;
    opacity: 0.95;
}

@keyframes streakPop {
    0% { transform: scale(0.9); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { 
        transform: scale(1.15);
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
    }
    100% { 
        transform: scale(1);
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    }
}

/* Efecto de brillo al actualizar el contador */
@keyframes streakGlow {
    0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 107, 107, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); }
}

.streak-updated {
    animation: streakGlow 1.5s ease-out;
}

/* Botón de nueva operación */
.new-problem-btn {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: 0 2px 6px rgba(52, 152, 219, 0.2);
    position: relative;
    overflow: hidden;
    height: 36px;
    white-space: nowrap;
}

/* Efecto de hover y focus para el botón */
.new-problem-btn:hover,
.new-problem-btn:focus {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(74, 144, 226, 0.3);
    outline: none;
}

.new-problem-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(74, 144, 226, 0.2);
}

/* Icono del botón */
.new-problem-btn .btn-icon {
    font-size: 1.1em;
    transition: transform 0.3s ease;
}

.new-problem-btn:hover .btn-icon {
    animation: spin 0.8s ease;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.new-problem-btn:hover {
    background: linear-gradient(135deg, #3f7bc8, #2c68a0);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}

.new-problem-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

@keyframes flame {
    0% { opacity: 0.8; transform: scale(1); }
    100% { opacity: 1; transform: scale(1.2); }
}

.streak-count {
    font-weight: 700;
    color: #fff;
    min-width: 1.2em;
    display: inline-block;
    text-align: center;
}

/* ========== Responsive Styles ========== */
/* Large Tablets and Small Desktops */
@media (min-width: 993px) and (max-width: 1200px) {
    :root {
        --ad-width: 200px;
    }
    
    .main-container {
        padding: 0 20px;
    }
    
    .operation-group {
        flex: 1 1 45%;
        margin: 10px 2.5%;
    }
}

/* Tablets */
@media (min-width: 641px) and (max-width: 992px) {
    :root {
        --ad-width: 0;
    }
    
    .ad-container {
        display: none;
    }
    
    .main-container {
        width: 100%;
        padding: 0 15px;
    }
    
    .operation-group {
        flex: 1 1 45%;
        margin: 10px 2.5%;
    }
    
    .operation-group label {
        font-size: 0.9rem;
    }
    
    .operation-select {
        font-size: 0.9rem;
        padding: 8px 12px;
    }
    
    .math-interface {
        padding: 15px;
    }
    
    #operationDisplay {
        font-size: 1.1rem;
    }
    
    .answer-input {
        font-size: 1rem;
        padding: 10px 15px;
    }
    
    .check-answer-btn, .new-problem-btn {
        padding: 10px 20px;
        font-size: 0.95rem;
    }
    
    .operation-controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .check-answer-btn,
    .new-problem-btn,
    .streak-counter {
        flex: 1 1 30%;
        margin: 5px 0;
    }
}

/* Small Tablets and Large Phones */
@media (min-width: 481px) and (max-width: 640px) {
    :root {
        --ad-width: 0;
    }
    
    .ad-container {
        display: none;
    }
    
    .main-container {
        width: 100%;
        padding: 0 15px;
    }
    
    .operation-group {
        flex: 1 1 100%;
        margin: 5px 0;
    }
    
    .operation-controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .check-answer-btn,
    .new-problem-btn,
    .streak-counter {
        flex: 1 1 45%;
        margin: 5px;
        padding: 10px 5px;
        font-size: 0.9rem;
    }
    
    .operation-group label {
        font-size: 0.85rem;
    }
    
    .operation-select {
        font-size: 0.9rem;
        padding: 8px 12px;
    }
}

/* Small Phones */
@media (max-width: 480px) {
    :root {
        --ad-width: 0;
    }
    
    .ad-container {
        display: none;
    }
    
    .main-container {
        width: 100%;
        padding: 0 10px;
    }
    
    .header-container h1 {
        font-size: 1.5rem;
        margin: 10px 0;
    }
    
    .search-container {
        margin: 10px 0;
    }
    
    #searchInput {
        padding: 12px 15px;
        font-size: 1rem;
    }
    
    .operations-container {
        padding: 5px 0;
    }
    
    .operation-group {
        flex: 1 1 100%;
        margin: 5px 0;
    }
    
    .operation-group label {
        display: block;
        margin-bottom: 5px;
        font-size: 0.85rem;
    }
    
    .operation-select {
        width: 100%;
        padding: 10px 12px;
        font-size: 0.9rem;
    }
    
    .toggle-button {
        width: 100%;
        margin: 10px 0;
        padding: 10px;
        font-size: 0.9rem;
    }
    
    .math-interface {
        padding: 10px;
        margin: 10px 0;
    }
    
    #operationDisplay {
        font-size: 1rem;
        line-height: 1.5;
        margin: 10px 0;
    }
    
    .answer-input {
        width: 100%;
        padding: 10px 12px;
        font-size: 1rem;
        margin: 10px 0;
    }
    
    .operation-controls {
        flex-direction: column;
        gap: 10px;
        margin: 10px 0;
    }
    
    .check-answer-btn, 
    .new-problem-btn,
    .streak-counter {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
        margin: 5px 0;
    }
    
    .streak-counter {
        order: 1;
        text-align: center;
    }
    
    .new-problem-btn {
        order: 2;
    }
    
    /* Improve touch targets */
    button, select, input[type="text"] {
        min-height: 44px; /* Minimum touch target size */
    }
    
    /* Hide complex elements on mobile */
    .ad-placeholder {
        display: none;
    }
    
    /* Adjust MathJax rendering for mobile */
    .MathJax_Display {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Main Content */
.operation-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
}

/* Ad Containers */
.ad-container {
    width: var(--ad-width);
    position: relative;
    margin-top: 5px;
}

.ad-placeholder {
    position: sticky;
    top: 20px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px dashed #ccc;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: #666;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    :root {
        --ad-width: 200px;
    }
}

@media (max-width: 992px) {
    .ad-container {
        display: none;
    }
    
    .page-wrapper {
        padding: 20px 15px;
    }
    
    .main-container {
        max-width: 100%;
    }
}

.container {
    width: 100%;
    max-width: 100%;
    padding: 0;
}

h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 2rem;
    font-size: 2.2rem;
}

/* Main Content Styling */
.main-container {
    background-color: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 0.5rem 1.5rem 1.5rem;
    margin: 0;
    min-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

/* Toggle Button */
.toggle-button {
    display: block;
    width: 100%;
    padding: 0.6rem;
    margin: 0.5rem 0 1.5rem;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    color: #495057;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-button:hover {
    background-color: #e9ecef;
    border-color: #ced4da;
}

.toggle-button:active {
    background-color: #dee2e6;
}

/* Header Styling */
h1 {
    text-align: left;
    color: var(--text-color);
    margin: 0 0 1rem 0;
    font-size: 1.5rem;
    font-weight: 700;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* Search Bar */
.search-container {
    margin-bottom: 1rem;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
}

#searchInput {
    width: 100%;
    padding: 1rem 1.25rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    outline: none;
    transition: all 0.3s ease;
    background-color: var(--bg-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

#searchInput:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

/* Operation Groups - Visible */
.operation-group {
    margin: 0;
    background-color: #ffffff;
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
}

.operation-group:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border-color: #cbd5e0;
}

.operation-group label {
    display: block;
    margin: 0 0 8px 0;
    font-weight: 600;
    color: #2d3748;
    font-size: 0.9rem;
    padding-bottom: 4px;
    border-bottom: 1px solid #edf2f7;
}

.operation-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background-color: #fff;
    font-size: 0.9rem;
    color: #4a5568;
    transition: all 0.2s ease;
    cursor: pointer;
    height: 38px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px 16px;
    padding-right: 36px;
}

.operation-select:hover {
    border-color: var(--primary-color);
    background-color: #fff;
}

.operation-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
    background-color: #fff;
}

.operation-select option {
    padding: 0.5rem;
    background: white;
    color: var(--text-color);
}

/* Operations Container - Collapsible */
.operations-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
    margin: 8px 0 12px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    padding: 0 2px;
}

.operations-container.expanded {
    max-height: 1000px; /* Enough height to show all items */
}

/* Operation Type */
.operation-type {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 1.2rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
    margin-bottom: 1.5rem;
}

.operation-type:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.operation-type h2 {
    color: var(--text-color);
    margin: 0 0 1.2rem 0;
    font-size: 1.4rem;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.75rem;
}

.operation-type h3 {
    color: var(--primary-color);
    font-size: 1.1rem;
    margin: 1.2rem 0 0.8rem;
    font-weight: 500;
}

.operations {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.6rem;
}

.operation-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.option, button[data-operation] {
    padding: 0.7rem 1rem;
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.95rem;
    text-align: center;
    color: var(--text-color);
    font-weight: 500;
}

.option:hover, button[data-operation]:hover {
    background-color: #e9ecef;
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.option.active, button[data-operation].active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

button[data-operation] {
    width: 100%;
    margin: 0;
    background-color: white;
}

button[data-operation]:hover {
    background-color: #f1f8ff;
}

/* Contenedor principal de la interfaz matemática */
.math-interface {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

/* Tarjeta de operación */
.operation-card {
    background: #ffffff;
    border-radius: 8px;
    padding: 12px 15px 15px;
    margin: 8px 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    border: 1px solid #f0f0f0;
}

.operation-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Área de visualización de la operación */
.operation-display {
    padding: 1.5rem 1rem;
    text-align: center;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
    width: 100%;
    box-sizing: border-box;
}

/* Mensaje de bienvenida */
.welcome-message {
    font-size: 1.1rem; /* Tamaño reducido desde 1.4rem */
    color: #4a5568;
    font-weight: 500;
    margin: 0;
    line-height: 1.4; /* Línea más compacta */
    max-width: 90%; /* Más ancho para mejor legibilidad */
    opacity: 0.85;
}

.operation-content {
    width: 100%;
    margin-bottom: 1.5rem;
}

/* Estilos para fracciones */
.fraccion {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 3px;
    vertical-align: middle;
    line-height: 1.2;
    position: relative;
    text-align: center;
}

.numerador, .denominador {
    padding: 0 6px;
    font-size: 1.1em;
    line-height: 1;
}

.barra {
    display: block;
    width: 100%;
    height: 1.5px;
    background-color: #333;
    margin: 3px 0;
    min-width: 20px;
}

/* Mejorar el espaciado alrededor de las fracciones */
.operation-question {
    font-size: 1em; /* Tamaño de fuente reducido */
    line-height: 1.6;
    margin: 8px 0;
    padding: 0 0.5rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Estilo para números mixtos */
.numero-mixto {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

.numero-mixto .entero {
    margin-right: 5px;
}

/* Mejorar la legibilidad de las expresiones matemáticas */
.math-expression {
    font-size: 1.2em;
    line-height: 1.6;
}

/* Ajustar el espaciado para operadores */
.operador {
    margin: 0 3px;
}

.operation-container {
    margin-bottom: 1.5rem;
}

.operation-question {
    font-size: 1.6rem;
    margin-bottom: 2rem;
    color: #2c3e50;
    line-height: 1.5;
    font-weight: 500;
    padding: 0 1rem;
}

.input-group {
    display: flex;
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.answer-input {
    width: 100%;
    max-width: 280px;
    padding: 8px 12px;
    margin: 10px 0;
    border: 1.5px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    height: 40px;
}

.answer-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.answer-input:disabled {
    background-color: #f8f9fa;
}

.verify-button {
    padding: 0.9rem 1.8rem;
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, #4a90e2, #357abd);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.verify-button:hover {
    background: linear-gradient(135deg, #3f7bc8, #2c68a0);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.verify-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.verify-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.4);
}

.operation-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), #6c5ce7);
}

.operation-display p {
    margin: 0;
    color: var(--text-color);
    line-height: 1.6;
    max-width: 100%;
    word-wrap: break-word;
    font-size: 1.8rem;
}

.operation-display .problem-text {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    font-weight: 600;
    line-height: 1.4;
}

.operation-display .hint {
    font-size: 1.1rem;
    color: var(--light-text);
    margin-top: 1.5rem;
    font-style: italic;
    max-width: 90%;
}

/* Sección de ayuda con pestañas */
.help-section {
    margin: 2rem 0 3rem;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

/* Pestañas de navegación */
.help-tabs {
    display: flex;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 1rem;
}

.tab-button {
    padding: 0.8rem 1.5rem;
    border: none;
    background: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}

.tab-button:hover {
    color: #4f46e5;
}

.tab-button.active {
    color: #4f46e5;
    border-bottom-color: #4f46e5;
    background: rgba(99, 102, 241, 0.05);
}

/* Contenido de las pestañas */
.tab-content {
    display: none;
    padding: 0;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

/* Área de ayuda */
.hint-display {
    background: #ffffff;
    padding: 2rem 2.5rem 2.5rem 2.5rem;
    color: #2d3748;
    line-height: 1.8;
    position: relative;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hint-display::before {
    content: '';
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.help-header {
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e9ecef;
}

.help-header h2 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.5em;
    font-weight: 600;
}

/* Contenido principal de ayuda */
.help-content {
    line-height: 1.8;
    color: #343a40;
    font-size: 1.05em;
}

.help-content h3 {
    color: #2c3e50;
    margin: 1.5em 0 0.8em 0;
    font-size: 1.3em;
    font-weight: 600;
    padding-bottom: 6px;
    border-bottom: 1px solid #f1f3f5;
}

.help-content p {
    margin: 1em 0;
    line-height: 1.7;
    color: #495057;
    max-width: 100%;
    width: 100%;
}

.help-content ul,
.help-content ol {
    margin: 1em 0 1em 1.5em;
    padding: 0;
    max-width: 100%;
}

.help-content li {
    margin-bottom: 0.6em;
    line-height: 1.7;
    color: #495057;
}

/* Fórmulas matemáticas */
.math-formula {
    display: inline-block;
    background-color: #f8f9fa;
    padding: 0.5em 1em;
    border-radius: 4px;
    margin: 0.5em 0;
    font-family: 'Courier New', monospace;
    font-size: 1.1em;
    border-left: 3px solid #4dabf7;
    white-space: nowrap;
}

/* Mensaje de bienvenida */
.help-placeholder {
    color: #6c757d;
    font-style: italic;
    text-align: center;
    padding: 2em 1em;
    font-size: 1.1em;
    background-color: #f8f9fa;
    border-radius: 6px;
}

.help-placeholder h3 {
    color: #2c3e50;
    margin-bottom: 0.8em;
    font-weight: 600;
}

/* Notación matemática */
.MathJax_Display {
    margin: 1.2em 0 !important;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.5em 0;
}

/* Estilos responsivos */
@media (max-width: 768px) {
    .help-container {
        padding: 15px;
        margin: 15px -15px; /* Extender hasta los bordes de la pantalla */
        border-radius: 0;
        max-width: 100vw;
        width: 100vw;
        box-sizing: border-box;
        position: relative;
        left: 50%;
        right: 50%;
        margin-left: -50vw;
        margin-right: -50vw;
    }
    
    .help-content {
        font-size: 1em;
        max-width: 100%;
        width: 100%;
        padding: 0 15px;
        box-sizing: border-box;
    }
    
    .help-content h3 {
        font-size: 1.2em;
        margin: 1.2em 0 0.8em 0;
        max-width: 100%;
    }
    
    .help-content p,
    .help-content ul,
    .help-content ol {
        margin-bottom: 1em;
        line-height: 1.6;
        max-width: 100%;
        width: 100%;
    }
    
    .help-content ul,
    .help-content ol {
        margin-left: 1em;
        padding-left: 0.5em;
    }
}

/* Resultados */
#result {
    margin: 1.5rem auto;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    font-weight: 500;
    text-align: center;
    transition: all 0.3s ease;
    width: 90%;
    max-width: 600px;
    box-sizing: border-box;
    font-size: 1.1em;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
    position: relative;
    overflow: hidden;
    min-height: 20px; /* Asegura que el espacio esté reservado incluso cuando está vacío */
}

#result::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: currentColor;
    opacity: 0.3;
}

#result.correct {
    background-color: rgba(46, 204, 113, 0.1);
    color: #27ae60;
    border: 1px solid rgba(46, 204, 113, 0.3);
    animation: fadeIn 0.4s ease-out forwards;
}

#result.incorrect {
    background-color: rgba(231, 76, 60, 0.1);
    color: #c0392b;
    border: 1px solid rgba(231, 76, 60, 0.3);
    animation: fadeIn 0.4s ease-out forwards;
}

#result.error {
    background-color: rgba(241, 196, 15, 0.1);
    color: #d35400;
    border: 1px solid rgba(241, 196, 15, 0.3);
    animation: shake 0.5s ease-in-out;
}

/* Asegurar que el mensaje de resultado esté entre la operación y la ayuda */
.operation-display + #result {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

#result + .hint-display {
    margin-top: 1.5rem;
}

/* Asegurar que el contenedor de resultado tenga espacio cuando está vacío */
#result:empty {
    display: none;
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.result .answer {
    margin-top: 0.5rem;
    display: block;
    font-size: 1.2rem;
}

/* Input and Button Styling */
.input-group {
    display: flex;
    gap: 1rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin: 1.5rem 0;
    width: 100%;
    max-width: 600px;
}

#answerInput {
    padding: 0.8rem 1rem;
    font-size: 1.1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    width: 200px;
    text-align: center;
    transition: all 0.3s ease;
}

#answerInput:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
    outline: none;
}

button {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background-color: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

button:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .input-group {
        flex-direction: column;
        gap: 1rem;
    }
    
    #answerInput {
        width: 100%;
        max-width: 300px;
    }
    
    button {
        width: 100%;
        max-width: 300px;
    }
}

.hint-display p {
    margin: 0 0 0.5rem 0; /* Espacio entre párrafos si la pista es larga */
    line-height: 1.6;     /* Altura de línea para buena legibilidad */
}

.hint-display p:last-child {
    margin-bottom: 0; /* Evitar margen extra al final */
}

/* Estilo para el texto "Ayuda:" */
.hint-display strong {
    color: var(--primary-color); /* Color primario para destacar */
    font-weight: 600;
}

/* Controles */
.controls {
    display: flex;
    justify-content: center;
    gap: 1.2rem;
    margin: 2rem 0 1.5rem;
    flex-wrap: wrap;
}

.button-container {
    display: flex;
    justify-content: center;
    margin: 10px 0 0;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.btn, button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.btn:hover, button:hover {
    background-color: #2980b9;
}

.btn:active, button:active {
    transform: translateY(0);
}

.check-btn {
    background-color: var(--success-color);
    margin-right: 8px;
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

.check-btn:hover {
    background-color: #27ae60;
}

.new-problem-btn {
    background-color: var(--primary-color);
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

.new-problem-btn:hover {
    background-color: #2980b9;
}

#checkBtn {
    background-color: var(--success-color);
    color: white;
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

#generateBtn {
    background-color: var(--primary-color);
    color: white;
    min-width: 140px;
    font-size: 0.9rem;
    padding: 0.4rem 0.8rem;
}

button:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

button:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#generateBtn:not(:disabled):hover {
    background-color: #2980b9;
}

#checkBtn:not(:disabled):hover {
    background-color: #27ae60;
}

/* Resultado */
.result {
    text-align: center;
    min-height: 28px;
    font-weight: 600;
    margin: 1.5rem 0;
    padding: 0.8rem;
    border-radius: 6px;
    font-size: 1.1rem;
    transition: var(--transition);
}

.result.correct {
    color: #27ae60;
    background-color: rgba(46, 204, 113, 0.1);
    border: 1px solid rgba(46, 204, 113, 0.2);
}

.result.incorrect {
    color: #e74c3c;
    background-color: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.2);
}

/* Input de respuesta */
.answer-input {
    width: 100%;
    max-width: 280px;
    padding: 8px 12px;
    margin: 10px 0;
    border: 1.5px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    height: 40px;
}

.answer-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.answer-input:disabled {
    background-color: #f8f9fa;
}

/* Responsive */
@media (max-width: 992px) {
    .operations {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }
}

/* =====================
   ESTILOS PARA MÓVILES
   ===================== */

@media (max-width: 768px) {
    /* Reset y ajustes base */
    :root {
        --mobile-padding: 8px;
        --mobile-margin: 4px;
        --mobile-border-radius: 5px;
        --primary-color: #3b82f6;
        --success-color: #10b981;
        --warning-color: #f59e0b;
        --danger-color: #ef4444;
        --text-primary: #1f2937;
        --text-secondary: #4b5563;
        --bg-primary: #ffffff;
        --bg-secondary: #f9fafb;
        --border-color: #e5e7eb;
    }
    
    html {
        font-size: 15px;
        -webkit-text-size-adjust: 100%;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    body {
        margin: 0;
        padding: 0;
        font-family: var(--font-main);
        color: var(--text-primary);
        line-height: 1.5;
        background-color: var(--bg-secondary);
    }
    
    .container {
        width: 100%;
        max-width: 100%;
        margin: 0 auto;
        padding: 0 var(--mobile-padding);
        box-sizing: border-box;
    }
    
    /* Contenedor principal */
    .main-container {
        background: #ffffff;
        border-radius: 0;
        box-shadow: none;
        padding: 0;
        margin: 0;
        max-width: 100%;
        min-height: 100vh;
        overflow-x: hidden;
    }
    
    /* Encabezado */
    .header-container {
        text-align: left;
        margin: 0;
        padding: 0.3rem 0.8rem; /* Mínimo padding vertical */
        background: #ffffff;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
        position: relative;
        z-index: 10;
        overflow: hidden;
    }
    
    .operation-card {
        background: #ffffff;
        border-radius: 0;
        padding: 0.3rem 0.3rem; /* Padding horizontal reducido */
        margin: 0;
        box-shadow: none;
        position: relative;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
        border: none;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .title-wrapper {
        position: relative;
        padding: 0.1rem 0; /* Mínimo padding vertical */
        width: 100%;
        margin: 0;
        display: flex;
        align-items: center;
        gap: 0.4rem; /* Reducido el espacio entre elementos */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        white-space: nowrap;
        flex-wrap: nowrap;
    }
    
    .title-wrapper::-webkit-scrollbar {
        display: none; /* Para Chrome, Safari y Edge */
    }
    
    .main-title {
        font-size: 1rem; /* Tamaño reducido */
        font-weight: 700;
        color: #1f2937;
        margin: 0;
        line-height: 1.1; /* Línea más compacta */
        letter-spacing: -0.01em;
        padding: 0 0.3rem 0 0; /* Padding reducido */
        text-align: left;
        white-space: nowrap;
        display: inline;
        flex-shrink: 0;
    }
    
    .instructions {
        display: inline-flex;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
        gap: 0.3rem; /* Reducido el espacio entre instrucciones */
        margin: 0;
        padding: 0;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        white-space: nowrap;
    }
    
    .instructions::-webkit-scrollbar {
        display: none; /* Para Chrome, Safari y Edge */
    }
    
    .instruction {
        display: inline-flex;
        align-items: center;
        font-size: 0.55rem; /* Tamaño más pequeño */
        font-weight: 500;
        color: #4b5563;
        background-color: #f8f9fa;
        padding: 0.1rem 0.3rem; /* Mínimo padding */
        border-radius: 2px;
        white-space: nowrap;
        border: 1px solid #e9ecef;
        flex-shrink: 0;
        line-height: 1.1; /* Línea más compacta */
    }
    
    .instruction:before {
        content: '✓';
        display: inline-block;
        margin-right: 0.4rem;
        color: var(--success-color);
        font-weight: bold;
    }
    
    /* Contenedor de operaciones */
    .operations-container {
        display: grid;
        grid-template-columns: 1fr 1fr; /* Dos columnas en móvil */
        gap: 0.5rem;
        margin: 0.5rem 0.8rem 0.8rem;
        padding: 0;
        width: auto;
        box-sizing: border-box;
    }
    
    .operation-group {
        background: #ffffff;
        border: 1px solid #e9ecef;
        border-radius: 4px;
        padding: 0.6rem 0.4rem;
        margin: 0;
        transition: all 0.2s ease;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        display: flex;
        flex-direction: column;
        min-height: 0; /* Para evitar problemas de desbordamiento */
    }
    
    .operation-group:focus-within {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    }
    
    .operation-group label {
        display: block;
        font-size: 0.7rem; /* Tamaño de fuente reducido */
        font-weight: 600;
        color: var(--text-secondary);
        margin: 0 0 0.3rem 0;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .operation-select {
        width: 100%;
        font-size: 0.75rem; /* Tamaño de fuente reducido */
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        color: #1f2937;
        background-color: #ffffff;
        border: 1px solid #e9ecef;
        border-radius: 4px;
        padding: 0.3rem 1.8rem 0.3rem 0.7rem;
        height: auto;
        min-height: 2.2rem; /* Altura ligeramente reducida */
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.5rem center;
        background-size: 0.9rem;
        transition: all var(--transition-fast);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .operation-select:focus {
        outline: none;
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    }
    
    /* Botón de alternar operaciones */
    .toggle-button {
        display: flex;
        align-items: center;
        justify-content: center;
        width: calc(100% - 1.6rem);
        padding: 0.7rem 1rem;
        font-size: 0.85rem;
        font-weight: 500;
        color: #2563eb;
        background-color: rgba(37, 99, 235, 0.1);
        border: 1px solid rgba(37, 99, 235, 0.2);
        border-radius: 6px;
        margin: 0.5rem auto;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .toggle-button:hover {
        background-color: rgba(59, 130, 246, 0.15);
        border-color: var(--primary-color);
    }
    
    .toggle-button:active {
        transform: translateY(1px);
    }
    
    /* Área de problemas */
    .math-interface {
        background: #ffffff;
        border-radius: 0;
        padding: 0.3rem 0; /* Mínimo padding vertical */
        margin: 0;
        border: none;
        border-top: 1px solid #e9ecef;
        border-bottom: 1px solid #e9ecef;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
        position: relative;
        left: 0;
        right: 0;
    }
    
    .operation-display {
        min-height: 60px; /* Altura mínima reducida */
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 0.2rem 0.3rem; /* Mínimo padding horizontal reducido */
        margin: 0;
        background: #ffffff;
        border-radius: 0;
        border: none;
        text-align: center;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .operation-display .problem-text {
        font-size: 0.68rem; /* Tamaño significativamente reducido */
        font-weight: 500;
        line-height: 1.1;
        color: #1f2937;
        margin: 0;
        padding: 0.05rem 0.1rem; /* Padding reducido al mínimo */
        overflow-x: auto;
        max-width: 100%;
        text-align: center;
        white-space: normal;
        word-break: break-word;
        width: 100%;
        letter-spacing: -0.05em; /* Espaciado entre letras más reducido */
        -webkit-text-size-adjust: none; /* Previene el zoom automático en iOS */
    }
    
    /* Mensaje de bienvenida en móviles */
    .welcome-message {
        font-size: 0.8rem; /* Tamaño más reducido */
        line-height: 1.2; /* Línea más compacta */
        max-width: 100%;
        padding: 0 0.3rem; /* Padding lateral reducido */
        margin: 0.2rem 0; /* Márgenes verticales reducidos */
    }
    
    .hint-display {
        font-size: 0.8rem;
        line-height: 1.3;
        color: #4b5563;
        background: #f8f9fa;
        border-left: 2px solid #3b82f6;
        padding: 0.5rem 0.7rem;
        margin: 0.5rem 0;
        border-radius: 0 4px 4px 0;
    }
    
    /* Controles */
    .controls {
        display: flex;
        flex-direction: column;
        gap: 0.2rem; /* Espacio mínimo entre elementos */
        margin: 0.2rem 0; /* Margen vertical mínimo */
    }
    
    .input-group {
        display: flex;
        flex-direction: column;
        gap: var(--space-sm);
        width: 100%;
    }
    
    .answer-input {
        width: 100%;
        max-width: 100%;
        font-size: 1.1rem;
        font-family: 'Roboto Mono', monospace;
        color: #1f2937;
        background: #ffffff;
        border: 1px solid #e0e3e7;
        border-radius: 4px;
        padding: 0.4rem 0.6rem; /* Padding mínimo */
        height: auto;
        box-sizing: border-box;
        transition: all 0.2s ease;
        text-align: center;
        margin: 0.1rem 0; /* Margen mínimo */
        box-shadow: 0 1px 1px rgba(0,0,0,0.03);
    }
    
    .answer-input:focus {
        outline: none;
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    }
    
    .answer-input::placeholder {
        color: #9ca3af;
        opacity: 1;
    }
    
    /* Botones */
    .button-group {
        display: grid;
        grid-template-columns: 1fr 2fr;
        gap: 0.3rem; /* Espacio mínimo entre botones */
        width: 100%;
        margin: 0.1rem 0 0; /* Margen superior mínimo */
        padding: 0 0.1rem; /* Padding lateral mínimo */
        align-items: center;
    }
    
    button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 0.6rem 0.4rem;
        font-size: 0.8rem;
        font-weight: 600;
        color: white;
        background: #3b82f6;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
    }
    
    /* Estilo específico para el botón de racha */
    .streak-button {
        padding: 0.4rem 0.2rem;
        font-size: 0.75rem;
        background: #4f46e5; /* Color ligeramente diferente para distinguirlo */
    }
    
    /* Estilo específico para el botón de nueva operación */
    .new-problem-button {
        padding: 0.8rem 0.6rem;
        font-size: 0.9rem;
    }
    
    button:hover {
        background: var(--primary-hover);
        transform: translateY(-1px);
        box-shadow: var(--shadow-md);
    }
    
    button:active {
        transform: translateY(0);
        box-shadow: var(--shadow-sm);
    }
    
    button:disabled {
        opacity: 0.7;
        cursor: not-allowed;
        transform: none !important;
    }
    
    .check-answer-btn {
        background: var(--success-color);
    }
    
    .new-problem-btn {
        background: var(--primary-color);
    }
    
    .show-solution-btn {
        background: var(--warning-color);
        grid-column: 1 / -1;
    }
    
    /* Resultados */
    .result {
        padding: var(--space-md);
        margin: var(--space-md) 0;
        border-radius: var(--mobile-border-radius);
        font-size: 1rem;
        line-height: 1.5;
        text-align: center;
        transition: all var(--transition-normal);
    }
    
    .result.correct {
        background: rgba(16, 185, 129, 0.1);
        color: #065f46;
        border-left: 4px solid var(--success-color);
    }
    
    .result.incorrect {
        background: rgba(239, 68, 68, 0.1);
        color: #991b1b;
        border-left: 4px solid var(--danger-color);
    }
    
    .result .solution {
        display: block;
        margin-top: var(--space-sm);
        font-family: var(--font-mono);
        font-size: 1.1rem;
        font-weight: 500;
        padding: var(--space-sm);
        background: rgba(255, 255, 255, 0.5);
        border-radius: calc(var(--mobile-border-radius) - 2px);
        overflow-x: auto;
    }
    
    /* Mensajes de ayuda */
    .hint-display {
        font-size: 0.9rem;
        line-height: 1.5;
        color: var(--text-secondary);
        background: rgba(249, 250, 251, 0.8);
        border-left: 3px solid var(--primary-color);
        padding: var(--space-sm) var(--space-md);
        margin: var(--space-sm) 0;
        border-radius: 0 var(--mobile-border-radius) var(--mobile-border-radius) 0;
    }
    
    /* Animaciones */
    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: translateY(0); }
    }
    
    .fade-in {
        animation: fadeIn 0.3s ease-out forwards;
    }
    
    /* Ajustes para pantallas muy pequeñas */
    @media (max-width: 360px) {
        :root {
            --mobile-padding: 10px;
            --mobile-font-size: 14px;
        }
        
        .main-title {
            font-size: 1.4rem;
        }
        
        .instruction {
            font-size: 0.7rem;
            padding: 0.25rem 0.6rem;
        }
        
        .operation-select, button {
            font-size: 0.9rem;
            padding: 0.7rem 0.9rem;
        }
        
        /* Controles */
        .controls {
            display: flex;
            flex-direction: column;
            gap: var(--space-sm);
            margin: var(--space-md) 0;
        }
        
        .input-group {
            display: flex;
            flex-direction: column;
            gap: var(--space-sm);
            width: 100%;
        }
        
        .answer-input {
            width: 100%;
            max-width: 100%;
            font-size: 1.2rem;
            font-family: var(--font-mono);
            color: var(--text-primary);
            background: var(--bg-primary);
            border: 2px solid var(--border-color);
            border-radius: 8px;
            padding: 1rem 1.2rem;
            height: auto;
            box-sizing: border-box;
            transition: all 0.2s ease;
            text-align: center;
        }
        
        .answer-input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
        }
        
        .answer-input::placeholder {
            color: #9ca3af;
            opacity: 1;
        }
        
        /* Botones */
        .button-group {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0.8rem;
            width: 100%;
            margin-top: 1rem;
        }
        
        button {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 100%;
            padding: 1rem;
            font-size: 1rem;
            font-weight: 600;
            color: white;
            background: var(--primary-color);
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s ease;
            -webkit-tap-highlight-color: transparent;
            user-select: none;
        }
        
        button:hover {
            background: var(--primary-hover);
            transform: translateY(-1px);
            box-shadow: var(--shadow-md);
        }
        
        button:active {
            transform: translateY(0);
            box-shadow: var(--shadow-sm);
        }
        
        button:disabled {
            opacity: 0.7;
            cursor: not-allowed;
            transform: none !important;
        }
        
        .check-answer-btn {
            background: var(--success-color);
        }
        
        .new-problem-btn {
            background: var(--primary-color);
        }
        
        .show-solution-btn {
            background: var(--warning-color);
            grid-column: 1 / -1;
        }
        
        /* Resultados */
        .result {
            padding: var(--space-md);
            margin: var(--space-md) 0;
            border-radius: var(--mobile-border-radius);
            font-size: 1rem;
            line-height: 1.5;
            text-align: center;
            transition: all var(--transition-normal);
        }
        
        .result.correct {
            background: rgba(16, 185, 129, 0.1);
            color: #065f46;
            border-left: 4px solid var(--success-color);
        }
        
        .result.incorrect {
            background: rgba(239, 68, 68, 0.1);
            color: #991b1b;
            border-left: 4px solid var(--danger-color);
        }
        
        .result .solution {
            display: block;
            margin-top: var(--space-sm);
            font-family: var(--font-mono);
            font-size: 1.1rem;
            font-weight: 500;
            padding: var(--space-sm);
            background: rgba(255, 255, 255, 0.5);
            border-radius: calc(var(--mobile-border-radius) - 2px);
            overflow-x: auto;
        }
        
        /* Mensajes de ayuda */
        .hint-display {
            font-size: 0.9rem;
            line-height: 1.5;
            color: var(--text-secondary);
            background: rgba(249, 250, 251, 0.8);
            border-left: 3px solid var(--primary-color);
            padding: var(--space-sm) var(--space-md);
            margin: var(--space-sm) 0;
            border-radius: 0 var(--mobile-border-radius) var(--mobile-border-radius) 0;
        }
        
        /* Animaciones */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .fade-in {
            animation: fadeIn 0.3s ease-out forwards;
        }
        
        /* Ajustes para pantallas muy pequeñas */
        @media (max-width: 360px) {
            :root {
                --mobile-padding: 10px;
                --mobile-font-size: 14px;
            }
            
            .main-title {
                font-size: 1.4rem;
            }
            
            .instruction {
                font-size: 0.7rem;
                padding: 0.25rem 0.6rem;
            }
            
            .operation-select, button {
                font-size: 0.9rem;
                padding: 0.7rem 0.9rem;
            }
            
            .operation-display .problem-text {
                font-size: 1.2rem;
            }
        }
        
        /* Ajustes para reducir el espacio vertical */
        .controls {
            margin: var(--space-sm) 0;
        }
        
        .result {
            margin: var(--space-sm) 0;
        }
        
        .hint-display {
            margin: var(--space-sm) 0;
        }
        
        /* Ajustes para tablets pequeñas */
        @media (min-width: 481px) and (max-width: 768px) {
            .operations-container {
                grid-template-columns: repeat(2, 1fr);
                gap: 0.75rem;
            }
            
            .main-container {
                padding: 0.75rem 1rem 1.25rem;
            }
            
            .main-title {
                font-size: 1.6rem;
            }
            
            .instruction {
                font-size: 0.8rem;
            }
            
            .operation-display {
                min-height: 140px;
                padding: 1.25rem;
            }
            
            .operation-display .problem-text {
                font-size: 1.3rem;
            }
            
            .controls {
                flex-direction: row;
                flex-wrap: wrap;
            }
            
            .check-answer-btn,
            .new-problem-btn {
                flex: 1 1 45%;
                min-width: 120px;
            }
            
            .streak-counter {
                flex: 1 1 100%;
                margin-top: 0.5rem;
            }
            
            .answer-input {
                max-width: 300px;
                margin: 0 auto;
            }
        }
        
        /* Estilos para el pie de página */
        .site-footer {
            background-color: #2c3e50;
            color: #ecf0f1;
            padding: 2rem 0;
            margin-top: 3rem;
            font-size: 0.95em;
        }
        
        .footer-content {
            display: flex;
            justify-content: space-around;
            flex-wrap: wrap;
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        
        .footer-section {
            flex: 1;
            min-width: 250px;
            margin: 0 1rem 1.5rem;
        }
        
        .footer-section h3 {
            color: #3498db;
            margin-bottom: 1rem;
            font-size: 1.2em;
        }
        
        .footer-section p, 
        .footer-section a {
            color: #bdc3c7;
            line-height: 1.6;
        }
        
        .footer-section a:hover {
            color: #3498db;
            text-decoration: none;
        }
        
        .footer-section ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .footer-section li {
            margin-bottom: 0.5rem;
        }
        
        .footer-bottom {
            text-align: center;
            padding-top: 1.5rem;
            margin-top: 1.5rem;
            border-top: 1px solid #34495e;
            font-size: 0.9em;
            color: #7f8c8d;
        }
        
        /* Mejoras de accesibilidad */
        .sr-only {
            position: absolute;
            width: 1px;
            height: 1px;
            padding: 0;
            margin: -1px;
            overflow: hidden;
            clip: rect(0, 0, 0, 0);
            white-space: nowrap;
            border-width: 0;
        }
        
        [role="button"],
        button,
        input[type="submit"],
        input[type="reset"],
        input[type="button"] {
            cursor: pointer;
        }
        
        :focus {
            outline: 3px solid #4a90e2;
            outline-offset: 2px;
        }
    }
    
    .main-container {
        padding: 0.75rem 1rem 1.25rem;
    }
    
    .main-title {
        font-size: 1.6rem;
    }
    
    .instruction {
        font-size: 0.8rem;
    }
    
    .operation-display {
        min-height: 140px;
        padding: 1.25rem;
    }
    
    .operation-display .problem-text {
        font-size: 1.3rem;
    }
    
    .controls {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .check-answer-btn,
    .new-problem-btn {
        flex: 1 1 45%;
        min-width: 120px;
    }
    
    .streak-counter {
        flex: 1 1 100%;
        margin-top: 0.5rem;
    }
    
    .answer-input {
        max-width: 300px;
        margin: 0 auto;
    }
}

/* Estilos para el pie de página */
.site-footer {
    background-color: #2c3e50;
    color: #ecf0f1;
    padding: 2rem 0;
    margin-top: 3rem;
    font-size: 0.95em;
}

.footer-content {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer-section {
    flex: 1;
    min-width: 250px;
    margin: 0 1rem 1.5rem;
}

.footer-section h3 {
    color: #3498db;
    margin-bottom: 1rem;
    font-size: 1.2em;
}

.footer-section p, 
.footer-section a {
    color: #bdc3c7;
    line-height: 1.6;
}

.footer-section a:hover {
    color: #3498db;
    text-decoration: none;
}

.footer-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-section li {
    margin-bottom: 0.5rem;
}

.footer-bottom {
    text-align: center;
    padding-top: 1.5rem;
    margin-top: 1.5rem;
    border-top: 1px solid #34495e;
    font-size: 0.9em;
    color: #7f8c8d;
}

/* Mejoras de accesibilidad */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

[role="button"],
button,
input[type="submit"],
input[type="reset"],
input[type="button"] {
    cursor: pointer;
}

:focus {
    outline: 3px solid #4a90e2;
    outline-offset: 2px;
}
