:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, sans-serif;
  color: #ecebdd;
  background: #d9d3bf;
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

body {
  --top-gutter: max(14px, env(safe-area-inset-top));
  --bottom-gutter: max(14px, env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: var(--top-gutter) max(12px, env(safe-area-inset-right))
    var(--bottom-gutter) max(12px, env(safe-area-inset-left));
  background: radial-gradient(#ada58a 0.7px, transparent 0.7px) 0 0 / 7px 7px;
}

.calculator {
  display: flex;
  flex-direction: column;
  width: min(100%, 480px);
  min-height: calc(100svh - var(--top-gutter) - var(--bottom-gutter));
  min-height: calc(100dvh - var(--top-gutter) - var(--bottom-gutter));
  padding: clamp(13px, 4vw, 25px);
  border: 1px solid #11191b;
  border-radius: 27px 27px 37px 37px;
  background: linear-gradient(145deg, #353f40, #222a2c 70%);
  box-shadow: inset 0 2px 0 #ffffff26, inset 0 -4px 0 #0005, 0 14px 32px #37342245;
}

.face {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 15px;
}

h1 {
  margin: 0;
  font-size: clamp(1.03rem, 5vw, 1.4rem);
  font-weight: 850;
  letter-spacing: .055em;
}

h1 span { color: #bed090; }

button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid #f6e9ad; outline-offset: 3px; }

.run-button {
  min-height: 44px;
  padding: .4rem .8rem;
  color: #eff3d6;
  background: #455744;
  border: 1px solid #63785a;
  border-radius: 8px;
  box-shadow: inset 0 1px #ffffff22, 0 2px 0 #111c16;
  font-size: .85rem;
  font-weight: 700;
}

.run-button:active { transform: translateY(1px); }

.bezel {
  padding: 10px;
  border-radius: 14px;
  background: #171e20;
  border: 1px solid #495456;
  box-shadow: inset 0 2px 8px #0009;
}

.readout {
  display: flex;
  justify-content: space-between;
  gap: 5px 12px;
  flex-wrap: wrap;
  margin: 0 2px 9px;
  color: #cbd5aa;
  font: 600 .68rem ui-monospace, SFMono-Regular, monospace;
}

.readout div { display: flex; align-items: baseline; gap: 6px; }
.readout dt { text-transform: uppercase; letter-spacing: .07em; }
.readout dd { margin: 0; color: #e7edcf; font-variant-numeric: tabular-nums; }

.screen {
  position: relative;
  overflow: hidden;
  border-radius: 5px;
  --lcd-key: #c6cea6;
  background: #acb787;
  box-shadow: inset 0 2px 6px #34452a60;
}
.screen-field { position: relative; }

canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }

#steering-help {
  position: absolute;
  bottom: 5%;
  left: 50%;
  translate: -50%;
  margin: 0;
  width: max-content;
  max-width: 94%;
  padding: .18em .35em;
  background: #c1c99f;
  color: #26392e;
  font: 700 clamp(.55rem, 2.3vw, .78rem)/1.2 ui-monospace, monospace;
  text-align: center;
}
#steering-help kbd { color: inherit; }

.screen-status {
  position: absolute;
  bottom: 12%;
  left: 50%;
  translate: -50% 0;
  width: max-content;
  max-width: calc(100% - 16px);
  color: #26392e;
  background: #c1c99f;
  padding: .25em .55em;
  font: 800 clamp(.72rem, 3vw, 1rem) ui-monospace, SFMono-Regular, monospace;
  letter-spacing: .12em;
  text-align: center;
}

#enter-help { margin: .25em 0 0; font-size: .82em; line-height: 1.2; letter-spacing: 0; }
.screen-status[data-ready] {
  top: 7%;
  bottom: auto;
  font-size: clamp(.68rem, 3vw, 1rem);
  letter-spacing: 0;
}

.game-over:not([hidden]) {
  position: absolute;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  box-sizing: border-box;
  inline-size: min(270px, calc(100% - 10px));
  max-block-size: calc(100% - 8px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: .45em;
  border: 2px solid #394d32;
  background: #c1c99f;
  color: #26392e;
  font: 750 clamp(.68rem, 3vw, .95rem)/1.15 ui-monospace, monospace;
  text-align: center;
}
.game-over h2 { margin: 0 0 .2em; font-size: 1.15em; }
.game-over h2:focus-visible { outline: 2px solid #273d2e; outline-offset: 2px; }
.game-over p { margin: 0 0 .32em; }
.game-over .game-over-quip { font-size: .88em; font-weight: 650; }
.game-over-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
.game-over .lcd-button { min-width: 0; border-radius: 2px; font-size: .92em; overflow-wrap: anywhere; }
#new-game,
#extra-life:has(+ #rewarded-life[hidden]),
#extra-life[hidden] + #rewarded-life { grid-column: 1 / -1; }
#rewarded-life:not([hidden]) { display: grid; place-items: center; }
#rewarded-life > span { grid-area: 1 / 1; }
#rewarded-life:not([aria-busy="true"]) .rewarded-loading,
#rewarded-life[aria-busy="true"] .rewarded-label { visibility: hidden; }
.ad-badge { white-space: nowrap; }
.ad-play {
  display: inline-block;
  padding: .08em .18em;
  border: 1px solid currentColor;
  border-radius: 2px;
  font-size: .8em;
}
.game-over #rewarded-lives-left,
.game-over #rewarded-ad-status { margin: .35em 0 0; font-size: .84em; }
#rewarded-ad-status:empty { display: none; }
.lcd-notice {
  padding: .35em .5em;
  margin: 0;
  background: var(--lcd-key);
  color: #26392e;
  font: 700 .74rem/1.25 ui-monospace, monospace;
  text-align: center;
}
.lcd-notice:empty { display: none; }

.lcd-button {
  min-width: 44px;
  min-height: 44px;
  padding: .15em .4em;
  border: 1px solid #5c6c4b;
  background: var(--lcd-key);
  color: #26392e;
  font: 750 .625rem/1.12 ui-monospace, monospace;
}
.lcd-button:active { background: #e0e7bd; }
.lcd-button:focus-visible { outline: 2px solid #273d2e; outline-offset: -3px; }

.keypad {
  --key-min-height: 17px;
  --utility-key-min-height: 44px;
  --key-gap: clamp(3px, .8vw, 6px);
  flex: 1 1 0;
  display: grid;
  container: keypad / size;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: minmax(var(--utility-key-min-height), 1fr) minmax(var(--key-min-height), 1fr) repeat(2, minmax(21px, 1fr));
  grid-auto-rows: minmax(var(--key-min-height), 1fr);
  min-height: calc(6 * var(--key-min-height) + 42px + var(--utility-key-min-height) + 8 * var(--key-gap));
  gap: var(--key-gap);
  margin-top: 10px;
  user-select: none;
}

.decorative-key,
.key-action {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 1px 2px;
  color: #e8ebdf;
  background: linear-gradient(#515b59, #333c3e);
  border: 1px solid #1a2425;
  border-radius: 5px 5px 7px 7px;
  box-shadow: inset 0 1px #ffffff28, 0 1px #101819;
  font: 700 clamp(8px, 2.7vw, 10px)/1 ui-monospace, SFMono-Regular, monospace;
  text-align: center;
}

.key-slot {
  display: grid;
  min-width: 0;
  min-height: 0;
}
.key-slot > [hidden] { display: none; }
.key-action { touch-action: manipulation; }
.key-action:active { transform: translateY(1px); }
.key-action:focus-visible { outline-offset: -3px; }
#privacy-options {
  border-color: #789178;
  background: linear-gradient(#516757, #3b4e40);
  color: #f0f2d3;
}
#privacy-options:not([hidden]) + .privacy-placeholder { display: none; }
#remove-ads { padding: 0 2px; }
#remove-ads svg {
  display: block;
  width: min(100%, 44px);
  height: 100%;
  max-height: 26px;
}
#remove-ads :is(circle, path) {
  fill: none;
  stroke: #ff716b;
  stroke-width: 2.4;
}

.graph-key { background: linear-gradient(#526761, #3a4a4a); color: #e8edc6; }
.second-key { background: linear-gradient(#e1c37c, #bca161); color: #242d2c; }
.alpha-key { background: linear-gradient(#95a877, #718961); color: #202e25; }
.number-key {
  color: #293430;
  background: linear-gradient(#c2c4ae, #9ea391);
  font-size: clamp(11px, 3.5vw, 15px);
}
.operator-key, .power-key { background: linear-gradient(#465252, #273134); }
.scientific-key { display: none; }

.enter-key {
  grid-area: 9 / 5;
  min-height: 0;
  padding: 0;
  border-radius: 5px 5px 7px 7px;
  font: 800 clamp(8px, 2.7vw, 10px)/1 ui-monospace, monospace;
}
.enter-key:focus-visible { outline-offset: -3px; }

@container keypad (min-height: 265px) {
  .enter-key { grid-row: 11; }
  .scientific-key { display: grid; }
}

.arrow-pad {
  grid-area: 3 / 4 / span 2 / span 2;
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(44px, 1fr));
  min-height: 44px;
  gap: 2px;
  border-radius: 50%;
  background: #212d2a;
  box-shadow: inset 0 1px 5px #101917;
}

.steer {
  min-height: 44px;
  display: grid;
  place-items: center;
  color: #eff3d6;
  background: #455744;
  border: 1px solid #839478;
  box-shadow: inset 0 1px #ffffff22, 0 2px 0 #111c16;
  font-size: min(40px, clamp(1.2rem, 6vw, 1.65rem));
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.steer.left { border-radius: 50% 3px 3px 50%; }
.steer.right { border-radius: 3px 50% 50% 3px; }

.steer:focus-visible { outline-offset: -5px; }
.steer:active,
.steer[data-held] { color: #1e3427; background: #e6edcc; }
.steer:active:focus-visible,
.steer[data-held]:focus-visible { outline-color: #283e2f; }

.side-controls {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.side-control {
  width: clamp(28px, 10vw, 104px);
  opacity: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  pointer-events: none;
  transition: opacity .2s ease-out;
}

.side-controls[data-mode="ready"] .side-control { opacity: .55; }
.side-controls[data-mode="playing"] .side-control { pointer-events: auto; }

.keypad button {
  position: relative;
  z-index: 2;
}

@media (prefers-reduced-motion: reduce) {
  .side-control { transition: none; }
}

.controls-help {
  margin: 13px 0 2px;
  color: #d2d8c3;
  text-align: center;
  font-size: .78rem;
  line-height: 1.5;
}

kbd { color: #edf0d4; font-size: 1em; }

@media (orientation: portrait) and (max-height: 650px) {
  .calculator { padding-block: 9px; }
  .face { margin-bottom: 8px; }
  .bezel { padding-block: 6px; }
  .keypad { --key-min-height: 15px; --key-gap: 3px; margin-top: 6px; }
  .controls-help { margin-top: 6px; }
  .screen-field {
    width: min(100%, max(130px, calc(100svh - 320px)));
    margin-inline: auto;
  }
}

@media (orientation: landscape) and (max-height: 490px) {
  .calculator { width: min(100%, 470px); padding: 10px; }
  .screen {
    --compact-lcd-size: max(112px, calc(100svh - max(174px, 128px + 1.7rem)));
    width: min(100%, var(--compact-lcd-size));
    margin-inline: auto;
  }
  .screen:has(.game-over:not([hidden])) {
    --compact-lcd-size: max(164px, calc(100svh - max(192px, 145px + 1.7rem)));
    width: 100%;
  }
  .screen canvas {
    width: min(100%, var(--compact-lcd-size));
    margin-inline: auto;
  }
  .screen:has(.screen-status[data-ready]:not([hidden])) { width: 100%; }
  .screen-field:has(.screen-status[data-ready]:not([hidden])) {
    display: grid;
    grid-template: 1fr 20px 1fr / minmax(0, 1fr);
    justify-items: center;
    align-items: start;
    min-block-size: var(--compact-lcd-size);
    padding-block: 5px;
  }
  .screen-field:has(.screen-status[data-ready]:not([hidden])) canvas {
    position: absolute;
    inset: 50% auto auto 50%;
    translate: -50% -50%;
  }
  .screen-field:has(.screen-status[data-ready]:not([hidden])) :is(.screen-status, #steering-help) {
    position: relative;
    inset: auto;
    translate: none;
  }
  .screen-status[data-ready] { grid-row: 1; }
  #steering-help { grid-row: 3; align-self: end; }
  .face { margin-bottom: 8px; }
  h1 { font-size: clamp(.85rem, 3.8svh, 1.1rem); }
  .bezel { padding: 7px; }
  .keypad { margin-top: 5px; }
  .screen-status {
    max-width: calc(100% - 6px);
    padding-inline: .2em;
    font-size: clamp(.64rem, 2.55vw, .9rem);
    letter-spacing: .04em;
  }
  .screen-status[data-ready] { font-size: clamp(.55rem, 2.55vw, .8rem); }
  .controls-help { margin-top: 6px; }
}

@media (orientation: landscape) and (min-width: 520px) and (max-height: 790px) {
  .calculator {
    display: grid;
    width: min(100%, 940px);
    grid-template-columns: min(428px, 61%) minmax(0, 1fr);
    grid-template-rows: auto minmax(min-content, 1fr);
    column-gap: clamp(12px, 2.3vw, 20px);
  }
  .face {
    grid-area: 1 / 1 / 2 / -1;
    margin-bottom: 6px;
  }
  .bezel { grid-area: 2 / 1; align-self: center; }
  .keypad { grid-area: 2 / 2; margin: 0; }
}

@media (orientation: landscape) and (min-width: 520px) and (max-height: 490px) {
  .calculator {
    width: min(100%, 740px);
    padding-block: 8px;
    grid-template-columns: minmax(0, 49%) minmax(0, 1fr);
  }
  .face { flex-wrap: nowrap; margin-bottom: 4px; }
  .face .run-button { padding: .2em .45rem; }
  .bezel { padding-block: 6px; }
  .readout { gap: 3px 6px; margin-bottom: 6px; }
  .keypad { --key-min-height: 15px; --key-gap: 3px; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#lives {
  display: inline-flex;
  justify-content: flex-end;
  min-width: 3ch;
  gap: .2em;
  color: #eecc82;
  font-weight: 800;
}

.run-button:disabled { opacity: .65; cursor: wait; }
.store-actions:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
}

#remove-ads-dialog {
  width: min(380px, calc(100% - 28px));
  max-inline-size: calc(100% - 28px);
  max-block-size: calc(100svh - max(14px, env(safe-area-inset-top)) - max(14px, env(safe-area-inset-bottom)));
  padding: clamp(12px, 3svh, 18px) clamp(12px, 3.75vw, 18px);
  overflow: hidden;
  border: 1px solid #63785a;
  border-radius: 14px;
  color: #ecebdd;
  background: #26302e;
}

#remove-ads-dialog::backdrop { background: #0b1510a6; }
#remove-ads-dialog h2 { margin: 0; }

#remove-ads-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
}

.purchase-dialog-body {
  overflow: auto;
  padding: 5px;
  scroll-padding-block: 5px;
}

.purchase-dialog-body > p { margin: 0; }
.purchase-dialog-body .run-button {
  max-inline-size: 100%;
  overflow-wrap: anywhere;
}

#buy-remove-ads { padding-inline: 8px; }

.purchase-dialog-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 5px;
}

#remove-ads-status { margin: 0; font-size: .85rem; overflow-wrap: anywhere; }

#house-ad {
  max-width: min(23rem, calc(100% - 24px));
  padding: 1rem;
  color: #ecebdd;
  background: #26302e;
  border: 1px solid #839478;
  border-radius: 14px;
}
#house-ad::backdrop { background: #0b1510a6; }
