/* ==========================================================================
   Midnight Aurora Theme Stylesheet
   ========================================================================== */

:root {
    --bg-color: #05050A;
    --oled-black: #080810;
    --text-white: #FFFFFF;
    --text-muted: #8E8E9F;
    --neon-cyan: #00E5FF;
    --neon-magenta: #FF007F;
    --neon-purple: #9C27B0;
    --neon-orange: #FF6D00;
    --neon-red: #FF3B30;
    
    /* Dynamic Theme variables fallbacks (Midnight Aurora) */
    --primary-neon: #00E5FF;
    --secondary-neon: #FF007F;
    --accent-neon: #9C27B0;
    --font-family: 'Plus Jakarta Sans', sans-serif;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: 1px solid rgba(255, 255, 255, 0.08);
    --btn-bg: rgba(255, 255, 255, 0.06);
    --btn-border: 1px solid rgba(255, 255, 255, 0.12);
    
    /* Interactive variables updated via JS */
    --mouse-x: 50%;
    --mouse-y: 50%;
    --glow-strength: 0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-family, 'Plus Jakarta Sans'), sans-serif;
    user-select: none;
    -webkit-user-select: none;
    transition: font-family 0.4s ease;
}

body {
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* ==========================================================================
   1. Interactive Blending Background
   ========================================================================== */

@keyframes slowHueShift {
    0% {
        filter: hue-rotate(0deg);
    }
    100% {
        filter: hue-rotate(360deg);
    }
}

.aurora-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--oled-black);
    z-index: 1;
    overflow: hidden;
    animation: slowHueShift 180s infinite linear;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(140px);
    opacity: 0.45;
    mix-blend-mode: screen;
    pointer-events: none;
    transition: transform 0.8s cubic-bezier(0.1, 0.8, 0.2, 1);
}

.blob-cyan {
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, var(--neon-cyan) 0%, rgba(0, 229, 255, 0) 70%);
    top: -10vw;
    left: -10vw;
    animation: float-cyan 22s infinite alternate ease-in-out;
}

.blob-magenta {
    width: 70vw;
    height: 70vw;
    background: radial-gradient(circle, var(--neon-magenta) 0%, rgba(255, 0, 127, 0) 70%);
    top: -15vw;
    right: -15vw;
    animation: float-magenta 28s infinite alternate ease-in-out;
}

.blob-purple {
    width: 65vw;
    height: 65vw;
    background: radial-gradient(circle, var(--neon-purple) 0%, rgba(156, 39, 176, 0) 70%);
    bottom: -15vw;
    left: 20vw;
    animation: float-purple 25s infinite alternate ease-in-out;
}

/* Vignette Shadow Overlay */
.vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, transparent 20%, rgba(5, 5, 10, 0.75) 80%);
    z-index: 2;
    pointer-events: none;
}

/* Background Drift Animation Keyframes */
@keyframes float-cyan {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(10%, 15%) scale(1.1); }
    100% { transform: translate(-5%, -5%) scale(0.9); }
}

@keyframes float-magenta {
    0% { transform: translate(0, 0) scale(1.05); }
    50% { transform: translate(-15%, 10%) scale(0.95); }
    100% { transform: translate(5%, -10%) scale(1.1); }
}

@keyframes float-purple {
    0% { transform: translate(0, 0) scale(0.9); }
    50% { transform: translate(8%, -15%) scale(1.05); }
    100% { transform: translate(-10%, 5%) scale(1); }
}

/* Dynamic Interactive Attraction glow overlay */
body::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle 200px at var(--mouse-x) var(--mouse-y), rgba(0, 229, 255, 0.15) 0%, transparent 80%);
    z-index: 2;
    pointer-events: none;
    opacity: var(--glow-strength);
    transition: opacity 0.5s ease;
}

/* ==========================================================================
   2. Main Calculator Layout
   ========================================================================== */

