:root {
  --bg: #070512; --ink: #f4f1ff; --dim: #a59fc9; --cyan: #3ef2ff; --pink: #ff4fd8; --violet: #8b5cff;
  --tri: #1b2cff; --tri2: #0a0f6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(60vmax 60vmax at 50% 45%, rgba(139, 92, 255, .22), transparent 60%),
    radial-gradient(40vmax 40vmax at 10% 100%, rgba(62, 242, 255, .12), transparent 60%),
    radial-gradient(40vmax 40vmax at 95% 0%, rgba(255, 79, 216, .14), transparent 60%),
    var(--bg);
  min-height: 100dvh;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.stage {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  text-align: center;
}
.top { display: grid; gap: 6px; justify-items: center; }
.back { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 14px; color: var(--dim); text-decoration: none; font-weight: 700; font-size: 14px; }
.back:hover { color: var(--cyan); }
h1 {
  margin: 0; font-weight: 900; letter-spacing: .12em; font-size: clamp(26px, 7vw, 44px);
  color: #fff; text-shadow: 0 0 6px var(--violet), 0 0 22px var(--violet), 0 0 44px rgba(139, 92, 255, .6);
}
h1 span { color: var(--cyan); text-shadow: 0 0 8px var(--cyan), 0 0 26px var(--cyan); }
.tag { margin: 0; color: var(--dim); max-width: 30ch; }

/* The ball */
.ball {
  --size: min(72vw, 340px);
  position: relative; width: var(--size); height: var(--size); border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: radial-gradient(circle at 34% 28%, #4a4560 0, #1a1726 22%, #07060c 55%, #000 75%);
  box-shadow:
    0 0 0 2px rgba(139, 92, 255, .55), 0 0 30px rgba(139, 92, 255, .55), 0 0 80px rgba(62, 242, 255, .25),
    inset -18px -24px 50px rgba(0, 0, 0, .9), inset 10px 12px 30px rgba(255, 255, 255, .06);
  -webkit-tap-highlight-color: transparent;
  transition: transform .2s;
}
.ball:hover { transform: scale(1.015); }
.ball:focus-visible { outline: 3px solid var(--cyan); outline-offset: 6px; }
.shine {
  position: absolute; left: 18%; top: 10%; width: 34%; height: 20%; border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, .35), transparent 70%); transform: rotate(-25deg); pointer-events: none;
}
.window {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; transform: translate(-50%, -50%);
  border-radius: 50%; background: #fff; display: grid; place-items: center; overflow: hidden;
  box-shadow: inset 0 0 0 4px #ddd, 0 0 18px rgba(255, 255, 255, .25);
  transition: background .35s, box-shadow .35s;
}
.eight { font: 900 calc(var(--size) * .26) / 1 system-ui, sans-serif; color: #000; transition: opacity .25s, transform .35s; }
.tri {
  position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transform: scale(.6) rotate(-8deg);
  transition: opacity .5s, transform .6s cubic-bezier(.2, 1.4, .4, 1);
}
.tri::before {
  content: ""; position: absolute; left: 50%; top: 46%; width: 112%; height: 100%; transform: translate(-50%, -50%);
  background: linear-gradient(180deg, var(--tri), var(--tri2));
  clip-path: polygon(50% 100%, 0 8%, 100% 8%);
  filter: drop-shadow(0 0 8px rgba(62, 242, 255, .7));
}
.answer {
  position: relative; width: 72%; margin-top: -18%; color: #dff8ff; font-weight: 800; text-transform: uppercase;
  font-size: calc(var(--size) * .043); line-height: 1.15; letter-spacing: .02em; text-shadow: 0 0 6px rgba(62, 242, 255, .9);
}
.answer.long { font-size: calc(var(--size) * .036); }

.ball.show .window { background: radial-gradient(circle, #05082a, #000 70%); box-shadow: inset 0 0 0 4px #10163f, 0 0 26px rgba(62, 242, 255, .45); }
.ball.show .eight { opacity: 0; transform: scale(.4); }
.ball.show .tri { opacity: 1; transform: none; }
.ball.thinking .window { background: radial-gradient(circle, #05082a, #000 70%); }
.ball.thinking .eight { opacity: 0; }

.ball.shake { animation: shake .9s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  10% { transform: translate(-14px, 6px) rotate(-7deg); }
  25% { transform: translate(14px, -8px) rotate(6deg); }
  40% { transform: translate(-12px, 4px) rotate(-5deg); }
  55% { transform: translate(10px, -4px) rotate(4deg); }
  70% { transform: translate(-6px, 2px) rotate(-2deg); }
  85% { transform: translate(3px, 0) rotate(1deg); }
}

/* Ask form */
.ask { display: flex; gap: 8px; width: min(100%, 460px); }
.ask input {
  flex: 1; min-width: 0; padding: 14px 16px; border-radius: 14px; border: 2px solid rgba(139, 92, 255, .6);
  background: rgba(10, 8, 26, .85); color: var(--ink); font: inherit; font-size: 17px;
}
.ask input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(62, 242, 255, .25); }
.ask input::placeholder { color: #6f6995; }
.ask button {
  padding: 0 22px; border-radius: 14px; border: 0; font: 900 17px system-ui, sans-serif; letter-spacing: .08em; cursor: pointer;
  color: #08051a; background: linear-gradient(135deg, var(--cyan), var(--pink)); box-shadow: 0 0 18px rgba(255, 79, 216, .45);
}
.ask button:disabled { opacity: .55; cursor: wait; }
.hint { margin: 0; color: var(--dim); min-height: 1.4em; }
.fine { margin: 0; color: #6f6995; font-size: 12.5px; max-width: 40ch; }

@media (prefers-reduced-motion: reduce) {
  .ball.shake { animation: none; }
  .tri, .eight, .window { transition: none; }
}

/* Spanish name is just "Bola Mágica": hide the 8 in the title. */
html[lang=es] h1 span { display: none; }
