:root {
  --black: #080809;
  --dark: #29292b;
  --off-white: #e8e6d6;
  --dim: rgba(232, 230, 214, 0.68);
  --faint: rgba(232, 230, 214, 0.18);
  --red: #e6141f;
  --yellow: #f7c727;
  --tile: calc(100% / 8);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--black);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% 18%, rgba(230, 20, 31, 0.08), transparent 33rem),
    linear-gradient(90deg, rgba(232, 230, 214, 0.025) 1px, transparent 1px),
    linear-gradient(0deg, rgba(232, 230, 214, 0.025) 1px, transparent 1px),
    var(--black);
  background-size: auto, 12px 12px, 12px 12px, auto;
  color: var(--off-white);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(232, 230, 214, 0.025) 50%, transparent 50%),
    radial-gradient(circle at center, transparent 44%, rgba(0, 0, 0, 0.62));
  background-size: 100% 4px, auto;
  mix-blend-mode: normal;
}

a {
  color: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100vh - 68px);
  margin: 0 auto;
  display: grid;
  align-content: center;
  padding: 34px 0 24px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: clamp(22px, 4vw, 38px);
  width: min(640px, 100%);
  margin: 0 auto;
}

.hero-copy {
  width: 100%;
  text-align: center;
}

.subtitle,
.updated {
  margin: 0;
  color: var(--dim);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  margin: 8px 0 0;
  font-size: clamp(54px, 10vw, 118px);
  line-height: 0.9;
  font-weight: 1000;
}

.subtitle {
  margin-top: 12px;
  color: var(--off-white);
}

.lede {
  max-width: 570px;
  margin: 24px auto 0;
  color: var(--dim);
  font-size: clamp(16px, 1.9vw, 20px);
  line-height: 1.55;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 30px;
}

.button {
  min-width: 168px;
  padding: 15px 18px;
  border: 2px solid var(--off-white);
  appearance: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: center;
  text-decoration: none;
  font-size: 14px;
  font-weight: 1000;
  text-transform: uppercase;
}

.button.primary {
  border-color: var(--yellow);
  background: var(--yellow);
  color: var(--black);
}

.button:active {
  transform: translateY(2px);
}

.button.secondary {
  color: var(--off-white);
}

.hero-art {
  position: relative;
  order: -1;
  width: 100%;
  display: grid;
  place-items: center;
}

.demo-panel {
  width: min(560px, 100%);
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.demo-hud {
  display: none;
  min-height: 22px;
  margin-bottom: 8px;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--off-white);
  font-size: clamp(12px, 2.2vw, 15px);
  font-weight: 1000;
  text-transform: uppercase;
}

.demo-hud span:first-child {
  color: var(--red);
}

.demo-board-wrap {
  display: block;
}

.checkfall-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--black);
  border: 0;
  image-rendering: pixelated;
}

.checkfall-board.is-resetting .piece,
.checkfall-board.is-resetting .danger-fill,
.checkfall-board.is-resetting .legal-square,
.checkfall-board.is-resetting .capture-target,
.checkfall-board.is-resetting .crack,
.checkfall-board.is-resetting .collapse-flash,
.checkfall-board.is-resetting .transform-ghost,
.checkfall-board.is-resetting .pixel,
.checkfall-board.is-resetting .move-pixel {
  visibility: hidden;
}

.checkfall-board.is-resetting .piece {
  transition: none;
}

.tile,
.piece,
.danger-fill,
.legal-square,
.capture-target,
.crack,
.collapse-flash,
.transform-ghost {
  position: absolute;
  left: calc(var(--file) * var(--tile));
  bottom: calc(var(--rank) * var(--tile));
  width: var(--tile);
  aspect-ratio: 1;
}

.tile {
  border: 1px solid rgba(232, 230, 214, 0.5);
  background: transparent;
  z-index: 1;
}

.tile.light {
  background:
    repeating-linear-gradient(
      135deg,
      transparent 0 2px,
      rgba(232, 230, 214, 0.28) 2px 3px,
      transparent 3px 5px
    );
}

