/* ============================================================
   Gomoku (五子棋) — Stylesheet
   ============================================================ */

:root {
  /* Board */
  --board-bg: #dcb468;
  --board-bg-light: #e8ca82;
  --board-border: #b08830;
  --grid-line: #a07428;
  --cell-size: 36px;

  /* Pieces */
  --black-main: #1a1a1a;
  --black-shine: #555;
  --white-main: #f5f5f5;
  --white-shine: #fff;

  /* UI */
  --bg: #1a1a2e;
  --surface: #16213e;
  --text: #eee;
  --text-muted: #999;
  --accent: #e2b04a;
  --accent-hover: #d4a03c;
  --danger: #e74c3c;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

/* ---- Reset & Base ---- */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- Header ---- */

header {
  text-align: center;
  padding: 24px 16px 8px;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
}

header .subtitle {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 6px;
}

/* ---- Layout ---- */

main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8px 16px 32px;
  width: 100%;
}

.game-container {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  max-width: 900px;
}

.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

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

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 8px 4px;
  font-size: 1.05rem;
}

#status {
  font-weight: 600;
}

#move-counter {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Piece indicator inside status */
.status-piece {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

.status-piece.black {
  background: radial-gradient(circle at 35% 35%, var(--black-shine), var(--black-main));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.status-piece.white {
  background: radial-gradient(circle at 35% 35%, var(--white-shine), #ccc);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  border: 1px solid #bbb;
}

/* ---- Board Wrapper (coordinates) ---- */

.board-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.col-labels {
  display: grid;
  gap: 0;
  margin-left: 22px; /* align with board, past row labels */
  font-size: 0.7rem;
  color: var(--text-muted);
  user-select: none;
}

.col-labels span {
  text-align: center;
}

.board-with-rows {
  display: flex;
  align-items: stretch;
}

.row-labels {
  display: flex;
  flex-direction: column;
  gap: 0;
  justify-content: space-around;
  margin-right: 4px;
  font-size: 0.7rem;
  color: var(--text-muted);
  user-select: none;
}

.row-labels span {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 18px;
}

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

.board {
  display: grid;
  background:
    linear-gradient(135deg, var(--board-bg-light) 0%, var(--board-bg) 50%, #c9a54e 100%);
  border: 2px solid var(--board-border);
  border-radius: 4px;
  box-shadow: var(--shadow), inset 0 0 20px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  position: relative;
}

/* ---- Cells ---- */

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Grid lines — draw cross-hairs through center of each cell */
.cell::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--grid-line);
  opacity: 0.55;
}

.cell::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--grid-line);
  opacity: 0.55;
}

/* Hide lines that bleed past the board edges */
.cell.edge-top::after    { top: 50%; }
.cell.edge-bottom::after { bottom: 50%; }
.cell.edge-left::before  { left: 50%; }
.cell.edge-right::before { right: 50%; }

/* Star points (decorative dots at traditional positions) */
.cell.star-point .star-dot {
  position: absolute;
  width: 6px;
  height: 6px;
  background: var(--grid-line);
  border-radius: 50%;
  z-index: 1;
  opacity: 0.7;
}

/* Hover preview stone */
.board:not(.game-over) .cell.empty:hover .hover-stone {
  opacity: 1;
}

.hover-stone {
  position: absolute;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.12s ease;
}

