@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&display=swap');

:root {
  --bg: #0c0c14;
  --x-color: #ff5c87;
  --x-glow: rgba(255, 92, 135, 0.5);
  --o-color: #3ecfcf;
  --o-glow: rgba(62, 207, 207, 0.5);
  --accent: #a78bfa;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.07);
  --surface-cell: rgba(255, 255, 255, 0.04);
  --surface-cell-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.09);
  --border-hover: rgba(255, 255, 255, 0.18);
  --text: #f0f0f8;
  --text-muted: rgba(240, 240, 248, 0.45);
  --text-subtle: rgba(240, 240, 248, 0.25);
  --strike-line-thickness: 3px;
  --radius: 20px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 65% 55% at 10% 5%,  rgba(255, 92, 135, 0.13) 0%, transparent 55%),
    radial-gradient(ellipse 55% 45% at 90% 95%,  rgba(62, 207, 207, 0.11) 0%, transparent 55%),
    radial-gradient(ellipse 45% 35% at 55% 50%, rgba(167, 139, 250, 0.07) 0%, transparent 60%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text);
  padding: 1.5rem;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: 400px;
  background: rgba(18, 14, 28, 0.75);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.025),
    0 40px 90px rgba(0, 0, 0, 0.65),
    0 0 80px rgba(255, 92, 135, 0.04),
    0 0 80px rgba(62, 207, 207, 0.04);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ─── Header ─────────────────────────────────── */
.game-header {
  padding: 1.75rem 1.75rem 1.5rem;
  text-align: left;
  background: transparent;
  border-bottom: 1px solid var(--border);
}

h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--x-color) 0%, var(--accent) 50%, var(--o-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1.25rem;
}

h1::after { display: none; }

.controls-wrapper { padding: 0; }

.status-area {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.65rem;
}

#status {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0;
  background: transparent;
  border: none;
  min-width: 0;
  text-align: left;
  letter-spacing: 0.01em;
  transition: color 0.2s;
}

.mode-selection {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mode-selection label {
  color: var(--text-subtle);
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

select {
  padding: 0.28rem 1.5rem 0.28rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='rgba(240,240,248,0.3)' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  backdrop-filter: blur(8px);
}

select:hover {
  border-color: var(--border-hover);
  background-color: var(--surface-hover);
}

select:focus {
  outline: none;
  border-color: rgba(167, 139, 250, 0.4);
}

select option {
  background: #16101e;
  color: var(--text);
}

/* ─── Board ──────────────────────────────────── */
.board-container {
  padding: 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  background: transparent;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 1px;
  aspect-ratio: 1 / 1;
  width: 100%;
  background: rgba(255,255,255,0.07);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.07);
}

.cell {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--surface-cell);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0;
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}

.cell:hover {
  background: var(--surface-cell-hover);
  transform: none;
  box-shadow: none;
}

.cell:active { background: rgba(255,255,255,0.12); }

/* ─── X ──────────────────────────────────────── */
.cell.X {
  background: rgba(255, 92, 135, 0.07);
}

.cell.X:hover {
  background: rgba(255, 92, 135, 0.1);
}

.cell.X::before,
.cell.X::after {
  content: '';
  position: absolute;
  width: 40%;
  height: 2px;
  border-radius: 2px;
  background: var(--x-color);
  box-shadow: 0 0 8px var(--x-glow), 0 0 2px var(--x-color);
  top: 50%;
  left: 50%;
}

.cell.X::before {
  transform: translate(-50%, -50%) rotate(45deg);
  animation: markInX1 0.18s ease forwards;
}
.cell.X::after {
  transform: translate(-50%, -50%) rotate(-45deg);
  animation: markInX2 0.18s ease forwards;
}

@keyframes markInX1 {
  from { opacity: 0; transform: translate(-50%, -50%) rotate(45deg)  scale(0.5); }
  to   { opacity: 1; transform: translate(-50%, -50%) rotate(45deg)  scale(1); }
}
@keyframes markInX2 {
  from { opacity: 0; transform: translate(-50%, -50%) rotate(-45deg) scale(0.5); }
  to   { opacity: 1; transform: translate(-50%, -50%) rotate(-45deg) scale(1); }
}

/* ─── O ──────────────────────────────────────── */
.cell.O {
  font-size: 0;
  background: rgba(62, 207, 207, 0.07);
}

