:root {
  --bg: #07070D;
  --surface: #14141F;
  --surface-2: #1C1C2B;
  --line: #2C2C40;
  --text: #F4F4F8;
  --muted: #A9A9BE;
  --accent: #D4FF3A;
  --gold: #FFC21A;
  --rare: #E07BFF;
  --normal: #5CC8FF;
  --danger: #FF6A5C;
  --display: 'Dela Gothic One', 'Zen Kaku Gothic New', sans-serif;
  --num: 'Space Grotesk', 'Zen Kaku Gothic New', sans-serif;
  --body: 'Zen Kaku Gothic New', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--body); -webkit-font-smoothing: antialiased; }
body { background: radial-gradient(circle at 50% 30%, #12152A 0%, #07070D 60%); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#stage {
  position: relative; margin: 0 auto; overflow: hidden;
  width: min(100vw, calc(100dvh * .56)); height: 100dvh;
  box-shadow: 0 0 80px rgba(0, 0, 0, .6);
  user-select: none; -webkit-user-select: none;
}
#fx { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(180deg, rgba(7, 7, 13, .75) 0%, rgba(7, 7, 13, 0) 100%);
}
.eyebrow { margin: 0; font-family: var(--num); font-size: 11px; font-weight: 700; letter-spacing: .2em; color: var(--muted); }
.brand h1 { margin: 2px 0 0; font-family: var(--display); font-weight: 400; font-size: 22px; line-height: 1.2; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(20, 20, 31, .7); display: grid; place-items: center; font-size: 20px; line-height: 1;
}
.icon-btn[aria-pressed="false"] .wave { opacity: 0; }
.icon-btn[aria-pressed="false"] { color: var(--muted); }
.user { position: relative; }
.user-chip {
  height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 14px 0 8px;
  border-radius: 999px; border: 1px solid var(--line); background: rgba(20, 20, 31, .7); max-width: 180px;
}
.user-chip img { width: 28px; height: 28px; border-radius: 999px; background: var(--surface-2); object-fit: cover; }
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 700; }
.menu {
  position: absolute; right: 0; top: 52px; min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column;
}
.menu a, .menu button {
  display: block; text-align: left; padding: 12px 14px; border-radius: 10px; border: 0; background: none;
  color: var(--text); text-decoration: none; font-size: 15px; min-height: 44px;
}
.menu a:hover, .menu button:hover { background: var(--surface-2); }

