:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  --felt-deep: #0d281d;
  --felt-mid: #12402d;
  --felt-bright: #1f5a41;
  --felt-line: rgba(225, 241, 229, 0.12);
  --panel-bg: rgba(7, 18, 14, 0.76);
  --panel-line: rgba(236, 247, 232, 0.14);
  --panel-line-strong: rgba(255, 244, 218, 0.36);
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
}

body.dice-app-body {
  min-height: 100svh;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  background:
    radial-gradient(circle at 50% 20%, rgba(101, 170, 131, 0.18), transparent 22%),
    radial-gradient(circle at 16% 16%, rgba(255, 212, 131, 0.08), transparent 18%),
    radial-gradient(circle at 84% 24%, rgba(12, 48, 31, 0.3), transparent 20%),
    linear-gradient(180deg, #071812 0%, #0a241a 28%, #081712 100%);
}

body.dice-app-body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.1;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 5px 5px;
}

img {
  display: block;
  width: 100%;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.dice-app {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overscroll-behavior: none;
}

.dice-stage {
  --cup-top: 5.1%;
  --impact-left: 50%;
  --impact-bottom: 23.4%;
  position: relative;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  cursor: pointer;
  touch-action: manipulation;
}

.dice-stage__glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.dice-stage__glow::before,
.dice-stage__glow::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(20px);
}

.dice-stage__glow::before {
  inset: 8% 24% auto;
  height: 12%;
  background: radial-gradient(circle, rgba(255, 208, 127, 0.09), transparent 72%);
}

.dice-stage__glow::after {
  inset: auto 10% 12%;
  height: 20%;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.3), transparent 72%);
}

.dice-effects {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.dice-effects__halo,
.dice-effects__flash,
.dice-effects__ring,
.dice-effects__sparks {
  position: absolute;
  left: var(--impact-left);
  bottom: var(--impact-bottom);
  transform: translateX(-50%);
  pointer-events: none;
}

.dice-effects__halo {
  width: min(74vw, 520px);
  height: min(34vw, 220px);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at center, rgba(255, 213, 140, 0.18), rgba(255, 213, 140, 0.04) 40%, transparent 72%),
    radial-gradient(ellipse at center, rgba(79, 182, 113, 0.18), transparent 68%);
  filter: blur(10px);
  opacity: 0.18;
}

.dice-effects__halo.is-hot {
  animation: dice-halo-surge 620ms ease-out;
}

.dice-stage[data-state="idle"] .dice-effects__halo:not(.is-hot) {
  animation: dice-halo-idle 5.6s ease-in-out infinite;
}

.dice-effects__flash {
  width: min(42vw, 260px);
  height: min(42vw, 260px);
  margin-left: -2%;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 246, 218, 0.82) 0%, rgba(255, 214, 140, 0.36) 28%, rgba(255, 214, 140, 0.08) 52%, transparent 74%);
  opacity: 0;
  filter: blur(6px);
}

.dice-effects__ring {
  width: min(56vw, 360px);
  height: min(16vw, 96px);
  border-radius: 50%;
  border: 2px solid rgba(255, 235, 195, 0.22);
  box-shadow:
    0 0 0 1px rgba(255, 222, 170, 0.06),
    0 0 30px rgba(255, 210, 128, 0.14);
  opacity: 0;
}

.dice-effects__sparks {
  width: 0;
  height: 0;
}

.dice-effects__spark {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 34px;
  height: 4px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(255, 244, 222, 0.96), rgba(255, 197, 111, 0.78), rgba(255, 197, 111, 0));
  opacity: 0;
  transform: rotate(var(--spark-rotate));
  box-shadow: 0 0 16px rgba(255, 211, 138, 0.26);
}

.dice-cup {
  position: absolute;
  top: max(var(--cup-top), 28px);
  left: 50%;
  width: clamp(180px, 38vw, 290px);
  transform: translateX(-50%);
  transform-origin: 50% 80%;
  z-index: 4;
  pointer-events: none;
}

.dice-cup img {
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 24px 34px rgba(0, 0, 0, 0.4));
}

.dice-cup.is-launching {
  animation: dice-cup-launch 920ms cubic-bezier(0.22, 1, 0.36, 1);
}

.dice-stage[data-state="idle"] .dice-cup:not(.is-launching) {
  animation: dice-cup-idle 4.8s ease-in-out infinite;
}

.dice-stage.is-shaking {
  animation: dice-stage-jolt 620ms cubic-bezier(0.16, 0.9, 0.24, 1);
}

