* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
    overflow: hidden;
    perspective: 1000px;
    transition: background 0.5s ease;
}

body.dark-mode {
    background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
}

body::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: float 20s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(-30px, -30px) rotate(120deg); }
    66% { transform: translate(30px, -30px) rotate(240deg); }
}

.calculator-container {
    position: relative;
    z-index: 1;
}

.calculator {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
    padding: 25px;
    max-width: 400px;
    width: 90vw;
    animation: slideIn 0.5s ease-out;
    transform-style: preserve-3d;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.calculator:hover {
    transform: rotateX(5deg) rotateY(5deg) scale(1.02);
    box-shadow: 0 12px 40px rgba(31, 38, 135, 0.5);
}

.calculator.dark-mode {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes successPulse {
    0%, 100% { box-shadow: 0 0 0 rgba(76, 175, 80, 0.4); }
    50% { box-shadow: 0 0 20px rgba(76, 175, 80, 0.7); }
}

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

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

@keyframes buttonPress {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

@keyframes glowPulse {
    0%, 100% { box-shadow: 0 0 5px rgba(255, 255, 255, 0.3); }
    50% { box-shadow: 0 0 20px rgba(255, 255, 255, 0.6); }
}

@keyframes confetti {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(-100px) rotate(360deg); opacity: 0; }
}

.display {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    text-align: right;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-family: 'Courier New', monospace;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
}

.previous-operand {
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.2rem;
    min-height: 24px;
    word-wrap: break-word;
    word-break: break-all;
}

.current-operand {
    color: white;
    font-size: 2.5rem;
    font-weight: 300;
    word-wrap: break-word;
    word-break: break-all;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

button {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    color: white;
    font-size: 1.3rem;
    font-weight: 500;
    padding: 25px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

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

button:active::before {
    width: 300px;
    height: 300px;
}

button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px) rotateX(10deg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15), 0 0 15px rgba(255, 255, 255, 0.2);
}

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

button.pressed {
    animation: buttonPress 0.3s ease;
}

.display.success {
    animation: successPulse 0.6s ease;
}

.display.error {
    animation: errorShake 0.5s ease;
}

.current-operand {
    animation: fadeIn 0.3s ease;
}

button.operation {
    background: rgba(101, 127, 234, 0.4);
    color: white;
}

button.operation:hover {
    background: rgba(101, 127, 234, 0.6);
}

button.equals {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    grid-column: span 2;
}

button.equals:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a3f9e 100%);
    animation: glowPulse 2s infinite;
}

button.clear {
    background: rgba(234, 84, 85, 0.4);
    color: white;
}

button.clear:hover {
    background: rgba(234, 84, 85, 0.6);
}

button[data-action="delete"] {
    background: rgba(255, 165, 0, 0.4);
    color: white;
}

button[data-action="delete"]:hover {
    background: rgba(255, 165, 0, 0.6);
}

button.span-2 {
    grid-column: span 2;
}

@media (max-width: 768px) {
    .calculator {
        width: 95vw;
        padding: 20px;
    }

    .display {
        padding: 18px;
        min-height: 90px;
    }

    .current-operand {
        font-size: 2.2rem;
    }

    .previous-operand {
        font-size: 1.1rem;
    }

    button {
        padding: 22px;
        font-size: 1.2rem;
    }

    .buttons {
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .calculator {
        padding: 15px;
    }

    .display {
        padding: 15px;
        min-height: 80px;
    }

    .current-operand {
        font-size: 2rem;
    }

    .previous-operand {
        font-size: 1rem;
    }

    button {
        padding: 20px;
        font-size: 1.1rem;
    }

    .buttons {
        gap: 10px;
    }
}

@media (max-height: 600px) and (orientation: landscape) {
    body {
        min-height: 100vh;
        padding: 10px 0;
    }

    .calculator {
        max-width: 90vw;
        padding: 15px;
    }

    .display {
        min-height: 60px;
        padding: 10px;
    }

    .current-operand {
        font-size: 1.8rem;
    }

    button {
        padding: 15px;
        font-size: 1rem;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .calculator {
        max-width: 350px;
    }

    button {
        padding: 20px;
    }
}

@media (hover: none) {
    button:hover {
        background: rgba(255, 255, 255, 0.15);
        transform: none;
    }

    button.operation:hover {
        background: rgba(101, 127, 234, 0.4);
    }

    button.equals:hover {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }

    button.clear:hover {
        background: rgba(234, 84, 85, 0.4);
    }

    button[data-action="delete"]:hover {
        background: rgba(255, 165, 0, 0.4);
    }
}