:root {
    /* light mode */
    --bg-color: #f0f0f3;
    --calc-bg: #ffffff;
    --display-bg: #f8f9fa;
    --display-color: #2c3e50;
    --btn-number-bg: #e8ecf1;
    --btn-number-color: #2c3e50;
    --btn-function-bg: #d1d5db;
    --btn-function-color: #2c3e50;
    --btn-operator-bg: #ff9f43;
    --btn-operator-color: #ffffff;
    --btn-equals-bg: #4CAF50;
    --btn-equals-color: #ffffff;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-dark: rgba(0, 0, 0, 0.2);
    --toggle-bg: #d1d5db;
    --toggle-slider: #ffffff;
}

body.dark-mode {
    --bg-color: #1a1a1d;
    --calc-bg: #2d2d30;
    --display-bg: #1e1e1e;
    --display-color: #e0e0e0;
    --btn-number-bg: #3e3e42;
    --btn-number-color: #ffffff;
    --btn-function-bg: #505053;
    --btn-function-color: #ffffff;
    --btn-operator-bg: #ff9f43;
    --btn-operator-color: #ffffff;
    --btn-equals-bg: #4CAF50;
    --btn-equals-color: #ffffff;
    --shadow-light: rgba(0, 0, 0, 0.3);
    --shadow-dark: rgba(0, 0, 0, 0.5);
    --toggle-bg: #505053;
    --toggle-slider: #ff9f43;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg-color);
    transition: background 0.3s ease;
    padding: 20px 20px 100px 20px;
}

.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 150;
}

.toggle-checkbox {
    display: none;
}

.toggle-label {
    display: block;
    width: 60px;
    height: 30px;
    background: var(--toggle-bg);
    border-radius: 50px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s ease;
    box-shadow: 0 2px 8px var(--shadow-light);
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    background: var(--toggle-slider);
    border-radius: 50%;
    transition: transform 0.3s ease, background 0.3s ease;
    box-shadow: 0 2px 4px var(--shadow-dark);
}

.toggle-checkbox:checked + .toggle-label .toggle-slider {
    transform: translateX(30px);
}

.calculator {
    background: var(--calc-bg);
    border-radius: 30px;
    padding: 20px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 10px 40px var(--shadow-dark);
    transition: all 0.3s ease;
}

.display-container {
    background: var(--display-bg);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    box-shadow: inset 0 2px 8px var(--shadow-light);
    overflow: hidden;
}

.display-container.result-mode {
    justify-content: center;
}

.display-expression {
    color: var(--display-color);
    font-size: 30px;
    font-weight: 300;
    word-wrap: break-word;
    word-break: break-all;
    width: 100%;
    text-align: right;
    transition: all 0.2s ease;
}

.display-live-result {
    color: var(--display-color);
    opacity: 0.6;
    font-size: 20px;
    margin-top: 5px;
    min-height: 24px;
}

/* Adjust the 'result displayed' state via JS class */
.display-expression.final-result {
    font-size: 30px;
    opacity: 1;
    font-weight: 700;
}

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

.btn {
    border: none;
    border-radius: 50%;
    width: 100%;
    aspect-ratio: 1;
    font-size: 24px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px var(--shadow-light);
    outline: none;
}

.btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 6px var(--shadow-light);
}

.btn.number {
    background: var(--btn-number-bg);
    color: var(--btn-number-color);
}

.btn.number:hover {
    filter: brightness(0.95);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-dark);
}

.btn.function {
    background: var(--btn-function-bg);
    color: var(--btn-function-color);
    font-weight: 600;
}

.btn.function:hover {
    filter: brightness(0.9);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-dark);
}

.btn.operator {
    background: var(--btn-operator-bg);
    color: var(--btn-operator-color);
    font-weight: 600;
}

.btn.operator:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-dark);
}

.btn.equals {
    background: var(--btn-equals-bg);
    color: var(--btn-equals-color);
    font-weight: 700;
    font-size: 28px;
}

.btn.equals:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-dark);
}

@media (max-width: 480px) {
    .calculator {
        max-width: 100%;
        padding: 15px;
        border-radius: 20px;
    }

    .display {
        font-size: 36px;
        padding: 20px 15px;
        min-height: 70px;
    }

    .buttons {
        gap: 10px;
    }

    .btn {
        font-size: 20px;
    }

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

    .toggle-label {
        width: 50px;
        height: 25px;
    }

    .toggle-slider {
        width: 20px;
        height: 20px;
        top: 2.5px;
        left: 2.5px;
    }

    .toggle-checkbox:checked + .toggle-label .toggle-slider {
        transform: translateX(25px);
    }
}

@media (max-width: 390px) {
    body {
        padding: 80px 10px 90px 10px;
    }

    .calculator {
        padding: 12px;
        max-width: 320px;
    }

    .display-container {
        height: 100px;
        padding: 15px;
        margin-bottom: 12px;
    }

    .display-expression {
        font-size: 24px;
    }

    .display-expression.final-result {
        font-size: 36px;
    }

    .display-live-result {
        font-size: 18px;
    }

    .buttons {
        gap: 8px;
    }

    .btn {
        font-size: 18px;
    }

    .btn.equals {
        font-size: 20px;
    }

    .history-toggle {
        top: 10px;
        left: 10px;
        width: 40px;
        height: 40px;
    }

    .history-toggle svg {
        width: 18px;
        height: 18px;
    }

    .toggle-label {
        width: 45px;
        height: 23px;
    }

    .toggle-slider {
        width: 18px;
        height: 18px;
        top: 2.5px;
        left: 2.5px;
    }

    .toggle-checkbox:checked + .toggle-label .toggle-slider {
        transform: translateX(22px);
    }
}

