:root {
  --black: #020202;
  --shell-dark: #070707;
  --shell-mid: #121212;
  --shell-edge: #1b1b1b;
  --divider: #050505;
  --lamp-off: #17120d;
  --lamp-warm: #f3b46a;
  --lamp-core: #ffe5b5;
  --drum-w: clamp(44px, 9.2vw, 118px);
  --drum-h: clamp(72px, 14.5vw, 178px);
  --dot: clamp(3.4px, 0.75vw, 8px);
  --gap: clamp(2px, 0.42vw, 5px);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 39%, rgba(80, 58, 36, 0.13), transparent 25%),
    radial-gradient(circle at 50% 70%, rgba(255, 177, 86, 0.07), transparent 27%),
    repeating-linear-gradient(91deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 5px),
    #020202;
  color: var(--lamp-core);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 0 42%, rgba(0, 0, 0, 0.74) 78%),
    linear-gradient(rgba(255, 255, 255, 0.025), transparent 22%, transparent 78%, rgba(255, 255, 255, 0.018));
  mix-blend-mode: screen;
}

.stage {
  position: relative;
  width: 100vw;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  perspective: 1100px;
  isolation: isolate;
  transition: background-color 700ms ease;
}

.counter-experience {
  position: relative;
  z-index: 4;
  display: grid;
  justify-items: center;
}

.counter-wrap {
  position: relative;
  transform: translateY(-3vh);
  z-index: 4;
  transition:
    filter 700ms ease,
    transform 900ms cubic-bezier(0.16, 1, 0.3, 1);
}

.counter-shell {
  position: relative;
  padding: clamp(12px, 2vw, 28px);
  border-radius: clamp(20px, 4vw, 46px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.09), transparent 15% 82%, rgba(255, 255, 255, 0.035)),
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.13), transparent 47%),
    linear-gradient(145deg, #181818, #050505 37%, #111 64%, #040404);
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.12) inset,
    0 -2px 0 rgba(0, 0, 0, 0.9) inset,
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 24px 72px rgba(0, 0, 0, 0.92),
    0 0 90px rgba(185, 106, 38, 0.11);
}

.counter-shell::before,
.counter-shell::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: inherit;
}

.counter-shell::before {
  inset: clamp(5px, 0.9vw, 12px);
  border: 1px solid rgba(255, 255, 255, 0.055);
  box-shadow:
    0 13px 24px rgba(255, 255, 255, 0.026) inset,
    0 -18px 28px rgba(0, 0, 0, 0.62) inset;
}

.counter-shell::after {
  inset: 0;
  background:
    repeating-linear-gradient(111deg, rgba(255, 255, 255, 0.023) 0 1px, transparent 1px 8px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08), transparent 11% 89%, rgba(255, 255, 255, 0.05));
  opacity: 0.34;
  mix-blend-mode: screen;
}

.counter {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, var(--drum-w)) clamp(14px, 2.6vw, 32px) repeat(3, var(--drum-w));
  gap: clamp(5px, 0.85vw, 11px);
  align-items: center;
  padding: clamp(7px, 1.2vw, 14px);
  border-radius: clamp(13px, 2.6vw, 30px);
  background:
    linear-gradient(180deg, #030303, #151515 45%, #040404),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 6px);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.045) inset,
    0 23px 22px rgba(0, 0, 0, 0.76) inset,
    0 -22px 22px rgba(0, 0, 0, 0.86) inset;
}

.digit-drum {
  position: relative;
  width: var(--drum-w);
  height: var(--drum-h);
  overflow: hidden;
  border-radius: clamp(9px, 1.7vw, 18px);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.86), transparent 16% 84%, rgba(0, 0, 0, 0.9)),
    radial-gradient(ellipse at 50% 50%, #1a1714 0%, #090807 62%, #020202 100%);
  box-shadow:
    0 1px 1px rgba(255, 255, 255, 0.08) inset,
    0 -1px 1px rgba(255, 255, 255, 0.035) inset,
    11px 0 20px rgba(0, 0, 0, 0.78) inset,
    -11px 0 20px rgba(0, 0, 0, 0.78) inset,
    0 0 0 clamp(3px, 0.65vw, 8px) var(--divider),
    0 0 0 clamp(4px, 0.8vw, 10px) rgba(255, 255, 255, 0.035);
  transform-style: preserve-3d;
}

.digit-drum::before,
.digit-drum::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  z-index: 5;
  pointer-events: none;
}

.digit-drum::before {
  top: 0;
  height: 38%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.018) 17%, transparent 64%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.85), transparent);
}

.digit-drum::after {
  bottom: 0;
  height: 40%;
  background:
    linear-gradient(0deg, rgba(0, 0, 0, 0.9), transparent 72%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04), transparent 22%);
}

.drum-band {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 1px;
  z-index: 6;
  background: linear-gradient(90deg, transparent, rgba(255, 229, 181, 0.18), transparent);
  box-shadow: 0 0 10px rgba(255, 180, 96, 0.08);
  opacity: 0.75;
}

