@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');

:root {
    --bg-gradient-start: #1D2B64;
    --bg-gradient-end: #F8CDDA;
    --glass-bg: rgba(30, 30, 46, 0.5);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #F0F2F5;
    --text-secondary: #A9A9C2;
    --btn-bg: rgba(255, 255, 255, 0.05);
    --btn-hover-bg: rgba(255, 255, 255, 0.1);
    --btn-special-text: #FFD6A5;
    --btn-operator-bg: #FF9F0A;
    --btn-operator-text: #1E1E2E;
    --shadow: rgba(0, 0, 0, 0.2);
    --font-family: 'Inter', sans-serif;
}

[data-theme="light"] {
    --bg-gradient-start: #E0EAFC;
    --bg-gradient-end: #CFDEF3;
    --glass-bg: rgba(255, 255, 255, 0.5);
    --glass-border: rgba(0, 0, 0, 0.1);
    --text-primary: #1C1C1E;
    --text-secondary: #6E6E73;
    --btn-bg: rgba(0, 0, 0, 0.03);
    --btn-hover-bg: rgba(0, 0, 0, 0.06);
    --btn-special-text: #D83F87;
    --btn-operator-bg: #4A90E2;
    --btn-operator-text: #FFFFFF;
    --shadow: rgba(100, 100, 111, 0.2);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 15px;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    background-attachment: fixed;
    transition: background 0.5s ease;
    overflow-x: hidden;
}

.calculator-body {
    width: 100%;
    max-width: 360px;
    background: var(--glass-bg);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    padding: 25px;
    box-shadow: 0 8px 32px 0 var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: background 0.5s ease, border 0.5s ease;
    transform: scale(0.95);
    opacity: 0;
    animation: fadeInScale 0.6s 0.2s forwards cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes fadeInScale {
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.calculator-header {
    display: flex;
    justify-content: center;
}

.theme-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
    border-radius: 99px;
    background-color: var(--btn-bg);
    cursor: pointer;
}

.theme-switcher .icon {
    width: 24px;
    height: 24px;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 50%;
    transition: color 0.3s, background-color 0.3s;
}

.theme-switcher .icon.active {
    background-color: var(--glass-bg);
    color: var(--text-primary);
}

.calculator-screen {
    width: 100%;
    padding: 15px 20px;
    text-align: right;
    word-wrap: break-word;
    word-break: break-all;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background: var(--btn-bg);
    border-radius: 20px;
}

.previous-operand {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 400;
    min-height: 25px;
    transition: color 0.5s ease;
}

.current-operand {
    color: var(--text-primary);
    font-size: 3rem;
    font-weight: 500;
    line-height: 1.2;
    transition: color 0.5s ease, font-size 0.3s ease-out;
}

.current-operand.updated {
    animation: flipIn 0.4s forwards cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes flipIn {
    from {
        transform: perspective(400px) rotateX(90deg);
        opacity: 0;
    }
    to {
        transform: perspective(400px) rotateX(0deg);
        opacity: 1;
    }
}

.calculator-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.calculator-buttons button {
    font-family: var(--font-family);
    font-size: 1.4rem;
    font-weight: 500;
    height: 65px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.5s forwards cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.calculator-buttons button:hover {
    background: var(--btn-hover-bg);
}

.calculator-buttons button:active {
    transform: scale(0.92);
}

.calculator-buttons button:nth-child(1) { animation-delay: 0.53s; }
.calculator-buttons button:nth-child(2) { animation-delay: 0.56s; }
.calculator-buttons button:nth-child(3) { animation-delay: 0.59s; }
.calculator-buttons button:nth-child(4) { animation-delay: 0.62s; }
.calculator-buttons button:nth-child(5) { animation-delay: 0.65s; }
.calculator-buttons button:nth-child(6) { animation-delay: 0.68s; }
.calculator-buttons button:nth-child(7) { animation-delay: 0.71s; }
.calculator-buttons button:nth-child(8) { animation-delay: 0.74s; }
.calculator-buttons button:nth-child(9) { animation-delay: 0.77s; }
.calculator-buttons button:nth-child(10) { animation-delay: 0.80s; }
.calculator-buttons button:nth-child(11) { animation-delay: 0.83s; }
.calculator-buttons button:nth-child(12) { animation-delay: 0.86s; }
.calculator-buttons button:nth-child(13) { animation-delay: 0.89s; }
.calculator-buttons button:nth-child(14) { animation-delay: 0.92s; }
.calculator-buttons button:nth-child(15) { animation-delay: 0.95s; }
.calculator-buttons button:nth-child(16) { animation-delay: 0.98s; }
.calculator-buttons button:nth-child(17) { animation-delay: 1.01s; }
.calculator-buttons button:nth-child(18) { animation-delay: 1.04s; }
.calculator-buttons button:nth-child(19) { animation-delay: 1.07s; }

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.span-two {
    grid-column: span 2;
}

.btn-special {
    color: var(--btn-special-text);
}

.btn-operator {
    background: var(--btn-operator-bg);
    color: var(--btn-operator-text);
}

.btn-operator:hover {
    background: var(--btn-operator-bg);
    filter: brightness(1.1);
}

.btn-equals {
    background: var(--btn-operator-bg);
    color: var(--btn-operator-text);
}
.btn-equals:hover {
    background: var(--btn-operator-bg);
    filter: brightness(1.1);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 15px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0s 0.4s;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.4s ease;
}

.modal-content {
    background: var(--glass-bg);
    padding: 30px;
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    text-align: center;
    max-width: 90%;
    width: 380px;
    position: relative;
    box-shadow: 0 8px 32px 0 var(--shadow);
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.4s ease;
}

.modal-overlay.visible .modal-content {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.modal-content h3 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.modal-content p {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 25px;
    line-height: 1.5;
}

.close-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s ease, transform 0.2s ease;
    padding: 5px;
}

.close-button:hover {
    color: var(--text-primary);
    transform: rotate(90deg);
}

.modal-link {
    display: inline-block;
    padding: 12px 24px;
    background: var(--btn-operator-bg);
    color: var(--btn-operator-text);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    transition: filter 0.2s ease, transform 0.2s ease;
}

.modal-link:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}