:root {
  --orange: #ff9f0a;
  --orange-active: #fff;
  --grey: #a5a5a5;
  --dark-grey: #333;
  --black: #000;
  --white: #fff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black);
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: clamp(12px, 4vw, 24px);
}

.calculator {
  display: flex;
  width: min(100%, 350px);
  height: min(100%, 590px);
  flex-direction: column;
}

.display {
  display: flex;
  flex: 1 1 auto;
  min-height: 90px;
  align-items: flex-end;
  justify-content: flex-end;
  overflow: hidden;
  padding: 8px 8px 14px;
}

#display {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(3.25rem, 17vw, 5rem);
  font-weight: 300;
  line-height: 1;
  text-align: right;
  text-overflow: clip;
  white-space: nowrap;
}

.buttons {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 3vw, 14px);
}

.key {
  aspect-ratio: 1;
  width: 100%;
  border: 0;
  border-radius: 999px;
  background: var(--dark-grey);
  color: var(--white);
  cursor: pointer;
  font: inherit;
  font-size: clamp(1.45rem, 7vw, 2rem);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.key:active {
  filter: brightness(1.65);
}

.key:focus-visible {
  outline: 3px solid #70b7ff;
  outline-offset: 2px;
}

.control {
  background: var(--grey);
  color: var(--black);
  font-size: clamp(1.15rem, 5.5vw, 1.55rem);
}

.operator {
  background: var(--orange);
  font-size: clamp(1.8rem, 8vw, 2.35rem);
}

.operator.selected {
  background: var(--orange-active);
  color: var(--orange);
}

.zero {
  aspect-ratio: auto;
  grid-column: span 2;
  padding-left: 28px;
  text-align: left;
}

@media (hover: hover) {
  .key:hover {
    filter: brightness(1.35);
  }
}

@media (max-height: 520px) {
  body {
    padding: 8px;
  }

  .calculator {
    width: min(100%, 280px);
  }

  .display {
    min-height: 64px;
    padding-bottom: 8px;
  }

  .buttons {
    gap: 7px;
  }
}