.drum-band.top {
  top: 23%;
}

.drum-band.bottom {
  bottom: 23%;
}

.wheel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform-style: preserve-3d;
  will-change: transform, filter, opacity;
}

.digit-drum.spinning .wheel.current {
  animation: roll-out 780ms cubic-bezier(0.22, 0.75, 0.25, 1) forwards;
}

.digit-drum.spinning .wheel.next {
  animation: roll-in 780ms cubic-bezier(0.22, 0.75, 0.25, 1) forwards;
}

.wheel.next {
  transform: translateY(102%) rotateX(-42deg);
  opacity: 0;
}

.dot-digit {
  display: grid;
  grid-template-columns: repeat(5, var(--dot));
  grid-template-rows: repeat(7, var(--dot));
  gap: var(--gap);
  filter: saturate(1.05);
}

.dot {
  width: var(--dot);
  height: var(--dot);
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 32%, rgba(255, 246, 222, 0.12), transparent 32%),
    #17120d;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.7) inset;
  opacity: 0.56;
}

.dot.on {
  background:
    radial-gradient(circle at 34% 29%, var(--lamp-core) 0 19%, var(--lamp-warm) 39%, #a55d22 72%, #3d210e 100%);
  box-shadow:
    0 0 3px rgba(255, 229, 181, 0.96),
    0 0 10px rgba(243, 180, 106, 0.5),
    0 0 18px rgba(184, 91, 28, 0.22);
  opacity: var(--lit-opacity, 0.94);
}

.separator {
  height: var(--drum-h);
  display: grid;
  place-items: center;
  color: var(--lamp-warm);
  text-shadow:
    0 0 8px rgba(243, 180, 106, 0.42),
    0 0 17px rgba(243, 180, 106, 0.18);
}

.separator::before {
  content: "";
  width: clamp(6px, 1vw, 12px);
  height: clamp(6px, 1vw, 12px);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, var(--lamp-core), var(--lamp-warm) 48%, #603111 100%);
  box-shadow:
    0 0 5px rgba(255, 229, 181, 0.78),
    0 0 16px rgba(243, 180, 106, 0.42);
}

.reflection {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% - 2px);
  opacity: 0.15;
  transform: scaleY(-1);
  transform-origin: top center;
  filter: blur(2.4px) saturate(0.82);
  pointer-events: none;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.58), transparent 73%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.58), transparent 73%);
}

.reflection .counter-shell {
  box-shadow: none;
}

.stop-button {
  position: relative;
  z-index: 6;
  min-width: 144px;
  min-height: 48px;
  margin-top: clamp(78px, 10vw, 154px);
  border: 1px solid rgba(255, 229, 181, 0.2);
  border-radius: 8px;
  padding: 0 28px;
  cursor: pointer;
  color: rgba(255, 240, 218, 0.92);
  background:
    linear-gradient(90deg, rgba(84, 22, 18, 0.38), transparent 22% 78%, rgba(72, 36, 17, 0.34)),
    linear-gradient(180deg, #181513, #080706 55%, #11100f);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08) inset,
    0 -1px 0 rgba(0, 0, 0, 0.8) inset,
    0 12px 28px rgba(0, 0, 0, 0.42),
    0 0 18px rgba(128, 44, 23, 0.12);
  font: 700 clamp(0.78rem, 1.1vw, 0.95rem) / 1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  text-transform: uppercase;
  transition:
    opacity 520ms ease,
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.stop-button::before {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 190, 122, 0.34), transparent);
}

.stop-button:hover {
  border-color: rgba(243, 180, 106, 0.38);
  background:
    linear-gradient(90deg, rgba(92, 26, 20, 0.48), transparent 22% 78%, rgba(84, 42, 19, 0.42)),
    linear-gradient(180deg, #1d1916, #090807 55%, #151311);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.1) inset,
    0 14px 32px rgba(0, 0, 0, 0.5),
    0 0 22px rgba(128, 44, 23, 0.16);
}

.stop-button:focus-visible {
  outline: 2px solid rgba(255, 216, 168, 0.72);
  outline-offset: 5px;
}

.stop-button:active {
  transform: translateY(1px) scale(0.99);
}

.stop-button.is-hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.stop-button:disabled {
  cursor: default;
}

.memorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at 50% 48%, rgba(243, 180, 106, 0.08), transparent 20%),
    radial-gradient(ellipse at center, transparent 0 34%, rgba(0, 0, 0, 0.58) 77%),
    repeating-linear-gradient(104deg, rgba(255, 255, 255, 0.014) 0 1px, transparent 1px 7px);
  transition: opacity 900ms ease;
}

