:root {
  --bg-a: #f4f7fb;
  --bg-b: #eef4ff;
  --bg-c: #fffaf1;
  --ink-strong: #1f2a44;
  --ink-soft: #5e6a85;
  --surface: rgba(255, 252, 247, 0.82);
  --surface-strong: rgba(255, 255, 255, 0.9);
  --border: rgba(107, 126, 162, 0.22);
  --border-strong: rgba(86, 108, 152, 0.36);
  --shadow: 0 24px 60px rgba(52, 72, 105, 0.16);
  --x-color: #2d6df6;
  --o-color: #ee6a3b;
  --win-bg: #c7f0c9;
  --win-glow: rgba(78, 175, 91, 0.28);
  --focus: #173f9d;
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --radius-pill: 999px;
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink-strong);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.8), transparent 38%),
    linear-gradient(145deg, var(--bg-a), var(--bg-b) 55%, var(--bg-c));
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-bg {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(244, 247, 251, 0.6), rgba(244, 247, 251, 0.7)),
    url("./assets/tictactoe-ambient-bg.png") center/cover no-repeat;
  opacity: 0.9;
  pointer-events: none;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-5);
}

.game-card {
  width: min(1040px, 100%);
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(rgba(255, 252, 247, 0.72), rgba(255, 255, 255, 0.84)),
    url("./assets/tictactoe-paper-texture.png") center/cover;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-copy {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.eyebrow {
  margin: 0;
  font-size: 0.88rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.hero-copy h1 {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
  font-size: clamp(2.4rem, 5vw, 4.5rem);
  line-height: 1;
  letter-spacing: 0.04em;
}

.subtitle {
  margin: 0;
  max-width: 44ch;
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(250px, 0.7fr);
  gap: var(--space-5);
  align-items: start;
}

.play-panel,
.info-panel {
  border: 1px solid rgba(108, 127, 164, 0.18);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.55);
}

.play-panel {
  padding: var(--space-4);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  width: min(100%, 520px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: var(--space-2);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(240, 245, 252, 0.88)),
    url("./assets/tictactoe-paper-texture.png") center/cover;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(103, 124, 164, 0.18);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  color: var(--ink-strong);
  font-size: clamp(3rem, 10vw, 5rem);
  font-weight: 700;
  line-height: 1;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease;
}

.cell:hover:not(:disabled),
.cell:focus-visible {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.75),
    0 12px 20px rgba(66, 91, 140, 0.16);
}

.cell:focus-visible {
  outline: 3px solid rgba(23, 63, 157, 0.28);
  outline-offset: 2px;
}

.cell:disabled {
  cursor: default;
}

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

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

.cell.is-winning {
  border-color: rgba(78, 175, 91, 0.35);
  background: linear-gradient(180deg, #e9fae7, var(--win-bg));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.7),
    0 0 0 4px rgba(130, 207, 138, 0.18),
    0 16px 28px var(--win-glow);
}

.cell.is-filled {
  cursor: not-allowed;
}

.cell.is-filled:hover {
  transform: none;
  border-color: rgba(103, 124, 164, 0.18);
  box-shadow: none;
}

.cell.is-invalid {
  animation: nudge 220ms ease;
}

.status-panel {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: rgba(247, 250, 255, 0.82);
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
}

.status-text {
  margin: 0;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  font-weight: 700;
}

.starter-badge,
.legend-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(110, 128, 163, 0.16);
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 600;
}

.hint-text {
  margin: 0;
  min-height: 1.6em;
  color: var(--ink-soft);
  font-size: 0.96rem;
  transition: color 160ms ease;
}

.hint-text.is-alert {
  color: #aa4e2d;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.control-button {
  min-height: 52px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-weight: 700;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease;
}

.control-button:hover,
.control-button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 16px 24px rgba(65, 87, 128, 0.16);
}

.control-button:active {
  transform: translateY(1px);
}

.control-button:focus-visible {
  outline: 3px solid rgba(23, 63, 157, 0.22);
  outline-offset: 2px;
}

.control-button.primary {
  background: linear-gradient(180deg, #2d6df6, #2559c5);
  color: #ffffff;
}

.control-button.secondary {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(95, 116, 154, 0.18);
  color: var(--ink-strong);
}

.info-panel {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
}

.info-block {
  display: grid;
  gap: var(--space-2);
}

.info-block h2 {
  margin: 0;
  font-size: 1.05rem;
}

.info-block p {
  margin: 0;
  line-height: 1.7;
  color: var(--ink-soft);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.x-chip {
  color: var(--x-color);
}

.o-chip {
  color: var(--o-color);
}

.win-chip {
  color: #347d3e;
  background: rgba(199, 240, 201, 0.72);
}

.site-footer {
  margin-top: var(--space-4);
  color: rgba(52, 67, 98, 0.78);
  font-size: 0.95rem;
  text-align: center;
}

@keyframes nudge {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@media (max-width: 1023px) {
  .game-card {
    padding: var(--space-5);
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 679px) {
  .app-shell {
    padding: var(--space-3);
  }

  .game-card {
    padding: var(--space-4);
    border-radius: 24px;
  }

  .play-panel,
  .info-panel {
    padding: var(--space-3);
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .control-button {
    width: 100%;
  }

  .status-row {
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
