:root {
  color-scheme: dark;
  --bg: #02050b;
  --ink: #f1fbff;
  --muted: #92a9bb;
  --cyan: #34d7ff;
  --cyan-soft: rgba(52, 215, 255, 0.18);
  --blue: #0b75ff;
  --green: #35f2b8;
  --danger: #ff5678;
  --panel: rgba(3, 12, 25, 0.72);
  --panel-strong: rgba(4, 15, 31, 0.9);
  --line: rgba(111, 214, 255, 0.2);
  --line-strong: rgba(111, 214, 255, 0.48);
  --shadow: 0 26px 90px rgba(0, 0, 0, 0.52);
  --radius: 8px;
  --row-h: 78px;
  --row-gap: 12px;
  --topbar-h: 78px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
svg {
  color: inherit;
}

button {
  border: 0;
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.scene-bg {
  position: fixed;
  inset: 0;
  z-index: -6;
  background:
    linear-gradient(90deg, rgba(1, 5, 12, 0.88), rgba(1, 6, 15, 0.28) 44%, rgba(1, 5, 12, 0.78)),
    linear-gradient(180deg, rgba(0, 0, 0, 0.2), #02050b 94%),
    url("/assets/smp-roll-bg.png") center / cover no-repeat;
}

.scene-bg::after {
  position: absolute;
  inset: 0;
  content: "";
  background:
    radial-gradient(circle at 43% 46%, rgba(52, 215, 255, 0.24), transparent 21rem),
    radial-gradient(circle at 78% 48%, rgba(11, 117, 255, 0.18), transparent 18rem),
    linear-gradient(rgba(52, 215, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(52, 215, 255, 0.025) 1px, transparent 1px);
  background-size: auto, auto, 42px 42px, 42px 42px;
  mix-blend-mode: screen;
  opacity: 0.72;
}

.storm-layer {
  position: fixed;
  inset: -20%;
  z-index: -4;
  pointer-events: none;
  background:
    repeating-linear-gradient(105deg, transparent 0 42px, rgba(116, 223, 255, 0.08) 43px 44px, transparent 45px 72px);
  filter: blur(0.4px);
  opacity: 0.5;
  animation: stormDrift 12s linear infinite;
}

.particle-layer {
  position: fixed;
  inset: 0;
  z-index: -3;
  overflow: hidden;
  pointer-events: none;
}

.particle-layer span {
  position: absolute;
  width: 5px;
  height: 5px;
  background: rgba(135, 229, 255, 0.78);
  box-shadow: 0 0 18px rgba(52, 215, 255, 0.78);
  opacity: 0;
  animation: particleFall 9s linear infinite;
}

.particle-layer span:nth-child(1) { left: 4%; animation-delay: -1s; }
.particle-layer span:nth-child(2) { left: 9%; animation-delay: -7s; }
.particle-layer span:nth-child(3) { left: 14%; animation-delay: -4s; }
.particle-layer span:nth-child(4) { left: 19%; animation-delay: -8s; }
.particle-layer span:nth-child(5) { left: 24%; animation-delay: -2s; }
.particle-layer span:nth-child(6) { left: 31%; animation-delay: -6s; }
.particle-layer span:nth-child(7) { left: 38%; animation-delay: -3s; }
.particle-layer span:nth-child(8) { left: 45%; animation-delay: -9s; }
.particle-layer span:nth-child(9) { left: 52%; animation-delay: -5s; }
.particle-layer span:nth-child(10) { left: 59%; animation-delay: -1.5s; }
.particle-layer span:nth-child(11) { left: 66%; animation-delay: -7.5s; }
.particle-layer span:nth-child(12) { left: 72%; animation-delay: -3.5s; }
.particle-layer span:nth-child(13) { left: 78%; animation-delay: -8.5s; }
.particle-layer span:nth-child(14) { left: 83%; animation-delay: -4.5s; }
.particle-layer span:nth-child(15) { left: 88%; animation-delay: -6.5s; }
.particle-layer span:nth-child(16) { left: 92%; animation-delay: -2.5s; }
.particle-layer span:nth-child(17) { left: 96%; animation-delay: -5.5s; }
.particle-layer span:nth-child(18) { left: 36%; animation-delay: -10s; }
.particle-layer span:nth-child(19) { left: 68%; animation-delay: -9.5s; }
.particle-layer span:nth-child(20) { left: 11%; animation-delay: -11s; }

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--topbar-h);
  padding: 16px 36px;
  background: linear-gradient(180deg, rgba(1, 6, 14, 0.82), rgba(1, 6, 14, 0));
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 1rem;
  font-weight: 950;
}

.brand-mark,
.icon-button,
.live-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(2, 12, 26, 0.72);
  box-shadow: 0 0 34px rgba(52, 215, 255, 0.12);
  backdrop-filter: blur(18px);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--cyan);
}

