* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #1e1e24;
  color: #f7f7f9;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

.app-container {
  display: flex;
  flex-direction: row;
  gap: 1.5rem;
  background: #2b2d42;
  padding: 1.5rem;
  border-radius: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  max-width: 650px;
  width: 100%;
}

.calculator {
  flex: 1 1 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.display {
  background: #111217;
  color: #fff;
  font-size: 2.2rem;
  font-weight: 500;
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  text-align: right;
  overflow-x: auto;
  white-space: nowrap;
  min-height: 4rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.btn {
  border: none;
  border-radius: 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  padding: 1rem;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-num {
  background: #4a4e69;
  color: #fff;
}

.btn-num:hover {
  filter: brightness(1.15);
}

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

.btn-action {
  background: #8d99ae;
  color: #111;
}

.btn-action:hover {
  filter: brightness(1.1);
}

.btn-op {
  background: #e09f3e;
  color: #111;
}

.btn-op:hover {
  filter: brightness(1.1);
}

.btn-equals {
  background: #ef233c;
  color: #fff;
  grid-row: span 2;
  grid-column: 4;
}

.btn-equals:hover {
  filter: brightness(1.1);
}

.history-panel {
  flex: 1 1 200px;
  background: #202233;
  padding: 1rem;
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 420px;
}

.history-panel h2 {
  font-size: 1.1rem;
  font-weight: 600;
  border-bottom: 1px solid #3d405b;
  padding-bottom: 0.5rem;
}

.history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-right: 0.25rem;
}

.history-item {
  padding: 0.5rem 0.75rem;
  background: #2b2d42;
  border-radius: 0.35rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  text-align: right;
  transition: background 0.15s ease;
}

.history-item:hover {
  background: #3d405b;
}

.btn-clear-history {
  background: #3d405b;
  color: #edf2f4;
  font-size: 0.9rem;
  padding: 0.6rem;
}

.btn-clear-history:hover {
  filter: brightness(1.2);
}

@media (max-width: 550px) {
  .app-container {
    flex-direction: column;
  }
}