/* Noughts and crosses in pen: a game against the barista on a white page, in a minimal style. Four hairline
   strings make the grid, X and O are written in one dark ink, and the only colour is the vermilion of the
   winning row. The component sits in the middle of the page: in a real café page it would sit in a sidebar or
   under the order, and .stage would simply be its column. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #141414;           /* the marks, the title and the chosen numbers */
  --grid: #141414;          /* the four grid lines */
  --muted: #8f8b84;         /* the score labels and the separators */
  --accent: #e5402a;        /* the winning row */
  --board: min(300px, calc(100vw - 64px));   /* the board's width */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Archivo Variable', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 40px 16px;
}

.game {
  width: var(--board);
  display: grid;
  gap: 0;
}

/* ---------------------------------------------------------------- the title */
.game__title {
  margin: 0 0 22px;
  font-size: 27px;
  line-height: 1.05;
  font-weight: 600;
  font-variation-settings: 'wdth' 92, 'wght' 620;
  letter-spacing: -0.02em;
}

/* ---------------------------------------------------------------- the board */
.board {
  position: relative;
  width: var(--board);
  aspect-ratio: 1;
}

.board__ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.board__grid path {
  fill: none;
  stroke: var(--grid);
  stroke-width: 1.5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.board__marks path,
.board__ghost {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.board__win {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.cell {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.cell[aria-disabled='true'] {
  cursor: default;
}

.cell:focus {
  outline: none;
}

/* the square chosen with the keyboard: a hairline frame inside it */
.cell:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: -12px;
}

/* ---------------------------------------------------------------- the status and the score */
.status {
  margin: 22px 0 0;
  min-height: 1.35em;
  font-size: 15px;
  line-height: 1.35;
  font-variation-settings: 'wdth' 100, 'wght' 430;
  white-space: nowrap;
}

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  margin-top: 10px;
}

.score {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-variation-settings: 'wdth' 96, 'wght' 420;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.score b {
  display: inline-block;
  min-width: 1ch;
  margin-left: 1px;
  color: var(--ink);
  font-weight: 600;
  font-variation-settings: 'wdth' 100, 'wght' 600;
}

.score__sep {
  margin: 0 8px;
}

/* a very narrow phone: the same words, condensed on the width axis */
@media (max-width: 359px) {
  .status {
    font-variation-settings: 'wdth' 86, 'wght' 430;
  }

  .score {
    font-variation-settings: 'wdth' 80, 'wght' 420;
  }

  .score__sep {
    margin: 0 5px;
  }

  .again {
    padding-inline: 13px;
  }
}

/* ---------------------------------------------------------------- Play again: a hairline pill that swells */
.again {
  position: relative;
  flex: none;
  margin: 0;
  padding: 9px 17px 10px;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  visibility: hidden;
  opacity: 0;
  -webkit-tap-highlight-color: transparent;
}

.again__bg {
  position: absolute;
  inset: 0;
  border: 1px solid var(--ink);
  border-radius: 999px;
  transition: transform 0.55s cubic-bezier(0.3, 1.6, 0.5, 1), background-color 0.2s;
}

.again__label {
  position: relative;
  display: inline-block;
  font-variation-settings: 'wdth' 100, 'wght' 480;
  transition: font-variation-settings 0.45s cubic-bezier(0.3, 1.4, 0.5, 1), color 0.2s;
}

@media (hover: hover) {
  .again:hover .again__bg {
    transform: scale(1.05, 1.12);
  }

  .again:hover .again__label {
    font-variation-settings: 'wdth' 114, 'wght' 560;
  }
}

.again:active .again__bg,
.again.is-pressed .again__bg {
  transform: scale(0.95);
  background-color: var(--ink);
  transition-duration: 0.12s;
}

.again:active .again__label,
.again.is-pressed .again__label {
  color: var(--page);
}

.again:focus {
  outline: none;
}

.again:focus-visible .again__bg {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .again__bg,
  .again__label {
    transition: background-color 0.2s, color 0.2s;
  }

  .again:hover .again__bg {
    transform: none;
  }
}
