:root {
  color-scheme: dark;
  --bg: #11110f;
  --panel: rgba(247, 242, 231, 0.94);
  --ink: #1c2118;
  --muted: #5d6456;
  --board: #205c39;
  --board-edge: #133823;
  --grid: rgba(245, 242, 232, 0.24);
  --valid: rgba(255, 224, 130, 0.85);
  --shadow: 0 22px 58px rgba(0, 0, 0, 0.46);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 34% 20%, rgba(216, 185, 122, 0.16), transparent 26%),
    radial-gradient(circle at 88% 78%, rgba(216, 185, 122, 0.1), transparent 34%),
    linear-gradient(180deg, #1b1a16 0%, var(--bg) 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background:
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,0.014) 1px, transparent 1px);
  background-size: 52px 52px;
  opacity: 0.62;
}

body::after {
  background:
    radial-gradient(ellipse at center, transparent 38%, rgba(0, 0, 0, 0.6) 100%),
    repeating-linear-gradient(12deg, rgba(241, 217, 164, 0.014) 0 1px, transparent 1px 9px);
  mix-blend-mode: screen;
  opacity: 0.6;
}

.nav-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 30;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(225, 207, 171, 0.32);
  border-radius: 8px;
  background: rgba(15, 15, 13, 0.72);
  color: #f1d9a4;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.nav-toggle span {
  width: 18px;
  height: 2px;
  background: currentColor;
  display: block;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

.nav-panel {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(300px, 86vw);
  z-index: 35;
  padding: 72px 18px 20px;
  background: rgba(13, 13, 11, 0.96);
  border-right: 1px solid rgba(225, 207, 171, 0.2);
  transform: translateX(-104%);
  transition: transform 180ms ease;
}

.nav-panel.is-open {
  transform: translateX(0);
}

.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.46);
  z-index: 34;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.nav-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.nav-list a {
  color: #f3ead8;
  text-decoration: none;
  padding: 10px 12px;
  display: block;
  border: 1px solid rgba(225, 207, 171, 0.2);
  border-radius: 8px;
  background: rgba(30, 30, 26, 0.6);
}

.neural-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.48;
  z-index: 0;
}

.neural-bg svg {
  width: 100%;
  height: 100%;
  display: block;
}

.neural-lines path {
  fill: none;
  stroke: rgba(168, 226, 195, 0.28);
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.neural-core circle {
  fill: rgba(225, 255, 239, 0.8);
  filter: drop-shadow(0 0 22px rgba(184, 255, 219, 0.95));
}

.neural-signals circle {
  fill: rgba(222, 255, 237, 0.97);
  filter: drop-shadow(0 0 14px rgba(199, 255, 227, 1));
  opacity: 0;
}

.neural-bg.is-thinking {
  opacity: 0.72;
}

.neural-bg.is-thinking .neural-lines path {
  stroke: rgba(216, 255, 233, 0.62);
  filter: drop-shadow(0 0 10px rgba(196, 255, 224, 0.94));
  stroke-width: 2.4;
}

.neural-bg.is-thinking .neural-signals circle {
  fill: rgba(241, 255, 247, 1);
  filter: drop-shadow(0 0 22px rgba(219, 255, 238, 1));
}

.neural-bg.is-thinking .neural-core circle {
  fill: rgba(245, 255, 250, 1);
  filter: drop-shadow(0 0 28px rgba(229, 255, 245, 1));
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 14px;
}

.layout {
  width: min(100%, 1120px);
  display: grid;
  grid-template-columns: minmax(0, 760px) minmax(280px, 320px);
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 18px;
  background: var(--panel);
  border: 1px solid rgba(241, 217, 164, 0.24);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.game-panel {
  width: 100%;
}

.rules-panel {
  width: 100%;
  position: sticky;
  top: 24px;
}

.heading-row {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.game-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-label {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.mode-select {
  border: 1px solid rgba(39, 53, 30, 0.2);
  background: rgba(255, 255, 255, 0.72);
  color: #22301f;
  border-radius: 999px;
  padding: 8px 12px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.25rem);
  line-height: 0.95;
}

button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.secondary-button,
#reset-button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
}

#reset-button {
  background: #27351e;
  color: #fffdf6;
}

.secondary-button {
  background: rgba(39, 53, 30, 0.1);
  color: #27351e;
  border: 1px solid rgba(39, 53, 30, 0.16);
}

.rules-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

h2 {
  margin: 0;
  font-size: 1.8rem;
}

.rules-content {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(57, 69, 43, 0.12);
}

.rules-lead,
.rules-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.rules-list {
  margin: 16px 0;
  padding-left: 20px;
  line-height: 1.55;
}

.rules-list li + li {
  margin-top: 10px;
}

.console-panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(57, 69, 43, 0.12);
}

