@property --chg {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
@property --va {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
@property --vb {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
@property --p {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
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);
}

.hm {
  display: flex;
  justify-content: center;
  width: 100%;
}

.hm__board {
  width: min(100%, 380px);
  background: #231f28;
  border-radius: 16px;
  box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
  padding: 8px;
  overflow: hidden;
}

.hm__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 8px;
}

.hm__title {
  margin: 0;
  font-weight: 800;
  font-size: clamp(11px, 3vw, 13px);
  color: #fff7e6;
}

.hm__live {
  font-weight: 700;
  font-size: clamp(9px, 2.4vw, 10px);
  color: #3ddc97;
  border: 1px solid #3ddc97;
  border-radius: 999px;
  padding: 0 8px;
  line-height: 1.6;
}

.hm__grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.hm__tile {
  --chg: calc(var(--va) + (var(--vb) - var(--va)) * var(--p));
  --up-mix: clamp(0%, calc(var(--chg) * 11%), 50%);
  --down-mix: clamp(0%, calc(var(--chg) * -11%), 50%);
  background-color: color-mix(in oklab, #ff7a5e var(--down-mix), color-mix(in oklab, #3ddc97 var(--up-mix), #231f28));
  transition: --chg 300ms ease-out;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0;
  min-height: 32px;
  padding: 4px 0;
  border-radius: 4px;
}

.hm__sym {
  font-weight: 700;
  font-size: clamp(8px, 2.2vw, 10px);
  line-height: 1.3;
  color: #fff7e6;
  letter-spacing: 0.04em;
  opacity: 0.78;
}

.hm__val {
  display: grid;
  justify-items: center;
}

.hm__chg {
  grid-area: 1/1;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(9px, 2.6vw, 11px);
  line-height: 1.3;
  color: #fff7e6;
}

.hm:not(.is-demo) .hm__chg--b {
  opacity: 0;
}

.hm.is-demo .hm__tile {
  animation-name: hmWave;
  animation-duration: 2s;
  animation-timing-function: ease-out;
  animation-iteration-count: infinite;
  animation-fill-mode: backwards;
}

.hm.is-demo .hm__tile[data-g="1"] {
  animation-delay: -667ms;
}

.hm.is-demo .hm__tile[data-g="2"] {
  animation-delay: -1333ms;
}

@keyframes hmWave {
  0%, 8% {
    --p: 0;
  }
  20%, 60% {
    --p: 1;
  }
  72%, 100% {
    --p: 0;
  }
}
.hm.is-demo .hm__chg--a, .hm.is-demo .hm__chg--b {
  animation-duration: 2s;
  animation-timing-function: steps(1, end);
  animation-iteration-count: infinite;
  animation-fill-mode: backwards;
}

.hm.is-demo .hm__chg--a {
  animation-name: hmTextA;
}

.hm.is-demo .hm__chg--b {
  animation-name: hmTextB;
}

.hm.is-demo .hm__tile[data-g="1"] .hm__chg--a,
.hm.is-demo .hm__tile[data-g="1"] .hm__chg--b {
  animation-delay: -667ms;
}

.hm.is-demo .hm__tile[data-g="2"] .hm__chg--a,
.hm.is-demo .hm__tile[data-g="2"] .hm__chg--b {
  animation-delay: -1333ms;
}

@keyframes hmTextA {
  0%, 6% {
    opacity: 1;
  }
  8%, 58% {
    opacity: 0;
  }
  60%, 100% {
    opacity: 1;
  }
}
@keyframes hmTextB {
  0%, 6% {
    opacity: 0;
  }
  8%, 58% {
    opacity: 1;
  }
  60%, 100% {
    opacity: 0;
  }
}
@media (max-width: 340px) {
  .hm__board {
    padding: 4px;
  }
  .hm__head {
    padding: 0 4px 4px;
  }
  .hm__tile {
    min-height: 30px;
    padding: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .hm__tile {
    transition: none !important;
  }
  .hm.is-demo .hm__tile {
    animation: none !important;
  }
  .hm.is-demo .hm__chg--a {
    animation: none !important;
    opacity: 1 !important;
  }
  .hm.is-demo .hm__chg--b {
    animation: none !important;
    opacity: 0 !important;
  }
}
