:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #7a8497;
  --border: #e6eaf0;
  --primary: #5b5ce2;
  --primary-light: #eef0ff;
  --x-color: #5865f2;
  --o-color: #ef6477;
  --success: #22a06b;
  --shadow: 0 24px 70px rgba(30, 42, 70, 0.12);
  --board-gap: 10px;
}

button {
  font: inherit;
}

.game-container {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.game-card {
  background: var(--card);
  border: 1px solid rgba(230, 234, 240, 0.9);
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.game-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--primary);
}

h1 {
  margin: 0;
  font-size: clamp(30px, 7vw, 42px);
  line-height: 1;
  letter-spacing: -0.04em;
}

.subtitle {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.btn {
  border: 0;
  cursor: pointer;
  border-radius: 11px;
  padding: 10px 13px;
  font-size: 12px;
  font-weight: 700;
  transition:
    transform 0.18s ease,
    background 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-secondary-v1 {
  color: #fff !important;
  background: #454c53 !important;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #f1f3f7;
  border-radius: 13px;
  margin-bottom: 20px;
}

.mode-btn {
  border: 0;
  border-radius: 10px;
  padding: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease;
}

.mode-btn.active {
  background: white;
  color: var(--text);
  box-shadow: 0 3px 10px rgba(20, 30, 50, 0.08);
}

.settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.setting-group {
  min-width: 0;
}

.setting-label {
  display: block;
  margin: 0 0 7px 2px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  background: #f4f5f8;
  border-radius: 10px;
}

.setting-group:last-child .segmented-control {
  grid-template-columns: 1fr 1fr;
}

.difficulty-btn,
.symbol-btn {
  border: 0;
  border-radius: 8px;
  padding: 8px 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  transition:
    background 0.18s ease,
    color 0.18s ease;
}

.difficulty-btn.active,
.symbol-btn.active {
  background: white;
  color: var(--text);
  box-shadow: 0 2px 6px rgba(20, 30, 50, 0.07);
}

.hidden {
  display: none !important;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.score-card {
  padding: 10px 7px;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
  background: #fafbfc;
  transition:
    border-color 0.2s ease,
    background 0.2s ease;
}

.score-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.score-card strong {
  font-size: 20px;
  line-height: 1;
}

.player-score {
  border-color: rgba(88, 101, 242, 0.18);
}

.computer-score {
  border-color: rgba(239, 100, 119, 0.18);
}

.x-score {
  border-color: rgba(88, 101, 242, 0.18);
}

.o-score {
  border-color: rgba(239, 100, 119, 0.18);
}

.status-area {
  min-height: 27px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.turn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--x-color);
  transition: background 0.2s ease;
}

.thinking-indicator {
  display: none;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.thinking-indicator.visible {
  display: flex;
}

.thinking-indicator .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  animation: thinking 1s infinite ease-in-out;
}

.thinking-indicator .dot:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-indicator .dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes thinking {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }

  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

.board-wrapper {
  width: 100%;
  aspect-ratio: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: var(--board-gap);
  width: 100%;
  height: 100%;
  padding: 7px;
  background: #eef0f5;
  border-radius: 20px;
}

.cell {
  position: relative;
  border: 0;
  border-radius: 14px;
  background: white;
  cursor: pointer;
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  transition:
    background 0.16s ease,
    transform 0.16s ease,
    box-shadow 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.cell:not(.occupied):not(.disabled):hover {
  background: #f7f8ff;
  box-shadow: inset 0 0 0 2px rgba(91, 92, 226, 0.1);
}

.cell:not(.occupied):not(.disabled):active {
  transform: scale(0.96);
}

.cell.disabled {
  cursor: default;
}

.cell.occupied {
  cursor: default;
}

.cell.x::after,
.cell.o::after {
  animation: placePiece 0.22s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.cell.x::after {
  content: "X";
  color: var(--x-color);
  font-size: clamp(45px, 12vw, 68px);
  font-weight: 850;
  line-height: 1;
  letter-spacing: -0.08em;
}

.cell.o::after {
  content: "O";
  color: var(--o-color);
  font-size: clamp(45px, 12vw, 68px);
  font-weight: 800;
  line-height: 1;
}

@keyframes placePiece {
  0% {
    opacity: 0;
    transform: scale(0.55);
  }

  65% {
    transform: scale(1.08);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.cell.winner {
  background: #ecf9f2;
  box-shadow:
    inset 0 0 0 2px rgba(34, 160, 107, 0.25),
    0 0 0 2px rgba(34, 160, 107, 0.08);
  animation: winningCell 0.7s ease-in-out infinite alternate;
}

@keyframes winningCell {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.025);
  }
}

.result-panel {
  text-align: center;
  padding: 18px 10px 4px;
  animation: resultIn 0.25s ease both;
}

@keyframes resultIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-label {
  margin: 0 0 4px;
  color: var(--success);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.13em;
}

.result-panel h2 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -0.03em;
}

.result-panel p:last-child {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.new-game-btn, .btn-secondary-v1 {
  padding: 14px 20px !important;
  border: 0;
  border-radius: 13px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(91, 92, 226, 0.22);
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease;
}

.new-game-btn:hover {
  background: #5051d3;
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(91, 92, 226, 0.27);
}

.new-game-btn:active {
  transform: translateY(0);
}

button:focus-visible {
  outline: 3px solid rgba(91, 92, 226, 0.3);
  outline-offset: 2px;
}

@media (max-width: 520px) {
  body {
    padding: 12px;
    align-items: flex-start;
  }

  .game-container {
    margin-top: 10px;
  }

  .game-card {
    padding: 20px;
    border-radius: 22px;
  }

  .game-header {
    margin-bottom: 20px;
  }

  .game-header .btn {
    padding: 9px 10px;
  }

  .subtitle {
    font-size: 13px;
  }

  .board {
    gap: 7px;
    padding: 5px;
    border-radius: 16px;
  }

  .cell {
    border-radius: 11px;
  }
}

@media (max-width: 380px) {
  body {
    padding: 8px;
  }

  .game-card {
    padding: 16px;
  }

  .game-header {
    gap: 10px;
  }

  .game-header .btn {
    font-size: 11px;
  }

  .settings {
    gap: 7px;
  }

  .score-label {
    font-size: 9px;
  }
}

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