/* Four in a Row. Every selector starts with .g-four-in-a-row so it cannot clash with other games. */

.g-four-in-a-row {
  /* Board width. It fills the game area, but on a narrow phone it grows past the card's
     side padding (stopping 8px from each screen edge) so every column stays at least
     42px wide on a 320px screen. On wide screens it stops at 448px. */
  --fr-w: min(448px, max(100%, min(100vw - 16px, 336px)));
}
.g-four-in-a-row [hidden] { display: none !important; }

/* ---------- opponent ladder ---------- */
.g-four-in-a-row .fr-levels { grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0 0 8px; }
.g-four-in-a-row .fr-lv {
  aspect-ratio: auto; min-height: 50px; padding: 6px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  color: var(--text);
}
.g-four-in-a-row .fr-lv-n { font-size: .66rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.g-four-in-a-row .fr-lv-name { font-size: .95rem; }
.g-four-in-a-row .fr-order { margin: 0 0 10px; }
.g-four-in-a-row .fr-order-l { font-weight: 700; font-size: .9rem; color: var(--muted); }
.g-four-in-a-row .fr-best { flex-basis: 100%; text-align: center; font-size: .85rem; font-weight: 700; color: var(--muted); }
@media (min-width: 540px) {
  .g-four-in-a-row .fr-levels { grid-template-columns: repeat(6, 1fr); }
}

/* ---------- status pills ---------- */
.g-four-in-a-row .fr-pill { align-items: center; }
.g-four-in-a-row .fr-pill.turn { box-shadow: inset 0 0 0 2px var(--accent); }
.g-four-in-a-row .fr-arrow { color: var(--accent); font-size: .8rem; }
.g-four-in-a-row .fr-chip {
  position: relative; display: inline-block; flex: none;
  width: 15px; height: 15px; border-radius: 50%; background: var(--accent);
}
.g-four-in-a-row .fr-chip.is-cpu { background: var(--text); }
.g-four-in-a-row .fr-chip.is-cpu::after {
  content: ''; position: absolute; inset: 3px; border-radius: 50%; border: 1.5px solid var(--surface);
}

/* ---------- board: seven columns, each one a big button ---------- */
.g-four-in-a-row .fr-board {
  display: grid; grid-template-columns: repeat(7, 1fr);
  width: var(--fr-w); margin: 0 0 0 calc((100% - var(--fr-w)) / 2);
  padding: 3px; border-radius: 14px; overflow: hidden;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1.5px var(--border);
}
.g-four-in-a-row .fr-col {
  appearance: none; -webkit-appearance: none;
  display: flex; flex-direction: column-reverse; /* row 0 sits at the bottom */
  min-width: 0; margin: 0; padding: 0; border: 0; border-radius: 10px;
  background: transparent; cursor: default;
}
.g-four-in-a-row .fr-col:focus-visible { outline-offset: -3px; }
.g-four-in-a-row .fr-col.full { cursor: not-allowed; }
.g-four-in-a-row .fr-board.my-turn .fr-col { cursor: pointer; }
.g-four-in-a-row .fr-board.my-turn .fr-col.full { cursor: not-allowed; }
.g-four-in-a-row .fr-board.my-turn .fr-col:active { background: color-mix(in srgb, var(--accent) 16%, transparent); }

.g-four-in-a-row .fr-cell { position: relative; display: block; width: 100%; aspect-ratio: 1; }
/* the empty hole */
.g-four-in-a-row .fr-cell::before {
  content: ''; position: absolute; inset: 8%; border-radius: 50%;
  background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--border);
}
/* where your disc would land in the column you are pointing at */
.g-four-in-a-row .fr-board.my-turn .fr-col:focus-visible .fr-cell.land::before { box-shadow: inset 0 0 0 3px var(--accent); }
@media (hover: hover) {
  .g-four-in-a-row .fr-board.my-turn .fr-col:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
  .g-four-in-a-row .fr-board.my-turn .fr-col:hover .fr-cell.land::before { box-shadow: inset 0 0 0 3px var(--accent); }
}

/* ---------- discs ----------
   Yours are the plain accent colour. The computer's carry a ring, so the two sides can
   be told apart without relying on colour. The disc element is the size of its cell, so
   the fall distance is a whole number of cells. */
.g-four-in-a-row .fr-disc { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.g-four-in-a-row .fr-disc::before {
  content: ''; position: absolute; inset: 8%; border-radius: 50%; background: var(--accent);
}
.g-four-in-a-row .fr-disc.is-cpu::before { background: var(--text); }
.g-four-in-a-row .fr-disc.is-cpu::after {
  content: ''; position: absolute; inset: 29%; border-radius: 50%; border: 2px solid var(--surface);
}
/* the last disc dropped has a pale rim */
.g-four-in-a-row .fr-cell.last .fr-disc::before { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--surface) 60%, transparent); }

.g-four-in-a-row .fr-disc.drop { animation: g-four-in-a-row-drop var(--fr-ms, 280ms) cubic-bezier(.45, 0, .85, .6); }
@keyframes g-four-in-a-row-drop { from { transform: translateY(calc(var(--fr-rows, 6) * -100%)); } }

/* ---------- the winning four: a star and a rim, everything else fades ---------- */
.g-four-in-a-row .fr-cell.win::after {
  content: '★'; position: absolute; inset: 0; z-index: 2; display: grid; place-items: center;
  font-size: clamp(12px, 3.6vw, 19px); line-height: 1; color: var(--accent-ink); pointer-events: none;
}
.g-four-in-a-row .fr-cell.win.cpu::after { color: var(--surface); }
.g-four-in-a-row .fr-cell.win .fr-disc.is-cpu::after { display: none; }
.g-four-in-a-row .fr-cell.win .fr-disc::before { box-shadow: 0 0 0 3px var(--good); }
.g-four-in-a-row .fr-cell.win .fr-disc { animation: g-four-in-a-row-pulse .45s ease-out 2; }
.g-four-in-a-row .fr-board.has-win .fr-cell:not(.win) .fr-disc { opacity: .38; }
@keyframes g-four-in-a-row-pulse { 50% { transform: scale(1.1); } }

@media (prefers-reduced-motion: reduce) {
  .g-four-in-a-row .fr-disc.drop,
  .g-four-in-a-row .fr-cell.win .fr-disc { animation: none; }
}

/* ---------- text under the board ---------- */
.g-four-in-a-row .fr-note { margin: 10px 0 4px; font-weight: 700; color: var(--text); }
.g-four-in-a-row .fr-ctrl { margin: 8px 0 4px; }
.g-four-in-a-row .fr-rules { margin: 8px 0 0; font-size: .88rem; }
