/* Four in a Row (dortlu) — chunky navy frame with see-through holes, coral / blue discs.
 * Geometry: .d4-board is exactly the 7×6 grid of square cells; the frame rim around it is the spread shadow
 * of the holes overlay (painted above the discs), so a falling disc slides "behind" the frame. */
.d4-wrap {
  --d4-frame: #27344f; --d4-frame-hi: #3a4a70; --d4-frame-lo: #161f33; --d4-hole: var(--surface-2);
  --d4-p0: var(--brand); --d4-p0-lo: #d94e2f; --d4-p1: var(--blue); --d4-p1-lo: #2a5bc4;
  --d4-pad: 12px;
  width: min(100%, 520px, max(280px, calc(100vh - 250px)));
}
:root[data-theme="dark"] .d4-wrap { --d4-frame: #2c3a58; --d4-frame-hi: #44567f; --d4-frame-lo: #0c111b; --d4-hole: #0d1219; --d4-p0-lo: #c94a2c; --d4-p1-lo: #3466d1; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .d4-wrap { --d4-frame: #2c3a58; --d4-frame-hi: #44567f; --d4-frame-lo: #0c111b; --d4-hole: #0d1219; --d4-p0-lo: #c94a2c; --d4-p1-lo: #3466d1; }
}
.d4-stage { width: 100%; padding: 0 var(--d4-pad) calc(var(--d4-pad) + 8px); box-sizing: border-box; }

/* hand row above the board: the disc you are about to drop */
.d4-hand { position: relative; width: 100%; aspect-ratio: 7 / 1; margin-bottom: var(--d4-pad); }
.d4-disc.d4-float { position: absolute; top: 0; left: 0; width: calc(100% / 7); height: 100%; opacity: 0; transform: translateY(-12%) scale(.8); transition: left .14s var(--ease), opacity .15s, transform .2s var(--spring); pointer-events: none; }
.d4-disc.d4-float.on { opacity: 1; transform: translateY(0) scale(.84); animation: d4bob .9s ease-in-out infinite alternate; }
@keyframes d4bob { to { transform: translateY(-8%) scale(.84); } }

.d4-board { position: relative; width: 100%; aspect-ratio: 7 / 6; border-radius: 6px; background: var(--d4-hole); }
.d4-board::before { content: ""; position: absolute; inset: calc(-1 * var(--d4-pad)); border-radius: calc(var(--d4-pad) + 6px); pointer-events: none; z-index: 0;
  box-shadow: 0 8px 0 var(--d4-frame-lo), 0 20px 30px -12px rgba(10, 16, 30, .5); transition: box-shadow .3s; }
.d4-discs, .d4-holes, .d4-marks { position: absolute; inset: 0; }
.d4-discs { display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(6, 1fr); z-index: 1; }
.d4-holes { z-index: 3; pointer-events: none; border-radius: 6px;
  background-image: radial-gradient(circle closest-side, transparent 79%, rgba(0, 0, 0, .4) 80%, var(--d4-frame) 90%);
  background-size: calc(100% / 7) calc(100% / 6);
  box-shadow: 0 0 0 var(--d4-pad) var(--d4-frame); }
.d4-holes::after { content: ""; position: absolute; inset: calc(-1 * var(--d4-pad)); border-radius: calc(var(--d4-pad) + 6px); pointer-events: none;
  box-shadow: inset 0 2px 0 var(--d4-frame-hi), inset 0 -3px 0 rgba(0, 0, 0, .28); }
.d4-marks { z-index: 4; pointer-events: none; display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(6, 1fr); }

.d4-slot { position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; }
.d4-slot.falling { z-index: 2; will-change: transform; }
.d4-disc { width: 86%; aspect-ratio: 1; border-radius: 50%; position: relative; }
.d4-disc.p0 { background: radial-gradient(circle, var(--d4-p0) 0 50%, var(--d4-p0-lo) 51% 58%, var(--d4-p0) 59%); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18), inset 0 3px 0 rgba(255, 255, 255, .3); }
.d4-disc.p1 { background: radial-gradient(circle, var(--d4-p1) 0 50%, var(--d4-p1-lo) 51% 58%, var(--d4-p1) 59%); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .2), inset 0 3px 0 rgba(255, 255, 255, .3); }

