/* ===== CSS VARIABLES ===== */
:root {
    /* Glassmorphism Colors */
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    
    /* Button Colors */
    --num-bg: rgba(255, 255, 255, 0.05);
    --num-hover: rgba(255, 255, 255, 0.15);
    --op-bg: rgba(245, 158, 11, 0.8);
    --op-hover: rgba(245, 158, 11, 1);
    --clear-bg: rgba(239, 68, 68, 0.8);
    --func-bg: rgba(148, 163, 184, 0.3);
    --equal-bg: rgba(16, 185, 129, 0.9);
    --sci-bg: rgba(139, 92, 246, 0.6);
    
    /* Text */
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    
    /* Sizing - COMPACT */
    --btn-size: clamp(48px, 12vw, 60px);
    --gap: clamp(6px, 1.5vw, 10px);
    --radius: 16px;
    --calculator-width: min(100%, 360px);
}

/* ===== RESET ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* ===== ANIMATED BACKGROUND ===== */
.bg-shapes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
}

.shape {
    position: absolute;
    filter: blur(50px);
    opacity: 0.6;
    animation: float 20s infinite ease-in-out;
}

.shape-1 {
    width: 300px;
    height: 300px;
    background: #ff6b6b;
    border-radius: 50%;
    top: -100px;
    left: -100px;
    animation-delay: 0s;
}

.shape-2 {
    width: 400px;
    height: 400px;
    background: #4ecdc4;
    border-radius: 50%;
    bottom: -150px;
    right: -150px;
    animation-delay: -5s;
}

.shape-3 {
    width: 200px;
    height: 200px;
    background: #ffe66d;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    animation-delay: -10s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -30px) scale(1.1); }
    66% { transform: translate(-20px, 20px) scale(0.9); }
}

/* ===== CALCULATOR CONTAINER ===== */
.calculator {
    position: relative;
    z-index: 1;
    width: var(--calculator-width);
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: clamp(12px, 3vw, 20px);
    box-shadow: var(--glass-shadow);
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    max-height: 95vh;
}

/* ===== DISPLAY ===== */
.display-glass {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: clamp(12px, 3vw, 16px);
    text-align: right;
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 4px;
}

.previous {
    color: var(--text-secondary);
    font-size: clamp(0.75rem, 2.5vw, 0.875rem);
    min-height: 18px;
    margin-bottom: 4px;
    font-weight: 500;
}

#display {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 2.5rem;
    font-weight: 300;
    text-align: right;
    outline: none;
    font-family: 'SF Mono', Monaco, monospace;
    transition: font-size 0.2s;
}

#display.pulse {
    animation: pulse 0.3s ease;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* ===== KEYPAD ===== */
.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--gap);
}

/* ===== BUTTONS ===== */
.btn {
    aspect-ratio: 1;
    min-height: var(--btn-size);
    border: none;
    border-radius: 12px;
    font-size: clamp(1.1rem, 4vw, 1.25rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 4px 6px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Neumorphic Press Effect */
.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.2s;
}

.btn:active {
    transform: scale(0.92);
    box-shadow: 
        inset 0 3px 5px rgba(0, 0, 0, 0.2),
        0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn:active::before {
    opacity: 1;
}

/* Button Types */
.btn-num {
    background: var(--num-bg);
}

.btn-num:hover {
    background: var(--num-hover);
    transform: translateY(-2px);
}

.btn-op {
    background: var(--op-bg);
    color: white;
    font-size: 1.5rem;
}

.btn-op:hover {
    background: var(--op-hover);
    transform: translateY(-2px);
}

.btn-clear {
    background: var(--clear-bg);
    color: white;
    font-size: 0.9rem;
}

.btn-clear:hover {
    background: rgba(239, 68, 68, 1);
}

.btn-func {
    background: var(--func-bg);
    font-size: 1rem;
}

.btn-func:hover {
    background: rgba(148, 163, 184, 0.5);
}

.btn-equal {
    background: var(--equal-bg);
    color: white;
    font-size: 1.5rem;
}

.btn-equal:hover {
    background: rgba(16, 185, 129, 1);
    transform: translateY(-2px);
}

.btn-zero {
    grid-column: span 2;
    aspect-ratio: 2 / 1;
}

/* ===== SCIENTIFIC PANEL ===== */
.scientific {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 90%;
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 10;
    pointer-events: none;
}

.scientific.show {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: all;
}

.btn-sci {
    background: var(--sci-bg);
    font-size: 0.9rem;
    aspect-ratio: 1.5 / 1;
}

.btn-sci:hover {
    background: rgba(139, 92, 246, 0.8);
}

/* ===== TOGGLE BUTTONS ===== */
.sci-toggle, .sound-toggle {
    position: fixed;
    z-index: 2;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
    box-shadow: var(--glass-shadow);
}

.sci-toggle {
    bottom: 20px;
    right: 20px;
}

.sci-toggle:hover {
    transform: scale(1.1) rotate(90deg);
    background: var(--op-bg);
}

.sound-toggle {
    bottom: 20px;
    left: 20px;
}

.sound-toggle:hover {
    transform: scale(1.1);
    background: var(--func-bg);
}

/* ===== RESPONSIVE ===== */

/* Very small phones */
@media (max-height: 700px) {
    :root {
        --btn-size: clamp(40px, 10vh, 50px);
        --gap: 6px;
    }
    
    .calculator {
        padding: 12px;
    }
    
    #display {
        font-size: 2rem;
    }
}

/* Landscape mode */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        align-items: flex-start;
        padding-top: 10px;
    }
    
    .calculator {
        flex-direction: row;
        max-width: 90vw;
        max-height: 90vh;
    }
    
    .display-glass {
        width: 40%;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .keypad {
        width: 60%;
        grid-template-columns: repeat(4, 1fr);
    }
    
    .sci-toggle, .sound-toggle {
        bottom: 10px;
    }
}

/* Large screens */
@media (min-width: 768px) {
    .calculator {
        max-width: 380px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .shape { animation: none; }
    .btn { transition: none; }
    .scientific { transition: opacity 0.2s; }
}

/* Dark mode support (system preference) */
@media (prefers-color-scheme: dark) {
    :root {
        --glass-bg: rgba(30, 41, 59, 0.7);
        --num-bg: rgba(255, 255, 255, 0.08);
    }
}