* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

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%);
    padding: 10px;
    transition: background 0.5s ease;
}

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

.background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.circle {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    animation: float 20s infinite ease-in-out;
}

.circle1 {
    width: 200px;
    height: 200px;
    top: -5vh;
    left: -5vw;
    animation-delay: 0s;
}

.circle2 {
    width: 150px;
    height: 150px;
    bottom: -3vh;
    right: -3vw;
    animation-delay: 3s;
}

.circle3 {
    width: 250px;
    height: 250px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: 6s;
}

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

.calculator-container {
    position: relative;
    z-index: 1;
    perspective: 1000px;
    width: 100%;
    max-width: 380px;
    max-height: 95vh;
    overflow-y: auto;
    margin: 0 auto;
}

.calculator {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 15px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3),
                0 0 0 1px rgba(255, 255, 255, 0.2) inset;
    width: 100%;
    animation: slideIn 0.6s ease-out;
    transition: all 0.3s ease;
}

body.dark-theme .calculator {
    background: rgba(30, 30, 50, 0.95);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6),
                0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) rotateX(20deg);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotateX(0);
    }
}

.display-section {
    margin-bottom: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 12px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4) inset;
    min-height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    transition: all 0.3s ease;
}

body.dark-theme .display-section {
    background: linear-gradient(135deg, #1e1e32 0%, #2d2d44 100%);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4) inset;
}

.history {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: 600;
    text-align: right;
    margin-bottom: 5px;
    min-height: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    letter-spacing: 1px;
}

.display {
    color: white;
    font-size: 32px;
    font-weight: 800;
    text-align: right;
    letter-spacing: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    animation: fadeIn 0.3s ease;
    text-shadow: 
        -1px -1px 0 rgba(0, 0, 0, 0.3),
        1px -1px 0 rgba(0, 0, 0, 0.3),
        -1px 1px 0 rgba(0, 0, 0, 0.3),
        1px 1px 0 rgba(0, 0, 0, 0.3),
        3px 3px 8px rgba(0, 0, 0, 0.4);
}

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

.mode-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 10px;
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

body.dark-theme .mode-btn {
    background: rgba(255, 255, 255, 0.05);
    color: #8b92ff;
}

.mode-btn:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: translateY(-2px);
}

.mode-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

body.dark-theme .mode-btn.active {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

.buttons-container {
    position: relative;
}

.basic-buttons,
.scientific-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    transition: all 0.5s ease;
}

.scientific-buttons {
    margin-bottom: 8px;
}

.hidden {
    display: none;
    opacity: 0;
}

.btn {
    padding: 16px 10px;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
    letter-spacing: 1px;
}

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

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn.pressed {
    animation: pressEffect 0.3s ease;
    background: rgba(255, 255, 255, 0.9) !important;
}

@keyframes pressEffect {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); }
    100% { transform: scale(1); }
}

.number-btn {
    background: white;
    color: #2d3748;
    font-weight: 800;
}

body.dark-theme .number-btn {
    background: #2d2d44;
    color: #e2e8f0;
}

.operator-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    font-weight: 900;
    font-size: 22px;
}

body.dark-theme .operator-btn {
    background: linear-gradient(135deg, #c471ed 0%, #f64f59 100%);
}

.function-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    font-weight: 800;
}

body.dark-theme .function-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.equals-btn {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    color: white;
    font-size: 24px;
    font-weight: 900;
}

body.dark-theme .equals-btn {
    background: linear-gradient(135deg, #f857a6 0%, #ff5858 100%);
}

.sci-btn {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #2d3748;
    font-size: 14px;
    font-weight: 700;
    padding: 12px 8px;
}

body.dark-theme .sci-btn {
    background: linear-gradient(135deg, #373b44 0%, #4286f4 100%);
    color: white;
}

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

.keyboard-info {
    margin-top: 12px;
    text-align: center;
    font-size: 11px;
    color: #667eea;
    font-weight: 600;
    padding: 8px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    letter-spacing: 0.5px;
}

.keyboard-info span {
    font-weight: 700;
    color: #764ba2;
}

body.dark-theme .keyboard-info {
    color: #8b92ff;
    background: rgba(255, 255, 255, 0.05);
}

body.dark-theme .keyboard-info span {
    color: #a78bfa;
}

.theme-toggle {
    margin-top: 10px;
    display: flex;
    justify-content: center;
}

.theme-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
    font-weight: 700;
}

body.dark-theme .theme-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.theme-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 7px 20px rgba(102, 126, 234, 0.6);
}

.theme-icon {
    font-size: 18px;
    display: inline-block;
    animation: rotate 0.5s ease;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

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

    .display {
        font-size: 28px;
    }

    .btn {
        padding: 14px 8px;
        font-size: 16px;
    }
}

@media (max-height: 700px) {
    .display-section {
        min-height: 60px;
        padding: 10px;
    }
    
    .display {
        font-size: 28px;
    }
    
    .btn {
        padding: 12px 8px;
    }

    .sci-btn {
        padding: 10px 6px;
    }
}

@media (max-height: 600px) {
    .calculator {
        padding: 10px;
    }

    .display-section {
        min-height: 50px;
        margin-bottom: 10px;
    }

    .display {
        font-size: 24px;
    }

    .btn {
        padding: 10px 6px;
        font-size: 14px;
    }

    .keyboard-info {
        font-size: 9px;
        padding: 6px;
    }
}