/* Ultimate Tic-Tac-Toe board – only what's specific to this game.
   Header, difficulty, score and status come from /css/style.css. */

/* Status sits above the board here, so you always know where to
   play without looking away from it. */
.ut-play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: -12px;
  text-align: center;
}

.ut-holder {
  width: min(100%, 480px);
}

/* 3 × 3 small boards */
.ut-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  aspect-ratio: 1;
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
}

/* Each small board: 3 × 3 cells */
.ut-small {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 3px;
  min-width: 0;
  min-height: 0;
  padding: 4px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--inset);
  transition: border-color 150ms ease, opacity 150ms ease;
}

/* Where the next move must go */
.ut-small.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ...but softer while it's the AI's (or your friend's) turn */
.ut-small.is-waiting {
  border-color: var(--border-strong);
  background: var(--inset);
}

/* While you can only play in one board, fade the rest a little */
.ut-board:not(.is-over):has(.ut-small.is-active:not(.is-waiting)) .ut-small:not(.is-active) {
  opacity: 0.55;
}

.ut-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.ut-cell:disabled {
  cursor: default;
}

.ut-cell:not(:disabled):hover {
  background: var(--surface-2);
}

.ut-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.ut-cell svg {
  position: absolute;
  inset: 14%;
  width: 72%;
  height: 72%;
}

.ut-cell.is-new svg {
  animation: ut-mark-in 140ms ease-out;
}

.ut-cell.is-mine {
  color: var(--accent);
}

.ut-cell.is-theirs {
  color: var(--text);
}

/* The last move gets a ring so you can spot what just happened */
.ut-cell.is-last {
  box-shadow: inset 0 0 0 2px var(--text-faint);
}

/* ---------- Won and drawn small boards ---------- */

.ut-small.is-mine .ut-cell,
.ut-small.is-theirs .ut-cell,
.ut-small.is-draw .ut-cell {
  opacity: 0.18;
}

/* Keep a hint of the three that won it */
.ut-small.is-mine .ut-cell.is-line,
.ut-small.is-theirs .ut-cell.is-line {
  opacity: 0.4;
}

.ut-won {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.ut-won svg {
  width: 78%;
  height: 78%;
  animation: ut-mark-in 200ms ease-out;
}

.ut-small.is-mine .ut-won {
  color: var(--accent);
}

.ut-small.is-theirs .ut-won {
  color: var(--text);
}

/* ---------- End of the game ---------- */

.ut-board.is-over .ut-small:not(.is-win) {
  opacity: 0.5;
}

.ut-small.is-win {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- How to play ---------- */

.ut-rules {
  max-width: 480px;
  color: var(--text-muted);
}

.ut-rules summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.ut-rules p {
  margin-top: 8px;
}

/* The long name needs a little less room on phones */
@media (max-width: 560px) {
  .game-title {
    font-size: 16px;
    line-height: 1.25;
    text-align: right;
  }
}

@keyframes ut-mark-in {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .ut-cell.is-new svg,
  .ut-won svg {
    animation: none;
  }
}

/* The pen stroke draws itself in */
.ut-cell.is-new svg path,
.ut-cell.is-new svg circle,
.ut-won svg path,
.ut-won svg circle {
  stroke-dasharray: 1;
  animation: ut-draw 300ms ease-out both;
}

@keyframes ut-draw {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ut-cell.is-new svg path,
  .ut-cell.is-new svg circle,
  .ut-won svg path,
  .ut-won svg circle {
    animation: none;
  }
}

/* Phone held sideways: fit the screen height (see css/style.css) */
@media (orientation: landscape) and (max-height: 540px) {
  .ut-holder { width: min(480px, var(--play-w), var(--play-h)); }
}
