:root {
    /* Color Palette - Dark Mode (Default) */
    --bg-primary: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --btn-primary: rgba(37, 99, 235, 0.2);
    --btn-secondary: rgba(148, 163, 184, 0.1);
    --btn-accent: #2563eb;
    --btn-text: #ffffff;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --blob-1: #1e3a8a;
    --blob-2: #312e81;
    --blob-3: #1e1b4b;
}

body.light-mode {
    --bg-primary: #f1f5f9;
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.1);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --btn-primary: rgba(37, 99, 235, 0.1);
    --btn-secondary: rgba(0, 0, 0, 0.05);
    --btn-accent: #2563eb;
    --btn-text: #ffffff;
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
    --blob-1: #bfdbfe;
    --blob-2: #ddd6fe;
    --blob-3: #fbcfe8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Background Blobs */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    filter: blur(80px);
}

.blob {
    position: absolute;
    border-radius: 50%;
    opacity: 0.6;
    animation: move 20s infinite alternate;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: var(--blob-1);
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 350px;
    height: 350px;
    background: var(--blob-2);
    bottom: -50px;
    right: -50px;
    animation-delay: -5s;
}

.blob-3 {
    width: 300px;
    height: 300px;
    background: var(--blob-3);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -10s;
}

@keyframes move {
    from { transform: translate(0, 0); }
    to { transform: translate(100px, 100px); }
}

/* App Container */
.app-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    gap: 20px;
}

/* Header */
.app-header {
    width: 100%;
    max-width: 400px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.2rem;
}

.controls {
    display: flex;
    gap: 10px;
}

.controls button {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
}

.controls button:hover {
    transform: translateY(-2px);
    background: var(--glass-border);
}

/* Calculator Card */
.calculator-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    width: 100%;
    max-width: 400px;
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Display Screen */
.display-screen {
    text-align: right;
    padding: 20px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow: hidden;
}

.expression-preview {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 8px;
    min-height: 1.2em;
    word-break: break-all;
}

.current-value {
    color: var(--text-primary);
    font-size: 2.5rem;
    font-weight: 500;
    font-family: 'JetBrains Mono', monospace;
    word-break: break-all;
    line-height: 1.2;
}

/* Keypad */
.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.btn {
    aspect-ratio: 1/1;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    font-size: 1.2rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--btn-secondary);
    color: var(--text-primary);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    transform: scale(1.05);
    background: var(--glass-border);
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background: var(--btn-primary);
    color: var(--accent);
    font-size: 1.5rem;
}

.btn-secondary {
    color: var(--text-secondary);
}

.btn-accent {
    background: var(--btn-accent);
    color: var(--btn-text);
    font-weight: 600;
}

.btn-accent:hover {
    background: var(--accent-hover);
}

.btn-copy {
    color: var(--accent);
}

/* Scientific Mode */
.scientific-toggle {
    display: flex;
    justify-content: center;
}

#sci-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}

.scientific-keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    transition: all 0.3s ease;
}

.btn-sci {
    aspect-ratio: 2/1;
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.05);
}

.hidden {
    display: none;
}

/* History Panel */
.history-panel {
    position: fixed;
    right: -320px;
    top: 0;
    width: 320px;
    height: 100%;
    background: var(--glass-bg);
    backdrop-filter: blur(30px);
    border-left: 1px solid var(--glass-border);
    z-index: 100;
    padding: 24px;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.history-panel.open {
    right: 0;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.history-item {
    padding: 12px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:hover {
    background: rgba(0, 0, 0, 0.1);
}

.history-item .hist-exp {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.history-item .hist-res {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
}

.empty-msg {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 40px;
}

#clear-history {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
}

/* Footer */
.app-footer {
    padding: 20px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 480px) {
    .calculator-card {
        max-width: 100%;
        border-radius: 0;
        height: 100%;
        border: none;
    }
    
    .app-container {
        padding: 0;
    }
    
    .app-header {
        padding: 15px;
    }
}