.calculator {
    width: 100%;
    max-width: 395px;
    height: 780px;
    background: var(--card-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-radius: 36px;
    border: var(--card-border);
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.5),
                inset 0 1px 0 rgba(255, 255, 255, 0.15);
    z-index: 10;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    padding: 12px;
    transition: background 0.6s ease, border 0.6s ease, box-shadow 0.6s ease;
}

/* ==========================================================================
   3. Swipeable History Drawer
   ========================================================================== */

.history-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 360px;
    background: rgba(8, 8, 16, 0.95);
    border-radius: 0 0 32px 32px;
    border-bottom: 1.5px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateY(-370px);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.15);
    padding: 20px 20px 8px 20px;
}

.history-panel.expanded {
    transform: translateY(0);
}

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

.history-header h3 {
    color: var(--text-white);
    font-size: 1.2rem;
    font-weight: 700;
}

.history-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.3s, color 0.3s;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

#clearHistoryBtn:hover {
    color: var(--neon-orange);
}

#closeHistoryBtn:hover {
    color: var(--neon-cyan);
}

.history-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 12px 0;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 4px;
}

/* Spacer pseudo-element to guarantee scrolling clearance above the handle bar in all browsers */
.history-list::after {
    content: '';
    display: block;
    height: 36px;
    flex-shrink: 0;
}

/* Custom History Scrollbar */
.history-list::-webkit-scrollbar {
    width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.empty-history {
    color: var(--text-muted);
    font-size: 0.95rem;
    text-align: center;
    margin: auto 0;
    line-height: 1.5;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid transparent;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    flex-shrink: 0; /* Prevent compression of items when history list grows long */
}

.history-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(80px circle at var(--item-x, 0px) var(--item-y, 0px), rgba(255, 255, 255, 0.07), transparent 80%);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 1;
}

