* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #fff;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid #2f6fed;
  outline-offset: 2px;
}

.app {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.calculator {
  width: 200px;
}

.display {
  border: 2px solid #000;
  background: #fff;
  padding: 10px 8px;
  margin-bottom: 10px;
  font-size: 1.1rem;
  text-align: right;
  overflow: hidden;
  white-space: nowrap;
}

.display[data-state="error"] {
  color: #c00;
}

.key[data-op] {
    background-color: orange;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.key {
  border: 2px solid #000;
  background: grey;
  color: #000;
  font-size: 1rem;
  font-weight: bold;
  padding: 10px 0;
}

.key:hover {
  background: #eee;
}

.key:active {
  background: #ddd;
}

.equals {
  display: block;
  width: 100%;
  border: 2px solid #000;
  background: green;
  font-size: 1rem;
  font-weight: bold;
  padding: 10px 0;
}

.equals:hover {
  background: #eee;
}

.equals:active {
  background: #ddd;
}

.history {
  width: 180px;
  display: flex;
  flex-direction: column;
}

#historyList {
  list-style: none;
  margin: 0;
  padding: 0;
}

#historyList li:nth-child(odd) {
  background: #eee;
}

#historyList button {
  all: unset;
  display: block;
  width: 100%;
  box-sizing: border-box;
  cursor: pointer;
  padding: 6px 8px;
  font-size: 0.85rem;
}

#historyList button:hover,
#historyList button:focus-visible {
  background: #ddd;
}

#historyList .expr {
  display: block;
  color: #555;
  font-size: 0.7rem;
}

#historyList .result {
  display: block;
  font-weight: bold;
}

.history-box {
  border: 2px solid #000;
  height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
}

#historyEmpty {
  padding: 8px;
  color: #777;
  font-size: 0.8rem;
}

#clearHistory {
  border: 2px solid #000;
  background: #fff;
  padding: 8px 0;
  font-size: 0.9rem;
}

#clearHistory:hover {
  background: #eee;
}

#clearHistory:active {
  background: #ddd;
}