*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-elevated: #243044;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --op: #f59e0b;
  --op-hover: #d97706;
  --eq: #22c55e;
  --eq-hover: #16a34a;
  --fn: #64748b;
  --error: #f87171;
  --radius: 16px;
  --shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: radial-gradient(ellipse at top, #1e3a5f 0%, var(--bg) 55%);
  color: var(--text);
  padding: 1.5rem;
}

.calculator {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.calculator__header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.calculator__header h1 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.calculator__subtitle {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.display {
  background: var(--surface-elevated);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.75rem;
  min-height: 5.5rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  direction: ltr;
  text-align: right;
}

.display__expression {
  font-size: 0.9rem;
  color: var(--text-muted);
  min-height: 1.25rem;
  word-break: break-all;
}

.display__result {
  font-size: 2.25rem;
  font-weight: 300;
  line-height: 1.2;
  word-break: break-all;
}

.message {
  font-size: 0.8rem;
  text-align: center;
  margin-bottom: 0.5rem;
  min-height: 1.2rem;
}

.message--error {
  color: var(--error);
}

.calculator__keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.key {
  border: none;
  border-radius: 12px;
  padding: 1rem;
  font-size: 1.15rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface-elevated);
  color: var(--text);
  transition: background 0.15s, transform 0.1s;
  direction: ltr;
}

.key:hover {
  background: #2d3d54;
}

.key:active {
  transform: scale(0.96);
}

.key--fn {
  color: var(--fn);
  font-size: 1rem;
}

.key--op {
  background: rgba(245, 158, 11, 0.15);
  color: var(--op);
}

.key--op:hover {
  background: rgba(245, 158, 11, 0.28);
}

.key--eq {
  background: var(--eq);
  color: #fff;
  grid-column: span 1;
}

.key--eq:hover {
  background: var(--eq-hover);
}

.key--wide {
  grid-column: span 2;
}

@media (max-width: 400px) {
  .key {
    padding: 0.85rem;
    font-size: 1rem;
  }

  .display__result {
    font-size: 1.85rem;
  }
}
