:root {
  --paper: #fff9f2;
  --paper-2: #fffdf9;
  --ink: #302a27;
  --ink-soft: #5d524c;
  --muted: #8d827b;
  --line: rgba(48, 42, 39, 0.17);
  --purple: #7657ef;
  --purple-deep: #5a3fd6;
  --lavender: #ddd3ff;
  --butter: #ffe7a8;
  --mint: #b9e8c8;
  --blush: #f7b6c2;
  --sky: #bee3f8;
  --coral: #ff8a7a;
  --danger: #a43b4c;
  --round: "YouYuan", "幼圆", "Microsoft YaHei", sans-serif;
  --font: "Microsoft YaHei", "PingFang SC", "HarmonyOS Sans SC", sans-serif;
  --shadow: 3px 4px 0 var(--ink);
  --touch: 44px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: #ede7de;
}

body.gomoku-body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(rgba(48, 42, 39, 0.05) 1px, transparent 1px) 0 0 / 24px 24px,
    #ede7de;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
a {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

a {
  text-decoration: none;
}

button {
  cursor: pointer;
}

.gomoku-ambient {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.ambient-stone {
  position: absolute;
  display: block;
  border: 2px solid var(--ink);
  border-radius: 50%;
  opacity: 0.25;
}

.stone-a {
  width: 180px;
  height: 180px;
  top: 12%;
  left: calc(50% - 370px);
  background: var(--lavender);
  box-shadow: 12px 16px 0 rgba(48, 42, 39, 0.08);
}

.stone-b {
  width: 110px;
  height: 110px;
  top: 62%;
  right: calc(50% - 360px);
  background: var(--butter);
  box-shadow: 8px 10px 0 rgba(48, 42, 39, 0.08);
}

.ambient-grid {
  position: absolute;
  width: 260px;
  height: 260px;
  right: calc(50% - 440px);
  top: 14%;
  opacity: 0.18;
  background:
    linear-gradient(var(--ink) 1.5px, transparent 1.5px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--ink) 1.5px, transparent 1.5px) 0 0 / 32px 32px;
  transform: rotate(8deg);
}

.gomoku-topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: calc(64px + env(safe-area-inset-top, 0px));
  display: grid;
  grid-template-columns: var(--touch) 1fr auto;
  align-items: center;
  gap: 9px;
  padding: env(safe-area-inset-top, 0px) 12px 0;
  border-bottom: 1.5px solid var(--line);
  background: rgba(255, 249, 242, 0.92);
  backdrop-filter: blur(16px);
}

.gomoku-back {
  width: var(--touch);
  height: var(--touch);
  display: grid;
  place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 14px;
  background: var(--paper-2);
  box-shadow: 1px 2px 0 rgba(48, 42, 39, 0.16);
  font-size: 20px;
  font-weight: 900;
}

.gomoku-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-orbit {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: conic-gradient(var(--lavender), var(--butter), var(--mint), var(--lavender));
  font-size: 14px;
  font-weight: 900;
}

.gomoku-brand b,
.gomoku-brand small {
  display: block;
}

.gomoku-brand b {
  font-family: var(--round);
  font-size: 14px;
}

.gomoku-brand small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 7px;
  letter-spacing: 0.08em;
}

.gomoku-user {
  min-width: 88px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 800;
}

.user-avatar {
  width: 29px;
  height: 29px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--lavender);
  font-size: 15px;
}

.gomoku-main {
  position: relative;
  width: min(100%, 700px);
  min-height: calc(100dvh - 64px);
  margin: 0 auto;
  padding: 20px 12px calc(28px + env(safe-area-inset-bottom, 0px));
}

.gomoku-lobby {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 14px 12px;
  align-items: center;
}

.lobby-copy {
  min-width: 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--purple-deep);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.09em;
}

.eyebrow i {
  width: 7px;
  height: 7px;
  display: block;
  border-radius: 50%;
  background: var(--mint);
  border: 1px solid var(--ink);
}

.lobby-copy h1 {
  margin: 10px 0 8px;
  font-family: var(--round);
  font-size: clamp(42px, 13vw, 62px);
  line-height: 0.92;
  letter-spacing: -0.06em;
}

