/* Border-box everywhere. Without it the shared .site-header (padding: 0 34px) is content-box,
 * so on a 1440px viewport it measures 1508px and the page scrolls sideways by 68px.
 * Every other Glov game applies the same reset. */
*, *::before, *::after { box-sizing: border-box; }
/* The browser default body margin is 8px, which offset the full-width header and made the page
 * 8px wider than the viewport on every screen size. Every Glov game resets it. */
body { margin: 0; }

/* ------------------------------------------------------------------- page backdrop ---
 * platform-design.css sets `color-scheme: dark`, so a page with no background of its own
 * renders on the browser's black canvas. Every other Glov title paints a gradient instead;
 * this game was missing that, which is why it showed up black.
 *
 * `html` gets the flat base colour so the area beyond the body (overscroll, and any viewport
 * taller than the content) is never black, then `body` lays the violet glow over it. The
 * colours match the .game-stage panel below so the board still reads as the focal point.
 */
html { background: #170a27; }

body {
  min-height: 100vh;
  color: #efe6fa;
  background:
    radial-gradient(circle at 80% 8%, #52206c66, transparent 31rem),
    radial-gradient(circle at 12% 92%, #35104755, transparent 28rem),
    linear-gradient(145deg, #1d0c3a, #170a27 60%, #120722);
  background-attachment: fixed;
}

/* Glov Games · Glov XO
 *
 * One flat 3x3 grid, built with plain CSS grid and no dependencies, matching how every other
 * Glov title is built. There is no separate decorative board: the grid users see is the same
 * DOM the keyboard and screen readers drive, so the two can never disagree about game state.
 */

.ttt-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 20px 56px;
}

/* ---------------------------------------------------------------- play card + stage --- */

.ttt-shell .play-card {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.ttt-shell .game-stage {
  position: relative;
  display: grid;
  gap: 16px;
  justify-items: center;
  padding: 18px;
  border: 1px solid #ffffff1f;
  border-radius: 22px;
  background:
    radial-gradient(520px 240px at 82% -18%, #6d28d92e, transparent 66%),
    linear-gradient(152deg, #1d0c3a, #150829 62%, #120722);
  box-shadow: 0 16px 38px #05000f5c;
}

.ttt-hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 460px;
}

.ttt-hud > div {
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 8px 10px;
  border: 1px solid #ffffff17;
  border-radius: 12px;
  background: #ffffff08;
}

.ttt-hud small {
  color: #b9a9d0;
  font: 700 10px/1.3 "Space Mono", ui-monospace, monospace;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.ttt-hud strong {
  color: #fff;
  font: 800 20px/1.1 "Space Grotesk", "Plus Jakarta Sans", sans-serif;
}

/* --------------------------------------------------------------- the board ---
 * A single flat 3x3 grid. It is both the visible board and the accessible grid, so there is
 * no decorative duplicate that could drift out of sync with the real game state.
 */

.board-accessible {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(320px, 78vw);
  margin: 4px 0 2px;
}

.grid-cell {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #ffffff26;
  border-radius: 12px;
  color: #fff;
  background: #ffffff0a;
  font: 900 clamp(22px, 6vw, 30px)/1 "Space Grotesk", "Plus Jakarta Sans", sans-serif;
  cursor: pointer;
  transition: border-color .16s, background .16s, transform .12s;
}

.grid-cell:hover:not(:disabled) { border-color: #e879f2aa; background: #e879f214; }
.grid-cell:active:not(:disabled) { transform: translateY(1px); }
.grid-cell:focus-visible { outline: 3px solid #67e8f9; outline-offset: 2px; }
.grid-cell:disabled { cursor: default; opacity: .92; }

.grid-cell[data-value="X"] { color: #67e8f9; }
.grid-cell[data-value="O"] { color: #f3b94c; }

/* --------------------------------------------------------------- mark animation ---
 * A mark drops in with a slight scale-and-fade so placing a square feels responsive. The
 * animation is driven by the .is-new class, which js/game.js sets only for the cell that
 * just received a value, then removed on animationend so it can replay for the next mark.
 *
 * Using a class rather than an attribute selector matters: re-rendering the same value would
 * not restart an animation bound to [data-value], so a fresh mark could appear with no motion.
 */
.grid-cell.is-new { animation: xo-mark-in .3s cubic-bezier(.34, 1.56, .64, 1) both; }

@keyframes xo-mark-in {
  from { transform: scale(.4); opacity: 0; }
  60%  { transform: scale(1.12); opacity: 1; }
  to   { transform: scale(1); opacity: 1; }
}

/* The three winning cells pulse once when the line lands, so the result is obvious even
 * before the eye reaches the drawn line. */
.grid-cell.is-win { border-color: #67e8f9cc; background: #67e8f91f; }
.grid-cell.is-win.is-celebrating { animation: xo-win-pulse .9s ease-out 2 both; }

@keyframes xo-win-pulse {
  0%   { box-shadow: 0 0 0 0 #67e8f900; background: #67e8f91f; }
  40%  { box-shadow: 0 0 0 4px #67e8f93d, 0 0 22px #67e8f966; background: #67e8f933; }
  100% { box-shadow: 0 0 0 0 #67e8f900; background: #67e8f91f; }
}

.live-message {
  margin: 0;
  min-height: 20px;
  color: #cbb8e4;
  font-size: 13px;
  text-align: center;
}

/* ------------------------------------------------------------------ start / result --- */

.start-panel,
.result-panel {
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
  padding: 16px;
  border: 1px solid #ffffff1a;
  border-radius: 16px;
  background: #ffffff08;
  width: 100%;
  max-width: 460px;
}

.start-panel[hidden],
.result-panel[hidden] { display: none; }

/* The result panel slides up when a round ends. Bound to :not([hidden]) so it replays on
 * every new result rather than only the first time the element is shown. */
.result-panel:not([hidden]) { animation: xo-panel-in .32s cubic-bezier(.22, 1, .36, 1) both; }

@keyframes xo-panel-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Score bump: js/game.js adds .is-bumped to the counter that just changed. */
.ttt-hud strong.is-bumped { animation: xo-score-bump .42s cubic-bezier(.34, 1.56, .64, 1) both; }

@keyframes xo-score-bump {
  from { transform: scale(1); }
  45%  { transform: scale(1.35); color: #67e8f9; }
  to   { transform: scale(1); }
}

.start-panel h2,
.result-panel h2 {
  margin: 0;
  color: #fff;
  font: 700 22px/1.15 "Space Grotesk", "Plus Jakarta Sans", sans-serif;
}

.start-panel p,
.result-panel p {
  margin: 0;
  color: #cbb8e4;
  font-size: 13px;
  line-height: 1.5;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}

.primary-action,
.result-actions button,
.result-actions a,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  font: 800 13px/1 "Plus Jakarta Sans", sans-serif;
  text-decoration: none;
  cursor: pointer;
}

.primary-action,
.result-actions .primary-action {
  color: #fff;
  background: linear-gradient(115deg, #a72cc0, #c23ad4);
  box-shadow: 0 10px 24px #a72cc03d;
}

.result-actions button:not(.primary-action) {
  color: #f4effb;
  background: #ffffff14;
  border: 1px solid #ffffff2b;
}

.result-actions a {
  color: #e879f2;
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.primary-action:hover,
.result-actions button:hover,
.result-actions a:hover { filter: brightness(1.1); }

.primary-action:focus-visible,
.result-actions button:focus-visible,
.result-actions a:focus-visible,
.secondary-action:focus-visible {
  outline: 3px solid #67e8f9;
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------- controls --- */

.game-controls {
  display: grid;
  gap: 14px;
}

.game-controls fieldset {
  margin: 0;
  padding: 14px;
  border: 1px solid #ffffff1a;
  border-radius: 16px;
  background: #ffffff08;
}

.game-controls legend {
  padding: 0 6px;
  color: #cbb8e4;
  font: 700 11px/1 "Space Mono", ui-monospace, monospace;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.mode-selector {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.mode-selector button {
  display: grid;
  gap: 3px;
  justify-items: center;
  min-height: 68px;
  padding: 9px 7px;
  border: 1px solid #ffffff1f;
  border-radius: 12px;
  color: #efe6fa;
  background: #ffffff08;
  cursor: pointer;
  transition: border-color .16s, background .16s;
}

.mode-selector button span { font-size: 18px; line-height: 1; }
.mode-selector button b { font: 800 12px/1.2 "Plus Jakarta Sans", sans-serif; }
.mode-selector button small { color: #a99ac1; font: 600 9.5px/1.2 "Plus Jakarta Sans", sans-serif; }

.mode-selector button:hover { border-color: #e879f288; }
.mode-selector button.selected {
  border-color: #e879f2;
  background: #a13ab329;
  box-shadow: 0 0 0 3px #e879f21f;
}
.mode-selector button:focus-visible { outline: 3px solid #67e8f9; outline-offset: 2px; }

.secondary-action {
  color: #efe6fa;
  background: #ffffff0f;
  border: 1px solid #ffffff26;
}

.secondary-action:hover { border-color: #e879f288; }

/* ------------------------------------------------------------------- responsive --- */

@media (max-width: 720px) {
  .ttt-shell { padding: 14px 14px 44px; }
  .mode-selector { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board-accessible { width: min(280px, 82vw); }
}

@media (max-width: 400px) {
  .ttt-hud strong { font-size: 17px; }
  .board-accessible { width: min(250px, 86vw); }
}

/* Respect the OS reduced-motion setting: no hover lift, no line reveal. */
@media (prefers-reduced-motion: reduce) {
  .grid-cell { transition: none; }
}

/* ------------------------------------------------------- overflow containment ---
 * Two elements pushed the document wider than the viewport on phones (8px), which allowed the
 * whole page to scroll sideways:
 *   1. main.ttt-shell was exactly viewport-wide, so its horizontal padding overflowed it;
 *   2. the shared .site-back link in the header did not fit once the brand took its width.
 */
.ttt-shell{
  box-sizing:border-box;
  width:100%;
  max-width:1080px;
}

@media (max-width:520px){
  /* Let the shared header stack instead of forcing one row. */
  .site-header{
    flex-wrap:wrap;
    gap:8px;
  }
  .site-header-actions{flex-wrap:wrap;gap:8px}
  .site-back{white-space:nowrap}
}

/* ------------------------------------------------------------- winning line overlay ---
 * A single line struck through the three matched cells. It is positioned by js/game.js from
 * the measured cell centres, then rotated to the line's angle, so rows, columns and diagonals
 * all use the same element and rule.
 */
.board-accessible {
  position: relative;
}

/* The element itself IS the stroke: a solid bar 8px tall whose `top` is offset by -4px in
 * js/game.js so the bar straddles the centre of the winning cells. Painting on the element
 * (rather than a ::before) means the clip-path reveal below animates the visible stroke. */
.win-line {
  position: absolute;
  left: 0;
  top: 0;
  height: 8px;
  width: 0;
  /* Rotate about the left-middle of the bar so it sweeps from the first cell's centre. */
  transform-origin: 0 50%;
  border-radius: 999px;
  background: linear-gradient(90deg, #67e8f9, #e879f2);
  box-shadow: 0 0 14px #67e8f9b3, 0 0 26px #e879f266;
  pointer-events: none;
  opacity: 0;
  z-index: 3;
  transition: opacity .18s ease;
}

.win-line.is-visible {
  opacity: 1;
  animation: win-line-in .34s cubic-bezier(.22, 1, .36, 1) both;
}

@keyframes win-line-in {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}

/* Inside .board-3d the line is a grid child, so it must be taken out of grid flow entirely or
 * it would occupy a cell. `position:absolute` already does that; the extra rules below pin it to
 * the board's top-left origin so the offset maths in js/game.js lines up. */

/* Cover every animation this game defines, not just the win line. Motion is decoration here:
 * the mark, the winning cells, the result panel and the score all remain legible without it. */
@media (prefers-reduced-motion: reduce) {
  .win-line.is-visible,
  .grid-cell.is-new,
  .grid-cell.is-win.is-celebrating,
  .result-panel:not([hidden]),
  .ttt-hud strong.is-bumped { animation: none; }
  .win-line { transition: none; }
  .grid-cell { transition: none; }
}
