:root {
  color-scheme: light;
  --ink: #0f1b2b;
  --muted: #52637a;
  --line: #d8e1ea;
  --panel: #ffffff;
  --soft: #f2f7f7;
  --teal: #137f74;
  --teal-soft: #dff2ee;
  --wood: #d9ad72;
  --wood-dark: #9b672f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 10%, rgba(248, 229, 171, 0.35), transparent 28%),
    linear-gradient(135deg, #fffaf0 0%, #eef7f5 45%, #f8fbff 100%);
}

button,
a {
  font: inherit;
}

.gomoku-shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.hero,
.toolbar,
.game-layout,
.message {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 16px 42px rgba(44, 61, 78, 0.08);
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-radius: 8px;
}

.back-link {
  color: var(--teal);
  font-weight: 800;
  text-decoration: none;
}

h1 {
  margin: 8px 0 4px;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
}

.turn-card {
  min-width: 150px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.turn-card span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.turn-card strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 8px;
}

.difficulty {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6fafc;
}

.segmented button,
.restart {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.segmented button {
  padding: 10px 14px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: #fff;
  background: var(--teal);
}

.restart {
  padding: 12px 18px;
  color: var(--ink);
  background: #e7eef3;
}

.game-layout {
  display: grid;
  grid-template-columns: 180px minmax(360px, 1fr) 180px;
  gap: 16px;
  align-items: start;
  margin-top: 12px;
  padding: 16px;
  border-radius: 8px;
}

.player-card {
  display: grid;
  gap: 10px;
  justify-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  text-align: center;
}

.player-card span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.player-card strong {
  display: block;
  margin-top: 4px;
}

.piece-preview {
  width: 86px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: visible;
}

.piece-preview img,
.piece img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

.board-panel {
  display: grid;
  place-items: center;
  min-width: 0;
}

.board {
  --board-pad: clamp(18px, 3.2vw, 34px);
  --point-size: clamp(28px, 4.4vw, 52px);
  position: relative;
  width: min(100%, 720px, 76vh);
  aspect-ratio: 1;
  padding: var(--board-pad);
  border: 3px solid var(--wood-dark);
  border-radius: 8px;
  background: #e4ba7c;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25), 0 18px 36px rgba(92, 58, 24, 0.18);
}

.board-lines {
  position: absolute;
  inset: var(--board-pad);
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(104, 65, 29, 0.62) 0 1px, transparent 1px calc(100% / 14)),
    repeating-linear-gradient(0deg, rgba(104, 65, 29, 0.62) 0 1px, transparent 1px calc(100% / 14));
  box-shadow:
    inset -1px 0 0 rgba(104, 65, 29, 0.62),
    inset 0 -1px 0 rgba(104, 65, 29, 0.62);
}

.board-points {
  position: absolute;
  inset: var(--board-pad);
}

.cell {
  position: absolute;
  width: var(--point-size);
  height: var(--point-size);
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.cell:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
}

.cell:disabled {
  cursor: default;
}

.piece {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.26);
  pointer-events: none;
  z-index: 2;
}

.cell.last::after,
.cell.win::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
}

.cell.last::after {
  background: rgba(19, 127, 116, 0.75);
}

.cell.win::after {
  inset: 22%;
  border: 3px solid #ffdf70;
  box-shadow: 0 0 12px rgba(255, 211, 74, 0.9);
}

.message {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 8px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .gomoku-shell {
    width: min(100vw - 12px, 620px);
    padding-top: 8px;
  }

  .hero,
  .toolbar,
  .game-layout,
  .message {
    border-radius: 8px;
  }

  .hero {
    padding: 14px;
  }

  h1 {
    font-size: 34px;
  }

  .turn-card {
    min-width: 116px;
    padding: 10px 12px;
  }

  .turn-card strong {
    font-size: 18px;
  }

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

  .difficulty {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .segmented {
    grid-template-columns: repeat(3, 1fr);
  }

  .game-layout {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .board-panel {
    grid-column: 1 / -1;
    order: 2;
  }

  .player-card {
    grid-template-columns: auto 1fr;
    justify-items: start;
    align-items: center;
    text-align: left;
    padding: 10px;
  }

  .piece-preview {
    width: 52px;
  }

  .board {
    --board-pad: 16px;
    --point-size: clamp(20px, 6vw, 34px);
    width: min(calc(100vw - 34px), 560px, 72vh);
  }
}

@media (max-width: 420px) {
  .hero {
    gap: 10px;
  }

  h1 {
    font-size: 30px;
  }

  .hero p {
    display: none;
  }

  .segmented button,
  .restart {
    padding: 10px 8px;
  }

  .board {
    --board-pad: 14px;
    --point-size: clamp(19px, 5.6vw, 30px);
  }
}
