/* -------------------------------------------------------------------------- */
/*                                 Root Variables                             */
/* -------------------------------------------------------------------------- */
:root {
    /* Light Theme Configuration */
    --bg-color: #e0e5ec;
    --card-bg: #e0e5ec;
    --text-main: #2d3748;
    --text-sec: #718096;

    /* Component Colors */
    --btn-num-bg: #e0e5ec;
    --btn-num-text: #2d3748;
    --btn-fn-bg: #e0e5ec;
    --btn-fn-text: #2b6cb0;
    --btn-op-bg: #eb6e4b;
    --btn-op-text: #ffffff;

    /* Neumorphic Shadows */
    --btn-shadow-light: #ffffff;
    --btn-shadow-dark: #a3b1c6;
    --shadow-card: 20px 20px 60px #bebebe, -20px -20px 60px #ffffff;

    /* Screen Styles */
    --screen-bg: #d1d9e6;
    --screen-shadow-inset: inset 6px 6px 12px #b8c2cc, inset -6px -6px 12px #ffffff;
    --screen-text: #1a202c;

    /* Layout */
    --radius-main: 2rem;
    --radius-btn: 50%;
}

[data-theme="dark"] {
    /* Dark Theme Configuration */
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f1f5f9;
    --text-sec: #94a3b8;

    --btn-num-bg: #1e293b;
    --btn-num-text: #e2e8f0;
    --btn-fn-bg: #1e293b;
    --btn-fn-text: #60a5fa;
    --btn-op-bg: #f59e0b;
    --btn-op-text: #ffffff;

    /* Dark Shadows */
    --btn-shadow-light: #2d3e56;
    --btn-shadow-dark: #0f151e;
    --shadow-card: 0 25px 50px -12px rgba(0, 0, 0, 0.5);

    --screen-bg: #0f172a;
    --screen-shadow-inset: inset 5px 5px 15px #0a101d, inset -5px -5px 15px #2a3a52;
    --screen-text: #f8fafc;
    --screen-glow: 0 0 10px rgba(248, 250, 252, 0.4);

    --panel-bg: rgba(15, 23, 42, 0.9);
}

/* -------------------------------------------------------------------------- */
/*                                 Base Reset                                 */
/* -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    font-variant-numeric: tabular-nums;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow: hidden;
}

.app-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

/* -------------------------------------------------------------------------- */
/*                              Calculator Card                               */
/* -------------------------------------------------------------------------- */
.calculator-card {
    background-color: var(--card-bg);
    width: 100%;
    max-width: 360px;
    border-radius: var(--radius-main);
    box-shadow: var(--shadow-card);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    transition: background-color 0.4s ease, box-shadow 0.4s ease;
    position: relative;
    z-index: 10;
}

/* Header & Controls */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.5rem;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-sec);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.1);
}

/* -------------------------------------------------------------------------- */
/*                               Theme Switch                                 */
/* -------------------------------------------------------------------------- */
.theme-switch-wrapper {
    display: flex;
    align-items: center;
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--screen-bg);
    transition: .4s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 5px;
    border-radius: 34px;
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.1);
}

.slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: var(--text-main);
    transition: .4s;
    border-radius: 50%;
    z-index: 2;
}

input:checked+.slider::before {
    transform: translateX(24px);
    background-color: #fff;
}

.sun,
.moon {
    z-index: 1;
    color: var(--text-sec);
}

/* -------------------------------------------------------------------------- */
/*                               Display Screen                               */
/* -------------------------------------------------------------------------- */
.display {
    background-color: var(--screen-bg);
    box-shadow: var(--screen-shadow-inset);
    border-radius: 1rem;
    padding: 1.2rem;
    text-align: right;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-direction: column;
    height: 150px;
    position: relative;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: box-shadow 0.3s ease, background-color 0.3s ease;
}

/* Reflection Effect */
.display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0) 100%);
    border-radius: 1rem 1rem 0 0;
    pointer-events: none;
}

.display-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-end;
    overflow: hidden;
}

