:root {
  --bg: #0a0e17;
  --panel: #121826;
  --panel-2: #1a2233;
  --accent: #4df3ff;
  --accent-2: #b866ff;
  --text: #e8f4ff;
  --text-dim: #9fb2c9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 2.5rem 1.5rem 3rem;
  gap: 1.5rem;
}

#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  overflow: hidden;
}

#loading-overlay p {
  font-size: 1.5rem;
  color: var(--accent);
  font-family: monospace;
  white-space: nowrap;
  overflow: hidden;
  border-right: 3px solid transparent;
  display: inline-block;
  animation: 
    typing 1s steps(13) forwards,
    blink-cursor 0.75s step-end infinite;
}

@keyframes typing {
  from { width: 0;}
  to { width: 13ch;}
}

@keyframes blink-cursor {
  from, to {border-color: transparent;}
  50% {border-color: var(--accent);}
}
#loading-overlay.hidden { display: none; }

/* ---------- Hero ---------- */

#hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  margin-bottom: 0.25rem;
}
#hero h1 {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: 0.02em;
  text-shadow: 0 0 14px rgba(77, 243, 255, 0.5);
}

.figure .head {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 0 16px rgba(184, 102, 255, 0.15);
}

.eye {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--accent) 60%, transparent 100%);
  animation: eye-idle 3s ease-in-out infinite;
}

@keyframes eye-idle {
  0%, 90%, 100% { opacity: 0.6; box-shadow: 0 0 4px var(--accent); }
  95% { opacity: 0.1; box-shadow: none; }
}

.figure.thinking .eye {
  animation: eye-thinking 0.6s ease-in-out infinite;
}
@keyframes eye-thinking {
  0%, 100% { opacity: 1; box-shadow: 0 0 16px var(--accent), 0 0 32px var(--accent); }
  50% { opacity: 0.5; box-shadow: 0 0 4px var(--accent); }
}

.figure.active .eye {
  opacity: 1;
  box-shadow: 0 0 10px var(--accent-2);
}

/* ---------- Status ---------- */

#status-banner {
  font-size: 1.05rem;
  font-weight: 500;
  min-height: 1.4rem;
  padding: 0.55rem 1.5rem;
  background: var(--panel);
  border: 1px solid rgba(77, 243, 255, 0.25);
  border-radius: 999px;
  color: var(--text-dim);
}

/* ---------- Scoreboard ---------- */

#scoreboard {
  display: flex;
  gap: 1.75rem;
  padding: 0.5rem 1.5rem;
  background: var(--panel);
  border: 1px solid rgba(232, 244, 255, 0.1);
  border-radius: 999px;
}

.score-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.score-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.score-entry span:last-child {
  font-size: 1.15rem;
  font-weight: 700;
}

#score-human { color: var(--accent); }
#score-ai { color: var(--accent-2); }

/* ---------- Board ---------- */

#board {
  --gap: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: var(--gap);
  background: var(--panel);
  padding: 16px;
  border-radius: 14px;
  width: min(92vw, 520px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.subboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 4px;
  border: 2px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.subboard.legal {
  border-color: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.subboard.won-1 { background: rgba(77, 243, 255, 0.22); }
.subboard.won-2 { background: rgba(184, 102, 255, 0.22); }

.cell {
  aspect-ratio: 1;
  background: var(--panel);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  position: relative;
}
.cell.disabled { cursor: not-allowed; opacity: 0.45; }
.cell.p1 { color: var(--accent); }
.cell.p2 { color: var(--accent-2); }

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.35); }
  to { opacity: 1; transform: scale(1); }
}
.cell.pop-in {
  animation: pop-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell.ai-last-move::after {
  content: '';
  position: absolute;
  inset: 3px;
  border: 2px solid var(--accent-2);
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(184, 102, 255, 0.6);
  pointer-events: none;
}

.cell:not(.disabled):hover {
  border: 2px solid var(--accent);
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(77, 243, 255, 0.6);
}


/* ---------- Buttons ---------- */

#button-row {
  display: flex;
  gap: 1rem;
}

.action-button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(232, 244, 255, 0.15);
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.action-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(77, 243, 255, 0.25);
}
.action-button:active { transform: translateY(0); }
.action-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#rules-button { color: var(--accent); border-color: rgba(77, 243, 255, 0.35); }
#new-game-button { color: var(--accent-2); border-color: rgba(184, 102, 255, 0.35); }


/* ---------- Rules modal ---------- */

#rules-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.75);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1.5rem;
}
#rules-modal.hidden { display: none; }
.modal-content {
  background: var(--panel);
  padding: 1.75rem;
  border-radius: 12px;
  max-width: 480px;
  border: 1px solid rgba(184, 102, 255, 0.35);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-content h2 { margin-top: 0; }
.modal-content p { color: var(--text-dim); line-height: 1.5; }
.modal-content #rules-modal-close {
  margin-top: 0.5rem;
  background: var(--accent);
  color: #04141a;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  font-weight: 600;
  cursor: pointer;
}

#rules-modal-close:hover {
  background-color: #66f7ff;
}