:root {
    --bg-gradient: linear-gradient(135deg, #0f172a, #1e1b4b);
    --calc-bg: rgba(255, 255, 255, 0.03);
    --calc-border: rgba(255, 255, 255, 0.08);
    --display-color: #f8fafc;
    --history-color: #94a3b8;
    
    --btn-bg: rgba(255, 255, 255, 0.05);
    --btn-bg-hover: rgba(255, 255, 255, 0.15);
    --btn-text: #e2e8f0;
    
    --btn-sci-bg: rgba(56, 189, 248, 0.08);
    --btn-sci-hover: rgba(56, 189, 248, 0.2);
    --btn-sci-text: #38bdf8;
    
    --btn-op-bg: rgba(244, 114, 182, 0.1);
    --btn-op-hover: rgba(244, 114, 182, 0.25);
    --btn-op-text: #f472b6;
    
    --btn-util-bg: rgba(251, 191, 36, 0.08);
    --btn-util-hover: rgba(251, 191, 36, 0.2);
    --btn-util-text: #fbbf24;
    
    --btn-eq-bg: #8b5cf6;
    --btn-eq-hover: #7c3aed;
    --btn-eq-text: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg-gradient);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Prevent bouncing on iOS */
    color: var(--display-color);
}

.calculator {
    width: 100vw;
    height: 100vh;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    padding: 24px;
    background: var(--calc-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--calc-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

@media (min-width: 450px) {
    .calculator {
        height: 85vh;
        border-radius: 40px;
    }
}

/* Display */
.display {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    padding: 20px 10px;
    word-break: break-all;
}

.display-history {
    font-family: 'Roboto Mono', monospace;
    font-size: 1.2rem;
    color: var(--history-color);
    margin-bottom: 8px;
    min-height: 1.5rem;
}

.display-current {
    font-family: 'Roboto Mono', monospace;
    font-size: 4rem;
    font-weight: 300;
    color: var(--display-color);
    letter-spacing: -2px;
    transition: font-size 0.2s;
}

/* Keypad Grid */
.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding-top: 20px;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 20px;
    font-size: 1.4rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--btn-bg);
    color: var(--btn-text);
    transition: all 0.15s ease;
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 70px;
}

@media (max-height: 800px) {
    .btn { height: 60px; font-size: 1.2rem; }
    .display-current { font-size: 3.2rem; }
}
@media (max-height: 650px) {
    .btn { height: 50px; border-radius: 15px; }
    .display-current { font-size: 2.5rem; }
    .keypad { gap: 8px; }
}

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

.btn-num {
    background: var(--btn-bg);
    font-size: 1.8rem;
}
.btn-num:hover { background: var(--btn-bg-hover); }

.span-2 {
    grid-column: span 2;
    border-radius: 20px;
}

.btn-sci {
    background: var(--btn-sci-bg);
    color: var(--btn-sci-text);
    font-size: 1.1rem;
    height: 50px;
    border-radius: 12px;
}
.btn-sci:hover { background: var(--btn-sci-hover); }

.btn-op {
    background: var(--btn-op-bg);
    color: var(--btn-op-text);
    font-size: 2rem;
    font-weight: 400;
}
.btn-op:hover { background: var(--btn-op-hover); }

.btn-util {
    background: var(--btn-util-bg);
    color: var(--btn-util-text);
    font-size: 1.2rem;
}
.btn-util:hover { background: var(--btn-util-hover); }

.btn-equals {
    background: var(--btn-eq-bg);
    color: var(--btn-eq-text);
    font-size: 2rem;
    box-shadow: 0 4px 14px 0 rgba(139, 92, 246, 0.39);
}
.btn-equals:hover { background: var(--btn-eq-hover); }

/* The Secret Button logic - look same as scientific, no special highlight */
.highlight-fmt {
    /* Looks identical to .btn-sci */
}

/* D-Pad Styles */
.btn-mock {
    font-size: 0.9rem;
    font-weight: 600;
}

.d-pad {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr; 
    background: var(--btn-bg);
    border-radius: 20px;
    height: 70px;
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.05);
    overflow: hidden;
}

@media (max-height: 800px) {
    .d-pad { height: 60px; }
}
@media (max-height: 650px) {
    .d-pad { height: 50px; border-radius: 15px; }
}

.d-btn {
    border: none; 
    background: transparent; 
    cursor: pointer; 
    color: var(--btn-text);
    font-size: 1rem;
    transition: background 0.1s;
}
.d-btn.up { grid-column: 2; grid-row: 1; }
.d-btn.down { grid-column: 2; grid-row: 2; }
.d-btn.left { grid-column: 1; grid-row: 1 / span 2; font-size: 0.8rem; }
.d-btn.right { grid-column: 3; grid-row: 1 / span 2; font-size: 0.8rem; }
.d-btn:active { background: rgba(255,255,255,0.15); }
.d-center { display: none; }

/* Inline Display Secrets */
.display-current.secret-math {
    /* Style specifically for when MathJax is injected inline */
    display: flex;
    justify-content: flex-end;
    align-items: center;
    color: #38bdf8;
    height: auto;
    font-size: 2.2rem !important; /* MathJax handles sizing, but restrict base font */
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 5px;
}

.display-current.secret-ans {
    color: #a78bfa;
    font-weight: 600;
}


/* Toast */
.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: #ef4444;
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 1rem;
    transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}
.toast.show {
    bottom: 40px;
}
