:root {
  color-scheme: light;
  --bg: #eef2e6;
  --ink: #262521;
  --muted: #69685f;
  --line: #2d2a23;
  --wood: #b57642;
  --wood-dark: #6d3d24;
  --red: #b84536;
  --gold: #e0b35d;
  --green: #526f58;
  --blue: #49677d;
  --tile: min(18vw, 104px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background:
    linear-gradient(135deg, rgba(82, 111, 88, .18), transparent 36%),
    linear-gradient(315deg, rgba(184, 69, 54, .16), transparent 42%),
    var(--bg);
}

button {
  border: 1px solid rgba(38, 37, 33, .18);
  border-radius: 6px;
  padding: 12px 16px;
  color: #fff;
  background: var(--green);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.game-shell {
  min-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: clamp(32px, 7vw, 72px);
  line-height: .95;
  letter-spacing: 0;
}

.topbar p,
.hint p,
.move-log {
  color: var(--muted);
}

.stats {
  display: flex;
  gap: 10px;
}

.stats div {
  min-width: 92px;
  padding: 12px;
  border: 1px solid rgba(38, 37, 33, .16);
  border-radius: 8px;
  background: rgba(255, 255, 255, .48);
  text-align: center;
}

.stats span {
  display: block;
  font-size: 26px;
  font-weight: 800;
}

.stats small {
  color: var(--muted);
}

.play-area {
  display: grid;
  grid-template-columns: max-content minmax(230px, 320px);
  gap: 24px;
  align-items: start;
}

.board-wrap {
  position: relative;
  padding: 14px 14px 36px;
  border: 8px solid var(--wood-dark);
  border-bottom-width: 0;
  background: var(--wood);
  box-shadow: 0 18px 40px rgba(38, 37, 33, .22);
}

.board {
  position: relative;
  width: calc(var(--tile) * 4);
  height: calc(var(--tile) * 5);
  outline: 0;
  background:
    linear-gradient(rgba(255, 255, 255, .12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .12) 1px, transparent 1px),
    #3a2b23;
  background-size: var(--tile) var(--tile);
  overflow: hidden;
  touch-action: none;
}

.exit-label {
  position: absolute;
  left: calc(50% - var(--tile));
  bottom: 0;
  width: calc(var(--tile) * 2);
  height: 30px;
  display: grid;
  place-items: center;
  color: #fff7e5;
  background: #3a2b23;
  font-weight: 800;
}

.piece {
  position: absolute;
  display: grid;
  place-items: center;
  width: calc(var(--tile) * var(--w));
  height: calc(var(--tile) * var(--h));
  transform: translate(calc(var(--tile) * var(--x)), calc(var(--tile) * var(--y)));
  border: 2px solid rgba(43, 28, 19, .65);
  border-radius: 7px;
  color: #fff9ec;
  font-weight: 900;
  font-size: clamp(18px, 4vw, 30px);
  text-shadow: 0 1px 1px rgba(0, 0, 0, .4);
  background: linear-gradient(145deg, color-mix(in srgb, var(--piece-color), white 18%), var(--piece-color));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .2), 0 4px 10px rgba(0, 0, 0, .25);
  transition: transform .16s ease, box-shadow .16s ease;
  user-select: none;
}

.piece.selected {
  box-shadow: inset 0 0 0 4px var(--gold), 0 8px 18px rgba(0, 0, 0, .32);
  z-index: 2;
}

.piece.cao {
  --piece-color: var(--red);
  font-size: clamp(26px, 6vw, 42px);
}

.piece.vertical {
  --piece-color: var(--green);
}

.piece.horizontal {
  --piece-color: var(--blue);
}

.piece.soldier {
  --piece-color: #8a6046;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.hint {
  padding: 16px 0;
  border-top: 1px solid rgba(38, 37, 33, .16);
  border-bottom: 1px solid rgba(38, 37, 33, .16);
}

.hint h2 {
  margin-bottom: 8px;
  font-size: 20px;
}

.move-log {
  min-height: 144px;
  margin: 0;
  padding-left: 22px;
  line-height: 1.8;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(20, 18, 15, .55);
}

.win-box {
  width: min(360px, calc(100vw - 36px));
  padding: 26px;
  border-radius: 8px;
  text-align: center;
  background: #fff9ec;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .28);
}

.win-box h2 {
  margin-bottom: 10px;
  font-size: 34px;
}

.win-box p {
  margin-bottom: 18px;
  color: var(--muted);
}

@media (max-width: 760px) {
  :root {
    --tile: min(20vw, 78px);
  }

  .app {
    padding: 16px;
  }

  .game-shell {
    justify-content: start;
  }

  .topbar,
  .play-area {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar {
    align-items: start;
  }

  .stats {
    width: 100%;
  }

  .stats div {
    flex: 1;
  }

  .board-wrap {
    justify-self: center;
    padding: 10px 10px 30px;
    border-width: 6px;
    border-bottom-width: 0;
  }
}