.lobby-copy h1 em {
  color: var(--purple-deep);
  font-style: normal;
}

.lobby-copy p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.75;
}

.duel-poster {
  position: relative;
  width: 128px;
  height: 188px;
  padding: 13px;
  border: 2px solid var(--ink);
  border-radius: 23px;
  background: var(--butter);
  box-shadow: var(--shadow);
  transform: rotate(2.5deg);
}

.poster-label {
  position: relative;
  z-index: 2;
  display: inline-block;
  padding: 3px 7px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 8px;
  font-weight: 900;
}

.mini-board {
  position: absolute;
  inset: 36px 10px 10px;
  border: 1.5px solid var(--ink);
  border-radius: 15px;
  background:
    linear-gradient(rgba(48, 42, 39, 0.32) 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(90deg, rgba(48, 42, 39, 0.32) 1px, transparent 1px) 0 0 / 18px 18px,
    rgba(255, 253, 249, 0.68);
}

.mini-stone {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.mini-stone.black {
  background: var(--ink);
}

.mini-stone.white {
  background: var(--paper-2);
}

.s1 { left: 36px; top: 46px; }
.s2 { left: 55px; top: 65px; }
.s3 { left: 73px; top: 84px; }
.s4 { left: 91px; top: 103px; }
.s5 { left: 109px; top: 122px; }

.poster-vs {
  position: absolute;
  z-index: 3;
  right: -12px;
  bottom: 18px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--blush);
  box-shadow: 2px 3px 0 var(--ink);
  font-family: var(--round);
  font-size: 14px;
  font-weight: 900;
}

.lobby-panel {
  grid-column: 1 / -1;
  margin-top: 5px;
  padding: 13px;
  border: 2px solid var(--ink);
  border-radius: 23px;
  background:
    radial-gradient(circle at 92% 0%, rgba(185, 232, 200, 0.55), transparent 35%),
    var(--paper-2);
  box-shadow: 3px 4px 0 rgba(48, 42, 39, 0.18), 0 14px 30px rgba(48, 42, 39, 0.09);
}

.lobby-status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 800;
}

.signal-dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 3px rgba(185, 232, 200, 0.35);
}

.lobby-room-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
}

.match-button {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 39px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--purple);
  color: #fff;
  box-shadow: 0 4px 0 var(--ink);
  text-align: left;
}

.match-button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.match-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.match-icon {
  width: 39px;
  height: 39px;
  display: grid;
  place-items: center;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background:
    conic-gradient(var(--butter), var(--blush), var(--mint), var(--sky), var(--butter));
  color: var(--ink);
  font-size: 16px;
}

.match-button b,
.match-button small {
  display: block;
}

.match-button b {
  font-family: var(--round);
  font-size: 17px;
}

.match-button small {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.74);
  font-size: 8px;
}

.match-button.compact {
  min-height: 52px;
  grid-template-columns: 1fr auto;
}

.lobby-error {
  min-height: 15px;
  margin: 7px 2px 0;
  color: var(--danger);
  font-size: 9px;
}

.rule-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.rule-strip span {
  min-width: 0;
  padding: 7px 5px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 249, 242, 0.75);
  color: var(--ink-soft);
  font-size: 8px;
  line-height: 1.35;
  text-align: center;
}

.rule-strip b {
  display: block;
  margin-bottom: 2px;
  color: var(--purple-deep);
  font-size: 9px;
}

.gomoku-state-card {
  width: min(100%, 440px);
  margin: 4vh auto 0;
  padding: 28px 20px 22px;
  border: 2px solid var(--ink);
  border-radius: 28px;
  background: var(--paper-2);
  box-shadow: 4px 6px 0 var(--ink), 0 22px 54px rgba(48, 42, 39, 0.12);
  text-align: center;
}

.waiting-orbit {
  position: relative;
  width: 106px;
  height: 106px;
  display: grid;
  place-items: center;
  margin: 0 auto 19px;
  border: 1.5px dashed rgba(48, 42, 39, 0.45);
  border-radius: 50%;
}

.waiting-orbit::before {
  content: "";
  position: absolute;
  inset: 13px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--lavender);
}

