html, body {
  margin: 0;
  overflow: hidden;
}

.stage {
  box-sizing: border-box;
  min-height: 100vh;
  display: grid;
  place-items: center;
  margin: 0;
  background: #ffd23f;
  font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
  padding: clamp(8px, 4vw, 24px);
}

.kc {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 300px;
  height: 100%;
  padding: 12px;
  box-sizing: border-box;
  border-radius: 16px;
  background-color: #ffffff;
}

.kc__out {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background-color: #17141a;
}

.kc__hint {
  font-weight: 500;
  font-size: clamp(8px, 2.2vw, 10px);
  color: rgba(255, 247, 230, 0.72);
}

.kc__val {
  font-weight: 800;
  font-size: clamp(18px, 5.5vw, 26px);
  line-height: 1.1;
  color: #fff7e6;
  font-variant-numeric: tabular-nums;
}

.kc__pad {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  grid-template-areas: "clear back pct div" "n7 n8 n9 mul" "n4 n5 n6 sub" "n1 n2 n3 add" "n0 n0 dot eq";
  gap: 8px;
  --kc-space: 8px;
}

.kc__key {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  background-color: #fff7e6;
  color: #17141a;
  font-weight: 700;
  font-size: clamp(12px, 3.2vw, 16px);
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

.kc__key:focus-visible {
  outline: 2px solid #0a4fe8;
  outline-offset: 2px;
}

.kc__key:active {
  transform: scale(0.96);
}

.kc__ic {
  width: clamp(12px, 3.4vw, 17px);
  height: clamp(12px, 3.4vw, 17px);
}

.kc__key--fn {
  background-color: rgba(23, 20, 26, 0.08);
  color: #17141a;
}

.kc__key--op {
  background-color: #ff4d1f;
  color: #17141a;
}

.kc__key--eq {
  background-color: #0a4fe8;
  color: #fff7e6;
}

.kc__key[data-k=clear] {
  grid-area: clear;
}

.kc__key[data-k=back] {
  grid-area: back;
}

.kc__key[data-k=pct] {
  grid-area: pct;
}

.kc__key[data-k="/"] {
  grid-area: div;
}

.kc__key[data-k="7"] {
  grid-area: n7;
}

.kc__key[data-k="8"] {
  grid-area: n8;
}

.kc__key[data-k="9"] {
  grid-area: n9;
}

.kc__key[data-k="*"] {
  grid-area: mul;
}

.kc__key[data-k="4"] {
  grid-area: n4;
}

.kc__key[data-k="5"] {
  grid-area: n5;
}

.kc__key[data-k="6"] {
  grid-area: n6;
}

.kc__key[data-k="-"] {
  grid-area: sub;
}

.kc__key[data-k="1"] {
  grid-area: n1;
}

.kc__key[data-k="2"] {
  grid-area: n2;
}

.kc__key[data-k="3"] {
  grid-area: n3;
}

.kc__key[data-k="+"] {
  grid-area: add;
}

.kc__key[data-k="0"] {
  grid-area: n0;
}

.kc__key[data-k="."] {
  grid-area: dot;
}

.kc__key[data-k="="] {
  grid-area: eq;
}

.kc__val--cut2, .kc__val--cut3, .kc__val--cut4 {
  display: none;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.kc.is-demo .kc__val--cut2,
.kc.is-demo .kc__val--cut3,
.kc.is-demo .kc__val--cut4 {
  display: block;
}

.kc.is-demo .kc__val--cut1 {
  animation-name: kcCut1;
}

.kc.is-demo .kc__val--cut2 {
  animation-name: kcCut2;
}

.kc.is-demo .kc__val--cut3 {
  animation-name: kcCut3;
}

.kc.is-demo .kc__val--cut4 {
  animation-name: kcCut4;
}

.kc.is-demo .kc__val {
  animation-duration: 2s;
  animation-timing-function: steps(1, end);
  animation-iteration-count: infinite;
  animation-fill-mode: backwards;
}

@keyframes kcCut1 {
  0% {
    opacity: 1;
  }
  28% {
    opacity: 0;
  }
  82% {
    opacity: 1;
  }
  100% {
    opacity: 1;
  }
}
@keyframes kcCut2 {
  0% {
    opacity: 0;
  }
  28% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}
@keyframes kcCut3 {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  72% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}
@keyframes kcCut4 {
  0% {
    opacity: 0;
  }
  72% {
    opacity: 1;
  }
  82% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}
.kc__ghost {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: calc((100% - var(--kc-space) * 3) / 4);
  height: calc((100% - var(--kc-space) * 4) / 5);
  box-sizing: border-box;
  border: 3px solid #0a4fe8;
  border-radius: 12px;
  pointer-events: none;
}

.kc.is-demo .kc__ghost {
  display: block;
  animation-name: kcHop;
  animation-duration: 2s;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-iteration-count: infinite;
}

@keyframes kcHop {
  0% {
    transform: translate(0, calc(100% + var(--kc-space))) scale(1.05);
  }
  6%, 14% {
    transform: translate(0, calc(100% + var(--kc-space))) scale(1);
  }
  20% {
    transform: translate(calc(calc(100% + var(--kc-space)) * 3), calc(100% + var(--kc-space))) scale(1.05);
  }
  26%, 34% {
    transform: translate(calc(calc(100% + var(--kc-space)) * 3), calc(100% + var(--kc-space))) scale(1);
  }
  40% {
    transform: translate(calc(100% + var(--kc-space)), calc(100% + var(--kc-space))) scale(1.05);
  }
  46%, 54% {
    transform: translate(calc(100% + var(--kc-space)), calc(100% + var(--kc-space))) scale(1);
  }
  60% {
    transform: translate(calc(calc(100% + var(--kc-space)) * 3), calc(calc(100% + var(--kc-space)) * 4)) scale(1.05);
  }
  66%, 82% {
    transform: translate(calc(calc(100% + var(--kc-space)) * 3), calc(calc(100% + var(--kc-space)) * 4)) scale(1);
  }
  88% {
    transform: translate(0, calc(100% + var(--kc-space))) scale(1.05);
  }
  94%, 100% {
    transform: translate(0, calc(100% + var(--kc-space))) scale(1);
  }
}
@media (max-width: 340px) {
  .kc {
    gap: 4px;
    padding: 8px;
  }
  .kc__out {
    padding: 4px 8px;
  }
  .kc__pad {
    gap: 4px;
    --kc-space: 4px;
  }
  .kc__val--cut2, .kc__val--cut3, .kc__val--cut4 {
    right: 8px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .kc__key:active {
    transform: none !important;
  }
  .kc.is-demo .kc__val,
  .kc.is-demo .kc__ghost {
    animation: none !important;
  }
  .kc.is-demo .kc__val--cut2,
  .kc.is-demo .kc__val--cut3,
  .kc.is-demo .kc__val--cut4 {
    display: none !important;
  }
}
