:root {
  --paper: #fafcfe;
  --grid: #d5e1ec;
  --margin: #f1b9b4;
  --pencil: #2e3138;
  --pencil-soft: #5d6370;
  --ink-x: #1f3fb5;
  --ink-o: #c42a22;
  --square: 24px;
  --gutter: 3.5rem;

  /* Scale: perfect fourth from an 18px base. */
  --step-0: 1.125rem;
  --step-1: 1.5rem;
  --step-2: 2rem;
  --step-3: clamp(2.25rem, 8vw, 3.55rem);

  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: "Andika", "Trebuchet MS", sans-serif;
  font-size: 100%;
  color: var(--pencil);
  background-color: var(--paper);
  /* Squared maths paper, one line per square. */
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: var(--square) var(--square);
  background-attachment: fixed;
}

body {
  margin: 0;
  min-height: 100vh;
  font-size: var(--step-0);
  line-height: 1.5;
}

/* The exercise-book margin line. */
body::before {
  content: "";
  position: fixed;
  inset: 0 auto 0 calc(var(--gutter) - 2px);
  width: 2px;
  background: var(--margin);
  pointer-events: none;
}

[hidden] {
  display: none !important;
}

.page {
  max-width: calc(var(--gutter) + 34rem);
  padding: 3rem 1.5rem 4rem calc(var(--gutter) + 1.5rem);
}

h1,
h2,
p {
  margin: 0;
}

.title {
  font-size: var(--step-3);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.title--small {
  font-size: var(--step-2);
  line-height: 1.2;
}

.lede {
  margin-top: 0.75rem;
  max-width: 30rem;
  font-size: var(--step-0);
  color: var(--pencil-soft);
}

.status {
  font-size: var(--step-2);
  font-weight: 700;
  line-height: 1.2;
}

.status[data-ink="X"] {
  color: var(--ink-x);
}

.status[data-ink="O"] {
  color: var(--ink-o);
}

.note {
  margin-top: 0.25rem;
  min-height: 1.5em;
  color: var(--pencil-soft);
}

/* Buttons */

.button {
  font: inherit;
  font-weight: 700;
  color: var(--pencil);
  background: var(--paper);
  border: 2px solid var(--pencil);
  border-radius: 4px;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
}

.button:hover {
  background: #eef3f8;
}

.button--primary {
  color: var(--paper);
  background: var(--pencil);
}

.button--primary:hover {
  background: #1d1f24;
}

.button--small {
  font-size: 1rem;
  padding: 0.3rem 0.75rem;
}

.button:disabled {
  opacity: 0.55;
  cursor: progress;
}

:focus-visible {
  outline: 3px solid var(--ink-x);
  outline-offset: 3px;
}

/* Home */

#home .button--primary,
#missing .button--primary {
  margin-top: 2rem;
}

.join {
  margin-top: 2.5rem;
}

.join label {
  display: block;
  color: var(--pencil-soft);
}

.join__row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.join input {
  font: inherit;
  width: 9rem;
  padding: 0.5rem 0.7rem;
  color: var(--pencil);
  background: var(--paper);
  border: 2px solid var(--pencil-soft);
  border-radius: 4px;
  letter-spacing: 0.08em;
}

.join input::placeholder {
  color: #a3aab6;
}

.join__error {
  margin-top: 0.4rem;
  min-height: 1.5em;
  color: var(--ink-o);
}

/* Room */

.room-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 2.25rem;
}

.home-link {
  font-weight: 700;
  color: var(--pencil);
  text-decoration: none;
  margin-right: auto;
  flex-basis: 100%;
}

.home-link:hover {
  text-decoration: underline;
}

.room-bar__code {
  color: var(--pencil-soft);
}

.room-bar__code strong {
  color: var(--pencil);
  letter-spacing: 0.08em;
}

.pick {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

.pick__option {
  width: min(9rem, 40vw);
  aspect-ratio: 1;
  padding: 1.1rem;
  background: transparent;
  border: 2px dashed var(--pencil-soft);
  border-radius: 4px;
  cursor: pointer;
}

.pick__option:hover {
  border-style: solid;
  background: rgb(255 255 255 / 0.6);
}

.pick__option svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Board */

.board {
  position: relative;
  width: min(100%, 26rem);
  aspect-ratio: 1;
  margin-top: 1.75rem;
}

.board--demo {
  width: min(100%, 17rem);
}

.board > svg,
.board__cells {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.board__lines,
.board__strike {
  pointer-events: none;
}

.board__strike {
  z-index: 1;
}

.board__cells {
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
}

.cell {
  display: grid;
  place-items: center;
  padding: 16%;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: default;
}

.cell svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.cell:focus-visible {
  outline-offset: -6px;
}

.cell--open {
  cursor: pointer;
}

/* A faint preview of your mark, like a pencil hovering over the square. */
.cell--open:hover .ghost,
.cell--open:focus-visible .ghost {
  opacity: 0.2;
}

.ghost {
  opacity: 0;
}

/* Pen strokes */

.ink {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ink--X {
  stroke: var(--ink-x);
}

.ink--O {
  stroke: var(--ink-o);
}

.pencil {
  fill: none;
  stroke: var(--pencil);
  stroke-linecap: round;
  stroke-opacity: 0.85;
}

.draw path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 240ms cubic-bezier(0.4, 0.1, 0.4, 1) forwards;
}

.draw path + path {
  animation-delay: 200ms;
}

.board--demo .draw path {
  animation-duration: 380ms;
}

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

#result-actions {
  margin-top: 2rem;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  padding: 0.5rem 1rem;
  color: var(--paper);
  background: var(--pencil);
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
}

.toast--show {
  opacity: 1;
}

@media (max-width: 40rem) {
  :root {
    --gutter: 1.25rem;
  }

  .page {
    padding: 2rem 1.25rem 3rem calc(var(--gutter) + 1rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .draw path {
    animation: none;
    stroke-dashoffset: 0;
  }
}