.console-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.activity-cluster {
  display: inline-flex;
  gap: 6px;
}

.activity-cluster span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(39, 53, 30, 0.2);
}

.activity-cluster.is-active span {
  background: rgba(232, 255, 243, 1);
  box-shadow: 0 0 12px rgba(198, 255, 226, 0.95);
  animation: clusterPulse 0.6s ease-in-out infinite;
}

.activity-cluster.is-active span:nth-child(2) { animation-delay: 0.12s; }
.activity-cluster.is-active span:nth-child(3) { animation-delay: 0.24s; }

.console-feed {
  margin: 10px 0 0;
  padding-left: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  color: #3b4437;
  line-height: 1.4;
  min-height: 92px;
  max-height: 180px;
  overflow: auto;
}

.console-feed li + li {
  margin-top: 4px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.status-card {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 18px;
}

.turn-card {
  background: #27351e;
  color: #fffdf6;
}

.turn-card .label {
  color: rgba(255, 253, 246, 0.72);
}

#turn-label {
  display: block;
  font-size: clamp(1.25rem, 2.6vw, 1.8rem);
  line-height: 1;
}

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.message {
  margin: 0 0 12px;
  min-height: 1.5em;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 6px;
  border-radius: 18px;
  background: var(--board-edge);
}

.square {
  aspect-ratio: 1;
  width: 100%;
  border: 0;
  border-radius: 10px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.06), transparent 45%),
    var(--board);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--grid);
  user-select: none;
}

.square:disabled {
  cursor: wait;
  opacity: 0.92;
}

.square.valid::after {
  content: "";
  width: 18%;
  height: 18%;
  border-radius: 999px;
  background: var(--valid);
}

.piece {
  width: 72%;
  height: 72%;
  border-radius: 50%;
  box-shadow: inset 0 2px 6px rgba(255, 255, 255, 0.28), 0 5px 10px rgba(0, 0, 0, 0.2);
}

.piece.black {
  background: radial-gradient(circle at 30% 30%, #45484b, #111314 65%);
}

.piece.white {
  background: radial-gradient(circle at 30% 30%, #ffffff, #cfd4d9 68%);
}

.piece.computer-new {
  box-shadow:
    0 0 0 6px rgba(189, 255, 221, 0.26),
    0 0 24px rgba(171, 255, 211, 0.9),
    inset 0 2px 6px rgba(255, 255, 255, 0.28);
  animation: computerDrop 1.2s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .neural-bg,
  .neural-bg * {
    animation: none !important;
  }

  .neural-bg {
    opacity: 0.1;
  }
}

@keyframes clusterPulse {
  0%, 100% { transform: scale(1); opacity: 0.74; }
  50% { transform: scale(1.35); opacity: 1; }
}

@keyframes computerDrop {
  0% { transform: scale(0.82); opacity: 0.75; }
  35% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 6px;
  }

  .panel {
    padding: 10px;
    border-radius: 18px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .heading-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 10px;
  }

  .game-actions {
    flex-wrap: wrap;
  }

  .rules-header {
    flex-direction: column;
    align-items: stretch;
  }

  .rules-panel {
    position: static;
  }

  .status-grid {
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .status-card {
    padding: 10px;
    border-radius: 14px;
  }

  .label {
    margin-bottom: 4px;
    font-size: 0.68rem;
  }

  #turn-label {
    font-size: 1.2rem;
  }

  .message {
    margin: 0 0 10px;
    font-size: 0.95rem;
  }

  .board {
    padding: 4px;
    border-radius: 14px;
  }

  .square {
    border-radius: 7px;
  }

  .piece {
    width: 76%;
    height: 76%;
  }

  #reset-button,
  .secondary-button {
    padding: 9px 14px;
  }
}