.brand-mark svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  padding: 0 13px;
  color: #dff7ff;
  font-size: 0.82rem;
  font-weight: 900;
}

.live-chip span {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 20px rgba(53, 242, 184, 0.8);
}

.live-chip.is-offline span {
  background: var(--danger);
  box-shadow: 0 0 20px rgba(255, 86, 120, 0.8);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  min-width: 42px;
  padding: 0 12px;
  color: #cff5ff;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 900;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: rgba(7, 33, 60, 0.82);
  transform: translateY(-1px);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button[aria-pressed="true"] {
  border-color: rgba(53, 242, 184, 0.52);
  color: #bfffe9;
}

.icon-button[aria-pressed="false"] .sound-wave {
  opacity: 0.24;
}

.roll-screen {
  position: relative;
  width: min(1320px, calc(100% - 48px));
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(var(--topbar-h) + 24px) 0 30px;
  display: grid;
  align-items: center;
}

.roll-screen::before {
  position: fixed;
  top: 74px;
  left: 50%;
  z-index: -1;
  width: min(900px, calc(100vw - 40px));
  color: rgba(217, 248, 255, 0.06);
  content: "MapixeSMP Roll";
  font-size: 5.2rem;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  text-shadow: 0 0 54px rgba(52, 215, 255, 0.16);
  transform: translateX(-50%);
  pointer-events: none;
}

.roll-arena {
  display: grid;
  grid-template-columns: minmax(420px, 1.15fr) minmax(340px, 0.85fr);
  gap: 22px;
  align-items: center;
}

.roll-machine {
  position: relative;
  min-height: 690px;
}

.machine-aura {
  position: absolute;
  inset: 7% 4%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(52, 215, 255, 0.28), rgba(11, 117, 255, 0.08) 34%, transparent 66%);
  filter: blur(30px);
  animation: auraPulse 5.8s ease-in-out infinite;
}

.machine-ring {
  position: absolute;
  inset: 12% 11%;
  border: 1px solid rgba(52, 215, 255, 0.24);
  border-radius: 50%;
  box-shadow:
    inset 0 0 40px rgba(52, 215, 255, 0.1),
    0 0 50px rgba(52, 215, 255, 0.16);
  animation: ringFloat 9s ease-in-out infinite;
}

.machine-ring::before,
.machine-ring::after {
  position: absolute;
  inset: 9%;
  border: 1px solid rgba(52, 215, 255, 0.14);
  border-radius: inherit;
  content: "";
}

.machine-ring::after {
  inset: 22%;
  border-color: rgba(255, 255, 255, 0.08);
}

.machine-frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid rgba(128, 225, 255, 0.22);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(4, 20, 40, 0.76), rgba(1, 7, 16, 0.88)),
    rgba(2, 8, 17, 0.82);
  box-shadow:
    var(--shadow),
    inset 0 0 0 1px rgba(255, 255, 255, 0.045),
    inset 0 0 90px rgba(52, 215, 255, 0.1);
  backdrop-filter: blur(22px);
}

.machine-frame::before {
  position: absolute;
  inset: 16px;
  z-index: 4;
  border: 1px solid rgba(128, 225, 255, 0.13);
  border-radius: var(--radius);
  pointer-events: none;
  content: "";
}

.roll-track {
  position: absolute;
  top: 0;
  left: 26px;
  right: 26px;
  z-index: 3;
  will-change: transform;
}

.roll-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  height: var(--row-h);
  margin-bottom: var(--row-gap);
  padding: 11px 15px;
  border: 1px solid color-mix(in srgb, var(--item-color), transparent 62%);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--item-color), transparent 82%), rgba(5, 15, 29, 0.84) 48%),
    rgba(4, 13, 26, 0.9);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.3);
}

.roll-item.is-target {
  border-color: color-mix(in srgb, var(--item-color), white 22%);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--item-color), transparent 72%), rgba(6, 22, 39, 0.95) 52%),
    rgba(5, 18, 35, 0.95);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--item-color), transparent 48%),
    0 0 44px color-mix(in srgb, var(--item-color), transparent 60%);
}

.roll-icon,
.result-orb {
  display: grid;
  place-items: center;
  color: var(--item-color, var(--cyan));
}

