/*
 * Pixel Pets: the partner, eggs and enemies are drawn as pixel art (assets/pixel/, built by
 * tools/pixelize.py) while the rest of the game keeps its smooth 2.5D look.
 * Scoped to html[data-pets="pixel"]; Settings -> Pixel Pets switches back to the classic art.
 */

/* every pixel image keeps hard edges */
html[data-pets="pixel"] img[src*="/assets/pixel/"],
html[data-pets="pixel"] .echo-sprite,
html[data-pets="pixel"] .dex-thumb,
html[data-pets="pixel"] .selected-egg-sprite,
html[data-pets="pixel"] .egg-glyph,
html[data-pets="pixel"] .echo-mg-arena * {
  image-rendering: pixelated;
}

/* The pixel canvas is 64px; 3x (192px) makes every sprite pixel an exact 3x3 block on 2x and 3x screens */
html[data-pets="pixel"] .echo-sprite { width: 192px; height: 192px; filter: none; }
/* on a short screen (set from the scene's real height) the partner is drawn at 2x so it stands fully above the status
   panel; 128px is still an exact multiple of the 64px canvas, so the pixels stay crisp */
html[data-pets="pixel"][data-pet-size="small"] .echo-sprite { width: 128px; height: 128px; }
/* eggs are drawn on a 96px canvas, so 2x = 192px */
html[data-pets="pixel"] .selected-egg-sprite { width: 192px; height: 192px; }
html[data-pets="pixel"] .egg-glyph { width: 192px; height: 192px; max-width: none; filter: none; }

/* the classic art needs vector eyes and mouth overlays; the pixel sprites already have faces */
html[data-pets="pixel"] .echo-expression,
html[data-pets="pixel"] .pet-eyes-layer { display: none !important; }

/* handheld frame rate: movement snaps in small steps instead of gliding */
html[data-pets="pixel"] .echo-sprite { animation-timing-function: steps(18, end); }
html[data-pets="pixel"] .echo-sprite.frame-animated-pet { transition: none; }

/* evolution scene */
html[data-pets="pixel"] .ceremony-sprite-wrap { width: 192px; height: 192px; }
html[data-pets="pixel"] .ceremony-stage { width: 224px; height: 216px; }
html[data-pets="pixel"] .ceremony-sprite { width: 192px; height: 192px; max-width: none; max-height: none; image-rendering: pixelated; }

/* battles: two 2x sprites side by side */
html[data-pets="pixel"] .vpet-battle { grid-template-columns: 1fr 8px 1fr; }
html[data-pets="pixel"] .battle-unit { min-width: 0; padding-left: 0; padding-right: 0; }
html[data-pets="pixel"] .battle-pixel,
html[data-pets="pixel"] .vpet-battle.boss-battle .guardian-pixel { width: 128px; height: 128px; max-width: none; image-rendering: pixelated; filter: none !important; }
html[data-pets="pixel"] .battle-flash { display: none; }

/* the sprite is bigger than the classic art, so walks are re-timed in whole-pixel hops and kept on screen */
html[data-pets="pixel"] .echo-sprite.frame-animated-pet.idle-walk-left { animation: pixel-walk-left 2.8s steps(1, end) both; }
html[data-pets="pixel"] .echo-sprite.frame-animated-pet.idle-walk-right { animation: pixel-walk-right 2.8s steps(1, end) both; }
/* a pixel partner's picture faces left, so "turn right" turns it to face right and back, and "turn left" is a little hop (the classic art starts the other way round) */
html[data-pets="pixel"] .echo-sprite.frame-animated-pet.idle-turn-right { animation: pixel-turn-right 2.4s ease-in-out both; }
html[data-pets="pixel"] .echo-sprite.frame-animated-pet.idle-turn-left { animation: pixel-turn-left 2.4s ease-in-out both; }
/* The Hexbit line has its own waddle, written for the classic art (which faces right and is turned round to walk left). A pixel partner's
   walking pictures already face the way they walk, so the waddle keeps the hops and the squash and drops the turning round, and the
   turn on the spot is the same one the other pets do. */
