/* ---- The Four in a Row table ---- */
#four {
  max-width: 760px; margin: 0 auto;
  --fr-frame: var(--t13); /* the frame of the grid: the same wood as the other boards */
  --fr-frame-edge: var(--t14);
  --fr-gold: var(--accent);
  --fr-red: #d8322c;
}
#fr-title { text-align: center; font-weight: 700; font-size: 0.9rem; padding: 0 48px; min-height: 1.3em; margin-bottom: 6px; }
/* The grid is a little wider than it is tall; on a low screen it is the height that decides its size. */
#fr-board-wrap, #four .fr-bar { width: min(100%, 520px, calc((100dvh - 350px) * 1.16)); min-width: 250px; margin-left: auto; margin-right: auto; }

/* The grid stands upright: a frame with seven columns of six round holes, the discs behind it. */
#fr-ghost-space { display: none; }
#fr-board {
  position: relative; box-sizing: border-box; width: 100%; aspect-ratio: 7 / 6;
  border: 8px solid var(--fr-frame); border-bottom-width: 6px; border-radius: 16px 16px 0 0;
  background: #07090b; /* what shows through an empty hole */
  box-shadow: 0 0 0 1.5px var(--fr-frame-edge), 0 8px 26px rgba(0, 0, 0, 0.55);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
#fr-base { height: 12px; border-radius: 0 0 10px 10px; background: var(--fr-frame-edge); box-shadow: 0 0 0 1.5px var(--fr-frame-edge), 0 8px 18px rgba(0, 0, 0, 0.5); }
#fr-discs, #fr-holes, #fr-line, #fr-cols { position: absolute; inset: 0; }
#fr-discs { overflow: hidden; z-index: 1; }
#fr-holes { z-index: 2; display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(6, 1fr); pointer-events: none; }
/* One place: the frame with a round hole in it, and a shadow just inside the rim. */
#four .fr-hole { background: radial-gradient(circle closest-side, transparent 74%, rgba(0, 0, 0, 0.55) 76%, rgba(0, 0, 0, 0.3) 81%, var(--fr-frame-edge) 83%, var(--fr-frame) 88%); }
/* A sheen over the whole frame, lighter at the top. */
#fr-holes::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 30%, rgba(0, 0, 0, 0.12)); pointer-events: none; }

/* Discs: seat 0 plays gold, seat 1 plays red. The red ones carry a white ring as well. */
#four .fr-disc { position: absolute; width: calc(100% / 7); height: calc(100% / 6); }
#four .fr-chip { position: absolute; inset: 6%; border-radius: 50%; }
#four .fr-s0 .fr-chip, #four .fr-dot.fr-s0 { background: var(--fr-gold); background: radial-gradient(circle at 36% 30%, color-mix(in srgb, var(--fr-gold) 55%, #fff), var(--fr-gold) 48%, color-mix(in srgb, var(--fr-gold) 62%, #000)); }
#four .fr-s1 .fr-chip, #four .fr-dot.fr-s1 { background: var(--fr-red); background: radial-gradient(circle at 36% 30%, #ff9a86, var(--fr-red) 48%, #8a1512); }
#four .fr-s1 .fr-chip::after, #four .fr-dot.fr-s1::after { content: ''; position: absolute; inset: 27%; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.92); box-sizing: border-box; }
/* The disc played last: a dot in its middle. */
#four .fr-disc.fr-last .fr-chip::before { content: ''; position: absolute; inset: 42%; border-radius: 50%; background: #1b1b1b; box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.55); }
#four .fr-disc.fr-s1.fr-last .fr-chip::before { background: #fff; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.35); }
/* It falls from the top of the grid, and bounces once or twice. */
#four .fr-disc.fr-fall { animation: fr-fall var(--fr-ms, 500ms) linear both; }
@keyframes fr-fall {
  0% { transform: translateY(var(--fr-from, -600%)); animation-timing-function: cubic-bezier(0.45, 0, 0.9, 0.6); }
  60% { transform: translateY(0); animation-timing-function: ease-out; }
  74% { transform: translateY(calc(var(--fr-from, -600%) * 0.075)); animation-timing-function: ease-in; }
  87% { transform: translateY(0); animation-timing-function: ease-out; }
  94% { transform: translateY(calc(var(--fr-from, -600%) * 0.02)); animation-timing-function: ease-in; }
  100% { transform: translateY(0); }
}
/* Four in a row: those discs pulse, the others step back, and a line is drawn through the four. */
#fr-board.fr-won .fr-disc:not(.fr-win) .fr-chip { filter: saturate(0.55) brightness(0.55); transition: filter 0.5s 0.4s; }
#four .fr-disc.fr-win .fr-chip { animation: fr-pulse 0.75s ease-in-out 0.5s infinite alternate; }
@keyframes fr-pulse { to { filter: brightness(1.4); box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.85); } }
#fr-line { z-index: 3; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#fr-line line { stroke: #fff; stroke-width: 0.13; stroke-linecap: round; opacity: 0.92; stroke-dasharray: 1; stroke-dashoffset: 1; animation: fr-draw 0.45s ease-out var(--fr-wait, 0ms) forwards; }
@keyframes fr-draw { to { stroke-dashoffset: 0; } }

