:root {
    --bg-gradient: linear-gradient(135deg, #e0e7ff 0%, #d1fae5 100%);
    --calc-bg: rgba(255, 255, 255, 0.7);
    --screen-bg: rgba(255, 255, 255, 0.5);
    --text-main: #4b5563;
    --text-muted: #9ca3af;
    
    /* Pastel Palette */
    --p-pink: #fce7f3;
    --p-peach: #ffedd5;
    --p-blue: #dbeafe;
    --p-lavender: #ede9fe;
    --p-mint: #d1fae5;
    --p-yellow: #fef3c7;
    --p-coral: #fee2e2;
    
    --accent: #8b5cf6;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    --inner-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
    --bg-gradient: linear-gradient(135deg, #1e1b4b 0%, #064e3b 100%);
    --calc-bg: rgba(30, 41, 59, 0.8);
    --screen-bg: rgba(15, 23, 42, 0.6);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --p-pink: #831843;
    --p-peach: #7c2d12;
    --p-blue: #1e3a8a;
    --p-lavender: #4c1d95;
    --p-mint: #064e3b;
    --p-yellow: #78350f;
    --p-coral: #7f1d1d;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    padding: 20px;
    transition: background 0.5s ease;
}

.calculator-container {
    background: var(--calc-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 32px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
}

/* Screen Styles */
.screen {
    background: var(--screen-bg);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 24px;
    text-align: right;
    box-shadow: var(--inner-shadow);
    min-height: 110px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 4px;
    position: relative;
}

.expression {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    color: var(--text-muted);
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}

.expression::-webkit-scrollbar { display: none; }

.result {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.2rem;
    font-weight: 600;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}

.mode-indicator {
    position: absolute;
    top: 10px;
    left: 15px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent);
    letter-spacing: 0.1em;
}

/* Grid Layout */
.controls {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

button {
    border: none;
    border-radius: 16px;
    height: 52px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

button:hover {
    transform: translateY(-2px);
    filter: brightness(0.95);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

button:active {
    transform: translateY(1px);
    filter: brightness(0.9);
}

/* Button Variations */
.btn-num { background: white; }
.btn-op { background: var(--p-blue); }
.btn-sci { background: var(--p-lavender); font-size: 0.8rem; }
.btn-mem { background: var(--p-mint); font-size: 0.75rem; }
.btn-clear { background: var(--p-coral); color: #b91c1c; }
.btn-equal { 
    background: var(--p-peach); 
    grid-column: span 2;
    color: #c2410c;
}
.btn-active {
    background: var(--accent);
    color: white;
}

/* Utilities */
.span-2 { grid-column: span 2; }

/* History Panel */
.history-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    z-index: 10;
}

.history-panel {
    position: absolute;
    top: 0;
    right: -100%;
    width: 100%;
    height: 100%;
    background: var(--calc-bg);
    backdrop-filter: blur(30px);
    z-index: 20;
    transition: 0.3s ease-in-out;
    padding: 60px 24px 24px;
    display: flex;
    flex-direction: column;
}

.history-panel.open { right: 0; }

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
}

.history-item {
    padding: 12px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.history-item:hover { background: rgba(0,0,0,0.03); }

.history-exp { font-size: 0.8rem; color: var(--text-muted); }
.history-res { font-size: 1.1rem; font-weight: 600; margin-top: 4px; }

/* Responsive adjustments */
@media (max-width: 400px) {
    .calculator-container {
        padding: 16px;
        border-radius: 24px;
    }
    .controls { gap: 8px; }
    button { height: 48px; border-radius: 12px; font-size: 0.85rem; }
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 100;
}