/*
 * The 4D games, on top of the site's Bootstrap theme (Vapor) and site.css.
 * Seat colours are always paired with a symbol or shape (spec §2).
 */

:root {
  --g4-seat0: #4cc9f0;
  --g4-seat1: #f72585;
  --g4-seat2: #ffd166;
  --g4-seat3: #06d6a0;
  --g4-panel: rgba(255, 255, 255, 0.05);
  --g4-line: rgba(255, 255, 255, 0.14);
  --g4-cell: rgba(255, 255, 255, 0.08);
  --g4-ink: #f4f1ff;
  --g4-muted: #b9b0d6;
  --g4-dark: #12062a;
}

.s0 { --seat: var(--g4-seat0); }
.s1 { --seat: var(--g4-seat1); }
.s2 { --seat: var(--g4-seat2); }
.s3 { --seat: var(--g4-seat3); }

/* ------------------------------------------------------------- layout -- */

.g4-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 1.5rem;
  align-items: start;
  margin-top: 1rem;
}
.g4-side {
  position: sticky;
  top: 4.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 1rem;
}
@media (max-width: 991.98px) {
  .g4-layout { grid-template-columns: minmax(0, 1fr); }
  .g4-side { position: static; max-width: 420px; margin: 0 auto; width: 100%; }
}