.history-item:hover::before {
    opacity: 1;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(0, 229, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.history-item:active {
    transform: scale(0.98) translateY(0);
}

.history-meta,
.history-values {
    position: relative;
    z-index: 2;
}

.history-meta {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.history-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: monospace;
}

.history-badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-block;
}

/* 16 Achievement Badges */
.history-badge-jackpot {
    background: rgba(0, 255, 102, 0.12);
    color: #00FF66;
    border: 1px solid rgba(0, 255, 102, 0.3);
    box-shadow: 0 0 8px rgba(0, 255, 102, 0.2);
}
.history-item.item-jackpot { border-left: 3px solid #00FF66; }

.history-badge-cosmic {
    background: rgba(0, 255, 255, 0.12);
    color: #00FFFF;
    border: 1px solid rgba(0, 255, 255, 0.3);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.2);
}
.history-item.item-cosmic { border-left: 3px solid #00FFFF; }

.history-badge-infernal {
    background: rgba(255, 59, 48, 0.12);
    color: #FF3B30;
    border: 1px solid rgba(255, 59, 48, 0.3);
    box-shadow: 0 0 8px rgba(255, 59, 48, 0.2);
}
.history-item.item-infernal { border-left: 3px solid #FF3B30; }

.history-badge-nice {
    background: rgba(255, 0, 127, 0.12);
    color: #FF007F;
    border: 1px solid rgba(255, 0, 127, 0.3);
    box-shadow: 0 0 8px rgba(255, 0, 127, 0.2);
}
.history-item.item-nice { border-left: 3px solid #FF007F; }

.history-badge-blaze {
    background: rgba(76, 175, 80, 0.12);
    color: #4CAF50;
    border: 1px solid rgba(76, 175, 80, 0.3);
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.2);
}
.history-item.item-blaze { border-left: 3px solid #4CAF50; }

.history-badge-unlucky {
    background: rgba(156, 39, 176, 0.12);
    color: #E040FB;
    border: 1px solid rgba(156, 39, 176, 0.3);
    box-shadow: 0 0 8px rgba(156, 39, 176, 0.2);
}
.history-item.item-unlucky { border-left: 3px solid #E040FB; }

.history-badge-pi {
    background: rgba(33, 150, 243, 0.12);
    color: #2196F3;
    border: 1px solid rgba(33, 150, 243, 0.3);
    box-shadow: 0 0 8px rgba(33, 150, 243, 0.2);
}
.history-item.item-pi { border-left: 3px solid #2196F3; }

.history-badge-golden {
    background: rgba(255, 193, 7, 0.12);
    color: #FFC107;
    border: 1px solid rgba(255, 193, 7, 0.3);
    box-shadow: 0 0 8px rgba(255, 193, 7, 0.2);
}
.history-item.item-golden { border-left: 3px solid #FFC107; }

.history-badge-euler {
    background: rgba(233, 30, 99, 0.12);
    color: #E91E63;
    border: 1px solid rgba(233, 30, 99, 0.3);
    box-shadow: 0 0 8px rgba(233, 30, 99, 0.2);
}
.history-item.item-euler { border-left: 3px solid #E91E63; }

.history-badge-gravity {
    background: rgba(142, 142, 159, 0.12);
    color: #D1D1D6;
    border: 1px solid rgba(142, 142, 159, 0.3);
    box-shadow: 0 0 8px rgba(142, 142, 159, 0.2);
}
.history-item.item-gravity { border-left: 3px solid #D1D1D6; }

.history-badge-light {
    background: rgba(255, 255, 255, 0.15);
    color: #FFFFFF;
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}
.history-item.item-light { border-left: 3px solid #FFFFFF; }

.history-badge-binary {
    background: rgba(0, 230, 118, 0.12);
    color: #00E676;
    border: 1px solid rgba(0, 230, 118, 0.3);
    box-shadow: 0 0 8px rgba(0, 230, 118, 0.2);
}
.history-item.item-binary { border-left: 3px solid #00E676; }

.history-badge-angel {
    background: rgba(255, 235, 59, 0.12);
    color: #FFEE58;
    border: 1px solid rgba(255, 235, 59, 0.3);
    box-shadow: 0 0 8px rgba(255, 235, 59, 0.2);
}
.history-item.item-angel { border-left: 3px solid #FFEE58; }

.history-badge-grand {
    background: rgba(255, 215, 0, 0.15);
    color: #FFD700;
    border: 1px solid rgba(255, 215, 0, 0.4);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}
.history-item.item-grand { border-left: 3px solid #FFD700; }

.history-badge-abyss {
    background: rgba(63, 81, 181, 0.12);
    color: #5C6BC0;
    border: 1px solid rgba(63, 81, 181, 0.3);
    box-shadow: 0 0 8px rgba(63, 81, 181, 0.2);
}
.history-item.item-abyss { border-left: 3px solid #5C6BC0; }

.history-badge-void {
    background: rgba(33, 33, 33, 0.2);
    color: #B0BEC5;
    border: 1px solid rgba(176, 190, 197, 0.3);
    box-shadow: 0 0 8px rgba(176, 190, 197, 0.1);
}
.history-item.item-void { border-left: 3px solid #B0BEC5; }

.history-values {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex: 1;
    min-width: 0;
    margin-left: 12px;
}

.history-eq {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: right;
    width: 100%;
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: normal;
    line-height: 1.2;
}

.history-res {
    color: var(--neon-cyan);
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 2px;
    width: 100%;
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: normal;
    line-height: 1.2;
}

.history-item.item-exit {
    animation: historyItemExit 0.25s cubic-bezier(0.4, 0, 1, 1) forwards !important;
}

@keyframes historyItemExit {
    0% {
        opacity: 1;
        transform: translateX(0) scale(1);
        max-height: 80px;
        margin-bottom: 16px;
        padding: 10px 12px;
        border-color: rgba(255, 255, 255, 0.05);
    }
    100% {
        opacity: 0;
        transform: translateX(50px) scale(0.9);
        max-height: 0;
        margin-bottom: 0;
        padding: 0 12px;
        border-color: transparent;
    }
}

.history-item-delete {
    opacity: 0;
    transform: translateX(-10px);
    background: rgba(255, 59, 48, 0.1);
    color: var(--neon-red);
    border: 1px solid rgba(255, 59, 48, 0.2);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.history-item:hover .history-item-delete {
    opacity: 1;
    transform: translateX(0);
}

.history-item-delete:hover {
    background: var(--neon-red);
    color: var(--text-white);
    border-color: var(--neon-red);
    box-shadow: 0 0 8px rgba(255, 59, 48, 0.4);
}

@keyframes historySlideIn {
    0% {
        opacity: 0;
        transform: translateY(15px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.history-handle-trigger {
    width: 100%;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    margin-top: 4px;
}

.handle-bar {
    width: 48px;
    height: 5px;
    background: rgba(0, 229, 255, 0.4);
    border-radius: 10px;
    transition: background 0.3s;
}

.history-handle-trigger:hover .handle-bar {
    background: rgba(0, 229, 255, 0.7);
}

/* ==========================================================================
   4. Display Viewport
   ========================================================================== */

.display-container {
    flex: 1.2;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    padding: 24px 20px 16px 20px;
    position: relative;
    cursor: grab;
}

.display-container:active {
    cursor: grabbing;
}

/* Top down swipe hint helper */
.drag-indicator {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.15);
    font-size: 0.75rem;
    letter-spacing: 1px;
    pointer-events: none;
    transition: color 0.3s;
}

.display-container:hover .drag-indicator {
    color: rgba(0, 229, 255, 0.4);
}

.equation-view {
    color: var(--text-muted);
    font-size: 1.5rem;
    font-weight: 400;
    text-align: right;
    min-height: 2.2rem;
    width: 100%;
    word-break: break-all;
    margin-bottom: 8px;
    opacity: 1;
    transition: opacity 0.25s, transform 0.25s;
}

.result-view {
    font-size: 3.8rem;
    font-weight: 600;
    text-align: right;
    width: 100%;
    word-break: break-all;
    min-height: 4.5rem;
    color: var(--text-white);
    
    transition: font-size 0.2s cubic-bezier(0.175, 0.885, 0.32, 1),
                text-shadow 0.3s ease;
}

@keyframes textGradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Decaying Error Shaker & Glow Alert */
.shake {
    animation: shake-decay 0.5s cubic-bezier(.36,.07,.19,.97) both;
    transform: translate3d(0, 0, 0);
}

.display-container.error-glow .result-view {
    filter: drop-shadow(0 0 12px rgba(255, 59, 48, 0.7));
}

.display-container.error-glow .result-view .char-span {
    background: linear-gradient(to right, var(--neon-red), #FF8A80) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
}

@keyframes shake-decay {
    10%, 90% { transform: translate3d(-12px, 0, 0); }
    20%, 80% { transform: translate3d(10px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* ==========================================================================
   5. Keypad Grid & Glass Buttons
   ========================================================================== */

.keypad {
    flex: 2;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 8px 12px 16px 12px;
}

.btn {
    border: none;
    outline: none;
    border-radius: 20px;
    font-size: 1.65rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--btn-bg);
    border: var(--btn-border);
    color: var(--text-white);
    display: flex;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1;
    
    /* Physics Bouncy Spring press scale */
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.3),
                background 0.3s,
                box-shadow 0.3s,
                border-color 0.3s,
                color 0.4s ease;
}

/* Hover States for Glass buttons */
.btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
}

/* spring compression on click */
.btn:active {
    transform: scale(0.92);
}

/* Operators (Breathing Neon Cyan/Purple) */
.btn-operator {
    color: var(--neon-cyan);
    background: rgba(0, 229, 255, 0.05);
    border: 1.5px solid rgba(0, 229, 255, 0.25);
    animation: neonBreatheCyan 3.5s infinite alternate ease-in-out;
}

.btn-operator:hover {
    background: rgba(0, 229, 255, 0.12);
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.2);
}

@keyframes neonBreatheCyan {
    0% {
        border-color: rgba(0, 229, 255, 0.2);
        box-shadow: 0 0 5px rgba(0, 229, 255, 0.05);
    }
    100% {
        border-color: rgba(156, 39, 176, 0.5); /* shift to purple border */
        box-shadow: 0 0 18px rgba(0, 229, 255, 0.15);
    }
}

/* Clearing & Backspace Actions (Breathing Neon Orange) */
.btn-secondary {
    color: var(--neon-orange);
    background: rgba(255, 109, 0, 0.05);
    border: 1.5px solid rgba(255, 109, 0, 0.25);
    animation: neonBreatheOrange 3.5s infinite alternate ease-in-out;
}

.btn-secondary:hover {
    background: rgba(255, 109, 0, 0.12);
    box-shadow: 0 0 15px rgba(255, 109, 0, 0.2);
}

@keyframes neonBreatheOrange {
    0% {
        border-color: rgba(255, 109, 0, 0.2);
        box-shadow: 0 0 5px rgba(255, 109, 0, 0.05);
    }
    100% {
        border-color: rgba(255, 0, 127, 0.5); /* shift to magenta */
        box-shadow: 0 0 18px rgba(255, 109, 0, 0.15);
    }
}

/* Equals Key (Vivid Aurora Gradient) */
.btn-primary {
    background: linear-gradient(135deg, var(--neon-orange), var(--neon-magenta));
    border: none;
    color: var(--text-white);
    box-shadow: 0 10px 25px rgba(255, 0, 127, 0.35),
                inset 0 1px 0 rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    box-shadow: 0 12px 30px rgba(255, 0, 127, 0.5),
                0 0 20px rgba(255, 109, 0, 0.2);
}

/* Mobile Screen Adaptation sizing */
@media (max-height: 700px) {
    .calculator {
        height: 680px;
    }
    .btn {
        font-size: 1.4rem;
        border-radius: 16px;
    }
    .result-view {
        font-size: 3.2rem;
    }
}

/* Deletion & Clear Smooth Animations */
.clear-active {
    animation: clearWipe 0.18s cubic-bezier(0.445, 0.05, 0.55, 0.95) both;
}

@keyframes clearWipe {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
        filter: blur(0);
    }
    45% {
        transform: translateY(10px) scale(0.96);
        opacity: 0;
        filter: blur(2px);
    }
    55% {
        transform: translateY(-10px) scale(0.96);
        opacity: 0;
        filter: blur(2px);
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
        filter: blur(0);
    }
}

/* Character Span Animations */
.char-span {
    display: inline-block;
    max-width: 60px;
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    white-space: pre;
    vertical-align: bottom;
    overflow: hidden;
    transition: max-width 0.12s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.12s ease,
                transform 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275);
                
    /* Premium Shifting Chrome Gradient Brush applied to spans to prevent inline-block transparent clipping bugs */
    background: linear-gradient(120deg, var(--text-white), var(--primary-neon), var(--text-muted), var(--text-white));
    background-size: 400% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: textGradientShift 8s infinite alternate ease-in-out;
}

.char-enter {
    animation: charEnter 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes charEnter {
    0% {
        opacity: 0;
        transform: translateY(-6px) scale(0.8);
        max-width: 0;
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        max-width: 60px;
    }
}

.char-exit {
    animation: charExit 0.12s cubic-bezier(0.4, 0, 1, 1) forwards;
    pointer-events: none;
}

@keyframes charExit {
    0% {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
        max-width: 60px;
    }
    100% {
        opacity: 0;
        transform: translate3d(15px, 0, 0) scale(0.5);
        max-width: 0;
        padding: 0;
        margin: 0;
    }
}

/* ==========================================================================
   Gravity and Zero-G Interactive Elements
   ========================================================================== */

.gravity-controls {
    position: absolute;
    top: 14px;
    left: 16px;
    display: flex;
    gap: 8px;
    z-index: 110;
    pointer-events: auto !important;
}

.gravity-btn {
    pointer-events: auto !important;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 6px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.gravity-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(0, 229, 255, 0.25);
    color: var(--text-white);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 229, 255, 0.15);
}

.gravity-btn:active {
    transform: translateY(1px);
}

.gravity-btn.active-zerog {
    background: rgba(0, 229, 255, 0.1);
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.35);
    animation: neonPulseCyan 2s infinite alternate ease-in-out;
}

.gravity-btn.active-gravitate {
    background: rgba(255, 109, 0, 0.1);
    border-color: var(--neon-orange);
    color: var(--neon-orange);
    box-shadow: 0 0 12px rgba(255, 109, 0, 0.35);
    animation: neonPulseOrange 2s infinite alternate ease-in-out;
}

@keyframes neonPulseCyan {
    0% {
        box-shadow: 0 0 4px rgba(0, 229, 255, 0.2);
        border-color: rgba(0, 229, 255, 0.6);
    }
    100% {
        box-shadow: 0 0 14px rgba(0, 229, 255, 0.5);
        border-color: var(--neon-cyan);
    }
}

@keyframes neonPulseOrange {
    0% {
        box-shadow: 0 0 4px rgba(255, 109, 0, 0.2);
        border-color: rgba(255, 109, 0, 0.6);
    }
    100% {
        box-shadow: 0 0 14px rgba(255, 109, 0, 0.5);
        border-color: var(--neon-orange);
    }
}

/* Disable transitions when physics loop updates style.transform in real-time */
.char-span.physics-active {
    transition: max-width 0.12s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.12s ease !important;
}
.btn.physics-active {
    transition: background 0.3s, box-shadow 0.3s, border-color 0.3s, color 0.4s ease !important;
}

/* ==========================================================================
   New Themes and Interactive Visual Effects Addition
   ========================================================================== */

#particleCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
}

/* Base body dynamic variables adjustment */
body {
    background-color: var(--bg-color);
    transition: background-color 0.8s ease;
}

/* Background Effect Overlays (hidden by default, shown based on theme) */
.theme-bg-effect {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
    z-index: 2;
}

/* Themes declarations */
body.theme-midnight {
    --bg-color: #05050A;
    --oled-black: #080810;
    --text-white: #FFFFFF;
    --text-muted: #8E8E9F;
    --primary-neon: #00E5FF;
    --secondary-neon: #FF007F;
    --accent-neon: #9C27B0;
    --font-family: 'Plus Jakarta Sans', sans-serif;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: 1px solid rgba(255, 255, 255, 0.08);
    --btn-bg: rgba(255, 255, 255, 0.06);
    --btn-border: 1px solid rgba(255, 255, 255, 0.12);
}

body.theme-cyberpunk {
    --bg-color: #020205;
    --oled-black: #080812;
    --text-white: #39FF14;
    --text-muted: #008F11;
    --primary-neon: #39FF14;
    --secondary-neon: #00FFFF;
    --accent-neon: #FFFF00;
    --font-family: 'Orbitron', monospace;
    --card-bg: rgba(0, 0, 0, 0.8);
    --card-border: 1.5px solid #39FF14;
    --btn-bg: rgba(57, 255, 20, 0.04);
    --btn-border: 1px solid rgba(57, 255, 20, 0.25);
}
body.theme-cyberpunk .btn {
    text-shadow: 0 0 5px var(--primary-neon);
}
body.theme-cyberpunk .cyberpunk-hud {
    opacity: 0.05;
    background: radial-gradient(circle, transparent 40%, rgba(57, 255, 20, 0.3) 100%),
                linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
                linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 100%, 100% 4px, 6px 100%;
}

body.theme-sakura {
    --bg-color: #FFEAEF;
    --oled-black: #FFF0F3;
    --text-white: #5D2E3C;
    --text-muted: #B88E9A;
    --primary-neon: #FF69B4;
    --secondary-neon: #FFB6C1;
    --accent-neon: #FFC0CB;
    --font-family: 'Plus Jakarta Sans', sans-serif;
    --card-bg: rgba(255, 255, 255, 0.55);
    --card-border: 1px solid rgba(255, 105, 180, 0.25);
    --btn-bg: rgba(255, 255, 255, 0.65);
    --btn-border: 1px solid rgba(255, 105, 180, 0.15);
}
body.theme-sakura .blob-cyan { background: radial-gradient(circle, #FFB6C1 0%, rgba(255,182,193,0) 70%) !important; }
body.theme-sakura .blob-magenta { background: radial-gradient(circle, #FFE4E1 0%, rgba(255,228,225,0) 70%) !important; }
body.theme-sakura #sakuraPetals {
    opacity: 1;
}

body.theme-matrix {
    --bg-color: #000200;
    --oled-black: #000600;
    --text-white: #00FF41;
    --text-muted: #008000;
    --primary-neon: #00FF41;
    --secondary-neon: #00FF41;
    --accent-neon: #003B00;
    --font-family: 'Courier New', monospace;
    --card-bg: rgba(0, 4, 0, 0.9);
    --card-border: 1.5px solid #00FF41;
    --btn-bg: rgba(0, 255, 65, 0.03);
    --btn-border: 1px solid rgba(0, 255, 65, 0.3);
}
body.theme-matrix #matrixCanvas {
    opacity: 0.18;
}
body.theme-matrix .result-view, body.theme-matrix .equation-view {
    text-shadow: 0 0 10px #00FF41;
}

body.theme-synthwave {
    --bg-color: #0A001F;
    --oled-black: #04000C;
    --text-white: #FFD700;
    --text-muted: #BC39E5;
    --primary-neon: #FF007F;
    --secondary-neon: #FF6D00;
    --accent-neon: #00FFFF;
    --font-family: 'Orbitron', monospace;
    --card-bg: rgba(10, 0, 31, 0.75);
    --card-border: 1.5px solid var(--primary-neon);
    --btn-bg: rgba(255, 0, 127, 0.04);
    --btn-border: 1px solid rgba(255, 0, 127, 0.25);
}
body.theme-synthwave .synthwave-sunset {
    opacity: 0.35;
    background: radial-gradient(circle at 50% 30%, #FF6D00 0%, #FF007F 30%, rgba(13,2,33,0) 70%);
}
body.theme-synthwave .retro-grid {
    opacity: 0.15;
    background-image: 
        linear-gradient(rgba(255, 0, 127, 0.3) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 0, 127, 0.3) 1px, transparent 1px);
    background-size: 40px 40px;
    transform: perspective(500px) rotateX(60deg);
    transform-origin: top;
    height: 150%;
    top: 0;
}

/* Sliding Theme Panel styling */
.theme-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 380px;
    background: rgba(8, 8, 16, 0.96);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border-radius: 32px 32px 0 0;
    border-top: 1.5px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.7);
    z-index: 120;
    display: flex;
    flex-direction: column;
    transform: translateY(390px);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.15);
    padding: 24px;
}
.theme-panel.expanded {
    transform: translateY(0);
}
.theme-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.theme-header h3 {
    color: var(--text-white);
    font-size: 1.25rem;
    font-weight: 700;
}
.theme-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 16px 0;
}
.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    overflow-y: auto;
}
.theme-option {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    color: var(--text-white);
    padding: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.25s ease;
}
.theme-option:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary-neon);
    transform: translateY(-2px);
}
.theme-option.active {
    background: rgba(0, 229, 255, 0.08);
    border-color: var(--primary-neon);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}
.theme-preview {
    width: 44px;
    height: 24px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}
.preview-midnight { background: linear-gradient(135deg, #00E5FF, #FF007F); }
.preview-cyberpunk { background: linear-gradient(135deg, #39FF14, #00FFFF); }
.preview-sakura { background: linear-gradient(135deg, #FF69B4, #FFEAEF); }
.preview-matrix { background: linear-gradient(135deg, #00FF41, #000000); }
.preview-synthwave { background: linear-gradient(135deg, #FF007F, #FF6D00); }

/* Sakura Petals Animation */
.petal {
    position: absolute;
    background-color: #FFB6C1;
    border-radius: 150px 0 150px 150px;
    opacity: 0.75;
    pointer-events: none;
    z-index: 3;
    animation: fadeAndFall 10s infinite linear;
}

@keyframes fadeAndFall {
    0% {
        transform: translate(0, -10px) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.85;
    }
    90% {
        opacity: 0.85;
    }
    100% {
        transform: translate(120px, 100vh) rotate(360deg);
        opacity: 0;
    }
}

/* Black Hole Vortex anomaly overlay styles */
.black-hole-vortex {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, #000 0%, #000 30%, transparent 70%);
    opacity: 0;
    transform: scale(0);
    z-index: 1000;
    pointer-events: none;
    transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.6, -0.28, 0.735, 0.045);
}
.black-hole-active {
    opacity: 1 !important;
    transform: scale(1.5) !important;
}
.vortex-spin {
    animation: vortex-spin-animation 1.5s infinite linear;
}
@keyframes vortex-spin-animation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(-360deg); }
}
.sucked-char {
    transition: transform 0.8s cubic-bezier(0.6, -0.28, 0.735, 0.045), opacity 0.8s ease, scale 0.8s ease !important;
    transform: translate(var(--suck-x), var(--suck-y)) rotate(360deg) scale(0) !important;
    opacity: 0 !important;
}

/* Sound button toggle states active styling */
.gravity-btn.active-sound {
    border-color: #FFEE58;
    color: #FFEE58;
    box-shadow: 0 0 10px rgba(255, 238, 88, 0.35);
}

/* Space Theme definitions */
body.theme-space {
    --bg-color: #020208;
    --oled-black: #04040e;
    --text-white: #E0E0FF;
    --text-muted: #6C5CE7;
    --primary-neon: #a29bfe; /* soft indigo */
    --secondary-neon: #00cec9; /* soft teal */
    --accent-neon: #fd79a8; /* pink */
    --font-family: 'Orbitron', sans-serif;
    --card-bg: rgba(2, 2, 8, 0.7);
    --card-border: 1px solid rgba(162, 155, 254, 0.3);
    --btn-bg: rgba(162, 155, 254, 0.04);
    --btn-border: 1px solid rgba(162, 155, 254, 0.15);
}
body.theme-space #spaceStarsCanvas {
    opacity: 1;
}
body.theme-space .blob-cyan { background: radial-gradient(circle, #00cec9 0%, rgba(0, 206, 201, 0) 70%) !important; }
body.theme-space .blob-magenta { background: radial-gradient(circle, #fd79a8 0%, rgba(253, 121, 168, 0) 70%) !important; }
body.theme-space .blob-purple { background: radial-gradient(circle, #6c5ce7 0%, rgba(108, 92, 231, 0) 70%) !important; }

.preview-space {
    background: linear-gradient(135deg, #6C5CE7, #00cec9);
}

/* Equals button long-press interactive styling */
.btn[data-key="="].holding {
    transform: scale(1.15) !important;
    filter: brightness(1.2) !important;
    box-shadow: 0 0 25px var(--neon-magenta), inset 0 1px 0 rgba(255, 255, 255, 0.4) !important;
    transition: transform 0.8s linear, box-shadow 0.8s linear, filter 0.8s linear !important;
}

.btn[data-key="="].activated {
    transform: scale(0.9) !important;
    filter: brightness(1.4) !important;
    box-shadow: 0 0 35px var(--neon-cyan), inset 0 1px 0 rgba(255, 255, 255, 0.5) !important;
    transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease !important;
}
