/* Four in a Row board – only what's specific to this game.
   Header, difficulty, score and status come from /css/style.css. */

/* The holder sits in a centred column, so it needs its own width;
   without one it shrinks to nothing and takes the board with it. */
.c4-holder {
  width: min(100%, 448px);
}

.c4-frame {
  position: relative;
  width: 100%;
}

/* Fixed 7 × 6 grid: cells are always equal, whatever's in them */
.c4-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 6px;
  aspect-ratio: 7 / 6;
  padding: 8px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
}

.c4-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 50%;
  background: var(--inset);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35);
}

/* The disc floats inside its hole, so it can't resize the grid */
.c4-disc {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
}

.c4-disc.is-mine {
  background: var(--accent);
}

.c4-disc.is-theirs {
  background: var(--text);
}

.c4-disc.is-preview {
  background: var(--accent);
  opacity: 0.25;
}

.c4-disc.is-dropping {
  animation: c4-drop calc(220ms + var(--fall) * 55ms) linear;
}

/* Falls (speeding up), lands, bounces a little, settles */
@keyframes c4-drop {
  0% {
    /* each row is the disc's height plus the gap between holes */
    transform: translateY(calc(var(--fall) * -122%));
    animation-timing-function: cubic-bezier(0.5, 0, 1, 1);
  }
  70% {
    transform: translateY(0);
    animation-timing-function: ease-out;
  }
  84% {
    transform: translateY(-9%);
    animation-timing-function: ease-in;
  }
  100% {
    transform: translateY(0);
  }
}

/* When someone wins, the winning four stand out */
.c4-board.is-over .c4-disc:not(.is-win) {
  opacity: 0.4;
}

.c4-disc.is-win {
  box-shadow: 0 0 0 3px var(--surface-2), 0 0 0 6px var(--accent);
  animation: c4-win 0.8s ease-in-out 3;
}

/* The disc that won it: drops first, then joins the pulse */
.c4-disc.is-dropping.is-win {
  animation: c4-drop calc(220ms + var(--fall) * 55ms) linear, c4-win 0.8s ease-in-out 0.6s 3;
}

@keyframes c4-win {
  50% { transform: scale(0.85); }
}

/* Invisible column buttons on top of the board */
.c4-columns {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 0 4px;
}

.c4-column {
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.c4-column:not(:disabled):hover {
  background: var(--hover-tint);
}

.c4-column:disabled {
  cursor: default;
}

.c4-column:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Score labels: coloured dot instead of X / O */
.c4-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 2px;
  border-radius: 50%;
  vertical-align: 0;
}

.c4-dot.is-mine {
  background: var(--accent);
}

.c4-dot.is-theirs {
  background: var(--text);
}

@media (prefers-reduced-motion: reduce) {
  .c4-disc.is-dropping,
  .c4-disc.is-win {
    animation: none;
  }
}

/* Phone held sideways: fit the screen height (see css/style.css) */
@media (orientation: landscape) and (max-height: 540px) {
  .c4-holder { width: min(448px, var(--play-w), calc(var(--play-h) * 1.17)); }
}
