:root {
  color-scheme: dark;
  --ink: #f6f1ff;
  --muted: #cbbfe6;
  --violet: #b9a2ec;
  --violet-strong: #9d7cf0;
  --amber: #ffb45e;
  --glass: rgba(24, 16, 44, .42);
  --line: rgba(255, 255, 255, .16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Manrope, system-ui, sans-serif;
  background: #1b1433;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { background: #1b1433; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid #e2d3ff; outline-offset: 4px; }
svg { display: block; }

#arena { position: fixed; inset: 0; overflow: hidden; isolation: isolate; touch-action: none; outline: none; }
#scene, .shade, #hurt { position: absolute; inset: 0; pointer-events: none; }
#scene canvas { width: 100%; height: 100%; display: block; }
.shade { background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(12, 6, 26, .55)); transition: background .4s; }
body:is([data-state=ready], [data-state=loading], [data-state=over], [data-state=paused], [data-state=error]) .shade {
  background: radial-gradient(120% 90% at 50% 45%, rgba(12, 6, 26, .05) 30%, rgba(12, 6, 26, .7)), linear-gradient(0deg, rgba(12, 6, 26, .6), transparent 45%);
}
body[data-state=paused] .shade, body[data-state=over] .shade { background: rgba(14, 8, 30, .62); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
#hurt { opacity: 0; box-shadow: inset 0 0 120px rgba(255, 70, 120, .75); }
#hurt.on { animation: hurt .55s ease-out; }
@keyframes hurt { from { opacity: 1; } to { opacity: 0; } }

/* Corner controls */
.corner { position: absolute; top: calc(14px + var(--safe-top)); display: flex; gap: 10px; z-index: 4; }
.corner-left { left: 14px; }
.corner-right { right: 14px; }
.icon-button {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  color: var(--ink); text-decoration: none; transition: background .2s, opacity .2s;
}
.icon-button:hover { background: rgba(157, 124, 240, .35); }
.icon-button:disabled { opacity: 0; pointer-events: none; }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#sound[aria-pressed=true] .off, #sound[aria-pressed=false] .on { display: none; }

/* HUD */
.hud { position: absolute; top: calc(12px + var(--safe-top)); left: 50%; transform: translateX(-50%); display: grid; justify-items: center; gap: 8px; pointer-events: none; opacity: 0; transition: opacity .3s; }
body[data-state=playing] .hud { opacity: 1; }
#score { font-size: 38px; font-weight: 700; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; text-shadow: 0 2px 18px rgba(20, 8, 40, .6); }
.gauge { display: flex; align-items: center; gap: 7px; }
.gauge svg { width: 16px; height: 16px; fill: var(--amber); filter: drop-shadow(0 0 6px rgba(255, 160, 80, .8)); }
.track { width: 132px; height: 7px; border-radius: 7px; background: rgba(20, 10, 40, .5); border: 1px solid rgba(255, 255, 255, .14); overflow: hidden; }
#flame { display: block; height: 100%; width: 100%; transform-origin: left; border-radius: 7px; background: linear-gradient(90deg, #ff5a3c, #ffab55 55%, #fff1c6); box-shadow: 0 0 12px rgba(255, 150, 70, .8); transition: transform .12s linear; }
.gauge.low svg, .gauge.low #flame { animation: low .5s ease-in-out infinite alternate; }
@keyframes low { to { opacity: .35; } }
.chain { font-size: 12px; font-weight: 800; letter-spacing: .14em; padding: 5px 11px; border-radius: 20px; color: #0f2b3a; background: linear-gradient(90deg, #aef4ff, #e7fbff); box-shadow: 0 0 18px rgba(120, 220, 255, .7); }
.chain.bump { animation: bump .3s ease-out; }
@keyframes bump { 40% { transform: scale(1.25); } }

#popups { position: absolute; left: 50%; top: 57%; width: 0; height: 0; pointer-events: none; }
.popup { position: absolute; left: 0; top: 0; transform: translate(-50%, 0); white-space: nowrap; font-weight: 800; font-size: 20px; letter-spacing: .06em; animation: rise .9s cubic-bezier(.2, .7, .3, 1) forwards; text-shadow: 0 0 14px currentColor; }
.popup.drift { color: #bff6ff; font-size: 24px; }
.popup.hit { color: #ff8fb1; }
.popup.shard { color: #ffd694; font-size: 15px; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } to { opacity: 0; transform: translate(-50%, -70px) scale(1); } }
.toast { position: absolute; left: 0; right: 0; top: 26%; margin: 0; text-align: center; font-size: 13px; font-weight: 700; letter-spacing: .32em; text-transform: uppercase; color: #fff; text-shadow: 0 0 20px rgba(200, 170, 255, .9); opacity: 0; pointer-events: none; }
.toast.on { animation: toast 2.6s ease forwards; }
@keyframes toast { 15%, 70% { opacity: 1; letter-spacing: .4em; } to { opacity: 0; letter-spacing: .5em; } }

/* Screens */
.screen { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; text-align: center; padding: calc(70px + var(--safe-top)) 22px calc(26px + var(--safe-bottom)); animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }
.title-screen { justify-content: space-between; }
.over-screen, .pause-screen, #failure { justify-content: center; gap: 14px; }
.brand-block { display: grid; justify-items: center; }
.emblem { width: 74px; height: 130px; margin-bottom: 4px; filter: drop-shadow(0 0 22px rgba(170, 120, 255, .55)); }
.emblem-fire { transform-origin: 480px 258px; animation: flicker .18s ease-in-out infinite alternate; }
@keyframes flicker { to { transform: scaleY(.86) scaleX(1.06); } }
h1 { margin: 0; font-size: clamp(54px, 15vw, 104px); font-weight: 600; line-height: .95; letter-spacing: -.07em; text-shadow: 0 6px 40px rgba(30, 10, 70, .55); }
h1 em { font-style: normal; background: linear-gradient(100deg, #c9b3ff, #9d7cf0 60%, #d7a6ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { margin: 12px 0 0; font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.action-block { display: grid; justify-items: center; gap: 18px; width: 100%; }
.play-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px; min-width: 220px; padding: 18px 34px; border: 0; border-radius: 999px;
  background: linear-gradient(135deg, #fff3dd, #ffc27a 45%, #ff8f5a); color: #2a1426; font-size: 18px; font-weight: 800; letter-spacing: .02em;
  box-shadow: 0 10px 40px rgba(255, 140, 80, .45), inset 0 1px 0 rgba(255, 255, 255, .7); transition: transform .15s, box-shadow .2s;
}
.play-button svg { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
#again svg { fill: none; stroke-width: 2.6; stroke-linecap: round; }
.play-button:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 14px 50px rgba(255, 140, 80, .6); }
.play-button:active { transform: scale(.97); }
.play-button:disabled { opacity: .6; cursor: progress; }
.title-screen .play-button:not(:disabled) { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { box-shadow: 0 10px 60px rgba(255, 150, 90, .75), inset 0 1px 0 rgba(255, 255, 255, .7); } }
.hints { list-style: none; margin: 0; padding: 0; display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; font-size: 12px; font-weight: 600; color: var(--muted); }
.hints li { display: flex; align-items: center; gap: 7px; }
.hints i { width: 16px; height: 16px; border-radius: 50%; display: inline-block; }
.hint-drag { border: 2px solid #e8dcff; box-shadow: 0 0 0 4px rgba(232, 220, 255, .18); }
.hint-shard { background: #ffcf7d; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); box-shadow: 0 0 10px #ffb45e; border-radius: 0 !important; }
.hint-drift { background: linear-gradient(90deg, transparent 45%, #aef4ff 45% 60%, transparent 60%), linear-gradient(#ff7fd0, #ff7fd0) left/5px 100% no-repeat; border-radius: 2px !important; }
.mouse-only { display: none; }
@media (hover: hover) and (pointer: fine) { .mouse-only { display: inline; } .touch-only { display: none; } }
.best { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.best strong { color: var(--ink); margin-left: 6px; font-variant-numeric: tabular-nums; }

.eyebrow { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: .34em; text-transform: uppercase; color: var(--amber); }
.over-screen h2, .pause-screen h2, #failure h2 { margin: 0; font-size: clamp(64px, 20vw, 120px); font-weight: 700; letter-spacing: -.06em; line-height: 1; font-variant-numeric: tabular-nums; }
.pause-screen h2, #failure h2 { font-size: clamp(44px, 12vw, 72px); }
.badge { margin: -4px 0 0; padding: 6px 14px; border-radius: 99px; font-size: 12px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; color: #2a1426; background: linear-gradient(90deg, #ffe3a8, #ffb45e); box-shadow: 0 0 24px rgba(255, 180, 94, .6); animation: bump .6s ease-out; }
.stats { margin: 0 0 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.stats b { color: var(--ink); font-weight: 700; }
.board { width: min(100%, 340px); display: grid; gap: 8px; }
.board-rank { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.board-rank b { color: var(--amber); font-variant-numeric: tabular-nums; }
.board-list { list-style: none; margin: 0; padding: 6px; display: grid; gap: 2px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--muted); }
.board-list li { display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; padding: 5px 10px; border-radius: 9px; text-align: left; }
.board-list li span:last-child { color: var(--ink); font-variant-numeric: tabular-nums; }
.board-list li.me { background: rgba(255, 180, 94, .18); color: var(--ink); }
.board-you { margin: 0; font-size: 12px; color: var(--muted); }
.board-you b { color: var(--ink); }
.more { margin-top: 18px; width: min(100%, 420px); display: grid; gap: 10px; }
.more > p { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.more-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.more-row a { display: grid; gap: 6px; text-decoration: none; font-size: 11px; font-weight: 600; color: var(--muted); }
.more-row img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #2a2046; transition: transform .2s, border-color .2s; }
.more-row a:hover img { transform: translateY(-3px); border-color: var(--violet); }
.text-link { font-size: 13px; font-weight: 700; color: var(--violet); text-underline-offset: 4px; }
.toggles { display: flex; gap: 10px; }
.pill { padding: 11px 18px; border-radius: 99px; border: 1px solid var(--line); background: var(--glass); font-size: 13px; font-weight: 700; }
.pill[aria-pressed=true] { background: rgba(157, 124, 240, .4); border-color: var(--violet); }

body[data-state=playing] #arena { cursor: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.no-script { position: fixed; inset: 40% 10% auto; text-align: center; }

@media (min-width: 900px) {
  .screen { padding-top: calc(64px + var(--safe-top)); }
  .emblem { width: 88px; height: 154px; }
  .tagline { font-size: 17px; }
  .hints { font-size: 13px; gap: 26px; }
  #score { font-size: 44px; }
  .track { width: 170px; }
  #popups { top: 60%; }
}
/* Short landscape phones: keep everything on screen. */
@media (max-height: 560px) {
  .screen { padding-top: calc(12px + var(--safe-top)); padding-bottom: calc(12px + var(--safe-bottom)); }
  .emblem { width: 44px; height: 76px; }
  h1 { font-size: 52px; }
  .tagline { margin-top: 6px; font-size: 13px; }
  .action-block { gap: 10px; }
  .play-button { padding: 13px 28px; font-size: 16px; }
  .over-screen, .pause-screen { gap: 8px; }
  .over-screen h2 { font-size: 60px; }
  .more { margin-top: 4px; }
  .more-row, .board-list { display: none; }
  #score { font-size: 30px; }
}
@media (prefers-reduced-motion: reduce) {
  .emblem-fire, .title-screen .play-button, .gauge.low svg, .gauge.low #flame { animation: none !important; }
}
/* ?cover: clean key art for catalogue cards and link previews. */
.cover-shot .corner, .cover-shot .action-block { display: none !important; }
.cover-shot .title-screen { justify-content: flex-start; padding-top: 5vh; }