.dice-dice {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.dice-sprite {
  --slot-left: 50%;
  --slot-bottom: 17%;
  --slot-size: 156px;
  --launch-x: 0px;
  --launch-y: -240px;
  --mid-x: 0px;
  --rest-rotate: -6deg;
  position: absolute;
  left: var(--slot-left);
  bottom: var(--slot-bottom);
  width: var(--slot-size);
  transform: translate(-50%, 0) rotate(var(--rest-rotate));
  transform-origin: 50% 82%;
  pointer-events: none;
  user-select: none;
}

.dice-dice[data-dice-count="1"] .dice-sprite[data-die-slot="0"] {
  --launch-x: 0px;
  --launch-y: -252px;
  --mid-x: 0px;
  --rest-rotate: -5deg;
}

.dice-dice[data-dice-count="2"] .dice-sprite[data-die-slot="0"] {
  --launch-x: 86px;
  --launch-y: -226px;
  --mid-x: 24px;
  --rest-rotate: -10deg;
}

.dice-dice[data-dice-count="2"] .dice-sprite[data-die-slot="1"] {
  --launch-x: -88px;
  --launch-y: -214px;
  --mid-x: -28px;
  --rest-rotate: 9deg;
}

.dice-sprite.is-launching {
  animation: dice-die-launch 1040ms cubic-bezier(0.18, 0.95, 0.24, 1) both;
}

.dice-sprite__shadow,
.dice-sprite__dust,
.dice-sprite__image {
  position: absolute;
  left: 50%;
  width: 100%;
  height: auto;
}

.dice-sprite__shadow {
  bottom: -5%;
  transform: translateX(-50%);
  opacity: 0.94;
  filter: blur(1px);
}

.dice-sprite__image {
  bottom: 0;
  transform: translateX(-50%);
  filter: drop-shadow(0 24px 34px rgba(5, 9, 16, 0.38));
}

.dice-sprite__dust {
  bottom: -8%;
  transform: translateX(-50%) scale(0.76);
  opacity: 0;
  mix-blend-mode: screen;
}

.dice-sprite__dust.is-active {
  animation: dice-dust-pop 360ms ease-out;
}

.dice-effects__flash.is-active {
  animation: dice-flash-pop 320ms ease-out;
}

.dice-effects__ring.is-active {
  animation: dice-ring-wave 480ms cubic-bezier(0.12, 0.88, 0.24, 1);
}

.dice-effects__sparks.is-active .dice-effects__spark {
  animation: dice-spark-burst 520ms cubic-bezier(0.18, 0.92, 0.24, 1) forwards;
}

.dice-effects__sparks.is-active .dice-effects__spark:nth-child(2) {
  animation-delay: 18ms;
}

.dice-effects__sparks.is-active .dice-effects__spark:nth-child(3) {
  animation-delay: 32ms;
}

.dice-effects__sparks.is-active .dice-effects__spark:nth-child(4) {
  animation-delay: 52ms;
}

.dice-effects__sparks.is-active .dice-effects__spark:nth-child(5) {
  animation-delay: 22ms;
}

.dice-effects__sparks.is-active .dice-effects__spark:nth-child(6) {
  animation-delay: 42ms;
}

.dice-controls {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 112px;
  padding:
    16px
    16px
    calc(14px + env(safe-area-inset-bottom, 0px));
  background:
    linear-gradient(180deg, rgba(7, 15, 12, 0), rgba(7, 15, 12, 0.76) 28%, rgba(7, 15, 12, 0.96)),
    linear-gradient(180deg, rgba(5, 14, 10, 0.92), rgba(5, 14, 10, 0.96));
  touch-action: manipulation;
}

.dice-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 24px;
  border: 1px solid var(--panel-line);
  background: var(--panel-bg);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
}

.dice-choice {
  position: relative;
  display: block;
}

.dice-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.dice-choice__chip,
.dice-sound-toggle {
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease;
}

.dice-choice__chip {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
}

.dice-choice__chip img {
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.2));
}

.dice-choice__chip--pair img {
  width: 108%;
}

.dice-choice input:checked + .dice-choice__chip {
  transform: translateY(-1px);
  border-color: var(--panel-line-strong);
  background:
    linear-gradient(180deg, rgba(53, 37, 21, 0.86), rgba(29, 19, 10, 0.94)),
    radial-gradient(circle at top, rgba(255, 229, 184, 0.14), transparent 62%);
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.22);
}

.dice-sound-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 66px;
  height: 66px;
  padding: 0;
  border: 1px solid var(--panel-line);
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 228, 183, 0.18), transparent 34%),
    linear-gradient(180deg, rgba(18, 43, 32, 0.94), rgba(8, 20, 15, 0.98));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 12px 24px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

