:root {
  --bg: #f4f1ea;
  --bg-card: #fbfaf6;
  --ink: #2b2722;
  --muted: #8a8378;
  --line: #e3ddd0;
  --x: #d9513b;
  --o: #2f8f83;
  --accent: #c9a24a;
  --shadow: 0 18px 40px -24px rgba(43, 39, 34, 0.55);
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  background:
    radial-gradient(120% 90% at 50% -10%, #fffdf7 0%, var(--bg) 60%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.board-wrap {
  width: min(26rem, 100%);
  text-align: center;
}

header h1 {
  margin: 0 0 0.2rem;
  font-size: clamp(2rem, 6vw, 2.6rem);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

header p {
  margin: 0 0 1.6rem;
  color: var(--muted);
  font-style: italic;
}

/* Mode toggle */
.modes {
  display: inline-flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  padding: 0.25rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.modes button {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 0.95rem;
  color: var(--muted);
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease;
}

.modes button[aria-pressed="true"] {
  background: var(--ink);
  color: #fbfaf6;
}

/* Status line */
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.2rem;
  margin-bottom: 1.1rem;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
}

.status .mark { font-weight: 700; }
.status .mark.x { color: var(--x); }
.status .mark.o { color: var(--o); }

/* Board */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  aspect-ratio: 1;
  margin-bottom: 1.6rem;
}

.cell {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-card);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  font-family: inherit;
  font-size: clamp(2.4rem, 14vw, 4rem);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.cell:hover:not(:disabled):empty {
  transform: translateY(-2px);
  background: #fffdf7;
}

.cell:disabled { cursor: default; }

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

.cell.win {
  background: var(--accent);
  color: #fbfaf6;
  box-shadow: 0 0 0 2px var(--accent), var(--shadow);
}

/* mark drop-in */
.cell.placed { animation: pop 0.18s ease; }
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Restart */
.restart {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-card);
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  padding: 0.7rem 1.8rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, background 0.18s ease;
}

.restart:hover { transform: translateY(-2px); background: #fffdf7; }
.restart:active { transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  *, .cell.placed { animation: none !important; transition: none !important; }
}
