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

:root {
    --background: #f3f4f6;
    --calculator: #ffffff;
    --display: #f8fafc;
    --text: #111827;
    --secondary-text: #6b7280;
    --button: #f3f4f6;
    --button-hover: #e5e7eb;
    --operator: #e5e7eb;
    --operator-hover: #d1d5db;
    --function: #e5e7eb;
    --equals: #2563eb;
    --equals-hover: #1d4ed8;
    --border: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.12);
}

body.dark {
    --background: #111827;
    --calculator: #1f2937;
    --display: #111827;
    --text: #f9fafb;
    --secondary-text: #9ca3af;
    --button: #374151;
    --button-hover: #4b5563;
    --operator: #4b5563;
    --operator-hover: #6b7280;
    --function: #4b5563;
    --equals: #3b82f6;
    --equals-hover: #2563eb;
    --border: #374151;
    --shadow: rgba(0, 0, 0, 0.35);
}

body {
    min-height: 100vh;

    display: flex;
    justify-content: center;
    align-items: center;

    padding: 20px;

    background: var(--background);

    color: var(--text);

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Arial,
        sans-serif;

    transition:
        background 0.3s ease,
        color 0.3s ease;
}

.calculator {
    width: 100%;
    max-width: 420px;

    padding: 24px;

    background: var(--calculator);

    border: 1px solid var(--border);

    border-radius: 24px;

    box-shadow:
        0 20px 50px var(--shadow);

    transition:
        background 0.3s ease,
        box-shadow 0.3s ease;
}


/* =========================
   Header
   ========================= */

.calculator-header {
    display: flex;

    justify-content: space-between;

    align-items: center;

    margin-bottom: 20px;
}

.calculator-header h1 {
    font-size: 24px;

    font-weight: 700;
}

.theme-button {
    width: 42px;
    height: 42px;

    border: none;

    border-radius: 50%;

    background: var(--button);

    color: var(--text);

    font-size: 18px;

    cursor: pointer;

    transition:
        background 0.2s ease,
        transform 0.15s ease;
}

.theme-button:hover {
    background: var(--button-hover);

    transform: scale(1.05);
}


/* =========================
   Display
   ========================= */

.display-container {
    width: 100%;

    min-height: 130px;

    padding: 18px;

    margin-bottom: 18px;

    background: var(--display);

    border: 1px solid var(--border);

    border-radius: 16px;

    display: flex;

    flex-direction: column;

    justify-content: flex-end;

    overflow: hidden;
}

.expression {
    min-height: 25px;

    margin-bottom: 8px;

    color: var(--secondary-text);

    font-size: 17px;

    text-align: right;

    overflow-x: auto;

    white-space: nowrap;
}

.display {
    font-size: 42px;

    font-weight: 600;

    line-height: 1.2;

    text-align: right;

    overflow-x: auto;

    white-space: nowrap;

    scrollbar-width: thin;
}


/* =========================
   Buttons
   ========================= */

.buttons {
    display: grid;

    grid-template-columns:
        repeat(4, 1fr);

    gap: 10px;
}

.button {
    min-height: 64px;

    border: none;

    border-radius: 14px;

    background: var(--button);

    color: var(--text);

    font-size: 21px;

    font-weight: 600;

    cursor: pointer;

    user-select: none;

    transition:
        background 0.15s ease,
        transform 0.08s ease;
}

.button:hover {
    background: var(--button-hover);
}

.button:active {
    transform: scale(0.95);
}


/* Number buttons */

.number {
    background: var(--button);
}


/* Operators */

.operator {
    background: var(--operator);

    font-size: 24px;
}

.operator:hover {
    background: var(--operator-hover);
}


/* Function buttons */

.function {
    background: var(--function);

    color: var(--secondary-text);

    font-size: 18px;
}


/* Equals */

.equals {
    background: var(--equals);

    color: white;

    font-size: 26px;
}

.equals:hover {
    background: var(--equals-hover);
}


/* Zero button */

.zero {
    grid-column: span 2;
}


/* =========================
   History
   ========================= */

.history-section {
    margin-top: 28px;

    border-top: 1px solid var(--border);

    padding-top: 18px;
}

.history-header {
    display: flex;

    align-items: center;

    justify-content: space-between;

    margin-bottom: 12px;
}

.history-header h2 {
    font-size: 18px;
}

#clearHistory {
    border: none;

    background: transparent;

    color: var(--secondary-text);

    cursor: pointer;

    font-size: 14px;
}

#clearHistory:hover {
    color: var(--text);
}

.history {
    max-height: 180px;

    overflow-y: auto;
}

.history-item {
    padding: 10px 12px;

    margin-bottom: 8px;

    background: var(--display);

    border-radius: 10px;

    color: var(--text);

    font-size: 14px;

    text-align: right;

    cursor: pointer;

    transition:
        background 0.15s ease;
}

.history-item:hover {
    background: var(--button-hover);
}

.empty-history {
    padding: 15px;

    color: var(--secondary-text);

    text-align: center;

    font-size: 14px;
}


/* =========================
   Mobile
   ========================= */

@media (max-width: 480px) {

    body {
        padding: 10px;
    }

    .calculator {
        padding: 16px;

        border-radius: 20px;
    }

    .calculator-header h1 {
        font-size: 21px;
    }

    .display-container {
        min-height: 115px;

        padding: 15px;
    }

    .display {
        font-size: 34px;
    }

    .expression {
        font-size: 15px;
    }

    .button {
        min-height: 58px;

        border-radius: 12px;

        font-size: 19px;
    }

    .operator {
        font-size: 22px;
    }

    .equals {
        font-size: 24px;
    }
}


/* =========================
   Small phones
   ========================= */

@media (max-width: 350px) {

    .calculator {
        padding: 12px;
    }

    .buttons {
        gap: 7px;
    }

    .button {
        min-height: 52px;

        font-size: 17px;
    }

    .display {
        font-size: 30px;
    }
}