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

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding: 64px 16px 48px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: #e8eaed;
  background: radial-gradient(circle at 50% -10%, #2a333f 0%, #182029 55%, #0e131a 100%) fixed;
}

h1 {
  position: absolute;
  top: 18px;
  left: 22px;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #f4f6f8;
}

#indicator {
  text-align: center;
  font-size: 22px;
  font-weight: 500;
  color: #d7dce3;
}

#info {
  text-align: center;
  margin-top: 14px;
}

#info span {
  display: inline-block;
  margin: 0 6px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 500;
  color: #c7cdd6;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 20px;
}

#controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: calc(100vw - 24px);   /* cap to the viewport so buttons wrap on phones */
  margin-top: 14px;
}

#controls button {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 20px;
  cursor: pointer;
  color: #e8eaed;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  transition: background 0.18s, border-color 0.18s, transform 0.05s;
}

#controls button:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
}

#controls button:active {
  transform: translateY(1px);
}

#resign {
  color: #ff9b9b;
  border-color: rgba(255, 107, 107, 0.35) !important;
}

#resign:hover {
  background: rgba(255, 107, 107, 0.16) !important;
  border-color: rgba(255, 107, 107, 0.55) !important;
}

#setup {
  text-align: center;
  max-width: calc(100vw - 24px);   /* keep the options within the viewport */
  margin-top: 14px;
  font-size: 13px;
  color: #aeb6c2;
}

#setup label {
  cursor: pointer;
  margin: 0 5px;
}

#setup input {
  vertical-align: middle;
  margin-right: 3px;
  cursor: pointer;
}

#message {
  text-align: center;
  margin-top: 12px;
  min-height: 22px;
  font-size: 15px;
  font-weight: 500;
  color: #9fb4d8;
}

#score {
  text-align: center;
  margin-top: 4px;
  min-height: 22px;
  font-size: 16px;
  font-weight: 600;
  color: #f4d27a;
}

/* --- rules modal ------------------------------------------------------- */

.hidden {
  display: none !important;
}

#rules-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 11, 16, 0.72);
  backdrop-filter: blur(2px);
}

#rules-modal {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 84vh;
  overflow-y: auto;
  padding: 28px 32px 32px;
  background: #1c2530;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  color: #d7dce3;
  line-height: 1.55;
}

#rules-modal h2 {
  font-size: 24px;
  font-weight: 600;
  color: #f4f6f8;
  margin-bottom: 6px;
}

#rules-modal h3 {
  font-size: 15px;
  font-weight: 600;
  color: #f4d27a;
  margin-top: 18px;
  margin-bottom: 4px;
}

#rules-modal p {
  font-size: 14px;
  margin-bottom: 4px;
}

#rules-modal ul {
  font-size: 14px;
  padding-left: 20px;
}

#rules-modal li {
  margin-bottom: 5px;
}

#rules-modal strong {
  color: #eef1f5;
}

#rules-modal em {
  color: #cdd4dd;
  font-style: italic;
}

#rules-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 32px;
  height: 32px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #c7cdd6;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  transition: background 0.18s, color 0.18s;
}

#rules-close:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

/* --- the board --------------------------------------------------------- */

#outerborder {
  position: relative;
  margin-top: 22px;
  width: fit-content;
  border: solid 12px #3a2a1c;
  border-radius: 8px;
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.55),
              inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Width/height are set in JS from the board geometry. */
#board {
  position: relative;
  border-radius: 2px;
  background: radial-gradient(circle at 30% 22%, #ecd8a6, #ddc086 65%, #d2b376 100%);
}

.lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.gridline {
  fill: none;
  stroke: #4a371f;
  stroke-width: 1;
}

.star {
  fill: #3d2c1a;
}

/* A full-cell hit area centered on each intersection. */
.point {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  transform: translate(-50%, -50%);
  cursor: pointer;
}

.point.black,
.point.white {
  cursor: default;
}

.stone {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--stone);
  height: var(--stone);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.15s;
}

.point.black .stone {
  opacity: 1;
  background: radial-gradient(circle at 35% 30%, #5e5e5e, #0a0a0a 78%);
  box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.5);
}

.point.white .stone {
  opacity: 1;
  background: radial-gradient(circle at 35% 30%, #ffffff, #cfcfcf 82%);
  box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.4);
}

/* Empty points preview a faint stone in the player-to-move's color on hover. */
#board.black-turn .point:not(.black):not(.white):hover .stone {
  opacity: 0.4;
  background: radial-gradient(circle at 35% 30%, #5e5e5e, #0a0a0a 78%);
}

#board.white-turn .point:not(.black):not(.white):hover .stone {
  opacity: 0.5;
  background: radial-gradient(circle at 35% 30%, #ffffff, #cfcfcf 82%);
}

/* --- scoring overlays -------------------------------------------------- */

/* Dead stones fade out and get a red cross. */
.point.dead .stone {
  opacity: 0.3;
}

.point.dead::after {
  content: '✕';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--stone) * 0.5);
  font-weight: 700;
  color: #d23b3b;
  pointer-events: none;
}

/* Territory is marked with a small dot in the owner's color. */
.point.terr-black::after,
.point.terr-white::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--stone) * 0.3);
  height: calc(var(--stone) * 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.point.terr-black::after {
  background: #111;
}

.point.terr-white::after {
  background: #fafafa;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

/* --- mobile / small screens -------------------------------------------- */

@media (max-width: 620px) {
  body {
    padding: 14px 10px 32px;
  }

  /* The title sits inline above the board instead of floating top-left. */
  h1 {
    position: static;
    text-align: center;
    font-size: 24px;
    margin-bottom: 4px;
  }

  #indicator {
    font-size: 19px;
  }

  /* Full width so centered text wraps within the viewport instead of
     shrink-wrapping to one (overflowing) line. */
  #info,
  #controls,
  #setup,
  #message,
  #score {
    width: 100%;
  }

  #info {
    margin-top: 10px;
  }

  #info span {
    font-size: 12px;
    padding: 4px 10px;
    margin: 0 4px;
  }

  #controls {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  #controls button {
    font-size: 13px;
    padding: 8px 14px;
    margin: 0;
  }

  #setup {
    margin-top: 10px;
    font-size: 12px;
    line-height: 1.9;
  }

  #message,
  #score {
    font-size: 13px;
    margin-top: 8px;
  }

  #outerborder {
    margin-top: 14px;
    border-width: 8px;
  }

  #rules-overlay {
    padding: 12px;
  }

  #rules-modal {
    padding: 24px 20px 26px;
  }

  #rules-modal h2 {
    font-size: 21px;
  }
}
