/* ------------------------------------------------------------------
   Transum Scientific Calculator
   Layout follows the key positions of a popular UK classroom
   scientific calculator so that a teacher can point at the same place
   on screen as pupils see on the desk. All artwork, colours, wording
   and code are original Transum work.
   ------------------------------------------------------------------ */

.tcalc-page {
    box-sizing: border-box;
    margin: 0;
    padding: 2rem 1rem;
    background: #f2f2f3;
    font-family: "Segoe UI", Arial, Helvetica, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
}

/* ------------------------------ shell ------------------------------ */

.tcalc {
    --tcalc-max: 430px;
    --red: #c8102e;
    --red-lt: #e2455c;
    --red-dk: #8d0a20;
    --pink: #f09aa6;
    --g900: #17181a;
    --g800: #232528;
    --g700: #303337;
    --g600: #414549;
    --g500: #565b61;
    --g400: #6d737a;
    --g150: #dfe1e4;
    --g100: #eef0f2;
    --lcd: #cfd6ce;
    --lcd-ink: #14211a;

    box-sizing: border-box;
    width: 100%;
    max-width: var(--tcalc-max);
    margin: 0 auto;
    padding: 0.85em 0.8em 1.05em;
    border-radius: 1.6em;
    background: linear-gradient(160deg, #45494f 0%, #2b2e32 38%, #1d1f22 100%);
    box-shadow: 0 1.4em 2.4em rgba(0, 0, 0, 0.34),
                0 0 0 1px rgba(255, 255, 255, 0.06) inset;
    font-size: 14px;         /* reset by script to scale the whole unit */
    line-height: 1.15;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.tcalc *,
.tcalc *::before,
.tcalc *::after { box-sizing: border-box; }

/* ------------------------------ brand ------------------------------ */

.tcalc-brand {
    display: flex;
    align-items: baseline;
    gap: 0.6em;
    padding: 0.1em 0.35em 0.7em;
}

.tcalc-word {
    font-size: 1.5em;
    font-weight: 800;
    letter-spacing: 0.24em;
    color: #fff;
    text-shadow: 0 0.06em 0 rgba(0, 0, 0, 0.5);
    border-bottom: 0.18em solid var(--red);
    padding-bottom: 0.06em;
}

.tcalc-sub {
    font-size: 0.72em;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #9aa0a7;
    margin-left: auto;
}

/* ------------------------------- LCD ------------------------------- */

.tcalc-lcd {
    position: relative;
    background: linear-gradient(180deg, #d7ded6 0%, #c6cec5 100%);
    color: var(--lcd-ink);
    border-radius: 0.55em;
    border: 0.28em solid #101113;
    box-shadow: 0 0.1em 0 rgba(255, 255, 255, 0.08),
                inset 0 0.15em 0.4em rgba(0, 0, 0, 0.22);
    padding: 0.35em 0.5em 0.4em;
    min-height: 7.8em;
    display: flex;
    flex-direction: column;
    font-family: "Lucida Sans Unicode", "Segoe UI", Arial, sans-serif;
    overflow: hidden;
}

.lcd-status {
    font-size: 0.66em;
    letter-spacing: 0.06em;
    height: 1.5em;
    display: flex;
    gap: 0.9em;
    align-items: center;
    border-bottom: 1px solid rgba(20, 33, 26, 0.22);
    margin-bottom: 0.25em;
    white-space: nowrap;
    overflow: hidden;
}

.lcd-status .st { opacity: 0.85; }
.lcd-status .st-on { font-weight: 700; opacity: 1; }
.lcd-status .st-shift {
    background: var(--red);
    color: #fff;
    border-radius: 0.25em;
    padding: 0 0.4em;
}

.lcd-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 0;
}

.lcd-input {
    font-size: 1.05em;
    min-height: 1.9em;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    padding-top: 0.15em;
}
.lcd-input::-webkit-scrollbar { height: 0; }

.lcd-answer {
    font-size: 1.35em;
    text-align: right;
    min-height: 1.6em;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    padding-bottom: 0.1em;
}
.lcd-answer::-webkit-scrollbar { height: 0; }

.lcd-answer .err { color: #8d0a20; font-weight: 700; font-size: 0.85em; }

/* blinking cursor */
.cur {
    display: inline-block;
    width: 0.09em;
    min-width: 1px;
    height: 1.15em;
    background: var(--lcd-ink);
    vertical-align: -0.2em;
    margin: 0 0.02em;
    animation: tcalc-blink 1.05s step-end infinite;
}
@keyframes tcalc-blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }

/* natural (textbook) maths rendering */
.ph { opacity: 0.55; }

.mfrac {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 0.14em;
    font-size: 0.92em;
    position: relative;
    top: -0.05em;
}
.mfrac > .num {
    border-bottom: 0.075em solid currentColor;
    padding: 0 0.22em 0.04em;
    line-height: 1.05;
}
.mfrac > .den { padding: 0.04em 0.22em 0; line-height: 1.05; }

.mmix { display: inline-flex; align-items: center; }
.mmix > .whole { margin-right: 0.06em; }

.msqrt { display: inline-flex; align-items: stretch; margin: 0 0.06em; }
.msqrt > .rsym {
    font-size: 1.15em;
    line-height: 1;
    align-self: flex-end;
    transform: scaleX(0.8);
}
.msqrt > .rbody {
    border-top: 0.075em solid currentColor;
    padding: 0.1em 0.16em 0 0.1em;
}
.msqrt > .ridx {
    font-size: 0.6em;
    align-self: flex-start;
    margin-right: -0.35em;
    position: relative;
    top: -0.1em;
}

.msup { font-size: 0.68em; vertical-align: super; line-height: 1; }
.msub { font-size: 0.62em; vertical-align: sub; line-height: 1; }

.recur { border-top: 0.09em solid currentColor; }

/* menus drawn inside the display */
.lcd-menu,
.lcd-msg {
    display: none;
    position: absolute;
    left: 0; right: 0; top: 0; bottom: 0;
    background: linear-gradient(180deg, #d7ded6 0%, #c6cec5 100%);
    padding: 0.3em 0.45em;
    flex-direction: column;
}
.lcd-menu.show, .lcd-msg.show { display: flex; }

.menu-title {
    font-size: 0.72em;
    font-weight: 700;
    letter-spacing: 0.05em;
    background: var(--lcd-ink);
    color: var(--lcd);
    border-radius: 0.2em;
    padding: 0.15em 0.45em;
    margin-bottom: 0.2em;
    display: flex;
    justify-content: space-between;
}

.menu-list { flex: 1 1 auto; overflow: hidden; }

.menu-item {
    font-size: 0.8em;
    padding: 0.09em 0.3em;
    display: flex;
    gap: 0.45em;
    border-radius: 0.2em;
    cursor: pointer;
    white-space: nowrap;
}
.menu-item .mi-val { margin-left: auto; opacity: 0.75; }
.menu-item.sel { background: var(--lcd-ink); color: var(--lcd); }
.menu-item.sel .mi-val { opacity: 0.85; }

.lcd-msg {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 0.9em 1.2em;
}
.lcd-msg .msg-box { font-size: 0.84em; line-height: 1.45; }
.lcd-msg .msg-hint { font-size: 0.66em; margin-top: 0.7em; opacity: 0.65; }

.tcalc-lcd.is-off { background: #6f766e; }
.tcalc-lcd.is-off .lcd-status,
.tcalc-lcd.is-off .lcd-main { visibility: hidden; }

/* ----------------------------- keypads ----------------------------- */

.kb {
    display: grid;
    gap: 0.34em 0.3em;
    margin-top: 0.5em;
}

.kb-nav   { grid-template-columns: repeat(6, 1fr); }
.kb-six   { grid-template-columns: repeat(6, 1fr); margin-top: 0.75em; }
.kb-five  { grid-template-columns: repeat(5, 1fr); }

.kb-nav [data-pos="on"]       { grid-column: 1; grid-row: 1; }
.kb-nav [data-pos="home"]     { grid-column: 2; grid-row: 1; }
.kb-nav [data-pos="up"]       { grid-column: 4; grid-row: 1; }
.kb-nav [data-pos="pgup"]     { grid-column: 6; grid-row: 1; }
.kb-nav [data-pos="settings"] { grid-column: 1; grid-row: 2; }
.kb-nav [data-pos="back"]     { grid-column: 2; grid-row: 2; }
.kb-nav [data-pos="left"]     { grid-column: 3; grid-row: 2; }
.kb-nav [data-pos="ok"]       { grid-column: 4; grid-row: 2; }
.kb-nav [data-pos="right"]    { grid-column: 5; grid-row: 2; }
.kb-nav [data-pos="pgdn"]     { grid-column: 6; grid-row: 2; }
.kb-nav [data-pos="mshift"]   { grid-column: 1; grid-row: 3; }
.kb-nav [data-pos="mvar"]     { grid-column: 2; grid-row: 3; }
.kb-nav [data-pos="mfun"]     { grid-column: 3; grid-row: 3; }
.kb-nav [data-pos="down"]     { grid-column: 4; grid-row: 3; }
.kb-nav [data-pos="mcat"]     { grid-column: 5; grid-row: 3; }
.kb-nav [data-pos="mtool"]    { grid-column: 6; grid-row: 3; }

/* a cell = tiny shift caption printed above the key, then the key */
.kcell { display: flex; flex-direction: column; min-width: 0; }

.shift {
    font-size: 0.8em;
    font-weight: 600;
    line-height: 1.2;
    height: 1.5em;
    text-align: center;
    color: var(--pink);
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: visible;
    cursor: pointer;
}
.shift[data-shift]:hover { color: #fff; }
.shift-off { color: #cfd3d8; }
.shift i { font-family: Georgia, "Times New Roman", serif; font-style: italic; }
.shift sup { font-size: 0.72em; }

.key {
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 2.75em;
    padding: 0 0.15em;
    border: 0;
    border-radius: 0.45em;
    font-family: inherit;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 0.16em 0 rgba(0, 0, 0, 0.45), 0 0.2em 0.35em rgba(0, 0, 0, 0.28);
    transition: transform 0.05s linear, filter 0.12s linear;
}

.key:focus { outline: none; }
.key:focus-visible { outline: 0.14em solid #ffd7de; outline-offset: 0.12em; }
.key:hover { filter: brightness(1.1); }
.key:active, .key.is-down {
    transform: translateY(0.13em);
    box-shadow: 0 0.03em 0 rgba(0, 0, 0, 0.45);
    filter: brightness(1.22);
}

.key .face { pointer-events: none; text-align: center; }
.key .face i { font-family: Georgia, "Times New Roman", serif; font-style: italic; }
.key sup { font-size: 0.62em; vertical-align: super; }
.key sub { font-size: 0.6em; vertical-align: sub; }
.key.k-word .face { font-size: 0.6em; letter-spacing: 0.04em; }

.face.dbl { display: flex; flex-direction: column; line-height: 0.62; font-size: 0.72em; }

/* mini fraction drawn on the fraction key (squares are drawn, not typed,
   so that the gaps above and below the bar can be made equal) */
.mf {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    line-height: 1;
    vertical-align: middle;
}
.mf .mfx { padding: 0 0.3em 0.2em; border-bottom: 0.09em solid currentColor; }
.mf .mfy { padding: 0.2em 0.3em 0; }
.mf .sq {
    display: block;
    width: 0.62em;
    height: 0.62em;
    border: 0.09em solid currentColor;
}
.mfw { display: inline-flex; align-items: center; gap: 0.14em; }
.mfw .sqf {
    display: inline-block;
    width: 0.5em;
    height: 0.5em;
    background: currentColor;
}
.shift .mf .sq { width: 0.5em; height: 0.5em; border-width: 0.08em; }
.shift .mf .mfx { padding: 0 0.2em 0.14em; }
.shift .mf .mfy { padding: 0.14em 0.2em 0; }

/* the navigation and menu blocks carry no shifted captions */
.kb-nav .shift { height: 0.4em; }

/* key colours */
.k-num {
    background: linear-gradient(180deg, #f6f7f8 0%, #dcdfe3 100%);
    color: #17181a;
}
.k-fn {
    background: linear-gradient(180deg, #55595f 0%, #3a3e43 100%);
    color: #f3f4f6;
}
.k-edit {
    background: linear-gradient(180deg, #7b8188 0%, #5a6067 100%);
    color: #fff;
}
.k-op {
    background: linear-gradient(180deg, #55595f 0%, #3a3e43 100%);
    color: #fff;
}
.k-op .face { font-size: 1.2em; }
.k-nav {
    background: linear-gradient(180deg, #838a92 0%, #5f666e 100%);
    color: #fff;
}
.k-ok {
    background: linear-gradient(180deg, #9aa2ab 0%, #6f767f 100%);
}
.k-ok .face { font-size: 0.85em; letter-spacing: 0.05em; }
.k-shift {
    background: linear-gradient(180deg, #e2455c 0%, #b60d28 100%);
    color: #fff;
}
.k-ac {
    background: linear-gradient(180deg, #f2f3f4 0%, #d7dade 100%);
    color: var(--red-dk);
    font-weight: 800;
}
.k-exe {
    background: linear-gradient(180deg, #d8213c 0%, #9e0c22 100%);
    color: #fff;
    font-weight: 800;
}
.k-exe .face { font-size: 1.35em; }

/* shift armed: give the shifted captions prominence */
.tcalc.shift-on .shift[data-shift] {
    color: #fff;
    text-shadow: 0 0 0.5em rgba(226, 69, 92, 0.9);
}
.tcalc.shift-on .k-shift {
    background: linear-gradient(180deg, #fff 0%, #f1c3ca 100%);
    color: var(--red-dk);
}

/* the floating-window version: trim the page padding and let the script
   scale the calculator to the height of the window */
.tcalc-page.tcalc-popup {
    padding: 6px;
    align-items: center;
}
.tcalc-page.tcalc-popup .tcalc { --tcalc-max: 100%; }

/* small print */
.tcalc-note {
    margin: 1.1em 0.2em 0;
    font-size: 0.5em;
    line-height: 1.45;
    text-align: center;
    color: #8a9098;
    letter-spacing: 0.01em;
}

@media (prefers-reduced-motion: reduce) {
    .cur { animation: none; }
    .key { transition: none; }
}
