/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-top:    #0d0d1a;
  --bg-bot:    #1a0030;
  --gold:      #f0c040;
  --gold-dim:  #a07820;
  --purple:    #6a0dad;
  --text:      #e8e0ff;
  --hint:      #8878aa;
  --ball-dark: #050510;
  --ball-mid:  #111128;
  --window-bg: #08081e;
  --answer-clr:#c8b8ff;
  --shine:     rgba(255,255,255,0.12);
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  color: var(--text);
  overflow-x: hidden;
}

/* ── Stars background ───────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 15%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 45%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 10%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 75% 60%, rgba(255,255,255,.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 25%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 20% 80%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 65% 85%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 70%, rgba(255,255,255,.3) 0%, transparent 100%),
    radial-gradient(2px 2px at 85% 90%, rgba(255,255,255,.2) 0%, transparent 100%),
    radial-gradient(2px 2px at 5%  50%, rgba(255,255,255,.2) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ─────────────────────────────────────────────────── */
.page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 2rem 1rem;
  gap: 1.5rem;
}

/* ── Header ─────────────────────────────────────────────────── */
header { text-align: center; }

header h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: .04em;
  background: linear-gradient(135deg, var(--gold) 0%, #fff8dc 50%, var(--gold) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  filter: drop-shadow(0 0 18px rgba(240,192,64,.5));
}

.subtitle {
  margin-top: .4rem;
  font-size: .95rem;
  color: var(--hint);
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* ── Scene / Ball ───────────────────────────────────────────── */
main { display: flex; flex-direction: column; align-items: center; gap: 2rem; }

.scene {
  perspective: 800px;
}

.ball {
  width: clamp(220px, 55vw, 320px);
  height: clamp(220px, 55vw, 320px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2a2a50 0%, var(--ball-mid) 35%, var(--ball-dark) 70%);
  box-shadow:
    0 0 60px rgba(106, 13, 173, .45),
    0 0 120px rgba(106, 13, 173, .2),
    inset 0 -10px 30px rgba(0,0,0,.8),
    inset 0 10px 20px rgba(255,255,255,.04);
  position: relative;
  cursor: pointer;
  user-select: none;
  transition: transform .15s ease, box-shadow .15s ease;
  will-change: transform;
}

.ball:hover {
  box-shadow:
    0 0 80px rgba(106, 13, 173, .65),
    0 0 160px rgba(106, 13, 173, .3),
    inset 0 -10px 30px rgba(0,0,0,.8),
    inset 0 10px 20px rgba(255,255,255,.04);
  transform: scale(1.03);
}

.ball:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 6px;
}

/* ── Shine highlight ────────────────────────────────────────── */
.ball-shine {
  position: absolute;
  top: 10%;
  left: 18%;
  width: 32%;
  height: 22%;
  background: radial-gradient(ellipse, rgba(255,255,255,.25) 0%, transparent 80%);
  border-radius: 50%;
  pointer-events: none;
  transform: rotate(-30deg);
}

/* ── Inner window ───────────────────────────────────────────── */
.window {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #10103a 0%, var(--window-bg) 100%);
  border: 3px solid rgba(120, 80, 200, .4);
  box-shadow:
    0 0 20px rgba(100, 50, 200, .5),
    inset 0 2px 8px rgba(0,0,0,.9);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Triangle behind the 8 / answer */
.triangle {
  position: absolute;
  width: 0; height: 0;
  border-left:  38px solid transparent;
  border-right: 38px solid transparent;
  border-bottom: 66px solid rgba(80, 30, 160, .55);
  top: 50%; left: 50%;
  transform: translate(-50%, -42%);
  filter: drop-shadow(0 0 6px rgba(140, 80, 255, .5));
  transition: opacity .3s;
}

.answer-text {
  position: relative;
  z-index: 1;
  font-size: clamp(.7rem, 2.5vw, 1.05rem);
  font-weight: 700;
  color: var(--answer-clr);
  text-align: center;
  padding: 0 6px;
  line-height: 1.25;
  text-shadow: 0 0 10px rgba(180, 140, 255, .8);
  transition: opacity .25s ease;
  max-width: 90%;
}

/* The resting "8" state */
.answer-text.resting {
  font-size: clamp(1.8rem, 6vw, 3rem);
  color: var(--text);
  text-shadow: 0 0 20px rgba(200,180,255,.6);
}

/* ── Shake Button ───────────────────────────────────────────── */
.shake-btn {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  padding: .85rem 2.2rem;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--ball-dark);
  background: linear-gradient(135deg, var(--gold) 0%, #ffe066 50%, var(--gold) 100%);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow:
    0 4px 20px rgba(240,192,64,.5),
    0 1px 0 rgba(255,255,255,.3) inset;
  transition: transform .1s ease, box-shadow .1s ease, filter .1s ease;
  position: relative;
  overflow: hidden;
}

.shake-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,.25) 0%, transparent 60%);
  border-radius: inherit;
  pointer-events: none;
}

