/* CSS Variables for theming */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --accent-primary: #e94560;
    --accent-secondary: #533483;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --btn-number: #2d3748;
    --btn-number-hover: #4a5568;
    --btn-operator: #e94560;
    --btn-operator-hover: #f56565;
    --btn-func: #533483;
    --btn-func-hover: #6b46c1;
    --btn-memory: #0f3460;
    --btn-memory-hover: #1a5f7a;
    --btn-clear: #c53030;
    --btn-clear-hover: #e53e3e;
    --btn-equals: #38a169;
    --btn-equals-hover: #48bb78;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --border-radius: 12px;
    --transition-speed: 0.2s;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
}

/* Container */
.container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 20px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Calculator Main */
.calculator {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: 0 20px 60px var(--shadow-color);
    width: 100%;
    max-width: 400px;
}

/* Display Section */
.display-section {
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 15px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
}

.expression {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: right;
    min-height: 24px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.display {
    font-size: 2.5rem;
    font-weight: 300;
    text-align: right;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
}

.memory-indicator {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.75rem;
    color: var(--accent-primary);
    font-weight: bold;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.mode-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--bg-tertiary);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all var(--transition-speed);
}

.mode-btn.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.mode-btn:hover {
    border-color: var(--accent-primary);
}

/* Button Grids */
.button-grid {
    display: grid;
    gap: 8px;
    margin-bottom: 10px;
}

.scientific-grid {
    grid-template-columns: repeat(5, 1fr);
}

.memory-grid {
    grid-template-columns: repeat(5, 1fr);
}

.basic-grid {
    grid-template-columns: repeat(4, 1fr);
}

/* Buttons */
.btn {
    padding: 15px 10px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-speed);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

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

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

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

.btn.operator {
    background: var(--btn-operator);
    color: var(--text-primary);
}

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

.btn.func {
    background: var(--btn-func);
    color: var(--text-primary);
    font-size: 0.8rem;
    padding: 12px 5px;
}

.btn.func:hover {
    background: var(--btn-func-hover);
}

.btn.memory {
    background: var(--btn-memory);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.btn.memory:hover {
    background: var(--btn-memory-hover);
}

.btn.clear {
    background: var(--btn-clear);
    color: var(--text-primary);
}

.btn.clear:hover {
    background: var(--btn-clear-hover);
}

.btn.equals {
    background: var(--btn-equals);
    color: var(--text-primary);
}

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

/* History Panel */
.history-panel {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 20px;
    width: 280px;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px var(--shadow-color);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--bg-tertiary);
}

.history-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
    display: none;
}

.clear-history {
    background: var(--btn-clear);
    border: none;
    color: var(--text-primary);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background var(--transition-speed);
}

.clear-history:hover {
    background: var(--btn-clear-hover);
}

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

.history-item {
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background var(--transition-speed);
}

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

.history-expression {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.history-result {
    font-size: 1.1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.no-history {
    color: var(--text-muted);
    text-align: center;
    font-size: 0.9rem;
    padding: 20px;
}

/* Mobile History Button */
.mobile-history-btn {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--shadow-color);
    z-index: 100;
}

/* Footer */
footer {
    background: var(--bg-secondary);
    padding: 15px;
    text-align: center;
    border-top: 1px solid var(--bg-tertiary);
}

footer p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

footer a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-speed);
}

footer a:hover {
    color: var(--btn-operator-hover);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
        flex-direction: column;
        align-items: center;
    }

    .calculator {
        max-width: 100%;
        padding: 15px;
    }

    .display {
        font-size: 2rem;
    }

    .btn {
        padding: 12px 8px;
        font-size: 0.9rem;
    }

    .btn.func {
        font-size: 0.7rem;
        padding: 10px 4px;
    }

    .scientific-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 5px;
    }

    .memory-grid {
        gap: 5px;
    }

    .basic-grid {
        gap: 6px;
    }

    /* History Panel Mobile */
    .history-panel {
        position: fixed;
        top: 0;
        right: -100%;
        width: 100%;
        max-width: 300px;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        z-index: 1000;
        transition: right 0.3s ease;
    }

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

    .history-toggle {
        display: block;
    }

    .mobile-history-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    header h1 {
        font-size: 1.2rem;
    }
}

@media (max-width: 380px) {
    .btn {
        padding: 10px 6px;
        font-size: 0.85rem;
    }

    .btn.func {
        font-size: 0.65rem;
        padding: 8px 3px;
    }

    .display {
        font-size: 1.8rem;
    }

    .expression {
        font-size: 0.8rem;
    }
}

/* Overlay for mobile history */
.history-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.history-overlay.active {
    display: block;
}

/* Keyboard focus styles */
.btn:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Animation for button press */
@keyframes buttonPress {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.btn.pressed {
    animation: buttonPress 0.1s ease;
}

/* Error state */
.display.error {
    color: var(--btn-clear);
}

/* Scrollbar styling */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