/* The seven columns to tap. */
#fr-cols { z-index: 4; display: grid; grid-template-columns: repeat(7, 1fr); }
#four .fr-col { position: relative; min-width: 0; min-height: 0; height: 100%; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#four .fr-col:disabled { cursor: default; opacity: 1; }
#four .fr-col:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
@media (hover: hover) {
  /* With a mouse: the column lights up, and a ghost of my disc waits above it. */
  #fr-ghost-space { display: block; height: 0; padding-top: 14.3%; }
  #four .fr-col:not(:disabled):hover { background: linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.03)); }
  #four .fr-col::before { content: ''; position: absolute; left: 9%; right: 9%; bottom: calc(100% + 11px); aspect-ratio: 1; border-radius: 50%; opacity: 0; transform: translateY(-6px); transition: opacity 0.12s, transform 0.12s; pointer-events: none; }
  #fr-board.fr-me-0 .fr-col::before { background: radial-gradient(circle at 36% 30%, color-mix(in srgb, var(--fr-gold) 55%, #fff), var(--fr-gold) 48%, color-mix(in srgb, var(--fr-gold) 62%, #000)); }
  #fr-board.fr-me-1 .fr-col::before { background: radial-gradient(circle closest-side, transparent 30%, rgba(255, 255, 255, 0.92) 32%, rgba(255, 255, 255, 0.92) 42%, transparent 44%), radial-gradient(circle at 36% 30%, #ff9a86, var(--fr-red) 48%, #8a1512); }
  #four .fr-col:not(:disabled):hover::before, #four .fr-col:not(:disabled):focus-visible::before { opacity: 0.8; transform: none; }
}

