:root {
    --bg: #0a0a0f;
    --surface: #121218;
    --surface-2: #1a1a22;
    --accent: #00f0ff;
    --accent-dark: #00c4d4;
    --text: #f0f0f5;
    --text-secondary: #8a8a9a;
    --border: #25252e;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    -webkit-font-smoothing: antialiased;
}

.container {
    display: flex;
    gap: 28px;
    align-items: flex-start;
}

.calculator {
    width: 420px;
    background: var(--surface);
    border-radius: 24px;
    padding: 22px 20px 20px;
    box-shadow: 
        0 30px 70px -15px rgba(0, 0, 0, 0.65),
        0 0 0 1px var(--border);
    border: 1px solid var(--border);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 4px;
}

.title {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.logo {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--accent);
}

.subtitle {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 6px #22c55e;
}

.display {
    background: #0f0f15;
    border-radius: 16px;
    padding: 18px 20px 16px;
    margin-bottom: 18px;
    min-height: 108px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    border: 1px solid var(--border);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.7);
    position: relative;
}

.display::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.05), transparent);
}

.expression {
    font-size: 14px;
    color: var(--text-secondary);
    min-height: 20px;
    text-align: right;
    font-feature-settings: "tnum";
    margin-bottom: 2px;
    word-break: break-all;
    opacity: 0.85;
}

.result {
    font-size: 42px;
    font-weight: 600;
    line-height: 1;
    text-align: right;
    font-feature-settings: "tnum";
    color: var(--text);
    transition: all 0.1s ease;
    letter-spacing: -1.5px;
    min-height: 48px;
    word-break: break-all;
    overflow: hidden;
}

.result.updated {
    animation: resultPop 0.18s cubic-bezier(0.23, 1, 0.32, 1);
}

@keyframes resultPop {
    0% { transform: scale(0.94); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

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

.btn {
    height: 52px;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.08s cubic-bezier(0.23, 1, 0.32, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    border: 1px solid transparent;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn:hover {
    filter: brightness(1.1);
}

.btn:active {
    transform: scale(0.92);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn.number {
    background: var(--surface-2);
    color: var(--text);
    font-weight: 500;
}

.btn.number:hover {
    background: #22222a;
}

.btn.operator {
    background: #1f1f28;
    color: var(--accent);
    font-size: 22px;
}

.btn.operator:hover {
    background: #282832;
}

.btn.operator.active-operator,
.btn.operator.active-operator:hover {
    background: var(--accent);
    color: #0a0a0f;
    box-shadow: 0 0 0 1px var(--accent);
}

.btn.function {
    background: #1f1f28;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
}

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

.btn.memory {
    background: #1a1a22;
    color: #a5a5b5;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.btn.memory:hover {
    background: #22222a;
    color: var(--text);
}

.btn.paren {
    background: #1f1f28;
    color: var(--text-secondary);
    font-size: 20px;
    font-weight: 400;
}

.btn.paren:hover {
    background: #282832;
}

.btn.equals {
    background: linear-gradient(145deg, #00f0ff, #00c4d4);
    color: #0a0a0f;
    font-size: 22px;
    font-weight: 700;
    box-shadow: 0 4px 14px rgba(0, 240, 255, 0.35);
    height: 52px;
}

.btn.equals:hover {
    filter: brightness(1.08);
    box-shadow: 0 6px 18px rgba(0, 240, 255, 0.45);
}

.btn.equals:active {
    transform: scale(0.93);
}

/* Zero no longer spans to keep grid clean */

.history-panel {
    width: 210px;
    background: var(--surface);
    border-radius: 20px;
    border: 1px solid var(--border);
    padding: 18px;
    height: fit-content;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.4);
}

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

.history-header span {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.clear-history {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.clear-history:hover {
    background: var(--surface-2);
    color: var(--text);
}

.history-list {
    max-height: 320px;
    overflow-y: auto;
    font-size: 13px;
}

.history-empty {
    color: var(--text-secondary);
    font-size: 12px;
    padding: 12px 4px;
    opacity: 0.6;
}

.history-item {
    padding: 10px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.1s ease;
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.history-item:hover {
    background: var(--surface-2);
    border-color: var(--border);
}

.history-expression {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 2px;
}

.history-result {
    color: var(--text);
    font-weight: 600;
    font-feature-settings: "tnum";
}

/* Scrollbar */
.history-list::-webkit-scrollbar {
    width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
    background: #33333a;
    border-radius: 4px;
}

/* Responsive */
@media (max-width: 680px) {
    .container {
        flex-direction: column;
        align-items: center;
    }
    
    .history-panel {
        width: 100%;
        max-width: 380px;
    }
}

/* Subtle animation on result update */
.result.updated {
    animation: resultPop 0.2s ease;
}

@keyframes resultPop {
    0% { transform: scale(0.96); }
    100% { transform: scale(1); }
}
