/* Reversi. Every selector starts with .g-reversi so it cannot clash with other games. */

.g-reversi {
  /* 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 square stays at least
     38px wide on a 320px screen. On wide screens it stops at 460px. */
  --rv-w: min(460px, max(100%, min(100vw - 16px, 352px)));
  --rv-line: color-mix(in srgb, var(--text) 26%, transparent);
}
.g-reversi [hidden] { display: none !important; }

/* ---------- opponent ladder ---------- */
.g-reversi .rv-levels { grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0 0 8px; }
.g-reversi .rv-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-reversi .rv-lv-n { font-size: .66rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.g-reversi .rv-lv-name { font-size: .95rem; }
.g-reversi .rv-order { margin: 0 0 10px; }
.g-reversi .rv-order-l { font-weight: 700; font-size: .9rem; color: var(--muted); }
.g-reversi .rv-best { flex-basis: 100%; text-align: center; font-size: .85rem; font-weight: 700; color: var(--muted); }
@media (min-width: 540px) {
  .g-reversi .rv-levels { grid-template-columns: repeat(6, 1fr); }
}

/* ---------- score pills ---------- */
.g-reversi .rv-pill { align-items: center; }
.g-reversi .rv-pill.turn { box-shadow: inset 0 0 0 2px var(--accent); }
.g-reversi .rv-arrow { color: var(--accent); font-size: .8rem; }
.g-reversi .rv-chip { position: relative; display: inline-block; flex: none; width: 15px; height: 15px; border-radius: 50%; }

/* ---------- board ---------- */
.g-reversi .rv-board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  width: var(--rv-w); aspect-ratio: 1;
  margin: 0 0 0 calc((100% - var(--rv-w)) / 2);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--text) 30%, var(--border));
}
.g-reversi .rv-cell {
  appearance: none; -webkit-appearance: none; position: relative;
  min-width: 0; min-height: 0; margin: 0; padding: 0;
  border: 0; border-right: 1px solid var(--rv-line); border-bottom: 1px solid var(--rv-line);
  border-radius: 0; background: transparent; cursor: default;
}
.g-reversi .rv-cell:nth-child(8n) { border-right: 0; }
.g-reversi .rv-cell:nth-child(n + 57) { border-bottom: 0; }
.g-reversi .rv-cell:focus-visible { outline-offset: -3px; border-radius: 0; }
.g-reversi .rv-cell.can { cursor: pointer; }
.g-reversi .rv-cell.can:active { background: color-mix(in srgb, var(--accent) 30%, transparent); }
@media (hover: hover) {
  .g-reversi .rv-cell.can:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
}
/* a dot on every square you may play (the "Show moves" switch) */
.g-reversi .rv-cell.hint::before {
  content: ''; position: absolute; inset: 37%; border-radius: 50%;
  background: color-mix(in srgb, var(--text) 34%, transparent);
}

/* ---------- discs ----------
   Dark = the side that moves first. Light discs carry a ring, so the two sides can be
   told apart without relying on colour. light-dark() keeps "dark" dark in both themes;
   the plain line above it is the fallback for older browsers. */
.g-reversi .rv-disc { position: absolute; inset: 10%; border-radius: 50%; pointer-events: none; }
.g-reversi .rv-disc,
.g-reversi .rv-chip { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--text) 45%, transparent); }
.g-reversi .rv-disc.is-dark,
.g-reversi .rv-chip.is-dark {
  background: var(--text);
  background: light-dark(var(--text), var(--bg));
}
.g-reversi .rv-disc.is-light,
.g-reversi .rv-chip.is-light {
  background: var(--surface);
  background: light-dark(var(--surface), var(--text));
}
.g-reversi .rv-disc.is-light::after,
.g-reversi .rv-chip.is-light::after {
  content: ''; position: absolute; inset: 24%; border-radius: 50%;
  border: 2px solid var(--text);
  border-color: light-dark(var(--text), var(--bg));
}
.g-reversi .rv-chip.is-light::after { inset: 3px; border-width: 1.5px; }
/* the last disc placed carries a small centre dot */
.g-reversi .rv-cell.last .rv-disc::before {
  content: ''; position: absolute; inset: 39%; border-radius: 50%; background: var(--accent);
}

.g-reversi .rv-disc.pop { animation: g-reversi-pop .16s ease-out; }
.g-reversi .rv-disc.flip { animation: g-reversi-flip .26s ease-out; }
@keyframes g-reversi-pop { from { transform: scale(.4); opacity: .4; } }
@keyframes g-reversi-flip { from { transform: scaleX(0); } 55% { transform: scaleX(1.06); } }
@media (prefers-reduced-motion: reduce) {
  .g-reversi .rv-disc { animation: none; }
}

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