/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --mColor: #333333;
    --sColor: #FD9427;
    --tColor: #A7A7A7;
    --bgColor: #10a7cd;
    --calcBg: #000000;
    --buttonSize: 80px;
    --transitionSpeed: 0.3s;

    /* Responsive Font Sizes */
    --displayFontSize: 2.5rem; /* 40px */
    --buttonFontSize: 1.5625rem; /* 25px */
    --acButtonFontSize: 2.1875rem; /* 35px */
}

/* Body Styles */
body {
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* Changed from height to min-height for better responsiveness */
    background-color: var(--bgColor);
    animation: bgFadeIn 1s ease-out forwards;
    padding: 20px; /* Added padding to prevent content from touching screen edges on small devices */
}

/* Calculator Container */
#calculator {
    background-color: var(--calcBg);
    border-radius: 15px;
    padding: 20px; /* Increased padding for better spacing */
    margin: 5px;
    max-width: 400px;
    width: 100%; /* Ensure calculator takes full width on smaller screens */
    overflow: hidden;
    border: 5px solid var(--calcBg);
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.5);
    animation: slideIn 0.5s ease-out forwards;
    position: relative;
    transform: scale(0.8);
    opacity: 0;
    transition: box-shadow var(--transitionSpeed) ease, transform var(--transitionSpeed) ease;
}

/* Display Styles */
#display {
    width: 100%;
    padding: 20px;
    font-size: var(--displayFontSize);
    text-align: right;
    border: none;
    background-color: var(--calcBg);
    color: #fff;
    font-family: "Londrina Sketch", sans-serif;
    animation: fadeInDisplay 0.3s ease-in-out;
    position: relative;
    overflow: hidden;
    margin-bottom: 20px; /* Space between display and keys */
    word-wrap: break-word; /* Ensure long inputs wrap within the display */
}

/* Keys Container */
#keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    padding: 0; /* Removed padding to better align buttons */
    position: relative;
}

/* Common Button Styles */
.button,
.Obutton,
.ACbutton {
    width: var(--buttonSize);
    height: var(--buttonSize);
    border-radius: 50%;
    border: none;
    color: #fff;
    font-size: var(--buttonFontSize);
    font-family: "Protest Strike", sans-serif;
    cursor: pointer;
    transition: 
        transform var(--transitionSpeed) ease, 
        box-shadow var(--transitionSpeed) ease, 
        background-color var(--transitionSpeed) ease,
        filter var(--transitionSpeed) ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Specific Button Styles */
.button {
    background-color: var(--mColor);
}

.Obutton {
    background-color: var(--sColor);
}

.ACbutton {
    border-radius: 25px;
    background-color: var(--sColor);
    font-size: var(--acButtonFontSize);
}

/* Hover Effects */
.button:hover,
.Obutton:hover,
.ACbutton:hover {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    transform: scale(1.1);
    filter: brightness(1.2);
}

/* Active (Press) Effects */
.button:active,
.Obutton:active,
.ACbutton:active {
    transform: scale(0.95);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    filter: brightness(1);
}

/* Ripple Effect on Button Click */
.button::after,
.Obutton::after,
.ACbutton::after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: scale(0);
    opacity: 0;
    transition: transform 0.4s, opacity 0.8s;
}

.button:active::after,
.Obutton:active::after,
.ACbutton:active::after {
    transform: scale(2.5);
    opacity: 1;
    transition: transform 0.1s, opacity 0.2s;
}

/* Entrance Animations */
@keyframes slideIn {
    from {
        transform: scale(0.8) translateY(-50px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes bgFadeIn {
    from {
        background-color: #ffffff;
    }
    to {
        background-color: var(--bgColor);
    }
}

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

.display-update {
    animation: displayUpdate 0.3s ease-in-out;
}

@keyframes displayUpdate {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }
    50% {
        opacity: 1;
        transform: translateY(5px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Calculator Hover Glow */
#calculator:hover {
    box-shadow: 0 0 30px rgba(255, 148, 39, 0.6);
    transition: box-shadow 0.5s ease;
}

/* Responsive Design */

/* Mobile Devices (up to 480px) */
@media (max-width: 480px) {
    :root {
        --buttonSize: 60px;
        --displayFontSize: 2rem; /* 32px */
        --buttonFontSize: 1.25rem; /* 20px */
        --acButtonFontSize: 1.75rem; /* 28px */
    }

    #calculator {
        max-width: 100%;
        padding: 15px;
        border: 3px solid var(--calcBg);
    }

    #display {
        padding: 15px;
        font-size: var(--displayFontSize);
        margin-bottom: 15px;
    }

    #keys {
        gap: 10px;
        padding: 0;
    }

    .button,
    .Obutton,
    .ACbutton {
        width: var(--buttonSize);
        height: var(--buttonSize);
        font-size: var(--buttonFontSize);
    }

    .ACbutton {
        font-size: var(--acButtonFontSize);
        height: 60px; /* Adjust height for AC button */
        border-radius: 20px; /* Less rounded for smaller size */
    }
}

/* Tablet Devices (481px to 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    :root {
        --buttonSize: 70px;
        --displayFontSize: 2.2rem; /* 35px */
        --buttonFontSize: 1.4rem; /* 22.5px */
        --acButtonFontSize: 1.9rem; /* 30px */
    }

    #calculator {
        max-width: 350px;
        padding: 18px;
        border: 4px solid var(--calcBg);
    }

    #display {
        padding: 18px;
        font-size: var(--displayFontSize);
        margin-bottom: 18px;
    }

    #keys {
        gap: 12px;
        padding: 0;
    }

    .button,
    .Obutton,
    .ACbutton {
        width: var(--buttonSize);
        height: var(--buttonSize);
        font-size: var(--buttonFontSize);
    }

    .ACbutton {
        font-size: var(--acButtonFontSize);
        height: 65px;
        border-radius: 22px; 
    }
}

@media (min-width: 769px) {
    :root {
        --buttonSize: 80px;
        --displayFontSize: 2.5rem; 
        --buttonFontSize: 1.5625rem; 
        --acButtonFontSize: 2.1875rem;
    }

    #calculator {
        max-width: 400px;
        padding: 20px;
        border: 5px solid var(--calcBg);
    }

    #display {
        padding: 20px;
        font-size: var(--displayFontSize);
        margin-bottom: 20px;
    }

    #keys {
        gap: 15px;
        padding: 0;
    }

    .button,
    .Obutton,
    .ACbutton {
        width: var(--buttonSize);
        height: var(--buttonSize);
        font-size: var(--buttonFontSize);
    }

    .ACbutton {
        font-size: var(--acButtonFontSize);
        height: 80px; 
        border-radius: 25px;
    }
}
