:root {
  color-scheme: dark;
  --bg: #0b0c12;
  --bg2: #141624;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.1);
  --stroke: rgba(255, 255, 255, 0.14);
  --ink: #f4f1ea;
  --muted: #a7a8b4;
  --amber: #ffb547;
  --amber2: #ffd38a;
  --violet: #8b5cf6;
  --board: #07080b;
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 700px at 20% -10%, #2a1b4d 0%, transparent 60%),
              radial-gradient(900px 600px at 110% 10%, #10303a 0%, transparent 55%), var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.playing { overflow: hidden; overscroll-behavior: none; }
a { color: var(--amber2); }
button { font: inherit; color: inherit; }
.loading { padding: 40vh 16px 0; padding-top: 40svh; text-align: center; color: var(--muted); }

/* Menus */
.page { max-width: 1040px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-right)) max(48px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.bar { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.bar .spacer { flex: 1; }
.wordmark { font-size: clamp(30px, 6vw, 44px); font-weight: 750; letter-spacing: -1.2px; margin: 18px 0 2px;
  background: linear-gradient(100deg, #fff 0%, #ffe2a8 40%, #c4b5fd 75%, #7dd3fc 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { color: var(--muted); margin: 0 0 22px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--panel);
  border: 1px solid var(--stroke); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip .bottle { width: 14px; height: 18px; display: inline-block; background: linear-gradient(180deg, var(--amber2), var(--amber));
  clip-path: polygon(35% 0, 65% 0, 65% 22%, 100% 40%, 100% 100%, 0 100%, 0 40%, 35% 22%); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid var(--stroke); background: var(--panel); cursor: pointer; text-decoration: none; color: var(--ink);
  font-weight: 600; transition: background .15s, transform .15s; }
.btn:hover { background: var(--panel2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #ffc76a, var(--amber)); color: #1d1406; border-color: transparent; }
.btn.primary:hover { background: linear-gradient(180deg, #ffd38a, #ffbe5a); }
.btn[disabled] { opacity: .45; cursor: default; }
.icon-btn { min-width: 44px; padding: 10px 12px; }
h2 { font-size: 22px; letter-spacing: -.4px; margin: 28px 0 12px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.card { position: relative; display: block; border-radius: var(--radius); overflow: hidden; background: var(--panel);
  border: 1px solid var(--stroke); color: var(--ink); text-decoration: none; cursor: pointer; text-align: left; padding: 0; width: 100%; }
.card:hover { border-color: rgba(255, 255, 255, .28); }
.card .art { aspect-ratio: 4 / 5; width: 100%; display: block; object-fit: cover; background: #111; }
.card .art.square { aspect-ratio: 1; }
.card .art.locked { filter: blur(14px) brightness(.55) saturate(.8); transform: scale(1.12); }
svg.ph { display: block; width: 100%; height: 100%; }
.card svg.art { height: auto; }
.hero .locked { filter: blur(14px) brightness(.55) saturate(.8); transform: scale(1.12); }
.next-art { width: 72px; height: 72px; border-radius: 12px; }
.next-art svg { filter: blur(6px) brightness(.55); transform: scale(1.2); }
.card .body { padding: 12px 14px 14px; position: relative; background: linear-gradient(180deg, rgba(11, 12, 18, .0), rgba(11, 12, 18, .9) 30%); }
.card .title { font-weight: 700; font-size: 18px; letter-spacing: -.3px; }
.card .meta { color: var(--muted); font-size: 14px; }
.card .lock { position: absolute; top: 10px; right: 10px; }
.artbox { overflow: hidden; position: relative; }
.progress { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .1); margin-top: 8px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--amber), var(--amber2)); }
.stars { color: var(--amber); letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: rgba(255, 255, 255, .22); }
.hero { display: grid; grid-template-columns: minmax(0, 240px) 1fr; gap: 20px; align-items: center; margin: 8px 0 8px; }
.hero .artbox { border-radius: var(--radius); }
.hero img, .hero svg { width: 100%; border-radius: var(--radius); aspect-ratio: 4 / 5; object-fit: cover; display: block; }
.hero h1 { margin: 0 0 6px; font-size: clamp(28px, 5vw, 40px); letter-spacing: -1px; }
.hero p { color: var(--muted); margin: 0 0 12px; }
@media (max-width: 560px) { .hero { grid-template-columns: 110px 1fr; gap: 14px; } .hero p { font-size: 14px; } }
.packs { display: grid; gap: 12px; }
.pack { display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; align-items: center; padding: 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--stroke); color: var(--ink); text-decoration: none; cursor: pointer; width: 100%; text-align: left; }
.pack:hover { border-color: rgba(255, 255, 255, .28); }
.pack .name { font-weight: 700; font-size: 17px; }
.pack .strip { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.pack .strip span { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #111; }
.pack .strip img, .pack .strip svg { width: 100%; height: 100%; object-fit: cover; display: block; }
.pack .strip .teaser { filter: blur(6px) brightness(.5); transform: scale(1.2); }
.pack.locked { opacity: .78; }
.dots { display: inline-flex; gap: 3px; vertical-align: middle; margin-left: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, .18); }
.dots i.on { background: var(--amber); }
.note { color: var(--muted); font-size: 14px; }
.foot { margin-top: 36px; display: flex; flex-wrap: wrap; gap: 10px; }
.credits h3 { margin: 26px 0 8px; }
.credits ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.credits li { font-size: 14px; color: var(--muted); padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, .03); overflow-wrap: anywhere; }
.credits li b { color: var(--ink); font-weight: 600; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--stroke); margin: 8px 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--amber); }

/* Modal */
.modal-wrap { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(4, 4, 8, .6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.modal { width: min(440px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; background: #171927; border: 1px solid var(--stroke); border-radius: 20px; padding: 20px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.modal h3 { margin: 0 0 8px; font-size: 21px; }
.modal p { color: var(--muted); margin: 0 0 12px; }
.modal .actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; }
.modal ul { padding-left: 20px; color: var(--muted); }
.modal li { margin: 6px 0; }

/* Puzzle */
/* All four safe areas (notch, home bar, landscape sides); no double-tap zoom while playing. */
.play { position: fixed; inset: 0; display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); touch-action: manipulation; }
html.playing { overscroll-behavior: none; }
.topbar { display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 12px 8px; min-height: 56px; }
.topbar .t { flex: 1; min-width: 0; }
.topbar .t h1 { display: block; margin: 0; font-size: 15px; font-weight: 700; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .t span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage { position: relative; flex: 1; min-height: 0; }
.board { position: absolute; border-radius: 14px; background: var(--board); border: 1px solid var(--stroke); overflow: hidden; touch-action: none; }
.board > .inner { position: absolute; left: 1px; top: 1px; overflow: hidden; border-radius: 13px; }
.board .layer, .board .full, .board .sweep { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.board .guide { position: absolute; left: 0; top: 0; width: 100%; height: 100%; transition: opacity .4s; pointer-events: none; }
/* The guide photo at exactly the board's size, a little less saturated (PuzzleStyle.guideSaturation). */
.board .guide-layer { position: absolute; left: 0; top: 0; width: 100%; height: 100%; filter: saturate(.75); transition: opacity .6s; }
.board .guide-layer.fading { opacity: 0; }
.board canvas { pointer-events: none; }
.board .full { opacity: 0; transition: opacity .5s; pointer-events: none; }
.board .sweep { opacity: 0; pointer-events: none; background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .55) 48%, rgba(255, 226, 168, .35) 52%, transparent 70%);
  background-size: 300% 100%; mix-blend-mode: plus-lighter; }
.board .sweep.go { animation: sweep .9s ease-in-out forwards; }
@keyframes sweep { 0% { opacity: 1; background-position: 100% 0; } 100% { opacity: 1; background-position: -50% 0; } }
.crate { position: absolute; overflow: auto; border-radius: 14px; background: rgba(255, 255, 255, .035); border: 1px solid rgba(255, 255, 255, .08);
  scrollbar-width: thin; overscroll-behavior: contain; }
.crate.h { touch-action: pan-x; display: grid; grid-auto-flow: column; align-content: center; padding: 6px; }
.crate.v { touch-action: pan-y; display: grid; align-content: start; padding: 8px; }
.slot { position: relative; cursor: grab; }
.slot canvas { position: absolute; left: 0; top: 0; transition: transform .18s ease-out; }
.overlay { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
.overlay canvas { position: absolute; left: 0; top: 0; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .55)); will-change: transform; }
.overlay canvas.fly { transition: transform .2s cubic-bezier(.2, .8, .3, 1.15); }
.overlay canvas.back { transition: transform .2s ease-out; }
.toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; background: rgba(23, 25, 39, .95);
  border: 1px solid var(--stroke); padding: 10px 16px; border-radius: 12px; font-size: 14px; pointer-events: none; transition: opacity .3s; }
.hint-shard { animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 181, 71, 0)); } 50% { filter: drop-shadow(0 0 10px rgba(255, 181, 71, .95)); } }
.result { position: fixed; left: 50%; bottom: 0; transform: translate(-50%, 110%); width: min(520px, 100%); z-index: 45; background: #171927;
  border: 1px solid var(--stroke); border-bottom: 0; border-radius: 22px 22px 0 0; padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  transition: transform .45s cubic-bezier(.2, .8, .2, 1); max-height: 88vh; max-height: 88dvh; overflow: auto; box-shadow: 0 -20px 60px rgba(0, 0, 0, .5); }
.result.show { transform: translate(-50%, 0); }
.result h3 { margin: 0; font-size: 24px; letter-spacing: -.5px; }
.result .bigstars { font-size: 34px; color: var(--amber); letter-spacing: 4px; margin: 6px 0; }
.result .bigstars span { display: inline-block; opacity: 0; transform: scale(.4); transition: opacity .3s, transform .35s cubic-bezier(.3, 1.6, .5, 1); }
.result .bigstars span.on { opacity: 1; transform: none; }
.result .bigstars span.dim { color: rgba(255, 255, 255, .2); }
.result .rows { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 15px; margin: 10px 0; }
.result .rows span:nth-child(odd) { color: var(--muted); }
.result .credit { font-size: 13px; color: var(--muted); margin: 10px 0 0; overflow-wrap: anywhere; }
.result .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.result .actions .btn { flex: 1; }
@media (prefers-reduced-motion: reduce) {
  .slot canvas, .overlay canvas.fly, .overlay canvas.back, .result, .board .full { transition-duration: .01s; }
  .board .sweep.go, .hint-shard { animation: none; }
  /* The stars show at once, without the pop. */
  .result .bigstars span { transition: none; transform: none; }
}
h1:focus { outline: none; }
.pack.next { grid-template-columns: 72px 1fr auto; }
@media (max-width: 520px) { .pack.next { grid-template-columns: 64px 1fr; } .pack.next > .btn { grid-column: 1 / -1; } }
.boosters { display: flex; gap: 8px; padding: 0 12px 6px; overflow-x: auto; scrollbar-width: none; }
.btn.booster { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 999px; white-space: nowrap; }
.btn.booster .count { display: inline-flex; align-items: center; gap: 4px; margin-left: 4px; padding: 1px 8px; border-radius: 999px; background: rgba(255, 255, 255, .1); font-variant-numeric: tabular-nums; }
.btn.booster .bottle { width: 9px; height: 12px; display: inline-block; background: linear-gradient(180deg, var(--amber2), var(--amber)); clip-path: polygon(35% 0, 65% 0, 65% 22%, 100% 40%, 100% 100%, 0 100%, 0 40%, 35% 22%); }
.btn.booster.armed { border-color: var(--amber); box-shadow: 0 0 0 2px rgba(255, 181, 71, .35); }
.note.warn { color: var(--amber2); }
.modal .summary { color: var(--ink); font-weight: 650; }
.notice { position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 60; width: min(520px, calc(100% - 24px));
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 14px; background: #171927; border: 1px solid var(--amber); box-shadow: 0 20px 50px rgba(0, 0, 0, .5); }
.notice p { margin: 0; flex: 1; font-size: 14px; }
.stage-msg { padding: 30vh 16px 0; padding-top: 30svh; text-align: center; color: var(--muted); }
.stage-msg p { margin: 0 0 14px; }
.vh { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.btn.booster.order { margin-left: auto; }
.btn.booster.order.on { border-color: var(--amber); color: var(--amber2); }
/* Free help: the empty cells breathe three times, then stay softly lit (BoardFreeHelpLayer). */
.board canvas.help { opacity: 0; transition: opacity .5s; }
.board canvas.help.on { opacity: .7; }
.board canvas.help.breathe { animation: breathe 3.2s ease-in-out 3; }
@keyframes breathe { 0%, 100% { opacity: .7; } 40% { opacity: .25; } 75% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .board canvas.help.breathe { animation: none; } }
/* Keyboard focus in the crate. */
.slot:focus { outline: none; }
.slot:focus-visible { outline: 2px solid var(--amber); outline-offset: -4px; border-radius: 10px; }
/* Narrow phones: the booster pills shrink so all of them and the order switch fit. */
.btn.booster { flex: 0 1 auto; min-width: 0; }
@media (max-width: 400px) {
  .boosters { gap: 5px; padding: 0 8px 6px; }
  .btn.booster { padding: 5px 8px; font-size: 13px; gap: 4px; }
  .btn.booster .count { margin-left: 1px; padding: 1px 6px; gap: 3px; }
  .btn.booster.order .long { display: none; }
}
@media (max-width: 340px) {
  .btn.booster { padding: 5px 6px; font-size: 12px; }
}
/* Old browsers that never start the game get a note after 10 s (no script needed). */
.loading .slow { display: block; max-width: 420px; margin: 12px auto 0; opacity: 0; animation: reveal .4s ease 10s forwards; }
@keyframes reveal { to { opacity: 1; } }
.notice.failure { flex-wrap: wrap; justify-content: flex-end; }
.notice.failure p { flex-basis: 100%; }
.wordmark.small { font-size: 34px; }
.grid.photos { grid-template-columns: repeat(auto-fill, minmax(min(46%, 200px), 1fr)); }
/* A booster key armed to buy says what that would put out of reach ("Pack 3 needs 25"), under the key. */
.play > .booster-note { position: absolute; z-index: 35; margin: 0; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650;
  white-space: nowrap; color: var(--amber2); background: rgba(23, 25, 39, .96); border: 1px solid var(--amber); pointer-events: none; }
.play > .booster-note[hidden] { display: none; }
/* Not enough glue: the key shakes once and says how much is missing. */
.btn.booster.short { animation: shake .42s linear; }
@keyframes shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@media (prefers-reduced-motion: reduce) { .btn.booster.short { animation: none; } }
/* A milestone's light sweep over the placed shards, lighter where it passes. */
.board canvas.milestone { mix-blend-mode: plus-lighter; }
/* Finished photos on a pack page offer free play from a round key on their card. */
.photo-item { position: relative; }
.photo-item .again { position: absolute; top: 6px; right: 6px; min-width: 44px; min-height: 44px; padding: 0; border-radius: 999px;
  background: rgba(11, 12, 18, .72); font-size: 18px; }
.modal .sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; margin: 4px 0 0; }
