:root {
  --metal-light: #efefeb;
  --metal: #c5c6c2;
  --metal-dark: #777b78;
  --ink: #161817;
  --red: #b70e0d;
  --red-dark: #5e0504;
  --yellow: #ffe820;
}

* { box-sizing: border-box; }

html {
  touch-action: pan-y;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 18px 0 28px;
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
  background:
    linear-gradient(90deg, #191b1a 1px, transparent 1px) 0 0 / 7px 7px,
    linear-gradient(#191b1a 1px, transparent 1px) 0 0 / 7px 7px,
    #292c2a;
}

button, input { font: inherit; }
button { cursor: pointer; }

.game-shell {
  position: relative;
  width: min(1120px, 97vw);
  border: 3px solid #0e0f0f;
  border-radius: 4px;
  overflow: hidden;
  background: var(--metal);
  box-shadow: 0 18px 34px #000a, inset 0 0 0 2px #fff9;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px 8px 22px;
  border-bottom: 3px ridge #fff;
  background:
    radial-gradient(circle, #777 0 1px, transparent 1.5px) 0 0 / 5px 5px,
    linear-gradient(#f8f8f5, #b4b6b2);
}

.brand {
  display: flex;
  align-items: baseline;
  transform: rotate(-3deg);
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-style: italic;
  line-height: .72;
  color: #fff027;
  text-shadow: 3px 3px 0 #e56c00, 5px 5px 0 #8d3000;
}

.brand span { font-size: 34px; }
.brand strong { font-size: 48px; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.sound-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 3px outset #fff;
  border-radius: 2px;
  background: #d7d8d5;
  font-size: 21px;
}

.new-game, .modal button {
  min-height: 42px;
  border: 3px outset #ff4a3e;
  border-radius: 2px;
  padding: 7px 13px;
  color: #fff680;
  background: linear-gradient(#e5231d, #8e0807);
  box-shadow: inset 0 0 0 2px #720300, 2px 3px 0 #555;
  text-shadow: 1px 1px #580000;
}

.sound-button:active, .new-game:active, .modal button:active { border-style: inset; transform: translateY(1px); }

.cabinet {
  display: grid;
  grid-template-columns: minmax(500px, 1fr) 250px;
  grid-template-areas: "board score";
  gap: 16px;
  padding: 18px;
  border-bottom: 3px ridge #fff;
  background:
    radial-gradient(circle at 25% 30%, #8b8e8a 0 1px, transparent 1.5px) 0 0 / 6px 6px,
    radial-gradient(circle at 70% 65%, #fff 0 1px, transparent 1.5px) 0 0 / 9px 9px,
    #cacbc8;
}

.board-wrap {
  grid-area: board;
  position: relative;
  min-width: 0;
  padding: 7px;
  border: 3px inset #f9f9f6;
  background: #a6a9a5;
  touch-action: none;
}

.board {
  aspect-ratio: 9 / 8;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  background: #b7b9b5;
  touch-action: none;
}

.cell {
  position: relative;
  min-width: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background:
    radial-gradient(ellipse at 48% 42%, #f3f3ef 0 28%, #a8aaa7 31%, #e1e2df 47%, #929591 49%, #c9cac7 68%, #a2a4a1 72%);
  box-shadow: inset 2px 2px 3px #777, inset -2px -2px 3px #fff;
  user-select: none;
}

.cell::after {
  content: "";
  position: absolute;
  inset: 3px;
  z-index: 0;
  border-radius: 4px;
  opacity: .18;
  pointer-events: none;
  background: radial-gradient(circle, #444 0 1px, transparent 1.3px) 0 0 / 5px 5px;
}

.cell.selected { outline: 4px solid #fff51d; outline-offset: -4px; filter: brightness(1.08); }
.cell.ability-target { outline: 4px solid #23cfff; outline-offset: -4px; }
.cell.swap-target { outline: 4px solid #ff8c00; outline-offset: -4px; }
.cell.hatch { outline: 4px solid #45d719; outline-offset: -4px; animation: hint .55s ease-in-out 3; }
.cell.hint { animation: hint .5s ease-in-out 3; }

.sprite-body, .preview, .counter-sprite {
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  image-rendering: pixelated;
}

.chicken-sprite {
  position: relative;
  z-index: 1;
  width: 88%;
  height: 88%;
  filter: drop-shadow(3px 5px 2px #3339);
}

.sprite-body {
  position: absolute;
  z-index: 1;
  inset: 0;
  clip-path: inset(0 0 18% 0);
}

.chicken-sprite.red .sprite-body, .red.preview, .red .counter-sprite { background-image: url("assets/original/red.png"); }
.chicken-sprite.gold .sprite-body, .gold.preview, .gold .counter-sprite { background-image: url("assets/original/yellow.png"); }
.chicken-sprite.white .sprite-body, .white.preview, .white .counter-sprite { background-image: url("assets/original/white.png"); }
.chicken-sprite.purple .sprite-body, .purple.preview, .purple .counter-sprite { background-image: url("assets/original/blue.png"); }
.chicken-sprite.blue .sprite-body, .blue.preview, .blue .counter-sprite { background-image: url("assets/original/green.png"); }
.chicken-sprite.brown .sprite-body, .brown.preview, .brown .counter-sprite { background-image: url("assets/original/brown.png"); }
.chicken-sprite.joker .sprite-body {
  background: radial-gradient(ellipse at 48% 48%, #fffdf0 0 42%, #ead39d 44% 50%, transparent 52%) center / 80% 96% no-repeat;
  clip-path: none;
}

.chicken-leg {
  position: absolute;
  z-index: 2;
  bottom: 9%;
  width: max(2px, 5%);
  height: 18%;
  border-inline: 1px solid #651400;
  background: #ff3b08;
  transform-origin: 50% 0;
}
.chicken-leg.left { left: 36%; transform: rotate(10deg); }
.chicken-leg.right { right: 36%; transform: rotate(-10deg); }
.chicken-leg::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 240%;
  height: max(2px, 28%);
  border: 1px solid #651400;
  background: #ff3b08;
  transform: translateX(-50%);
}
.cell.dancing .chicken-leg.left { animation: leg-step-left .78s steps(1, end); }
.cell.dancing .chicken-leg.right { animation: leg-step-right .78s steps(1, end); }
.cell:hover .sprite-body { filter: brightness(1.06); }
.cell.pop .chicken-sprite { animation: pop .27s forwards; }
.cell.drop .chicken-sprite { animation: drop .25s ease-out; }

.message {
  position: absolute;
  z-index: 6;
  inset: 44% 0 auto;
  padding: 4px 10px;
  text-align: center;
  pointer-events: none;
  color: #fff928;
  font: 700 30px Impact, Haettenschweiler, sans-serif;
  text-shadow: 2px 2px 0 #9a0c00, 4px 4px 0 #333;
  opacity: 0;
  transform: scale(.5);
}

.message.show { animation: message .85s; }

.score-panel {
  grid-area: score;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border: 3px outset #f8f8f5;
  background: #b5b7b3;
}

.score-card, .next-card {
  position: relative;
  padding: 9px;
  text-align: center;
  border: 4px outset #f1f1ee;
  border-radius: 2px;
  background: #d5d6d3;
}

.score-card span, .next-card > span {
  display: block;
  margin-bottom: 6px;
  color: #333;
  font-size: 12px;
}

.score-card strong {
  display: block;
  min-height: 45px;
  padding: 6px 8px 4px;
  overflow: hidden;
  color: #fff928;
  border: 4px inset #ff5952;
  background: linear-gradient(#de1714, #9a0706);
  box-shadow: inset 0 0 12px #4d0000;
  font-size: 27px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  text-shadow: 2px 2px #6d0000;
}

.primary-score strong { font-size: 33px; }
.best strong { font-size: 23px; }
.next-card { margin-top: 2px; }

.next-card #nextChickens {
  min-height: 78px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border: 3px inset #eee;
  background: #c5c6c2;
}

.next-card .preview { width: 64px; height: 64px; filter: drop-shadow(2px 4px 1px #5558); }

.tool-rail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  min-width: 0;
  margin-top: auto;
  padding-top: 9px;
  border-top: 3px ridge #eee;
}

.egg-bank, .tool {
  min-width: 0;
  height: 86px;
  border: 3px outset #f5f5f2;
  border-radius: 2px;
  background: #d5d6d2;
  box-shadow: 2px 3px 0 #777;
}

.egg-bank {
  grid-column: 1 / -1;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 12px;
  color: #444;
  font-size: 11px;
}

.egg-meter {
  width: 58px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a2100;
  background: radial-gradient(ellipse, #fff9d2 0 46%, #ead28e 49%, transparent 52%);
}

.egg-meter strong { font-size: 25px; }
.egg-meter small { font-size: 11px; }

.tool {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  padding: 5px 3px 12px;
  color: #111;
}

.tool:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.tool:active:not(:disabled) { border-style: inset; transform: translateY(1px); }
.tool:disabled { opacity: .72; cursor: not-allowed; }
.tool:disabled .super-sprite { filter: grayscale(1); opacity: .68; }
.tool.active { outline: 4px solid #fff20d; outline-offset: 1px; background: #fff9c9; }
.tool.ready { background: #e1f5b9; }
.tool > span { font-size: 30px; line-height: 32px; }
.tool .super-sprite {
  width: 58px;
  height: 54px;
  display: block;
  background-image: url("assets/original/super-chickens.png");
  background-repeat: no-repeat;
  background-size: 158px 262px;
  image-rendering: pixelated;
}
.tool .super-sprite.joker { background-position: 0 0; }
.tool .super-sprite.pilot { background-position: 0 -66px; }
.tool .super-sprite.ghost { background-position: 0 -132px; }
.tool .super-sprite.boxer { background-position: 0 -197px; }
.tool small { display: block; max-width: 100%; overflow: hidden; font-size: 9px; }
.tool b {
  position: absolute;
  right: 4px;
  bottom: 3px;
  min-width: 25px;
  height: 19px;
  display: grid;
  place-items: center;
  padding: 0 3px;
  color: #fff625;
  border: 2px inset #ff4f45;
  background: #b00b09;
  font-size: 11px;
}
.tool b.cooldown { color: #fff; background: #555; border-color: #aaa; }

.flock-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 9px;
  padding: 11px 18px;
  border-bottom: 3px ridge #fff;
  background:
    radial-gradient(circle, #777 0 1px, transparent 1.4px) 0 0 / 6px 6px,
    #c9cac7;
}

.flock-count {
  position: relative;
  height: 68px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: end;
  border-bottom: 5px double #595b59;
}

.counter-sprite { width: 60px; height: 60px; justify-self: center; filter: drop-shadow(2px 4px 1px #5558); }
.flock-count strong {
  align-self: start;
  min-width: 38px;
  padding: 3px;
  color: #fff;
  border: 2px inset #eee;
  background: #333;
  text-align: center;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.flock-count.red strong { background: #c3130e; }
.flock-count.gold strong { color: #161817; background: #ffe700; }
.flock-count.white strong { color: #161817; background: #fff; }
.flock-count.purple strong { background: #585599; }
.flock-count.blue strong { background: #77804b; }
.flock-count.brown strong { background: #653716; }

footer {
  padding: 9px 12px;
  text-align: center;
  color: #303230;
  background: #b9bbb7;
  font-size: 11px;
}

.global-leaderboard {
  padding: 17px 20px 23px;
  border-top: 3px ridge #fff;
  background:
    radial-gradient(circle, #777 0 1px, transparent 1.5px) 0 0 / 6px 6px,
    #c8c9c6;
}

.global-leaderboard h2 {
  width: min(560px, 100%);
  margin: 0 auto 10px;
  padding: 7px 10px;
  color: #fff82c;
  border: 4px inset #ff4f45;
  background: linear-gradient(#d81815, #930706);
  text-align: center;
  font-size: 20px;
  text-shadow: 2px 2px #630000;
}

.global-leaderboard ol {
  width: min(560px, 100%);
  display: grid;
  gap: 4px;
  margin: 0 auto;
  padding: 0;
  list-style: none;
  counter-reset: rank;
}

.global-leaderboard li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 6px 9px;
  border: 2px inset #eee;
  background: #e4e5e2;
}
.global-leaderboard li::before { content: counter(rank) "."; color: #8a0b09; }
.global-leaderboard li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.global-leaderboard li strong { color: #9d0b09; font-variant-numeric: tabular-nums; }
.global-leaderboard .leaderboard-empty { display: block; text-align: center; color: #555; }
.global-leaderboard .leaderboard-empty::before { content: ""; }

.game-over {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #111c;
  backdrop-filter: blur(3px);
}
.game-over[hidden] { display: none; }
.modal {
  width: min(430px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px;
  border: 5px outset #fff;
  border-radius: 3px;
  background:
    radial-gradient(circle, #777 0 1px, transparent 1.5px) 0 0 / 6px 6px,
    #c9cac7;
  text-align: center;
  touch-action: pan-y;
  box-shadow: 0 18px 40px #000b;
}
.modal h1 { margin: 2px 0 8px; color: #b30c09; font-size: 34px; }
.modal p { margin: 8px 0 18px; }
.record-form { display: grid; gap: 8px; margin: 0 0 16px; }
.record-form[hidden] { display: none; }
.record-form label { color: #a20a08; font-size: 17px; }
.record-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.record-entry input { min-width: 0; padding: 9px; color: #111; border: 3px inset #fff; border-radius: 2px; background: #f6f6f1; }
.record-entry button { padding-inline: 12px; }
.record-form small { min-height: 16px; color: #740000; }
.modal > #playAgain { width: 100%; }

@keyframes hint { 50% { filter: brightness(1.35); } }
@keyframes pop { to { transform: scale(1.7) rotate(15deg); opacity: 0; } }
@keyframes drop { from { transform: translateY(-90%); opacity: .2; } }
@keyframes leg-step-left { 0%, 100% { transform: translate(0) rotate(10deg); } 20% { transform: translate(-50%, -10%) rotate(24deg); } 40% { transform: translate(35%, 5%) rotate(-15deg); } 60% { transform: translate(-35%, 0) rotate(18deg); } 80% { transform: translate(40%, -8%) rotate(-16deg); } }
@keyframes leg-step-right { 0%, 100% { transform: translate(0) rotate(-10deg); } 20% { transform: translate(45%, 5%) rotate(-20deg); } 40% { transform: translate(-40%, -10%) rotate(16deg); } 60% { transform: translate(40%, -8%) rotate(-20deg); } 80% { transform: translate(-35%, 2%) rotate(13deg); } }
@keyframes message { 30% { opacity: 1; transform: scale(1.15); } 70% { opacity: 1; transform: scale(1); } to { opacity: 0; transform: translateY(-35px); } }

@media (max-width: 760px) {
  body { align-items: stretch; padding: 0; }
  .game-shell { width: 100vw; border-inline: 0; }
  .topbar { min-height: 58px; padding: 6px 9px 5px 13px; }
  .brand span { font-size: 24px; }
  .brand strong { font-size: 34px; }
  .header-actions { gap: 6px; }
  .sound-button { width: 37px; height: 37px; font-size: 18px; }
  .new-game { min-height: 37px; padding: 5px 8px; font-size: 12px; }
  .cabinet {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "board" "score";
    gap: 7px;
    padding: 7px;
  }
  .board-wrap { padding: 4px; }
  .board { gap: 1px; padding: 1px; }
  .cell { border-radius: 2px; }
  .chicken-sprite { width: 95%; height: 95%; filter: drop-shadow(1px 2px 1px #3338); }
  .message { font-size: 23px; }
  .score-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 5px;
  }
  .score-card, .next-card { min-width: 0; margin: 0; padding: 4px; border-width: 2px; }
  .score-card span, .next-card > span { margin-bottom: 3px; font-size: 8px; }
  .score-card strong { min-height: 31px; padding: 4px 3px 2px; border-width: 2px; font-size: 16px; }
  .primary-score strong { font-size: 17px; }
  .best strong { font-size: 14px; }
  .next-card #nextChickens { min-height: 31px; gap: 1px; padding: 1px; border-width: 2px; }
  .next-card .preview { width: 32px; height: 32px; }
  .tool-rail {
    grid-column: 1 / -1;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
    margin-top: 0;
    padding-top: 5px;
  }
  .egg-bank, .tool { height: 62px; border-width: 2px; box-shadow: 1px 2px #777; }
  .egg-bank { grid-column: auto; display: grid; place-items: center; gap: 1px; padding: 2px; font-size: 7px; }
  .egg-meter { width: 42px; height: 34px; }
  .egg-meter strong { font-size: 17px; }
  .egg-meter small { font-size: 8px; }
  .tool { padding: 3px 1px 10px; }
  .tool > span { font-size: 20px; line-height: 22px; }
  .tool .super-sprite { width: 38px; height: 36px; background-size: 111px 184px; }
  .tool .super-sprite.joker { background-position: 0 0; }
  .tool .super-sprite.pilot { background-position: 0 -46px; }
  .tool .super-sprite.ghost { background-position: 0 -92px; }
  .tool .super-sprite.boxer { background-position: 0 -138px; }
  .tool small { font-size: 6px; }
  .tool b { right: 2px; bottom: 2px; min-width: 18px; height: 14px; border-width: 1px; font-size: 8px; }
  .flock-strip { gap: 3px; padding: 7px 6px; }
  .flock-count { height: 48px; grid-template-columns: minmax(0, 1fr) 23px; border-bottom-width: 3px; }
  .counter-sprite { width: 42px; height: 42px; }
  .flock-count strong { min-width: 23px; padding: 2px 0; border-width: 1px; font-size: 11px; }
  footer { padding: 7px 5px; font-size: 8px; }
  .global-leaderboard { padding: 14px 12px 20px; }
  .global-leaderboard h2 { font-size: 17px; }
  .global-leaderboard li { font-size: 12px; }
}

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