@font-face {
  font-family: KaTeX Main;
  src: url('./assets/katex/KaTeX_Main-Regular.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: KaTeX Math;
  src: url('./assets/katex/KaTeX_Math-BoldItalic.woff2') format('woff2');
  font-style: italic;
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: KaTeX Size2;
  src: url('./assets/katex/KaTeX_Size2-Regular.woff2') format('woff2');
  font-display: swap;
}

:root {
  --shell: #192328;
  --shift-accent: #ffda85;
  --alpha-accent: #88eee4;
  --lcd: #c3d3c4;
  --ink: #1c322a;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  --inset: clamp(6px, 1.25dvh, 16px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  align-content: center;
  padding: var(--inset);
  background: radial-gradient(ellipse at top, #25383d, #111a1f 72%);
  font-family: system-ui, sans-serif;
}
#app { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; }

.calc {
  --face-unit: 1dvh;
  --key-gap: clamp(3px, .75vw, 7px);
  --legend-height: clamp(15px, calc(2.15 * var(--face-unit)), 22px);
  --function-height: clamp(27px, calc(4.15 * var(--face-unit)), 46px);
  --digit-height: clamp(34px, calc(5.35 * var(--face-unit)), 55px);
  display: grid;
  grid-template-rows: auto minmax(86px, 1fr) auto auto;
  gap: clamp(4px, calc(.65 * var(--face-unit)), 8px);
  padding: clamp(8px, calc(1.25 * var(--face-unit)), 14px);
  background: linear-gradient(155deg, #242f33, var(--shell) 57%);
  border: 1px solid #4c5f65;
  border-radius: clamp(15px, calc(2.5 * var(--face-unit)), 24px);
  box-shadow: 0 18px 44px #070f149c, inset 0 1px #ffffff22;
  color: #f7faf9;
}

.calc:not(.graph-mode) {
  --face-unit: min(1dvh, 7px);
  width: min(100%, 376px);
  min-height: 570px;
  max-height: calc(100dvh - 2 * var(--inset) - 32px);
  aspect-ratio: 730 / 1286;
}

@media (max-height: 600px) {
  .calc:not(.graph-mode) {
    min-height: 546px;
    max-height: calc(100dvh - 2 * var(--inset));
    grid-template-rows: auto minmax(64px, 1fr) auto auto;
  }
}

.calc.graph-mode {
  width: min(100%, 570px, max(390px, calc(58dvh - var(--inset))));
  --graph-key-height: clamp(29px, calc(4.15 * var(--face-unit)), 37px);
  height: clamp(360px, calc(100dvh - 2 * var(--inset)), 1020px);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}
.calc.graph-mode .board { display: none; }
.calc.graph-mode .lcd { container-type: size; }
.graph-pad {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: var(--graph-key-height);
  gap: 4px;
}
.graph-pad[hidden] { display: none; }
.graph-pad button.key { font-size: clamp(13px, calc(2.2 * var(--face-unit)), 18px); }
.graph-pad [data-graph-key="plot"] { background: #eaca7d; color: #2f2515; border-color: #ffdf93; }
.graph-mode .workspace-form label[data-active] input { border-color: #236e61; box-shadow: inset 0 -1px #236e61; }

.display-header {
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) minmax(0, auto);
  align-items: center;
  gap: 10px;
  min-height: 33px;
  padding: 1px 4px 2px;
}
.calculator-brand {
  display: flex;
  align-items: center;
  gap: 7px;
}
.brand-logo {
  display: block;
  width: auto;
  height: clamp(24px, calc(3.5 * var(--face-unit)), 32px);
  mix-blend-mode: screen;
}
.brandline {
  font-size: clamp(12px, calc(1.8 * var(--face-unit)), 15px);
  font-weight: 760;
  line-height: 1.16;
  letter-spacing: -.025em;
  white-space: nowrap;
}
.header-controls {
  display: grid;
  justify-items: end;
  gap: 3px;
  padding-inline-start: 8px;
  border-inline-start: 1px solid #536770;
  font: 700 clamp(9px, calc(1.45 * var(--face-unit)), 12px)/1 var(--mono);
  color: #c8dada;
}
.header-modes {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.header-mode, .header-angle {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding-inline: 6px;
  border: 1px solid #566b71;
  border-radius: 5px;
}
.header-mode {
  gap: 5px;
  background: #29383d;
  color: #f7faf9;
  font: inherit;
  cursor: pointer;
}
.header-mode::after {
  content: "";
  width: 4px;
  height: 4px;
  border: solid currentColor;
  border-width: 0 1px 1px 0;
  transform: translateY(-1px) rotate(45deg);
}
.header-angle {
  justify-content: center;
  background: #132025;
  color: var(--alpha-accent);
}
.evaluation-switch {
  display: inline-flex;
  min-height: 24px;
  border: 1px solid #566b71;
  border-radius: 5px;
  background: #132025;
}
.evaluation-switch[hidden] { display: none; }
.evaluation-switch button {
  background: transparent;
  border: 0;
  border-radius: 4px;
  padding: 0 5px;
  color: #c8dada;
  font: inherit;
  cursor: pointer;
}
.evaluation-switch button[aria-pressed="true"] {
  background: var(--alpha-accent);
  color: #132025;
}

.bezel {
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 3px;
  border: 1px solid #3b4f54;
  border-radius: 11px;
  background: #0e191c;
}
.lcd {
  --math-size: clamp(19px, min(6.6cqw, calc(3.7 * var(--face-unit))), 30px);
  --menu-size: clamp(12px, 3.55cqw, 15px);
  min-width: 0;
  min-height: 0;
  container-type: inline-size;
  background: linear-gradient(145deg, #e0ebd9, var(--lcd) 71%);
  color: var(--ink);
  border-radius: 7px;
  padding: clamp(7px, calc(1.2 * var(--face-unit)), 13px) clamp(9px, calc(1.55 * var(--face-unit)), 16px);
  position: relative;
  overflow: auto;
  box-shadow: inset 0 1px 5px #122c2540;
  scrollbar-color: #78978a transparent;
}
.lcd.off { background: #afc0b4; }
.lcd.off .expr, .lcd.off .result, .lcd.off .menu, .lcd.off .calc-step { visibility: hidden; }
#math-keyboard {
  position: absolute;
  inset: 8px auto auto 8px;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 16px;
  opacity: .01;
  pointer-events: none;
  resize: none;
}

.status {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 3px 5px;
  align-items: center;
  min-width: 0;
  color: var(--alpha-accent);
}
.status:empty { display: none; }
.status .shift-status, .status .alpha-status {
  font-weight: 800;
  color: #16272a;
  border-radius: 3px;
  padding: 2px 3px;
}
.status .shift-status { background: var(--shift-accent); }
.status .alpha-status { background: var(--alpha-accent); }

#screen:has(> .expr) { min-height: 100%; display: flex; flex-direction: column; gap: 8px; }
#screen > .result { margin-top: auto; }

.expr, .result {
  font: var(--math-size)/1.2 "KaTeX Main", "Cambria Math", "STIXGeneral", serif;
  font-variant-numeric: lining-nums tabular-nums;
}
.expr {
  min-height: 0;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding: 2px 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.result {
  min-height: 0;
  display: flex;
  justify-content: safe flex-end;
  align-items: flex-end;
  text-align: right;
  gap: 8px;
  flex-wrap: wrap;
  overflow-x: auto;
  scrollbar-width: thin;
}
.result.error { justify-content: flex-start; font-weight: 700; }
.result-detail { font-size: .72em; }
.evaluation-details {
  flex: 0 0 100%;
  color: #354e45;
}
.evaluation-details .line > span { display: inline-block; }
.substitution-form > label:first-child { grid-column: 1 / -1; }
.result.equation-results { display: grid; gap: .22em; }
.equation, .equation-answer { white-space: pre; }
.equation-answer > sub { font-size: .65em; }
.zero-idle {
  margin-left: auto;
  opacity: .9;
}

.caret {
  display: inline-block;
  flex: none;
  width: .48em;
  height: .88em;
  background: #186d67;
  margin: 0 1px;
  vertical-align: -0.05em;
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.math-row { display: inline-block; flex: 0 0 auto; white-space: pre; }
.math-slot { cursor: text; }
.math-slot:hover:not(:has(.math-slot:hover)) { background: #dbe9d8; border-radius: 2px; }
.ph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: .8em;
  min-height: 1.05em;
  border: 1.4px solid #4f695d;
  border-radius: 1px;
}
.ph:has(> .caret) { border-color: #25584c; }
.ph > .caret { width: .42em; height: .74em; margin-inline: 0; }
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  vertical-align: middle;
  margin: 0 .12em;
  line-height: 1.14;
}
.frac .frac { font-size: .82em; }
.frac > .num, .frac > .den { text-align: center; min-width: 1em; padding-inline: .14em; }
.frac > .num { padding-bottom: .12em; border-bottom: max(1px, .065em) solid currentColor; }
.frac > .den { padding-top: .12em; }
.integral {
  display: inline-grid;
  grid-template-columns: max-content max-content max-content;
  grid-template-rows: auto auto auto;
  align-items: center;
  gap: .1em .2em;
  padding: .06em .08em;
  line-height: 1;
  vertical-align: middle;
}
.integral-sign {
  grid-area: 2 / 1;
  justify-self: center;
  font-size: 2.2em;
  line-height: .85;
}
.integral-upper, .integral-lower { font-size: .65em; justify-self: center; }
.integral-upper { grid-area: 1 / 1; }
.integral-lower { grid-area: 3 / 1; }
.integral-integrand { grid-area: 2 / 2; }
.integral-differential { grid-area: 2 / 3; }
.indefinite-integral { row-gap: 0; }
.indefinite-integral .integral-sign { font-size: 1.9em; }
.derivative {
  display: inline-flex;
  align-items: center;
  gap: .12em;
  vertical-align: middle;
}
.derivative-point {
  align-self: flex-end;
  margin-inline-start: .05em;
  padding-inline-start: .22em;
  border-inline-start: 1px solid currentColor;
  color: inherit;
  font: inherit;
  font-size: .7em;
}
.limit-expression {
  display: inline-flex;
  align-items: center;
  gap: .3em;
  vertical-align: middle;
}
.limit-operator {
  display: inline-grid;
  justify-items: center;
  line-height: 1.12;
}
.limit-approach {
  display: inline-flex;
  align-items: baseline;
  font-size: .7em;
}
.limit-target { white-space: nowrap; }
.limit-target > sup { margin-inline-start: .1em; }
.math-variable { font-family: "KaTeX Math", "Cambria Math", serif; font-style: italic; font-weight: 700; }
.integral-variable {
  appearance: none;
  color-scheme: light;
  border: 0;
  border-bottom: 1px solid #578074;
  border-radius: 2px;
  padding: 0 .12em;
  background: #2f756718;
  color: inherit;
  font-size: inherit;
  line-height: 1;
  cursor: pointer;
}
.integral-variable:focus-visible { outline: 2px solid #186d67; outline-offset: 1px; }
.bounded-operator {
  display: inline-flex;
  align-items: center;
  gap: .16em;
  margin-inline: .06em;
  vertical-align: middle;
}
.bounded-operator-stack {
  display: inline-grid;
  grid-template-rows: 1fr auto 1fr;
  justify-items: center;
  row-gap: .08em;
}
.bounded-operator-sign {
  display: block;
  font-family: "KaTeX Size2", "KaTeX Main", serif;
  line-height: 1.55;
}
.bounded-operator-upper, .bounded-operator-lower {
  font-size: .7em;
  line-height: 1.15;
}
.bounded-operator-upper { align-self: end; }
.bounded-operator-lower { align-self: start; }
.bounded-operator-lower > .ph { vertical-align: middle; }
.bounded-operator-term { white-space: nowrap; }
.pow {
  display: inline;
}
.pow > .exp, .pow > sup {
  font-size: .7em;
  line-height: 1;
  margin: 0 0 0 1px;
  position: static;
  top: auto;
  vertical-align: .62em;
}
.rad { display: inline-flex; align-items: flex-end; margin: 0 .08em; }
.rad-index { font-size: .62em; line-height: 1; margin: 0 -0.12em 0.45em 0; align-self: flex-start; font-weight: 750; }
.rad-sign {
  font-size: 1.15em;
  line-height: .8;
  padding-right: 1px;
}
.rad-body {
  border-top: 1.6px solid currentColor;
  padding: 0 .18em .02em .12em;
  display: inline-flex;
  align-items: center;
}
.fn { display: inline-flex; align-items: baseline; }
.fn b { font-weight: 500; margin-inline-end: .06em; }
.abs { display: inline-flex; align-items: center; }
.abs i { font-style: normal; padding: 0 .04em; }

.menu {
  font: var(--menu-size)/1.3 system-ui, sans-serif;
  padding-top: 2px;
}
.menu h2 {
  margin: 0 0 4px;
  font-size: 1em;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 750;
}
.menu button.choice, .menu .line {
  display: flex;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 2px 0;
  cursor: pointer;
}
.menu button.choice:hover, .menu button.choice.on { background: rgba(20,40,36,.08); }
.menu .line { display: block; cursor: auto; overflow-wrap: anywhere; }
.menu button.calculus-choice {
  display: grid;
  grid-template-columns: 1.3em minmax(0, 1fr);
  grid-template-areas: "number formula" "number description";
  align-items: center;
  gap: .15em .45em;
  min-height: 44px;
  padding: .35em .2em .4em;
}
.menu button.calculus-choice + .calculus-choice { border-top: 1px solid #46695e45; }
.calculus-choice-number { grid-area: number; font-weight: 700; }
.calculus-choice-formula {
  grid-area: formula;
  font-family: "KaTeX Main", "Cambria Math", serif;
}
.calculus-choice-description { grid-area: description; font-size: .9em; }
.limit-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: .6em;
}
.menu .limit-choices button.calculus-choice { border-top: 0; min-height: 3.4em; }
.menu .limit-choices button.calculus-choice:nth-child(n + 3) { border-top: 1px solid #46695e45; }
.lcd-editor-heading {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.lcd-editor-heading h2 { flex: 1; margin: 0; }
.lcd-action {
  color: inherit;
  font: 600 11px/1.25 system-ui, sans-serif;
  border: 1px solid #758d7d;
  border-radius: 4px;
  padding: 2px 8px;
  background: #bad0bf;
  cursor: pointer;
}
.lcd-action:hover { background: #aec7b6; }
.solve-options-button { margin-block: 5px 2px; }
.workspace-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 8px;
  margin-block: 5px;
  font: 600 var(--menu-size)/1.3 system-ui, sans-serif;
}
.workspace-form label { display: grid; gap: 2px; min-width: 0; }
.workspace-form :is(input, select) {
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid #758d7d;
  border-radius: 4px;
  background: #eef5eb;
  color: inherit;
  font: inherit;
}
.workspace-form :focus-visible { outline: 2px solid #085650; outline-offset: 1px; }
.workspace-form button { justify-self: start; align-self: end; padding-block: 5px; }
.graph-viewport {
  position: relative;
  border: 1px solid #758d7d;
  background: #eff5ee;
  overflow: hidden;
  cursor: grab;
  user-select: none;
}
.graph-canvas { display: block; width: 100%; height: auto; }
.graph-mode .graph-canvas { height: clamp(130px, calc(100cqh - 220px), 520px); }
.graph-tools, .graph-curve {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding-block: 0.25rem;
  font-size: var(--menu-size);
}
.graph-tools .lcd-action[aria-pressed="true"] {
  background: #085650;
  color: #f4fcf8;
  border-color: #085650;
}
.graph-curve select {
  background: #eff5ee;
  color: #183b30;
  border: 1px solid #758d7d;
  border-radius: 4px;
}
.graph-trace-viewport { cursor: crosshair; touch-action: none; }
.graph-viewport.is-panning { cursor: grabbing; }
.graph-trace-viewport:focus-visible { outline: 2px solid #085650; outline-offset: 2px; }
.graph-trace-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  --trace-color: #085650;
}
.graph-trace-overlay[data-curve="1"] { --trace-color: #963b56; }
.graph-trace-guide {
  position: absolute;
  inset: 0 auto 0 0;
  width: 1px;
  background: #4b645a;
}
.graph-trace-marker {
  position: absolute;
  inset: 0 auto auto 0;
  width: 9px;
  height: 9px;
  border: 1px solid #eff5ee;
  border-radius: 50%;
  background: var(--trace-color);
}
.graph-trace-coordinates {
  position: absolute;
  inset: 0 auto auto 0;
  padding: 3px 6px;
  border: 1px solid #5e796e;
  border-radius: 4px;
  background: #f7fbf4;
  color: #183b30;
  font: 650 11px/1.25 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.graph-legend { display: flex; gap: 12px; font-size: var(--menu-size); }
.graph-legend span::before {
  display: inline-block;
  width: 16px;
  margin-inline-end: 4px;
  border-top: 3px solid #085650;
  vertical-align: middle;
  content: '';
}
.graph-legend span + span::before { border-color: #963b56; }
.graph-range { margin: 2px 0; font: 11px/1.2 system-ui, sans-serif; }
.graph-results { padding-block: 4px; font-size: var(--menu-size); }
.graph-results h2 { font-size: 1em; margin: 4px 0; }
.stat-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-block: 2px;
}
.stat-entry .numfield { width: min(100%, 12em); min-width: 0; }
.stat-mean-control {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 5px;
  padding: 2px 4px;
  font: inherit;
  text-align: left;
}
.stat-overbar {
  display: inline-block;
  text-decoration: overline;
  text-decoration-thickness: 1px;
}
.stat-mean-action { font-size: 10px; font-weight: 700; white-space: nowrap; }
.mode-choices, .stat-values {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 135px), 1fr));
  gap: 3px 10px;
}
.mode-error {
  margin-bottom: 6px;
  color: #811b16;
  font: 700 var(--menu-size) system-ui, sans-serif;
}
.coeff {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.coeff-grid {
  display: grid;
  grid-template-columns: repeat(var(--columns, 4), minmax(0, 1fr));
}
.coeff-grid > label { min-width: 0; }
.coeff-grid .numfield {
  width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}
.eqn-system {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  gap: 2px 7px;
}
.eqn-column {
  padding-inline: 3px;
  font-size: 11px;
  font-weight: 700;
  text-align: right;
}
.eqn-system .numfield {
  width: 100%;
  min-width: 0;
  min-height: 20px;
  padding: 0 3px;
  border-bottom-width: 1px;
  font-size: 16px;
  line-height: 18px;
  overflow-wrap: anywhere;
  text-align: right;
}
.matrix-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-block: 4px;
}
.matrix-parts button.choice {
  width: auto;
  padding: 1px 9px;
  border: 1px solid #758d7d;
  border-radius: 4px;
}
.matrix-parts button.choice[aria-pressed="true"] {
  background: #bad0bf;
  font-weight: 700;
}
.matrix-result {
  margin: 4px 0 8px;
  border-inline: 1.5px solid currentColor;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.matrix-result-scroll { max-width: 100%; overflow-x: auto; }
.matrix-result td {
  padding: 1px clamp(3px, 1.6cqw, 8px);
  text-align: right;
  white-space: nowrap;
}
.coeff label, .field {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  font-weight: 700;
  gap: 2px;
}
.coeff input, .numfield {
  width: 64px;
  font: 700 16px "Palatino Linotype", Palatino, serif;
  border: 0;
  border-bottom: 2px solid #1c2422;
  background: transparent;
  color: inherit;
  padding: 2px 2px 1px;
}
.coeff input:focus, .numfield:focus, .onfield {
  outline: none;
  background: rgba(20, 60, 40, .12);
}
.calc input[data-lcd-field] {
  user-select: text;
  -webkit-user-select: text;
}
input[data-lcd-field]:focus { box-shadow: 0 1px #355b45; }
.calc button.hold-shift-ready { outline: 2px solid var(--shift-accent); outline-offset: -3px; }
.calc button.hold-shift-ready:active { background: #716140; }
.table {
  width: auto;
  margin-left: auto;
  border-collapse: collapse;
  font-family: "Palatino Linotype", Palatino, serif;
  font-size: 14px;
}
.table th { font-family: "Avenir Next", sans-serif; font-size: 11px; letter-spacing: .08em; text-align: right; }
.table td { text-align: right; padding: 1px 4px; }
.tiny {
  margin-top: 4px;
  font-size: 11px;
  opacity: .75;
}
.calc-step {
  display: grid;
  min-width: 0;
  gap: clamp(4px, calc(.75 * var(--face-unit)), 8px);
  --prompt-font: system-ui, "Noto Sans Myanmar", "Myanmar Text", "Myanmar Sangam MN", sans-serif;
}
.calc-step-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #385d4f4d;
  padding-bottom: 3px;
  font-family: var(--prompt-font);
}
.calc-step-header h2 {
  margin: 0;
  font-size: var(--menu-size);
  font-weight: 800;
  color: #26463a;
}
.calc-step-header button {
  border: 1px solid #4b7868;
  border-radius: 5px;
  background: #edf5e8;
  color: #244d3c;
  cursor: pointer;
  padding: 3px 7px;
  font: 650 clamp(11px, 3.5cqw, 13px)/1.45 var(--prompt-font);
}
.calc-step-header button:focus-visible {
  outline: 2px solid #1c6156;
  outline-offset: 1px;
}
.calc-equation {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .24em;
  overflow-x: auto;
  padding-block: 2px;
  scrollbar-width: thin;
  font: var(--math-size)/1.15 "KaTeX Main", "Cambria Math", serif;
  font-variant-numeric: lining-nums tabular-nums;
}
.calc-equation > * { flex: 0 0 auto; }
.calc-step-value { white-space: nowrap; }
.calc-value-slot {
  width: clamp(4em, 30cqw, 9em);
  min-width: 2.8em;
  min-height: 1.24em;
  padding-inline: .22em;
  background: #f0f7e9;
  border: 1.5px solid #407566;
  border-radius: 4px;
  font: inherit;
}
.calc-step-bound {
  margin-inline-end: .2em;
  padding-inline-end: .45em;
  border-inline-end: 1px solid #668879;
}
.calc-step-symbolic { font-size: calc(var(--math-size) * .85); }
.calc-step-answer {
  border-radius: 5px;
  background: #b4d1be;
  padding: .26em .35em;
}
.calc-step-hint {
  margin: 0;
  color: #305045;
  font: 600 clamp(11px, 3.5cqw, 13px)/1.5 var(--prompt-font);
}
@media (max-height: 620px) {
  .lcd:has(.calc-step) { padding-block: 3px 4px; }
  .calc-step {
    --math-size: clamp(16px, 5.8cqw, 20px);
    gap: 2px;
  }
  .calc-step-header { padding-bottom: 1px; }
  .calc-step-header:not(:has(button)) { display: none; }
  .calc-step-header button { padding-block: 1px; }
  .calc-equation { padding-block: 1px; }
  .calc-step-hint { line-height: 1.4; }
}
.pad-logic {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.pad-logic button {
  border: 0;
  background: #1c2422;
  color: #e4eef0;
  border-radius: 4px;
  padding: 3px 7px;
  font-weight: 750;
  font-size: 11px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--key-gap);
}
.toolbar .ico {
  flex: 0 1 auto;
  width: clamp(28px, 8vw, 40px);
  min-width: 24px;
  height: clamp(27px, calc(3.8 * var(--face-unit)), 37px);
  border: 1px solid #566b71;
  border-radius: 8px;
  background: #29383d;
  color: #e0ebe9;
  font: 740 clamp(15px, calc(2.35 * var(--face-unit)), 21px)/1 system-ui, sans-serif;
  display: grid;
  place-items: center;
  padding: 0;
}
.toolbar [data-k="liminf"] {
  color: var(--alpha-accent);
  border-color: #688982;
}
.toolbar [data-k="liminf"]:disabled { opacity: .5; }
.pills {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid #566b71;
  border-radius: 8px;
  margin-left: auto;
  background: #132025;
}
.pills button {
  min-height: 22px;
  border: 0;
  background: transparent;
  color: #d3e0df;
  font: 720 clamp(10px, calc(1.65 * var(--face-unit)), 14px)/1 var(--mono);
  padding: 4px clamp(4px, 1.05vw, 8px);
  border-radius: 5px;
}
.pills button.on { background: var(--alpha-accent); color: #122e2c; }
.pills [data-k="fracpill"] { border-left: 1px solid #456061; border-radius: 0 5px 5px 0; }

.board, #pad {
  display: grid;
  gap: var(--key-gap);
  min-width: 0;
}
.face {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(0, 2fr) repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: var(--key-gap);
}
.side {
  display: grid;
  container-type: inline-size;
  grid-template-rows: var(--function-height) calc(var(--legend-height) + var(--function-height));
  gap: 3px;
  min-width: 0;
}
.pad-disk {
  height: 100%;
  position: relative;
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  gap: 2px;
  padding: 3px;
  border: 1px solid #50666b;
  border-radius: 14px 8px;
  background: #132025;
}
.dpad button {
  border: 1px solid #485e64;
  border-radius: 5px;
  background: #30434a;
  color: #dcecea;
  font: 720 clamp(10px, calc(1.8 * var(--face-unit)), 16px)/1 system-ui, sans-serif;
  padding: 0;
  cursor: pointer;
}
.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }
.dpad .ring {
  grid-area: 2 / 2;
  place-self: center;
  width: 10px;
  height: 10px;
  rotate: 45deg;
  border: 1px solid #839997;
  border-radius: 2px;
  background: #425b5f;
  pointer-events: none;
}

.block6, .block5 {
  display: grid;
  gap: 2px var(--key-gap);
  min-width: 0;
}
.block6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: calc(var(--legend-height) + var(--function-height));
}
.block5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-auto-rows: calc(var(--legend-height) + var(--digit-height));
}
.slot {
  display: grid;
  grid-template-rows: var(--legend-height) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  container-type: inline-size;
}
.calc, .calc button { user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.calc .board button { -webkit-touch-callout: none; }
.alts {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2px;
  padding: 0 2px;
  font: 800 min(16px, calc((100cqw - 6px) * 1.64 / var(--legend-chars)))/1 var(--mono);
  white-space: nowrap;
}
.alts > span { display: inline-flex; align-items: center; }
.alts > span:only-child { margin-inline: auto; }
.shift-legend { color: var(--shift-accent); }
.alpha-legend { color: var(--alpha-accent); }
.calc.expression-mode.shift .has-shift .key,
.calc.expression-mode.alpha .has-alpha .key {
  outline: 1px solid var(--modifier-accent);
  outline-offset: -2px;
}
.calc.shift { --modifier-accent: var(--shift-accent); }
.calc.alpha { --modifier-accent: var(--alpha-accent); }
.calc.expression-mode.shift .shift-legend,
.calc.expression-mode.alpha .alpha-legend { color: #fffaf0; }
.alts .scr {
  font-size: min(1em, calc(var(--legend-height) / 1.24));
  grid-template-rows: .62em .62em;
}
.alts .key-power { grid-template-rows: .43em .7em; }
.alts .mbox { background: color-mix(in srgb, currentColor 42%, transparent); }
.alts sup .mbox { width: .62em; height: .62em; border-width: 1px; }
.key-factorial { display: inline-flex; align-items: center; gap: .16em; }
.math-overbar { display: inline-flex; border-top: .08em solid currentColor; padding-top: .04em; }
.kfrac {
  display: inline-flex;
  flex-direction: column;
  width: 12px;
  height: 14px;
  justify-content: space-between;
  vertical-align: middle;
}
.kfrac b {
  display: block;
  height: 5px;
  border: 1.5px solid currentColor;
  border-radius: 1px;
}
.alts .kfrac { width: 9px; height: 10px; }
.alts .kfrac b { height: 3px; border-width: 1px; }

button.key, button.mod, button.ico, .pills button { cursor: pointer; }
button.key, button.mod {
  min-width: 0;
  min-height: 0;
  padding: 0 2px 1px;
  border: 1px solid #536770;
  border-radius: clamp(6px, calc(1.15 * var(--face-unit)), 11px);
  color: #eaf2f0;
  background: linear-gradient(#38494f, #2b3b42);
  box-shadow: inset 0 1px #ffffff18, inset 0 -2px #11252b;
  font: 710 clamp(13px, calc(2.55 * var(--face-unit)), 25px)/1 system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.face button.key { font-size: clamp(13px, min(calc(2.55 * var(--face-unit)), 38cqw), 25px); }
button.key:active, button.mod:active, .dpad button:active {
  translate: 0 1px;
  filter: brightness(1.2);
}
.calc button:focus-visible { outline: 2px solid #f8d788; outline-offset: -3px; }
button.mod { font-size: clamp(11px, min(calc(2.25 * var(--face-unit)), 28cqw), 20px); font-weight: 780; }
button.shift-key { background: #eaca7d; border-color: #ffdf93; color: #2f2515; }
button.alpha-key { background: #82d6cb; border-color: #99e7de; color: #192f2b; }
.calc .mod[aria-pressed="true"] {
  background: var(--modifier-accent);
  border-color: #fffaf0;
  box-shadow: inset 0 0 0 2px #1a282a, 0 0 8px color-mix(in srgb, var(--modifier-accent) 45%, transparent);
}
button.num, button.op {
  font-size: clamp(21px, calc(3.7 * var(--face-unit)), 37px);
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}
button.num { background: linear-gradient(#627880, #4f646e); border-color: #849ba3; }
button.op { background: linear-gradient(#e2ece6, #c8d7d2); border-color: #edf5f1; color: #1c3435; box-shadow: inset 0 -2px #9badab; }
button[data-k="eq"] { background: #eaca7d; border-color: #ffdf93; color: #2f2515; box-shadow: inset 0 -2px #b89a55; }
button[data-k="ac"], button[data-k="del"] { color: #ffe2c1; }
button[data-k="ac"], button[data-k="ans"], button[data-k="sci"] { font-size: clamp(17px, calc(3.25 * var(--face-unit)), 32px); }
.glyph { height: 1em; width: auto; max-width: 100%; display: block; }
.alts .glyph { height: min(1.12em, calc(var(--legend-height) - 2px)); width: auto; }

@media (max-width: 520px) {
  .calc.graph-mode { width: 100%; }
}
.scr {
  display: inline-grid;
  grid-template-columns: max-content max-content;
  grid-template-rows: 0.85em 0.7em;
  column-gap: 1px;
  line-height: 1;
  vertical-align: middle;
}
.scr > .mb {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: end;
  font-weight: inherit;
  line-height: 0.9;
}
.scr > sup, .scr > sub {
  font-size: 0.74em;
  font-weight: 750;
  line-height: 1;
  position: static;
  top: auto;
  margin: 0;
  vertical-align: baseline;
  font-style: normal;
}
.scr > sup { grid-column: 2; grid-row: 1; align-self: start; justify-self: start; }
.scr > sub { grid-column: 2; grid-row: 2; align-self: end; justify-self: start; }
[data-k="sqrt"] .glyph { height: 1.25em; }
.indexed-root { display: inline-flex; align-items: flex-start; gap: 1px; }
.indexed-root sup { font-size: .85em; line-height: 1; }
.alts .indexed-root .glyph { height: 1.13em; }
.key-power {
  display: inline-grid;
  grid-template-columns: max-content max-content;
  grid-template-rows: .58em .8em;
  column-gap: .08em;
  line-height: 1;
}
.key .key-power { font-size: min(.94em, 34cqw); }
.key-power > .mbox { grid-area: 2 / 1; align-self: end; width: .78em; height: .78em; }
.key-power > sup { grid-area: 1 / 2; align-self: start; font-size: .78em; line-height: 1; }
.key-power > sup .mbox { width: .69em; height: .69em; }
.alts .key-power .mbox { border-width: 1px; }
.log-layout { display: inline-block; line-height: 1.2; white-space: nowrap; }
.log-layout > sub { font-size: .7em; line-height: 1; vertical-align: -.32em; }
.log-argument { margin-inline-start: .08em; }
.key .log-layout { font-size: min(1em, 29cqw); }
.log-layout .mbox { display: inline-block; }
.mbox {
  display: block;
  width: 0.72em;
  height: 0.62em;
  border: 1.5px solid currentColor;
  border-radius: 1.5px;
  box-sizing: border-box;
}
.ibox, .xbox {
  display: inline-block;
  width: 0.68em;
  height: 0.68em;
  border: 1.6px solid currentColor;
  border-radius: 2px;
  vertical-align: -0.02em;
}
.fbox {
  display: inline-block;
  width: 0.42em;
  height: 0.42em;
  background: currentColor;
  vertical-align: 0.02em;
}
.powi { position: relative; width: 1.15em; height: 0.95em; display: inline-block; }
.powi i {
  position: absolute;
  width: 0.58em;
  height: 0.58em;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}
.powi i:first-child { left: 0; bottom: 0; }
.powi i:last-child { right: 0; top: 0; }
.logduo { display: inline-flex; gap: 1px; margin-left: 2px; vertical-align: middle; }
.logduo i {
  width: 0.42em;
  height: 0.42em;
  border: 1.4px solid currentColor;
  border-radius: 1px;
}
.supk { display: inline-flex; align-items: flex-start; line-height: 1; }
.supk sup { font-size: .62em; margin-left: 1px; }
.ibar {
  display: inline-block;
  width: 0.7em;
  height: 0.55em;
  border-top: 1.6px solid currentColor;
}
.mx {
  display: inline-block;
  width: 0.85em;
  height: 0.7em;
  margin-left: 1px;
  vertical-align: -0.05em;
  background:
    linear-gradient(currentColor, currentColor) 0 0 / 1px 100% no-repeat,
    linear-gradient(currentColor, currentColor) 100% 0 / 1px 100% no-repeat,
    linear-gradient(currentColor, currentColor) 0 0 / 100% 1px no-repeat,
    linear-gradient(currentColor, currentColor) 0 100% / 100% 1px no-repeat,
    linear-gradient(currentColor, currentColor) 33% 0 / 1px 100% no-repeat,
    linear-gradient(currentColor, currentColor) 66% 0 / 1px 100% no-repeat,
    linear-gradient(currentColor, currentColor) 0 50% / 100% 1px no-repeat;
}
.sdswap { display: inline-flex; flex-direction: column; width: 0.7em; height: 0.75em; justify-content: space-between; }
.sdswap i { display: block; height: 0.28em; border: 1px solid currentColor; border-radius: 1px; }

/* Size the keys from the available viewport height so the last row stays visible. */
body {
  padding: 0;
  background: var(--shell);
}

.calc {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.calc:not(.graph-mode),
.calc.graph-mode {
  width: min(100%, 425px);
  height: min(100vh, 765px);
  height: min(100dvh, 765px);
  min-height: 0;
  max-height: none;
  aspect-ratio: auto;
}

/* Leave a little more vertical space for the LCD in calculation modes. */
.calc:not(.graph-mode) {
  --legend-height: clamp(14px, calc(2 * var(--face-unit)), 20px);
  --function-height: clamp(26px, calc(3.92 * var(--face-unit)), 42px);
  --digit-height: clamp(32px, calc(5.05 * var(--face-unit)), 52px);
}

.calc.graph-mode { width: min(100%, 570px); }
@media (max-width: 480px) {
  body { align-content: start; }
  .calc:not(.graph-mode), .calc.graph-mode { height: 100vh; height: 100dvh; }
}

@media (max-height: 620px) {
  .calc {
    --key-gap: clamp(2px, .8vw, 5px);
    gap: clamp(2px, .65vh, 4px);
    padding: clamp(4px, 1vh, 7px);
  }
  .calc:not(.graph-mode) {
    --legend-height: clamp(6px, 2.05vh, 16px);
    --function-height: clamp(12px, 4.22vh, 32px);
    --digit-height: clamp(14px, 5.25vh, 40px);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }
  .display-header { min-height: 0; gap: 4px; }
  .brand-logo { height: clamp(13px, 4vh, 24px); }
  .header-mode, .header-angle { min-height: clamp(15px, 4vh, 24px); }
  .toolbar .ico { height: clamp(17px, 4.5vh, 28px); }
  .pills button { min-height: clamp(13px, 3.7vh, 22px); padding-block: 2px; }
  .lcd { padding-block: clamp(3px, 1vh, 7px); }
  .calc button.key { font-size: clamp(9px, min(3.65vh, 6vw), 17px); }
  .calc button.num, .calc button.op { font-size: clamp(10px, min(4.8vh, 7vw), 23px); }
  .alts { font-size: min(calc(var(--legend-height) - 1px), calc((100cqw - 6px) * 1.64 / var(--legend-chars))); }
  .graph-mode .graph-canvas { height: max(56px, calc(100cqh - 100px)); }
}

/* Keep the expression and answer visible together in short windows. */
@media (max-height: 400px) {
  .calc:not(.graph-mode) .lcd {
    --math-size: clamp(12px, 4.8vh, 17px);
    padding-block: 3px;
  }
  .calc:not(.graph-mode) #screen:has(> .expr) { gap: 2px; }
  .calc:not(.graph-mode) #screen > .expr { padding-block: 1px; }
}

@media (max-height: 280px) {
  .calc:not(.graph-mode) #screen:has(> .expr:first-child + .result:last-child) {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .calc:not(.graph-mode) #screen > .expr:first-child:has(+ .result:last-child) {
    flex: 1 1 auto;
    min-width: 0;
  }
  .calc:not(.graph-mode) #screen > .expr:first-child + .result:last-child {
    flex: 0 0 auto;
    max-width: 50%;
    margin-top: 0;
  }
}

@media (max-height: 340px) {
  .calc:not(.graph-mode) {
    --legend-height: max(5px, 1.8vh);
    --function-height: max(10px, 3.6vh);
    --digit-height: max(12px, 5vh);
    --key-gap: 2px;
    padding: 3px;
  }
  .calc:not(.graph-mode) .side,
  .calc:not(.graph-mode) .block5,
  .calc:not(.graph-mode) .block6 { row-gap: 1px; }
  .calc:not(.graph-mode) .display-header { padding-block: 0; }
  .calc:not(.graph-mode) .toolbar .ico { height: 15px; }
  .calc:not(.graph-mode) .pills { padding: 1px; }
  .calc:not(.graph-mode) .pills button { padding-block: 0; }
}

@media (max-width: 335px) {
  .calculator-brand { gap: 4px; }
  .brandline { font-size: clamp(8px, 3.4vw, 12px); }
  .header-controls { padding-inline-start: 4px; }
  .toolbar .ico { min-width: 20px; width: min(8vw, 27px); }
  .pills { gap: 0; }
  .pills button { padding-inline: clamp(2px, .9vw, 4px); }
}

@media (max-width: 260px) {
  .display-header { padding-inline: 2px; }
  .header-controls { font-size: 8px; }
  .header-modes, .header-mode { gap: 3px; }
  .header-mode, .header-angle, .evaluation-switch button { padding-inline: 3px; }
}
