:root {
  color-scheme: dark;
  --ink: #f9fbff;
  --muted: rgba(249, 251, 255, 0.68);
  --cyan: #16e8ff;
  --pink: #ff2fb2;
  --lime: #b8ff4f;
  --violet: #7558ff;
  --void: #070816;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 47, 178, 0.28), transparent 34%),
    radial-gradient(circle at 28% 70%, rgba(22, 232, 255, 0.2), transparent 32%),
    linear-gradient(160deg, #0c1025 0%, #070816 46%, #12071e 100%);
  -webkit-tap-highlight-color: transparent;
}

.roller {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  height: 100dvh;
  min-height: 100svh;
  padding: max(24px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
  isolation: isolate;
  cursor: pointer;
}

.roller::before,
.roller::after {
  position: absolute;
  inset: 0;
  z-index: -2;
  content: "";
}

.roller::before {
  background-image:
    linear-gradient(rgba(22, 232, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 47, 178, 0.07) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, transparent, #000 18%, #000 72%, transparent);
}

.roller::after {
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.95) 0 1px, transparent 2px) 12% 18% / 86px 96px,
    radial-gradient(circle, rgba(22, 232, 255, 0.9) 0 1px, transparent 2px) 74% 34% / 110px 110px,
    radial-gradient(circle, rgba(255, 47, 178, 0.8) 0 1px, transparent 2px) 50% 64% / 128px 126px;
  opacity: 0.42;
  animation: drift 10s linear infinite;
}

.ambient {
  position: absolute;
  z-index: -1;
  width: 48vmin;
  aspect-ratio: 1;
  border-radius: 999px;
  filter: blur(34px);
  opacity: 0.5;
}

.ambient-a {
  top: 14%;
  left: -16%;
  background: rgba(22, 232, 255, 0.42);
}

.ambient-b {
  right: -20%;
  bottom: 6%;
  background: rgba(255, 47, 178, 0.45);
}

.grid-floor {
  position: absolute;
  right: -16vw;
  bottom: -15vh;
  left: -16vw;
  z-index: -1;
  height: 45vh;
  background-image:
    linear-gradient(rgba(22, 232, 255, 0.24) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 47, 178, 0.22) 1px, transparent 1px);
  background-size: 38px 28px;
  transform: perspective(420px) rotateX(62deg);
  transform-origin: top;
  opacity: 0.45;
}

.topbar {
  display: flex;
  justify-content: center;
  padding-top: 8px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 900;
  letter-spacing: 0;
  cursor: pointer;
  text-shadow:
    0 0 14px rgba(22, 232, 255, 0.72),
    0 0 34px rgba(255, 47, 178, 0.42);
  user-select: none;
}

h1:focus-visible {
  border-radius: 8px;
  outline: 3px solid rgba(22, 232, 255, 0.55);
  outline-offset: 8px;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding-bottom: 7svh;
}

.die-shell {
  position: relative;
  display: grid;
  place-items: center;
  width: min(76vw, 360px);
  aspect-ratio: 1;
  outline: none;
}

.die-shell:focus-visible {
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.24);
}

.speed-ring {
  position: absolute;
  width: 78%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(22, 232, 255, 0.22);
  background: radial-gradient(circle, transparent 56%, rgba(22, 232, 255, 0.13) 57% 58%, transparent 60%);
  filter: drop-shadow(0 0 14px rgba(22, 232, 255, 0.42));
  opacity: 0.68;
  animation: ringSpin 7s linear infinite;
}

.die-canvas {
  position: relative;
  z-index: 2;
  display: block;
  width: min(76vw, 360px);
  aspect-ratio: 1;
  filter:
    drop-shadow(0 18px 30px rgba(0, 0, 0, 0.36))
    drop-shadow(0 0 34px rgba(22, 232, 255, 0.44));
}

.speed-ring,
.platform {
  display: none;
}

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

.settings-dialog {
  width: min(88vw, 360px);
  padding: 0;
  border: 1px solid rgba(22, 232, 255, 0.32);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(8, 10, 26, 0.92);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(18px);
}

.settings-dialog,
.settings-dialog * {
  touch-action: manipulation;
}