.tile.shrink-warning {
  background:
    linear-gradient(rgba(230, 20, 31, 0.38), rgba(230, 20, 31, 0.38)),
    repeating-linear-gradient(
      135deg,
      transparent 0 2px,
      rgba(232, 230, 214, 0.24) 2px 3px,
      transparent 3px 5px
    );
  border-color: var(--red);
  z-index: 8;
  animation: warningPulse 0.52s steps(2, end) infinite;
}

.tile.falling {
  z-index: 50;
  animation: tileFall 0.36s steps(6, end) forwards;
  animation-delay: var(--delay, 0ms);
}

.tile.removed {
  visibility: hidden;
  opacity: 0;
  border-color: transparent;
  background: transparent;
}

.collapse-gap {
  position: absolute;
  background: var(--black);
  z-index: 7;
  pointer-events: none;
}

.collapse-gap.column {
  box-shadow: 2px 0 0 var(--black);
}

.collapse-gap.row {
  box-shadow: 0 2px 0 var(--black);
}

.collapse-jagged-edge {
  position: absolute;
  z-index: 16;
  pointer-events: none;
  background: transparent;
  opacity: 1;
  overflow: visible;
}

.collapse-jagged-edge svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.collapse-jagged-edge .jagged-fill {
  fill: var(--black);
  stroke: none;
}

.collapse-jagged-edge .jagged-line {
  fill: none;
  stroke: rgba(232, 230, 214, 0.82);
  stroke-width: 2;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.collapse-jagged-edge.reveal-bottom {
  animation: edgeRevealBottom var(--edge-duration, 665ms) steps(8, end) forwards;
}

.collapse-jagged-edge.reveal-top {
  animation: edgeRevealTop var(--edge-duration, 665ms) steps(8, end) forwards;
}

.collapse-jagged-edge.reveal-left {
  animation: edgeRevealLeft var(--edge-duration, 665ms) steps(8, end) forwards;
}

.collapse-jagged-edge.reveal-right {
  animation: edgeRevealRight var(--edge-duration, 665ms) steps(8, end) forwards;
}

.collapse-flash {
  z-index: 52;
  pointer-events: none;
  background:
    linear-gradient(rgba(232, 230, 214, 0.16), rgba(232, 230, 214, 0.16)),
    repeating-linear-gradient(
      135deg,
      transparent 0 3px,
      rgba(232, 230, 214, 0.34) 3px 5px,
      transparent 5px 8px
    );
  outline: 2px solid rgba(232, 230, 214, 0.82);
  animation: collapseFlash 0.26s steps(4, end) forwards;
}

.danger-fill {
  background: rgba(230, 20, 31, 0.42);
  z-index: 5;
}

.legal-square {
  border: 3px solid var(--off-white);
  transform: scale(0.7);
  z-index: 18;
  opacity: 0.78;
}

.capture-target {
  background: rgba(230, 20, 31, 0.42);
  z-index: 6;
}

.player-corners {
  pointer-events: none;
}

.player-corners {
  position: absolute;
  inset: 9%;
  z-index: 35;
}

.player-corners::before,
.player-corners::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(currentColor, currentColor) left top / 28% 4px no-repeat,
    linear-gradient(currentColor, currentColor) left top / 4px 28% no-repeat,
    linear-gradient(currentColor, currentColor) right top / 28% 4px no-repeat,
    linear-gradient(currentColor, currentColor) right top / 4px 28% no-repeat,
    linear-gradient(currentColor, currentColor) left bottom / 28% 4px no-repeat,
    linear-gradient(currentColor, currentColor) left bottom / 4px 28% no-repeat,
    linear-gradient(currentColor, currentColor) right bottom / 28% 4px no-repeat,
    linear-gradient(currentColor, currentColor) right bottom / 4px 28% no-repeat;
}

.player-corners {
  color: var(--yellow);
}

.piece {
  display: grid;
  place-items: center;
  z-index: 30;
  transition:
    left 0.42s steps(6, end),
    bottom 0.42s steps(6, end),
    transform 0.22s steps(3, end);
}

.piece.player {
  z-index: 38;
}

.piece.enemy {
  z-index: 30;
}

