:root {
    color-scheme: light;
    --page: #eceff1;
    --surface: #fbfcfb;
    --surface-strong: #ffffff;
    --ink: #161a1d;
    --muted: #687076;
    --line: #d7dde0;
    --display: #111418;
    --display-muted: #98a2aa;
    --accent: #1f8a70;
    --accent-strong: #0f6f5a;
    --warm: #e49a28;
    --danger: #c0392b;
    --shadow: 0 18px 50px rgba(17, 20, 24, 0.16);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        linear-gradient(135deg, rgba(31, 138, 112, 0.14), transparent 32%),
        linear-gradient(315deg, rgba(228, 154, 40, 0.12), transparent 34%),
        var(--page);
    font-family: "Segoe UI", Arial, sans-serif;
}

button {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.calculator {
    width: min(100%, 390px);
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.topbar {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: 1.45rem;
    line-height: 1.1;
}

.icon-button {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    border: 1px solid #e7c9bf;
    border-radius: 8px;
    color: var(--danger);
    background: #fff4f1;
    cursor: pointer;
}

.icon-button:focus-visible,
.key:focus-visible {
    outline: 3px solid rgba(31, 138, 112, 0.3);
    outline-offset: 2px;
}

.display {
    min-height: 118px;
    display: flex;
    flex-direction: column;
    justify-content: end;
    gap: 8px;
    margin-bottom: 16px;
    padding: 18px;
    border-radius: 8px;
    color: #fff;
    background: var(--display);
    overflow: hidden;
}

.history {
    min-height: 20px;
    color: var(--display-muted);
    font-size: 0.95rem;
    line-height: 1.2;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result {
    min-height: 44px;
    display: block;
    font-size: clamp(2rem, 10vw, 3rem);
    font-weight: 700;
    line-height: 1;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.key {
    aspect-ratio: 1 / 0.78;
    min-height: 58px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: var(--surface-strong);
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 700;
    transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.key:hover,
.icon-button:hover {
    transform: translateY(-1px);
}

.key:active,
.icon-button:active {
    transform: translateY(1px);
}

.key.function {
    color: #7d530d;
    border-color: #f0d7ac;
    background: #fff7e8;
}

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

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

@media (max-width: 420px) {
    .app-shell {
        padding: 12px;
    }

    .calculator {
        padding: 14px;
    }

    .keypad {
        gap: 8px;
    }

    .key {
        min-height: 54px;
    }
}