.settings-dialog::backdrop {
  background: rgba(2, 3, 10, 0.58);
  backdrop-filter: blur(3px);
}

.settings-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-header h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.08);
}

.setting-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 14px;
  align-items: center;
  color: rgba(249, 251, 255, 0.84);
  font-size: 15px;
}

.setting-field select,
.setting-field input {
  grid-column: 1 / -1;
}

.setting-field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(22, 232, 255, 0.28);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  background: rgba(255, 255, 255, 0.08);
}

.setting-field output {
  color: var(--lime);
  font-weight: 800;
}

.setting-field input[type="range"] {
  accent-color: var(--cyan);
}

.setting-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  color: rgba(249, 251, 255, 0.84);
  font-size: 15px;
}

.setting-toggle input {
  width: 46px;
  height: 26px;
  accent-color: var(--cyan);
}

.platform {
  position: absolute;
  bottom: 20%;
  width: 62%;
  height: 18%;
  border: 1px solid rgba(22, 232, 255, 0.5);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(22, 232, 255, 0.38), rgba(255, 47, 178, 0.08) 46%, transparent 70%);
  filter: blur(0.5px) drop-shadow(0 0 26px rgba(22, 232, 255, 0.72));
  transform: translateY(60%);
}

.orbit {
  position: absolute;
  inset: 13% 10%;
  pointer-events: none;
  animation: orbit 9s linear infinite;
  opacity: 0.72;
}

.orbit-two {
  inset: 20% 8%;
  animation-duration: 12s;
  animation-direction: reverse;
}

.orbit span {
  position: absolute;
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  font-weight: 800;
  background: rgba(7, 8, 22, 0.46);
  box-shadow: 0 0 18px rgba(22, 232, 255, 0.2);
  backdrop-filter: blur(10px);
}

.orbit span:nth-child(1) {
  top: 18%;
  left: 3%;
}

.orbit span:nth-child(2) {
  top: 2%;
  right: 16%;
}

.orbit span:nth-child(3) {
  right: 7%;
  bottom: 18%;
}

.rolling .die-canvas {
  animation: diceLift 900ms cubic-bezier(0.2, 0.86, 0.28, 1.08) both;
  filter:
    drop-shadow(0 20px 38px rgba(0, 0, 0, 0.34))
    drop-shadow(0 0 62px rgba(255, 47, 178, 0.76));
}

.rolling .speed-ring {
  animation: ringSpin 280ms linear infinite;
  border-color: rgba(22, 232, 255, 0.54);
  opacity: 0.9;
}

.rolling .orbit {
  animation-duration: 1200ms;
}

.rolling .platform {
  animation: pulse 460ms ease-in-out infinite alternate;
}

@keyframes diceLift {
  0% {
    transform: translateY(0) scale(1);
  }
  38% {
    transform: translateY(-12px) scale(1.12);
  }
  72% {
    transform: translateY(6px) scale(0.97);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes ringSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes orbit {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  from {
    opacity: 0.62;
    transform: translateY(60%) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(60%) scale(1.08);
  }
}

@keyframes drift {
  to {
    transform: translate3d(-42px, 36px, 0);
  }
}

@media (min-width: 720px) {
  .roller {
    max-width: 480px;
    margin: 0 auto;
    overflow: hidden;
    border-inline: 1px solid rgba(255, 255, 255, 0.08);
  }
}

@media (max-width: 480px) and (min-height: 820px) {
  .roller {
    padding-top: max(20px, env(safe-area-inset-top));
  }

  h1 {
    font-size: clamp(34px, 9.8vw, 42px);
  }

  .stage {
    padding-bottom: 10svh;
  }

  .die-shell {
    width: min(72vw, 330px);
  }

  .die-canvas {
    width: min(72vw, 330px);
  }

  .roller::after {
    animation-play-state: paused;
  }

  .ambient {
    filter: blur(22px);
    opacity: 0.36;
  }

  .die-canvas {
    filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.28));
  }

  .rolling .die-canvas {
    filter: drop-shadow(0 16px 24px rgba(0, 0, 0, 0.32));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
