:root {
  color-scheme: dark;
  --ink: #fbf8ee;
  --muted: #b8b1a2;
  --body: #17231f;
  --body-deep: #0c1110;
  --display: #c8d7ae;
  --display-ink: #1d261e;
  --amber: #efb65d;
  --teal: #74d6c4;
  --red: #d8665c;
  --line: rgba(255, 255, 255, 0.16);
  --shadow: 0 32px 80px rgba(0, 0, 0, 0.46);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 18% 18%, rgba(116, 214, 196, 0.15), transparent 30%),
    radial-gradient(circle at 82% 12%, rgba(239, 182, 93, 0.17), transparent 28%),
    linear-gradient(145deg, #111617, #20251d 52%, #130f12);
  background-size: 40px 40px, 40px 40px, auto, auto, auto;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(116, 214, 196, 0.72);
  outline-offset: 3px;
}

.puff-app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(330px, 580px);
  align-items: center;
  justify-content: center;
  padding: clamp(14px, 3vw, 42px);
}

.calculator-shell {
  display: grid;
  place-items: center;
  min-width: 0;
}

.calculator {
  --stink: 0;
  position: relative;
  z-index: 0;
  width: min(100%, 560px);
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
  overflow: visible;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 32px;
  padding: clamp(18px, 3vw, 26px);
  background:
    radial-gradient(circle at 28% 0%, rgba(239, 182, 93, 0.28), transparent 34%),
    linear-gradient(145deg, #253a34, var(--body) 58%, var(--body-deep));
  box-shadow:
    inset 0 0 0 7px rgba(0, 0, 0, 0.64),
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    var(--shadow);
}

.calculator::before,
.calculator::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: inherit;
  opacity: calc(var(--stink) * 0.95);
  transition: opacity 260ms ease, box-shadow 260ms ease;
}

.calculator::before {
  z-index: -2;
  inset: -46px -42px -28px;
  background:
    radial-gradient(ellipse at 50% -5%, rgba(137, 255, 71, 0.34), transparent 58%),
    radial-gradient(ellipse at 8% 40%, rgba(86, 255, 128, 0.24), transparent 44%),
    radial-gradient(ellipse at 92% 44%, rgba(198, 255, 82, 0.2), transparent 42%),
    radial-gradient(ellipse at 50% 102%, rgba(126, 255, 94, 0.22), transparent 45%);
  filter: blur(calc(14px + var(--stink) * 12px));
}

.calculator::after {
  z-index: -1;
  inset: -9px;
  box-shadow:
    0 0 calc(22px + var(--stink) * 76px) rgba(109, 255, 92, 0.48),
    0 -24px calc(34px + var(--stink) * 96px) rgba(164, 255, 76, 0.34),
    0 18px calc(28px + var(--stink) * 68px) rgba(94, 255, 128, 0.2),
    inset 0 0 calc(14px + var(--stink) * 44px) rgba(133, 255, 92, 0.18);
}

.calculator.is-stink-burst::after {
  animation: stink-glow-pop 420ms ease-out;
}

.calculator > :not(.stink-cloud):not(.frame-fumes) {
  position: relative;
  z-index: 2;
}

.stink-cloud {
  position: absolute;
  z-index: 1;
  inset: -150px -90px auto -90px;
  height: 238px;
  overflow: visible;
  pointer-events: none;
  opacity: calc(var(--stink) * 0.98);
  transition: opacity 260ms ease;
}

.stink-cloud span {
  --x-start: 0px;
  --x-end: 18px;
  position: absolute;
  bottom: 0;
  left: 50%;
  width: calc(42px + var(--stink) * 54px);
  height: calc(70px + var(--stink) * 112px);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 48% 65%, rgba(180, 255, 103, 0.55), transparent 62%),
    radial-gradient(ellipse at 34% 44%, rgba(92, 255, 137, 0.34), transparent 58%),
    radial-gradient(ellipse at 55% 20%, rgba(224, 255, 117, 0.18), transparent 60%);
  filter: blur(calc(9px + var(--stink) * 8px));
  mix-blend-mode: screen;
  transform: translate3d(var(--x-start), 38px, 0) scale(0.62);
  animation: stink-drift 4.2s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.frame-fumes {
  position: absolute;
  z-index: 1;
  inset: -54px -46px -34px;
  overflow: visible;
  pointer-events: none;
  opacity: calc(var(--stink) * 0.96);
  transition: opacity 180ms ease;
}

