/* The calculator is an object, so it looks the same in light and dark mode. */
:root {
  --body: #24272f;
  --body-hi: #2c3039;
  --desk: #15171c;
  --key-fn: #31353f;
  --key-fn-lo: #282b33;
  --key-ink: #eef1f6;
  --key-num: #e2e5e9;
  --key-num-lo: #cbd0d6;
  --key-num-ink: #191c22;
  --key-blue: #2f5bd6;
  --key-blue-lo: #2346b5;
  --shift: #f2b941;
  --alpha: #f07ca0;
  --lcd: #c8d2c2;
  --lcd-lo: #b9c4b3;
  --ink: #1b221d;
  --ink-soft: #4b5a4f;
  --brand: #c5cad3;
  --warn: #b3261e;
  /* LCD type: thin pixel letters like the real screen; STIX fills in the few glyphs it lacks (π, Σ). */
  --math: 'DotGothic16', 'STIX Two Text', 'Cambria Math', serif;
  --label: 'Barlow Semi Condensed', 'Roboto Condensed', 'Arial Narrow', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--desk); }
body { overscroll-behavior: none; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

.calc {
  height: 100dvh;
  max-width: 460px;
  max-height: 940px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--body-hi), var(--body) 30%);
  padding: max(10px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
  font-family: var(--label);
  /* Key labels scale with the narrower of width and height so all 52 keys always fit. */
  font-size: clamp(12px, min(4.3vw, 2.15dvh), 19px);
}
@media (min-width: 520px) and (min-height: 700px) {
  body { display: grid; place-items: center; }
  .calc { width: 440px; font-size: clamp(12px, 2.05dvh, 18px); height: min(100dvh - 32px, 900px); border-radius: 28px; box-shadow: 0 0 0 1px #343843, 0 30px 60px rgba(0, 0, 0, .5); }
}

/* ---- brand ---- */
.brand { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 8px; }
.word { height: 1.15em; width: auto; fill: var(--brand); }
.solar { display: flex; gap: 2px; padding: 3px; background: #1a1c21; border-radius: 3px; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .6); }
.solar i { width: 1.15em; height: 1.1em; background: linear-gradient(160deg, #4a3a33, #2b211d 60%, #3c2e28); }

/* ---- screen ---- */
.bezel { background: #16181d; border-radius: 12px; padding: 7px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04); }
.lcd {
  position: relative;
  height: clamp(132px, 22dvh, 220px);
  background: linear-gradient(180deg, var(--lcd), var(--lcd-lo));
  border-radius: 6px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .28);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.status { display: flex; justify-content: space-between; min-height: 1.35em; padding: 4px 8px 0; font-family: var(--label); font-weight: 600; font-size: .78em; }
.status .left, .status .right { display: flex; gap: 6px; }
.ind { font-weight: 700; padding: 0 3px; border-radius: 2px; line-height: 1.25; }
.ind.s { background: var(--ink); color: var(--shift); }
.ind.a { background: var(--ink); color: var(--alpha); }
.ind.ang { border: 1.5px solid var(--ink); padding: 0 3px; line-height: 1.05; }
.ind.ang.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.ind.hist { color: var(--ink-soft); }
.screen { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; font-family: var(--math); }

/* input line and answer */
.in { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding: 2px 10px 0; flex: 1; min-height: 0; }
.in::-webkit-scrollbar { display: none; }
.line { display: inline-flex; align-items: center; white-space: nowrap; font-size: 1.7em; min-height: 1.6em; padding: .4em 0 .3em; }
.out { text-align: right; padding: 0 12px 10px; font-size: 2.15em; white-space: nowrap; overflow-x: auto; scrollbar-width: none; line-height: 1.15; }
.out::-webkit-scrollbar { display: none; }
.out.multi-out { font-size: 1.55em; }
.multi .lbl { font-style: italic; margin-right: .2em; }
.histno { position: absolute; left: 10px; bottom: 8px; font-family: var(--label); font-size: .8em; color: var(--ink-soft); }

/* ---- textbook maths ---- */
.it { display: inline-flex; align-items: center; }
.op { margin: 0 .15em; }
.nw { display: inline-block; width: .32em; text-align: center; overflow: visible; }
.fn { margin-right: .02em; }
.pc { font-style: normal; font-weight: 600; margin: 0 .08em; }
.frac { display: inline-flex; flex-direction: column; align-items: stretch; text-align: center; vertical-align: middle; margin: 0 .1em; font-size: .92em; }
.frac > .num, .frac > .den { display: flex; justify-content: center; align-items: center; padding: 0 .12em; line-height: 1.1; }
.frac > .num { border-bottom: .065em solid currentColor; padding-bottom: .06em; }
.frac > .den { padding-top: .06em; }
.whole { margin-right: .08em; }
.sup { font-size: .66em; display: inline-flex; align-items: center; position: relative; top: -.62em; margin-left: .03em; }
.post { font-size: .66em; position: relative; top: -.55em; }
.sub { font-size: .66em; display: inline-flex; align-items: center; position: relative; top: .5em; }
.root { display: inline-flex; align-items: flex-end; }
.root > .idx { font-size: .55em; margin-right: -.55em; margin-bottom: .75em; z-index: 1; display: inline-flex; }
.rad { display: inline-flex; position: relative; padding-left: .62em; margin-left: .04em; }
.radsign { position: absolute; left: 0; top: 0; width: .66em; height: 100%; overflow: visible; }
.radsign path { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.under { display: inline-flex; align-items: center; border-top: .065em solid currentColor; padding: .06em .1em 0 .06em; }
.abs { display: inline-flex; align-items: center; border-left: .065em solid; border-right: .065em solid; padding: 0 .14em; margin: 0 .08em; }
.paren { display: inline-flex; align-items: center; }
.bigop { display: inline-flex; align-items: center; }
.lims { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; margin-right: .1em; }
.lims .hi, .lims .lo { font-size: .58em; display: inline-flex; align-items: center; }
.lims .sym { font-size: 1.35em; line-height: 1.05; }
.dx { margin-left: .15em; }
.int { display: inline-flex; align-items: center; margin-right: .08em; }
.isym { font-size: 1.6em; line-height: 1; font-style: italic; }
.ilims { display: inline-flex; flex-direction: column; justify-content: space-between; align-self: stretch; font-size: .58em; margin-left: -.05em; gap: .9em; }
.ilims > span { display: inline-flex; align-items: center; }
.at { display: inline-flex; align-items: stretch; }
.at .bar { border-left: .065em solid; margin: 0 .05em; }
.box { display: inline-flex; align-items: center; justify-content: center; min-width: .55em; height: .78em; border: 1.5px dotted var(--ink-soft); margin: 0 .06em; vertical-align: middle; }
.box.has-cur { border-color: var(--ink); }
.cur { display: inline-block; width: 2px; height: 1.05em; background: var(--ink); margin: 0 -1px; animation: blink 1.05s steps(1) infinite; align-self: center; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cur { animation: none; } }

/* error */
.err { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 10px; font-family: var(--label); }
.err-t { font-size: 1.9em; font-weight: 700; }
.err-h { display: flex; flex-direction: column; align-items: center; font-size: .95em; color: var(--ink-soft); font-weight: 600; }

/* MENU modes: grids, solutions, f(x) */
.grid > .lt { font-family: var(--math); font-weight: 400; font-size: 1.1em; }
.grid > .lt sup { font-size: .65em; }
.grid, .sol, .tablef { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.tbl-wrap { flex: 1; min-height: 0; overflow: auto; scrollbar-width: none; padding: 0 8px; }
.tbl { border-collapse: collapse; width: 100%; font-size: 1.05em; }
.tbl th:first-child { width: 1.6em; }
.tbl th { font-family: var(--label); font-weight: 700; font-size: .8em; color: var(--ink-soft); padding: 1px 4px; text-align: center; }
.tbl tr:first-child th { position: sticky; top: 0; background: var(--lcd); color: var(--ink); font-family: var(--math); font-size: .95em; }
.tbl td { border: 1px solid rgba(27, 34, 29, .35); padding: 1px 6px; text-align: right; height: 1.7em; white-space: nowrap; }
.tbl td.sel, .tbl tr.sel td { background: var(--ink); color: var(--lcd); }
.tbl td .frac { font-size: .75em; }
.mhint { font-family: var(--label); font-weight: 600; font-size: .82em; color: var(--ink-soft); padding: 2px 10px 8px; }
.mhint.big { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 1em; text-align: center; }
.mline { flex: 0 0 auto; border-top: 1px solid rgba(27, 34, 29, .3); }
.mline .line { font-size: 1.35em; padding: .3em 0 .2em; }
.sl { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 3px 10px; font-size: 1.25em; min-height: 1.9em; }
.sl .lbl { font-family: var(--math); }
.sl .lbl sub { position: relative; top: .3em; font-size: .65em; }
.sl.sel { background: var(--ink); color: var(--lcd); }
.fxl { margin-right: .2em; }

/* lists, MENU, RECALL, prompts */
.list, .recall, .prompt { display: flex; flex-direction: column; min-height: 0; flex: 1; font-family: var(--label); }
.lt { font-weight: 700; padding: 2px 10px 4px; font-size: .95em; }
.li-wrap { overflow-y: auto; scrollbar-width: none; flex: 1; }
.li { display: flex; width: 100%; align-items: baseline; gap: 8px; padding: 6px 10px; text-align: left; font-weight: 600; font-size: 1em; }
.li .n { width: 1.2em; color: var(--ink-soft); }
.li .lbl { flex: 1; }
.li .note { color: var(--ink-soft); font-weight: 500; font-size: .9em; }
.li .note sup { font-size: .7em; }
.li .tick { font-size: .7em; }
.li.sel { background: var(--ink); color: var(--lcd); }
.li.sel .n, .li.sel .note { color: var(--lcd-lo); }
.menu { flex: 1; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 6px; padding: 4px 8px 8px; font-family: var(--label); }
.app { border: 2px solid var(--ink); border-radius: 6px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: 6px 10px; text-align: left; }
.app .n { font-size: .85em; font-weight: 700; }
.app .nm { font-size: 1.2em; font-weight: 700; }
.app.sel { background: var(--ink); color: var(--lcd); }
.vars { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; padding: 0 10px 6px; overflow-y: auto; }
.var { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px; font-size: 1.05em; border-bottom: 1px solid rgba(27, 34, 29, .15); }
.var .vn { font-weight: 700; font-family: var(--math); }
.var .vv { font-family: var(--math); font-size: .95em; }
.prompt .pl { padding: 2px 10px 0; font-weight: 700; font-size: 1em; }
.prompt .in { flex: 1; }
.prompt .pc { padding: 0 10px 8px; color: var(--ink-soft); font-size: .85em; font-weight: 600; display: flex; align-items: center; gap: 4px; font-family: var(--label); }

.toast { position: absolute; left: 50%; bottom: 10px; transform: translate(-50%, 8px); background: var(--ink); color: var(--lcd); font-family: var(--label); font-weight: 600; font-size: .85em; padding: 5px 10px; border-radius: 4px; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- keypad ---- */
.pad { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1.5%; padding-top: 10px; }
.top, .g6, .g5 { display: grid; column-gap: 3.2%; }
.top { grid-template-columns: repeat(6, 1fr); grid-template-rows: 1fr 1fr; flex: 2.05; }
.g6 { grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(3, 1fr); flex: 3.3; }
.g5 { grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(4, 1fr); flex: 4.9; column-gap: 4.2%; }
.cell { display: flex; flex-direction: column; min-height: 0; }
.legends { display: flex; justify-content: space-between; align-items: flex-end; gap: 3px; height: 1.3em; font-size: .68em; font-weight: 600; line-height: 1; padding: 0 2px 3px; white-space: nowrap; }
.legends > span { display: inline-block; }
.legends .kfrac { font-size: .62em; }
.legends .bx { width: .5em; height: .55em; border-width: 1.2px; }
.legends .kddx .kfrac { font-size: .55em; }
.lg-s { color: var(--shift); }
.lg-a { color: var(--alpha); margin-left: auto; }
.legends .na { opacity: .62; }
.legends sup, .key sup { font-size: .62em; line-height: 0; position: relative; top: -.15em; vertical-align: super; }
.legends sub, .key sub { font-size: .6em; line-height: 0; }
.key {
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 1.12em;
  background: linear-gradient(180deg, var(--key-fn), var(--key-fn-lo));
  color: var(--key-ink);
  box-shadow: 0 2px 0 #17191e, inset 0 1px 0 rgba(255, 255, 255, .06);
  transition: transform .04s, box-shadow .04s, filter .04s;
}
.kl { display: inline-block; line-height: 1; white-space: nowrap; }
.key i { font-family: var(--math); font-size: 1.12em; }
.key.pressed { transform: translateY(2px); box-shadow: 0 0 0 #17191e; filter: brightness(.88); }
.num .key .op-k { font-size: 1.15em; }
.num .key { background: linear-gradient(180deg, var(--key-num), var(--key-num-lo)); color: var(--key-num-ink); font-size: 1.55em; box-shadow: 0 2px 0 #8d939c, inset 0 1px 0 rgba(255, 255, 255, .6); }
.num .key.pressed { box-shadow: 0 0 0 #8d939c; }
.blue .key { background: linear-gradient(180deg, var(--key-blue), var(--key-blue-lo)); color: #fff; font-size: 1.35em; font-weight: 700; box-shadow: 0 2px 0 #18307c; }
.mod-shift .key { color: var(--shift); }
.mod-alpha .key { color: var(--alpha); }
.mod-shift .key, .mod-alpha .key, .top .key { font-size: .95em; font-weight: 700; border-radius: 6px; }
.top .cell .key { flex: 0 1 72%; margin-top: auto; }
body.shift .mod-shift .key { background: var(--shift); color: #23262e; }
body.alpha .mod-alpha .key { background: var(--alpha); color: #23262e; }
/* While SHIFT or ALPHA is on, its legends light up so the kid sees what the next key does. */
body.shift .lg-s:not(.na) { text-shadow: 0 0 8px rgba(242, 185, 65, .8); color: #ffd36e; }
body.shift .lg-a, body.alpha .lg-s { opacity: .35; }
body.alpha .lg-a:not(.na) { text-shadow: 0 0 8px rgba(240, 124, 160, .8); color: #ff9fbd; }

/* key icons */
.ico { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.ico.s { width: 1.25em; height: 1.1em; }
.bx { display: inline-block; width: .52em; height: .6em; border: 1.5px solid currentColor; border-radius: 1px; vertical-align: middle; margin: 0 .03em; }
.bx.f { background: currentColor; }
.kfrac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: .95; font-size: .9em; }
.kfrac > span:first-child { border-bottom: 1.5px solid currentColor; padding-bottom: 1px; margin-bottom: 1px; }
.kfrac.sm { font-size: .7em; }
.key .kfrac .bx { width: .62em; height: .5em; }
.kddx { display: inline-flex; align-items: center; gap: 1px; }
.kab { display: inline-flex; align-items: center; gap: 1px; font-size: .95em; }
.k10 { font-size: .72em; font-weight: 600; }
.k10 sup { font-size: .75em; }

/* D-pad: an oval rocker over columns 3–4 */
.dpad { grid-column: 3 / span 2; grid-row: 1 / span 2; position: relative; margin: 6% 0 2%; border-radius: 50% / 46%;
  background: radial-gradient(ellipse at 50% 35%, #3a3f4a, #262930 70%); box-shadow: 0 3px 0 #14161a, inset 0 1px 0 rgba(255, 255, 255, .07); }
.dp { position: absolute; display: flex; align-items: center; justify-content: center; }
.dp span { width: 0; height: 0; border: .42em solid transparent; }
.dp.up { left: 30%; right: 30%; top: 0; height: 33%; }
.dp.up span { border-bottom: .55em solid #d9dde4; border-top-width: 0; }
.dp.down { left: 30%; right: 30%; bottom: 0; height: 33%; }
.dp.down span { border-top: .55em solid #d9dde4; border-bottom-width: 0; }
.dp.left { left: 0; top: 25%; bottom: 25%; width: 30%; }
.dp.left span { border-right: .55em solid #d9dde4; border-left-width: 0; }
.dp.right { right: 0; top: 25%; bottom: 25%; width: 30%; }
.dp.right span { border-left: .55em solid #d9dde4; border-right-width: 0; }
.dp.pressed span { filter: brightness(.7); }
.dp-hub { position: absolute; left: 39%; right: 39%; top: 38%; bottom: 38%; border-radius: 50%; background: #1d1f25; pointer-events: none; }

:focus-visible { outline: 2px solid var(--shift); outline-offset: 2px; }

/* long-press help */
.help { position: fixed; inset: 0; display: none; align-items: flex-end; justify-content: center; background: rgba(10, 11, 14, .55); padding: 16px; z-index: 10; }
.help.show { display: flex; }
.help-card { background: #f4f5f7; color: #1a1d24; border-radius: 14px; padding: 16px 18px 12px; max-width: 420px; width: 100%; font-family: var(--label); font-size: 17px; line-height: 1.4; }
.help-card p { margin: 0 0 10px; }
.help-card .ms { display: block; color: #5a606c; font-size: .92em; }
.help-card .hs { color: #a36d00; }
.help-card .ha { color: #b8325c; }
.help-ok { display: block; margin-left: auto; font-weight: 700; padding: 6px 14px; border-radius: 8px; background: #1a1d24; color: #fff; }