.dice-sound-toggle__icon {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: rgba(255, 245, 224, 0.92);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dice-sound-toggle__wave,
.dice-sound-toggle__slash {
  transition: opacity 180ms ease;
}

.dice-sound-toggle__wave--outer {
  opacity: 0.82;
}

.dice-sound-toggle[data-muted="true"] .dice-sound-toggle__wave {
  opacity: 0;
}

.dice-sound-toggle[data-muted="true"] .dice-sound-toggle__slash {
  opacity: 1;
}

.dice-sound-toggle[data-muted="false"] .dice-sound-toggle__slash {
  opacity: 0;
}

.dice-choice input:focus-visible + .dice-choice__chip,
.dice-sound-toggle:hover,
.dice-sound-toggle:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255, 243, 213, 0.24);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.28);
}

.dice-sound-toggle:disabled,
.dice-choice input:disabled + .dice-choice__chip {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
  box-shadow: none;
}

@keyframes dice-cup-launch {
  0% {
    transform: translateX(-50%) translateY(0) rotate(-6deg);
  }
  22% {
    transform: translateX(-50%) translateY(-10px) rotate(5deg);
  }
  48% {
    transform: translateX(-50%) translateY(-36px) rotate(11deg);
  }
  72% {
    transform: translateX(-50%) translateY(-10px) rotate(-2deg);
  }
  100% {
    transform: translateX(-50%) translateY(0) rotate(-3deg);
  }
}

@keyframes dice-cup-idle {
  0% {
    transform: translateX(-50%) translateY(0) rotate(-1.5deg);
  }
  50% {
    transform: translateX(-50%) translateY(-6px) rotate(1.8deg);
  }
  100% {
    transform: translateX(-50%) translateY(0) rotate(-1.5deg);
  }
}

@keyframes dice-die-launch {
  0% {
    transform: translate(calc(-50% + var(--launch-x)), var(--launch-y)) rotate(-34deg) scale(0.78);
  }
  42% {
    transform: translate(calc(-50% + var(--mid-x)), -48px) rotate(152deg) scale(1.04);
  }
  72% {
    transform: translate(-50%, 12px) rotate(calc(var(--rest-rotate) - 18deg)) scale(0.98);
  }
  100% {
    transform: translate(-50%, 0) rotate(var(--rest-rotate)) scale(1);
  }
}

@keyframes dice-dust-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.68);
  }
  24% {
    opacity: 0.44;
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(1.12);
  }
}

@keyframes dice-flash-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.44);
  }
  18% {
    opacity: 0.92;
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(1.16);
  }
}

@keyframes dice-halo-surge {
  0% {
    opacity: 0.12;
    transform: translateX(-50%) scale(0.9);
  }
  30% {
    opacity: 0.4;
    transform: translateX(-50%) scale(1.04);
  }
  100% {
    opacity: 0.18;
    transform: translateX(-50%) scale(1);
  }
}

@keyframes dice-halo-idle {
  0% {
    opacity: 0.14;
    transform: translateX(-50%) scale(0.96);
  }
  50% {
    opacity: 0.22;
    transform: translateX(-50%) scale(1.03);
  }
  100% {
    opacity: 0.14;
    transform: translateX(-50%) scale(0.96);
  }
}

@keyframes dice-ring-wave {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.72);
  }
  18% {
    opacity: 0.56;
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(1.42);
  }
}

@keyframes dice-spark-burst {
  0% {
    opacity: 0;
    transform: translate(0, 0) rotate(var(--spark-rotate)) scale(0.7);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--spark-x), var(--spark-y)) rotate(var(--spark-rotate)) scale(0.22);
  }
}

@keyframes dice-stage-jolt {
  0% {
    transform: translate3d(0, 0, 0);
  }
  18% {
    transform: translate3d(-0.8px, 0.6px, 0);
  }
  32% {
    transform: translate3d(1.2px, -0.5px, 0);
  }
  48% {
    transform: translate3d(-0.9px, -0.4px, 0);
  }
  64% {
    transform: translate3d(0.8px, 0.3px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dice-choice__chip,
  .dice-sound-toggle {
    transition: none;
  }

  .dice-stage[data-state="idle"] .dice-cup:not(.is-launching),
  .dice-stage[data-state="idle"] .dice-effects__halo:not(.is-hot),
  .dice-cup.is-launching,
  .dice-sprite.is-launching,
  .dice-sprite__dust.is-active,
  .dice-effects__flash.is-active,
  .dice-effects__ring.is-active,
  .dice-effects__sparks.is-active .dice-effects__spark,
  .dice-stage.is-shaking {
    animation-duration: 1ms;
  }
}

@media (min-width: 960px) {
  .dice-sound-toggle {
    width: 72px;
    height: 72px;
  }
}

@media (max-width: 420px) {
  .dice-controls {
    gap: 10px;
    min-height: 102px;
    padding-inline: 12px;
  }

  .dice-picker {
    gap: 8px;
    padding: 7px;
  }

  .dice-choice__chip {
    width: 66px;
    height: 66px;
  }

  .dice-sound-toggle {
    width: 62px;
    height: 62px;
  }
}
