/* AI Work 2048 (/ai-work-2048): the cupcakes' game.css in another skin.
   Each tile's --tile-bg and --ring come from the page (src/site/ai-work.ts);
   every merge eats a cupcake; from 64 up ai-work.js adds a moment of its
   own, and Floatboat (2048) a full-screen finale. */

/* ---- the AI Work design tokens ----
   One set of colors for everything on the page: the page, the board, the
   overlays, and the arcade kit's dialogs (the share sheet, the offers),
   which sit on <body> outside the page's <main>, so the tokens go on the
   root of a document that has the page. game.css's cupcake tokens (cream,
   cocoa, berry, butter) are mapped onto them, so no rule of the cupcakes'
   look shows here; 2048 Cupcakes' own pages never match :has(.skin-ai). */

:root:has(.skin-ai) {
  --aw-bg: #f3f6fc;
  --aw-bg-dot: rgba(59, 108, 246, 0.1);
  --aw-surface: #ffffff;
  --aw-surface-2: #e9eefa;
  --aw-ink: #1f2a44;
  --aw-ink-soft: #56627e;
  --aw-primary: #3b6cf6;
  --aw-primary-strong: #2a50c8;
  --aw-primary-soft: #c9d7ff;
  --aw-violet: #7c5cff;
  --aw-success: #0f9f75;
  --aw-success-strong: #0b7655;
  --aw-success-soft: #d6f4e9;
  --aw-highlight: #e4ecff;
  --aw-line: #d9e1f1;
  --aw-board: #1d2742;
  --aw-board-cell: #2b3758;
  --aw-board-shadow: #10172a;
  --aw-scrim: rgba(16, 23, 42, 0.58);

  /* game.css */
  --cream: var(--aw-bg);
  --paper: var(--aw-surface);
  --cocoa: var(--aw-ink);
  --cocoa-soft: var(--aw-ink-soft);
  --tray: var(--aw-board);
  --tray-cell: var(--aw-board-cell);
  --berry: var(--aw-primary);
  --berry-dark: var(--aw-primary-strong);
  --berry-ink: var(--aw-primary-strong);
  --mint: var(--aw-success-soft);
  --butter: var(--aw-highlight);
  --line: var(--aw-line);
  /* the arcade kit's dialogs, share sheet and badge */
  --arcade-ink: var(--aw-ink);
  --arcade-paper: var(--aw-surface);
  --arcade-accent: var(--aw-primary);
  --arcade-line: var(--aw-line);
  --arcade-badge: var(--aw-success);
  --arcade-ink-soft: var(--aw-ink-soft);
  --arcade-accent-strong: var(--aw-primary-strong);
  --arcade-accent-soft: var(--aw-highlight);
  --arcade-scrim: var(--aw-scrim);
  --arcade-shadow: 0 24px 60px rgba(16, 23, 42, 0.36), 0 0 0 1px var(--aw-line);
  /* this file */
  --sky: var(--aw-highlight);
  --ai-ink: var(--aw-ink);
}

/* the site's nav takes its colors inline from the layout */
:root:has(.skin-ai) [data-site-nav] {
  --arcade-nav-ink: var(--aw-ink) !important;
  --arcade-nav-paper: var(--aw-surface) !important;
  --arcade-nav-accent: var(--aw-primary) !important;
  --arcade-nav-line: var(--aw-line) !important;
}

