* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 20px;
    background: #f0f2f5;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
}

.reset-section {
    max-width: 1200px;
    margin: 0 auto 20px;
    text-align: center;
}

#resetAllBtn {
    padding: 12px 28px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

#resetAllBtn:hover {
    background: #c82333;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

#resetAllBtn:active {
    transform: translateY(0);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
    }
}

.calc-section,
.history-section {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    padding: 30px;
}

.calc-section {
    max-width: 550px;
    margin: 0 auto;
}

.calc-section h2,
.history-section h2 {
    margin: 0 0 20px 0;
    font-size: 24px;
    font-weight: 600;
    color: #2d3436;
    text-align: center;
}

#result {
    width: 100%;
    height: 70px;
    font-size: 32px;
    font-weight: 500;
    text-align: right;
    margin-bottom: 20px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 0 20px;
    background: #f8f9fa;
    color: #212529;
    font-family: 'Courier New', monospace;
    transition: all 0.3s ease;
}

#result:focus {
    outline: none;
    border-color: #adb5bd;
    background: white;
}

.keys {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(4, 65px);
    grid-auto-flow: dense;
    gap: 10px;
}

.key-row {
    display: contents;
}

.undo-redo-row {
    grid-column: span 5;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.keys button {
    height: 65px;
    font-size: 20px;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.keys button:active {
    transform: scale(0.95);
}

/* Number buttons */
.number-btn {
    background: #f8f9fa;
    color: #2d3436;
}

.number-btn:hover {
    background: #e9ecef;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Operator buttons */
.operator-btn {
    background: #e9ecef;
    color: #495057;
    font-weight: 600;
}

.operator-btn:hover {
    background: #dee2e6;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Plus button - spans 2 rows */
.keys .plus-btn {
    grid-column: 4;
    grid-row: 3 / span 2;
    height: 100%;
}

/* Minus button - column 5, row 3 */
.minus-btn {
    grid-column: 5;
    grid-row: 3;
}

/* Clear button */
.clear-btn {
    background: #f8d7da;
    color: #721c24;
    font-weight: 600;
}

.clear-btn:hover {
    background: #f1b0b7;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Backspace button */
.backspace-btn {
    background: #d1ecf1;
    color: #0c5460;
    font-size: 24px;
    font-weight: 600;
}

.backspace-btn:hover {
    background: #bee5eb;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Equals button */
.equals-btn {
    background: #007bff;
    color: white;
    font-size: 24px;
    font-weight: 600;
    grid-column: 5;
    grid-row: 4;
}

.equals-btn:hover {
    background: #0056b3;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Undo/Redo buttons */
.undo-redo-btn {
    background: #6c757d;
    color: white;
    font-weight: 600;
    height: 55px;
}

.undo-redo-btn:hover:not(:disabled) {
    background: #5a6268;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.undo-redo-btn:disabled {
    background: #e9ecef;
    color: #adb5bd;
    cursor: not-allowed;
    box-shadow: none;
}

/* History section */
#copyLogBtn {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    touch-action: manipulation;
}

#copyLogBtn:hover {
    background: #218838;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

#importLogArea {
    width: 100%;
    height: 100px;
    margin-bottom: 15px;
    resize: vertical;
    padding: 12px;
    border: 2px solid #e1e8ed;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    transition: all 0.3s ease;
}

#importLogArea:focus {
    outline: none;
    border-color: #007bff;
    background: #f8f9fa;
}

#importLogBtn {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    touch-action: manipulation;
}

#importLogBtn:hover {
    background: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.event-log {
    font-size: 13px;
    color: #2d3436;
    max-height: 400px;
    overflow-y: auto;
    border: 2px solid #e1e8ed;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
}

.event-log::-webkit-scrollbar {
    width: 8px;
}

.event-log::-webkit-scrollbar-track {
    background: #e1e8ed;
    border-radius: 10px;
}

.event-log::-webkit-scrollbar-thumb {
    background: #b2bec3;
    border-radius: 10px;
}

.event-log::-webkit-scrollbar-thumb:hover {
    background: #95afc0;
}

.event-log div {
    padding: 6px 0;
    border-bottom: 1px solid #e1e8ed;
}

.event-log div:last-child {
    border-bottom: none;
}

.event-log .undone {
    color: #b2bec3;
    opacity: 0.6;
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        padding: 15px;
    }

    .calc-section,
    .history-section {
        padding: 20px;
    }

    .calc-section {
        max-width: 100%;
    }

    .keys button {
        height: 70px;
        font-size: 22px;
    }

    .equals-btn {
        font-size: 30px;
    }

    #result {
        font-size: 36px;
        height: 80px;
    }

    .calc-section h2,
    .history-section h2 {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .keys button {
        height: 60px;
        font-size: 18px;
    }

    .equals-btn {
        font-size: 26px;
    }

    #result {
        font-size: 28px;
        height: 70px;
    }

    .undo-redo-btn {
        height: 50px;
        font-size: 14px;
    }
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    pointer-events: none;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: #28a745;
}

.toast.error {
    background: #dc3545;
}