.panel.bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  padding: 72px 20px max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(7, 7, 13, 0) 0%, rgba(7, 7, 13, .9) 34%, #07070D 100%);
  display: flex; flex-direction: column; gap: 12px;
}
.desc { margin: 0; font-size: 15px; line-height: 1.6; color: #D7D7E4; text-align: center; }
.status { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; line-height: 1.6; text-align: center; }
.status a { color: var(--accent); }
.cta {
  height: 64px; border: 0; border-radius: 999px; background: var(--accent); color: #0B0B12;
  font-family: var(--display); font-size: 20px; letter-spacing: .02em;
  box-shadow: 0 0 36px rgba(212, 255, 58, .45);
  transition: transform 120ms cubic-bezier(.2, .9, .1, 1);
  animation: ctaGlow 2.4s ease-in-out infinite;
}
.cta:active { transform: scale(.95); }
.cta.twitch { background: #9146FF; color: #fff; box-shadow: 0 0 36px rgba(145, 70, 255, .5); }
.cta:disabled { opacity: .5; animation: none; cursor: default; }
@keyframes ctaGlow { 0%, 100% { box-shadow: 0 0 24px rgba(212, 255, 58, .35); } 50% { box-shadow: 0 0 48px rgba(212, 255, 58, .7); } }
.cta.twitch { animation: none; }
.sub-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.link-btn { min-height: 44px; padding: 0 4px; border: 0; background: none; color: var(--text); text-decoration: underline; text-underline-offset: 4px; font-size: 14px; }
.muted { color: var(--muted); font-family: var(--num); font-size: 13px; }
.muted.center { text-align: center; }
.small { font-size: 13px; margin: 0 0 12px; }

.tear-hint {
  position: absolute; left: 0; right: 0; bottom: max(32px, env(safe-area-inset-bottom)); z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; pointer-events: none;
  animation: hintIn 400ms cubic-bezier(.2, .9, .1, 1) both;
}
.tear-hint p { margin: 0; font-size: 15px; line-height: 1.6; text-shadow: 0 2px 12px rgba(0, 0, 0, .8); }
.tear-hint strong { font-family: var(--display); font-weight: 400; font-size: 22px; }
.tear-hint .link-btn { pointer-events: auto; color: var(--muted); }
@keyframes hintIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.skip {
  position: absolute; right: 16px; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 4;
  height: 44px; padding: 0 18px; border-radius: 8px; border: 1.5px solid rgba(255, 255, 255, .85);
  background: rgba(0, 0, 0, .45); color: #fff; font-family: var(--num); font-weight: 700; font-size: 14px; letter-spacing: .12em;
}

/* Result: the card itself is drawn by the engine (tilt it by dragging); the page adds the words around it. */
.result { position: absolute; inset: 0; z-index: 3; pointer-events: none; text-align: center; }
.result-text {
  position: absolute; left: 20px; right: 20px; top: calc(37% + 153.5 * var(--u, 1px) + 10px);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.rank { margin: 0; font-family: var(--display); font-size: 50px; line-height: 1.05; color: var(--tier, var(--gold)); -webkit-text-stroke: 1.5px rgba(10, 4, 0, .85); paint-order: stroke fill; text-shadow: 0 3px 0 rgba(0, 0, 0, .55), 0 0 28px var(--glow, rgba(255, 194, 26, .6)); animation: pop 460ms cubic-bezier(.34, 1.56, .64, 1) 80ms both; }
.prize-name { margin: 4px 0 0; font-size: 19px; line-height: 1.4; text-shadow: 0 2px 10px rgba(0, 0, 0, .95); animation: rise 420ms ease-out 260ms both; }
.prize-desc { margin: 0; max-width: 320px; font-size: 14px; line-height: 1.6; color: #E6E6F0; text-shadow: 0 2px 8px rgba(0, 0, 0, .95); animation: rise 420ms ease-out 340ms both; }
.tilt-tip { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-shadow: 0 1px 6px rgba(0, 0, 0, .9); animation: rise 420ms ease-out 900ms both; }
.result-foot {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 20px max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; pointer-events: auto;
  background: linear-gradient(180deg, rgba(7, 7, 13, 0) 0%, rgba(7, 7, 13, .78) 55%);
  animation: rise 420ms ease-out 480ms both;
}
.result-actions { display: flex; gap: 10px; width: 100%; }
.result-actions .cta.again { flex: 1.4; height: 52px; font-size: 17px; }
.ghost { flex: 1; min-height: 50px; border-radius: 999px; border: 1px solid var(--line); background: rgba(20, 20, 31, .8); font-weight: 700; }
/* only when WebGL is unavailable: a plain card in the same spot */
.card {
  position: absolute; left: 50%; top: 37%; width: calc(220 * var(--u, 1px)); aspect-ratio: 220 / 307; transform: translate(-50%, -50%);
  border-radius: 13px; overflow: hidden; background: #fff; padding: 6px;
  box-shadow: 0 0 60px var(--glow, rgba(255, 194, 26, .6)), 0 24px 60px rgba(0, 0, 0, .6);
}
.card img, .card-ph { width: 100%; height: 100%; border-radius: 8px; object-fit: cover; display: block; }
.card-ph { background: linear-gradient(135deg, var(--tier, #FFC21A), #141420); display: grid; place-items: center; font-family: var(--display); font-size: 40px; color: rgba(255, 255, 255, .9); }
@keyframes pop { from { opacity: 0; transform: scale(.4); } 60% { opacity: 1; transform: scale(1.12); } to { opacity: 1; transform: scale(1); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.sheet {
  width: min(92vw, 440px); max-height: 80dvh; padding: 18px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); overflow: auto;
}
.sheet::backdrop { background: rgba(0, 0, 0, .65); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 20px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 8px; border-radius: 12px; background: var(--surface-2); }
.list img, .list .ph { width: 44px; height: 60px; border-radius: 6px; object-fit: cover; background: #2A2A3C; }
.list .r { font-family: var(--display); font-size: 15px; }
.list .n { font-size: 14px; color: #D7D7E4; }
.list .p { font-family: var(--num); font-weight: 700; font-size: 15px; }
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid li { display: flex; flex-direction: column; gap: 4px; }
.grid img, .grid .ph { width: 100%; aspect-ratio: 63 / 88; border-radius: 8px; object-fit: cover; background: #2A2A3C; }
.grid .r { font-family: var(--display); font-size: 13px; }
.grid .d { font-family: var(--num); font-size: 11px; color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 20px 0; text-align: center; grid-column: 1 / -1; }

.toast {
  position: absolute; left: 50%; top: 84px; transform: translateX(-50%); z-index: 6; max-width: 90%;
  padding: 12px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; line-height: 1.5;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
}

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