.piece.enemy.moving .sprite {
  animation: enemyMovePulse 0.46s steps(4, end);
}

.piece.enemy.slow.moving .sprite {
  animation-duration: 0.68s;
}

.piece.enemy.capturer {
  z-index: 98;
}

.piece.slow {
  transition-duration: 0.62s;
}

.piece .sprite,
.transform-ghost .sprite {
  width: 86%;
  height: 86%;
  background-image: var(--sprite);
  background-repeat: no-repeat;
  background-size: 300% 100%;
  background-position: var(--frame-position, 0%) 0;
  image-rendering: pixelated;
}

.piece.enemy .sprite {
  position: relative;
  background-image: none;
  filter: none;
}

.piece.enemy .sprite::before,
.piece.enemy .sprite::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--sprite);
  background-repeat: no-repeat;
  background-size: 300% 100%;
  background-position: var(--frame-position, 0%) 0;
  image-rendering: pixelated;
}

.piece.enemy .sprite::before {
  filter:
    brightness(0)
    drop-shadow(-2px 0 0 var(--black))
    drop-shadow(2px 0 0 var(--black))
    drop-shadow(0 -2px 0 var(--black))
    drop-shadow(0 2px 0 var(--black));
}

.piece.enemy .sprite::after {
  filter:
    grayscale(0.62)
    brightness(0.64)
    contrast(1.28);
}

