:root {
  --bg: #f5f7f2;
  --ink: #18201b;
  --muted: #667064;
  --line: #dfe5d9;
  --paper: #ffffff;
  --green: #2f8f5b;
  --yellow: #efb840;
  --red: #d95043;
  --blue: #3574b8;
  --wood: #c78b48;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 10%, rgba(239, 184, 64, 0.2), transparent 25rem),
    linear-gradient(135deg, #f5f7f2 0%, #eef4f8 100%);
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    sans-serif;
}

button {
  font: inherit;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.8rem);
  line-height: 1;
}

h2 {
  font-size: 1.7rem;
}

.subtitle {
  max-width: 32rem;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.ghost-button,
.toolbar button,
.pad button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.ghost-button {
  padding: 0 18px;
  white-space: nowrap;
}

.ghost-button:hover,
.toolbar button:hover,
.pad button:hover,
.game-card:hover {
  border-color: rgba(47, 143, 91, 0.55);
  box-shadow: 0 14px 28px rgba(40, 52, 44, 0.1);
  transform: translateY(-2px);
}

main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto 48px;
}

.lobby {
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.lobby.active {
  display: grid;
}

.game-card {
  display: flex;
  min-height: 210px;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 22px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.game-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.35rem;
}

.game-card small {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.game-mark {
  position: relative;
  display: block;
  width: 76px;
  height: 76px;
  border-radius: 8px;
  background: #edf3ed;
}

.snake-mark::before {
  content: "";
  position: absolute;
  inset: 16px 10px 18px 14px;
  border: 12px solid var(--green);
  border-left-color: transparent;
  border-bottom-color: transparent;
  border-radius: 24px;
}

.snake-mark::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--red);
}

.mole-mark::before {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  height: 20px;
  border-radius: 50%;
  background: #8a5a32;
}

.mole-mark::after {
  content: "";
  position: absolute;
  left: 23px;
  top: 15px;
  width: 30px;
  height: 42px;
  border-radius: 18px 18px 12px 12px;
  background: var(--wood);
}

.gomoku-mark {
  background:
    radial-gradient(circle at 26px 26px, #161616 0 9px, transparent 10px),
    radial-gradient(circle at 50px 50px, #ffffff 0 9px, transparent 10px),
    linear-gradient(90deg, transparent 23px, #b88b50 24px 25px, transparent 26px),
    linear-gradient(0deg, transparent 23px, #b88b50 24px 25px, transparent 26px),
    #e8c887;
}

.xiangqi-mark::before,
.xiangqi-mark::after {
  position: absolute;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff8eb;
  box-shadow: inset 0 0 0 2px currentColor;
  font-weight: 800;
}

.xiangqi-mark::before {
  content: "帅";
  left: 8px;
  top: 10px;
  color: var(--red);
}

.xiangqi-mark::after {
  content: "将";
  right: 8px;
  bottom: 10px;
  color: #222;
}

.game-panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  padding: 20px;
}

.game-panel.active {
  display: block;
}

.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.stats span {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf6;
  padding: 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats b {
  margin-left: 6px;
  color: var(--ink);
}

canvas {
  display: block;
  width: min(100%, 540px);
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
  background: #f7fbf5;
  box-shadow: inset 0 0 0 1px var(--line);
}

#snakeCanvas {
  width: min(100%, 420px);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.toolbar button {
  min-width: 92px;
  padding: 0 14px;
}

.mode-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: -4px 0 16px;
}

.mode-bar button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 13px;
  color: var(--muted);
  cursor: pointer;
}

.mode-bar button.active {
  border-color: rgba(47, 143, 91, 0.75);
  background: #eaf6ee;
  color: var(--green);
  font-weight: 800;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.pad button {
  width: 48px;
  height: 44px;
  padding: 0;
}

.pad button[data-dir="up"] {
  grid-column: 2;
}

.pad button[data-dir="left"] {
  grid-column: 1;
}

.pad button[data-dir="down"] {
  grid-column: 2;
}

.pad button[data-dir="right"] {
  grid-column: 3;
}

.mole-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 132px));
  justify-content: center;
  gap: 14px;
  margin: 8px auto 0;
}

.hole {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  background: #e5dfd0;
  cursor: pointer;
  overflow: hidden;
}

.hole::before {
  content: "";
  position: absolute;
  left: 15%;
  right: 15%;
  bottom: 15%;
  height: 20%;
  border-radius: 50%;
  background: #7b5132;
}

.hole::after {
  content: "";
  position: absolute;
  left: 29%;
  top: 52%;
  width: 42%;
  height: 42%;
  border-radius: 50% 50% 40% 40%;
  background: var(--wood);
  transform: translateY(80%);
  transition: transform 0.12s ease;
}

.hole.up::after {
  transform: translateY(-32%);
}

.xiangqi-board {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 8 / 9;
  margin: 0 auto;
  border: 3px solid #8a5a32;
  border-radius: 8px;
  background: #f1c57d;
  box-shadow: inset 0 0 0 5px rgba(255, 246, 223, 0.3);
}

.xiangqi-lines {
  position: absolute;
  inset: 6.5%;
  width: 87%;
  height: 87%;
  overflow: visible;
  pointer-events: none;
}

.river-label {
  position: absolute;
  top: 50%;
  color: rgba(103, 61, 24, 0.62);
  font-size: clamp(1.1rem, 4vw, 2.05rem);
  font-weight: 800;
  letter-spacing: 0.28em;
  transform: translateY(-50%);
  pointer-events: none;
}

.river-label.left {
  left: 18%;
}

.river-label.right {
  right: 15%;
}

.cell {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  cursor: pointer;
  position: absolute;
  width: 10.5%;
  aspect-ratio: 1;
  padding: 0;
  transform: translate(-50%, -50%);
}

.piece {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: #fff6df;
  font-size: clamp(0.92rem, 4vw, 1.35rem);
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(99, 62, 27, 0.22);
}

.piece.red {
  color: #c7362e;
}

.piece.black {
  color: #1c1c1c;
}

.cell.selected .piece {
  outline: 4px solid rgba(47, 143, 91, 0.35);
}

.cell.target::before {
  content: "";
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(47, 143, 91, 0.5);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 5;
  max-width: min(420px, calc(100% - 32px));
  border-radius: 8px;
  background: #172019;
  color: #fff;
  padding: 12px 16px;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

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

@media (max-width: 900px) {
  .lobby {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .site-header,
  .panel-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .lobby {
    grid-template-columns: 1fr;
  }

  .game-card {
    min-height: 158px;
  }

  .game-panel {
    padding: 14px;
  }
}
