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

html, body {
  margin: 0;
  height: 100%;
  background: #16181d;
  color: #f2f3f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.calc {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-width: 420px;
  height: 100%;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  padding: 8px 6px 18px;
  min-height: 140px;
  overflow: hidden;
}

.expr {
  min-height: 1.4em;
  font-size: 20px;
  color: #8b909a;
  white-space: nowrap;
}

.out {
  font-size: 64px;
  font-weight: 300;
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.out.s1 { font-size: 48px; }
.out.s2 { font-size: 34px; }
.out.s3 { font-size: 24px; white-space: normal; word-break: break-all; text-align: right; }

.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.k {
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 50%;
  background: #2b2f38;
  color: #f2f3f5;
  font: inherit;
  font-size: 28px;
  cursor: pointer;
  touch-action: manipulation;
  transition: filter 0.08s;
}
.k:active { filter: brightness(1.35); }
.k:focus-visible { outline: 2px solid #5ec2b7; outline-offset: 2px; }
.k.fn { background: #4a505c; font-size: 22px; }
.k.op { background: #2f8f86; font-size: 32px; }
.k.eq { background: #e0a33a; color: #16181d; font-size: 32px; }

@media (min-width: 700px) {
  .calc { justify-content: center; }
  .screen { flex: 0 0 auto; }
}