.waiting-orbit i {
  position: absolute;
  inset: -4px;
  border: 3px solid transparent;
  border-top-color: var(--purple);
  border-right-color: var(--mint);
  border-radius: 50%;
  animation: orbit 1.2s linear infinite;
}

.waiting-orbit b {
  position: relative;
  font-size: 25px;
}

.gomoku-state-card h2 {
  margin: 10px 0 8px;
  font-family: var(--round);
  font-size: 25px;
}

.gomoku-state-card > p {
  margin: 0 auto;
  max-width: 340px;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.7;
}

.waiting-room {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 18px 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  font-size: 9px;
}

.waiting-room code {
  color: var(--purple-deep);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 12px;
  font-weight: 900;
}

.waiting-room button {
  min-height: 32px;
  margin-left: auto;
  padding: 0 10px;
  border: 1px solid var(--ink);
  border-radius: 9px;
  background: var(--butter);
  font-size: 9px;
  font-weight: 800;
}

.waiting-pulse {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin: 16px 0;
}

.waiting-pulse span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--purple);
  animation: pulse 1.2s ease-in-out infinite;
}

.waiting-pulse span:nth-child(2) {
  animation-delay: 0.15s;
}

.waiting-pulse span:nth-child(3) {
  animation-delay: 0.3s;
}

.text-button {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border: 1.5px solid var(--ink);
  border-radius: 13px;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 10px;
  font-weight: 800;
}

.text-button.danger {
  color: var(--danger);
  border-color: rgba(164, 59, 76, 0.55);
}

.gomoku-game {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.players-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px minmax(0, 1fr);
  align-items: stretch;
  gap: 6px;
}

.player-card {
  position: relative;
  min-width: 0;
  min-height: 61px;
  display: grid;
  grid-template-columns: 23px 32px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-radius: 15px;
  background: var(--paper-2);
}

.player-card.is-turn {
  box-shadow: 0 0 0 3px rgba(118, 87, 239, 0.18);
}

.player-card.is-me::after {
  content: "我";
  position: absolute;
  right: 5px;
  top: 5px;
  padding: 1px 4px;
  border-radius: 999px;
  background: var(--butter);
  font-size: 7px;
  font-weight: 900;
}

.player-stone {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
}

.player-stone.black {
  background: var(--ink);
  box-shadow: inset 4px 4px 0 rgba(255, 255, 255, 0.15);
}

.player-stone.white {
  background: #fff;
  box-shadow: inset 3px 3px 0 rgba(48, 42, 39, 0.08);
}

.player-avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--lavender);
  font-size: 15px;
}

.player-copy {
  min-width: 0;
}

.player-copy small,
.player-copy b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-copy small {
  color: var(--muted);
  font-size: 7px;
}

.player-copy b {
  margin-top: 2px;
  font-size: 10px;
}

.online-mark {
  position: absolute;
  right: 5px;
  bottom: 4px;
  color: var(--muted);
  font-size: 7px;
}

.online-mark.is-online {
  color: #2f7a55;
}

.players-vs {
  align-self: center;
  color: var(--purple-deep);
  font-family: var(--round);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.game-stage {
  padding: 9px;
  border: 2px solid var(--ink);
  border-radius: 23px;
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 231, 168, 0.62), transparent 28%),
    var(--paper-2);
  box-shadow: 3px 4px 0 rgba(48, 42, 39, 0.2);
}

.turn-ribbon {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 1px 8px;
  padding: 5px 10px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--butter);
  font-size: 10px;
  font-weight: 900;
  text-align: center;
}

.turn-ribbon.is-mine {
  background: var(--mint);
}

.turn-ribbon.is-ended {
  background: var(--lavender);
}

.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-radius: 17px;
  background: #e7c98f;
}

#gomokuBoard {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.board-lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  padding-bottom: 12px;
  background: linear-gradient(transparent 70%, rgba(48, 42, 39, 0.12));
  pointer-events: none;
}

.board-lock span {
  padding: 5px 10px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: rgba(255, 253, 249, 0.9);
  font-size: 8px;
  font-weight: 800;
}

