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

body {
    background: #808080; /* Серый фон вместо градиента */
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: background 0.3s;
}

body.dark-theme {
    background: #404040; /* Темно-серый фон для тёмной темы */
}

.calculator-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 500px;
}

.calculator {
    background-color: #2d2d2d;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 100%;
    transition: background-color 0.3s;
}

body.dark-theme .calculator {
    background-color: #1e1e1e;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #444;
    color: white;
}

body.dark-theme .header {
    border-bottom-color: #333;
}

.header h1 {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.theme-toggle {
    background: none;
    border: none;
    color: #ff9500;
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.3s;
}

.theme-toggle:hover {
    transform: rotate(30deg);
}

.display-container {
    padding: 20px;
}

.history-display {
    font-size: 0.9rem;
    color: #888;
    height: 20px;
    margin-bottom: 5px;
    text-align: right;
    overflow: hidden;
    white-space: nowrap;
}

body.dark-theme .history-display {
    color: #aaa;
}

.display {
    width: 100%;
    height: 80px;
    border: none;
    background-color: #1a1a1a;
    border-radius: 10px;
    font-size: 2.5rem;
    text-align: right;
    padding: 0 20px;
    color: white;
    outline: none;
    transition: background-color 0.3s;
}

body.dark-theme .display {
    background-color: #2a2a2a;
}

.buttons {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

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

.btn {
    height: 70px;
    border: none;
    border-radius: 10px;
    font-size: 1.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(1px);
}

.number-btn {
    background-color: #444;
    color: white;
}

.number-btn:hover {
    background-color: #555;
}

body.dark-theme .number-btn {
    background-color: #333;
}

body.dark-theme .number-btn:hover {
    background-color: #444;
}

.zero-btn {
    grid-column: span 2;
}

.func-btn {
    background-color: #a6a6a6;
    color: white;
}

.func-btn:hover {
    background-color: #8a8a8a;
}

body.dark-theme .func-btn {
    background-color: #555;
}

body.dark-theme .func-btn:hover {
    background-color: #666;
}

.operator-btn {
    background-color: #ff9500;
    color: white;
}

.operator-btn:hover {
    background-color: #e08500;
}

.equals-btn {
    background-color: #4CAF50;
    color: white;
    grid-column: span 1;
}

.equals-btn:hover {
    background-color: #66bb6a;
}

.history-section {
    padding: 20px;
    border-top: 1px solid #444;
    color: white;
}

body.dark-theme .history-section {
    border-top-color: #333;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.history-header h3 {
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.clear-history-btn {
    background-color: #f44336;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 15px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.clear-history-btn:hover {
    background-color: #d32f2f;
}

.history-list {
    max-height: 200px;
    overflow-y: auto;
}

.history-empty {
    text-align: center;
    color: #888;
    padding: 20px;
    font-style: italic;
}

body.dark-theme .history-empty {
    color: #666;
}

.history-item {
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    background-color: #3a3a3a;
    cursor: pointer;
    transition: background-color 0.3s;
}

body.dark-theme .history-item {
    background-color: #2a2a2a;
}

.history-item:hover {
    background-color: #444;
}

body.dark-theme .history-item:hover {
    background-color: #333;
}

.history-expression {
    font-size: 1rem;
    font-weight: 500;
    color: #ccc;
}

.history-result {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 5px 0;
    color: #4CAF50;
}

.history-time {
    font-size: 0.8rem;
    color: #888;
}

body.dark-theme .history-time {
    color: #aaa;
}

@media (max-width: 480px) {
    .calculator-container {
        max-width: 100%;
        padding: 10px;
    }
    
    .btn {
        height: 60px;
        font-size: 1.3rem;
    }
    
    .display {
        height: 70px;
        font-size: 2rem;
    }
}