/* the few colors game.css writes out instead of naming a token */
:root:has(.skin-ai) body {
  background:
    radial-gradient(circle, var(--aw-bg-dot) 1.2px, transparent 1.8px) 0 0 / 22px 22px,
    var(--aw-bg);
}
:root:has(.skin-ai) :focus-visible { outline-color: var(--aw-primary); }
.skin-ai .shop-title span {
  color: var(--aw-primary);
  background: var(--aw-highlight);
  box-shadow: 0 4px 0 var(--aw-primary-soft);
}
.skin-ai .board {
  box-shadow: 0 8px 0 var(--aw-board-shadow), 0 18px 36px rgba(16, 23, 42, 0.28);
}
.skin-ai .overlay { background: var(--aw-scrim); }
.skin-ai .sizes { background: var(--aw-surface-2); }
.skin-ai .stat-badge { box-shadow: 0 2px 0 var(--aw-success-strong); }
.skin-ai .undo-note { color: var(--aw-success-strong); }
.skin-ai .book-list li.is-baked { background: var(--aw-highlight); }
.skin-ai .tile-4096 { --ring: var(--aw-violet); --tile-bg: #ece6ff; }
.skin-ai .tile-8192 { --ring: var(--aw-success); --tile-bg: var(--aw-success-soft); }

.skin-ai .tile { container-type: inline-size; }
.skin-ai .tile-face { background: var(--tile-bg, #fff); }
.skin-ai .tile-face img { transform: scale(1.04); }
.skin-ai .tile-value { color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }

/* ---- every merge: a cupcake flies in and gets eaten ---- */

.skin-ai .tile.is-merged .tile-face {
  animation: ai-chomp 380ms cubic-bezier(0.3, 1.5, 0.5, 1) 90ms backwards;
}

@keyframes ai-chomp {
  0% { transform: scale(0.72); }
  35% { transform: scale(1.12) scaleY(0.9); }
  55% { transform: scale(0.96) scaleY(1.06); }
  75% { transform: scale(1.04); }
  100% { transform: none; }
}

.skin-ai .tile.is-merged::before {
  content: "🧁";
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  font-size: 34cqi;
  line-height: 1;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  animation: ai-cupcake 420ms ease-in 60ms;
}

@keyframes ai-cupcake {
  0% { opacity: 1; transform: translate(-50%, -190%) scale(1.1) rotate(-12deg); }
  70% { opacity: 1; transform: translate(-50%, -40%) scale(0.75) rotate(8deg); }
  100% { opacity: 0; transform: translate(-50%, -10%) scale(0.1); }
}

/* ---- 64 and up: one moment per level, over the board ---- */

.ai-fx {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  overflow: visible;
}

.fx {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.fx-hero {
  width: 46%;
  aspect-ratio: 1;
  border-radius: 22px;
  box-shadow: 0 0 0 5px var(--fx-ring, #fff), 0 14px 30px rgba(0, 0, 0, 0.28);
  background: var(--fx-bg, #fff);
}

.fx-caption {
  position: absolute;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
  font-weight: 900;
  font-size: clamp(14px, 3.6vw, 20px);
  color: var(--ai-ink);
  background: #fff;
  box-shadow: 0 0 0 3px var(--fx-ring, #fff);
}

.fx .fx-hero { animation: fx-pop 1500ms cubic-bezier(0.3, 1.4, 0.5, 1) both; }
.fx .fx-caption { animation: fx-caption 1500ms ease both; }

@keyframes fx-pop {
  0% { transform: scale(0.2); opacity: 0; }
  18% { transform: scale(1.05); opacity: 1; }
  80% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.6); opacity: 0; }
}

@keyframes fx-caption {
  0%, 10% { opacity: 0; transform: translate(-50%, 12px); }
  22%, 82% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

.fx-bit {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px;
  border-radius: 50%;
  background: var(--bit, #fff);
  opacity: 0;
}

/* 64 Manus: the hand waves hello and high-fives the board */
.fx-64 .fx-hero { animation: fx-pop 1500ms cubic-bezier(0.3, 1.4, 0.5, 1) both, fx-wave 500ms ease-in-out 250ms 2 alternate; }
@keyframes fx-wave { from { rotate: -14deg; } to { rotate: 14deg; } }
.fx-64 .fx-bit {
  width: 60%;
  height: auto;
  aspect-ratio: 1;
  margin: 0;
  left: 20%;
  top: 20%;
  background: none;
  border: 6px solid var(--fx-ring);
  animation: fx-ring 900ms ease-out calc(var(--i) * 160ms + 300ms);
}
@keyframes fx-ring { from { opacity: 0.9; transform: scale(0.4); } to { opacity: 0; transform: scale(1.5); } }

/* 128 DSH: the whale dives in and splashes the whole board */
.fx-128 .fx-hero { animation: fx-pop 1500ms cubic-bezier(0.3, 1.4, 0.5, 1) both, fx-dive 700ms ease-in-out 200ms; }
@keyframes fx-dive { 50% { translate: 0 18%; rotate: 10deg; } }
.fx-128 .fx-bit { --bit: #6f8dff; animation: fx-splash 900ms ease-out calc(var(--i) * 40ms + 450ms); }
@keyframes fx-splash {
  0% { opacity: 1; transform: translate(0, 0) scale(0.6); }
  60% { opacity: 1; transform: translate(calc(var(--dx) * 1px), calc(var(--dy) * 1px - 60px)) scale(1); }
  100% { opacity: 0; transform: translate(calc(var(--dx) * 1.3px), calc(var(--dy) * 1px + 40px)) scale(0.8); }
}

/* 256 Antigravity: everything floats up a little, rainbow bubbles rise */
.fx-256 .fx-hero { animation: fx-pop 1500ms cubic-bezier(0.3, 1.4, 0.5, 1) both, fx-float 1300ms ease-in-out; }
@keyframes fx-float { 50% { translate: 0 -14%; } }
.board.is-floating .tile { animation: fx-tiles-float 1300ms ease-in-out; }
@keyframes fx-tiles-float { 50% { margin-top: -10px; } }
.fx-256 .fx-bit { top: 95%; animation: fx-rise 1300ms ease-out calc(var(--i) * 70ms); }
@keyframes fx-rise {
  0% { opacity: 0.9; transform: translate(calc(var(--dx) * 1px), 0) scale(0.5); }
  100% { opacity: 0; transform: translate(calc(var(--dx) * 1px), -340px) scale(1.2); }
}

/* 512 Codex: a cursor scans the board and blocks of light compile */
.fx-512::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 18%;
  border-radius: 14px;
  background: linear-gradient(180deg, transparent, rgba(124, 108, 242, 0.55), transparent);
  animation: fx-scan 1100ms ease-in-out 2 alternate;
}
@keyframes fx-scan { from { transform: translateY(-20%); } to { transform: translateY(520%); } }
.fx-512 .fx-bit {
  --bit: #7c6cf2;
  width: 10px;
  height: 22px;
  margin: 0;
  border-radius: 2px;
  left: calc(10% + var(--i) * 7%);
  top: calc(12% + var(--j) * 9%);
  animation: fx-blink 300ms steps(2) calc(var(--i) * 90ms) 3;
}
@keyframes fx-blink { 0% { opacity: 1; } 100% { opacity: 0; } }

/* 1024 Claude Cowork: the finished pages fly out of her folder */
.fx-1024 .fx-bit {
  --bit: #fffaf3;
  width: 26px;
  height: 34px;
  border-radius: 3px;
  box-shadow: 0 0 0 2px #d97757, inset 0 -18px 0 -14px #f2c1a8;
  animation: fx-paper 1300ms ease-out calc(var(--i) * 60ms + 250ms);
}
@keyframes fx-paper {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(calc(var(--dx) * 1.6px), calc(var(--dy) * 1.6px)) rotate(calc(var(--dx) * 2deg)); }
}

/* ---- 2048 Floatboat: the finale, over the whole screen ---- */

.ai-finale {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  z-index: 1000;
  overflow: hidden;
  place-items: center;
  background: linear-gradient(180deg, #14234d 0%, #3657a8 55%, #8fc8f2 100%);
  color: #fff;
}

.ai-finale[open] { display: grid; }
.ai-finale::backdrop { background: transparent; }

.ai-finale-sea {
  position: absolute;
  /* wider than the screen by more than the 120px it slides, so no edge shows */
  left: -160px;
  right: -160px;
  bottom: 0;
  height: 26%;
  background:
    radial-gradient(60px 22px at 30px 0, transparent 98%, #2b8fd6 100%) 0 0 / 120px 40px repeat-x,
    linear-gradient(#2b8fd6, #1a5f9f);
  animation: ai-sea 3s linear infinite;
}
@keyframes ai-sea { to { transform: translateX(120px); } }

.ai-finale-boat {
  position: absolute;
  bottom: 14%;
  left: 0;
  width: min(46vw, 46vh, 380px);
  aspect-ratio: 1;
  border-radius: 28px;
  box-shadow: 0 0 0 6px #fff, 0 20px 40px rgba(0, 0, 0, 0.35);
  animation: ai-sail 5200ms cubic-bezier(0.4, 0, 0.6, 1) both, ai-bob 1300ms ease-in-out infinite alternate;
}
@keyframes ai-sail {
  from { transform: translateX(-110%); }
  to { transform: translateX(calc(100vw + 10%)); }
}
@keyframes ai-bob { from { margin-bottom: 0; rotate: -3deg; } to { margin-bottom: 18px; rotate: 3deg; } }

.ai-finale-title {
  position: relative;
  z-index: 2;
  margin: 0 0 30vh;
  padding: 0 16px;
  text-align: center;
  font-size: clamp(30px, 7vw, 64px);
  font-weight: 900;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  animation: fx-caption-in 700ms ease 300ms both;
}
@keyframes fx-caption-in { from { opacity: 0; transform: translateY(20px); } }

.ai-finale-close {
  position: absolute;
  z-index: 3;
  right: 16px;
  top: 16px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
  /* the finale sits on <body>, outside .skin-ai and its variables */
  color: #1f2a44;
  background: #fff;
  cursor: pointer;
}

.ai-firework {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 0;
  height: 0;
}
.ai-firework i {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px;
  border-radius: 50%;
  background: var(--c);
  opacity: 0;
  animation: ai-spark 1100ms ease-out var(--d) infinite;
  --a: calc(var(--k) * 30deg);
}
@keyframes ai-spark {
  0% { opacity: 1; transform: rotate(var(--a)) translateY(0) scale(1); }
  100% { opacity: 0; transform: rotate(var(--a)) translateY(-110px) scale(0.4); }
}

/* still, for players who asked for less motion: the moments and the finale
   show their picture and words without moving (game.css also stops every
   animation) */
.ai-finale.is-still .ai-finale-boat { left: 50%; translate: -50% 0; animation: none; }
.ai-finale.is-still .ai-finale-sea,
.ai-finale.is-still .ai-firework { display: none; }

@media (prefers-reduced-motion: reduce) {
  .skin-ai .tile.is-merged::before { display: none; }
  .fx .fx-bit, .fx-512::before { display: none; }
  .fx .fx-hero, .fx .fx-caption { animation: none !important; opacity: 1; }
}

.ai-note { margin-top: 18px; font-size: 13px; opacity: 0.75; }

/* the FAQ's link to Floatboat's site, as a button */
.skin-ai .ai-floatboat-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  color: var(--aw-surface);
  background: var(--aw-primary);
  text-decoration: none;
  box-shadow: 0 3px 0 var(--aw-primary-strong);
}
.skin-ai .ai-floatboat-link:hover { background: var(--aw-primary-strong); }

/* the agents' leaderboard (/ai-work-2048/agents) and its button */
.agents-play {
  margin: 0 auto 18px;
  max-width: 720px;
  padding: 16px 18px;
  border-radius: 18px;
  background: var(--aw-surface);
  box-shadow: inset 0 0 0 2px var(--aw-line);
}
.agents-play h2 { margin: 0 0 6px; }
.agents-steps { margin: 0 0 12px; padding-left: 1.3em; }
.agents-rules { margin: 12px 0 0; font-size: 14px; color: var(--aw-ink-soft); }
.arcade-agent-note { margin: 8px 0 0; font-weight: 800; }
.arcade-agent-prompt {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border: 2px solid var(--aw-line);
  border-radius: 12px;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--aw-ink);
  background: var(--aw-bg);
  resize: vertical;
}
.ai-agent-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 14px;
  margin: 12px 0 0;
  font-weight: 800;
}
