:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --light-color: #ecf0f1;
    --dark-color: #2c3e50;
    --danger-color: #e74c3c;
    --success-color: #2ecc71;
    --shadow: 0 10px 20px rgba(0,0,0,0.15);
    --button-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

body {
    font-family: 'Inter', 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    color: var(--dark-color);
}

h1 {
    text-align: center;
    color: var(--primary-color);
    font-size: 2.2rem;
    font-weight: 600;
    margin-bottom: 2rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.calculator {
    width: 100%;
    max-width: 380px;
    margin: 20px auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    padding: 20px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    box-sizing: border-box;
}

#display {
    width: 100%;
    height: 80px;
    margin-bottom: 25px;
    text-align: right;
    padding: 0 20px;
    font-size: 2.2rem;
    font-weight: 500;
    border: none;
    background: linear-gradient(145deg, #e6e9ef, #ffffff);
    border-radius: 16px;
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.1);
    color: var(--dark-color);
    box-sizing: border-box;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    font-family: 'Inter', monospace;
    letter-spacing: 1px;
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

/* Estilos base para todos los botones */
button {
    padding: 18px 10px;
    font-size: 1.3rem;
    font-weight: 600;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    position: relative;
    overflow: hidden;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Botones numéricos */
button:not(:nth-child(4n)):not(:nth-child(-n+4)):not(.equals) {
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    color: var(--dark-color);
    border: 1px solid rgba(0,0,0,0.1);
}

/* Botones de operadores (los de la derecha) */
button:nth-child(4n):not(.equals) {
    background: linear-gradient(145deg, #4a90e2, #357abd);
    color: white;
    font-size: 1.4rem;
}

/* Botones superiores (C, ⌫, (, )) */
button:nth-child(-n+4) {
    background: linear-gradient(145deg, #576574, #485563);
    color: white;
    font-weight: 500;
}

/* Botón Clear */
button:first-child {
    background: linear-gradient(145deg, #e74c3c, #c0392b);
    color: white;
}

/* Botón Igual */
.equals {
    background: linear-gradient(145deg, #2ecc71, #27ae60);
    color: white;
    grid-column: span 2;
    grid-row: auto;
    font-size: 1.5rem;
    font-weight: 700;
}

/* Efectos hover */
button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.2);
    filter: brightness(1.1);
}

button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    filter: brightness(0.95);
}

/* Botones especiales (%, ±, √) */
button:nth-last-child(3),
button:nth-last-child(2) {
    background: linear-gradient(145deg, #7f8c8d, #95a5a6);
    color: white;
}

#history {
    max-width: 380px;
    margin: 2rem auto;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

#history h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.4rem;
    font-weight: 600;
}

#historyList {
    list-style: none;
    padding: 0;
    margin: 0;
}

#historyList li {
    padding: 12px 15px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    color: var(--dark-color);
    font-size: 1rem;
    transition: background-color 0.3s ease;
}

#historyList li:hover {
    background-color: rgba(0,0,0,0.03);
}

#historyList li:last-child {
    border-bottom: none;
}

footer {
    text-align: center;
    margin-top: 2rem;
    padding: 1rem;
    color: var(--dark-color);
    font-size: 0.9rem;
}

/* Responsive Design Mejorado */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 1.8rem;
        margin-bottom: 1.5rem;
    }

    .calculator {
        padding: 15px;
    }

    #display {
        height: 70px;
        font-size: 2rem;
        padding: 0 15px;
        margin-bottom: 20px;
    }

    .buttons {
        gap: 6px;
    }

    button {
        padding: 15px 10px;
        font-size: 1.2rem;
        min-height: 45px;
    }

    #history {
        max-width: 100%;
        margin: 1.5rem auto;
        padding: 1.2rem;
    }

    .equals {
        font-size: 1.3rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 8px;
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .calculator {
        padding: 12px;
    }

    #display {
        height: 60px;
        font-size: 1.8rem;
        padding: 0 12px;
        margin-bottom: 15px;
    }

    .buttons {
        gap: 5px;
    }

    button {
        padding: 12px 8px;
        font-size: 1.1rem;
        min-height: 40px;
        border-radius: 12px;
    }

    .equals {
        font-size: 1.2rem;
    }

    #history {
        padding: 1rem;
        margin: 1rem auto;
    }

    #history h2 {
        font-size: 1.2rem;
    }

    #historyList li {
        padding: 8px 10px;
        font-size: 0.9rem;
    }
}

/* Para pantallas muy pequeñas */
@media (max-width: 320px) {
    button {
        padding: 10px 6px;
        font-size: 1rem;
        min-height: 35px;
        border-radius: 10px;
    }

    #display {
        height: 50px;
        font-size: 1.5rem;
        padding: 0 10px;
        margin-bottom: 12px;
    }

    .calculator {
        padding: 10px;
    }

    .buttons {
        gap: 4px;
    }

    .equals {
        font-size: 1.1rem;
    }
}

/* Para tablets en modo landscape */
@media (min-width: 768px) and (max-height: 768px) {
    .calculator {
        max-width: 450px;
    }

    button {
        padding: 12px 8px;
    }
}

/* Para asegurar que la altura de los botones sea proporcional en todos los dispositivos */
@media (orientation: portrait) {
    button {
        aspect-ratio: 1.2;
    }
}

/* Para dispositivos con pantalla táctil */
@media (hover: none) {
    button:hover {
        transform: none;
        box-shadow: var(--button-shadow);
    }
}

/* Efecto de presión mejorado */
button::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: radial-gradient(circle, transparent 1%, rgba(255,255,255,0.1) 1%) center/15000%;
    opacity: 0;
    transition: all 0.3s ease;
}

button:active::after {
    opacity: 1;
    background-size: 100%;
    transition: 0s;
}

/* Selector de idiomas actualizado */
.language-selector {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.language-selector a {
    text-decoration: none;
    color: var(--dark-color);
    padding: 5px 8px;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    font-weight: 500;
}

.language-selector a.active {
    background: var(--primary-color);
    color: white;
}

.language-selector a:hover:not(.active) {
    background: rgba(0,0,0,0.1);
}

@media (max-width: 480px) {
    .language-selector {
        top: 10px;
        right: 10px;
        padding: 6px;
        gap: 4px;
    }

    .language-selector a {
        padding: 4px 6px;
        font-size: 0.8rem;
    }
}
