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

:root {
  --bg: #0b1026;
  --calc-bg: rgba(20, 28, 58, 0.65);
  --display-bg: rgba(12, 18, 40, 0.8);
  --text: #e0e6f8;
  --muted: #8b9bdc;
  --accent: #6c7bff;
  --accent-glow: rgba(108, 123, 255, 0.55);
  --equal-bg: #4f5bdb;
  --equal-glow: rgba(108, 130, 255, 0.7);
  --btn-bg: rgba(40, 50, 95, 0.55);
  --btn-hover: rgba(55, 68, 130, 0.65);
  --btn-active: rgba(30, 38, 75, 0.9);
  --operator-bg: rgba(60, 45, 130, 0.55);
  --operator-hover: rgba(80, 65, 170, 0.7);
  --function-bg: rgba(35, 42, 80, 0.6);
  --error: #ff6b8a;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --glow: 0 0 18px var(--accent-glow);
  --glow-strong: 0 0 28px var(--accent-glow), 0 0 48px rgba(108, 123, 255, 0.35);
  --glow-equal: 0 0 32px var(--equal-glow), 0 0 60px rgba(108, 130, 255, 0.45);
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

.calculator {
  width: 100%;
  max-width: 400px;
  background: var(--calc-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 24px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,0.06);
  padding: 20px 16px 24px;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mute-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--btn-bg);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  user-select: none;
}

.mute-btn:hover {
  background: var(--btn-hover);
}

.mute-btn.active {
  color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.volume-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
}

.volume-wrap input[type="range"] {
  width: 70px;
  accent-color: var(--accent);
  cursor: pointer;
}

.display {
  background: var(--display-bg);
  border-radius: 16px;
  padding: 16px 18px;
  text-align: right;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.35);
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  word-break: break-all;
}

.expression {
  font-size: 1.05rem;
  color: var(--muted);
  min-height: 1.6em;
  opacity: 0.9;
}

.result {
  font-size: 2.6rem;
  font-weight: 300;
  color: var(--text);
  line-height: 1.1;
  margin-top: 6px;
  transition: color 0.2s;
}

.result.error {
  color: var(--error);
  text-shadow: 0 0 12px rgba(255, 107, 138, 0.5);
}

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

.btn {
  border: none;
  border-radius: 14px;
  padding: 18px 4px;
  font-size: 1.35rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  background: var(--btn-bg);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.04),
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 3px 6px rgba(0,0,0,0.25);
  transition: transform 0.06s, background 0.15s, box-shadow 0.18s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  background: var(--btn-hover);
}

.btn:active, .btn.pressed {
  transform: scale(0.95);
  background: var(--btn-active);
  box-shadow:
    inset 0 0 12px rgba(108, 123, 255, 0.35),
    0 0 22px rgba(108, 123, 255, 0.4),
    0 0 40px rgba(108, 123, 255, 0.2);
}

.btn.number {
  background: var(--btn-bg);
}

.btn.number:active, .btn.number.pressed {
  box-shadow:
    inset 0 0 14px rgba(108, 123, 255, 0.45),
    0 0 24px rgba(108, 123, 255, 0.45),
    0 0 44px rgba(108, 123, 255, 0.25);
}

.btn.operator {
  background: var(--operator-bg);
  color: #c8d0ff;
}

.btn.operator:hover {
  background: var(--operator-hover);
}

.btn.operator:active, .btn.operator.pressed {
  box-shadow:
    inset 0 0 14px rgba(160, 140, 255, 0.45),
    0 0 24px rgba(160, 140, 255, 0.45),
    0 0 44px rgba(160, 140, 255, 0.25);
}

.btn.equal {
  background: var(--equal-bg);
  color: #fff;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.08),
    0 0 16px var(--equal-glow);
}

.btn.equal:hover {
  background: #5a6ae8;
}

.btn.equal:active, .btn.equal.pressed {
  transform: scale(0.95);
  background: #3d4bc4;
  box-shadow:
    inset 0 0 18px rgba(140, 160, 255, 0.55),
    0 0 36px var(--equal-glow),
    0 0 64px rgba(108, 130, 255, 0.45);
}

.btn.function {
  background: var(--function-bg);
  color: var(--muted);
  font-size: 1.15rem;
}

.btn.function:active, .btn.function.pressed {
  box-shadow:
    inset 0 0 12px rgba(108, 123, 255, 0.3),
    0 0 18px rgba(108, 123, 255, 0.35);
}

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

.btn.spacer {
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 360px) {
  .calculator {
    padding: 16px 12px 20px;
    border-radius: 20px;
  }
  .btn {
    padding: 16px 4px;
    font-size: 1.25rem;
    border-radius: 12px;
  }
  .result {
    font-size: 2.2rem;
  }
}

@media (min-width: 768px) {
  body {
    align-items: center;
  }
  .calculator {
    margin-top: 0;
  }
}

.btn.pressed {
  animation: press-glow 0.28s ease-out;
}

@keyframes press-glow {
  0% {
    box-shadow:
      inset 0 0 0 1px rgba(255,255,255,0.04),
      0 0 0 transparent;
  }
  40% {
    box-shadow:
      inset 0 0 18px rgba(108, 123, 255, 0.55),
      0 0 28px rgba(108, 123, 255, 0.55),
      0 0 52px rgba(108, 123, 255, 0.35);
  }
  100% {
    box-shadow:
      inset 0 0 0 1px rgba(255,255,255,0.04),
      0 0 0 transparent;
  }
}