/* The advert, exactly as in the 4D Viewer's sidebar. */
.ad-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b7280;
  margin-bottom: 6px;
}
.g4-ad a { display: block; border-radius: 8px; overflow: hidden; transition: transform 0.15s; }
.g4-ad a:hover { transform: scale(1.02); }
.g4-ad img { display: block; width: 100%; height: auto; }
.g4-steam .wishlist-button { width: 100%; justify-content: center; font-size: 0.9rem; padding: 10px 14px; }
/* The 4D Viewer and Discord links, as two buttons (the separator between them is hidden). */
.g4-side-links { display: flex; gap: 0.5rem; margin: 0; font-size: 0; }
.g4-side-links a {
  flex: 1 1 0;
  display: flex; align-items: center; justify-content: center;
  min-height: 2.6rem; padding: 0.4rem 0.6rem;
  font-size: 0.95rem; font-weight: 700; text-align: center; text-decoration: none;
  color: #fff; border-radius: 8px;
  border: 1px solid rgba(80, 230, 255, 0.6);
  background: rgba(80, 230, 255, 0.12);
  transition: background 0.15s, transform 0.15s;
}
.g4-side-links a:hover { background: rgba(80, 230, 255, 0.25); transform: translateY(-1px); }
.g4-side-links a[href*="discord"] { border-color: #5865f2; background: rgba(88, 101, 242, 0.3); }
.g4-side-links a[href*="discord"]:hover { background: rgba(88, 101, 242, 0.5); }

.g4-message { padding: 3rem 0; text-align: center; font-size: 1.1rem; }

/* -------------------------------------------------------- front page -- */

/* The games, one tile each (a radio button), and the chosen game's board panel. */
.g4-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin: 0.75rem 0;
}
.g4-tile {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.7rem 0.85rem;
  background: var(--g4-panel);
  border: 1px solid var(--g4-line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.g4-tile:hover { border-color: rgba(255, 255, 255, 0.35); }
.g4-tile strong { font-size: 1.05rem; }
.g4-tile-blurb { font-size: 0.82rem; color: var(--g4-muted); }
.g4-tile:has(input:checked) {
  border-color: var(--g4-seat2);
  background: color-mix(in srgb, var(--g4-seat2) 12%, transparent);
  box-shadow: 0 0 0 1px var(--g4-seat2);
}
.g4-tile:has(input:focus-visible) { outline: 2px solid var(--g4-seat2); outline-offset: 2px; }
.g4-board-panel { display: grid; gap: 0.6rem; max-width: 34rem; }
.g4-game { display: grid; gap: 0.6rem; }
.g4-game[hidden] { display: none; }
.g4-game h3 { font-size: 1.3rem; margin: 0; }
.g4-game-blurb { margin: 0; font-size: 0.92rem; display: none; }
.g4-board-panel .g4-create { justify-self: start; }
@media (max-width: 767.98px) {
  /* Narrow screens: names only in the tiles; the chosen game's description is in the panel. */
  .g4-tiles { grid-template-columns: repeat(2, 1fr); }
  .g4-tile { padding: 0.55rem 0.7rem; justify-content: center; min-height: 3rem; }
  .g4-tile-blurb { display: none; }
  .g4-game-blurb { display: block; }
}
.g4-custom { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.3rem; font-size: 0.85rem; }
.g4-custom input { width: 3.6rem; margin-left: 0.2rem; display: inline-block; }
.g4-custom small { flex: 1 0 100%; }
.g4-custom[hidden] { display: none; }
.g4-note { color: var(--g4-muted); }
.g4-warning { margin: 0; padding: 0.4rem 0.6rem; border-radius: 6px; border: 1px solid rgba(255, 209, 102, 0.45); background: rgba(255, 209, 102, 0.08); color: #ffe3a3; }
.g4-warning[hidden] { display: none; }
.g4-seat { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 0.6rem; margin: 0.35rem 0; }
.g4-seat > span { color: var(--g4-muted); font-size: 0.85rem; }
.g4-seat[hidden] { display: none; }
.g4-seat select { flex: 1 0 100%; min-width: 0; margin-top: 0.1rem; }
.g4-who h2 { font-size: 1.2rem; margin: 0 0 0.4rem; }
.g4-who-seats { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: 0 1rem; margin-bottom: 0.4rem; }
.g4-who-seats .g4-seat > strong { flex: 1 0 100%; padding: 0.25rem 0; }
.g4-form-error { color: #ffb3c7; margin: 0; }
.g4-how li { margin-bottom: 0.4rem; }

.g4-reading { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }
.g4-reading p { flex: 1 1 280px; margin: 0; }
.g4-reading-demo { display: grid; grid-template-columns: repeat(2, 70px); gap: 16px 10px; padding-top: 12px; }
.g4-reading-mini { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
.g4-reading-mini span { position: absolute; top: -14px; left: 0; font-size: 10px; color: var(--g4-muted); }
.g4-reading-mini i { aspect-ratio: 1; background: var(--g4-cell); border-radius: 2px; }
.g4-reading-mini i.on { background: var(--g4-seat2); }

/* ------------------------------------------------------------ status -- */

.g4-status { margin: 0.75rem 0 0.75rem; }
.g4-status-title { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.g4-status h1 { font-size: 1.5rem; margin: 0; }
.g4-mode { color: var(--g4-muted); font-size: 0.9rem; }
.g4-players { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.g4-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.6rem 0.15rem 0.3rem;
  border: 1px solid var(--g4-line);
  border-radius: 99px;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.2);
}
.g4-chip-piece {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.4rem; height: 1.4rem; border-radius: 50%;
  color: var(--seat); font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
}
/* The seat symbols (games/pieces.js), sized by the font size of where they sit. */
.g4-sym { display: block; width: 0.82em; height: 0.82em; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.g4-chip-piece .g4-sym { width: 65%; height: 65%; stroke-width: 3.4; }
.g4-disc .g4-sym { width: 52%; height: 52%; stroke-width: 2.8; }
.g4-cell > .g4-sym { width: 1.05em; height: 1.05em; }
.g4-chip-turn { border-color: var(--seat); box-shadow: 0 0 0 1px var(--seat), 0 0 10px color-mix(in srgb, var(--seat) 50%, transparent); }
.g4-chip-out { opacity: 0.45; text-decoration: line-through; }
.g4-chip-absent { opacity: 0.55; border-style: dashed; }
.g4-turn { font-size: 1.15rem; font-weight: 700; color: var(--g4-ink); }
.g4-turn-mine { color: var(--g4-seat2); }
/* Several people at one screen: whose turn it is, large and in their colour. */
.g4-turn.g4-turn-big {
  display: inline-flex; align-items: center; gap: 0.6rem;
  margin-top: 0.25rem; padding: 0.35rem 1rem 0.35rem 0.5rem;
  font-size: 1.75rem; color: var(--seat);
  border: 2px solid var(--seat); border-radius: 12px;
  background: color-mix(in srgb, var(--seat) 15%, transparent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--seat) 45%, transparent);
}
.g4-turn-big .g4-chip-piece { width: 2.4rem; height: 2.4rem; font-size: 1.5rem; }
.g4-turn-big .g4-chip-piece .g4-sym { width: 65%; height: 65%; }
.g4-notice { margin-top: 0.4rem; font-size: 0.85rem; color: #ffb3c7; }

.g4-panel {
  background: var(--g4-panel);
  border: 1px solid var(--g4-line);
  border-radius: 10px;
  padding: 1rem;
  margin: 0.75rem 0 1rem;
}
.g4-panel h2 { font-size: 1.2rem; margin-top: 0; }
.g4-invite { margin-bottom: 0.75rem; }
.g4-invite label { display: block; font-size: 0.85rem; color: var(--g4-muted); margin-bottom: 0.2rem; }
.g4-invite-buttons { display: flex; gap: 0.5rem; margin-top: 0.35rem; }
.g4-invite-buttons .btn { min-height: 2.4rem; min-width: 5.5rem; }
.g4-result { text-align: center; }
.g4-result-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }
.g4-result-buttons[hidden], #g4-next[hidden] { display: none; }
.g4-result-buttons p { flex: 1 0 100%; color: var(--g4-muted); }
.g4-next-form { text-align: left; max-width: 26rem; margin: 0 auto; display: grid; gap: 0.6rem; }
.g4-next-row { display: flex; align-items: center; gap: 0.6rem; }
.g4-next-row > span { flex: 0 0 4.5rem; color: var(--g4-muted); font-size: 0.85rem; }
.g4-next-row > :last-child { flex: 1 1 auto; min-width: 0; }
.g4-next-row select { width: 100%; }
.g4-next-form .g4-custom input { width: 3.6rem; display: inline-block; }
.g4-next-form fieldset { margin: 0; }
.g4-next-form legend { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--g4-muted); margin-bottom: 0.2rem; }
.g4-next-form .g4-seat > strong { flex: 1 0 100%; padding: 0.2rem 0; }
.g4-next-buttons { display: flex; justify-content: flex-end; gap: 0.5rem; }
.g4-invite-own label { color: var(--g4-ink); font-weight: 600; }
.g4-links > summary { cursor: pointer; }
.g4-result h2 { font-size: 1.5rem; }
.g4-promo { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: 0.4rem; }

/* ------------------------------------------------------------- board -- */

.g4-board-host { display: flex; justify-content: center; }
.g4-board {
  --gap: clamp(4px, 1.3vw, 12px);
  display: grid;
  grid-template-columns: repeat(var(--Z), minmax(0, 1fr));
  column-gap: var(--gap);
  row-gap: calc(var(--gap) + 0.75rem);
  padding-top: 0.75rem;
  /* As big as fits: the whole width, or the height left under the status bar. */
  width: min(100%, max(280px, calc((100svh - 12rem) * var(--aspect, 1))));
  user-select: none;
  -webkit-user-select: none;
}
.g4-board-zoom { width: min(78vw, 250px); padding-top: 0; row-gap: 0; }
.g4-mini {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--X), minmax(0, 1fr));
  gap: max(1px, 0.4cqi);
  container-type: inline-size;
  padding: 2px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.25);
  transition: box-shadow 0.2s;
}
.g4-mini-label {
  position: absolute;
  top: -0.95rem;
  left: 1px;
  font-size: 0.6rem;
  line-height: 1;
  color: var(--g4-muted);
  pointer-events: none;
}
.g4-board-zoom .g4-mini-label { display: none; }
.g4-cell {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--g4-cell);
  color: var(--seat, var(--g4-ink));
  font-size: calc(100cqi / var(--X) * 0.62);
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s;
}
.g4-cell:hover { background: rgba(255, 255, 255, 0.16); }
.g4-cell:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.g4-disabled .g4-cell { cursor: default; }
.g4-disabled .g4-cell:hover { background: var(--g4-cell); }