.roll-icon {
  width: 48px;
  height: 48px;
  border: 1px solid color-mix(in srgb, var(--item-color), transparent 42%);
  border-radius: 7px;
  background:
    radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.18), transparent 34%),
    color-mix(in srgb, var(--item-color), transparent 86%);
}

.roll-icon svg,
.result-orb svg {
  width: 28px;
  height: 28px;
}

.roll-copy {
  min-width: 0;
}

.roll-copy strong {
  display: block;
  overflow: hidden;
  color: #f6fcff;
  font-size: 1rem;
  font-weight: 950;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roll-copy span {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: #9fb4c5;
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roll-number {
  color: color-mix(in srgb, var(--item-color), white 20%);
  font-size: 0.78rem;
  font-weight: 950;
}

.selection-beam {
  position: absolute;
  left: 18px;
  right: 18px;
  top: calc(50% + 41px);
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  transform: translateY(-50%);
  pointer-events: none;
}

.selection-beam span {
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(70, 221, 255, 0.95), transparent);
  box-shadow: 0 0 28px rgba(52, 215, 255, 0.9);
}

.selection-beam strong {
  padding: 7px 11px;
  border: 1px solid rgba(89, 225, 255, 0.62);
  border-radius: var(--radius);
  background: rgba(1, 9, 20, 0.88);
  color: #dffaff;
  font-size: 0.74rem;
  font-weight: 950;
}

.machine-frame.is-rolling .selection-beam strong {
  animation: beamPulse 520ms ease-in-out infinite alternate;
}

.machine-frame.is-rolling .roll-track {
  filter: saturate(1.24);
}

.scanline,
.machine-vignette {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
}

.scanline {
  background: linear-gradient(180deg, transparent 0 48%, rgba(255, 255, 255, 0.08) 50%, transparent 52%);
  transform: translateY(-120%);
  animation: scanSweep 3.8s ease-in-out infinite;
}

.machine-vignette {
  background:
    linear-gradient(180deg, #020813 0%, transparent 26%, transparent 74%, #020813 100%),
    linear-gradient(90deg, rgba(2, 8, 19, 0.85), transparent 17%, transparent 83%, rgba(2, 8, 19, 0.85));
}

.result-panel {
  position: relative;
  overflow: hidden;
  min-height: 620px;
  padding: 38px;
  border: 1px solid rgba(128, 225, 255, 0.23);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--item-color, var(--cyan)), transparent 76%), transparent 18rem),
    linear-gradient(160deg, rgba(5, 20, 39, 0.9), rgba(2, 8, 17, 0.7)),
    rgba(2, 9, 19, 0.82);
  box-shadow: var(--shadow), inset 0 0 80px rgba(52, 215, 255, 0.08);
  backdrop-filter: blur(22px);
}

.result-panel::before {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background:
    linear-gradient(120deg, transparent 0 22%, rgba(255, 255, 255, 0.08) 36%, transparent 49%),
    radial-gradient(circle at 78% 18%, color-mix(in srgb, var(--item-color, var(--cyan)), transparent 70%), transparent 10rem);
  content: "";
  pointer-events: none;
}

.result-panel.is-revealed {
  animation: resultKick 620ms ease both;
}

.result-orb {
  position: relative;
  width: 108px;
  height: 108px;
  border: 1px solid color-mix(in srgb, var(--item-color, var(--cyan)), transparent 34%);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 34% 18%, rgba(255, 255, 255, 0.28), transparent 32%),
    color-mix(in srgb, var(--item-color, var(--cyan)), transparent 82%);
  box-shadow:
    0 0 48px color-mix(in srgb, var(--item-color, var(--cyan)), transparent 56%),
    inset 0 0 28px rgba(255, 255, 255, 0.05);
}

.result-orb::after {
  position: absolute;
  inset: -12px;
  border: 1px solid color-mix(in srgb, var(--item-color, var(--cyan)), transparent 72%);
  border-radius: inherit;
  content: "";
  animation: iconOrbit 3.4s ease-in-out infinite;
}

.result-orb svg {
  width: 52px;
  height: 52px;
}

.result-label {
  margin: 28px 0 0;
  color: var(--cyan);
  font-size: 0.8rem;
  font-weight: 950;
  text-transform: uppercase;
}

.result-panel h1 {
  position: relative;
  margin: 10px 0 0;
  max-width: 720px;
  color: #f8fdff;
  font-size: 3.7rem;
  line-height: 0.98;
  font-weight: 950;
  overflow-wrap: anywhere;
  text-shadow: 0 0 36px color-mix(in srgb, var(--item-color, var(--cyan)), transparent 72%);
}