/* The two players: picture, disc colour, name, whose move, the countdown and games won. */
#four .fr-bar { position: relative; box-sizing: border-box; display: flex; align-items: center; gap: 8px; margin-top: 8px; margin-bottom: 8px; padding: 5px 8px; border-radius: 12px; min-height: 48px; border: 1px solid transparent; }
#four .fr-bar.fr-on { border-color: var(--accent); background: rgba(255, 255, 255, 0.06); }
#four .fr-bar.fr-vacant { cursor: pointer; }
#four .fr-bar.fr-vacant .fr-name { text-decoration: underline; }
#four .fr-cam { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: #000; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6); flex: none; transform: none; /* my own picture is shown as the others see it, not mirrored */ }
#four .fr-cam.blank { display: none; }
#four .fr-dot { position: relative; width: 22px; height: 22px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.55); }
#four .fr-dot.fr-s1::after { border-width: 2px; inset: 24%; }
#four .fr-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
#four .fr-ready { font-size: 0.72rem; color: #1b1b1b; background: var(--t15); border-radius: 999px; padding: 1px 8px; font-weight: 700; flex: none; }
#four .fr-stats { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; font-variant-numeric: tabular-nums; }
#four .fr-turn { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }
#four .fr-clock { font-weight: 700; font-size: 0.95rem; padding: 2px 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.45); min-width: 2.6em; text-align: center; }
#four .fr-clock.fr-low { background: var(--danger); color: #fff; }
#four .fr-score { font-weight: 800; font-size: 1.1rem; padding: 2px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.45); min-width: 1.2em; text-align: center; }
/* The time left, as a thin line along the bottom of the bar. */
#four .fr-left { position: absolute; left: 10px; bottom: 1px; height: 3px; max-width: calc(100% - 20px); border-radius: 2px; background: var(--accent); transition: width 0.2s linear; pointer-events: none; }
#four .fr-left.fr-low { background: var(--danger); }
#four .fr-bubble { position: absolute; left: 8px; top: calc(100% + 4px); z-index: 6; max-width: min(320px, 86%); background: #fdfdfd; color: #161616; border-radius: 12px; padding: 7px 11px; font-size: 0.88rem; font-weight: 600; line-height: 1.25; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5); pointer-events: none; }
#four .fr-bubble::after { content: ''; position: absolute; left: 18px; top: -12px; border: 6px solid transparent; border-bottom-color: #fdfdfd; }
#four .fr-bubble.fr-up { top: auto; bottom: calc(100% + 4px); }
#four .fr-bubble.fr-up::after { top: auto; bottom: -12px; border-bottom-color: transparent; border-top-color: #fdfdfd; }
#four .fr-bubble.fr-pop { animation: fr-pop 0.22s ease-out; }
@keyframes fr-pop { from { transform: scale(0.7); opacity: 0; } }

/* Under the grid. */
#fr-status { text-align: center; font-weight: 700; min-height: 1.5em; margin: 6px 0 2px; }
#fr-note { text-align: center; min-height: 1.2em; margin: 0; }
#fr-error { text-align: center; min-height: 1.2em; margin: 0; }
#fr-result { text-align: center; margin: 6px auto; padding: 12px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--accent); max-width: 460px; box-sizing: border-box; animation: fr-pop 0.3s ease-out 0.5s backwards; }
#fr-result-text { font-weight: 800; font-size: 1.35rem; }
#fr-result.fr-won #fr-result-text { color: var(--t15); }
#fr-result.fr-lost { border-color: var(--danger); }
#fr-result.fr-drawn { border-color: var(--muted); }
#fr-result-how { margin: 2px 0 0; }
#fr-result .row { margin-top: 10px; }
#four .row { max-width: 460px; margin-left: auto; margin-right: auto; }
#four .row > button { min-height: 46px; }
#fr-setup p { text-align: center; margin: 6px 0; }
#fr-bot { margin-top: 10px; }
#fr-bot-levels { flex-wrap: wrap; justify-content: center; }
#fr-bot-levels button { flex: 1 1 150px; }

@media (max-width: 699px) {
  #four { padding-top: 46px; } /* room for the row of round buttons along the top */
  #fr-title { padding: 0; }
  #fr-board-wrap, #four .fr-bar { width: min(100%, calc((100dvh - 330px) * 1.16)); }
  #fr-board { border-width: 6px; border-bottom-width: 5px; border-radius: 12px 12px 0 0; }
  #fr-base { height: 9px; }
  #four .fr-bar { margin-top: 6px; margin-bottom: 6px; padding: 4px 6px; gap: 6px; }
  #four .fr-cam { width: 56px; height: 56px; }
  #four .fr-s1 .fr-chip::after { border-width: 2.5px; }
  #four .fr-score { font-size: 1rem; padding: 2px 8px; }
  #four .fr-stats { gap: 6px; }
  #four .fr-turn { font-size: 0.66rem; }
}

@media (prefers-reduced-motion: reduce) {
  #four .fr-disc.fr-fall, #four .fr-disc.fr-win .fr-chip, #four .fr-bubble.fr-pop, #fr-result { animation: none; }
  #four .fr-disc.fr-win .fr-chip { box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.85); }
  #fr-line line { animation: none; stroke-dashoffset: 0; }
  #four .fr-col::before, #fr-board.fr-won .fr-disc:not(.fr-win) .fr-chip { transition: none; }
}