.transform-ghost {
  z-index: 88;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.transform-ghost.old .sprite {
  animation: transformOldOut 0.46s steps(7, end) forwards;
}

.transform-ghost.player.old .sprite {
  filter:
    drop-shadow(-2px 0 0 var(--black))
    drop-shadow(2px 0 0 var(--black))
    drop-shadow(0 -2px 0 var(--black))
    drop-shadow(0 2px 0 var(--black));
}

.transform-ghost.enemy.old .sprite {
  filter:
    grayscale(1)
    brightness(0.58)
    contrast(1.16)
    drop-shadow(-2px 0 0 var(--black))
    drop-shadow(2px 0 0 var(--black))
    drop-shadow(0 -2px 0 var(--black))
    drop-shadow(0 2px 0 var(--black));
}

.transform-ghost.new .sprite {
  filter:
    sepia(1)
    saturate(2.2)
    brightness(1.22)
    drop-shadow(-2px 0 0 var(--black))
    drop-shadow(2px 0 0 var(--black))
    drop-shadow(0 -2px 0 var(--black))
    drop-shadow(0 2px 0 var(--black));
  animation: transformNewIn 0.62s steps(8, end) forwards;
}

.transform-ghost.enemy.new .sprite {
  animation-name: transformNewEnemyIn;
}

.piece.player .sprite {
  filter:
    drop-shadow(-2px 0 0 var(--black))
    drop-shadow(2px 0 0 var(--black))
    drop-shadow(0 -2px 0 var(--black))
    drop-shadow(0 2px 0 var(--black));
}

.piece.powerup {
  z-index: 26;
}

.piece.powerup::before {
  content: "";
  position: absolute;
  inset: 15%;
  background: var(--yellow);
  border: 2px solid var(--black);
  box-shadow: 0 0 0 2px var(--yellow);
  animation: pickupPulse 2.1s ease-in-out infinite;
}

.piece.powerup::after {
  content: "";
  position: absolute;
  inset: 5%;
  border: 0;
  background:
    radial-gradient(circle at 28% 24%, rgba(232, 230, 214, 0.5) 0 5%, transparent 7%),
    radial-gradient(circle at 78% 72%, rgba(247, 199, 39, 0.36) 0 8%, transparent 11%),
    linear-gradient(135deg, transparent 18%, rgba(232, 230, 214, 0.34) 22% 27%, transparent 31% 100%);
  opacity: 0.34;
  animation: powerupShine 2.6s ease-in-out infinite;
  z-index: 1;
}

.piece.powerup .sprite {
  width: 70%;
  height: 70%;
  filter: brightness(0);
  z-index: 2;
}

.piece.interlace .sprite {
  animation: interlaceOut 0.58s steps(8, end) forwards;
}

.piece.enemy.interlace {
  z-index: 32;
}

.piece.player.interlace {
  z-index: 40;
}

.piece.hit {
  animation: pieceHit 0.28s steps(3, end);
}

.crack {
  z-index: 14;
  opacity: 0.88;
  display: grid;
  place-items: center;
  overflow: visible;
  pointer-events: none;
  transform: rotate(var(--rotate, 0deg)) scale(var(--scale, 1));
}

.crack.falling {
  z-index: 51;
  animation: crackFall 0.36s steps(6, end) forwards;
  animation-delay: var(--delay, 0ms);
}

.crack-sprite {
  width: 72%;
  height: 72%;
  background-image: url("assets/telegraphs/telegraph_crack_overlay.png");
  background-size: 100% 100%;
  filter: brightness(0) invert(93%);
  image-rendering: pixelated;
}

.pixel {
  position: absolute;
  width: var(--size, 6px);
  height: var(--size, 6px);
  left: var(--x);
  bottom: var(--y);
  background: var(--color, var(--off-white));
  z-index: 70;
  image-rendering: pixelated;
  animation: pixelBurst var(--duration, 0.7s) steps(8, end) forwards;
}

.pixel.death-pixel {
  z-index: 92;
}

.move-pixel {
  position: absolute;
  width: var(--size, 5px);
  height: var(--size, 5px);
  left: var(--x);
  bottom: var(--y);
  background: var(--color, var(--off-white));
  z-index: 24;
  opacity: 0;
  image-rendering: pixelated;
  animation: moveTrail 0.42s steps(5, end) var(--delay, 0ms) forwards;
}

.move-pixel.enemy {
  z-index: 25;
}

.demo-caption {
  display: none;
  min-height: 24px;
  margin-top: 10px;
  color: var(--dim);
  font-size: clamp(11px, 2vw, 13px);
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

footer {
  width: min(1180px, calc(100% - 32px));
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: rgba(232, 230, 214, 0.48);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.cookie-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 90;
  max-width: 760px;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 2px solid rgba(232, 230, 214, 0.84);
  background: rgba(8, 8, 9, 0.96);
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.28);
  color: var(--off-white);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.cookie-banner[hidden] {
  display: none;
}

.cookie-banner p {
  margin: 4px 0 0;
  color: var(--dim);
  line-height: 1.35;
}

.cookie-banner a {
  display: inline-block;
  margin-top: 5px;
  color: var(--dim);
  text-underline-offset: 3px;
}

.cookie-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: 220px;
}

.cookie-actions button {
  min-height: 42px;
  border: 2px solid var(--off-white);
  appearance: none;
  background: transparent;
  color: var(--off-white);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  text-transform: uppercase;
}

.cookie-actions button:last-child {
  border-color: var(--yellow);
  background: var(--yellow);
  color: var(--black);
}

.policy-shell {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 44px 0 72px;
}

.policy-shell h1 {
  font-size: clamp(36px, 8vw, 68px);
}

.policy-shell section {
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid rgba(232, 230, 214, 0.28);
}

.policy-shell p {
  margin: 0;
  color: var(--dim);
  line-height: 1.55;
}

.back-link {
  display: inline-block;
  margin-bottom: 24px;
  color: var(--dim);
  font-size: 13px;
  font-weight: 1000;
  text-decoration: none;
  text-transform: uppercase;
}

@keyframes warningPulse {
  50% { filter: brightness(1.25); }
}

@keyframes pickupPulse {
  50% {
    box-shadow: 0 0 0 3px rgba(247, 199, 39, 0.48);
    filter: brightness(1.03);
  }
}

@keyframes powerupShine {
  0% {
    opacity: 0.24;
    transform: scale(0.96);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.04);
  }
  100% {
    opacity: 0.24;
    transform: scale(0.96);
  }
}

@keyframes transformOldOut {
  0% {
    clip-path: inset(0 0 0 0);
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    clip-path: inset(100% 0 0 0);
    transform: translateY(-12px);
    opacity: 0.2;
  }
}

