:root {
  --charcoal: #232321;
  --charcoal-deep: #1a1a18;
  --offwhite: #ece7dc;
  --faint: rgba(236, 231, 220, 0.34);
  --rule: rgba(236, 231, 220, 0.16);
  --accent: #c4614c;
  --easy: #7fa86a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--charcoal);
  color: var(--offwhite);
  font: 400 17px/1.62 Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  -webkit-font-smoothing: antialiased;
  transition: background 2400ms ease;
}

body.is-over { background: var(--charcoal-deep); }

.stage {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(240px, 360px) minmax(320px, 460px);
  gap: clamp(2rem, 6vw, 5.5rem);
  align-items: center;
  justify-content: center;
  padding: clamp(1.25rem, 4vw, 3rem);
}

@media (max-width: 820px) {
  .stage {
    grid-template-columns: minmax(0, 480px);
    grid-template-rows: auto minmax(0, 1fr);
    align-items: start;
    gap: 1rem;
  }
}

.game { min-height: 0; }

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  aspect-ratio: 1;
  width: min(100%, 52vh);
  margin: 0 auto;
}

@media (max-width: 820px) {
  .board { width: min(100%, 32vh); }
}

.cell {
  appearance: none;
  min-width: 0;
  min-height: 0;
  background: none;
  border: 0;
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 13%;
  cursor: pointer;
  color: inherit;
  transition: background 260ms ease;
}
.cell:nth-child(3n) { border-right: 0; }
.cell:nth-child(n+7) { border-bottom: 0; }

.cell:not(:disabled):hover,
.cell:not(:disabled):focus-visible { background: rgba(236, 231, 220, 0.06); }
.cell:focus-visible { outline: 1px solid var(--faint); outline-offset: -5px; }
.cell:disabled { cursor: default; }

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

.stroke {
  fill: none;
  stroke: var(--offwhite);
  stroke-width: 4.5;
  stroke-linecap: round;
}
.cell.is-human .stroke { opacity: 0.92; }
.cell.is-machine .stroke { opacity: 0.72; }
.cell.is-winning .stroke { stroke: var(--accent); opacity: 1; }

.cell circle.stroke {
  stroke-dasharray: 196;
  stroke-dashoffset: 196;
  animation: draw 620ms ease forwards;
}
.cell line.stroke {
  stroke-dasharray: 76;
  stroke-dashoffset: 76;
  animation: draw 340ms ease forwards;
}
.cell line.stroke:last-child { animation-delay: 180ms; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.cell.is-safe { box-shadow: inset 0 0 0 1px var(--accent); }
body.is-easy .cell.is-safe { box-shadow: inset 0 0 0 2px var(--easy); }

.status, .tally {
  margin: 1.5rem 0 0;
  font: 400 12px/1.4 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.16em;
  text-transform: lowercase;
  color: var(--faint);
  min-height: 1.2em;
}
.tally { margin-top: 0.35rem; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.2rem;
  margin-top: 1.1rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.2rem 0;
  background: none;
  border: 0;
  color: var(--faint);
  font: 400 11px/1.4 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: color 400ms ease;
}

.toggle .dot {
  position: relative;
  top: 0.045em;
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border: 1px solid currentColor;
  border-radius: 50%;
  transition: background 400ms ease;
}

.toggle:hover { color: rgba(236, 231, 220, 0.6); }
.toggle:focus-visible { outline: 1px solid var(--faint); outline-offset: 4px; }

.toggle[aria-pressed="true"] { color: rgba(127, 168, 106, 0.75); }
.toggle[aria-pressed="true"] .dot { background: currentColor; }
.toggle[aria-pressed="true"]:hover { color: var(--easy); }

.again {
  padding: 0.65rem 1.2rem;
  background: none;
  border: 1px solid var(--rule);
  color: var(--offwhite);
  font: 400 12px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.16em;
  text-transform: lowercase;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 300ms ease, border-color 300ms ease;
}
.again:hover { opacity: 1; border-color: var(--faint); }

.conversation {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  align-items: center;
}

.talk {
  position: relative;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem 1rem 1.5rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 3rem);
  mask-image: linear-gradient(to bottom, transparent 0, #000 3rem);
}

@media (max-width: 820px) {
  .conversation { align-items: stretch; }
  .talk { padding-right: 0.5rem; }
}

.line {
  margin: 0 0 1.3rem;
  max-width: 40ch;
  text-wrap: pretty;
  hyphens: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1400ms ease, transform 1400ms ease;
}
.line--death { margin-left: auto; }
body[data-align="text"] .line--death { text-align: right; }

.line.is-in { opacity: 0.38; transform: none; }
.line.is-in.is-lit { opacity: 1; }
.talk:hover .line.is-in { opacity: 0.72; }
.talk:hover .line.is-in.is-lit { opacity: 1; }

.divider {
  height: 1px;
  margin: 2.2rem 0 2.2rem;
  max-width: 40ch;
  background: var(--rule);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .cell circle.stroke, .cell line.stroke { stroke-dashoffset: 0; }
}
