:root {
  --bg0: #091224;
  --bg1: #0d1f3b;
  --bg2: #14305f;
  --panel: rgba(10, 20, 35, 0.86);
  --line: rgba(165, 191, 227, 0.28);
  --text: #e8f0ff;
  --muted: #a4b4d1;
  --accent: #4f8fff;
  --glow: #79f0ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  background:
    radial-gradient(circle at 18% 16%, rgba(83, 141, 255, 0.3), transparent 34%),
    radial-gradient(circle at 80% 15%, rgba(121, 199, 255, 0.18), transparent 28%),
    linear-gradient(140deg, var(--bg0) 0%, var(--bg1) 45%, var(--bg2) 100%);
}

.ball-shell {
  width: min(1160px, 96vw);
  margin: 0 auto;
  padding: 1.2rem 0 1.4rem;
}

.back-link {
  color: #c5ddff;
  text-decoration: none;
  font-size: 0.95rem;
}

.ball-header {
  text-align: center;
  margin: 0.7rem 0 1rem;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #b4c9eb;
  font-size: 0.74rem;
}

h1 {
  margin: 0.28rem 0 0.58rem;
  font-size: clamp(2rem, 4.4vw, 3.2rem);
  line-height: 1.06;
}

.subtitle {
  margin: 0;
  color: #c3d5f0;
}

.ball-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 1rem;
  align-items: stretch;
}

.control-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.28);
}

.control-card label {
  display: block;
  margin: 0.45rem 0 0.26rem;
  font-weight: 600;
}

.control-card select {
  width: 100%;
  border: 1px solid rgba(179, 206, 248, 0.4);
  border-radius: 10px;
  background: rgba(8, 18, 34, 0.9);
  color: #e6f2ff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.92rem;
  padding: 0.52rem 0.62rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.72rem;
}

.primary-btn,
.ghost-btn {
  border-radius: 999px;
  padding: 0.46rem 0.88rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn {
  border: 1px solid rgba(221, 236, 255, 0.5);
  background: var(--accent);
  color: #ffffff;
}

.primary-btn:disabled {
  opacity: 0.66;
  cursor: wait;
}

.ghost-btn {
  border: 1px solid rgba(179, 206, 248, 0.44);
  background: transparent;
  color: #e8f2ff;
}

.settings-link {
  display: inline-block;
  margin-top: 0.7rem;
  color: #9cc6ff;
  text-decoration: none;
  font-size: 0.92rem;
}

.settings-link:hover,
.settings-link:focus-visible {
  color: #cae3ff;
}

.result-label {
  margin: 1rem 0 0.24rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #b2c5e4;
  font-size: 0.76rem;
}

.result-text {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.04rem;
  color: #f4f8ff;
  min-height: 1.45rem;
}

.ball-stage {
  border-radius: 16px;
  border: 1px solid rgba(171, 201, 240, 0.28);
  background:
    radial-gradient(circle at 50% 42%, rgba(129, 197, 255, 0.12), transparent 64%),
    linear-gradient(150deg, rgba(11, 20, 40, 0.85) 0%, rgba(13, 25, 52, 0.9) 100%);
  min-height: 520px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.ball-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.ball-btn:disabled {
  cursor: wait;
}

.decision-ball {
  width: min(78vw, 420px);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(160, 206, 255, 0.3), transparent 35%),
    radial-gradient(circle at 64% 72%, rgba(18, 49, 113, 0.76), transparent 54%),
    linear-gradient(160deg, #0b1e4e 0%, #0a1b45 34%, #050d24 100%);
  border: 1px solid rgba(157, 185, 230, 0.3);
  box-shadow:
    0 32px 62px rgba(0, 0, 0, 0.46),
    inset 0 -22px 36px rgba(0, 0, 0, 0.35),
    inset 0 14px 20px rgba(189, 223, 255, 0.1);
  display: grid;
  place-items: center;
  transform-origin: center;
}

.decision-ball.rolling {
  animation: ballShake 280ms ease-in-out infinite;
}

.answer-window {
  width: 46%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 40%, rgba(13, 24, 52, 0.92), rgba(8, 14, 33, 0.96) 72%, rgba(3, 6, 16, 0.98) 100%);
  border: 1px solid rgba(106, 132, 182, 0.45);
  box-shadow:
    0 0 16px rgba(79, 130, 191, 0.26),
    inset 0 0 22px rgba(8, 17, 40, 0.9),
    inset 0 10px 22px rgba(157, 196, 255, 0.08);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  perspective: 720px;
}

.answer-window::after {
  content: "";
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 38%, rgba(10, 20, 48, 0.25), rgba(7, 13, 30, 0.75) 58%, rgba(5, 9, 22, 0.9) 100%),
    linear-gradient(170deg, rgba(16, 35, 76, 0.6), rgba(7, 13, 30, 0.6));
  opacity: 0.96;
  transition: opacity 700ms ease;
  pointer-events: none;
  z-index: 3;
}

