/* ── Reset & base ────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #0f0f1a;
  color: #e0e0e0;
  font-family: 'Segoe UI', 'Consolas', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  width: 100%;
  max-width: 500px;
}

/* ── Back link ───────────────────────────────────────── */
.back-link {
  align-self: flex-start;
  color: #00e5ff;
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}
.back-link:hover { color: #fff; }

h1 {
  font-size: 2rem;
  letter-spacing: 0.5rem;
  color: #00e5ff;
  text-shadow: 0 0 12px #00e5ff88;
}

.hidden { display: none !important; }

/* ── Mode selector ───────────────────────────────────── */
#mode-select {
  margin-top: 32px;
  text-align: center;
}
#mode-select .prompt {
  color: #888;
  margin-bottom: 20px;
  font-size: 0.95rem;
}
.mode-buttons {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
.mode-btn {
  background: #1a1a2e;
  border: 2px solid #333;
  border-radius: 12px;
  padding: 24px 20px;
  color: #e0e0e0;
  cursor: pointer;
  width: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.mode-btn:hover {
  transform: translateY(-3px);
  border-color: #00e5ff;
  box-shadow: 0 6px 24px #00e5ff22;
}
.mode-icon { font-size: 2rem; }
.mode-btn strong { font-size: 1rem; color: #fff; }
.mode-btn small { font-size: 0.72rem; color: #888; line-height: 1.4; }

/* ── Status bar ──────────────────────────────────────── */
#status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
#mode-badge {
  font-size: 0.65rem;
  padding: 2px 10px;
  border-radius: 20px;
  background: #00e5ff22;
  color: #00e5ff;
  border: 1px solid #00e5ff44;
  letter-spacing: 0.08rem;
}
#phase-badge {
  font-size: 0.65rem;
  padding: 2px 10px;
  border-radius: 20px;
  background: #f0a00022;
  color: #f0a000;
  border: 1px solid #f0a00044;
  letter-spacing: 0.08rem;
}
#turn-indicator {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

/* ── Board wrapper (for overlay positioning) ─────────── */
#board-wrapper {
  position: relative;
  width: 330px;
  height: 330px;
}

/* ── Board ───────────────────────────────────────────── */
#board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 330px;
  height: 330px;
  position: relative;
}

.cell {
  background: #1a1a2e;
  border: 2px solid #333;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 3rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
  position: relative;
}
.cell:hover:not(.taken):not(.disabled) {
  background: #252542;
  border-color: #555;
}
.cell.taken { cursor: default; }
.cell.disabled { cursor: default; opacity: 0.6; }

/* Markers */
.cell.x { color: #00e5ff; }
.cell.o { color: #f06292; }

/* Win highlight */
.cell.win-cell {
  background: #00e5ff22;
  border-color: #00e5ff;
  box-shadow: 0 0 16px #00e5ff44;
}
.cell.win-cell.o {
  background: #f0629222;
  border-color: #f06292;
  box-shadow: 0 0 16px #f0629244;
}

/* Move-mode: selectable own pieces */
.cell.selectable {
  cursor: pointer;
  border-color: #f0a000;
  animation: pulse-border 1.2s infinite;
}
@keyframes pulse-border {
  0%, 100% { border-color: #f0a000; }
  50% { border-color: #f0a00066; }
}
.cell.selected {
  background: #f0a00033;
  border-color: #f0a000;
  box-shadow: 0 0 14px #f0a00044;
  transform: scale(1.06);
}
/* Move targets */
.cell.move-target {
  cursor: pointer;
  border-color: #4caf50;
  background: #4caf5018;
}
.cell.move-target:hover {
  background: #4caf5033;
  border-color: #66bb6a;
}

/* ── Result overlay ──────────────────────────────────── */
#result-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.78);
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 8px;
  z-index: 10;
}
#result-content {
  text-align: center;
}
#result-text {
  font-size: 1.8rem;
  color: #00e5ff;
  margin-bottom: 20px;
}
.result-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.result-buttons button {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
}
#play-again-btn {
  background: #00e5ff;
  color: #111;
}
#play-again-btn:hover { background: #00bcd4; }
#change-mode-btn {
  background: transparent;
  color: #888;
  border: 1px solid #444;
}
#change-mode-btn:hover { border-color: #888; color: #ccc; }

/* ── Scoreboard ──────────────────────────────────────── */
#scoreboard {
  display: flex;
  gap: 28px;
  justify-content: center;
}
.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.score-label {
  font-size: 0.75rem;
  color: #888;
  letter-spacing: 0.1rem;
}
.score-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
}

#reset-scores-btn {
  background: transparent;
  border: 1px solid #333;
  color: #555;
  padding: 4px 14px;
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  font-family: inherit;
}
#reset-scores-btn:hover { color: #aaa; border-color: #666; }

/* ── Game area wrapper (for overlay positioning) ─────── */
#game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  position: relative;
}

/* ── Rules panel ─────────────────────────────────────── */
details.rules{background:#1a1a2e;border:1px solid #333;border-radius:8px;padding:0;margin:8px auto;max-width:420px;width:100%;font-size:.78rem;color:#aaa}
details.rules summary{cursor:pointer;padding:8px 14px;color:#888;font-size:.8rem;letter-spacing:.08rem;list-style:none;user-select:none}
details.rules summary::-webkit-details-marker{display:none}
details.rules summary::before{content:"▸ ";color:#00e5ff}
details.rules[open] summary::before{content:"▾ "}
details.rules .rules-body{padding:4px 14px 12px}
details.rules .rules-body h4{color:#00e5ff;font-size:.75rem;margin:8px 0 4px;letter-spacing:.06rem}
details.rules .rules-body ul{padding-left:16px;margin:0}
details.rules .rules-body li{margin:2px 0;line-height:1.5}
details.rules .rules-body kbd{background:#252542;border:1px solid #444;border-radius:3px;padding:1px 5px;font-size:.72rem;color:#ccc}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 400px) {
  #board { width: 280px; height: 280px; }
  .cell { font-size: 2.4rem; }
}
