:root {
  --font-display: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "Gill Sans", "Noto Sans", "Lucida Grande", sans-serif;
  --ink-strong: #1f2933;
  --ink-soft: #52606d;
  --surface: #f4f2ec;
  --surface-panel: #fffaf1;
  --surface-card: #fffdf8;
  --line-soft: #d9cdb7;
  --line-strong: #2f3e4d;
  --accent: #df5f2f;
  --shadow-soft: 0 16px 30px rgba(31, 41, 51, 0.14);
  --shadow-lift: 0 28px 54px rgba(31, 41, 51, 0.2);
  --x-color: #dc2626;
  --o-color: #2563eb;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink-strong);
  font-family: var(--font-body);
  background: radial-gradient(circle at 100% -20%, rgba(223, 95, 47, 0.22), transparent 44%),
              radial-gradient(circle at 8% 14%, rgba(26, 122, 128, 0.24), transparent 42%),
              linear-gradient(175deg, #f8f3e7 0%, #efe5d5 52%, #e9ddc8 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image: linear-gradient(38deg, rgba(47, 62, 77, 0.08) 1px, transparent 1px),
                    linear-gradient(-38deg, rgba(47, 62, 77, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  z-index: -1;
}

.app {
  width: min(1320px, calc(100vw - 1rem));
  margin: 0.7rem auto 1.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.back-link {
  color: var(--ink-strong);
  text-decoration: none;
  font-weight: 500;
}

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

.hero {
  text-align: center;
  padding: 1.5rem 1rem 1rem;
  background: var(--surface-panel);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
}

.hero-copy h1 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  margin: 0 0 0.25rem;
}

main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 700px) {
  main { grid-template-columns: 1fr; }
}

.board-panel {
  background: var(--surface-panel);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-soft);
}

.play-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.board-container {
  aspect-ratio: 1;
  max-width: min(70vw, 320px);
  width: 100%;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  aspect-ratio: 1;
  background: var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
}

.cell {
  background: var(--surface-panel);
  border: none;
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.status-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.player-indicator {
  font-size: 1.5rem;
}

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

.controls { display: flex; }

.control-card {
  background: var(--surface-card);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-soft);
}

#restart,
.overlay .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 140px;
  min-height: 48px;
  padding: 0.7rem 1.4rem;
  border-radius: 24px;
  border: 2px solid var(--line-strong);
  background: linear-gradient(135deg, var(--surface-card) 0%, var(--surface-panel) 100%);
  font: 700 1rem var(--font-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(31, 41, 51, 0.15);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

#restart:hover,
.overlay .btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(31, 41, 51, 0.2);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.overlay-panel {
  background: white;
  padding: 2rem;
  border-radius: 16px;
  text-align: center;
  box-shadow: var(--shadow-lift);
}

.overlay-panel h2 { margin: 0 0 1rem; }

.hidden { display: none !important; }