:root {
  --panel: rgba(19, 25, 42, 0.74);
  --text: #f8fbff;
  --muted: #94a3b8;
  --key: rgba(255, 255, 255, 0.11);
  --key-hover: rgba(255, 255, 255, 0.18);
  --accent: #24d3ee;
  --accent-soft: #66f0c1;
  --accent-two: #ffb84d;
  --science: #b9a7ff;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 12%, rgba(36, 211, 238, 0.22), transparent 28rem),
    radial-gradient(circle at 82% 84%, rgba(255, 184, 77, 0.18), transparent 30rem),
    radial-gradient(circle at 72% 18%, rgba(185, 167, 255, 0.15), transparent 24rem),
    linear-gradient(135deg, #080b12 0%, #141923 48%, #090c13 100%);
}

button {
  border: 0;
  font: inherit;
}

.scene {
  position: relative;
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  isolation: isolate;
}

.ambient {
  position: absolute;
  width: 220px;
  aspect-ratio: 1;
  border-radius: 999px;
  filter: blur(8px);
  opacity: 0.72;
  z-index: -1;
  animation: drift 8s ease-in-out infinite alternate;
}

.ambient-one {
  top: 12%;
  left: 10%;
  background: linear-gradient(135deg, rgba(36, 211, 238, 0.35), rgba(30, 64, 175, 0.15));
}

.ambient-two {
  right: 10%;
  bottom: 10%;
  background: linear-gradient(135deg, rgba(255, 184, 77, 0.32), rgba(255, 111, 145, 0.18));
  animation-delay: -2s;
}

.ambient-three {
  right: 25%;
  top: 15%;
  width: 150px;
  background: linear-gradient(135deg, rgba(185, 167, 255, 0.26), rgba(36, 211, 238, 0.15));
  animation-delay: -4s;
}

.calculator {
  width: min(100%, 640px);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 28px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.15), transparent 38%),
    var(--panel);
  box-shadow: 0 28px 80px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(24px);
  animation: calculatorIn 680ms cubic-bezier(.2, .85, .2, 1.15) both;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 1.7rem);
  letter-spacing: 0;
}

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

.mode-toggle,
.sound-toggle {
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease;
}

.mode-toggle {
  min-width: 58px;
  height: 32px;
  border-radius: 999px;
  color: #07131c;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  font-size: 0.78rem;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(36, 211, 238, 0.18);
}

.mode-toggle:hover,
.sound-toggle:hover {
  transform: translateY(-1px);
}

.sound-toggle {
  position: relative;
  width: 54px;
  height: 32px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.sound-toggle span {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--muted);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
  transition: transform 220ms cubic-bezier(.2, .85, .2, 1.25), background 180ms ease;
}

.sound-toggle.is-on {
  background: rgba(36, 211, 238, 0.2);
}

.sound-toggle.is-on span {
  background: var(--accent);
  transform: translateX(22px);
}

.display {
  display: grid;
  align-content: end;
  min-height: 132px;
  margin-bottom: 18px;
  padding: 22px 18px;
  overflow: hidden;
  border-radius: 22px;
  background: rgba(4, 8, 18, 0.62);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 -18px 45px rgba(36, 211, 238, 0.06);
}

.history,
.result {
  min-width: 0;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history {
  min-height: 24px;
  color: var(--muted);
  font-size: 0.94rem;
}

.result {
  font-size: clamp(2rem, 7vw, 3.35rem);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: 0;
  text-shadow: 0 0 24px rgba(36, 211, 238, 0.2);
  transition: transform 180ms ease, color 180ms ease;
}

.result.pop {
  color: var(--accent);
  transform: scale(1.025);
}

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

.key {
  position: relative;
  min-height: 56px;
  overflow: hidden;
  border-radius: 16px;
  color: var(--text);
  background: var(--key);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.13), 0 12px 22px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 800;
  transition: transform 140ms ease, background 160ms ease, box-shadow 160ms ease;
}

.key sup {
  font-size: 0.68rem;
}

.key::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(255, 255, 255, 0.32), transparent 34%);
  opacity: 0;
  transform: scale(0.65);
  transition: opacity 180ms ease, transform 220ms ease;
}

.key:hover {
  background: var(--key-hover);
  transform: translateY(-2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 16px 30px rgba(0, 0, 0, 0.26);
}

.key:active,
.key.is-pressed {
  transform: translateY(2px) scale(0.97);
}

.key:active::before,
.key.is-pressed::before {
  opacity: 1;
  transform: scale(1.25);
}

.utility {
  color: #172033;
  background: rgba(255, 255, 255, 0.76);
}

.utility:hover {
  background: rgba(255, 255, 255, 0.9);
}

.science {
  color: #f9f7ff;
  background: rgba(185, 167, 255, 0.18);
}

.science:hover {
  background: rgba(185, 167, 255, 0.28);
}

.operator {
  color: #07131c;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
}

.operator:hover {
  background: linear-gradient(135deg, #5be5f7, #93ffd7);
}

.equals {
  color: #1a1000;
  background: linear-gradient(135deg, var(--accent-two), #ffdf6e);
}

.equals:hover {
  background: linear-gradient(135deg, #ffc76d, #fff08d);
}

.zero {
  grid-column: span 2;
}

.tall {
  grid-row: span 2;
}

@keyframes calculatorIn {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes drift {
  from {
    transform: translate3d(-10px, 8px, 0) scale(1);
  }
  to {
    transform: translate3d(14px, -18px, 0) scale(1.08);
  }
}

@media (max-width: 620px) {
  body {
    overflow: auto;
  }

  .scene {
    min-height: auto;
    padding: 14px;
  }

  .calculator {
    padding: 16px;
    border-radius: 24px;
  }

  .topbar {
    align-items: flex-start;
  }

  .display {
    min-height: 118px;
    padding: 18px 15px;
  }

  .keys {
    gap: 8px;
  }

  .key {
    min-height: 50px;
    border-radius: 14px;
    font-size: 0.88rem;
  }
}