.history-preview {
    font-size: 1rem;
    color: var(--text-sec);
    height: 1.5rem;
    line-height: 1.5rem;
    white-space: nowrap;
    opacity: 0.8;
    width: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.current-row {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.current-operand {
    font-size: 2.5rem;
    font-weight: 300;
    color: var(--screen-text);
    white-space: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    width: 100%;
    text-align: right;
    line-height: 1.2;
    text-shadow: var(--screen-glow, none);
    transition: text-shadow 0.3s ease, color 0.3s ease;
}

.current-operand::-webkit-scrollbar {
    display: none;
}

.backspace-btn {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: none;
    border: none;
    color: var(--text-sec);
    cursor: pointer;
    padding: 5px;
    opacity: 0.5;
    transition: opacity 0.2s, color 0.2s;
}

.backspace-btn:hover {
    opacity: 1;
    color: var(--btn-op-bg);
}

/* Tooltip */
.copy-tooltip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.8rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.copy-tooltip.show {
    opacity: 1;
}

/* -------------------------------------------------------------------------- */
/*                                Button Grid                                 */
/* -------------------------------------------------------------------------- */
.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.2rem;
    padding: 0.5rem;
}

.btn {
    font-family: inherit;
    font-size: 1.5rem;
    font-weight: 400;
    border: none;
    border-radius: var(--radius-btn);
    aspect-ratio: 1;
    cursor: pointer;
    transition: all 0.1s ease-out;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 6px 6px 10px var(--btn-shadow-dark), -6px -6px 10px var(--btn-shadow-light);
    color: var(--btn-num-text);
    background-color: var(--btn-num-bg);
}

.btn:active,
.btn.pressed {
    transform: scale(0.95);
    box-shadow: inset 4px 4px 8px var(--btn-shadow-dark), inset -4px -4px 8px var(--btn-shadow-light);
}

.btn.operator {
    background-color: var(--btn-op-bg);
    color: var(--btn-op-text);
    box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2), -4px -4px 10px rgba(255, 255, 255, 0.1);
}

.btn.operator:active,
.btn.operator.pressed {
    box-shadow: inset 3px 3px 8px rgba(0, 0, 0, 0.3);
}

.btn.function {
    color: var(--btn-fn-text);
}

.btn.equals {
    background-color: var(--btn-op-bg);
    color: var(--btn-op-text);
    box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2), -4px -4px 10px rgba(255, 255, 255, 0.1);
}

.btn.equals:active,
.btn.equals.pressed {
    box-shadow: inset 3px 3px 8px rgba(0, 0, 0, 0.3);
}

.span-two {
    grid-column: span 2;
    aspect-ratio: auto;
    border-radius: 1rem;
}

/* -------------------------------------------------------------------------- */
/*                               History Panel                                */
/* -------------------------------------------------------------------------- */
.history-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background-color: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2);
    transform: translateX(110%);
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 20;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.history-panel.open {
    transform: translateX(0);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    color: var(--text-main);
}

.history-list {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0.5rem;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background-color: var(--text-sec);
    border-radius: 10px;
}

.history-item {
    background-color: transparent;
    padding: 0.8rem;
    border-radius: 1rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.2s;
    border: 1px solid rgba(127, 127, 127, 0.1);
}

.history-item:hover {
    transform: translateX(-5px);
    background-color: rgba(127, 127, 127, 0.1);
}

.history-expression {
    font-size: 0.85rem;
    color: var(--text-sec);
    text-align: right;
    margin-bottom: 0.2rem;
}

.history-result {
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--text-main);
    text-align: right;
}

.clear-history-btn {
    margin-top: 1rem;
    padding: 0.6rem 1rem;
    background-color: transparent;
    color: var(--text-main);
    border: 2px solid var(--text-main);
    border-radius: 0.5rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    align-self: center;
    width: 80%;
}

.clear-history-btn:hover {
    background-color: var(--text-main);
    color: var(--card-bg);
}

.clear-history-btn.hidden {
    display: none;
}

/* Overlay */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(2px);
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* -------------------------------------------------------------------------- */
/*                                Responsive                                  */
/* -------------------------------------------------------------------------- */
@media (max-width: 480px) {
    .calculator-card {
        height: 100%;
        max-width: 100%;
        border-radius: 0;
        justify-content: flex-end;
        padding: 1.5rem;
    }

    .history-panel {
        width: 85%;
    }
}