.cell.O:hover {
  background: rgba(62, 207, 207, 0.1);
}

.cell.O::before {
  content: '';
  position: absolute;
  width: 40%;
  height: 40%;
  border: 2px solid var(--o-color);
  box-shadow: 0 0 8px var(--o-glow), 0 0 2px var(--o-color);
  background-color: transparent;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  animation: markInO 0.18s ease forwards;
}

@keyframes markInO {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ─── Game Over ──────────────────────────────── */
.game-over .cell { cursor: not-allowed; }
.game-over .cell:hover { background: var(--surface-cell); }
.game-over .cell.X:hover { background: rgba(255, 92, 135, 0.07); }
.game-over .cell.O:hover { background: rgba(62, 207, 207, 0.07); }

/* ─── AI Thinking ────────────────────────────── */
.board.ai-thinking .cell { pointer-events: none; }

.board.ai-thinking::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(12, 12, 20, 0.5);
  z-index: 20;
  animation: dimPulse 1s infinite ease-in-out;
}

@keyframes dimPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.75; }
}

/* ─── Strike Line ────────────────────────────── */
#strike-line {
  position: absolute;
  background: linear-gradient(90deg, var(--x-color), var(--accent), var(--o-color));
  height: var(--strike-line-thickness);
  border-radius: 999px;
  display: none;
  z-index: 10;
  box-shadow: 0 0 10px rgba(167, 139, 250, 0.6), 0 0 20px rgba(167, 139, 250, 0.3);
}

.strike-row-0 { top: calc(16.67% - (var(--strike-line-thickness) / 2)); left: 8%; width: 84%; display: block; }
.strike-row-1 { top: calc(50%    - (var(--strike-line-thickness) / 2)); left: 8%; width: 84%; display: block; }
.strike-row-2 { top: calc(83.33% - (var(--strike-line-thickness) / 2)); left: 8%; width: 84%; display: block; }

.strike-col-0 { top: 8%; left: calc(16.67% - (var(--strike-line-thickness) / 2)); width: var(--strike-line-thickness); height: 84% !important; display: block; }
.strike-col-1 { top: 8%; left: calc(50%    - (var(--strike-line-thickness) / 2)); width: var(--strike-line-thickness); height: 84% !important; display: block; }
.strike-col-2 { top: 8%; left: calc(83.33% - (var(--strike-line-thickness) / 2)); width: var(--strike-line-thickness); height: 84% !important; display: block; }

.strike-diag-0 { top: 10%; left: 10%;  width: 115%; transform: rotate(45deg);  transform-origin: top left;  display: block; }
.strike-diag-1 { top: 10%; right: 10%; left: auto; width: 115%; transform: rotate(-45deg); transform-origin: top right; display: block; }

/* ─── Bottom Bar ─────────────────────────────── */
.bottom-bar {
  padding: 1.1rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
}

#goBackButton {
  text-decoration: none;
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.9rem;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.2s, color 0.2s;
  display: inline-block;
  letter-spacing: 0.01em;
}

#goBackButton:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--text);
}


#resetButton {
  background: linear-gradient(135deg, rgba(255,92,135,0.12), rgba(167,139,250,0.12), rgba(62,207,207,0.12));
  color: var(--text);
  border: 1px solid rgba(167, 139, 250, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.9rem;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.2s, box-shadow 0.2s;
  display: inline-block;
  letter-spacing: 0.01em;
  margin: 0;
  backdrop-filter: blur(8px);
}

#resetButton:hover {
  background: linear-gradient(135deg, rgba(255,92,135,0.2), rgba(167,139,250,0.2), rgba(62,207,207,0.2));
  border-color: rgba(167, 139, 250, 0.5);
  box-shadow: 0 0 16px rgba(167, 139, 250, 0.15);
  transform: none;
}

#resetButton:active {
  background: linear-gradient(135deg, rgba(255,92,135,0.25), rgba(167,139,250,0.25), rgba(62,207,207,0.25));
}

.game-footer {
  font-size: 0.7rem;
  color: var(--text-subtle);
  letter-spacing: 0.03em;
  padding: 0;
  background: transparent;
  border: none;
}

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 480px) {
  body { padding: 1rem; }
  .container { border-radius: 16px; }
  .game-header { padding: 1.4rem 1.4rem 1.2rem; }
  .board-container { padding: 1.25rem; }
  h1 { font-size: 1rem; }
}