.shake-btn:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 8px 28px rgba(240,192,64,.65), 0 1px 0 rgba(255,255,255,.3) inset;
}

.shake-btn:active {
  transform: translateY(1px) scale(.97);
  box-shadow: 0 2px 10px rgba(240,192,64,.4);
}

.shake-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.btn-icon { font-size: 1.3rem; }

/* ── Hint ───────────────────────────────────────────────────── */
.hint {
  font-size: .82rem;
  color: var(--hint);
  letter-spacing: .04em;
  text-align: center;
  transition: opacity .4s;
}

/* ── Footer ─────────────────────────────────────────────────── */
footer {
  font-size: .78rem;
  color: var(--hint);
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════
   ANIMATIONS
═══════════════════════════════════════════════════════════════ */

/* Shake keyframes */
@keyframes shake {
  0%   { transform: translate(0, 0)    rotate(0deg)   scale(1);    }
  5%   { transform: translate(-10px, -6px) rotate(-8deg)  scale(1.04); }
  10%  { transform: translate(12px, 4px)  rotate(7deg)   scale(1.06); }
  15%  { transform: translate(-8px, 8px)  rotate(-6deg)  scale(1.04); }
  20%  { transform: translate(10px, -8px) rotate(5deg)   scale(1.06); }
  25%  { transform: translate(-12px, 4px) rotate(-7deg)  scale(1.04); }
  30%  { transform: translate(8px, 6px)   rotate(6deg)   scale(1.05); }
  35%  { transform: translate(-6px, -10px)rotate(-5deg)  scale(1.04); }
  40%  { transform: translate(10px, 8px)  rotate(4deg)   scale(1.05); }
  45%  { transform: translate(-8px, 4px)  rotate(-4deg)  scale(1.03); }
  50%  { transform: translate(6px, -6px)  rotate(3deg)   scale(1.04); }
  55%  { transform: translate(-4px, 6px)  rotate(-3deg)  scale(1.03); }
  60%  { transform: translate(5px, -4px)  rotate(2deg)   scale(1.02); }
  65%  { transform: translate(-4px, 3px)  rotate(-2deg)  scale(1.02); }
  70%  { transform: translate(3px, -3px)  rotate(1deg)   scale(1.01); }
  80%  { transform: translate(-2px, 2px)  rotate(-.5deg) scale(1.01); }
  90%  { transform: translate(1px, -1px)  rotate(.25deg) scale(1);    }
  100% { transform: translate(0, 0)    rotate(0deg)   scale(1);    }
}

/* Glow pulse while shaking */
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 60px rgba(106,13,173,.45), 0 0 120px rgba(106,13,173,.2), inset 0 -10px 30px rgba(0,0,0,.8); }
  50%       { box-shadow: 0 0 100px rgba(160,50,255,.8), 0 0 200px rgba(120,30,220,.5), inset 0 -10px 30px rgba(0,0,0,.8); }
}

/* Reveal answer fade-in */
@keyframes revealAnswer {
  0%   { opacity: 0; transform: scale(.6); }
  60%  { opacity: 1; transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}

/* Floating idle bob */
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50%       { transform: translateY(-10px); }
}

.ball.idle    { animation: float 4s ease-in-out infinite; }
.ball.shaking { animation: shake .9s ease-in-out forwards, glowPulse .9s ease-in-out; }

.answer-text.reveal {
  animation: revealAnswer .5s ease-out forwards;
}

/* ── Ripple on button click ─────────────────────────────────── */
@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

.ripple-el {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.35);
  width: 40px; height: 40px;
  margin-top: -20px; margin-left: -20px;
  animation: ripple .6s linear;
  pointer-events: none;
}

/* ── Splash / entry screen ───────────────────────────────────── */
.splash {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  transition: opacity .5s ease, visibility .5s ease;
}

.splash.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  text-align: center;
  padding: 2rem;
}

.splash-ball {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--ball-mid), var(--ball-dark) 70%);
  box-shadow: 0 0 40px rgba(106,13,173,.7), 0 0 80px rgba(106,13,173,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--gold);
  animation: float 3s ease-in-out infinite, glowPulse 3s ease-in-out infinite;
}

.splash-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: .04em;
}

.splash-sub {
  font-size: 1rem;
  color: var(--hint);
}

.splash-btn {
  margin-top: .4rem;
  padding: .9rem 2.2rem;
  font-size: 1.1rem;
  font-weight: 700;
  border: 2px solid var(--gold);
  border-radius: 50px;
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  letter-spacing: .05em;
  text-transform: uppercase;
  animation: splashPulse 1.5s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

.splash-btn:active {
  background: var(--gold);
  color: var(--bg-top);
}

@keyframes splashPulse {
  0%, 100% { box-shadow: 0 0 8px var(--gold-dim); }
  50%       { box-shadow: 0 0 22px var(--gold), 0 0 40px rgba(240,192,64,.3); }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 400px) {
  .shake-btn { padding: .75rem 1.6rem; font-size: 1rem; }
}
