/* style.css */
:root {
    --bg-main: #ffffff;
    --bg-sidebar: #f5f5f7;
    --bg-card: rgba(245, 245, 247, 0.7);
    --text-main: #000000;
    --text-muted: #86868b;
    --accent: #6366f1;
    --danger: #ff3b30;
    --border-color: rgba(0, 0, 0, 0.1);
    --hover-color: #e5e5ea;
    --active-color: #d1d1d6;
    --dot-color: rgba(0, 0, 0, 0.05);
    --glow-color: rgba(99, 102, 241, 0.2);
    --btn-bg: rgba(99, 102, 241, 0.1);
    --btn-num-bg: #e5e5ea;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-main: #141416;
        --bg-sidebar: #08080a;
        --bg-card: rgba(30, 30, 34, 0.45);
        --text-main: #ffffff;
        --text-muted: #98989d;
        --accent: #818cf8;
        --danger: #ff453a;
        --border-color: rgba(255, 255, 255, 0.08);
        --hover-color: #2c2c2e;
        --active-color: #3a3a3c;
        --dot-color: rgba(255, 255, 255, 0.03);
        --glow-color: rgba(129, 140, 242, 0.25);
        --btn-bg: rgba(129, 140, 242, 0.15);
        --btn-num-bg: #2c2c2e;
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    color: var(--text-main);
    background-color: var(--bg-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

#loadingScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.6s ease, visibility 0.6s ease;
    overflow: hidden;
}

#loadingScreen h1 {
    font-size: 46px;
    font-weight: 700;
    letter-spacing: -1px;
    position: relative;
    z-index: 2;
    opacity: 0;
    animation: charmFade 2.2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    text-align: center;
    padding: 0 20px;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: 1;
    opacity: 0;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(168, 85, 247, 0.3));
    margin-right: 150px;
    margin-bottom: 100px;
    animation: blobFloat1 2.2s ease forwards;
}

.blob-2 {
    width: 350px;
    height: 350px;
    background: linear-gradient(135deg, rgba(129, 140, 242, 0.3), rgba(217, 70, 239, 0.3));
    margin-left: 200px;
    margin-top: 150px;
    animation: blobFloat2 2.2s ease forwards;
}

@keyframes charmFade {
    0% { opacity: 0; transform: translateY(20px) scale(0.95); }
    20% { opacity: 1; transform: translateY(0) scale(1); }
    80% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-10px) scale(1.05); }
}

@keyframes blobFloat1 {
    0% { opacity: 0; transform: scale(0.8) translate(-20px, -20px); }
    30% { opacity: 1; transform: scale(1.1) translate(0, 0); }
    80% { opacity: 1; transform: scale(1) translate(10px, 10px); }
    100% { opacity: 0; transform: scale(1.2) translate(20px, 20px); }
}

@keyframes blobFloat2 {
    0% { opacity: 0; transform: scale(0.8) translate(20px, 20px); }
    30% { opacity: 1; transform: scale(1.1) translate(0, 0); }
    80% { opacity: 1; transform: scale(1) translate(-10px, -10px); }
    100% { opacity: 0; transform: scale(1.2) translate(-20px, -20px); }
}

.hide-loader {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.sidebar {
    width: 280px;
    min-width: 250px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.35s ease;
}

.sidebar-brand {
    padding: 24px 20px 5px 20px;
}

.sidebar-brand h2 {
    font-size: 20px;
    font-weight: 600;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px 15px 20px;
}

.sidebar-header h3 {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-muted);
}

.clear-btn {
    background: rgba(255, 59, 48, 0.08);
    color: var(--danger);
    border: none;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.clear-btn:hover {
    background: var(--danger);
    color: white;
}

.history-container {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    flex: 1;
}

.history-item {
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;
}

.history-expr {
    color: var(--text-muted);
    font-size: 12px;
}

.history-res {
    font-weight: 600;
    color: var(--accent);
}

.editor {
    flex: 1;
    display: flex;
    padding: 40px;
    background-color: var(--bg-main);
    background-image: radial-gradient(var(--dot-color) 1.5px, transparent 1.5px);
    background-size: 32px 32px;
    justify-content: center;
    align-items: center;
}

.display-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    padding: 40px 50px;
    border-radius: 28px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.editor-header {
    display: flex;
    justify-content: flex-start; 
}

.editor-header button {
    background: transparent;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    padding: 10px 18px;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.back-btn {
    color: var(--accent);
    display: none;
}

.back-btn:hover {
    background: var(--btn-bg);
}

.calculator-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

#Display {
    font-size: 56px;
    font-weight: 700;
    letter-spacing: -1px;
    text-align: right;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    padding: 10px 0;
    color: var(--accent);
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.Button-Number, .Button-Operator, .Button-Equal {
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 20px;
    font-weight: 600;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1 / 1;
}

.Button-Number {
    background-color: var(--btn-num-bg);
    color: var(--text-main);
}

.Button-Number:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.Button-Operator {
    background-color: var(--btn-bg);
    color: var(--accent);
}

.Button-Operator:hover {
    background-color: var(--accent);
    color: #ffffff;
    transform: scale(1.05);
    box-shadow: 0 4px 15px var(--glow-color);
}

.Button-Equal {
    background-color: var(--accent);
    color: #ffffff;
    grid-column: 1 / -1;
    aspect-ratio: auto;
    padding: 16px;
}

.Button-Equal:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px var(--glow-color);
}

@media (max-width: 768px) {
    #loadingScreen h1 {
        font-size: 32px;
    }
    
    .blob-1, .blob-2 {
        width: 220px;
        height: 220px;
        filter: blur(50px);
    }
    
    .blob-1 {
        margin-right: 40px;
        margin-bottom: 60px;
    }

    .blob-2 {
        margin-left: 60px;
        margin-top: 80px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        z-index: 20;
        transform: translateX(-100%);
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }

    .container.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .editor {
        padding: 16px;
    }

    .display-card {
        padding: 24px;
        border-radius: 24px;
    }

    .back-btn {
        display: block;
    }

    #Display {
        font-size: 44px;
    }
}