:root {
  --key: min(78px, calc((100vw - 5 * 14px) / 4));
  --gap: min(14px, calc(var(--key) * 0.18));
  --digit: #333333;
  --function: #a5a5a5;
  --operator: #ff9f0a;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: #000;
  color: #fff;
  font-family: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.back {
  position: fixed;
  top: 16px;
  left: 20px;
  color: #a5a5a5;
  text-decoration: none;
  font-size: 15px;
}

.back:hover, .back:focus-visible { color: #fff; }

.calculator {
  width: calc(4 * var(--key) + 5 * var(--gap));
  padding: 0 calc(var(--gap) / 2);
}

.display {
  display: block;
  height: 150px;
  padding: 0 14px 6px;
  font-weight: 300;
  font-size: 84px;
  line-height: 150px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  user-select: text;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, var(--key));
  gap: var(--gap);
  padding: calc(var(--gap) / 2);
}

button {
  display: grid;
  place-items: center;
  width: var(--key);
  height: var(--key);
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: var(--digit);
  color: #fff;
  font: inherit;
  font-size: calc(var(--key) * 0.44);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: filter 0.25s, background-color 0.2s, color 0.2s;
}

button.fn { background: var(--function); color: #000; font-size: calc(var(--key) * 0.36); }
button.op { background: var(--operator); font-size: calc(var(--key) * 0.51); }

/* A selected operator swaps to white with an orange symbol, like a phone calculator. */
button.op.selected { background: #fff; color: var(--operator); }

button:active, button.flash { filter: brightness(1.45); transition: none; }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* calculator.js nudges each label so its ink, not its font box, is centred. */
button span { display: block; white-space: nowrap; }

button svg {
  display: block;
  width: calc(var(--key) * 0.46);
  height: auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* Shift left a little so the icon is centred on its area, not its outline. */
  transform: translateX(-4%);
}