.frame-fumes span {
  --x-start: 0px;
  --x-end: 0px;
  --y-start: 0px;
  --y-end: -150px;
  --duration: 3.9s;
  --delay: 0s;
  position: absolute;
  left: var(--left);
  top: var(--top);
  width: calc(28px + var(--stink) * 58px);
  height: calc(48px + var(--stink) * 104px);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 68%, rgba(177, 255, 70, 0.6), transparent 62%),
    radial-gradient(ellipse at 35% 42%, rgba(83, 255, 128, 0.42), transparent 58%),
    radial-gradient(ellipse at 68% 24%, rgba(225, 255, 94, 0.24), transparent 54%);
  filter: blur(calc(7px + var(--stink) * 10px));
  mix-blend-mode: screen;
  transform: translate3d(var(--x-start), var(--y-start), 0) scale(0.52);
  animation: frame-fume-rise var(--duration) ease-in-out infinite;
  animation-delay: var(--delay);
}

.calculator.is-stink-burst .frame-fumes span {
  filter: blur(calc(5px + var(--stink) * 8px)) brightness(1.28);
}

.frame-fumes span:nth-child(1) {
  --left: -3%;
  --top: 18%;
  --x-start: -6px;
  --x-end: -56px;
  --y-end: -174px;
  --delay: -0.6s;
}

.frame-fumes span:nth-child(2) {
  --left: 6%;
  --top: 57%;
  --x-start: 2px;
  --x-end: -44px;
  --y-end: -202px;
  --delay: -2.2s;
}

.frame-fumes span:nth-child(3) {
  --left: 22%;
  --top: 92%;
  --x-start: -16px;
  --x-end: -34px;
  --y-end: -216px;
  --duration: 4.4s;
  --delay: -1.1s;
}

.frame-fumes span:nth-child(4) {
  --left: 43%;
  --top: 95%;
  --x-start: 8px;
  --x-end: 16px;
  --y-end: -234px;
  --duration: 4.8s;
  --delay: -3.4s;
}

.frame-fumes span:nth-child(5) {
  --left: 67%;
  --top: 92%;
  --x-start: -10px;
  --x-end: 34px;
  --y-end: -218px;
  --delay: -2.8s;
}

.frame-fumes span:nth-child(6) {
  --left: 88%;
  --top: 56%;
  --x-start: 6px;
  --x-end: 58px;
  --y-end: -196px;
  --delay: -1.7s;
}

.frame-fumes span:nth-child(7) {
  --left: 96%;
  --top: 22%;
  --x-start: -2px;
  --x-end: 46px;
  --y-end: -176px;
  --delay: -3s;
}

.frame-fumes span:nth-child(8) {
  --left: 49%;
  --top: 3%;
  --x-start: -18px;
  --x-end: 10px;
  --y-end: -156px;
  --duration: 4.6s;
  --delay: -2.4s;
}

.frame-fumes span:nth-child(9) {
  --left: 30%;
  --top: 4%;
  --x-start: 6px;
  --x-end: -28px;
  --y-end: -142px;
  --delay: -3.8s;
}

.frame-fumes span:nth-child(10) {
  --left: 73%;
  --top: 5%;
  --x-start: -6px;
  --x-end: 32px;
  --y-end: -146px;
  --delay: -0.9s;
}

.stink-cloud span:nth-child(1) {
  left: 5%;
  --x-start: -8px;
  --x-end: -34px;
  --delay: -1.1s;
}

.stink-cloud span:nth-child(2) {
  left: 18%;
  --x-start: 12px;
  --x-end: 36px;
  --delay: -3.6s;
}

.stink-cloud span:nth-child(3) {
  left: 33%;
  --x-start: -14px;
  --x-end: -6px;
  --delay: -2.4s;
}

.stink-cloud span:nth-child(4) {
  left: 47%;
  --x-start: 4px;
  --x-end: 26px;
  --delay: -4.2s;
}

.stink-cloud span:nth-child(5) {
  left: 62%;
  --x-start: -2px;
  --x-end: -30px;
  --delay: -0.7s;
}

.stink-cloud span:nth-child(6) {
  left: 78%;
  --x-start: 10px;
  --x-end: 42px;
  --delay: -2.9s;
}

.stink-cloud span:nth-child(7) {
  left: 91%;
  --x-start: -14px;
  --x-end: -52px;
  --delay: -1.8s;
}

.stink-cloud span:nth-child(8) {
  left: 52%;
  width: calc(66px + var(--stink) * 74px);
  height: calc(72px + var(--stink) * 104px);
  --x-start: -22px;
  --x-end: 8px;
  --delay: -3.1s;
}

@keyframes stink-drift {
  0% {
    opacity: 0;
    transform: translate3d(var(--x-start), 46px, 0) scale(0.58);
  }

  18% {
    opacity: calc(0.18 + var(--stink) * 0.46);
  }

  62% {
    opacity: calc(0.1 + var(--stink) * 0.34);
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--x-end), -132px, 0) scale(1.28);
  }
}

