:root {
    --body: #3b3632;
    --body-edge: #2a2623;
    --lcd: #c9cdb6;
    --ink: #22251c;
    --key: #4a4440;
    --key-top: #f1ece2;
    --key-num: #e6e0d4;
    --equals: #f0c419;
    --muted: #8a827a;
    --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

body {
    background: #e7e3dc;
    color: var(--key-top);
    font-family: var(--font-main);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calculator-container {
    width: 340px;
    background: var(--body);
    border-radius: 14px;
    padding: 20px 20px 14px;
    box-shadow: 0 1px 0 rgba(255,255,255,0.08) inset, 0 18px 40px -18px rgba(40, 30, 20, 0.6);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.calc-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0 2px;
}

.logo-text { font-weight: 600; font-size: 0.85rem; color: var(--key-top); }
.model-no { font-size: 0.7rem; color: var(--muted); }

.display-panel {
    background: var(--lcd);
    color: var(--ink);
    border-radius: 4px;
    padding: 12px 14px;
    min-height: 128px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
    border: 2px solid var(--body-edge);
    overflow: hidden;
}

.history-layer {
    width: 100%;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    text-align: right;
    margin-bottom: 6px;
    max-height: 56px;
    overflow-y: auto;
    scrollbar-width: none;
}
.history-layer::-webkit-scrollbar { display: none; }

.input-layer { width: 100%; text-align: right; }

.expression-preview {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    opacity: 0.65;
    min-height: 1.2em;
    margin-bottom: 4px;
}

.current-value {
    font-family: var(--font-mono);
    font-size: 2.8rem;
    font-variant-numeric: tabular-nums;
    word-break: break-all;
    line-height: 1;
}

.controls-panel { display: flex; flex-direction: column; }

.mode-toggle {
    display: flex;
    gap: 2px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--body-edge);
}

.mode-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font: 500 0.8rem var(--font-main);
    padding: 6px;
    cursor: pointer;
}
.mode-btn.active { color: var(--key-top); border-bottom-color: var(--equals); }

.sci-keypad-wrapper {
    display: grid;
    grid-template-rows: 0fr;
    overflow: hidden;
    visibility: hidden;
    transition: grid-template-rows 0.25s ease, margin 0.25s ease;
}
.sci-mode .sci-keypad-wrapper { grid-template-rows: 1fr; visibility: visible; margin-bottom: 10px; }
.sci-grid-content { min-height: 0; }

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

.key {
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--key);
    color: var(--key-top);
    font: 400 1.15rem var(--font-main);
    cursor: pointer;
    user-select: none;
    box-shadow: 0 2px 0 var(--body-edge);
    justify-self: center;
    width: 56px;
}
.key:hover { filter: brightness(1.1); }
.key:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--body-edge); }

.num-key { background: var(--key-num); color: var(--ink); }
.sci-key { height: 40px; width: 100%; border-radius: 6px; font-size: 0.85rem; }
.func-key { font-size: 0.85rem; color: #f1a38f; }
.op-key { font-size: 1.3rem; }
.equals-key { background: var(--equals); color: var(--ink); font-size: 1.4rem; }

.double { grid-column: span 2; width: 100%; border-radius: 28px; text-align: left; padding-left: 22px; }

.calculator-footer {
    display: flex;
    gap: 14px;
    justify-content: center;
    font-size: 0.72rem;
    color: var(--muted);
    padding-top: 4px;
}
.calculator-footer a { color: var(--muted); }
.calculator-footer a:hover { color: var(--key-top); }

@media (max-width: 480px) {
    body { align-items: stretch; }
    .calculator-container { width: 100%; border-radius: 0; justify-content: flex-end; }
    .key { width: 64px; height: 64px; }
    .double { width: 100%; }
}
@media (max-width: 480px) { .sci-key { height: 44px; width: 100%; } }