.history-panel {
    position: fixed;
    top: 0;
    right: -350px;
    width: 350px;
    height: 100vh;
    background: var(--calc-bg);
    box-shadow: -4px 0 20px var(--shadow-dark);
    transition: right 0.3s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-panel.active {
    right: 0;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--btn-function-bg);
}

.history-header h3 {
    color: var(--display-color);
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.history-clear {
    background: var(--btn-function-bg);
    color: var(--btn-function-color);
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.history-clear:hover {
    filter: brightness(0.9);
    transform: translateY(-1px);
}

.history-clear:active {
    transform: translateY(0);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.history-empty {
    text-align: center;
    color: var(--display-color);
    opacity: 0.5;
    padding: 40px 20px;
    font-size: 14px;
}

.history-item {
    background: var(--display-bg);
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.history-item:hover {
    filter: brightness(0.95);
}

.history-content {
    flex: 1;
    cursor: pointer;
    min-width: 0;
}

.history-content:hover {
    opacity: 0.8;
}

.history-delete {
    background: transparent;
    border: none;
    color: var(--display-color);
    opacity: 0.5;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.history-delete:hover {
    opacity: 1;
    background: rgba(255, 0, 0, 0.1);
    color: #e74c3c;
}

.history-delete:active {
    transform: scale(0.9);
}

.history-expression {
    color: var(--display-color);
    font-size: 14px;
    opacity: 0.7;
    margin-bottom: 5px;
}

.history-result {
    color: var(--display-color);
    font-size: 18px;
    font-weight: 600;
}

.history-toggle {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    background: var(--calc-bg);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 12px var(--shadow-light);
    transition: all 0.3s ease;
    z-index: 150;
    color: var(--display-color);
}

.history-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px var(--shadow-dark);
}

.history-toggle:active {
    transform: scale(1);
}

.history-toggle.active {
    background: var(--btn-operator-bg);
    color: white;
}

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

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

.history-list::-webkit-scrollbar-thumb {
    background: var(--btn-function-bg);
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--btn-operator-bg);
}

@media (max-width: 480px) {
    .history-panel {
        width: 100%;
        right: -100%;
    }

    .history-header {
        padding-left: 70px;
    }

    .history-toggle {
        width: 45px;
        height: 45px;
        top: 15px;
        left: 15px;
        z-index: 250;
    }

    .history-toggle svg {
        width: 20px;
        height: 20px;
    }
}

/* Custom Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--calc-bg);
    border-radius: 20px;
    padding: 30px;
    max-width: 350px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px var(--shadow-dark);
    transform: scale(0.8) translateY(-20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 15px;
    background: var(--btn-operator-bg);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
}

.modal-icon.alert {
    background: #e74c3c;
}

.modal-icon.success {
    background: var(--btn-equals-bg);
}

.modal-title {
    color: var(--display-color);
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 10px;
}

.modal-message {
    color: var(--display-color);
    opacity: 0.7;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 25px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn-cancel {
    background: var(--btn-function-bg);
    color: var(--btn-function-color);
}

.modal-btn-cancel:hover {
    filter: brightness(0.9);
    
}

.modal-btn-confirm {
    background: var(--btn-operator-bg);
    color: white;
}

.modal-btn-confirm:hover {
    filter: brightness(1.1);
    
}

.modal-btn-confirm.danger {
    background: #e74c3c;
}

.modal-btn:active {
    transform: translateY(0);
}

/* Alert modal - single button */
.modal-buttons.alert-only .modal-btn-cancel {
    display: none;
}

.modal-buttons.alert-only .modal-btn-confirm {
    flex: none;
    min-width: 120px;
}

button {
  -webkit-tap-highlight-color: transparent;
}

/* Footer Styles */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: transparent;
    padding: 15px 20px;
    border-top: 2px solid rgba(0, 0, 0, 0.1);
    z-index: 50;
}

body.dark-mode .footer {
    border-top: 2px solid rgba(255, 255, 255, 0.2);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.trademark {
    color: var(--display-color);
    font-size: 13px;
    opacity: 0.7;
}

.social-links {
    display: flex;
    gap: 15px;
}

.social-links a {
    color: var(--display-color);
    opacity: 0.6;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 50%;
}

.social-links a:hover {
    opacity: 1;
    background: var(--btn-function-bg);
    transform: translateY(-2px);
}

.social-links a:active {
    transform: translateY(0);
}

@media (max-width: 480px) {
    .footer {
        padding: 12px 15px;
    }

    .footer-content {
        flex-direction: column;
        gap: 10px;
    }

    .footer-right {
        flex-direction: column;
        gap: 10px;
    }

    .trademark {
        font-size: 11px;
        text-align: center;
    }

    .social-links {
        gap: 12px;
    }

    .social-links a {
        padding: 6px;
    }

    .social-links a svg {
        width: 18px;
        height: 18px;
    }
    
}