.result-panel.is-long-title h1 {
  font-size: 2.7rem;
  line-height: 1.05;
}

.result-panel.is-very-long-title h1 {
  font-size: 2.25rem;
  line-height: 1.08;
}

.result-copy {
  position: relative;
  min-height: 96px;
  margin: 20px 0 0;
  color: #adc1cf;
  font-size: 1.06rem;
  line-height: 1.62;
}

.next-roll {
  position: absolute;
  left: 38px;
  right: 38px;
  bottom: 38px;
  padding: 18px;
  border: 1px solid rgba(128, 225, 255, 0.18);
  border-radius: var(--radius);
  background: rgba(1, 9, 20, 0.58);
}

.next-roll span,
.next-roll small {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.next-roll strong {
  display: block;
  margin: 7px 0;
  color: #f4fbff;
  font-size: 2rem;
  line-height: 1;
  font-weight: 950;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid rgba(52, 215, 255, 0.34);
  border-radius: var(--radius);
  background: rgba(2, 12, 26, 0.94);
  color: #e9fbff;
  font-size: 0.9rem;
  font-weight: 850;
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@keyframes stormDrift {
  to { transform: translate3d(-90px, 0, 0); }
}

@keyframes particleFall {
  0% { opacity: 0; transform: translate3d(0, -8vh, 0) rotate(0deg); }
  9% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(22px, 112vh, 0) rotate(180deg); }
}

@keyframes auraPulse {
  50% { transform: scale(1.08); opacity: 0.72; }
}

@keyframes ringFloat {
  50% { transform: scale(1.04) rotate(2deg); }
}

@keyframes beamPulse {
  from { transform: scale(1); box-shadow: 0 0 16px rgba(52, 215, 255, 0.24); }
  to { transform: scale(1.06); box-shadow: 0 0 32px rgba(52, 215, 255, 0.58); }
}

@keyframes scanSweep {
  0%, 44% { transform: translateY(-120%); opacity: 0; }
  52% { opacity: 1; }
  86%, 100% { transform: translateY(120%); opacity: 0; }
}

@keyframes iconOrbit {
  50% { transform: scale(1.08); opacity: 0.52; }
}

@keyframes resultKick {
  0% { transform: translateY(10px); filter: brightness(1.18); }
  100% { transform: translateY(0); filter: brightness(1); }
}

@media (max-width: 1040px) {
  .topbar {
    position: relative;
    padding: 14px 18px;
  }

  .roll-screen {
    width: min(100% - 28px, 760px);
    min-height: auto;
    padding: 18px 0 34px;
  }

  .roll-screen::before {
    top: 80px;
    font-size: 3.4rem;
  }

  .roll-arena {
    grid-template-columns: 1fr;
  }

  .roll-machine {
    min-height: 560px;
  }

  .result-panel {
    min-height: 480px;
  }

  .result-panel h1 {
    font-size: 2.55rem;
  }

  .result-panel.is-long-title h1,
  .result-panel.is-very-long-title h1 {
    font-size: 2.05rem;
  }
}

@media (max-width: 640px) {
  :root {
    --row-h: 72px;
    --row-gap: 10px;
  }

  .topbar {
    gap: 12px;
  }

  .brand span:last-child,
  .live-chip strong,
  .icon-button span {
    display: none;
  }

  .top-controls {
    margin-left: auto;
  }

  .roll-screen {
    width: min(100% - 18px, 520px);
    padding-top: 10px;
  }

  .roll-screen::before {
    display: none;
  }

  .roll-machine {
    min-height: 440px;
  }

  .roll-track {
    left: 12px;
    right: 12px;
  }

  .roll-item {
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 10px;
    padding: 9px 10px;
  }

  .roll-icon {
    width: 42px;
    height: 42px;
  }

  .roll-number {
    display: none;
  }

  .selection-beam {
    display: none;
  }

  .result-panel {
    min-height: auto;
    padding: 24px;
  }

  .result-orb {
    width: 84px;
    height: 84px;
  }

  .result-orb svg {
    width: 42px;
    height: 42px;
  }

  .result-panel h1 {
    font-size: 2rem;
  }

  .result-panel.is-long-title h1,
  .result-panel.is-very-long-title h1 {
    font-size: 1.62rem;
  }

  .result-copy {
    font-size: 1rem;
  }

  .next-roll {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    margin-top: 22px;
  }

  .next-roll strong {
    font-size: 1.5rem;
  }
}

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