:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --text: #162033;
  --muted: #667085;
  --border: #d9e1ee;
  --number: #f8fafc;
  --function: #e9f1ff;
  --operator: #fff0d6;
  --control: #ffe5e5;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --error: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.calculator {
  width: min(100%, 520px);
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(21, 36, 64, 0.14);
}

.display {
  min-height: 150px;
  margin-bottom: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mode-toggle {
  min-width: 68px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.status {
  color: var(--muted);
  font-size: 0.92rem;
  text-align: right;
}

.status.error {
  color: var(--error);
  font-weight: 700;
}

.expression,
.result {
  min-height: 36px;
  overflow-wrap: anywhere;
  text-align: right;
}

.expression {
  color: var(--muted);
  font-size: clamp(1.05rem, 3vw, 1.35rem);
}

.result {
  margin-top: auto;
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 750;
}

.keys {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.key {
  min-height: 56px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.08s ease,
    filter 0.08s ease;
}

.key:hover {
  filter: brightness(0.98);
}

.key:active {
  transform: translateY(1px);
}

.number {
  background: var(--number);
  font-weight: 750;
}

.function {
  background: var(--function);
}

.operator {
  background: var(--operator);
  font-weight: 750;
}

.control {
  background: var(--control);
  font-weight: 750;
}

.equals {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
  font-size: 1.25rem;
  font-weight: 800;
}

.tall {
  grid-row: span 2;
}

.wide {
  grid-column: span 2;
}

@media (max-width: 460px) {
  body {
    padding: 10px;
    align-items: start;
  }

  .calculator {
    padding: 12px;
  }

  .keys {
    gap: 6px;
  }

  .key {
    min-height: 50px;
    padding: 0;
    font-size: 0.95rem;
  }
}