.memorial-mosaic {
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.portrait-frame {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  z-index: var(--z, 1);
  width: clamp(82px, calc(var(--w) * 1vw), 168px);
  height: clamp(82px, calc(var(--w) * 1vw), 168px);
  overflow: hidden;
  border-radius: 50%;
  background: transparent;
  box-shadow:
    0 16px 34px rgba(0, 0, 0, 0.48),
    0 0 30px rgba(179, 102, 48, 0.045);
  opacity: 0;
  transform:
    translate(var(--start-x, 0), var(--start-y, 0))
    rotate(calc(var(--rotation, 0) * 1deg))
    scale(0.86);
  filter: blur(8px) grayscale(100%) saturate(55%) contrast(0.92) brightness(0.68);
  mask-image: radial-gradient(circle, #000 0 54%, rgba(0, 0, 0, 0.86) 64%, rgba(0, 0, 0, 0.36) 78%, transparent 100%);
  -webkit-mask-image: radial-gradient(circle, #000 0 54%, rgba(0, 0, 0, 0.86) 64%, rgba(0, 0, 0, 0.36) 78%, transparent 100%);
  transition:
    opacity var(--duration, 1200ms) cubic-bezier(0.16, 1, 0.3, 1) var(--delay, 0ms),
    transform var(--duration, 1200ms) cubic-bezier(0.16, 1, 0.3, 1) var(--delay, 0ms),
    filter var(--duration, 1200ms) cubic-bezier(0.16, 1, 0.3, 1) var(--delay, 0ms);
}

.portrait-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 38%, rgba(0, 0, 0, 0.16) 64%, rgba(0, 0, 0, 0.62) 100%),
    linear-gradient(180deg, rgba(255, 205, 151, 0.09), rgba(23, 13, 8, 0.18));
  mix-blend-mode: soft-light;
}

.portrait-frame.is-visible {
  opacity: var(--photo-opacity, 0.76);
  transform:
    translate(0, 0)
    rotate(calc(var(--rotation, 0) * 1deg))
    scale(1);
  filter: blur(0) grayscale(35%) saturate(70%) contrast(1.05) brightness(0.82);
}

.portrait-frame.is-hidden {
  display: none;
}

.portrait-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--object-position, center);
}

.memorial-message {
  position: relative;
  z-index: 7;
  max-width: min(74vw, 520px);
  margin: clamp(18px, 3vw, 34px) 0 0;
  color: rgba(241, 230, 216, 0.82);
  font: 500 clamp(0.78rem, 1.3vw, 0.95rem) / 1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.04em;
  text-align: center;
  opacity: 0;
  transform: translateY(7px);
  transition:
    opacity 700ms ease,
    transform 700ms ease;
}

.memorial-message.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.sr-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.counter-stage.is-memorial .memorial-overlay {
  opacity: 1;
}

.counter-stage.is-memorial .counter-wrap {
  filter: brightness(0.78) saturate(0.88);
  transform: translateY(-3vh) translateZ(42px);
}

.counter-stage.is-memorial .dot.on {
  box-shadow:
    0 0 2px rgba(255, 229, 181, 0.78),
    0 0 8px rgba(243, 180, 106, 0.34),
    0 0 15px rgba(184, 91, 28, 0.16);
}

.counter-stage.is-memorial .reflection {
  opacity: 0.07;
}

.counter-stage.is-memorial::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(circle at 50% 48%, rgba(244, 173, 92, 0.12), transparent 18%);
  mix-blend-mode: screen;
  opacity: 0.48;
}

@keyframes roll-out {
  0% {
    transform: translateY(0) rotateX(0deg);
    filter: blur(0);
    opacity: 1;
  }
  42% {
    filter: blur(1px);
    opacity: 0.82;
  }
  100% {
    transform: translateY(-104%) rotateX(48deg);
    filter: blur(1.6px);
    opacity: 0;
  }
}

@keyframes roll-in {
  0% {
    transform: translateY(102%) rotateX(-42deg);
    filter: blur(1.7px);
    opacity: 0;
  }
  58% {
    filter: blur(0.7px);
    opacity: 0.92;
  }
  100% {
    transform: translateY(0) rotateX(0deg);
    filter: blur(0);
    opacity: 1;
  }
}

@media (max-width: 620px) {
  .stage {
    padding: 14px;
  }

  .counter {
    gap: 4px;
  }

  .stop-button {
    min-width: 132px;
    min-height: 46px;
    margin-top: clamp(62px, 16vw, 96px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .digit-drum.spinning .wheel.current,
  .digit-drum.spinning .wheel.next {
    animation-duration: 1ms;
  }

  .counter-wrap,
  .memorial-overlay,
  .memorial-message,
  .portrait-frame,
  .stop-button {
    transition-duration: 180ms !important;
    transition-delay: 0ms !important;
  }

  .portrait-frame {
    transform:
      translate(0, 0)
      rotate(calc(var(--rotation, 0) * 1deg))
      scale(0.98);
    filter: grayscale(45%) saturate(65%) contrast(1) brightness(0.78);
  }
}
