* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: #fff;
    transition: background 0.3s ease;
}

body.default-theme {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
}

body.light-theme {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: #333;
}

body.dark-theme {
    background: #000;
    color: #fff;
}

body.colorful-theme {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

body.monochrome-theme {
    background: #f0f0f0;
    color: #333;
}

.calculator-container {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.control-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(44, 62, 80, 0.8);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    color: #fff;
}

body.light-theme .control-panel {
    background: rgba(255, 255, 255, 0.8);
    color: #333;
}

body.dark-theme .control-panel {
    background: rgba(20, 20, 20, 0.8);
    color: #fff;
}

body.colorful-theme .control-panel {
    background: rgba(102, 126, 234, 0.8);
    color: #fff;
}

body.monochrome-theme .control-panel {
    background: rgba(200, 200, 200, 0.8);
    color: #333;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 120px;
}

.control-group label {
    font-size: 0.9rem;
    white-space: nowrap;
}

.control-group select {
    padding: 6px 10px;
    border: none;
    border-radius: 8px;
    background: #4a5568;
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
}

body.default-theme .control-group select {
    background: #4a5568;
    color: white;
}

body.light-theme .control-group select {
    background: #6b7280;
    color: white;
}

body.dark-theme .control-group select {
    background: #333;
    color: white;
}

body.colorful-theme .control-group select {
    background: #5b21b6;
    color: white;
}

body.monochrome-theme .control-group select {
    background: #888;
    color: white;
}

.toggle-history {
    padding: 8px 15px;
    border: none;
    border-radius: 8px;
    background: #10b981;
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.toggle-history:hover {
    background: #34d399;
    transform: scale(1.02);
}

.toggle-history:active {
    background: #059669;
    transform: scale(0.98);
}

.calculator {
    width: 100%;
    background: #2c3e50;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

body.light-theme .calculator {
    background: #ffffff;
    color: #333;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

body.dark-theme .calculator {
    background: #111;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

body.colorful-theme .calculator {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

body.monochrome-theme .calculator {
    background: #ddd;
    color: #333;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* Affichage mémoire */
.memory-display {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-bottom: 10px;
    font-size: 0.8rem;
}

.memory-display.show {
    display: flex;
}

#memoryIndicator {
    background: #10b981;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.7rem;
}

#memoryValue {
    font-family: monospace;
}

.history-panel {
    background: transparent;
    border-radius: 10px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, background 0.3s ease;
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
    opacity: 0;
}

.history-panel.show {
    max-height: 200px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
    opacity: 1;
}

.history-content {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
}

.history-empty {
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    font-style: italic;
    padding: 10px;
}

body.light-theme .history-empty,
body.monochrome-theme .history-empty {
    color: rgba(0, 0, 0, 0.5);
}

.history-item {
    padding: 8px 12px;
    margin-bottom: 5px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.2);
}

body.light-theme .history-item,
body.monochrome-theme .history-item {
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme .history-item:hover,
body.monochrome-theme .history-item:hover {
    background: rgba(0, 0, 0, 0.1);
}

.history-item .expression {
    font-weight: bold;
}

.history-item .result {
    color: #10b981;
}

.clear-history {
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: #ef4444;
    color: white;
    font-size: 0.8rem;
    cursor: pointer;
    align-self: flex-end;
    transition: all 0.2s;
}

.clear-history:hover {
    background: #f87171;
}

.clear-history:active {
    background: #dc2626;
}

.display {
    background: #000;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
    text-align: right;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    transition: all 0.3s ease;
}

body.default-theme .display {
    background: #000;
    color: #fff;
}

body.light-theme .display {
    background: #f8f9fa;
    color: #333;
}

body.dark-theme .display {
    background: #000;
    color: #fff;
}

body.colorful-theme .display {
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
}

body.monochrome-theme .display {
    background: #eee;
    color: #333;
}

.previous-operand {
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.2rem;
    height: 24px;
    overflow: hidden;
    transition: all 0.3s ease;
}

body.default-theme .previous-operand {
    color: rgba(255, 255, 255, 0.7);
}

body.light-theme .previous-operand,
body.monochrome-theme .previous-operand {
    color: rgba(0, 0, 0, 0.5);
}

body.dark-theme .previous-operand {
    color: rgba(255, 255, 255, 0.7);
}

body.colorful-theme .previous-operand {
    color: rgba(255, 255, 255, 0.7);
}

.current-operand {
    color: #fff;
    font-size: 2.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.3s ease;
}

body.default-theme .current-operand {
    color: #fff;
}

body.light-theme .current-operand,
body.monochrome-theme .current-operand {
    color: #333;
}

body.dark-theme .current-operand {
    color: #fff;
}

body.colorful-theme .current-operand {
    color: #fff;
}

/* Boutons scientifiques */
.scientific-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.scientific-buttons.small {
    gap: 5px;
}

.scientific-buttons.medium {
    gap: 7px;
}

.scientific-buttons.large {
    gap: 10px;
}

.scientific-buttons button {
    background: #374151;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    height: 45px;
}

.scientific-buttons.small button {
    padding: 8px;
    font-size: 0.8rem;
    height: 35px;
}

.scientific-buttons.medium button {
    padding: 10px;
    font-size: 0.9rem;
    height: 40px;
}

.scientific-buttons.large button {
    padding: 15px;
    font-size: 1.1rem;
    height: 55px;
}

.scientific-buttons button:hover {
    background: #4a5568;
    transform: scale(1.02);
}

.scientific-buttons button:active {
    background: #252f3f;
    transform: scale(0.98);
}

.scientific-buttons button.span-two {
    grid-column: span 2;
}

/* Boutons mémoire */
.buttons .memory-btn {
    background: #3b82f6;
    color: white;
}

.buttons .memory-btn:hover {
    background: #60a5fa;
}

.buttons .memory-btn:active {
    background: #2563eb;
}

/* Boutons principaux */
.buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.buttons.small {
    gap: 5px;
}

.buttons.medium {
    gap: 7px;
}

.buttons.large {
    gap: 12px;
}

.buttons button {
    background: #4a5568;
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 16px;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
    height: 60px;
}

.buttons.small button {
    padding: 10px;
    font-size: 1rem;
    height: 45px;
}

.buttons.medium button {
    padding: 14px;
    font-size: 1.2rem;
    height: 55px;
}

.buttons.large button {
    padding: 20px;
    font-size: 1.5rem;
    height: 70px;
}

button:hover {
    transform: scale(1.02);
}

button:active {
    transform: scale(0.98);
}

button.span-two {
    grid-column: span 2;
}

button.span-three {
    grid-column: span 3;
}

/* Thème par défaut */
body.default-theme .buttons button {
    background: #4a5568;
    color: #fff;
}

body.default-theme .buttons button:not(.span-two):not(.span-three):not(.memory-btn):nth-child(5n+5) {
    background: #f59e0b;
}

body.default-theme .buttons button.span-two:last-child {
    background: #10b981;
}

body.default-theme button:first-child,
body.default-theme button:nth-child(2),
body.default-theme button:nth-child(3),
body.default-theme button:nth-child(4) {
    background: #ef4444;
}

body.default-theme button:nth-child(5) {
    background: #6b7280;
}

/* Thème clair */
body.light-theme .buttons button {
    background: #6b7280;
    color: white;
}

body.light-theme .buttons button:not(.span-two):not(.span-three):not(.memory-btn):nth-child(5n+5) {
    background: #f59e0b;
}

body.light-theme .buttons button.span-two:last-child {
    background: #10b981;
}

body.light-theme button:first-child,
body.light-theme button:nth-child(2),
body.light-theme button:nth-child(3),
body.light-theme button:nth-child(4) {
    background: #ef4444;
}

body.light-theme button:nth-child(5) {
    background: #9ca3af;
}

/* Thème sombre */
body.dark-theme .buttons button {
    background: #374151;
    color: white;
}

body.dark-theme .buttons button:not(.span-two):not(.span-three):not(.memory-btn):nth-child(5n+5) {
    background: #f59e0b;
}

body.dark-theme .buttons button.span-two:last-child {
    background: #10b981;
}

body.dark-theme button:first-child,
body.dark-theme button:nth-child(2),
body.dark-theme button:nth-child(3),
body.dark-theme button:nth-child(4) {
    background: #ef4444;
}

body.dark-theme button:nth-child(5) {
    background: #4b5563;
}

/* Thème coloré */
body.colorful-theme .buttons button {
    background: #5b21b6;
    color: white;
}

body.colorful-theme .buttons button:nth-child(1) { background: #ef4444; }
body.colorful-theme .buttons button:nth-child(2) { background: #f59e0b; }
body.colorful-theme .buttons button:nth-child(3) { background: #10b981; }
body.colorful-theme .buttons button:nth-child(4) { background: #3b82f6; }
body.colorful-theme .buttons button:nth-child(5) { background: #8b5cf6; }
body.colorful-theme .buttons button:nth-child(6) { background: #ec4899; }
body.colorful-theme .buttons button:nth-child(7) { background: #f97316; }
body.colorful-theme .buttons button:nth-child(8) { background: #eab308; }
body.colorful-theme .buttons button:nth-child(9) { background: #22c55e; }
body.colorful-theme .buttons button:nth-child(10) { background: #06b6d4; }
body.colorful-theme .buttons button:nth-child(11) { background: #84cc16; }
body.colorful-theme .buttons button:nth-child(12) { background: #f59e0b; }
body.colorful-theme .buttons button:nth-child(13) { background: #ef4444; }
body.colorful-theme .buttons button:nth-child(14) { background: #3b82f6; }
body.colorful-theme .buttons button:nth-child(15) { background: #10b981; }
body.colorful-theme .buttons button:nth-child(16) { background: #8b5cf6; }
body.colorful-theme .buttons button:nth-child(17) { background: #6366f1; }
body.colorful-theme .buttons button:nth-child(18) { background: #16a34a; }

body.colorful-theme .buttons button.span-two:last-child { background: #16a34a; }

body.colorful-theme .memory-btn {
    background: #7c3aed;
}

/* Thème monochrome */
body.monochrome-theme .buttons button {
    background: #888;
    color: white;
}

body.monochrome-theme .buttons button:not(.span-two):not(.span-three):not(.memory-btn):nth-child(5n+5) {
    background: #666;
}

body.monochrome-theme .buttons button.span-two:last-child {
    background: #555;
}

body.monochrome-theme button:first-child,
body.monochrome-theme button:nth-child(2),
body.monochrome-theme button:nth-child(3),
body.monochrome-theme button:nth-child(4) {
    background: #444;
}

body.monochrome-theme button:nth-child(5) {
    background: #777;
}

body.monochrome-theme .memory-btn {
    background: #555;
}

/* Boutons scientifiques - thèmes */
body.default-theme .scientific-buttons button {
    background: #374151;
    color: #fff;
}

body.light-theme .scientific-buttons button {
    background: #4b5563;
    color: #fff;
}

body.dark-theme .scientific-buttons button {
    background: #1f2937;
    color: #fff;
}

body.colorful-theme .scientific-buttons button {
    background: #5b21b6;
    color: #fff;
}

body.monochrome-theme .scientific-buttons button {
    background: #666;
    color: #fff;
}

.install-prompt {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    padding: 15px 20px;
    border-radius: 10px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.install-prompt.show {
    display: flex;
}

.install-prompt button {
    background: #10b981;
    padding: 8px 16px;
    font-size: 1rem;
    height: auto;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.install-prompt button:last-child {
    background: #ef4444;
}

@media (max-width: 400px) {
    .calculator {
        margin: 0;
        border-radius: 0;
        max-width: 100%;
    }
    
    body {
        padding: 0;
    }
    
    .display {
        padding: 15px;
    }
    
    .current-operand {
        font-size: 2rem;
    }
    
    .control-panel {
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-group {
        flex: none;
        width: 100%;
    }
    
    .toggle-history {
        width: 100%;
        justify-content: center;
    }
    
    .scientific-buttons {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .buttons {
        grid-template-columns: repeat(5, 1fr);
    }
}