.game-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 3px 1px;
  color: var(--muted);
  font-size: 8px;
}

.game-room {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ink-soft);
}

.game-room i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
}

.copy-link-button {
  min-height: 31px;
  margin-left: auto;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  font-size: 8px;
}

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

.game-actions p {
  flex: 1;
  margin: 0 4px;
  color: var(--ink-soft);
  font-size: 9px;
  line-height: 1.5;
}

.result-panel {
  position: fixed;
  z-index: 35;
  left: 50%;
  top: 50%;
  width: min(calc(100vw - 32px), 380px);
  padding: 23px 18px 18px;
  border: 2px solid var(--ink);
  border-radius: 25px;
  background:
    radial-gradient(circle at 80% 5%, rgba(185, 232, 200, 0.65), transparent 38%),
    var(--paper);
  box-shadow: 0 8px 0 var(--ink), 0 28px 80px rgba(30, 25, 22, 0.32);
  transform: translate(-50%, -50%);
  animation: resultIn 0.25s ease-out;
  text-align: center;
}

.result-kicker {
  color: var(--purple-deep);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.result-panel h2 {
  margin: 8px 0 4px;
  font-family: var(--round);
  font-size: 30px;
}

.result-panel p {
  margin: 0 0 16px;
  color: var(--ink-soft);
  font-size: 10px;
}

.result-actions {
  display: grid;
  gap: 9px;
}

.result-actions .text-button {
  width: 100%;
}

.gomoku-toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: calc(15px + env(safe-area-inset-top, 0px));
  max-width: 82vw;
  padding: 9px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.gomoku-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.gomoku-dialog-layer {
  position: fixed;
  z-index: 55;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
}

.dialog-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(30, 25, 22, 0.58);
  backdrop-filter: blur(4px);
}

.gomoku-dialog {
  position: relative;
  width: min(100%, 340px);
  padding: 21px 18px 17px;
  border: 2px solid var(--ink);
  border-radius: 23px;
  background: var(--paper);
  box-shadow: 0 7px 0 var(--ink);
  text-align: center;
}

.gomoku-dialog h2 {
  margin: 0 0 5px;
  font-family: var(--round);
  font-size: 23px;
}

.gomoku-dialog p {
  margin: 0 0 16px;
  color: var(--ink-soft);
  font-size: 10px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.danger-button {
  min-height: var(--touch);
  border: 1.5px solid var(--ink);
  border-radius: 13px;
  background: var(--blush);
  color: var(--danger);
  font-size: 10px;
  font-weight: 900;
}

:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 2px;
}

@keyframes orbit {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-4px); }
}

@keyframes resultIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 16px)) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@media (max-width: 360px) {
  .gomoku-main {
    padding-left: 9px;
    padding-right: 9px;
  }

  .gomoku-lobby {
    grid-template-columns: minmax(0, 1fr) 105px;
    gap: 10px 8px;
  }

  .duel-poster {
    width: 105px;
    height: 168px;
    padding: 10px;
  }

  .player-card {
    grid-template-columns: 19px 27px minmax(0, 1fr);
    gap: 4px;
    padding: 6px;
  }

  .player-avatar {
    width: 27px;
    height: 27px;
  }
}

@media (min-width: 720px) {
  .gomoku-main {
    padding-top: 28px;
  }

  .gomoku-lobby {
    grid-template-columns: minmax(0, 1fr) 180px;
  }

  .duel-poster {
    width: 180px;
    height: 242px;
  }

  .mini-board {
    inset: 46px 18px 18px;
    background-size: 26px 26px;
  }

  .mini-stone {
    width: 22px;
    height: 22px;
  }

  .gomoku-game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    align-items: start;
  }

  .players-bar,
  .game-stage {
    grid-column: 1;
  }

  .game-actions,
  .result-panel {
    grid-column: 2;
  }

  .game-actions {
    position: sticky;
    top: 84px;
    align-items: stretch;
    flex-direction: column;
    padding: 15px;
    border: 2px solid var(--ink);
    border-radius: 20px;
    background: var(--paper-2);
  }

  .result-panel {
    position: sticky;
    top: 84px;
    left: auto;
    top: 200px;
    transform: none;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
