.gomoku-page {
  min-height: 100vh;
}

.game-shell,
.game-main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.game-shell {
  padding: 24px 0 18px;
}

.game-nav,
.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.back-link {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-weight: 800;
  padding: 10px 16px;
}

.back-link:hover {
  color: var(--text);
  border-color: rgba(34, 211, 238, 0.45);
}

.game-panel,
.board-card,
.rules-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}

.game-panel {
  position: absolute;
  z-index: 2;
  top: clamp(18px, 2.4vw, 30px);
  right: clamp(18px, 3vw, 30px);
  width: min(600px, calc(100% - 36px));
  border-radius: 24px;
  padding: 16px;
}

.panel-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.turn-indicator {
  margin-bottom: 12px;
  font-size: clamp(1.05rem, 1.8vw, 1.15rem);
  font-weight: 900;
  line-height: 1.18;
}

.primary-controls,
.online-actions-row,
.mode-switch,
.room-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
}

.primary-controls {
  align-items: stretch;
}

.online-actions-row {
  align-items: flex-end;
}

.mode-switch {
  flex: 1 1 250px;
}

.mode-button {
  flex: 1 1 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 900;
}

.game-panel .button {
  min-height: 40px;
  padding: 0 16px;
  font-size: 0.92rem;
  white-space: nowrap;
}

.primary-controls .button {
  flex: 0 0 auto;
}

.mode-button.active {
  background: var(--text);
  color: #101322;
}

.online-controls {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.online-controls[hidden] {
  display: none;
}

.room-actions {
  flex: 0 0 240px;
}

.room-actions .button {
  flex: 1 1 0;
}

.room-join-form {
  flex: 1 1 0;
  min-width: 0;
}

.room-join-form label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.room-join-form .form-row {
  flex-wrap: nowrap;
  gap: 8px;
}

.room-join-form input {
  flex: 1 1 140px;
  min-width: 0;
  min-height: 40px;
  padding: 0 14px;
  font-size: 0.92rem;
  text-transform: uppercase;
}

.room-note {
  margin: 0;
  color: var(--accent);
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.35;
}

.game-main {
  padding-bottom: 54px;
}

.board-card,
.rules-card {
  border-radius: 32px;
  padding: clamp(18px, 3vw, 30px);
}

.game-stage {
  position: relative;
  isolation: isolate;
  margin-top: 18px;
}

.board-header {
  align-items: flex-start;
  min-height: clamp(184px, 21vw, 232px);
  margin-bottom: 0;
}

.board-header h1 {
  max-width: 520px;
  margin-bottom: 0;
  font-size: clamp(2.4rem, 6vw, 4.4rem);
  letter-spacing: -0.06em;
}

.rules-card h2 {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

.game-status {
  width: fit-content;
  max-width: 100%;
  margin-bottom: 18px;
  border: 1px solid rgba(34, 211, 238, 0.28);
  border-radius: 18px;
  background: rgba(34, 211, 238, 0.08);
  color: var(--text);
  font-weight: 800;
  padding: 12px 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.board-wrap {
  overflow-x: auto;
  position: relative;
  z-index: 1;
  display: grid;
  justify-content: center;
  padding: 8px 0 4px;
}

.celebration-effects {
  position: fixed;
  inset: 0;
  z-index: 20;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  pointer-events: none;
}

.celebration-burst,
.celebration-spark {
  position: absolute;
  left: var(--x);
  top: var(--y);
}

.celebration-burst {
  width: 1px;
  height: 1px;
}

.celebration-burst::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid hsl(var(--hue), 100%, 66%);
  border-radius: 999px;
  box-shadow: 0 0 22px hsl(var(--hue), 100%, 62%);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.2);
  animation: firework-ring 900ms ease-out var(--delay) forwards;
}

.celebration-spark {
  width: var(--size);
  height: var(--size);
  border-radius: 999px;
  background: hsl(var(--hue), 100%, 72%);
  box-shadow:
    0 0 12px 2px hsl(var(--hue), 100%, 62%),
    0 0 28px hsl(var(--hue), 100%, 56%);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.4);
  animation: firework-pop 1100ms ease-out var(--delay) forwards;
}

@keyframes firework-ring {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2);
  }

  18% {
    opacity: 0.9;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(8);
  }
}

