* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: pan-x pan-y;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #000;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.calculator {
  width: 100%;
  max-width: 400px;
}

.history-row {
  display: flex;
  align-items: flex-end;
  padding: 0 10px;
}

.history-row.hidden {
  display: none;
}

.history {
  flex: 1;
  text-align: right;
  color: #888;
  font-size: 1rem;
  max-height: 1.5em;
  overflow: hidden;
}

.history-toggle {
  background: none;
  border: none;
  color: #555;
  padding: 0 0 0 8px;
  cursor: pointer;
  transition: color 0.2s;
}

.history-toggle.expanded {
  color: #ff9f0a;
}

.history.expanded {
  max-height: 200px;
  overflow-y: auto;
}

.history-item {
  padding: 4px 0;
  transition: color 0.1s;
}

.history-item:active {
  color: #ff9f0a;
}

.display {
  width: 100%;
  background: transparent;
  color: #fff;
  font-size: 3.5rem;
  text-align: right;
  padding: 20px 10px;
  margin-bottom: 10px;
  min-height: 4.5rem;
  cursor: text;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  white-space: nowrap;
  overflow-x: auto;
}

.display-text:empty::before {
  content: "0";
  color: #888;
}

.display .char {
  display: inline-block;
}

.cursor {
  position: absolute;
  width: 2px;
  height: 0.8em;
  background: #ff9f0a;
  animation: blink 1s step-end infinite;
  pointer-events: none;
}

@keyframes blink {
  50% { opacity: 0; }
}

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

.btn {
  aspect-ratio: 1;
  border: none;
  border-radius: 50%;
  font-size: 1.8rem;
  cursor: pointer;
  transition: opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  opacity: 0.7;
}

.btn.num {
  background: #333;
  color: #fff;
}

.btn.op {
  background: #ff9f0a;
  color: #fff;
}

.btn.clear {
  background: #a5a5a5;
  color: #000;
}

.btn.equals {
  background: #ff9f0a;
  color: #fff;
  grid-row: span 2;
  aspect-ratio: auto;
  border-radius: 40px;
}

.btn.paren {
  background: #a5a5a5;
  color: #000;
}

.btn.backspace {
  background: #333;
  color: #fff;
}
