/* Dört Bir Sırada (dort): candy connect-four, two players on one device.
   JS sets on .d4: --gap, --bw (landscape badge width), --bh (portrait badge height), --bc (badge candy), --bf (badge font).
   JS sets on .d4-wrap: --cell, --cs (candy size) and its pixel width/height. */

.d4 {
  position: absolute; inset: 0;
  display: grid; gap: var(--gap, 12px);
  padding: var(--gap, 12px);
}
.d4.d4-port {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: var(--bh, 90px) minmax(0, 1fr);
  grid-template-areas: "b1 b2" "board board";
}
.d4.d4-land {
  grid-template-columns: var(--bw, 160px) minmax(0, 1fr) var(--bw, 160px);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "b1 board b2";
}
.d4-area { grid-area: board; display: grid; place-items: center; min-width: 0; min-height: 0; }

/* ---------- player badges ---------- */
.d4-badge {
  --pc: var(--red);
  position: relative; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 6px 10px;
  background: var(--white); border: var(--outline); border-radius: var(--r-md);
  box-shadow: 0 6px 0 var(--navy);
  opacity: .5; filter: saturate(.55);
  transform: scale(.92);
  transition: transform .4s cubic-bezier(.2, 1.6, .4, 1), opacity .25s ease, filter .25s ease, box-shadow .25s ease;
}
.d4-badge.b1 { grid-area: b1; }
.d4-badge.b2 { grid-area: b2; --pc: #FFD400; }
.d4-land .d4-badge { flex-direction: column; align-self: center; padding: 14px 8px 12px; gap: 4px; }
.d4-badge.on {
  opacity: 1; filter: none;
  transform: scale(1.05);
  box-shadow: 0 6px 0 var(--navy), 0 0 0 5px var(--pc);
  animation: d4-badge-glow 1.3s ease-in-out infinite;
}
@keyframes d4-badge-glow {
  0%, 100% { box-shadow: 0 6px 0 var(--navy), 0 0 0 4px var(--pc), 0 0 0 4px var(--pc); }
  50% { box-shadow: 0 6px 0 var(--navy), 0 0 0 6px var(--pc), 0 0 22px 10px var(--pc); }
}
.d4-badge-art { flex: none; width: var(--bc, 60px); height: var(--bc, 60px); }
.d4-badge-art img { width: 100%; height: 100%; display: block; }
.d4-badge.on .d4-badge-art img { animation: d4-wobble 1s ease-in-out infinite; }
@keyframes d4-wobble {
  0%, 100% { transform: rotate(-9deg) scale(1); }
  50% { transform: rotate(9deg) scale(1.1); }
}
.d4-badge.bump .d4-badge-art { animation: d4-bump .55s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes d4-bump { 0% { transform: scale(1); } 35% { transform: scale(1.45) rotate(-10deg); } 100% { transform: scale(1); } }
.d4-badge-txt { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.d4-land .d4-badge-txt, .d4-stack .d4-badge-txt { align-items: center; }
.d4-stack .d4-badge { flex-direction: column; gap: 2px; padding: 4px 6px; }
.d4-badge-name { font-size: var(--bf, 20px); font-weight: 900; line-height: 1.05; white-space: nowrap; }
.d4-badge-wins {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: calc(var(--bf, 20px) * 1.05); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums;
}
.d4-badge-wins svg { width: calc(var(--bf, 20px) * 1.15); height: calc(var(--bf, 20px) * 1.15); }

.d4-pill-c { width: 32px; height: 32px; display: block; margin-left: -4px; animation: d4-wobble 1.1s ease-in-out infinite; }

/* ---------- board ---------- */
.d4-wrap {
  position: relative; isolation: isolate;
  cursor: pointer; touch-action: none;
}
.d4-wrap.thud { animation: d4-thud .22s ease-out; }
@keyframes d4-thud { 30% { transform: translateY(3px); } 100% { transform: none; } }
.d4-back, .d4-front, .d4-line { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; display: block; }
.d4-back { z-index: 1; }
.d4-glows { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.d4-pieces { position: absolute; inset: 0; pointer-events: none; } /* no z-index: pieces join the wrap stacking context */
.d4-front { z-index: 4; }
.d4-line { z-index: 6; filter: drop-shadow(0 0 6px rgba(255, 255, 255, .8)); }

/* pieces */
.d4-pc {
  position: absolute; left: 0; top: 0; z-index: 3;
  width: var(--cs); height: var(--cs);
  margin: calc(var(--cs) / -2) 0 0 calc(var(--cs) / -2);
  will-change: transform;
}
.d4-pc img { width: 100%; height: 100%; display: block; transition: filter .35s ease, opacity .35s ease; }
.d4-pc.dim img { filter: brightness(.5) saturate(.45); }
.d4-pc.win { z-index: 7; }
.d4-pc.win img {
  animation: d4-winspin 1.15s ease-in-out infinite;
  filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 12px var(--yellow));
}
@keyframes d4-winspin {
  0% { transform: scale(1) rotateY(0deg); }
  25% { transform: scale(1.32) rotateY(90deg); }
  50% { transform: scale(1.18) rotateY(180deg); }
  75% { transform: scale(1.32) rotateY(270deg); }
  100% { transform: scale(1) rotateY(360deg); }
}
.d4-pc.wiggle img { animation: d4-wiggle .5s ease-in-out infinite; }
@keyframes d4-wiggle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) scale(1.05); } }