/* last move: a small white ring in the middle of the disc */
.d4-slot.last .d4-disc::after { content: ""; position: absolute; left: 50%; top: 50%; width: 24%; height: 24%; border-radius: 50%; transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, .95); box-shadow: 0 0 0 2px rgba(0, 0, 0, .1); animation: d4ringin .35s var(--spring); }
@keyframes d4ringin { from { transform: translate(-50%, -50%) scale(0); } }

/* landing preview: dashed ring in the cell the disc will fall into */
.d4-ghost { position: absolute; z-index: 2; left: 0; top: 0; width: calc(100% / 7); height: calc(100% / 6); display: grid; place-items: center; opacity: 0; pointer-events: none; transition: opacity .12s; }
.d4-ghost::before { content: ""; width: 66%; aspect-ratio: 1; border-radius: 50%; border: 4px dashed currentColor; box-sizing: border-box; }
.d4-ghost.p0 { color: var(--d4-p0); }
.d4-ghost.p1 { color: var(--d4-p1); }
.d4-ghost.on { opacity: .9; }
.d4-ghost.on::before { animation: d4spin 7s linear infinite; }
@keyframes d4spin { to { transform: rotate(360deg); } }

/* column buttons: the whole column (and the hand cell above it) is the target */
.d4-cols { position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; top: calc(-100% / 6 - var(--d4-pad)); display: grid; grid-template-columns: repeat(7, 1fr); touch-action: pan-y; }
.d4-col { appearance: none; -webkit-appearance: none; border: 0; margin: 0; padding: 0; background: transparent; border-radius: 10px; cursor: default; min-width: 0; -webkit-tap-highlight-color: transparent; transition: background .12s; }
.d4-col.can { cursor: pointer; }
.d4-col.hot { background: linear-gradient(to bottom, transparent 0, rgba(255, 255, 255, .04) 15%, rgba(255, 255, 255, .08)); }
.d4-col:focus { outline: none; }
.d4-col:focus-visible { box-shadow: inset 0 0 0 3px var(--d4-p0); }
.d4-wrap.p1 .d4-col:focus-visible { box-shadow: inset 0 0 0 3px var(--d4-p1); }

/* turn cue: a soft halo in your colour around the frame while it is your move */
.d4-wrap.mine .d4-board::before { box-shadow: 0 8px 0 var(--d4-frame-lo), 0 0 0 4px var(--brand-soft), 0 0 0 1px color-mix(in srgb, var(--d4-p0) 45%, transparent), 0 20px 30px -12px rgba(10, 16, 30, .5); }
.d4-wrap.mine.p1 .d4-board::before { box-shadow: 0 8px 0 var(--d4-frame-lo), 0 0 0 4px var(--blue-soft), 0 0 0 1px color-mix(in srgb, var(--d4-p1) 45%, transparent), 0 20px 30px -12px rgba(10, 16, 30, .5); }

/* end of the game: rings over the winning discs (above the frame), the other discs fade */
.d4-slot.dim .d4-disc { opacity: .5; filter: saturate(.55); transition: opacity .5s .3s, filter .5s .3s; }
.d4-mark { display: grid; place-items: center; min-width: 0; min-height: 0; }
.d4-mark::before { content: ""; width: 82%; aspect-ratio: 1; border-radius: 50%; box-sizing: border-box; border: 4px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .15), 0 0 16px 4px rgba(255, 214, 102, .85), inset 0 0 10px 2px rgba(255, 214, 102, .6);
  animation: d4markin .45s var(--spring) both, d4pulse .8s .45s ease-in-out infinite alternate; animation-delay: var(--d, 0s), calc(var(--d, 0s) + .45s); }
@keyframes d4markin { from { transform: scale(.2); opacity: 0; } }
@keyframes d4pulse { to { transform: scale(1.08); box-shadow: 0 0 0 2px rgba(0, 0, 0, .15), 0 0 24px 8px rgba(255, 214, 102, .95), inset 0 0 12px 3px rgba(255, 214, 102, .7); } }

@media (max-width: 560px) {
  .d4-wrap { --d4-pad: 8px; width: 100%; }
  .d4-ghost::before { border-width: 3px; }
  .d4-mark::before { border-width: 3px; }
  .d4-slot.last .d4-disc::after { border-width: 2.5px; }
}
@media (prefers-reduced-motion: reduce) {
  .d4-disc.d4-float.on, .d4-ghost.on::before, .d4-mark::before { animation: none; }
  .d4-disc.d4-float, .d4-col, .d4-ghost, .d4-board::before, .d4-slot.dim .d4-disc { transition: none; }
  .d4-slot.last .d4-disc::after { animation: none; }
}
