:root {
  --bg-1: #0f1226;
  --bg-2: #1a1d3a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f3f4ff;
  --muted: #a3a7c7;
  --num: #2a2f57;
  --num-hover: #353b69;
  --fn: #3a3f6e;
  --fn-hover: #474d80;
  --op: #ff8b3d;
  --op-hover: #ff9d59;
  --eq: #4f7cff;
  --eq-hover: #6a91ff;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui,
    Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 20% -10%, #2b2f6c 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 110%, #4f3aa3 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.calculator {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 18px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.display {
  border-radius: 16px;
  padding: 18px 16px;
  background: rgba(0, 0, 0, 0.35);
  margin-bottom: 14px;
  text-align: right;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
}

.history {
  color: var(--muted);
  font-size: 14px;
  min-height: 18px;
  word-break: break-all;
  line-height: 1.2;
}

.current {
  font-size: clamp(34px, 8vw, 48px);
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-top: 6px;
  word-break: break-all;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

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

.key {
  appearance: none;
  border: 0;
  border-radius: 14px;
  height: 64px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  background: var(--num);
  cursor: pointer;
  transition: transform 60ms ease, background-color 120ms ease, box-shadow 120ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.key:hover { background: var(--num-hover); }
.key:active { transform: translateY(1px) scale(0.98); }
.key:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.key.fn {
  background: var(--fn);
  font-size: 18px;
}
.key.fn:hover { background: var(--fn-hover); }

.key.op {
  background: var(--op);
  color: #fff;
  font-size: 24px;
}
.key.op:hover { background: var(--op-hover); }
.key.op.active {
  box-shadow: inset 0 0 0 2px #fff;
}

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

.zero {
  grid-column: span 2;
  text-align: center;
}

.hint {
  margin-top: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.2px;
}

@media (max-width: 380px) {
  .key { height: 58px; font-size: 18px; }
}
