:root {
  --bg: #fbfbfa;
  --fg: #23211e;
  --muted: #8a857d;
  --line: #ddd9d2;
  --accent: #2f6f4f;
  --x: #b4522f;
  --o: #35618a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --fg: #e8e5e0;
    --muted: #8f8a82;
    --line: #33302c;
    --accent: #6fae8c;
    --x: #e08a63;
    --o: #7aa8d0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 3rem 1.25rem 2rem;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

main { width: 100%; max-width: 26rem; }

h1 {
  margin: 0 0 .25rem;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -.01em;
}

.sub { margin: 0 0 1.75rem; color: var(--muted); font-size: .95rem; }

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: .4rem .8rem;
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}

.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  border-radius: 8px;
  padding: .4rem .8rem;
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}

.ghost:hover { border-color: var(--muted); }

#board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--line);
  border: 6px solid var(--line);
  border-radius: 10px;
}

.cell {
  aspect-ratio: 1;
  border: 0;
  background: var(--bg);
  font: 600 2.6rem/1 system-ui, sans-serif;
  color: var(--fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s;
}

.cell:hover:not([disabled]) { background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.cell[disabled] { cursor: default; }
.cell.x { color: var(--x); }
.cell.o { color: var(--o); }
.cell.win { background: color-mix(in srgb, var(--accent) 18%, var(--bg)); }

#status {
  text-align: center;
  min-height: 1.6em;
  margin: 1rem 0 1.5rem;
  font-size: .95rem;
  color: var(--muted);
}

.score {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  margin-bottom: 2rem;
}

.score caption {
  text-align: left;
  color: var(--muted);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding-bottom: .4rem;
}

.score th, .score td {
  border: 1px solid var(--line);
  padding: .45rem;
  text-align: center;
}

.score th { font-weight: 500; color: var(--muted); font-size: .8rem; }
.score td { font-variant-numeric: tabular-nums; font-size: 1.1rem; }

details { font-size: .9rem; color: var(--muted); }
details summary { cursor: pointer; color: var(--fg); }
details p { margin: .75rem 0; }

footer {
  margin-top: auto;
  padding-top: 2.5rem;
  font-size: .8rem;
  color: var(--muted);
}

footer a { color: inherit; }
