/* 计算器 (resources/views/calculator.blade.php, js/calculator.js): a white page, the screen as a card at the top,
   the Casio-style keys below — light function keys, darker digit keys, Cerdek orange for =. */
.page-calc {
    --ck-fn: #f4f2ef;
    --ck-fn-ink: #2a2733;
    --ck-digit: #e9e6e1;
    --ck-op-ink: #e0641c;
    --ck-alt: #b8860b;
    --ck-eq: #f26a1b;
    --calc-card: #ffffff;
    --calc-line: #ece9e4;
    --calc-muted: #8d8794;
}
.page-calc .chat-main { background: #fff; }
.page-calc .dock { display: none !important; } /* a tool page: the keys need the room */

.calc { position: relative; flex: 1 1 auto; display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 520px;
    min-height: 0; overflow-y: auto; margin: 0 auto; padding: 4px 14px calc(14px + env(safe-area-inset-bottom, 0px)); box-sizing: border-box; }

/* ---- screen ---- */
.calc-screen { position: relative; flex: 1 0 auto; display: flex; flex-direction: column; padding: 14px 16px 10px;
    border: 1px solid var(--calc-line); border-radius: 22px; background: var(--calc-card); }
.calc-status { display: flex; gap: 6px; justify-content: flex-end; min-height: 16px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: var(--calc-muted); }
.calc-flag-shift, .calc-flag-mem { display: none; }
.calc.is-shift .calc-flag-shift { display: inline; color: var(--ck-alt); }
.calc.has-mem .calc-flag-mem { display: inline; }
.calc-expr { flex: 1 1 auto; display: flex; align-items: center; min-height: 52px; overflow-x: auto; overflow-y: hidden; padding: 4px 0;
    font-size: 26px; line-height: 1.3; color: #1f1d23; white-space: nowrap; scrollbar-width: none; cursor: text; }
.calc-expr::-webkit-scrollbar { display: none; }
.calc-expr .katex { font-size: 1em; }
.calc-result { min-height: 40px; overflow-x: auto; text-align: right; font-size: 22px; line-height: 1.6; color: var(--calc-muted); white-space: nowrap; scrollbar-width: none; }
.calc-result::-webkit-scrollbar { display: none; }
.calc-result .katex { font-size: 1em; }
.calc-result.is-final { font-size: 32px; font-weight: 700; color: #1f1d23; }
.calc-result.is-hint { font-size: 14px; line-height: 40px; color: var(--ck-op-ink); }
.calc-result.is-error { font-size: 14px; line-height: 40px; color: #d33f36; }
.calc-tools { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--calc-line); }
.calc-tool { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 0; border-radius: 17px; background: var(--ck-fn);
    color: var(--ck-fn-ink); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.calc-tool .material-symbols-outlined { --icon-size: 18px; font-size: 18px; }
.calc-ai { background: #fff1e8; color: #c2520f; }
.calc:not(.has-expr) .calc-ai { opacity: 0.55; }

/* ---- keys ---- */
.calc-pad { flex: 0 0 auto; display: flex; flex-direction: column; gap: clamp(14px, 2.2vh, 20px); }
/* The SHIFT functions are printed in the gaps above the keys (as on the Casio), so each key carries one label. */
.calc-fn { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(17px, 2.3vh, 20px) 8px; padding-top: 14px; }
.calc-num { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.ck { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 0; border: 0; border-radius: 13px;
    background: var(--ck-fn); color: var(--ck-fn-ink); font: inherit; cursor: pointer; user-select: none; -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; touch-action: manipulation;
    transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.16s, background-color 0.15s, opacity 0.15s; }
/* Pressed: dips and darkens at once (js adds .is-down on pointerdown), springs back on release. */
.ck:active, .ck.is-down { transform: scale(0.92); filter: brightness(0.92); transition-duration: 0.05s; }
.calc-tool { transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.16s; -webkit-tap-highlight-color: transparent; }
.calc-tool:active, .calc-tool.is-down { transform: scale(0.95); filter: brightness(0.94); transition-duration: 0.05s; }
:root[data-theme="dark"] .ck:active, :root[data-theme="dark"] .ck.is-down,
:root[data-theme="dark"] .calc-tool:active, :root[data-theme="dark"] .calc-tool.is-down { filter: brightness(1.25); }
@media (prefers-reduced-motion: reduce) { .ck:active, .ck.is-down, .calc-tool:active, .calc-tool.is-down { transform: none; } }
.ck-fn { height: clamp(28px, 4.6vh, 40px); font-size: 15.5px; font-weight: 600; }
.calc-num .ck { height: clamp(40px, 6.4vh, 56px); border-radius: 15px; font-size: 22px; font-weight: 600; }
.ck-main { display: inline-block; line-height: 1.1; white-space: nowrap; }
.ck sup { font-size: 0.62em; line-height: 0; vertical-align: 0.6em; }
.ck .material-symbols-outlined { --icon-size: 22px; font-size: 22px; }
/* The SHIFT function, small and gold just above the key. */
.ck-alt { position: absolute; bottom: calc(100% + 3px); left: -4px; right: -4px; font-size: 10px; font-weight: 700; line-height: 1.2; letter-spacing: 0.01em;
    color: var(--ck-alt); text-align: center; white-space: nowrap; pointer-events: none; }
.ck-alt sup { font-size: 0.75em; vertical-align: 0.45em; }
.ck-box { display: inline-block; width: 0.62em; height: 0.62em; border: 1.5px dashed currentColor; border-radius: 2px; opacity: 0.7; vertical-align: -0.05em; box-sizing: border-box; }
sup .ck-box { width: 0.8em; height: 0.8em; }
.ck-frac { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; vertical-align: middle; }
.ck-frac .ck-box { width: 10px; height: 8px; }
.ck-bar { display: block; width: 14px; height: 1.5px; background: currentColor; border-radius: 1px; }
.ck-var { font-family: "KaTeX_Math", "Times New Roman", serif; font-size: 1.2em; font-style: italic; font-weight: 400; }
.ck-sm { font-size: 0.72em; font-style: normal; }
.ck-shift { padding-top: 0; font-size: 12.5px; font-weight: 800; letter-spacing: 0.02em; color: #8a6a00; background: #fbf0cf; }
.ck-shift.is-on { background: #f6c443; color: #3d2c00; }
.ck-nav { padding-top: 0; }
.ck-mode { padding-top: 0; font-size: 12.5px; letter-spacing: 0.02em; }
.ck-sd { padding-top: 0; font-size: 13px; }
.ck-sd.is-on { background: #e7f3ea; color: #1f7a3d; }
.ck-digit { background: var(--ck-digit); color: #1f1d23; }
.ck-op { color: var(--ck-op-ink); font-size: 26px !important; }
.ck-del { color: #4a4552; }
.ck-ac { background: #fdeceb; color: #d33f36; font-size: 18px !important; font-weight: 700 !important; }
.ck-exp { font-size: 15px !important; }
.ck-ans { font-size: 16px !important; }
.ck-eq { background: var(--ck-eq); color: #fff; font-size: 28px !important; }

/* SHIFT on: keys with a second function show it big; the others step back. */
.calc.is-shift .ck[data-shift] .ck-main { display: none; }
.calc.is-shift .ck[data-shift] .ck-alt { position: static; font-size: 14px; color: #8a6200; }
.calc.is-shift .ck[data-shift] { padding-top: 0; background: #fdf3d6; }
.calc.is-shift .calc-num .ck[data-shift] .ck-alt { font-size: 20px; }
.calc.is-shift .ck:not([data-shift]):not(.ck-shift) { opacity: 0.4; }

/* ---- toast ---- */
.calc-toast { position: absolute; left: 50%; top: 12px; z-index: 5; max-width: calc(100% - 40px); padding: 8px 14px; border-radius: 12px;
    background: rgba(31, 29, 35, 0.9); color: #fff; font-size: 13px; opacity: 0; transform: translate(-50%, -6px); pointer-events: none;
    transition: opacity 0.2s, transform 0.2s; }
.calc-toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 901px) {
    .calc { padding-top: 16px; }
    .calc-screen { min-height: 180px; }
}
@media (max-height: 700px) {
    .calc { gap: 8px; }
    .calc-screen { padding: 10px 14px 8px; }
    .calc-expr { min-height: 40px; }
    .calc-result { min-height: 32px; }
    .calc-result.is-hint, .calc-result.is-error { line-height: 32px; }
    .calc-tools { margin-top: 4px; padding-top: 8px; }
    .calc-tool { height: 30px; }
}

/* ---- dark ---- */
:root[data-theme="dark"] .page-calc {
    --ck-fn: #26262a;
    --ck-fn-ink: #e6e4ea;
    --ck-digit: #33333a;
    --ck-op-ink: #ff8a45;
    --ck-alt: #e0b54a;
    --calc-card: #1c1c1f;
    --calc-line: #303035;
    --calc-muted: #9a96a2;
}
:root[data-theme="dark"] .page-calc .chat-main { background: var(--bg); }
:root[data-theme="dark"] .calc-expr, :root[data-theme="dark"] .calc-result.is-final, :root[data-theme="dark"] .ck-digit { color: #f2f0f5; }
:root[data-theme="dark"] .ck-shift { background: #3a3220; color: #f0c85a; }
:root[data-theme="dark"] .ck-shift.is-on { background: #e0b54a; color: #2a1f00; }
:root[data-theme="dark"] .ck-del { color: #cfcbd6; }
:root[data-theme="dark"] .ck-ac { background: #3a2222; color: #ff7a70; }
:root[data-theme="dark"] .ck-sd.is-on { background: #1f3326; color: #7fd69a; }
:root[data-theme="dark"] .calc-ai { background: #3a2616; color: #ffad73; }
:root[data-theme="dark"] .calc.is-shift .ck[data-shift] { background: #3a3220; }
:root[data-theme="dark"] .calc.is-shift .ck[data-shift] .ck-alt { color: #f0c85a; }
