* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --dark-bg: #1a1a2e;
    --card-bg: rgba(255, 255, 255, 0.05);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 30px 80px rgba(0, 0, 0, 0.4);
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--dark-bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.background-gradient {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(245, 87, 108, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 40% 20%, rgba(118, 75, 162, 0.2) 0%, transparent 50%);
    animation: gradientShift 15s ease infinite;
    z-index: 0;
}

@keyframes gradientShift {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(5%, 5%) rotate(120deg); }
    66% { transform: translate(-5%, 5%) rotate(240deg); }
}

.container {
    position: relative;
    z-index: 1;
    padding: 20px;
    animation: fadeInUp 0.8s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.calculator {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-radius: 30px;
    padding: 30px;
    box-shadow: var(--shadow-xl),
                inset 0 1px 1px rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 400px;
    animation: scaleIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.calculator-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 25px;
}

.header-dots {
    display: flex;
    gap: 8px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    transition: var(--transition-smooth);
    cursor: pointer;
}

.dot:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px currentColor;
}

.dot-red {
    background: linear-gradient(135deg, #ff6b6b, #ee5a6f);
}

.dot-yellow {
    background: linear-gradient(135deg, #ffd93d, #f9ca24);
}

.dot-green {
    background: linear-gradient(135deg, #6bcf7f, #4cd964);
}

.calculator-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.display-container {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    padding: 25px;
    margin-bottom: 25px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    border: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
}

.display-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

.display-container.flash::before {
    left: 100%;
}

.display-history {
    font-size: 16px;
    color: var(--text-secondary);
    text-align: right;
    margin-bottom: 8px;
    min-height: 24px;
    font-weight: 300;
    opacity: 0.6;
}

.display-current {
    font-size: 48px;
    color: var(--text-primary);
    text-align: right;
    font-weight: 300;
    letter-spacing: -1px;
    word-break: break-all;
    animation: digitFadeIn 0.3s ease;
}

@keyframes digitFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.btn {
    background: var(--glass-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 24px;
    font-size: 24px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition-smooth);
    font-family: 'Inter', sans-serif;
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn:active {
    transform: scale(0.95);
}

.btn-number {
    background: rgba(255, 255, 255, 0.08);
}

.btn-number:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-operator {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(118, 75, 162, 0.3));
    font-weight: 600;
}

.btn-operator:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.5), rgba(118, 75, 162, 0.5));
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.btn-operator.active {
    background: var(--primary-gradient);
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.6);
    animation: pulse 0.3s ease;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.btn-function {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

.btn-function:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-equals {
    background: var(--secondary-gradient);
    font-weight: 700;
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.3);
}

.btn-equals:hover {
    box-shadow: 0 8px 30px rgba(245, 87, 108, 0.5);
    transform: translateY(-3px);
}

.btn-equals:active {
    animation: equalsPress 0.3s ease;
}

@keyframes equalsPress {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.95); }
}

.btn-zero {
    grid-column: span 2;
}

/* Error state animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.error {
    animation: shake 0.4s ease;
    color: #ff6b6b !important;
}

/* Responsive design */
@media (max-width: 480px) {
    .calculator {
        padding: 20px;
        max-width: 100%;
    }
    
    .display-current {
        font-size: 36px;
    }
    
    .btn {
        padding: 20px;
        font-size: 20px;
    }
}

/* Accessibility improvements */
.btn:focus {
    outline: 2px solid rgba(102, 126, 234, 0.6);
    outline-offset: 2px;
}

.btn:focus:not(:focus-visible) {
    outline: none;
}
