:root {
  --bg: #0b0f14;
  --panel: #121b26;
  --text: #e8eef5;
  --muted: #9fb0c3;
  --line: #263546;
  --you: #59c7ff;
  --bot: #ff8570;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(circle at 12% -10%, #1a2a3d 0%, transparent 35%),
    radial-gradient(circle at 90% -10%, #271d2f 0%, transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
}

.app {
  width: min(920px, 92%);
  margin: 0 auto;
  padding: 0 0 2.5rem;
}

.page-head h1 {
  margin: 1.2rem 0 0.35rem;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

.rules-panel {
  max-width: 68ch;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: rgba(24, 36, 51, 0.4);
}

.rules-panel summary {
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 500;
  list-style-type: "▸ ";
}

.rules-panel[open] summary {
  border-bottom: 1px solid var(--line);
  list-style-type: "▾ ";
}

.rules {
  margin: 0;
  padding: 0.7rem 0.8rem;
  color: var(--muted);
}

.status-row {
  margin-top: 1.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.status-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}

#difficultyLabel {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  opacity: 0.82;
}

#turnLabel {
  margin: 0;
  font-weight: 700;
  min-height: 2.8rem;
  min-width: 23ch;
  line-height: 1.4;
  text-align: right;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.controls label {
  color: var(--muted);
  font-size: 0.92rem;
}

#difficultySelect {
  border: 1px solid var(--line);
  background: #182433;
  color: var(--text);
  padding: 0.56rem 0.72rem;
  border-radius: 0.6rem;
}

#resetBtn {
  border: 1px solid var(--line);
  background: #182433;
  color: var(--text);
  padding: 0.6rem 0.9rem;
  border-radius: 0.6rem;
  cursor: pointer;
}

#resetBtn:hover {
  border-color: #3b5773;
}

.board-wrap {
  position: relative;
  margin-top: 1rem;
}

.board {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: linear-gradient(180deg, #0f1722, #0c131d);
  display: grid;
  grid-template-columns: repeat(6, minmax(72px, 1fr));
  align-items: end;
  gap: 0.8rem;
  position: relative;
  z-index: 1;
}

.move-arrow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

.move-arrow .arrow-line {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(255, 239, 143, 0.3));
}

.move-arrow .arrow-line.player {
  stroke: #8bd2ff;
}

.move-arrow .arrow-line.ai {
  stroke: #ffb09f;
}

.cell {
  border: 1px solid #32465e;
  border-radius: 0.7rem;
  min-height: 96px;
  padding: 0.45rem;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.2rem;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.cell.empty {
  background: rgba(255, 255, 255, 0.01);
}

.cell.selectable:hover,
.cell.target:hover {
  border-color: #73a0ca;
}

.cell.selected {
  border-color: #8bd2ff;
  box-shadow: 0 0 0 1px rgba(139, 210, 255, 0.55);
}

.cell.target {
  border-color: #66bd8e;
  box-shadow: inset 0 0 0 1px rgba(102, 189, 142, 0.55);
}

.cell.last-from {
  box-shadow: inset 0 0 0 1px rgba(255, 236, 117, 0.55);
}

.cell.last-to.last-player {
  border-color: #6bd4ff;
  box-shadow:
    0 0 0 1px rgba(107, 212, 255, 0.6),
    0 0 16px rgba(107, 212, 255, 0.22);
}

.cell.last-to.last-ai {
  border-color: #ff9883;
  box-shadow:
    0 0 0 1px rgba(255, 152, 131, 0.6),
    0 0 16px rgba(255, 152, 131, 0.2);
}

.cell.disabled {
  opacity: 0.42;
}

.stone {
  height: 11px;
  border-radius: 0.25rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.stone.player {
  background: linear-gradient(160deg, #6bd4ff, #2f8ebf);
}

.stone.ai {
  background: linear-gradient(160deg, #ff9883, #cf5b49);
}

.legend {
  margin-top: 1rem;
  display: flex;
  gap: 1rem;
  color: var(--muted);
}

.new-game-modal {
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 0;
  width: min(420px, calc(100vw - 2rem));
  background: #101823;
  color: var(--text);
}

.new-game-modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.game-over-modal {
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 0;
  width: min(420px, calc(100vw - 2rem));
  background: #101823;
  color: var(--text);
}

.game-over-modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.game-over-content {
  position: relative;
  display: grid;
  gap: 0.55rem;
  padding: 1rem;
}

.game-over-content h2 {
  margin: 0;
  font-size: 1.2rem;
}

.game-over-content p {
  margin: 0;
  color: var(--muted);
}

.new-game-form {
  position: relative;
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
}

.new-game-form h2 {
  margin: 0 0 0.15rem;
  font-size: 1.2rem;
}

.new-game-form label {
  color: var(--muted);
  font-size: 0.92rem;
}

.new-game-form select {
  border: 1px solid var(--line);
  background: #182433;
  color: var(--text);
  padding: 0.56rem 0.72rem;
  border-radius: 0.6rem;
}

.modal-close-btn {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #182433;
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close-btn:hover {
  border-color: #3b5773;
}

.modal-actions {
  margin-top: 0.4rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-actions button {
  border: 1px solid var(--line);
  background: #182433;
  color: var(--text);
  padding: 0.55rem 0.85rem;
  border-radius: 0.6rem;
  cursor: pointer;
}

.modal-actions button:hover {
  border-color: #3b5773;
}

.dot {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  margin-right: 0.35rem;
}

.dot.player {
  background: var(--you);
}

.dot.ai {
  background: var(--bot);
}

@media (max-width: 700px) {
  .app {
    padding-bottom: max(4rem, env(safe-area-inset-bottom));
  }

  .board {
    grid-template-columns: repeat(6, minmax(42px, 1fr));
    gap: 0.45rem;
    padding: 0.6rem;
  }

  .move-arrow .arrow-line {
    stroke-width: 2;
  }

  .cell {
    min-height: 84px;
    padding: 0.35rem;
  }

  .stone {
    height: 9px;
  }

  .status-meta {
    align-items: flex-start;
  }

  #turnLabel {
    min-height: 2.8rem;
    width: 24ch;
    text-align: left;
  }
}
