:root {
    /* Light Theme Colors */
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    
    --btn-number-bg: #ffffff;
    --btn-number-hover: #f7fafc;
    --btn-number-text: #2d3748;
    
    --btn-operator-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --btn-operator-hover: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
    --btn-operator-text: #ffffff;
    
    --btn-function-bg: #edf2f7;
    --btn-function-hover: #e2e8f0;
    --btn-function-text: #4a5568;
    
    --btn-equals-bg: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --btn-equals-hover: linear-gradient(135deg, #e082ea 0%, #e4465b 100%);
    
    --btn-memory-bg: #fef5e7;
    --btn-memory-hover: #fdebd0;
    --btn-memory-text: #d68910;
    
    --card-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    --card-shadow-hover: 0 25px 70px rgba(0, 0, 0, 0.15);
    
    --display-bg: #f7fafc;
    --display-border: #e2e8f0;
}

[data-theme="dark"] {
    /* Dark Theme Colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-gradient-start: #4c1d95;
    --bg-gradient-end: #1e1b4b;
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    
    --btn-number-bg: #334155;
    --btn-number-hover: #475569;
    --btn-number-text: #f1f5f9;
    
    --btn-operator-bg: linear-gradient(135deg, #7c3aed 0%, #c026d3 100%);
    --btn-operator-hover: linear-gradient(135deg, #6d28d9 0%, #a21caf 100%);
    
    --btn-function-bg: #1e293b;
    --btn-function-hover: #334155;
    --btn-function-text: #94a3b8;
    
    --btn-equals-bg: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
    --btn-equals-hover: linear-gradient(135deg, #db2777 0%, #e11d48 100%);
    
    --btn-memory-bg: #422006;
    --btn-memory-hover: #713f12;
    --btn-memory-text: #fbbf24;
    
    --card-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    --card-shadow-hover: 0 25px 70px rgba(0, 0, 0, 0.6);
    
    --display-bg: #0f172a;
    --display-border: #334155;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

.background-gradient {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, var(--bg-gradient-start) 0%, transparent 50%),
                radial-gradient(circle at 70% 50%, var(--bg-gradient-end) 0%, transparent 50%);
    opacity: 0.15;
    z-index: -1;
    animation: gradientShift 15s ease infinite;
}

@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 {
    width: 100%;
    max-width: 420px;
    position: relative;
}

.calculator-card {
    background: var(--bg-secondary);
    border-radius: 32px;
    padding: 32px;
    box-shadow: var(--card-shadow);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.calculator-card:hover {
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-5px);
}

/* Header */
.calculator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.calculator-title {
    font-size: 28px;
    font-weight: 700;
    background: var(--btn-operator-bg);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.theme-toggle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--btn-function-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.theme-toggle:hover {
    background: var(--btn-function-hover);
    transform: rotate(180deg);
}

.theme-icon {
    width: 24px;
    height: 24px;
    color: var(--text-primary);
    position: absolute;
    transition: all 0.3s ease;
}

.sun-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.moon-icon {
    opacity: 0;
    transform: rotate(180deg) scale(0);
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: rotate(-180deg) scale(0);
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Display */
.display-container {
    background: var(--display-bg);
    border: 2px solid var(--display-border);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 16px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 8px;
    transition: all 0.3s ease;
}

.display-history {
    font-size: 16px;
    color: var(--text-muted);
    text-align: right;
    min-height: 24px;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.display-main {
    font-size: 48px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    animation: fadeIn 0.2s ease;
}

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

/* Memory Indicator */
.memory-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--btn-memory-bg);
    border-radius: 12px;
    margin-bottom: 16px;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.memory-indicator.active {
    opacity: 1;
    transform: translateY(0);
}

.memory-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--btn-memory-text);
}

.memory-value {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Buttons Grid */
.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.btn {
    border: none;
    border-radius: 16px;
    font-size: 20px;
    font-weight: 600;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Inter', sans-serif;
    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.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

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

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

.btn-number {
    background: var(--btn-number-bg);
    color: var(--btn-number-text);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.btn-number:hover {
    background: var(--btn-number-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.btn-operator {
    background: var(--btn-operator-bg);
    color: var(--btn-operator-text);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

.btn-operator:hover {
    background: var(--btn-operator-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.btn-function {
    background: var(--btn-function-bg);
    color: var(--btn-function-text);
}

.btn-function:hover {
    background: var(--btn-function-hover);
    transform: translateY(-2px);
}

.btn-equals {
    background: var(--btn-equals-bg);
    color: white;
    box-shadow: 0 4px 16px rgba(245, 87, 108, 0.4);
}

.btn-equals:hover {
    background: var(--btn-equals-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.5);
}

.btn-memory {
    background: var(--btn-memory-bg);
    color: var(--btn-memory-text);
    font-size: 16px;
}

.btn-memory:hover {
    background: var(--btn-memory-hover);
    transform: translateY(-2px);
}

/* History Panel */
.btn-toggle-history {
    width: 100%;
    padding: 16px;
    background: var(--btn-function-bg);
    border: none;
    border-radius: 16px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
}

.btn-toggle-history:hover {
    background: var(--btn-function-hover);
    transform: translateY(-2px);
}

.btn-toggle-history svg {
    width: 20px;
    height: 20px;
}

.history-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 20px;
}

.history-panel.active {
    max-height: 400px;
    overflow-y: auto;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--display-border);
}

.history-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-clear-history {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.btn-clear-history:hover {
    background: var(--btn-function-bg);
    color: var(--text-primary);
}

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

.history-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    padding: 32px 16px;
}

.history-item {
    background: var(--display-bg);
    padding: 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    animation: slideIn 0.3s ease;
}

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

.history-item:hover {
    background: var(--btn-function-hover);
    transform: translateX(5px);
}

.history-expression {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.history-result {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

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

.history-panel::-webkit-scrollbar-track {
    background: transparent;
}

.history-panel::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 4px;
}

.history-panel::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive Design */
@media (max-width: 480px) {
    .calculator-card {
        padding: 24px;
        border-radius: 24px;
    }
    
    .calculator-title {
        font-size: 24px;
    }
    
    .display-main {
        font-size: 40px;
    }
    
    .btn {
        padding: 16px;
        font-size: 18px;
    }
    
    .buttons-grid {
        gap: 10px;
    }
}

@media (max-width: 360px) {
    .display-main {
        font-size: 32px;
    }
    
    .btn {
        padding: 14px;
        font-size: 16px;
    }
}
