/* Blitz Tic Tac Toe — minimal high-contrast.
   No glassmorphism, no glow stacks, no gradient text. Contrast and spacing do
   the work: a flat slate field, hairline rules, one accent (amber) for O and
   for anything time-critical. */

:root {
  --bg: #12141a;
  --surface: #191c24;
  --line: #2b303b;
  --line-strong: #454d5e;
  --ink: #f4f4f5;
  --ink-dim: #a1a7b3;
  --ink-faint: #6c7381;
  --mark-x: #f4f4f5;
  --mark-o: #f59e0b;
  --danger: #ef4444;
  --ok: #34d399;

  --board: 336px;
  --radius: 6px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* The game used to sit in the top half of the viewport with the rest left as
   empty gradient. Centring it vertically makes the whitespace deliberate. */
.container {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 48px;
}

.game-container {
  width: 100%;
  max-width: var(--board);
  margin-inline: auto;
}

.screen {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Typography ---------- */

h1 {
  font-size: 1.9rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--ink);
  margin-bottom: 10px;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.lede {
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink-dim);
  margin-bottom: 32px;
}

.eyebrow {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  margin-bottom: 12px;
}

/* ---------- Rules list ---------- */

.game-description {
  margin-bottom: 32px;
}

.game-description ul {
  list-style: none;
  border-top: 1px solid var(--line);
}

.game-description li {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink-dim);
  text-align: left;
}

.game-description li::before {
  content: counter(rule);
  counter-increment: rule;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  min-width: 1ch;
}

.game-description ul {
  counter-reset: rule;
}

/* ---------- Difficulty ---------- */

.difficulty-selector {
  margin-bottom: 28px;
}

.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.difficulty-btn {
  background: transparent;
  color: var(--ink-dim);
  border: 0;
  border-left: 1px solid var(--line-strong);
  padding: 11px 8px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.difficulty-btn:first-child {
  border-left: 0;
}

.difficulty-btn:hover {
  background: var(--surface);
  color: var(--ink);
}

.difficulty-btn.active {
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

/* ---------- Buttons ---------- */

.btn {
  display: block;
  width: 100%;
  background: var(--ink);
  color: var(--bg);
  border: 0;
  padding: 14px 24px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn:hover {
  opacity: 0.88;
}

.btn:active {
  transform: translateY(1px);
}

/* ---------- HUD ---------- */
/* The round and countdown used to live in a .game-header that was set to
   display:none, so a game built around a 1-2 second clock showed no clock. */

.hud {
  margin-bottom: 20px;
}

.hud-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.hud-round {
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}

.hud-round b {
  color: var(--ink-dim);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.timer-bar {
  width: 100%;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.timer-progress {
  height: 100%;
  width: 100%;
  background: var(--ink-dim);
  transition: width 0.1s linear, background-color 0.2s ease;
}

.timer-progress.warn {
  background: var(--mark-o);
}

.timer-progress.critical {
  background: var(--danger);
}

/* ---------- Board ---------- */

.game-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  /* Room below for the losing message, which is absolutely positioned against
     this box. The space is reserved permanently so the layout does not jump
     when it shows. */
  margin-bottom: 44px;
}

/* Queued grids sit at translateX(110%) waiting to slide in. Unclipped they
   stretched the document to 733px on a 390px viewport; clipping them here also
   makes the slide start at the board edge instead of off-screen. The losing
   message is appended to .game-board, which stays unclipped so it can sit
   below the board. */
.board-track {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* Real grid lines: the container's own colour shows through 2px gaps, giving
   the classic # with no outer box. Cells used to be 3%-white rounded tiles
   floating on a dark field, which never read as a grid at all. */
.grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 2px;
  background: var(--line-strong);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
  transform: translateX(110%);
  opacity: 0;
  pointer-events: none;
}

.grid.active {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.grid.sliding-out {
  transform: translateX(-110%);
  opacity: 0;
  pointer-events: none;
}

.cell {
  background: var(--bg);
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.1rem;
  font-weight: 500;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease;
}

.cell:hover {
  background: var(--surface);
}

.cell.x,
.cell.o {
  cursor: default;
}

.cell.x {
  color: var(--mark-x);
  animation: markIn 0.18s ease-out;
}

.cell.o {
  color: var(--mark-o);
  animation: markIn 0.18s ease-out;
}

/* .winning is applied to whichever side completed the line — X means the
   player won, O means they lost, so the two cannot share one colour.
   These fills are opaque on purpose: a cell sits on top of the grid, whose
   background IS the line colour, so a translucent tint composites over
   #454d5e and paints mauve/teal instead of red/green. */
.cell.x.winning {
  background: #16302b;
  color: var(--ok);
}

.cell.o.winning {
  background: #3a1a20;
  color: var(--danger);
}

@keyframes markIn {
  from {
    opacity: 0;
    transform: scale(0.7);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* JS sets `style.animation = "pulse ..."` on placement — keep the name alive */
@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
}

/* ---------- Overlays injected by the script ---------- */

.timeout-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 20, 26, 0.84);
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.22em;
}

.losing-message {
  position: absolute;
  top: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  z-index: 1000;
  pointer-events: none;
}

/* ---------- End screen ---------- */

#end-message {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}

#end-message.win {
  color: var(--ok);
}

#end-message.lose {
  color: var(--danger);
}

.game-summary-info {
  margin-bottom: 28px;
}

.difficulty-display {
  font-size: 0.85rem;
  color: var(--ink-faint);
}

.difficulty-display span:last-child {
  color: var(--ink-dim);
  font-weight: 600;
}

/* One row, so the per-grid labels can never collide with the row above — they
   used to sit at top:-22px inside a 20px wrap gap and overlapped it. */
.grid-summary {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 26px 0 0;
  margin-bottom: 30px;
  border-top: 1px solid var(--line);
}

.summary-grid {
  position: relative;
  flex: 0 1 52px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
}

.summary-grid::before {
  content: attr(data-grid-number);
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.summary-cell {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
}

.summary-cell.x {
  color: var(--mark-x);
}

.summary-cell.o {
  color: var(--mark-o);
}

.summary-cell.o.winning {
  /* opaque for the same reason as .cell.o.winning above */
  background: #3a1a20;
  color: var(--danger);
}

/* ---------- Responsive ---------- */

@media (max-width: 400px) {
  .container {
    padding: 20px 16px 32px;
  }

  h1 {
    font-size: 1.6rem;
  }

  .cell {
    font-size: 2.25rem;
  }

  .grid-summary {
    gap: 8px;
  }
}
