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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', 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;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.calculator {
    width: 340px;
    height: 640px;
    background: #1c1c1e;
    border-radius: 40px;
    padding: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Display */
.display {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 10px;
    min-height: 100px;
    max-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    overflow: hidden;
}

.expression {
    color: rgba(255, 255, 255, 0.5);
    font-size: 70px;
    min-height: 0;
    max-height: none;
    white-space: normal;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: right;
    width: 100%;
    margin-bottom: 4px;
    scrollbar-width: none;
    line-height: 1.05;
    transition: none;
}

.expression::-webkit-scrollbar {
    display: none;
}

.result {
    color: #ffffff;
    font-size: 140px;
    font-weight: 480;
    line-height: 1.05;
    max-height: none;
    white-space: normal;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: right;
    width: 100%;
    scrollbar-width: none;
    transition: none;
}

.result::-webkit-scrollbar {
    display: none;
}

/* Buttons Grid */
.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
}

.btn {
    height: 55px;
    border: none;
    border-radius: 14px;
    font-size: 20px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

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

.btn.number {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.btn.number:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn.operator {
    background: #0a84ff;
    color: #ffffff;
}

.btn.operator:hover {
    background: #409cff;
}

.btn.operator:active {
    background: #0070e0;
}

.btn.action {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.btn.action:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn.func {
    background: rgba(10, 132, 255, 0.2);
    color: #5ac8fa;
    font-size: 22px;
}

.btn.func:hover {
    background: rgba(10, 132, 255, 0.3);
}

/* History Panel */
.history-panel {
    background: rgba(30, 30, 30, 0.95);
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.history-panel.open {
    max-height: 300px;
    padding: 16px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.history-header h3 {
    color: #ffffff;
    font-size: 16px;
    font-weight: 600;
}

.clear-history {
    background: none;
    border: none;
    color: #ff6b6b;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}

.clear-history:hover {
    background: rgba(255, 107, 107, 0.15);
}

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

.history-item {
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: opacity 0.2s;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item:hover {
    opacity: 0.7;
}

.history-expr {
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
}

.history-result {
    color: #ffffff;
    font-size: 18px;
    font-weight: 400;
    margin-top: 2px;
}

.history-empty {
    color: rgba(255, 255, 255, 0.3);
    font-size: 14px;
    text-align: center;
    padding: 20px 0;
}

/* Toggle History Button */
.toggle-history {
    background: rgba(30, 30, 30, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-history:hover {
    background: rgba(30, 30, 30, 0.95);
    color: #ffffff;
}

/* Responsive */
@media (max-width: 400px) {
    body {
        padding: 10px;
    }

    .calculator {
        padding: 14px;
        border-radius: 20px;
    }

    .btn {
        height: 50px;
        font-size: 16px;
        border-radius: 12px;
    }

    .buttons {
        gap: 8px;
    }

    .btn.func {
        font-size: 14px;
    }
}

@media (max-width: 340px) {
    .btn {
        height: 46px;
        font-size: 15px;
    }
}