@keyframes frame-fume-rise {
  0% {
    opacity: 0;
    transform: translate3d(var(--x-start), var(--y-start), 0) scale(0.5);
  }

  16% {
    opacity: calc(0.2 + var(--stink) * 0.6);
  }

  58% {
    opacity: calc(0.12 + var(--stink) * 0.42);
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--x-end), var(--y-end), 0) scale(calc(0.95 + var(--stink) * 0.5));
  }
}

@keyframes stink-glow-pop {
  0% {
    filter: brightness(1);
  }

  45% {
    filter: brightness(1.38) saturate(1.35);
  }

  100% {
    filter: brightness(1);
  }
}

.calc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.calc-top {
  min-height: 54px;
  padding: 10px 4px 0;
}

.calc-top span,
.display-panel small,
.readout-grid span,
.key small {
  font-size: 0.68rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.calc-top span {
  color: rgba(251, 248, 238, 0.62);
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.6rem, 4vw, 2.35rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.display-panel {
  display: grid;
  gap: 12px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 16px;
  padding: 18px;
  color: var(--display-ink);
  background:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    var(--display);
  background-size: 18px 18px;
  box-shadow:
    inset 0 0 0 4px rgba(0, 0, 0, 0.12),
    inset 0 12px 34px rgba(255, 255, 255, 0.22);
}

.expression {
  min-height: 22px;
  overflow: hidden;
  color: rgba(29, 38, 30, 0.68);
  font-size: clamp(0.82rem, 2.2vw, 1rem);
  font-weight: 880;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-value {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  font-size: clamp(3.1rem, 12vw, 5.8rem);
  font-weight: 950;
  line-height: 0.9;
  letter-spacing: 0;
  text-align: right;
}

.main-value.is-error {
  color: #9f2f2b;
  font-size: clamp(2.2rem, 9vw, 4rem);
}

.readout-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.readout-grid div {
  min-width: 0;
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid rgba(29, 38, 30, 0.15);
  border-radius: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.22);
}

.readout-grid span {
  color: rgba(29, 38, 30, 0.56);
}

.readout-grid strong {
  overflow: hidden;
  font-size: clamp(0.9rem, 2.4vw, 1.12rem);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1.6vw, 10px);
}

.key {
  position: relative;
  min-height: clamp(64px, 12vw, 86px);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 3px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.055)),
    rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 8px 0 rgba(0, 0, 0, 0.2),
    0 16px 26px rgba(0, 0, 0, 0.16);
  cursor: pointer;
  user-select: none;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    border-color 120ms ease,
    filter 120ms ease;
}

.key:hover {
  border-color: rgba(255, 255, 255, 0.27);
  filter: brightness(1.06);
}

.key:active,
.key.is-pressed {
  transform: translateY(6px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 2px 0 rgba(0, 0, 0, 0.25),
    0 8px 18px rgba(0, 0, 0, 0.16);
}

.key.number {
  min-height: clamp(84px, 15vw, 106px);
  padding: 10px 8px 8px;
  background:
    radial-gradient(circle at 28% 16%, rgba(255, 255, 255, 0.18), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
}

.key.operator {
  color: #21180d;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.08)),
    var(--amber);
  font-size: clamp(1.75rem, 5vw, 2.55rem);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.34);
}

.key.utility {
  color: #fff3f1;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04)),
    rgba(216, 102, 92, 0.72);
  font-size: clamp(1.08rem, 3.2vw, 1.45rem);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.26);
}

.key.equals {
  color: #08221d;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.08)),
    var(--teal);
  font-size: clamp(1.95rem, 5.6vw, 2.85rem);
}

.key.wide {
  grid-column: span 2;
}

.key.number img {
  width: min(138px, 96%);
  height: min(108px, 92%);
  object-fit: contain;
  filter:
    drop-shadow(0 8px 10px rgba(0, 0, 0, 0.22))
    drop-shadow(0 0 10px rgba(239, 182, 93, 0.08));
}

@media (max-width: 900px) {
  .puff-app {
    grid-template-columns: 1fr;
    align-items: start;
  }
}

@media (max-width: 540px) {
  .puff-app {
    padding: 10px;
  }

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

  .display-panel {
    padding: 14px;
  }

  .readout-grid {
    grid-template-columns: 1fr;
  }

  .keypad {
    gap: 7px;
  }

  .key,
  .key.number {
    border-radius: 12px;
  }

  .key.number img {
    width: min(112px, 96%);
    height: min(92px, 90%);
  }
}
