/* ── HEARTS GAME CABINET ─────────────────────────────────────────── */

.puyo-cabinet {
  background: #15110a;
  border: 1px solid var(--ink);
  border-radius: 12px;
  padding: 14px;
  box-shadow:
    inset 0 0 0 2px #2a2218,
    inset 0 0 0 4px #15110a,
    4px 4px 0 var(--ink);
  position: relative;
}
.puyo-cabinet::before {
  content: "HEARTS · ARCADE-01";
  position: absolute;
  top: -10px; left: 18px;
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.2em;
  background: var(--paper);
  color: var(--ink);
  padding: 2px 8px;
  border: 1px solid var(--ink);
  text-transform: uppercase;
}

.puyo-screen {
  background: #0a0d06;
  border: 2px solid #2a2218;
  border-radius: 6px;
  padding: 12px;
  position: relative;
  overflow: hidden;
}
.puyo-screen::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0, rgba(0,0,0,0) 3px,
    rgba(255,255,255,0.03) 3px, rgba(255,255,255,0.03) 4px);
}

.puyo-hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
  font-family: "VT323", monospace;
}
.puyo-hud-blk {
  border: 1px solid #4d3a2a;
  padding: 4px 10px;
  background: #110d08;
}
.puyo-hud-blk .lbl {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: #f5c878;
  opacity: 0.7;
  font-family: "JetBrains Mono", monospace;
}
.puyo-hud-blk .val {
  font-size: 28px;
  color: #ffd97a;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  text-shadow: 0 0 6px rgba(255, 217, 122, 0.4);
}

.puyo-play {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}

/* ── The play area: HALF of the temple background as backdrop ── */
.puyo-board {
  position: relative;
  border: 2px solid #4d3a2a;
  aspect-ratio: 6/12;
  width: 100%;
  max-width: 280px;
  overflow: hidden;
  box-shadow:
    inset 0 0 32px rgba(0,0,0,0.65),
    inset 0 0 0 1px rgba(0,0,0,0.6);
}

/* The temple backdrop, cropped to the exact play-area rectangle the
   user marked up. `cover` preserves the temple's vertical proportions
   and just trims a hair from the sides if the board's aspect drifts. */
.puyo-board-bg {
  position: absolute;
  inset: 0;
  background-image: url("assets/temple-bg.png");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  image-rendering: pixelated;
  filter: brightness(0.82) contrast(1.05) saturate(0.95);
}
/* Subtle scanline grid over the temple, ties it to the CRT look */
.puyo-board-bg::after {
  content: "";
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(to bottom,
      rgba(0,0,0,0) 0, rgba(0,0,0,0) 3px,
      rgba(0,0,0,0.18) 3px, rgba(0,0,0,0.18) 4px),
    linear-gradient(180deg,
      rgba(10,8,4,0.45) 0%,
      rgba(10,8,4,0.15) 35%,
      rgba(10,8,4,0.55) 100%);
  pointer-events: none;
}

.puyo-board-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: repeat(12, 1fr);
  z-index: 2;
}
.puyo-board-grid .row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
}

.cell {
  aspect-ratio: 1;
  position: relative;
  border-right: 1px solid rgba(255, 217, 122, 0.05);
  border-bottom: 1px solid rgba(255, 217, 122, 0.05);
}
.cell.empty {}

/* ── HEART SPRITES ──────────────────────────────────────────────── */
/* Five colour variants derived from the original blue heart sprite via
   per-pixel luminance-driven tinting. Each PNG is an 8-frame horizontal
   strip of the rotation animation from the source sprite sheet — we
   step through it with CSS steps(8) for a clean retro spin. */
.cell.filled .heart {
  position: absolute;
  inset: 6%;
  background-image: url("assets/heart-blue.png");
  background-size: 800% 100%;
  background-repeat: no-repeat;
  background-position: 0% 0%;   /* frame 0 — frontal heart, used at rest */
  image-rendering: pixelated;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.55));
  animation: heartLand 200ms ease-out;
}
/* Only the active falling pair spins. All falling hearts share the same
   2s timeline so they stay synchronized; once a heart locks into the
   board the `.falling` class drops and the sprite freezes on frame 0. */