/* tension glows: an open hole that would complete four */
.d4-glow {
  position: absolute; left: 0; top: 0;
  width: calc(var(--cell) * 1.05); height: calc(var(--cell) * 1.05);
  margin: calc(var(--cell) * -.525) 0 0 calc(var(--cell) * -.525);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .95) 0 14%, var(--gc) 42%, transparent 70%);
  animation: d4-glow 1.1s ease-in-out infinite alternate;
}
.d4-glow.p1 { --gc: rgba(224, 36, 26, .95); }
.d4-glow.p2 { --gc: rgba(255, 212, 0, .95); }
.d4-glow.alt { animation-delay: -1.1s; }
@keyframes d4-glow { from { opacity: .25; transform: scale(.75); } to { opacity: 1; transform: scale(1); } }

/* column highlight (on top of the panel) */
.d4-colhl {
  position: absolute; left: 0; top: 0; z-index: 5;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .75);
  opacity: 0; pointer-events: none;
  transition: transform .14s cubic-bezier(.3, 1.4, .5, 1), opacity .15s ease;
}
.d4-colhl.on { opacity: 1; }
.d4-colhl.full { background: rgba(224, 36, 26, .22); box-shadow: inset 0 0 0 3px rgba(224, 36, 26, .9); }
.d4-colhl.no { animation: d4-no .36s ease; }
@keyframes d4-no { 20% { margin-left: -6px; } 40% { margin-left: 6px; } 60% { margin-left: -4px; } 80% { margin-left: 3px; } }

/* ghost candy above the board */
.d4-ghost {
  position: absolute; left: 0; top: 0; z-index: 8;
  width: var(--cs); height: var(--cs);
  margin: calc(var(--cs) / -2) 0 0 calc(var(--cs) / -2);
  pointer-events: none;
  transition: transform .14s cubic-bezier(.3, 1.4, .5, 1), opacity .15s ease;
}
.d4-ghost.hide { opacity: 0; transition: none; }
.d4-ghost-bob { width: 100%; height: 100%; animation: d4-bob 1.1s ease-in-out infinite; }
.d4-ghost img {
  width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 4px 0 rgba(42, 36, 102, .45));
  transition: transform .18s cubic-bezier(.2, 1.6, .4, 1);
}
.d4-ghost.lift img { transform: scale(1.18) translateY(-6%); }
.d4-ghost img.spawn { animation: d4-spawn .45s cubic-bezier(.2, 1.7, .4, 1); }
.d4-ghost img.no { animation: d4-shakeimg .36s ease; }
@keyframes d4-bob { 0%, 100% { transform: translateY(-5%); } 50% { transform: translateY(5%); } }
@keyframes d4-spawn { 0% { transform: scale(0) rotate(-120deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes d4-shakeimg {
  20% { transform: translateX(-18%) rotate(-10deg); } 40% { transform: translateX(16%) rotate(8deg); }
  60% { transform: translateX(-10%) rotate(-5deg); } 80% { transform: translateX(6%); }
}

@media (prefers-reduced-motion: reduce) {
  .d4-badge.on, .d4-badge.on .d4-badge-art img, .d4-pill-c, .d4-ghost-bob, .d4-wrap.thud { animation: none; }
  .d4-pc.win img { animation-duration: 2.4s; }
  .d4-glow { animation-duration: 2.2s; }
}

/* Grow the active badge inward so its ring stays on screen. */
.d4-badge.b1 { transform-origin: left center; }
.d4-badge.b2 { transform-origin: right center; }
