*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #11131a;
  color: #f4f6fb;
  -webkit-text-size-adjust: 100%;
}

.calculator {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  min-height: 100vh;
  padding: 1rem;
}

.display {
  padding: 0.5rem 0.75rem;
  text-align: right;
}

.expression {
  min-height: 1.5em;
  font-size: 0.9rem;
  color: #9aa3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result {
  display: block;
  font-size: clamp(1.75rem, 10vw, 2.5rem);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The error message is text, not a number, so it needs to fit rather than fill. */
.result.is-error {
  font-size: 1.25rem;
}

.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  flex: 1;
}

.keys button {
  min-height: 44px;
  padding: 0.5rem;
  border: 0;
  border-radius: 0.75rem;
  background: #262a36;
  color: inherit;
  font: inherit;
  font-size: 1.375rem;
  cursor: pointer;
  touch-action: manipulation;
}

.keys button:active {
  filter: brightness(1.4);
}

.keys button:focus-visible {
  outline: 2px solid #7aa2ff;
  outline-offset: 2px;
}

.keys button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.keys .key-fn {
  background: #39404f;
}

.keys .key-op {
  background: #4a4258;
}

.keys .key-equals {
  background: #3b6cf6;
  grid-row: span 2;
}

.key-zero {
  grid-column: span 2;
}

@media (min-width: 480px) {
  body {
    align-items: center;
    padding: 1.5rem;
  }

  .calculator {
    max-width: 22rem;
    min-height: 0;
    background: #1a1e28;
    border-radius: 1.25rem;
    box-shadow: 0 1.5rem 3rem rgb(0 0 0 / 45%);
  }

  .keys {
    flex: 0 0 auto;
  }

  .keys button {
    min-height: 3.5rem;
  }
}