html[data-pets="pixel"] .habitat:has(.echo-sprite[data-family="hexbit"]) .echo-sprite.idle-walk-left { animation: chibi-pixel-walk-left 2.6s ease-in-out both !important; }
html[data-pets="pixel"] .habitat:has(.echo-sprite[data-family="hexbit"]) .echo-sprite.idle-walk-right { animation: chibi-pixel-walk-right 2.6s ease-in-out both !important; }
html[data-pets="pixel"] .habitat:has(.echo-sprite[data-family="hexbit"]) .echo-sprite.idle-turn-right { animation: pixel-turn-right 2.4s ease-in-out both !important; }
html[data-pets="pixel"] .habitat:has(.echo-sprite[data-family="hexbit"]) .echo-sprite.idle-turn-left { animation: pixel-turn-left 2.4s ease-in-out both !important; }
@keyframes chibi-pixel-walk-left {
  0%,100% { transform: translate(-50%,-50%); }
  15%     { transform: translate(-58%,-60%) rotate(-3deg) scaleY(.95); }
  35%     { transform: translate(-80%,-46%) scaleY(.9) scaleX(1.06); }
  55%     { transform: translate(-120%,-58%) rotate(2deg); }
  75%     { transform: translate(-150%,-46%) scaleY(.9) scaleX(1.04); }
}
@keyframes chibi-pixel-walk-right {
  0%,100% { transform: translate(-50%,-50%); }
  15%     { transform: translate(-42%,-60%) rotate(3deg) scaleY(.95); }
  35%     { transform: translate(-20%,-46%) scaleY(.9) scaleX(1.06); }
  55%     { transform: translate(20%,-58%) rotate(-2deg); }
  75%     { transform: translate(50%,-46%) scaleY(.9) scaleX(1.04); }
}
@keyframes pixel-turn-right { 0%, 100% { transform: translate(-50%, -50%) scaleX(1); } 28%, 72% { transform: translate(-50%, -54%) scaleX(-1); } 50% { transform: translate(-50%, -61%) scaleX(-1); } }
@keyframes pixel-turn-left { 0%, 100% { transform: translate(-50%, -50%) scaleX(1); } 28%, 72% { transform: translate(-50%, -54%) scaleX(1); } 50% { transform: translate(-50%, -61%) scaleX(1); } }
@keyframes pixel-walk-left {
  0%, 100% { transform: translate(-50%, -50%); }
  8%  { transform: translate(calc(-50% - 18px), calc(-50% - 6px)); }
  16% { transform: translate(calc(-50% - 36px), -50%); }
  24% { transform: translate(calc(-50% - 54px), calc(-50% - 6px)); }
  32% { transform: translate(calc(-50% - 72px), -50%); }
  40% { transform: translate(calc(-50% - 84px), calc(-50% - 6px)); }
  50% { transform: translate(calc(-50% - 84px), -50%); }
  60% { transform: translate(calc(-50% - 60px), calc(-50% - 6px)); }
  70% { transform: translate(calc(-50% - 42px), -50%); }
  80% { transform: translate(calc(-50% - 24px), calc(-50% - 6px)); }
  90% { transform: translate(calc(-50% - 9px), -50%); }
}
@keyframes pixel-walk-right {
  0%, 100% { transform: translate(-50%, -50%); }
  8%  { transform: translate(calc(-50% + 18px), calc(-50% - 6px)); }
  16% { transform: translate(calc(-50% + 36px), -50%); }
  24% { transform: translate(calc(-50% + 54px), calc(-50% - 6px)); }
  32% { transform: translate(calc(-50% + 72px), -50%); }
  40% { transform: translate(calc(-50% + 84px), calc(-50% - 6px)); }
  50% { transform: translate(calc(-50% + 84px), -50%); }
  60% { transform: translate(calc(-50% + 60px), calc(-50% - 6px)); }
  70% { transform: translate(calc(-50% + 42px), -50%); }
  80% { transform: translate(calc(-50% + 24px), calc(-50% - 6px)); }
  90% { transform: translate(calc(-50% + 9px), -50%); }
}