@keyframes transformNewIn {
  0% {
    clip-path: inset(100% 0 0 0);
    transform: translateY(14px) scale(0.94);
    opacity: 0.92;
    filter:
      sepia(1)
      saturate(2.2)
      brightness(1.22)
      drop-shadow(-2px 0 0 var(--black))
      drop-shadow(2px 0 0 var(--black))
      drop-shadow(0 -2px 0 var(--black))
      drop-shadow(0 2px 0 var(--black));
  }
  100% {
    clip-path: inset(0 0 0 0);
    transform: translateY(0) scale(1);
    opacity: 1;
    filter:
      drop-shadow(-2px 0 0 var(--black))
      drop-shadow(2px 0 0 var(--black))
      drop-shadow(0 -2px 0 var(--black))
      drop-shadow(0 2px 0 var(--black));
  }
}

@keyframes transformNewEnemyIn {
  0% {
    clip-path: inset(100% 0 0 0);
    transform: translateY(14px) scale(0.94);
    opacity: 0.92;
    filter:
      sepia(1)
      saturate(2.2)
      brightness(1.22)
      drop-shadow(-2px 0 0 var(--black))
      drop-shadow(2px 0 0 var(--black))
      drop-shadow(0 -2px 0 var(--black))
      drop-shadow(0 2px 0 var(--black));
  }
  100% {
    clip-path: inset(0 0 0 0);
    transform: translateY(0) scale(1);
    opacity: 1;
    filter:
      grayscale(1)
      brightness(0.58)
      contrast(1.16)
      drop-shadow(-2px 0 0 var(--black))
      drop-shadow(2px 0 0 var(--black))
      drop-shadow(0 -2px 0 var(--black))
      drop-shadow(0 2px 0 var(--black));
  }
}

@keyframes interlaceOut {
  0% {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
  100% {
    clip-path: inset(100% 0 0 0);
    opacity: 0;
  }
}

@keyframes pieceHit {
  33% { transform: translate(-3px, 2px); }
  66% { transform: translate(3px, -2px); }
}

@keyframes enemyMovePulse {
  0% { transform: translate(0, 0) scale(1); filter: brightness(1); }
  25% { transform: translate(-2px, 1px) scale(1.03); filter: brightness(1.18); }
  50% { transform: translate(2px, -1px) scale(0.97); filter: brightness(0.92); }
  75% { transform: translate(-1px, 0) scale(1.02); filter: brightness(1.08); }
  100% { transform: translate(0, 0) scale(1); filter: brightness(1); }
}

@keyframes tileFall {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--fall-x, 0), var(--fall-y, -145%)) rotate(var(--fall-rotate, 0.22rad)); opacity: 0; }
}

@keyframes crackFall {
  0% {
    transform: translate(0, 0);
    opacity: 0.88;
  }
  100% {
    transform: translate(var(--fall-x, 0), var(--fall-y, -145%));
    opacity: 0;
  }
}

@keyframes pixelBurst {
  0% { transform: translate(0, 0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)); opacity: 0; }
}

@keyframes collapseFlash {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.82); }
}

@keyframes edgeRevealBottom {
  0% { clip-path: inset(100% 0 0 0); }
  100% { clip-path: inset(0 0 0 0); }
}

@keyframes edgeRevealTop {
  0% { clip-path: inset(0 0 100% 0); }
  100% { clip-path: inset(0 0 0 0); }
}

@keyframes edgeRevealLeft {
  0% { clip-path: inset(0 100% 0 0); }
  100% { clip-path: inset(0 0 0 0); }
}

@keyframes edgeRevealRight {
  0% { clip-path: inset(0 0 0 100%); }
  100% { clip-path: inset(0 0 0 0); }
}

@keyframes moveTrail {
  0% { transform: translate(0, 0) scale(0.82); opacity: 0.62; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.35); opacity: 0; }
}

@media (max-width: 860px) {
  .shell {
    align-content: start;
    padding-top: 28px;
  }

  .demo-panel {
    width: min(560px, 100%);
    margin: 0 auto;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1180px);
  }

  .actions {
    width: 100%;
  }

  .button {
    flex: 1 1 100%;
  }

  .demo-panel {
    padding: 10px;
  }

  .cookie-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .cookie-actions {
    min-width: 0;
  }
}

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