.hover-stone.preview-black {
  background: radial-gradient(circle at 35% 35%, #666, #222);
  opacity: 0;
}

.hover-stone.preview-white {
  background: radial-gradient(circle at 35% 35%, #fff, #ddd);
  opacity: 0;
}

.board:not(.game-over) .cell.empty:hover .hover-stone.preview-black {
  opacity: 0.35;
}

.board:not(.game-over) .cell.empty:hover .hover-stone.preview-white {
  opacity: 0.35;
}

/* ---- Pieces ---- */

.piece {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  z-index: 3;
  position: relative;
  transition: transform 0.1s ease;
  animation: place 0.15s ease-out;
}

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

.piece.black {
  background: radial-gradient(circle at 35% 35%, var(--black-shine), var(--black-main));
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.5),
    inset 0 1px 2px rgba(255, 255, 255, 0.08);
}

.piece.white {
  background: radial-gradient(circle at 35% 35%, var(--white-shine), #ccc);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.25),
    inset 0 1px 2px rgba(255, 255, 255, 0.5);
  border: 1px solid #c0c0c0;
}

/* Last-move indicator */
.piece.last-move::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.piece.black.last-move::after {
  background: var(--accent);
  box-shadow: 0 0 4px var(--accent);
}

.piece.white.last-move::after {
  background: var(--danger);
  box-shadow: 0 0 4px var(--danger);
}

/* Winning highlight */
.piece.winning {
  animation: winPulse 0.8s ease-in-out infinite alternate;
}

.piece.black.winning {
  box-shadow:
    0 0 8px 3px rgba(226, 176, 74, 0.7),
    0 2px 4px rgba(0, 0, 0, 0.5);
}

.piece.white.winning {
  box-shadow:
    0 0 8px 3px rgba(226, 176, 74, 0.7),
    0 2px 4px rgba(0, 0, 0, 0.25);
}

@keyframes winPulse {
  0%   { box-shadow: 0 0 6px 2px rgba(226, 176, 74, 0.5); }
  100% { box-shadow: 0 0 14px 5px rgba(226, 176, 74, 0.9); }
}

/* ---- Controls ---- */

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  padding: 8px 18px;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: background 0.15s, transform 0.1s;
  user-select: none;
}

.btn:hover {
  background: #1e2d50;
  transform: translateY(-1px);
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

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

.btn.active-mode {
  background: #2a3f72;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(226, 176, 74, 0.45), 0 1px 6px rgba(0, 0, 0, 0.25);
}

.board.ai-thinking .cell,
.cell.disabled {
  cursor: not-allowed;
}

/* ---- History Panel ---- */

.history-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 170px;
  max-height: 560px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.history-panel h2 {
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: var(--accent);
  font-weight: 600;
}

.history-panel ol {
  list-style: none;
  counter-reset: hist;
  padding: 0;
  font-size: 0.82rem;
}

.history-panel li {
  counter-increment: hist;
  padding: 3px 0;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-panel li::before {
  content: counter(hist) ".";
  color: var(--text-muted);
  min-width: 24px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.history-panel li .hist-piece {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.history-panel li .hist-piece.black {
  background: #333;
  box-shadow: 0 0 2px rgba(0,0,0,0.5);
}

.history-panel li .hist-piece.white {
  background: #eee;
  border: 1px solid #bbb;
}

.history-panel li.latest {
  color: var(--text);
  font-weight: 600;
}

/* Custom scrollbar for history */
.history-panel::-webkit-scrollbar {
  width: 5px;
}
.history-panel::-webkit-scrollbar-track {
  background: transparent;
}
.history-panel::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
}

/* ---- Win Banner ---- */

.win-banner {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 8px 0 2px;
  color: var(--accent);
  animation: bannerIn 0.3s ease-out;
}

@keyframes bannerIn {
  0%   { opacity: 0; transform: translateY(-8px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ---- Responsive ---- */

@media (max-width: 720px) {
  .game-container {
    flex-direction: column;
    align-items: center;
  }

  .history-panel {
    max-height: 180px;
    min-width: unset;
    width: 100%;
    max-width: 400px;
  }

  :root {
    --cell-size: min(6.2vw, 32px);
  }

  header h1 {
    font-size: 1.5rem;
  }
}

@media (max-width: 400px) {
  :root {
    --cell-size: min(5.8vw, 28px);
  }

  .controls {
    gap: 6px;
  }

  .btn {
    padding: 6px 12px;
    font-size: 0.8rem;
  }
}
