:root {
    color-scheme: light;
    --page: #eef2f7;
    --card: #ffffff;
    --screen: #dc2626;
    --screen-muted: #9ca3af;
    --text: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --key: #f3f4f6;
    --key-hover: #e5e7eb;
    --soft: #e2e8f0;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --equals: #16a34a;
    --equals-hover: #15803d;
    --danger: #dc2626;
    --shadow: 0 24px 70px rgba(15, 23, 42, .12);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--page);
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(37, 99, 235, .10), transparent 28rem),
        var(--page);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.page-shell {
    width: min(980px, calc(100% - 32px));
    margin: 0 auto;
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(320px, 450px) minmax(280px, 1fr);
    gap: 24px;
    align-items: center;
    padding: 34px 0;
}

.calculator-card,
.history-card {
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(255, 255, 255, .8);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.calculator-card {
    padding: 22px;
}

.calculator-header,
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.4px;
    direction: ltr;
}

h1,
h2 {
    margin: 0;
    line-height: 1.2;
}

h1 {
    font-size: 25px;
}

h2 {
    font-size: 20px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 6px rgba(34, 197, 94, .12);
}

.screen {
    min-height: 126px;
    padding: 19px 18px 16px;
    background: var(--screen);
    border-radius: 18px;
    margin-bottom: 16px;
    overflow: hidden;
}

.expression {
    min-height: 24px;
    color: var(--screen-muted);
    text-align: left;
    direction: ltr;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.display {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: #fff;
    text-align: left;
    direction: ltr;
    font-size: clamp(35px, 8vw, 49px);
    font-weight: 700;
    line-height: 1.35;
    padding: 8px 0 0;
}

.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    direction: ltr;
}

.key {
    min-height: 66px;
    border: 0;
    border-radius: 15px;
    background: var(--key);
    color: var(--text);
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .08s ease, background .14s ease, box-shadow .14s ease;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .025);
}

.key:hover {
    background: var(--key-hover);
}

.key:active {
    transform: scale(.96);
}

.key:focus-visible,
.clear-history:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .25);
    outline-offset: 2px;
}

.key-soft {
    background: var(--soft);
    color: #334155;
}

.key-operator {
    background: var(--accent);
    color: #fff;
}

.key-operator:hover,
.key-operator.is-active {
    background: var(--accent-hover);
}

.key-equals {
    background: var(--equals);
    color: #fff;
}

.key-equals:hover {
    background: var(--equals-hover);
}

.key-backspace {
    color: var(--danger);
}

.key[disabled] {
    opacity: .62;
    cursor: wait;
}

.error-message {
    margin: 13px 2px 0;
    color: var(--danger);
    font-size: 13px;
    font-weight: 700;
}

.keyboard-hint {
    margin: 14px 4px 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.7;
}

.history-card {
    align-self: stretch;
    max-height: 690px;
    padding: 22px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.clear-history {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    border-radius: 10px;
    padding: 9px 11px;
    cursor: pointer;
    white-space: nowrap;
}

.clear-history:hover {
    color: var(--danger);
    border-color: #fecaca;
    background: #fef2f2;
}

.history-list {
    min-height: 180px;
    overflow-y: auto;
    padding-left: 3px;
}

.history-item {
    padding: 15px 3px;
    border-bottom: 1px solid var(--line);
}

.history-expression,
.history-result {
    direction: ltr;
    text-align: left;
}

.history-expression {
    color: var(--muted);
    font-size: 14px;
}

.history-result {
    margin-top: 4px;
    font-size: 21px;
    font-weight: 700;
}

.history-item time {
    display: block;
    margin-top: 7px;
    color: #9ca3af;
    font-size: 11px;
    direction: ltr;
    text-align: left;
}

.empty-history {
    min-height: 170px;
    display: grid;
    place-items: center;
    color: var(--muted);
    text-align: center;
    line-height: 1.8;
    border: 1px dashed var(--line);
    border-radius: 15px;
    padding: 20px;
}

@media (max-width: 800px) {
    .page-shell {
        grid-template-columns: 1fr;
        width: min(520px, calc(100% - 22px));
        align-items: start;
        padding: 18px 0 30px;
    }

    .history-card {
        max-height: none;
    }
}

@media (max-width: 430px) {
    .calculator-card,
    .history-card {
        border-radius: 18px;
        padding: 15px;
    }

    .key {
        min-height: 59px;
        border-radius: 13px;
    }

    .screen {
        min-height: 114px;
    }
}
