/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --bg: #f4f1ec;
  --bg-soft: #faf8f4;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-soft: rgba(22, 28, 36, 0.05);
  --line: rgba(22, 28, 36, 0.09);
  --text: #1a1f2b;
  --muted: #6b7280;
  --brand: #10b981;
  --brand-soft: rgba(16, 185, 129, 0.12);
  --accent-x: #6366f1;
  --accent-o: #f59e0b;
  --win-glow: rgba(16, 185, 129, 0.22);
  --shadow: 0 16px 48px rgba(17, 24, 32, 0.10);
  --radius: 20px;
  --cell-radius: 14px;
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ── Page shell ────────────────────────────────────────────── */
.page-shell {
  width: min(560px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Site nav ──────────────────────────────────────────────── */
.site-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.site-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, #10b981, #6366f1);
  position: relative;
}

.site-brand-mark::before,
.site-brand-mark::after {
  content: "";
  position: absolute;
  border-radius: 5px;
}

.site-brand-mark::before {
  inset: 6px 13px 13px 6px;
  background: rgba(255, 255, 255, 0.90);
}

.site-brand-mark::after {
  inset: 13px 6px 6px 13px;
  background: rgba(99, 102, 241, 0.90);
}

.site-brand-label {
  display: block;
  color: var(--brand);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.site-brand-name {
  display: block;
  font-size: 15px;
  font-weight: 800;
}

.site-links {
  display: flex;
  gap: 8px;
}

.site-links a,
.site-links .mini-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  transition: border-color var(--transition), background var(--transition);
}

.site-links button.mini-link {
  font: inherit;
  cursor: pointer;
}

.site-links a:hover,
.site-links .mini-link:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

/* ── Game card ─────────────────────────────────────────────── */
.game-card {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Status bar ────────────────────────────────────────────── */
.status-bar {
  text-align: center;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 12px;
  background: var(--panel-soft);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  transition: background var(--transition);
}

.status-bar[data-status="won"] {
  background: var(--win-glow);
  color: #065f46;
}

.status-bar[data-status="draw"] {
  background: rgba(245, 158, 11, 0.12);
  color: #92400e;
}

.status-bar .turn-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-x);
  transition: background var(--transition);
}

.status-bar .turn-indicator[data-turn="O"] {
  background: var(--accent-o);
}

/* ── Board ─────────────────────────────────────────────────── */
.board-wrapper {
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: min(340px, 80vw);
  aspect-ratio: 1;
  border-radius: 16px;
  padding: 6px;
  background: var(--line);
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border-radius: var(--cell-radius);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.cell:hover:not(.cell--filled):not(.cell--disabled) {
  background: #fff;
  transform: scale(1.03);
}

.cell--filled {
  cursor: default;
}

.cell--disabled {
  cursor: default;
  opacity: 0.85;
}

.cell--selectable {
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--brand);
  animation: pulse-ring 1.6s ease-in-out infinite;
}

.cell--selected {
  background: var(--brand-soft) !important;
  box-shadow: 0 0 0 3px var(--brand);
  transform: scale(1.06);
  animation: none;
}

.cell--win {
  background: var(--win-glow) !important;
  transform: scale(1.06);
}

.cell--last-move {
  box-shadow: inset 0 0 0 2px rgba(16, 185, 129, 0.28);
}

@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 2px var(--brand); }
  50% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.3); }
}

/* ── Piece marks ───────────────────────────────────────────── */
.mark {
  width: 60%;
  height: 60%;
  position: relative;
  animation: mark-pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes mark-pop {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* X mark — two rotated bars */
.mark-x::before,
.mark-x::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 80%;
  height: 14%;
  border-radius: 4px;
  background: var(--accent-x);
  transform-origin: center;
}

.mark-x::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.mark-x::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* O mark — circle ring */
.mark-o::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: clamp(4px, 1.4vw, 7px) solid var(--accent-o);
  transform: translate(-50%, -50%);
}

/* ── Controls ──────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.btn:active {
  transform: scale(0.96);
}

.btn--active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.btn--active:hover {
  background: #059669;
  border-color: #059669;
}

.btn--restart {
  background: var(--panel-soft);
  border-color: transparent;
}

.btn--restart:hover {
  background: var(--line);
}

/* ── Score strip ───────────────────────────────────────────── */
.score-strip {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.score-strip .score-x { color: var(--accent-x); }
.score-strip .score-o { color: var(--accent-o); }
.score-strip .score-d { color: var(--muted); }

/* ── Footer ────────────────────────────────────────────────── */
.game-footer {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.game-footer a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}

.game-footer a:hover {
  text-decoration: underline;
}

/* ── Hint text ─────────────────────────────────────────────── */
.hint {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
  transition: opacity var(--transition);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .page-shell {
    width: calc(100% - 16px);
    padding: 10px 0 28px;
    gap: 12px;
  }

  .site-nav {
    padding: 10px 12px;
    border-radius: 14px;
  }

  .site-brand-name {
    font-size: 14px;
  }

  .game-card {
    padding: 16px;
    border-radius: 16px;
    gap: 14px;
  }

  .board {
    width: min(300px, 85vw);
  }

  .controls {
    gap: 6px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 12px;
  }
}