@keyframes firework-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.45);
  }

  14% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform:
      translate(calc(-50% + var(--dx)), calc(-50% + var(--dy)))
      scale(0.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .celebration-spark {
    animation: none;
  }
}

.gomoku-board {
  --cell-size: clamp(22px, 4.8vw, 38px);
  --grid-line: rgba(255, 255, 255, 0.26);
  position: relative;
  display: grid;
  grid-template-columns: repeat(15, var(--cell-size));
  grid-template-rows: repeat(15, var(--cell-size));
  width: max-content;
  border: 2px solid rgba(255, 255, 255, 0.34);
  border-radius: 24px;
  background:
    linear-gradient(rgba(21, 28, 48, 0.84), rgba(21, 28, 48, 0.84)),
    #141c30;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 24px 60px rgba(0, 0, 0, 0.24);
  isolation: isolate;
  overflow: hidden;
}

.cell {
  --horizontal-line-size: 100% 1px;
  --horizontal-line-position: center;
  --vertical-line-size: 1px 100%;
  --vertical-line-position: center;
  position: relative;
  display: grid;
  z-index: 1;
  width: var(--cell-size);
  height: var(--cell-size);
  place-items: center;
  border: 0;
  background:
    linear-gradient(var(--grid-line), var(--grid-line)) var(--horizontal-line-position) /
      var(--horizontal-line-size) no-repeat,
    linear-gradient(90deg, var(--grid-line), var(--grid-line)) var(--vertical-line-position) /
      var(--vertical-line-size) no-repeat;
  cursor: pointer;
  padding: 0;
}

.cell:nth-child(15n + 1) {
  --horizontal-line-size: 50% 1px;
  --horizontal-line-position: right center;
}

.cell:nth-child(15n) {
  --horizontal-line-size: 50% 1px;
  --horizontal-line-position: left center;
}

.cell:nth-child(-n + 15) {
  --vertical-line-size: 1px 50%;
  --vertical-line-position: center bottom;
}

.cell:nth-child(n + 211) {
  --vertical-line-size: 1px 50%;
  --vertical-line-position: center top;
}

.cell:focus-visible {
  z-index: 1;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.cell::before {
  content: "";
  width: 72%;
  height: 72%;
  border-radius: 50%;
  transform: scale(0);
  transition:
    box-shadow 140ms ease,
    transform 140ms ease;
}

.cell.black::before,
.cell.white::before {
  transform: scale(1);
}

.cell.black::before {
  background: radial-gradient(circle at 35% 30%, #5a6478, #05070c 62%);
  box-shadow: 0 7px 16px rgba(0, 0, 0, 0.45);
}

.cell.white::before {
  background: radial-gradient(circle at 34% 28%, #ffffff, #d8e1ef 70%);
  box-shadow: 0 7px 16px rgba(255, 255, 255, 0.16);
}

.cell.last-move::after {
  content: "";
  position: absolute;
  width: 20%;
  height: 20%;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.9);
}

.cell.winning::before {
  box-shadow:
    0 0 0 3px rgba(34, 211, 238, 0.78),
    0 0 24px rgba(34, 211, 238, 0.7);
}

.rules-card ul {
  margin: 0 0 18px;
  padding-left: 20px;
  color: var(--muted);
}

.rules-card li {
  margin-bottom: 10px;
}

.game-info {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.72fr);
  gap: 22px;
  margin-top: 22px;
}

.link-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

@media (max-width: 1020px) {
  .game-info {
    grid-template-columns: 1fr;
  }

  .board-header {
    flex-direction: column;
    align-items: flex-start;
    min-height: 0;
    margin-bottom: 18px;
  }

  .game-panel {
    position: static;
    width: 100%;
  }

  .primary-controls,
  .online-actions-row {
    display: block;
  }

  .mode-switch,
  .room-actions,
  .room-join-form .form-row {
    flex-wrap: wrap;
  }

  .mode-switch,
  .room-actions {
    margin-bottom: 12px;
  }

  .room-actions {
    flex-basis: auto;
  }
}

@media (max-width: 640px) {
  .game-shell,
  .game-main {
    width: min(100% - 20px, 1180px);
  }

  .game-nav,
  .board-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
