:root {
    /* Light Mode (Default) */
    --bg-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(0, 0, 0, 0.05);
    --glass-highlight: rgba(255, 255, 255, 0.4);
    
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent-color: #0284c7;
    --accent-glow: rgba(2, 132, 199, 0.2);
    
    --key-num-bg: #ffffff;
    --key-op-bg: rgba(2, 132, 199, 0.08);
    --key-util-bg: rgba(239, 68, 68, 0.08);
    --key-equal-bg: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    
    --radius-lg: 32px;
    --radius-md: 18px;
    --radius-sm: 10px;
    
    --font-main: 'Outfit', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    
    --panel-bg: rgba(255, 255, 255, 0.3);
    --keypad-bg: rgba(255, 255, 255, 0.5);
}

.dark-mode {
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.05);
    --glass-highlight: rgba(255, 255, 255, 0.05);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.3);
    
    --key-num-bg: rgba(255, 255, 255, 0.05);
    --key-op-bg: rgba(56, 189, 248, 0.1);
    --key-util-bg: rgba(248, 113, 113, 0.1);
    --key-equal-bg: linear-gradient(135deg, #38bdf8 0%, #2563eb 100%);

    --panel-bg: rgba(0, 0, 0, 0.1);
    --keypad-bg: rgba(0, 0, 0, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Calculator Container */
.calculator-container {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    height: 100vh;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* Display Panel */
.display-panel {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-grow: 1;
    min-height: 200px;
}

.mode-toggle {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    align-items: center;
}

.theme-btn {
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-btn:hover {
    background: var(--glass-highlight);
    color: var(--accent-color);
    transform: rotate(15deg);
}

.moon-icon { display: none; }
.dark-mode .sun-icon { display: none; }
.dark-mode .moon-icon { display: block !important; }

#toggle-scientific {
    background: var(--glass-highlight);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

#toggle-scientific.active {
    background: var(--accent-color);
    color: #000;
    font-weight: 600;
}

.history-log {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: right;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
}

.history-item {
    animation: fadeIn 0.3s ease;
}

.main-display {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: auto;
}

.input-line {
    font-size: 2.5rem;
    font-weight: 300;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}

.result-line {
    font-size: 1.5rem;
    color: var(--accent-color);
    min-height: 1.8rem;
    font-weight: 500;
}

.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.icon-btn:hover {
    color: var(--accent-color);
    background: var(--glass-highlight);
}

.toast {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--accent-color);
    color: #000;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Keypad Grid */
.keypad {
    padding: 24px;
    background: var(--keypad-bg);
    border-top: 1px solid var(--glass-border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.scientific-keys {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 12px;
    animation: slideDown 0.3s ease;
}

.basic-keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.calculator-container.scientific .scientific-keys {
    display: grid;
    gap: 8px;
    margin-bottom: 8px;
}

.calculator-container.scientific .basic-keys {
    gap: 8px;
}

.calculator-container.scientific .keypad {
    padding: 16px;
}

.calculator-container.scientific .display-panel {
    padding: 16px 20px;
    gap: 8px;
}

.calculator-container.scientific .key {
    aspect-ratio: 1.65;
    font-size: 1rem;
    border-radius: var(--radius-sm);
}

.calculator-container.scientific .key.zero {
    aspect-ratio: auto;
}

.calculator-container.scientific .history-log {
    min-height: 90px;
    flex-grow: 1;
}

.calculator-container.scientific .input-line {
    font-size: 1.85rem;
}

.calculator-container.scientific .result-line {
    font-size: 1.25rem;
}

.key {
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    font-family: var(--font-main);
    font-size: 1.25rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
}

.key:active {
    transform: scale(0.92);
    background: var(--glass-highlight);
}

.key.num { background: var(--key-num-bg); }
.key.operator { 
    background: var(--key-op-bg);
    color: var(--accent-color);
    font-size: 1.5rem;
}
.key.util { 
    background: var(--key-util-bg);
    color: #f87171;
}
.key.equal {
    background: var(--key-equal-bg);
    box-shadow: 0 8px 20px var(--accent-glow);
    border: none;
    color: #fff;
}
.key.func {
    background: var(--glass-bg);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.key.zero {
    grid-column: span 2;
    aspect-ratio: auto;
}

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

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

/* Responsiveness & Embedding */
@media (max-width: 480px) {
    .calculator-container {
        max-width: 100%;
        height: 100vh;
        border-radius: 0;
    }
}

/* Compact Mode for Keyboard Embedding */
.calculator-container.compact {
    height: 100%;
    max-height: none;
}

.calculator-container.compact .display-panel {
    padding: 12px;
    min-height: 120px;
}

.calculator-container.compact .input-line {
    font-size: 1.8rem;
}

.calculator-container.compact .keypad {
    padding: 12px;
}

.calculator-container.compact .key {
    gap: 8px;
}
