:root {
  --bg: #1b1d23;
  --panel: #24262e;
  --display-bg: #14151a;
  --text: #f2f2f5;
  --text-dim: #9a9ca6;
  --key-digit: #33353f;
  --key-digit-hover: #40424d;
  --key-func: #4a4d59;
  --key-func-hover: #585b68;
  --key-op: #ff9f43;
  --key-op-hover: #ffb26b;
  --key-equals: #4cd137;
  --key-equals-hover: #6be857;
  --accent: #ff9f43;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #101116, #1c1e26);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  padding: 24px;
}

.app {
  width: 100%;
  max-width: 640px;
}

.app-title {
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 20px;
}

.calculator-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
}

.calculator {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
  width: 300px;
}

.display {
  background: var(--display-bg);
  border-radius: 10px;
  padding: 24px 16px;
  margin-bottom: 16px;
  text-align: right;
  font-size: 2.4rem;
  font-weight: 300;
  letter-spacing: 0.02em;
  overflow-x: auto;
  white-space: nowrap;
  min-height: 1.2em;
}

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

.key {
  border: none;
  border-radius: 10px;
  padding: 18px 0;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.12s ease, transform 0.05s ease;
  -webkit-tap-highlight-color: transparent;
}

.key:active {
  transform: scale(0.96);
}

.key-digit {
  background: var(--key-digit);
}

.key-digit:hover {
  background: var(--key-digit-hover);
}

.key-func {
  background: var(--key-func);
}

.key-func:hover {
  background: var(--key-func-hover);
}

.key-op {
  background: var(--key-op);
  color: #1b1d23;
}

.key-op:hover {
  background: var(--key-op-hover);
}

.key-op.active {
  outline: 2px solid #fff;
  outline-offset: -2px;
}

.key-equals {
  background: var(--key-equals);
  color: #10230b;
  grid-column: span 1;
}

.key-equals:hover {
  background: var(--key-equals-hover);
}

.key-zero {
  grid-column: span 1;
}

.display.error {
  color: #ff5f57;
}

.history-panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  width: 220px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  max-height: 420px;
}

.history-title {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
  border-radius: 8px;
  background: var(--display-bg);
}

.history-list li {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  text-align: right;
  font-size: 0.95rem;
  transition: background-color 0.12s ease;
}

.history-list li:last-child {
  border-bottom: none;
}

.history-list li:hover {
  background: rgba(255, 159, 67, 0.15);
}

.history-empty {
  color: var(--text-dim);
  text-align: center;
  padding: 16px 8px;
  cursor: default;
}

.history-empty:hover {
  background: transparent;
}

.clear-history-btn {
  margin-top: 14px;
  border: none;
  border-radius: 8px;
  padding: 10px;
  background: var(--key-func);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.12s ease;
}

.clear-history-btn:hover {
  background: var(--key-func-hover);
}

@media (max-width: 560px) {
  .calculator-wrapper {
    flex-direction: column;
    align-items: center;
  }

  .calculator,
  .history-panel {
    width: 100%;
    max-width: 300px;
  }
}
