/* ===== Theme tokens: dark, game-style ===== */
:root {
  --bg: #0f1020;
  --bg-grad-1: #1a1a3e;
  --bg-grad-2: #0f1020;
  --panel: #1c1d35;
  --panel-soft: #25274a;
  --cell: #2a2c52;
  --cell-hover: #353871;
  --text: #e8e9f3;
  --text-dim: #9a9cc4;
  --x-color: #ff4d6d;
  --o-color: #38e0c9;
  --win: #ffd166;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --cell-size: 30px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 50% 0%, var(--bg-grad-1), var(--bg-grad-2) 70%);
}

/* ===== Layout ===== */
.game {
  width: 100%;
  max-width: 760px;
  background: var(--panel);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.game__header { text-align: center; margin-bottom: 18px; }

.game__title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(90deg, var(--x-color), var(--o-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.game__subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 2px; }

/* ===== Scoreboard ===== */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.score {
  background: var(--panel-soft);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.score__label { font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.score__value { font-size: 1.5rem; font-weight: 800; }

.score--x .score__value { color: var(--x-color); }
.score--o .score__value { color: var(--o-color); }
.score--draw .score__value { color: var(--text-dim); }

/* ===== Status ===== */
.status {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  min-height: 1.6em;
}

.status__mark { font-weight: 800; }
.status__mark--x { color: var(--x-color); }
.status__mark--o { color: var(--o-color); }

/* ===== Board (50x50, cuộn được; số cột do JS đặt qua grid-template-columns) ===== */
.board-scroll {
  max-height: 65vh;
  overflow: auto;
  border-radius: 12px;
  background: var(--bg);
  padding: 6px;
  -webkit-overflow-scrolling: touch;
}

.board {
  display: grid;
  grid-auto-rows: var(--cell-size);
  gap: 2px;
  width: max-content;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--cell);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
  user-select: none;
  padding: 2px;
}

.cell:hover:not(.cell--filled) { background: var(--cell-hover); }

/* Ô máy vừa đánh: viền nổi bật để biết đánh chỗ nào */
.cell--last { box-shadow: 0 0 0 2px var(--win); }

/* Highlight đường thắng */
.cell--win { background: var(--win); animation: pop 0.3s ease; }
.cell--win .mark { stroke: var(--bg); }

@keyframes pop {
  0% { transform: scale(0.8); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ===== Ký hiệu X / O dạng SVG, có hiệu ứng "vẽ nét" ===== */
.mark {
  width: 100%;
  height: 100%;
  fill: none;
  stroke-width: 16;
  stroke-linecap: round;
}
.mark--x { stroke: var(--x-color); }
.mark--o { stroke: var(--o-color); }

.mark line, .mark circle {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 0.45s ease forwards;
}
.mark line:nth-child(2) { animation-delay: 0.18s; }

@keyframes draw { to { stroke-dashoffset: 0; } }

/* ===== Reset button ===== */
.reset-btn {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: linear-gradient(90deg, var(--x-color), var(--o-color));
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.08s ease;
}

.reset-btn:hover { opacity: 0.9; }
.reset-btn:active { transform: scale(0.98); }

/* ===== Popup kết quả ===== */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 8, 20, 0.72);
  backdrop-filter: blur(3px);
  z-index: 10;
  animation: fade 0.2s ease;
}

.modal[hidden] { display: none; }

.modal__card {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 360px;
  width: 100%;
  animation: pop 0.3s ease;
}

.modal__msg {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 20px;
  background: linear-gradient(90deg, var(--x-color), var(--o-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal__btn {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: linear-gradient(90deg, var(--x-color), var(--o-color));
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.08s ease;
}

.modal__btn:hover { opacity: 0.9; }
.modal__btn:active { transform: scale(0.98); }

/* Hai nút chọn người đi trước */
.modal__choices { display: flex; gap: 10px; }
.modal__choices .modal__btn { flex: 1; }
.modal__btn--alt {
  background: var(--panel-soft);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ===== Mobile ===== */
@media (max-width: 560px) {
  :root { --cell-size: 26px; }
  .game { padding: 14px; border-radius: 16px; }
  .game__title { font-size: 1.7rem; }
  .board-scroll { max-height: 60vh; }
  .modal__msg { font-size: 1.3rem; }
}
