:root {
  --bg-1: #0f1226;
  --bg-2: #1a1f3d;
  --surface: #191d3a;
  --surface-2: #232a52;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f5fb;
  --text-dim: #9aa0c3;
  --x-color: #5ee7ff;
  --x-glow: rgba(94, 231, 255, 0.55);
  --o-color: #ff6fb1;
  --o-glow: rgba(255, 111, 177, 0.55);
  --draw-color: #ffd166;
  --accent: #7c5cff;
  --accent-2: #5ee7ff;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow-soft: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(124, 92, 255, 0.35), transparent 55%),
    radial-gradient(circle at 85% 90%, rgba(94, 231, 255, 0.25), transparent 50%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  padding: 24px;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.header h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 40px);
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--x-color), var(--accent), var(--o-color));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
}

/* ---------- Mode select ---------- */

.mode-select {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: fadeIn 0.4s ease;
}

.subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 500;
}

.subtitle.small {
  font-size: 13px;
}

.mode-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.mode-btn:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.25);
}

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

.mode-icon {
  font-size: 30px;
}

.difficulty {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: fadeIn 0.3s ease;
}

.difficulty-buttons {
  grid-template-columns: 1fr 1fr;
}

.diff-btn {
  padding: 14px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.diff-btn:hover {
  color: var(--text);
}

.diff-btn.selected {
  color: var(--bg-1);
  background: linear-gradient(120deg, var(--x-color), var(--accent));
  border-color: transparent;
}

/* ---------- Game ---------- */

.game {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: fadeIn 0.4s ease;
}

.status-bar {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: rotate(-8deg);
}

.scoreboard {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  gap: 8px;
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.score-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}

.score-value {
  font-size: 20px;
  font-weight: 800;
}

.x-color .score-value { color: var(--x-color); }
.o-color .score-value { color: var(--o-color); }
.draw-color .score-value { color: var(--draw-color); }

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  min-height: 24px;
}

.turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--x-color);
  box-shadow: 0 0 12px var(--x-glow);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.turn-dot.o {
  background: var(--o-color);
  box-shadow: 0 0 12px var(--o-glow);
}

.board {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.cell {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(34px, 9vw, 52px);
  font-weight: 800;
  cursor: pointer;
  color: var(--text);
  position: relative;
  transition: background 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.cell:hover:not(:disabled):not(.filled) {
  background: rgba(255, 255, 255, 0.09);
}

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

.cell:disabled {
  cursor: default;
}

.cell.x { color: var(--x-color); text-shadow: 0 0 18px var(--x-glow); }
.cell.o { color: var(--o-color); text-shadow: 0 0 18px var(--o-glow); }

.cell.pop {
  animation: pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell.win {
  animation: winPulse 1s ease-in-out infinite;
}

.win-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.win-line line {
  stroke: var(--accent-2);
  stroke-width: 6;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px var(--accent-2));
  opacity: 0;
  transition: opacity 0.2s ease;
}

.win-line.show line {
  opacity: 1;
}

.primary-btn {
  padding: 13px 28px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(120deg, var(--x-color), var(--accent));
  color: #0d0f24;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(124, 92, 255, 0.45);
}

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

/* ---------- Overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 20, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fadeIn 0.2s ease;
  padding: 20px;
}

.overlay-card {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow-soft);
  max-width: 340px;
  width: 100%;
  animation: pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay-message {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
}

/* ---------- Animations ---------- */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes winPulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.35) inset; }
}

@media (max-width: 380px) {
  .score-label { max-width: 60px; }
}
