/* CSS Variables for Theming */
:root {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-calculator: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --border-color: #d2d2d7;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 6px 25px rgba(0, 0, 0, 0.12);

    /* Button colors */
    --btn-number: #f5f5f7;
    --btn-number-hover: #e8e8ed;
    --btn-operator: #ff9500;
    --btn-operator-hover: #e68600;
    --btn-equals: #34c759;
    --btn-equals-hover: #2db04d;
    --btn-clear: #ff3b30;
    --btn-clear-hover: #e6352b;
    --btn-function: #007aff;
    --btn-function-hover: #0066d6;
    --btn-delete: #ff9500;
    --btn-delete-hover: #e68600;

    --transition: all 0.3s ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-calculator: #1c1c1e;
    --text-primary: #f5f5f7;
    --text-secondary: #98989d;
    --border-color: #38383a;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 6px 25px rgba(0, 0, 0, 0.5);

    --btn-number: #2c2c2e;
    --btn-number-hover: #3a3a3c;
    --btn-operator: #ff9500;
    --btn-operator-hover: #ffaa33;
    --btn-equals: #34c759;
    --btn-equals-hover: #4cd964;
    --btn-clear: #ff3b30;
    --btn-clear-hover: #ff4f46;
    --btn-function: #0a84ff;
    --btn-function-hover: #409cff;
    --btn-delete: #ff9500;
    --btn-delete-hover: #ffaa33;
}

/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: var(--transition);
}

/* Container */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.header h1 {
    font-size: 2rem;
    font-weight: 600;
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.5rem;
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
}

.main-content.show-history {
    grid-template-columns: 1fr 350px;
}

/* Calculator */
.calculator {
    background: var(--bg-calculator);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.calculator:hover {
    box-shadow: var(--shadow-hover);
}

/* Display */
.display {
    background: var(--bg-primary);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 25px;
    text-align: right;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.display-previous {
    color: var(--text-secondary);
    font-size: 1.2rem;
    min-height: 30px;
    margin-bottom: 5px;
}

.display-current {
    font-size: 2.5rem;
    font-weight: 500;
    word-wrap: break-word;
    word-break: break-all;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.mode-btn:hover {
    background: var(--btn-number-hover);
}

.mode-btn.active {
    background: var(--btn-operator);
    color: white;
    border-color: var(--btn-operator);
}

/* Scientific Buttons */
.scientific-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: var(--transition);
}

.scientific-buttons.show {
    max-height: 500px;
    opacity: 1;
    margin-bottom: 20px;
}

/* Buttons Grid */
.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

/* Button Styles */
.btn {
    padding: 20px;
    font-size: 1.3rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
    color: var(--text-primary);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn:active {
    transform: translateY(0);
}

.btn-number {
    background: var(--btn-number);
}

.btn-number:hover {
    background: var(--btn-number-hover);
}

.btn-operator {
    background: var(--btn-operator);
    color: white;
}

.btn-operator:hover {
    background: var(--btn-operator-hover);
}

.btn-equals {
    background: var(--btn-equals);
    color: white;
}

.btn-equals:hover {
    background: var(--btn-equals-hover);
}

.btn-clear {
    background: var(--btn-clear);
    color: white;
}

.btn-clear:hover {
    background: var(--btn-clear-hover);
}

.btn-delete {
    background: var(--btn-delete);
    color: white;
}

.btn-delete:hover {
    background: var(--btn-delete-hover);
}

.btn-function {
    background: var(--btn-function);
    color: white;
    font-size: 1.1rem;
}

.btn-function:hover {
    background: var(--btn-function-hover);
}

/* History Panel */
.history-panel {
    background: var(--bg-calculator);
    border-radius: 20px;
    padding: 25px;
    box-shadow: var(--shadow);
    max-height: 700px;
    display: none;
    flex-direction: column;
}

.history-panel.show {
    display: flex;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.history-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.btn-clear-history {
    background: var(--btn-clear);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
}

.btn-clear-history:hover {
    background: var(--btn-clear-hover);
    transform: translateY(-1px);
}

.history-list {
    overflow-y: auto;
    flex: 1;
}

.history-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-style: italic;
}

.history-item {
    background: var(--bg-primary);
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: var(--transition);
}

.history-item:hover {
    background: var(--btn-number-hover);
    transform: translateX(-5px);
}

.history-expression {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.history-result {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-time {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* History Toggle Button */
.history-toggle {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--btn-operator);
    color: white;
    border: none;
    padding: 15px 25px;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: var(--transition);
    z-index: 1000;
}

.history-toggle:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

/* Scrollbar Styles */
.history-list::-webkit-scrollbar {
    width: 8px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.5rem;
    }

    .main-content.show-history {
        grid-template-columns: 1fr;
    }

    .history-panel {
        max-height: 400px;
    }

    .calculator {
        padding: 20px;
    }

    .display {
        padding: 20px;
        min-height: 80px;
    }

    .display-current {
        font-size: 2rem;
    }

    .btn {
        padding: 15px;
        font-size: 1.1rem;
    }

    .btn-function {
        font-size: 0.9rem;
    }

    .history-toggle {
        bottom: 20px;
        right: 20px;
        padding: 12px 20px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .buttons {
        gap: 8px;
    }

    .scientific-buttons {
        gap: 8px;
    }

    .btn {
        padding: 12px;
        font-size: 1rem;
    }

    .display-current {
        font-size: 1.8rem;
    }
}
