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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 500px;
}

.calculator {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    backdrop-filter: blur(10px);
    animation: slideIn 0.5s ease-out;
    transition: max-width 0.3s ease;
}

.calculator.scientific-mode {
    max-width: 500px;
}

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

.calculator-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    text-align: center;
}

.calculator-header h1 {
    color: white;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.mode-toggles {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}

.toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    font-weight: 500;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.toggle-btn.active {
    background: white;
    color: #667eea;
}

.display-section {
    background: #1e1e1e;
    padding: 30px 25px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    word-wrap: break-word;
    word-break: break-all;
    position: relative;
}

.mode-indicator {
    position: absolute;
    top: 10px;
    left: 25px;
    display: flex;
    gap: 10px;
}

.indicator {
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

#memoryIndicator.active {
    color: #4CAF50;
    background: rgba(76, 175, 80, 0.2);
}

#memoryIndicator.active::before {
    content: 'M';
}

.previous-operand {
    color: rgba(255, 255, 255, 0.6);
    font-size: 18px;
    min-height: 22px;
    margin-bottom: 5px;
    max-width: 100%;
}

.current-operand {
    color: white;
    font-size: 36px;
    font-weight: 300;
    min-height: 45px;
    animation: fadeIn 0.2s ease;
    max-width: 100%;
}

@keyframes fadeIn {
    from {
        opacity: 0.5;
    }
    to {
        opacity: 1;
    }
}

/* History Panel */
.history-panel {
    background: #f5f5f5;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.history-panel.active {
    max-height: 300px;
    padding: 15px;
    overflow-y: auto;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 2px solid #ddd;
}

.history-header h3 {
    color: #333;
    font-size: 16px;
    font-weight: 600;
}

.clear-history-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-history-btn:hover {
    background: #c0392b;
    transform: scale(1.05);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: white;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid #667eea;
}

.history-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.history-expression {
    color: #666;
    font-size: 14px;
    margin-bottom: 4px;
}

.history-result {
    color: #333;
    font-size: 18px;
    font-weight: 600;
}

.no-history {
    color: #999;
    text-align: center;
    padding: 20px;
    font-style: italic;
}

/* Scientific Buttons */
.scientific-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1px;
    background: #e0e0e0;
    padding: 1px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.scientific-buttons.active {
    max-height: 500px;
}

.btn-sci {
    background: #f8f9fa;
    color: #495057;
    font-size: 16px;
    padding: 15px 8px;
}

.btn-sci:hover {
    background: #e9ecef;
}

/* Memory Buttons */
.memory-buttons {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1px;
    background: #e0e0e0;
    padding: 1px;
}

.btn-memory {
    background: #fff3cd;
    color: #856404;
    font-size: 14px;
    padding: 12px;
    font-weight: 600;
}

.btn-memory:hover {
    background: #ffeaa7;
}

.btn-memory.active {
    background: #ffc107;
    color: white;
}

/* Basic Buttons */
.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: #e0e0e0;
    padding: 1px;
}

.btn {
    border: none;
    background: white;
    font-size: 22px;
    padding: 22px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

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

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

.btn:hover {
    background: #f5f5f5;
    transform: scale(1.02);
}

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

.btn-number {
    color: #2c3e50;
}

.btn-operator {
    background: #667eea;
    color: white;
}

.btn-operator:hover {
    background: #5568d3;
}

.btn-function {
    background: #95a5a6;
    color: white;
    font-size: 18px;
}

.btn-function:hover {
    background: #7f8c8d;
}

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

.btn-equals:hover {
    background: linear-gradient(135deg, #5568d3 0%, #65408b 100%);
}

.btn-zero {
    grid-column: span 2;
}

/* Parentheses Row */
.parentheses-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: #e0e0e0;
    padding: 1px;
}

/* Responsive design */
@media (max-width: 540px) {
    .container {
        max-width: 100%;
    }
    
    .calculator {
        border-radius: 0;
    }
    
    .btn {
        padding: 18px;
        font-size: 18px;
    }
    
    .btn-sci {
        padding: 12px 5px;
        font-size: 14px;
    }
    
    .current-operand {
        font-size: 32px;
    }
    
    .previous-operand {
        font-size: 16px;
    }
    
    .calculator-header h1 {
        font-size: 18px;
    }
    
    .toggle-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* Error state */
.error {
    color: #e74c3c !important;
    animation: shake 0.5s;
}

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

/* Calculation animation */
.calculating {
    animation: pulse 0.3s;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Scrollbar styling for history */
.history-panel::-webkit-scrollbar {
    width: 8px;
}

.history-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.history-panel::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.history-panel::-webkit-scrollbar-thumb:hover {
    background: #555;
}
