:root {
  color-scheme: light;
  --bg: #eef3f5;
  --ink: #182026;
  --muted: #5d6b75;
  --line: #7f8c96;
  --board: #f8fbfa;
  --palace-north: #dceee8;
  --palace-south: #e9e4f3;
  --north: #b4463d;
  --north-dark: #7d2722;
  --south: #1f6f78;
  --south-dark: #124b52;
  --yellow: #d49a23;
  --panel: #ffffff;
  --accent: #2e7d5b;
  --danger: #b23a48;
  --shadow: 0 18px 38px rgba(31, 47, 61, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    sans-serif;
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

.home-screen,
.setup-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.home-panel {
  width: min(100%, 760px);
}

.home-panel h1 {
  margin-bottom: 22px;
  font-size: 42px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.mode-grid.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.online-panel {
  width: min(100%, 520px);
}

.field-label {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: left;
}

.text-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #b8c2c9;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
}

.text-input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(46, 125, 91, 0.18);
}

.online-actions {
  display: grid;
  margin-top: 12px;
}

.online-status {
  min-height: 24px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}

.mode-button {
  min-height: 128px;
  border: 2px solid #26323a;
  color: #fff;
  cursor: pointer;
  font-size: 24px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.mode-button:hover {
  transform: translateY(-2px);
}

.mode-button.local-mode {
  background: linear-gradient(135deg, #b4463d, #7d2722);
}

.mode-button.ai-mode {
  background: linear-gradient(135deg, #1f6f78, #124b52);
}

.mode-button.online-mode {
  background: linear-gradient(135deg, #6b7280, #35404a);
}

.plain-button {
  margin-top: 16px;
  border: 1px solid #b8c2c9;
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: minmax(360px, 560px) minmax(280px, 360px);
  gap: 24px;
  align-items: start;
  justify-content: center;
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 24px;
}

.play-area,
.side-panel {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
  color: var(--muted);
}

.status {
  margin-top: 6px;
  color: var(--muted);
  font-size: 15px;
}

.mode-label {
  margin-top: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.status.win {
  color: var(--danger);
  font-weight: 700;
}

.status.warning {
  color: var(--danger);
  font-weight: 700;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
}

.controls button,
.source-button,
.action-button {
  border: 1px solid #b8c2c9;
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  cursor: pointer;
}

.controls button:hover,
.source-button:hover,
.action-button:hover {
  border-color: var(--accent);
}

.controls button:disabled,
.source-button:disabled,
.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: min(100%, 540px);
  aspect-ratio: 6 / 10;
  background: var(--board);
  border: 2px solid #26323a;
  box-shadow: var(--shadow);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.cell:nth-child(6n) {
  border-right: 0;
}

.cell:nth-last-child(-n + 6) {
  border-bottom: 0;
}

.cell.north-palace {
  background: var(--palace-north);
}

.cell.south-palace {
  background: var(--palace-south);
}

.cell.selected {
  box-shadow: inset 0 0 0 4px rgba(46, 125, 91, 0.46);
}

.cell.legal-target::after {
  content: "";
  position: absolute;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(46, 125, 91, 0.32);
}

.cell.blocked {
  background:
    linear-gradient(45deg, transparent 45%, rgba(178, 58, 72, 0.9) 46%, rgba(178, 58, 72, 0.9) 54%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, rgba(178, 58, 72, 0.9) 46%, rgba(178, 58, 72, 0.9) 54%, transparent 55%),
    #f4e6e9;
}

.cell::before {
  position: absolute;
  left: 4px;
  top: 3px;
  color: rgba(24, 32, 38, 0.3);
  font-size: 10px;
}

.cell[data-col="1"][data-row="0"]::before,
.cell[data-col="4"][data-row="0"]::before,
.cell[data-col="1"][data-row="2"]::before,
.cell[data-col="4"][data-row="2"]::before,
.cell[data-col="1"][data-row="7"]::before,
.cell[data-col="4"][data-row="7"]::before,
.cell[data-col="1"][data-row="9"]::before,
.cell[data-col="4"][data-row="9"]::before {
  content: "";
  inset: 0;
  width: auto;
  height: auto;
  background:
    linear-gradient(135deg, transparent calc(50% - 1px), rgba(38, 50, 58, 0.28) 50%, transparent calc(50% + 1px));
  pointer-events: none;
}

.piece {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 78%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  color: #fff;
  font-size: clamp(16px, 4vw, 28px);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    inset 0 -5px 10px rgba(0, 0, 0, 0.18),
    0 4px 10px rgba(0, 0, 0, 0.16);
}

.piece.north {
  background: radial-gradient(circle at 35% 28%, #d56a5f, var(--north) 68%, var(--north-dark));
}

.piece.south {
  background: radial-gradient(circle at 35% 28%, #3c9ba5, var(--south) 68%, var(--south-dark));
}

.piece.type-yellow {
  outline: 3px solid var(--yellow);
  outline-offset: -7px;
}

.piece.protected {
  box-shadow:
    0 0 0 4px rgba(212, 154, 35, 0.42),
    inset 0 -5px 10px rgba(0, 0, 0, 0.18),
    0 4px 10px rgba(0, 0, 0, 0.16);
}

.piece.source-member {
  box-shadow:
    0 0 0 5px rgba(46, 125, 91, 0.54),
    0 0 0 10px rgba(46, 125, 91, 0.16),
    inset 0 -5px 10px rgba(0, 0, 0, 0.18),
    0 4px 10px rgba(0, 0, 0, 0.16);
}

.piece.preview-source-piece {
  opacity: 0.42;
  filter: saturate(0.75);
}

.piece.preview-piece {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  width: 72%;
  pointer-events: none;
  opacity: 0.62;
  transform: translate(-50%, -50%) scale(0.94);
  outline: 3px solid rgba(255, 255, 255, 0.78);
  outline-offset: -5px;
  box-shadow:
    0 0 0 4px rgba(46, 125, 91, 0.34),
    inset 0 -5px 10px rgba(0, 0, 0, 0.18),
    0 6px 12px rgba(0, 0, 0, 0.14);
}

.preview-marker {
  position: absolute;
  inset: 7%;
  z-index: 0;
  pointer-events: none;
  border-radius: 4px;
}

.preview-capture-marker {
  border: 3px solid rgba(178, 58, 72, 0.78);
  background: rgba(178, 58, 72, 0.12);
}

.preview-blocked-marker {
  border: 3px solid rgba(178, 58, 72, 0.82);
  background:
    linear-gradient(45deg, transparent 44%, rgba(178, 58, 72, 0.45) 45%, rgba(178, 58, 72, 0.45) 55%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, rgba(178, 58, 72, 0.45) 45%, rgba(178, 58, 72, 0.45) 55%, transparent 56%),
    rgba(178, 58, 72, 0.1);
}

.piece.combo-member::after {
  content: "";
  position: absolute;
  right: 12%;
  bottom: 10%;
  width: 18%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff;
  opacity: 0.9;
}

.side-panel {
  display: grid;
  gap: 14px;
}

.panel-section {
  background: var(--panel);
  border: 1px solid #d6dee4;
  padding: 14px;
  box-shadow: 0 8px 22px rgba(31, 47, 61, 0.08);
}

.selected-info {
  margin-top: 10px;
  min-height: 28px;
  color: var(--ink);
  font-weight: 700;
}

.actions,
.combos {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.source-list {
  display: grid;
  gap: 8px;
}

.source-button {
  width: 100%;
  min-height: 40px;
  border-radius: 0;
  text-align: left;
  font-size: 14px;
  line-height: 1.35;
  white-space: normal;
}

.source-button.selected-source {
  border-color: var(--accent);
  background: #e6f2ed;
  color: #174935;
  font-weight: 700;
}

.action-subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
}

.action-button {
  display: grid;
  gap: 6px;
  width: 100%;
  text-align: left;
  border-radius: 0;
  line-height: 1.35;
}

.action-label {
  min-width: 0;
}

.action-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.action-tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.action-tag.info {
  background: #e6f1ff;
  color: #1f5f9f;
}

.action-tag.danger {
  background: #fde9ed;
  color: var(--danger);
}

.combo-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #e3e8ec;
  font-size: 14px;
}

.combo-line:last-child {
  border-bottom: 0;
}

.combo-kind {
  color: var(--ink);
  font-weight: 700;
}

.combo-side {
  color: var(--muted);
  white-space: nowrap;
}

.social-panel {
  display: grid;
  gap: 12px;
}

.social-notice {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.social-flash {
  display: grid;
  gap: 6px;
  min-height: 42px;
  border: 1px solid #d6dee4;
  background: #f8fbfa;
  padding: 9px;
  font-size: 13px;
}

.social-flash-name {
  color: var(--accent);
  font-weight: 700;
}

.social-flash-text {
  color: var(--ink);
  line-height: 1.35;
}

.social-flash-emoji {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.social-flash-emoji img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.social-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.social-tab {
  min-height: 34px;
  border: 1px solid #b8c2c9;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.social-tab.active {
  border-color: var(--accent);
  background: #e6f2ed;
  color: #174935;
}

.social-tab:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.social-tray {
  display: grid;
}

.social-actions {
  display: grid;
  gap: 7px;
}

.emoji-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.social-button {
  min-width: 0;
  min-height: 34px;
  border: 1px solid #b8c2c9;
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  line-height: 1.25;
}

.social-button:hover {
  border-color: var(--accent);
}

.social-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.emoji-button {
  display: grid;
  place-items: center;
  min-height: 54px;
  padding: 6px;
}

.emoji-button img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.move-log {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  margin: 10px 0 0;
  padding-left: 24px;
  color: var(--muted);
  font-size: 14px;
}

.move-log li::marker {
  color: #84939e;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .mode-grid,
  .mode-grid.two-column {
    grid-template-columns: 1fr;
  }

  .board {
    width: min(100%, 460px);
    margin: 0 auto;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 24px;
  }
}

@media (max-width: 460px) {
  .app {
    padding: 10px;
  }

  .controls {
    flex-direction: column;
  }

  .piece {
    font-size: 17px;
  }

  .home-panel h1 {
    font-size: 34px;
  }

  .mode-button {
    min-height: 92px;
    font-size: 22px;
  }
}
