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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

.calculator {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 20px;
    width: 100%;
    max-width: 320px;
}

.display-container {
    position: relative;
    margin-bottom: 20px;
}

.display {
    width: 100%;
    padding: 20px;
    font-size: 2.5rem;
    border: none;
    background: #f0f0f0;
    border-radius: 10px;
    text-align: right;
    color: #333;
    font-weight: 300;
    word-wrap: break-word;
    word-break: break-all;
}

.display:focus {
    outline: 2px solid #667eea;
}

.clear-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border: none;
    background: #ff6b6b;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    transition: all 0.3s ease;
}

.clear-btn:hover {
    background: #ff5252;
    transform: scale(1.05);
}

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

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

.btn {
    padding: 20px 10px;
    border: none;
    border-radius: 10px;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f0f0f0;
    color: #333;
    user-select: none;
}

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

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

.btn.number {
    background: #f0f0f0;
}

.btn.operator {
    background: #667eea;
    color: white;
    font-weight: bold;
}

.btn.operator:hover {
    background: #5568d3;
}

.btn.function {
    background: #ffd93d;
    color: #333;
    font-weight: bold;
}

.btn.function:hover {
    background: #ffcc00;
}

.btn.equals {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    grid-column: span 2;
    font-weight: bold;
}

.btn.equals:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.decimal {
    font-weight: bold;
}

.history-toggle {
    text-align: center;
}

.toggle-btn {
    width: 100%;
    padding: 12px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.toggle-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
}

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

.history {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 20px;
    width: 100%;
    max-width: 300px;
    max-height: 500px;
    display: flex;
    flex-direction: column;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
}

.history-header h3 {
    color: #333;
    font-size: 1.1rem;
}

.clear-history {
    padding: 6px 12px;
    border: none;
    background: #ff6b6b;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

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

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

.history-item {
    padding: 10px;
    margin-bottom: 8px;
    background: #f9f9f9;
    border-left: 4px solid #667eea;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    word-break: break-all;
}

.history-item:hover {
    background: #f0f0f0;
    transform: translateX(5px);
}

.history-item-expression {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.history-item-result {
    color: #667eea;
    font-size: 1.1rem;
    font-weight: bold;
}

.empty-history {
    text-align: center;
    color: #999;
    padding: 20px;
    font-size: 0.95rem;
}

@media (max-width: 640px) {
    .container {
        flex-direction: column;
        gap: 20px;
    }

    .calculator,
    .history {
        max-width: 100%;
    }

    .display {
        font-size: 2rem;
    }

    .btn {
        font-size: 1.2rem;
        padding: 15px 8px;
    }
}