.cell.filled.falling .heart {
  animation:
    heartSpin 2s steps(8, jump-none) infinite,
    heartLand 200ms ease-out;
}
@keyframes heartLand {
  0%   { transform: scale(0.85) translateY(-2px); }
  100% { transform: scale(1) translateY(0); }
}
/* Drive bg-position-x from 0% (image left edge → container left edge,
   showing frame 0) to 100% (image right edge → container right edge,
   showing frame 7). With steps(8, jump-none) the 8 stable values land
   exactly on the 8 frame boundaries. */
@keyframes heartSpin {
  from { background-position-x: 0%;   }
  to   { background-position-x: 100%; }
}
.cell.filled.heart-blue   .heart { background-image: url("assets/heart-blue.png");   }
.cell.filled.heart-red    .heart { background-image: url("assets/heart-red.png");    }
.cell.filled.heart-yellow .heart { background-image: url("assets/heart-yellow.png"); }
.cell.filled.heart-green  .heart { background-image: url("assets/heart-green.png");  }
.cell.filled.heart-pink   .heart { background-image: url("assets/heart-pink.png");   }

/* ── EXPLOSION FRAMES ───────────────────────────────────────────── */
.cell.exploding {
  position: relative;
}
.cell.exploding .boom {
  position: absolute;
  inset: -25%;             /* slightly larger than the cell */
  background-image: url("assets/explosion-strip.png");
  background-repeat: no-repeat;
  background-size: 1200% 100%; /* 12-frame horizontal strip */
  background-position: 0% 0%;
  image-rendering: pixelated;
  animation: explosion 1100ms steps(12, end) forwards;
  filter:
    drop-shadow(0 0 6px rgba(255, 180, 60, 0.7))
    drop-shadow(0 0 12px rgba(255, 90, 30, 0.5));
  pointer-events: none;
}
@keyframes explosion {
  from { background-position-x: 0%;     }
  to   { background-position-x: -1200%; } /* step past last frame */
}

.puyo-chain {
  position: absolute;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: "VT323", monospace;
  font-size: 36px;
  color: #fff36f;
  text-shadow: 0 0 12px #fff36f, 0 0 24px #e0464a;
  pointer-events: none;
  z-index: 5;
  animation: chainPop 0.6s ease-out;
}
@keyframes chainPop {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  40% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.puyo-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 12px;
  background: rgba(5, 4, 2, 0.85);
  font-family: "VT323", monospace;
  text-align: center;
  z-index: 10;
}
.puyo-overlay .big {
  font-size: 36px; color: #ffd97a;
  letter-spacing: 0.06em;
  text-shadow: 0 0 16px rgba(255, 90, 30, 0.7);
}
.puyo-overlay .big.start {
  font-size: 44px;
  letter-spacing: 0.12em;
  color: #ff7aa8;
  text-shadow: 0 0 18px rgba(255, 122, 168, 0.7), 0 0 36px rgba(255, 90, 30, 0.4);
}
.puyo-overlay .small {
  font-size: 16px; color: #f5c878;
  font-family: "JetBrains Mono", monospace;
  letter-spacing: 0.15em;
}
.puyo-overlay .restart {
  margin-top: 4px;
  appearance: none;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.15em;
  padding: 8px 14px;
  background: #ffd97a;
  color: #15110a;
  border: none;
  cursor: pointer;
  border-radius: 2px;
}

.puyo-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 84px;
}
.puyo-next-lbl {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: #f5c878;
  opacity: 0.8;
}
.puyo-next {
  display: grid;
  grid-template-rows: repeat(2, 1fr);
  width: 38px;
  border: 1px solid #4d3a2a;
  background: #110d08;
}
.puyo-next .cell {
  border: none;
}
.puyo-next.dim { opacity: 0.5; }
.puyo-btn {
  appearance: none;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  padding: 6px 8px;
  background: #110d08;
  color: #f5c878;
  border: 1px solid #4d3a2a;
  cursor: pointer;
  margin-top: auto;
  border-radius: 2px;
}
.puyo-btn:hover { background: #2a1f12; }

.puyo-pad {
  display: none;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 12px;
}
.puyo-pad button {
  appearance: none;
  background: #2a1f12;
  color: #f5c878;
  border: 1px solid #4d3a2a;
  padding: 14px 0;
  font-size: 18px;
  font-family: "JetBrains Mono", monospace;
  border-radius: 4px;
  cursor: pointer;
}
.puyo-pad button:active { background: #4d3a2a; }

@media (max-width: 820px) {
  .puyo-pad { display: grid; }
  .puyo-board { max-width: 100%; }
}