.g4-cell.g4-ray { background: rgba(255, 209, 102, 0.2); }
.g4-cell.g4-preview { background: rgba(255, 255, 255, 0.26); }
.g4-cell.g4-last { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.75); }
.g4-cell.g4-selected { box-shadow: inset 0 0 0 3px #fff; background: rgba(255, 255, 255, 0.3); }
.g4-cell.g4-line { background: color-mix(in srgb, var(--seat) 40%, transparent); animation: g4-pulse 1.4s ease-in-out infinite; }
.g4-mini.g4-board-line { box-shadow: 0 0 0 2px var(--g4-seat2); }
.g4-mini.g4-board-focus { box-shadow: 0 0 0 2px #fff; }
.g4-mini.g4-board-flash { animation: g4-board-flash 0.5s ease-out; }

/* Connect Four tokens. */
.g4-disc {
  width: 84%; height: 84%; border-radius: 50%;
  background: var(--seat); color: var(--g4-dark);
  font-size: 0.62em;
  display: flex; align-items: center; justify-content: center;
}
.g4-drop .g4-disc { animation: g4-drop 0.45s cubic-bezier(0.5, 0, 0.75, 1.3); }

/* Atoms: the count on the seat's shape. */
.g4-atom {
  position: relative;
  isolation: isolate;
  width: 86%; height: 86%;
  display: flex; align-items: center; justify-content: center;
  color: var(--g4-dark);
  font-size: 0.8em;
}
.g4-atom::before { content: ''; position: absolute; inset: 0; z-index: -1; background: var(--seat); }
.g4-shape0::before { clip-path: circle(50%); }
.g4-shape1::before { clip-path: inset(6% round 14%); }
.g4-shape2::before { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.g4-shape3::before { clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%); }
.g4-critical .g4-atom::before { animation: g4-throb 1.1s ease-in-out infinite; }
.g4-explode { animation: g4-explode 0.35s ease-out; }
.g4-placed { animation: g4-explode 0.4s ease-out; }

/* Squares you can play (Reversi, Light Cycles, and where a domino can finish). */
.g4-cell.g4-hint:empty::after { content: ''; width: 24%; height: 24%; border-radius: 50%; background: rgba(255, 255, 255, 0.38); }
.g4-disabled .g4-cell.g4-hint:empty::after { display: none; }

/* Reversi: a captured piece turns over. */
.g4-flip .g4-disc { animation: g4-flip 0.6s ease-in-out; }

/* Light Cycles: the trail behind each cycle, and its head. */
.g4-cell.g4-trail { background: color-mix(in srgb, var(--seat) 42%, var(--g4-cell)); }
.g4-head-out .g4-disc { opacity: 0.4; }

/* Domineering: a domino fills its two squares and, inside one small board,
   bridges the gap between them; one along Z or W says which. */
.g4-cell { position: relative; }
.g4-domino {
  position: absolute; inset: 7%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  background: var(--seat); color: var(--g4-dark);
  font-size: 0.62em;
}
.g4-domino small { font-size: 0.55em; font-weight: 700; margin-left: 0.15em; }
.g4-join-r .g4-domino { right: calc(-1 * max(1px, 0.4cqi)); border-top-right-radius: 0; border-bottom-right-radius: 0; }
.g4-join-l .g4-domino { left: calc(-1 * max(1px, 0.4cqi)); border-top-left-radius: 0; border-bottom-left-radius: 0; }
.g4-join-d .g4-domino { bottom: calc(-1 * max(1px, 0.4cqi)); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.g4-join-u .g4-domino { top: calc(-1 * max(1px, 0.4cqi)); border-top-left-radius: 0; border-top-right-radius: 0; }

/* Dots and Boxes: thin dots and edges between wide boxes (games/boxes.js). */
.g4-board-weighted { --gap: clamp(2px, 0.6vw, 6px); }
.g4-board-weighted .g4-mini { gap: 1px; padding: 1px; }
.g4-board-weighted .g4-mini-label { display: none; }
.g4-board-weighted .g4-cell { aspect-ratio: auto; border-radius: 1px; font-size: calc(100cqi * var(--cell-share) * 0.6); }
.g4-cell.g4-void, .g4-disabled .g4-cell.g4-void:hover { background: transparent; cursor: default; }
.g4-cell.g4-dot, .g4-disabled .g4-cell.g4-dot:hover { background: radial-gradient(circle closest-side, rgba(255, 255, 255, 0.32) 55%, transparent 62%); }
.g4-cell.g4-face { background: rgba(255, 255, 255, 0.08); }
.g4-cell.g4-face:hover { background: rgba(255, 255, 255, 0.3); }
.g4-cell.g4-face.g4-shaded { background: color-mix(in srgb, var(--seat) 80%, transparent); cursor: default; }
.g4-cell.g4-box, .g4-disabled .g4-cell.g4-box:hover { background: rgba(0, 0, 0, 0.2); cursor: default; }
.g4-cell.g4-box.g4-shaded { background: color-mix(in srgb, var(--seat) 28%, var(--g4-cell)); }

/* Gamepads: where the cursor is, and which button or field has the focus. */
.g4-pad .g4-cell.g4-cursor { box-shadow: inset 0 0 0 3px #fff, 0 0 12px rgba(255, 255, 255, 0.7); z-index: 1; }
.g4-pad .g4-result :focus { outline: 3px solid #fff; outline-offset: 2px; }

@keyframes g4-pulse { 50% { filter: brightness(1.5); } }
@keyframes g4-flip { 50% { transform: scaleX(0.05); } }
@keyframes g4-board-flash { from { box-shadow: 0 0 0 3px #fff, 0 0 16px #fff; } }
@keyframes g4-drop { from { transform: translateY(-260%); } }
@keyframes g4-throb { 50% { filter: brightness(1.45); } }
@keyframes g4-explode { 0% { background: #fff; transform: scale(1.15); } 100% { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .g4-cell, .g4-mini, .g4-disc, .g4-atom::before, .g4-domino { animation: none !important; transition: none !important; }
}

/* ----------------------------------------------------------- toolbar -- */

.g4-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem 1.25rem;
  margin: 0.75rem 0;
  font-size: 0.85rem;
}
.g4-readout { font-variant-numeric: tabular-nums; color: var(--g4-muted); min-width: 10rem; text-align: center; }
.g4-switch { margin: 0; min-height: 2rem; display: inline-flex; align-items: center; gap: 0.4rem; }
.g4-switch .form-check-input { margin-top: 0; }
.g4-rules { margin: 1rem 0; font-size: 0.92rem; }
.g4-rules summary { cursor: pointer; font-weight: 700; }

/* --------------------------------- select, then confirm (small screens) -- */

.g4-confirm {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 16px calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(18, 6, 42, 0.97);
  border-top: 1px solid var(--g4-line);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
}
.g4-confirm[hidden] { display: none; }
.g4-confirm-coords { font-size: 0.85rem; color: var(--g4-muted); }
.g4-confirm-buttons { display: flex; gap: 0.75rem; width: min(100%, 420px); }
.g4-confirm-buttons .btn { min-height: 3.2rem; }
.g4-confirm-buttons .btn-primary { flex: 1; font-weight: 700; }
body.g4-confirm-open main { padding-bottom: 24rem; }

.g4-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 1050;
  max-width: calc(100% - 32px);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  background: #2b1055;
  border: 1px solid var(--g4-line);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
}
body.g4-confirm-open .g4-toast { bottom: auto; top: 4.5rem; }