.answer-core {
  width: 66%;
  aspect-ratio: 1 / 1;
  clip-path: polygon(50% 7%, 92% 84%, 8% 84%);
  background:
    radial-gradient(circle at 50% 36%, rgba(130, 230, 255, 0.55), rgba(55, 122, 215, 0.26) 62%, rgba(20, 44, 104, 0.95) 100%);
  border: 1px solid rgba(140, 231, 255, 0.38);
  box-shadow:
    0 0 12px rgba(121, 218, 255, 0.2),
    inset 0 0 14px rgba(116, 214, 255, 0.18);
  display: grid;
  place-items: center;
  padding: 0.65rem 0.35rem 0.28rem;
  opacity: 0.52;
  transform: scale(0.96);
  transition: opacity 1150ms ease, transform 1150ms ease;
  z-index: 2;
}

.answer-text {
  text-align: center;
  font-size: clamp(0.82rem, 2.2vw, 1.18rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.02em;
  color: #ecf8ff;
  text-shadow: 0 0 8px rgba(171, 236, 255, 0.45);
  opacity: 0.08;
  transition: opacity 1100ms ease;
}

.answer-window.mode-die .answer-core {
  display: none;
}

.answer-die {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 39%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  --die-depth: 18px;
  z-index: 2;
  opacity: 0.22;
  filter: brightness(0.3) saturate(0.55) contrast(0.9);
  transition: opacity 640ms ease, filter 640ms ease;
}

.die-cube {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  will-change: transform;
  transition: transform 280ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.die-face {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background-color: #08142b;
  background:
    radial-gradient(circle at 50% 36%, #153664 0%, #0d2347 56%, #08142b 100%);
  border: 0;
  box-shadow:
    inset 0 0 7px rgba(44, 102, 170, 0.1),
    inset 0 1px 0 rgba(96, 144, 198, 0.1);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.face-label {
  display: grid;
  place-items: center;
  padding: 0.12rem 0.14rem;
  width: 100%;
  height: 100%;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: #ffcb05;
  text-shadow: 0 0 8px rgba(255, 203, 5, 0.42);
  white-space: normal;
  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;
}

.die-face.face-front { transform: translateZ(calc(var(--die-depth, 18px))); }
.die-face.face-back { transform: rotateY(180deg) translateZ(calc(var(--die-depth, 18px))); }
.die-face.face-right { transform: rotateY(90deg) translateZ(calc(var(--die-depth, 18px))); }
.die-face.face-left { transform: rotateY(-90deg) translateZ(calc(var(--die-depth, 18px))); }
.die-face.face-top { transform: rotateX(90deg) translateZ(calc(var(--die-depth, 18px))); }
.die-face.face-bottom { transform: rotateX(-90deg) translateZ(calc(var(--die-depth, 18px))); }

.answer-window.revealed::after {
  opacity: 0.2;
}

.answer-window.mode-die.surfacing::after {
  opacity: 0.84;
}

.answer-window.revealed .answer-core {
  opacity: 0.95;
  transform: scale(1);
}

.answer-window.revealed .answer-text {
  opacity: 1;
}

.answer-window.mode-die .answer-text {
  opacity: 0;
}

.answer-window.mode-die.revealed .answer-die {
  opacity: 0.95;
  filter: brightness(1) saturate(1.05) contrast(1);
}

.answer-window.mode-die.surfacing .answer-die {
  opacity: 0.35;
  filter: brightness(0.44) saturate(0.62) contrast(0.92);
}

.answer-window.mode-die.revealed .answer-text {
  opacity: 1;
}

@keyframes ballShake {
  0% { transform: translate(-2px, 1px) rotate(-2.2deg); }
  20% { transform: translate(2px, -2px) rotate(2.5deg); }
  40% { transform: translate(-1px, 2px) rotate(-1.8deg); }
  60% { transform: translate(2px, 1px) rotate(2.1deg); }
  80% { transform: translate(-2px, -1px) rotate(-2.4deg); }
  100% { transform: translate(1px, 2px) rotate(1.7deg); }
}

@media (max-width: 920px) {
  .ball-layout {
    grid-template-columns: 1fr;
  }

  .ball-stage {
    min-height: 440px;
    order: -1;
  }

  .decision-ball {
    width: min(84vw, 360px);
  }
}

@media (max-width: 540px) {
  .ball-shell {
    width: 95vw;
  }

  .ball-stage {
    min-height: 390px;
  }

  .subtitle {
    font-size: 1.02rem;
  }
}
