/* --- General Styles & Variables --- */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;700&display=swap');

:root {
    --bg-color-light: #e0e0e0;
    --primary-light: #d1d1d1;
    --secondary-light: #f5f5f5;
    --text-color-light: #333;
    --shadow-light-1: #ffffff;
    --shadow-light-2: #bebebe;

    --bg-color-dark: #2c2c2c;
    --primary-dark: #252525;
    --secondary-dark: #3a3a3a;
    --text-color-dark: #f0f0f0;
    --shadow-dark-1: #383838;
    --shadow-dark-2: #202020;

    --bg-color: var(--bg-color-light);
    --primary: var(--primary-light);
    --secondary: var(--secondary-light);
    --text-color: var(--text-color-light);
    --shadow-1: var(--shadow-light-1);
    --shadow-2: var(--shadow-light-2);
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    transition: background-color 0.3s ease;
}

body.dark-mode {
    --bg-color: var(--bg-color-dark);
    --primary: var(--primary-dark);
    --secondary: var(--secondary-dark);
    --text-color: var(--text-color-dark);
    --shadow-1: var(--shadow-dark-1);
    --shadow-2: var(--shadow-dark-2);
}

/* --- Calculator Container --- */
.calculator-container {
    width: 100%;
    max-width: 340px;
    padding: 25px;
    border-radius: 30px;
    background: var(--bg-color);
    box-shadow: 10px 10px 20px var(--shadow-2), -10px -10px 20px var(--shadow-1);
    transition: max-width 0.4s ease-in-out;
}

/* --- Header & Toggles --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.toggle-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-color);
    background: var(--bg-color);
    box-shadow: 5px 5px 10px var(--shadow-2), -5px -5px 10px var(--shadow-1);
    transition: all 0.2s ease-in-out;
}

.toggle-btn:active, .toggle-btn.active {
    box-shadow: inset 5px 5px 10px var(--shadow-2), inset -5px -5px 10px var(--shadow-1);
}

/* --- Display --- */
.display {
    width: 100%;
    height: 90px;
    margin-bottom: 20px;
    border-radius: 20px;
    background: var(--primary);
    box-shadow: inset 8px 8px 15px var(--shadow-2), inset -8px -8px 15px var(--shadow-1);
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: flex-end;
    padding: 10px 20px;
    box-sizing: border-box;
    word-wrap: break-word;
    word-break: break-all;
    color: var(--text-color);
    overflow: hidden;
}

#previous-operand {
    font-size: 1.2rem;
    opacity: 0.7;
    min-height: 20px;
}

#current-operand {
    font-size: 2.5rem;
    font-weight: bold;
    min-height: 40px;
}

/* --- Buttons Grid --- */
.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
}

.btn {
    height: 65px;
    border-radius: 15px;
    border: none;
    background: var(--bg-color);
    box-shadow: 5px 5px 10px var(--shadow-2), -5px -5px 10px var(--shadow-1);
    font-size: 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover {
    box-shadow: 7px 7px 12px var(--shadow-2), -7px -7px 12px var(--shadow-1);
}

.btn:active, .btn.active {
    box-shadow: inset 5px 5px 10px var(--shadow-2), inset -5px -5px 10px var(--shadow-1);
    font-size: 1.4rem;
}

.btn.operator { color: #ff9500; }
.btn.function { color: #34c759; }
.btn.span-two { grid-column: span 2; }

/* --- History Panel --- */
.history-panel {
    font-family: 'Vazirmatn';
    position: fixed;
    top: 0;
    right: -100%;
    width: 300px;
    height: 100%;
    background: var(--bg-color);
    box-shadow: -10px 0px 20px rgba(0,0,0,0.1);
    padding: 20px;
    box-sizing: border-box;
    transition: right 0.4s ease-in-out;
    z-index: 1000;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
}

.history-panel.show { right: 0; }
.history-panel h3 { margin-top: 0; text-align: center; border-bottom: 2px solid var(--primary); padding-bottom: 10px; }
#history-content { flex-grow: 1; overflow-y: auto; list-style: none; padding: 0; margin: 0; font-size: 1.1rem; }
#history-content li { padding: 10px 5px; border-bottom: 1px solid var(--primary); cursor: pointer; }
#history-content li:hover { background-color: var(--secondary); }
#clear-history { margin-top: 15px;    font-family: 'Vazirmatn'; }

/* --- About Me Modal --- */
.modal-backdrop {
    font-family: 'Vazirmatn';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 1001;
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
}

.modal-backdrop.show {
    display: flex; /* Show the modal */
}

.modal-content {
    width: 90%;
    max-width: 400px;
    padding: 30px;
    border-radius: 30px;
    background: var(--bg-color);
    box-shadow: 10px 10px 20px var(--shadow-2), -10px -10px 20px var(--shadow-1);
    color: var(--text-color);
    position: relative;
    text-align: center;
    line-height: 1.8;
}

.close-modal {
    position: absolute;
    top: 15px;
    left: 20px;
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--text-color);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.close-modal:hover {
    transform: scale(1.2);
}


/* --- Preloader Styles --- */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color); /* از رنگ پس‌زمینه تم فعلی استفاده می‌کند */
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    transition-delay: 0.2s; /* تاخیر برای محو شدن نرم */
}

#preloader.hidden {
    opacity: 0;
    visibility: hidden;
}

.preloader-content {
    text-align: center;
    color: var(--text-color);
}

.preloader-display {
    width: 250px;
    height: 60px;
    padding: 10px;
    margin: 0 auto 1rem;
    border-radius: 10px;
    background: var(--primary);
    box-shadow: inset 5px 5px 10px var(--shadow-2), inset -5px -5px 10px var(--shadow-1);
    color: var(--text-color);
    font-size: 2rem;
    font-weight: bold;
    display: flex;
    justify-content: center; /* این خط را برای وسط‌چین کردن تغییر دهید */
    align-items: center;
    direction: ltr;
    overflow: hidden;
    white-space: nowrap;
}

.preloader-content p {
    font-family: 'Vazirmatn';
    font-size: 1.1rem;
    animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}



