:root {
  --green-bright: #35a779;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  background: transparent;
}
body {
  display: grid;
  place-items: start center;
  color: #173a31;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(53, 167, 121, 0.55);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
.calculator-stage {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 1rem;
  max-height: calc(100vh - 126px);
  overflow: auto;
  padding: clamp(0.7rem, 2vw, 1.1rem);
  background:
    radial-gradient(circle at 100% 0, rgba(178, 209, 191, 0.3), transparent 22rem),
    #edf1ed;
}

.calculator-mount {
  flex: 0 0 min(360px, 92vw);
  width: min(360px, 92vw);
}

.calculator-shell {
  position: relative;
  width: 100%;
  padding: 0.82rem 0.78rem 0.72rem;
  border: 1px solid #66706c;
  border-radius: 18px 18px 28px 28px;
  color: #ecefed;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05), transparent 18%, transparent 82%, rgba(255, 255, 255, 0.04)),
    linear-gradient(155deg, #3b4140, #171b1b 72%);
  box-shadow:
    0 20px 42px rgba(11, 22, 18, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.17),
    inset 0 -4px 8px rgba(0, 0, 0, 0.3);
}

.calculator-shell::after {
  position: absolute;
  z-index: 0;
  inset: 3px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 15px 15px 25px 25px;
  content: "";
  pointer-events: none;
}

.calculator-shell > * {
  position: relative;
  z-index: 1;
}

.student-calculator {
  box-shadow: 0 0 0 3px rgba(53, 167, 121, 0.26), 0 20px 42px rgba(11, 22, 18, 0.28);
}

.calculator-branding {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: start;
  gap: 0.65rem;
  min-height: 36px;
  padding: 0 0.28rem;
}

.calculator-branding > div {
  display: grid;
}

.calculator-branding strong {
  font-size: 0.73rem;
  letter-spacing: 0.09em;
}

.calculator-branding small {
  margin-top: 0.12rem;
  color: #9aa4a0;
  font-size: 0.44rem;
  letter-spacing: 0.12em;
}

.calculator-branding > b {
  color: #8ea59b;
  font-family: Georgia, serif;
  font-size: 0.66rem;
  font-style: italic;
}

.solar-strip {
  display: grid;
  grid-template-columns: repeat(4, 13px);
  gap: 1px;
  padding: 2px;
  border: 1px solid #5d5a54;
  border-radius: 3px;
  background: #181613;
}

.solar-strip i {
  height: 13px;
  border-right: 1px solid #6f5740;
  background: linear-gradient(135deg, #3a261c, #191715);
}

.calculator-screen {
  position: relative;
  min-height: 119px;
  overflow: hidden;
  padding: 0.45rem 0.6rem 0.55rem;
  border: 3px solid #8d9690;
  border-radius: 8px;
  color: #15211b;
  background:
    repeating-linear-gradient(0deg, rgba(35, 50, 39, 0.026) 0 1px, transparent 1px 3px),
    linear-gradient(145deg, #dbe3d4, #bdcbb9);
  box-shadow:
    inset 0 3px 7px rgba(23, 38, 29, 0.22),
    0 1px 0 rgba(255, 255, 255, 0.18);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.calculator-screen.is-off > * {
  visibility: hidden;
}

.screen-indicators {
  display: flex;
  justify-content: space-between;
  min-height: 15px;
  color: #43534a;
  font-size: 0.49rem;
  font-weight: 750;
  letter-spacing: 0.04em;
}

.screen-indicators > div {
  display: flex;
  gap: 0.35rem;
}

.screen-main {
  display: grid;
  grid-template-rows: minmax(40px, auto) auto 1fr;
  min-height: 88px;
}

.screen-expression {
  overflow: auto hidden;
  padding-top: 0.38rem;
  font-size: 0.88rem;
  line-height: 1.35;
  white-space: nowrap;
}

.screen-cursor {
  display: inline-block;
  width: 1.5px;
  height: 1.05em;
  margin: 0 -0.5px;
  vertical-align: -0.17em;
  background: #1b2a22;
  animation: cursor-blink 1s steps(1) infinite;
}

@keyframes cursor-blink {
  50% { opacity: 0; }
}

.screen-error {
  color: #6b2b28;
  font-size: 0.7rem;
  font-weight: 800;
}

.screen-result {
  align-self: end;
  justify-self: end;
  max-width: 100%;
  overflow: auto hidden;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 1.25rem;
  font-weight: 600;
  white-space: nowrap;
}

.screen-menu {
  position: absolute;
  z-index: 5;
  inset: 19px 0 0;
  overflow: auto;
  padding: 0.35rem 0.48rem 0.55rem;
  background: #cbd6c6;
}

.screen-menu header {
  position: sticky;
  z-index: 2;
  top: -0.35rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: -0.35rem -0.1rem 0.3rem;
  padding: 0.3rem 0.1rem 0.22rem;
  border-bottom: 1px solid rgba(30, 47, 37, 0.22);
  background: #cbd6c6;
}

.screen-menu header strong {
  font-size: 0.63rem;
}

.screen-menu header span {
  color: #59665e;
  font-size: 0.45rem;
}

.home-menu > div {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
}

.home-menu button,
.tools-menu button {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.32rem;
  min-height: 38px;
  padding: 0.25rem;
  border: 1px solid rgba(35, 53, 42, 0.22);
  border-radius: 4px;
  text-align: left;
  background: rgba(240, 244, 237, 0.52);
  cursor: pointer;
}

.home-menu button:hover,
.home-menu button:focus,
.tools-menu button:hover,
.catalog-menu button:hover,
.settings-menu button:hover,
.variables-menu button:hover {
  color: white;
  background: #365a4c;
}

.screen-menu [data-menu-selected="true"] {
  color: white;
  outline: 2px solid #d7a63e;
  outline-offset: -2px;
  background: #365a4c;
}

.home-menu button i {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 4px;
  color: white;
  background: #41695a;
  font-family: Georgia, serif;
  font-size: 0.6rem;
  font-style: normal;
}

.home-menu button span,
.tools-menu button {
  min-width: 0;
}

.home-menu b,
.home-menu small,
.tools-menu b,
.tools-menu small {
  display: block;
}

.home-menu b,
.tools-menu b {
  overflow: hidden;
  font-size: 0.48rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-menu small,
.tools-menu small {
  margin-top: 0.08rem;
  overflow: hidden;
  color: #65736b;
  font-size: 0.38rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catalog-menu section,
.settings-menu section {
  margin-top: 0.28rem;
}

.catalog-menu h4,
.settings-menu h4 {
  margin: 0 0 0.16rem;
  color: #516057;
  font-size: 0.44rem;
}

.catalog-menu section > div,
.settings-menu section > div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.18rem;
}

.catalog-menu button,
.settings-menu button {
  min-height: 22px;
  padding: 0.1rem 0.28rem;
  border: 1px solid #829087;
  border-radius: 3px;
  background: #e0e8dc;
  font-size: 0.43rem;
  cursor: pointer;
}

.settings-menu button.is-selected {
  color: white;
  background: #294e40;
}

.variables-menu > div {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.2rem;
}

.variables-menu button {
  display: grid;
  padding: 0.2rem;
  border: 1px solid #829087;
  border-radius: 3px;
  background: #e0e8dc;
  cursor: pointer;
}

.variables-menu button b {
  font-size: 0.55rem;
}

.variables-menu button small {
  overflow: hidden;
  font-size: 0.35rem;
  text-overflow: ellipsis;
}

.variables-menu p,
.function-menu p {
  margin: 0.3rem 0 0;
  color: #526158;
  font-size: 0.42rem;
}

.function-menu label {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.3rem;
  font-size: 0.5rem;
  font-weight: 800;
}

.function-menu input {
  width: 100%;
  min-height: 25px;
  border: 1px solid #829087;
  border-radius: 3px;
  background: #e8eee4;
  font-family: inherit;
  font-size: 0.5rem;
}

.tools-menu {
  display: grid;
  gap: 0.25rem;
}

.tools-menu button {
  display: block;
}

.calculator-navigation {
  display: grid;
  grid-template-columns: 1fr 1fr 2.3fr 1fr;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.15rem 0.35rem;
}

.calculator-navigation > button {
  display: grid;
  place-items: center;
  min-height: 37px;
  padding: 0.1rem;
  border: 1px solid #767d7a;
  border-radius: 7px;
  color: #ebefed;
  background: linear-gradient(#4d5351, #292e2c);
  box-shadow: 0 3px 0 #111514, inset 0 1px rgba(255, 255, 255, 0.16);
  cursor: pointer;
}

.calculator-navigation > button span {
  font-size: 0.85rem;
}

.calculator-navigation > button small {
  color: #aeb8b3;
  font-size: 0.37rem;
  letter-spacing: 0.04em;
}

.direction-pad {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 17px 24px 17px;
  overflow: hidden;
  border: 1px solid #737a77;
  border-radius: 50%;
  background: radial-gradient(circle, #626865, #303532 68%);
  box-shadow: 0 3px 0 #111514, inset 0 1px rgba(255, 255, 255, 0.14);
}

.direction-pad button {
  padding: 0;
  border: 0;
  color: #e4e8e5;
  background: transparent;
  font-size: 0.5rem;
  cursor: pointer;
}

.direction-pad [data-key="cursor-up"] { grid-column: 2; grid-row: 1; }
.direction-pad [data-key="cursor-left"] { grid-column: 1; grid-row: 2; }
.direction-pad [data-key="ok"] { grid-column: 2; grid-row: 2; border: 1px solid #777e7b; border-radius: 50%; background: #242826; font-size: 0.48rem; }
.direction-pad [data-key="cursor-right"] { grid-column: 3; grid-row: 2; }
.direction-pad [data-key="cursor-down"] { grid-column: 2; grid-row: 3; }

.calculator-keys {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.38rem 0.42rem;
  padding: 0.22rem 0.06rem 0;
}

.calc-key {
  position: relative;
  display: grid;
  grid-template-rows: 11px minmax(30px, auto);
  align-items: center;
  min-width: 0;
  min-height: 45px;
  padding: 0;
  border: 0;
  color: #ecf0ed;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.calc-key small {
  align-self: start;
  overflow: hidden;
  color: #e5ae54;
  font-size: 0.39rem;
  font-weight: 750;
  line-height: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calc-key strong {
  display: grid;
  width: 100%;
  height: 31px;
  place-items: center;
  border: 1px solid #717875;
  border-radius: 5px 5px 7px 7px;
  background: linear-gradient(#545a58, #2d3230);
  box-shadow: 0 3px 0 #111513, inset 0 1px rgba(255, 255, 255, 0.18);
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1;
  text-shadow: 0 1px #111;
  transition: transform 70ms ease, box-shadow 70ms ease, color 100ms ease, background 100ms ease;
}

.calc-key:hover strong {
  background: linear-gradient(#626966, #353b38);
}

.key-number strong {
  color: #222b27;
  border-color: #b9c0bc;
  background: linear-gradient(#f2f3f1, #c8cdca);
  box-shadow: 0 3px 0 #747a77, inset 0 1px white;
  font-size: 0.84rem;
  text-shadow: none;
}

.key-number:hover strong {
  background: linear-gradient(#fff, #d9dedb);
}

.key-operator strong {
  color: #17241f;
  border-color: #aeb9b4;
  background: linear-gradient(#dce3df, #afb9b4);
  box-shadow: 0 3px 0 #68716d, inset 0 1px white;
  font-size: 0.9rem;
  text-shadow: none;
}

.key-execute strong {
  color: white;
  border-color: #4b9d7e;
  background: linear-gradient(#4cb085, #26775a);
  box-shadow: 0 3px 0 #174c3a, inset 0 1px rgba(255, 255, 255, 0.25);
  text-shadow: 0 1px #174b39;
}

.key-danger-soft strong {
  color: white;
  border-color: #a7645e;
  background: linear-gradient(#c47770, #914d48);
  box-shadow: 0 3px 0 #592d2a, inset 0 1px rgba(255, 255, 255, 0.18);
}

.key-modifier strong,
.key-menu strong,
.key-format strong {
  font-size: 0.52rem;
  letter-spacing: -0.01em;
}

.key-modifier strong {
  color: #f1c36f;
}

.calc-key.is-latched strong {
  color: #1b2e27;
  background: linear-gradient(#f4c468, #d99a35);
  box-shadow: 0 2px 0 #7e5720, inset 0 1px rgba(255, 255, 255, 0.4);
  transform: translateY(1px);
  text-shadow: none;
}

.calc-key.local-pressed strong,
.calculator-navigation button.local-pressed,
.direction-pad button.local-pressed {
  box-shadow: 0 0 0 #111, inset 0 2px 5px rgba(0, 0, 0, 0.28);
  transform: translateY(3px) scale(0.98);
}

.calc-key.remote-pressed strong,
.calculator-navigation button.remote-pressed,
.direction-pad button.remote-pressed {
  color: #0c2c20 !important;
  border-color: #8ae0b8 !important;
  background: linear-gradient(#8ff0bd, #43bd84) !important;
  box-shadow: 0 0 0 4px rgba(79, 220, 153, 0.3), inset 0 3px 7px rgba(18, 98, 61, 0.2) !important;
  transform: translateY(3px) scale(0.97);
  text-shadow: none !important;
  animation: student-key-pulse 360ms ease;
}

@keyframes student-key-pulse {
  0% { filter: brightness(1.35); }
  100% { filter: brightness(1); }
}

.calc-key:disabled,
.calculator-navigation button:disabled,
.screen-menu button:disabled {
  cursor: default;
  opacity: 1;
}

.calculator-model {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.55rem;
  padding: 0 0.25rem;
  color: #8f9995;
  font-size: 0.42rem;
}

.calculator-model b {
  color: #b8c0bc;
  font-family: Georgia, serif;
  font-size: 0.55rem;
  font-style: italic;
}

.advanced-workspace {
  flex: 1 1 420px;
  min-width: 0;
  max-width: 510px;
  min-height: 650px;
  overflow: auto;
  padding: 1rem;
  border: 1px solid #cbd4ce;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 16px 40px rgba(23, 58, 49, 0.08);
}

.workspace-heading {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid #dde3df;
}

.workspace-heading > span {
  display: grid;
  width: 45px;
  height: 45px;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, #396f5c, #1d493b);
  font-family: Georgia, serif;
  font-weight: 800;
}

.workspace-heading p,
.workspace-heading h3,
.workspace-heading small {
  margin: 0;
}

.workspace-heading p {
  color: #71837b;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.workspace-heading h3 {
  margin-top: 0.12rem;
  font-size: 1.05rem;
}

.workspace-heading small {
  display: block;
  margin-top: 0.15rem;
  color: #73827c;
  font-size: 0.66rem;
}

.workspace-heading button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid #d4ddd7;
  border-radius: 9px;
  background: white;
  cursor: pointer;
}

.workspace-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-top: 0.9rem;
}

.workspace-field {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.workspace-field:has(textarea),
.workspace-field:has(input[name="f"]),
.workspace-field:has(input[name="g"]),
.workspace-field:has(input[name="expression"]),
.workspace-field:has(input[name="coefficients"]) {
  grid-column: 1 / -1;
}

.workspace-field > span {
  color: #52645d;
  font-size: 0.66rem;
  font-weight: 750;
}

.workspace-field input,
.workspace-field textarea,
.workspace-field select {
  width: 100%;
  min-height: 39px;
  padding: 0.55rem 0.65rem;
  border: 1px solid #c8d3cc;
  border-radius: 10px;
  color: #1e3930;
  background: #fbfdfb;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
}

.workspace-field textarea {
  min-height: 63px;
  resize: vertical;
}

.workspace-execute {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 42px;
  margin-top: 0.85rem;
  padding: 0.42rem 0.9rem 0.42rem 0.42rem;
  border: 0;
  border-radius: 11px;
  color: white;
  background: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
}

.workspace-execute span {
  display: grid;
  min-width: 42px;
  height: 29px;
  place-items: center;
  border-radius: 7px;
  background: #36a877;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.25);
  font-size: 0.6rem;
}

.workspace-empty,
.workspace-output {
  margin-top: 0.9rem;
  padding: 0.85rem;
  border: 1px solid #d6dfd9;
  border-radius: 13px;
  background: #f5f8f5;
}

.workspace-empty {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #78867f;
  font-size: 0.7rem;
}

.workspace-empty span {
  display: grid;
  min-width: 42px;
  height: 29px;
  place-items: center;
  border-radius: 7px;
  color: white;
  background: #5a8171;
  font-size: 0.57rem;
  font-weight: 800;
}

.workspace-empty p {
  margin: 0;
}

.workspace-output > strong {
  display: block;
  margin-bottom: 0.5rem;
  color: #466156;
  font-size: 0.67rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.workspace-output pre {
  margin: 0;
  overflow: auto;
  color: #172d25;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.74rem;
  line-height: 1.65;
  white-space: pre-wrap;
}

.workspace-output.is-error {
  border-color: #e3bfba;
  color: #7d3934;
  background: #fff4f2;
}

.result-table-wrap {
  max-height: 280px;
  overflow: auto;
  border: 1px solid #d5ded8;
  border-radius: 9px;
}

.workspace-output table {
  width: 100%;
  border-collapse: collapse;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.65rem;
}

.workspace-output th,
.workspace-output td {
  padding: 0.42rem 0.5rem;
  border-right: 1px solid #dde4df;
  border-bottom: 1px solid #dde4df;
  text-align: right;
}

.workspace-output th {
  position: sticky;
  top: 0;
  color: #466156;
  background: #e6eee8;
}

.field-help,
.ratio-preview {
  grid-column: 1 / -1;
  margin: 0;
  color: #73837c;
  font-size: 0.64rem;
  line-height: 1.45;
}

.ratio-preview {
  padding: 0.65rem;
  border: 1px dashed #cbd5cf;
  border-radius: 9px;
  text-align: center;
}

.spreadsheet-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 24px repeat(5, minmax(62px, 1fr));
  max-width: 100%;
  overflow: auto;
  border: 1px solid #cfd8d2;
  border-radius: 9px;
  background: white;
}

.spreadsheet-grid b {
  display: grid;
  min-height: 28px;
  place-items: center;
  border-right: 1px solid #dce3df;
  border-bottom: 1px solid #dce3df;
  color: #5b6d65;
  background: #edf2ee;
  font-size: 0.58rem;
}

.spreadsheet-grid input {
  min-width: 62px;
  height: 31px;
  padding: 0.25rem 0.35rem;
  border: 0;
  border-right: 1px solid #e1e6e2;
  border-bottom: 1px solid #e1e6e2;
  border-radius: 0;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.61rem;
}

.visually-hidden,
.hardware-status {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

.calculator-popup {
  place-items: center;
  padding: 0.6rem;
  background: rgba(8, 16, 14, 0.48);
  backdrop-filter: blur(5px);
}

.calculator-window {
  width: min(400px, calc(100vw - 1.2rem));
  max-height: none;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.calculator-stage {
  display: block;
  max-height: none;
  overflow: visible;
  padding: 0;
  background: transparent;
}

.calculator-mount {
  width: min(400px, calc(100vw - 1.2rem));
  margin: 0 auto;
}

.calculator-shell {
  position: relative;
  width: 100%;
  padding: 1.05rem 1rem 0.85rem;
  overflow: hidden;
  border: 6px solid #e5e1d6;
  border-radius: 38px 38px 48px 48px;
  color: #f4f4ef;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.025) 25%, transparent 25%) 0 0 / 8px 8px,
    linear-gradient(315deg, rgba(255,255,255,0.018) 25%, transparent 25%) 0 0 / 8px 8px,
    radial-gradient(circle at 50% 0, #303435, #171a1b 62%, #111314);
  box-shadow:
    0 30px 75px rgba(0, 0, 0, 0.48),
    inset 0 0 0 2px #515556,
    inset 0 -9px 18px rgba(0, 0, 0, 0.42);
}

.calculator-shell::before {
  position: absolute;
  z-index: 0;
  inset: 5px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 29px 29px 39px 39px;
  content: "";
  pointer-events: none;
}

.calculator-shell::after {
  inset: 10px;
  border: 0;
  border-radius: 24px 24px 36px 36px;
  background: repeating-linear-gradient(135deg, rgba(255,255,255,0.018) 0 2px, transparent 2px 7px);
}

.student-calculator {
  box-shadow:
    0 0 0 3px rgba(55, 190, 130, 0.3),
    0 30px 75px rgba(0, 0, 0, 0.48),
    inset 0 0 0 2px #515556;
}

.calculator-branding {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 122px auto;
  align-items: start;
  gap: 0.65rem;
  min-height: 74px;
  padding: 0.1rem 0.25rem 0.6rem;
  cursor: grab;
  touch-action: none;
}

.calculator-window.is-dragging .calculator-branding {
  cursor: grabbing;
}

.calculator-brand-copy {
  display: grid;
  align-content: start;
  min-width: 0;
}

.calculator-brand-copy strong {
  color: #f1f2ed;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.12rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
  text-shadow: 0 2px 1px #050606;
}

.calculator-brand-copy > span {
  margin-top: 0.42rem;
  color: #f2f2ec;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.calculator-brand-copy em {
  margin-top: 0.13rem;
  color: #db638b;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.22em;
}

.calculator-brand-copy small {
  max-width: 130px;
  margin-top: 0.22rem;
  overflow: hidden;
  color: #8bb9a6;
  font-size: 0.36rem;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.solar-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  width: 122px;
  height: 42px;
  padding: 3px;
  border: 4px solid #252728;
  border-radius: 5px;
  background: #0d0f0f;
  box-shadow: inset 0 2px 4px #080909, 0 1px rgba(255,255,255,0.09);
}

.solar-strip i {
  height: auto;
  border-right: 1px solid #74543d;
  background: linear-gradient(115deg, #6a4630, #2b201a 70%);
}

.calculator-hardware-actions {
  display: grid;
  grid-template-columns: repeat(2, 25px);
  align-items: center;
  gap: 0.3rem;
  padding-top: 0.1rem;
}

.calculator-hardware-actions .window-live-dot {
  grid-column: 1 / -1;
  justify-self: center;
  width: 6px;
  height: 6px;
  background: #5bd29a;
  box-shadow: 0 0 0 3px rgba(91,210,154,0.13);
}

.calculator-hardware-actions button {
  display: grid;
  width: 25px;
  height: 25px;
  min-height: 0;
  padding: 0;
  place-items: center;
  border: 1px solid #b8b7ae;
  border-radius: 50%;
  color: #16191a;
  background: radial-gradient(circle at 36% 28%, #f1eee5, #9d9d98 68%, #5d6060);
  box-shadow: 0 2px 0 #050606, inset 0 1px white;
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

.calculator-hardware-actions button:active {
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.45);
  transform: translateY(2px);
}

.calculator-screen {
  min-height: 132px;
  padding: 0.55rem 0.7rem 0.62rem;
  border: 9px solid #292d2c;
  border-radius: 10px;
  color: #111914;
  background:
    repeating-linear-gradient(0deg, rgba(34, 47, 38, 0.025) 0 1px, transparent 1px 3px),
    linear-gradient(145deg, #d6d9bd, #bdc5ac);
  box-shadow: inset 0 3px 8px rgba(20, 28, 22, 0.25), 0 1px rgba(255,255,255,0.08);
}

.screen-main {
  min-height: 85px;
}

.screen-menu {
  inset: 17px 0 0;
  background: #c7ceb4;
}

.screen-menu header {
  background: #c7ceb4;
}

.calculator-navigation {
  display: grid;
  grid-template-columns: 52px 52px minmax(102px, 1fr) 52px 52px;
  align-items: end;
  gap: 0.26rem;
  padding: 0.72rem 0.05rem 0.35rem;
}

.calculator-navigation > button.round-control {
  display: grid;
  grid-template-rows: 17px 38px;
  min-height: 58px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 0;
  color: #e9e2a3;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
}

.calculator-navigation > button.round-control small {
  align-self: start;
  color: #d8ce82;
  font-size: 0.47rem;
  font-weight: 850;
  letter-spacing: 0.03em;
  line-height: 1;
}

.calculator-navigation > button.alpha-control small {
  color: #df678e;
}

.calculator-navigation > button.round-control small b {
  color: #e0d58e;
  font-size: 0.39rem;
}

.calculator-navigation > button.round-control > span {
  display: block;
  width: 38px;
  height: 38px;
  border: 1px solid #aaa99f;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #eee9db, #a4a39d 66%, #5c5e5d);
  box-shadow: 0 3px 0 #050606, inset 0 1px white;
}

.calculator-navigation > button.round-control.local-pressed,
.calculator-navigation > button.round-control.remote-pressed {
  background: transparent !important;
  box-shadow: none !important;
  transform: none;
}

.calculator-navigation > button.round-control.local-pressed > span {
  box-shadow: inset 0 3px 5px rgba(0,0,0,0.45);
  transform: translateY(3px);
}

.calculator-navigation > button.round-control.remote-pressed > span {
  box-shadow: 0 0 0 4px rgba(67, 219, 147, 0.48), inset 0 3px 5px rgba(0,0,0,0.32) !important;
  transform: translateY(3px);
}

.direction-pad {
  align-self: end;
  grid-template-columns: 1fr 1.25fr 1fr;
  grid-template-rows: 26px 33px 26px;
  min-width: 102px;
  height: 85px;
  border: 0;
  border-radius: 48%;
  background: #050707;
  box-shadow: 0 3px 0 #050606;
}

.direction-pad button {
  color: #1a1d1d;
  background: linear-gradient(#d7d2c5, #878884);
  font-size: 0.48rem;
  text-shadow: 0 1px rgba(255,255,255,0.3);
}

.direction-pad [data-key="cursor-up"] { border-radius: 50% 50% 8% 8%; }
.direction-pad [data-key="cursor-left"] { border-radius: 50% 8% 8% 50%; }
.direction-pad [data-key="cursor-right"] { border-radius: 8% 50% 50% 8%; }
.direction-pad [data-key="cursor-down"] { border-radius: 8% 8% 50% 50%; }
.direction-pad [data-key="ok"] {
  border: 5px solid #050707;
  border-radius: 42%;
  background: #111414;
}

.direction-pad button.local-pressed,
.direction-pad button.remote-pressed {
  color: #1a1d1d !important;
  background: linear-gradient(#d7d2c5, #878884) !important;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.42) !important;
  transform: translateY(2px);
}

.direction-pad button.remote-pressed {
  outline: 3px solid rgba(67, 219, 147, 0.62);
}

.calculator-quick-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.48rem;
  padding: 0.1rem 0.15rem 0.35rem;
}

.calculator-quick-row button {
  display: grid;
  grid-template-rows: 12px 34px;
  min-width: 0;
  min-height: 47px;
  padding: 0;
  border: 0;
  color: #f1f2ee;
  background: transparent;
  cursor: pointer;
}

.calculator-quick-row button small {
  color: #d6ca82;
  font-size: 0.42rem;
  font-weight: 800;
}

.calculator-quick-row button strong {
  display: grid;
  place-items: center;
  border: 1px solid #696d6c;
  border-radius: 5px 5px 8px 8px;
  background: linear-gradient(#383d3d, #111415);
  box-shadow: 0 3px 0 #050606, inset 0 1px rgba(255,255,255,0.16);
  font-size: 0.72rem;
}

.calculator-quick-row button.local-pressed strong {
  box-shadow: inset 0 3px 5px rgba(0,0,0,0.5);
  transform: translateY(3px);
}

.calculator-quick-row button.remote-pressed strong {
  border-color: #4cdc94;
  box-shadow: 0 0 0 4px rgba(67, 219, 147, 0.36), inset 0 3px 5px rgba(0,0,0,0.38);
  transform: translateY(3px);
}

.calculator-keys {
  display: grid;
  padding: 0.1rem 0.05rem 0;
}

.scientific-keys {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.3rem 0.34rem;
}

.numeric-keys {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.42rem 0.44rem;
  margin-top: 0.28rem;
}

.calc-key {
  grid-template-rows: 11px minmax(31px, auto);
  min-height: 45px;
}

.calc-key small {
  color: #d7ca82;
  font-size: 0.4rem;
  line-height: 10px;
}

.calc-key small.legend-pink { color: #df638d; }
.calc-key small.legend-blue { color: #31a9d3; }
.calc-key small.legend-gold { color: #d7ca82; }

.scientific-keys .calc-key strong {
  height: 32px;
  border-color: #5e6361;
  border-radius: 4px 4px 7px 7px;
  background: linear-gradient(#3b4040, #121516);
  box-shadow: 0 3px 0 #050606, inset 0 1px rgba(255,255,255,0.15);
  font-size: 0.68rem;
}

.numeric-keys .calc-key {
  grid-template-rows: 12px minmax(42px, auto);
  min-height: 57px;
}

.numeric-keys .calc-key strong,
.numeric-keys .key-number strong,
.numeric-keys .key-operator strong,
.numeric-keys .key-execute strong {
  height: 43px;
  color: #171a1b;
  border-color: #d3d0c8;
  border-radius: 5px 5px 9px 9px;
  background: linear-gradient(#fffefa, #d6d4cd);
  box-shadow: 0 4px 0 #7d7d78, inset 0 1px white;
  font-size: 1.02rem;
  font-weight: 800;
  text-shadow: none;
}

.numeric-keys .key-danger-soft strong {
  color: white;
  border-color: #1871d3;
  background: linear-gradient(#147ee5, #0756b5);
  box-shadow: 0 4px 0 #06366d, inset 0 1px rgba(255,255,255,0.3);
  font-size: 0.82rem;
  text-shadow: 0 1px #06366d;
}

.numeric-keys .key-execute strong {
  font-size: 1.25rem;
}

.calculator-shell .calc-key.remote-pressed strong {
  border-color: #42dd91 !important;
  box-shadow: 0 0 0 4px rgba(67, 219, 147, 0.5), inset 0 3px 6px rgba(0,0,0,0.22) !important;
  transform: translateY(3px) scale(0.98);
  animation: student-key-pulse 360ms ease;
}

.calculator-shell .scientific-keys .calc-key.remote-pressed strong {
  color: #f4f4ef !important;
  background: linear-gradient(#3b4040, #121516) !important;
}

.calculator-shell .numeric-keys .calc-key.remote-pressed strong {
  color: #171a1b !important;
  background: linear-gradient(#fffefa, #d6d4cd) !important;
  text-shadow: none !important;
}

.calculator-shell .numeric-keys .key-danger-soft.remote-pressed strong {
  color: white !important;
  background: linear-gradient(#147ee5, #0756b5) !important;
  text-shadow: 0 1px #06366d !important;
}

.calculator-model {
  display: flex;
  min-height: 24px;
  margin-top: 0.5rem;
  padding: 0 0.3rem;
  color: #88928e;
  font-size: 0.42rem;
}

.calculator-model > span {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  min-width: 0;
}

.calculator-model > span i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #48d693;
  box-shadow: 0 0 0 3px rgba(72,214,147,0.13);
}

.calculator-model > span b {
  overflow: hidden;
  color: #9ba6a1;
  font-family: inherit;
  font-size: 0.42rem;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calculator-model > strong {
  color: #dc638b;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.46rem;
  letter-spacing: 0.14em;
}

.calculator-shell .advanced-workspace {
  position: absolute;
  z-index: 50;
  inset: 80px 10px 12px;
  width: auto;
  min-width: 0;
  max-width: none;
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 0.85rem;
  border: 8px solid #252929;
  border-radius: 10px 10px 32px 32px;
  color: #26362f;
  background: #f2f3e8;
  box-shadow: inset 0 2px 7px rgba(18,35,27,0.18), 0 8px 22px rgba(0,0,0,0.35);
}

.calculator-shell .workspace-heading {
  grid-template-columns: 38px 1fr 32px;
  gap: 0.55rem;
}

.calculator-shell .workspace-heading > span {
  width: 38px;
  height: 38px;
  border-radius: 7px;
}

.calculator-shell .workspace-fields {
  gap: 0.55rem;
}

.calculator-shell .workspace-scientific-keys,
.calculator-shell .workspace-numeric-keys {
  margin-top: 0.55rem;
  padding: 0.35rem 0.4rem;
  border-radius: 10px;
  background: linear-gradient(#2c3130, #151818);
}

.calculator-shell .workspace-numeric-keys {
  margin-top: 0.25rem;
}

.workspace-execute.local-pressed,
.workspace-execute.remote-pressed {
  color: white;
  background: #278b63;
}

body[data-role="student"] .calculator-popup {
  background: rgba(7, 18, 22, 0.48);
}


@media (max-width: 680px) {
  .calculator-popup {
    align-items: start;
    justify-items: center;
    padding: 0.45rem;
  }

  .calculator-window {
    width: min(400px, calc(100vw - 0.9rem));
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .calculator-stage {
    display: block;
    padding: 0;
  }

  .calculator-mount {
    width: min(400px, calc(100vw - 0.9rem));
  }

  .calculator-shell .advanced-workspace {
    position: absolute;
    width: auto;
    min-width: 0;
    min-height: 0;
    max-width: none;
  }
}

@media (max-width: 390px) {
  .calculator-shell {
    padding: 0.9rem 0.72rem 0.75rem;
    border-width: 5px;
  }

  .calculator-branding {
    grid-template-columns: minmax(0, 1fr) 105px auto;
    gap: 0.4rem;
  }

  .solar-strip {
    width: 105px;
  }

  .calculator-navigation {
    grid-template-columns: 47px 47px minmax(94px, 1fr) 47px 47px;
    gap: 0.12rem;
  }

  .direction-pad {
    min-width: 94px;
  }

  .scientific-keys {
    gap-inline: 0.22rem;
  }

  .numeric-keys {
    gap-inline: 0.3rem;
  }

  .numeric-keys .calc-key strong,
  .numeric-keys .key-number strong,
  .numeric-keys .key-operator strong,
  .numeric-keys .key-execute strong {
    height: 41px;
  }
}

/* Embedded lesson-room surface: only the handset is visible. */
.calculator-stage,
.calculator-mount {
  width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  overflow: hidden;
  padding: 0;
  background: transparent;
}
.calculator-shell {
  width: 100%;
  max-width: none;
  min-height: 100%;
  margin: 0;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.42), inset 0 0 0 2px #515556, inset 0 -9px 18px rgba(0, 0, 0, 0.42);
}
.calculator-branding {
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.calculator-branding.is-dragging { cursor: grabbing; }
.calculator-hardware-actions button { touch-action: manipulation; }
body[data-role="student"] .calculator-branding { cursor: default; }
body[data-role="student"] .calculator-shell {
  box-shadow: 0 0 0 3px rgba(55, 190, 130, 0.3), 0 18px 38px rgba(0, 0, 0, 0.42), inset 0 0 0 2px #515556;
}

/* The embedded handset must show every key inside the movable lesson pop-up. */
.calculator-shell {
  padding: .5rem .65rem .42rem;
  border-width: 4px;
  border-radius: 28px 28px 36px 36px;
}
.calculator-shell::before { inset: 3px; border-radius: 22px 22px 30px 30px; }
.calculator-shell::after { inset: 7px; border-radius: 19px 19px 27px 27px; }
.calculator-branding {
  grid-template-columns: minmax(0,1fr) 96px auto;
  min-height: 50px;
  gap: .38rem;
  padding: .05rem .18rem .32rem;
}
.calculator-brand-copy strong { font-size: .88rem; }
.calculator-brand-copy > span { margin-top: .22rem; font-size: .48rem; }
.calculator-brand-copy em { font-size: .48rem; }
.calculator-brand-copy small { margin-top: .08rem; font-size: .3rem; }
.solar-strip { width: 96px; height: 33px; border-width: 3px; }
.calculator-hardware-actions { grid-template-columns:repeat(2,22px); gap:.18rem; padding-top:0; }
.calculator-hardware-actions button { width:22px; height:22px; font-size:.68rem; }
.calculator-screen {
  min-height: 98px;
  padding: .34rem .5rem .38rem;
  border-width: 6px;
}
.screen-main { min-height: 58px; grid-template-rows:minmax(28px,auto) auto 1fr; }
.screen-expression { padding-top:.2rem; font-size:.78rem; }
.screen-result { font-size:1.05rem; }
.calculator-navigation {
  grid-template-columns: 42px 42px minmax(90px,1fr) 42px 42px;
  gap: .14rem;
  padding: .34rem .02rem .18rem;
}
.calculator-navigation > button.round-control {
  grid-template-rows: 12px 32px;
  min-height: 46px;
}
.calculator-navigation > button.round-control small { font-size:.39rem; }
.calculator-navigation > button.round-control > span { width:32px; height:32px; }
.direction-pad {
  grid-template-rows: 20px 26px 20px;
  min-width:90px;
  height:66px;
}
.calculator-quick-row { gap:.28rem; padding:.04rem .08rem .16rem; }
.calculator-quick-row button { grid-template-rows:8px 28px; min-height:38px; }
.calculator-quick-row button small { font-size:.34rem; }
.calculator-quick-row button strong { font-size:.62rem; }
.calculator-keys { padding-top:.04rem; }
.scientific-keys { gap:.12rem .24rem; }
.calc-key { grid-template-rows:7px minmax(26px,auto); min-height:34px; }
.calc-key small { font-size:.32rem; line-height:7px; }
.scientific-keys .calc-key strong { height:27px; font-size:.58rem; }
.numeric-keys { gap:.2rem .34rem; margin-top:.12rem; }
.numeric-keys .calc-key { grid-template-rows:8px minmax(39px,auto); min-height:48px; }
.numeric-keys .calc-key strong,
.numeric-keys .key-number strong,
.numeric-keys .key-operator strong,
.numeric-keys .key-execute strong { height:39px; font-size:.9rem; }
.numeric-keys .key-danger-soft strong { font-size:.72rem; }
.calculator-model { min-height:16px; margin-top:.22rem; font-size:.36rem; }
.calculator-model > span b,.calculator-model > strong { font-size:.36rem; }
.calculator-shell .advanced-workspace { inset:55px 8px 8px; }

/* Below the normal handset width, scale the complete 340 × 650 calculator so
   every display, key and footer remains visible inside the resized host. */
body.is-ultra-compact {
  display: block;
  place-items: initial;
}
body.is-ultra-compact .calculator-stage {
  width: 340px;
  height: 650px;
  inset: 0 auto auto 0;
  justify-self: start;
  margin: 0;
  position: fixed;
  transform: scale(var(--calculator-compact-scale));
  transform-origin: top left;
}
body.is-ultra-compact .calculator-mount,
body.is-ultra-compact .calculator-shell {
  width: 340px;
  height: 650px;
  min-height: 650px;
}
