:root {
  color-scheme: light;
  --ink: #211b16;
  --muted: #70665c;
  --paper: #f4efe5;
  --linen: #e7dbc9;
  --line: #2b2218;
  --red: #bb2d2d;
  --red-deep: #721d23;
  --blue: #1f6e88;
  --blue-deep: #123e56;
  --gold: #c9932d;
  --green: #54785b;
  --shadow: 0 22px 70px rgba(45, 30, 14, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Songti SC", "STSong", serif;
  background:
    linear-gradient(90deg, rgba(33, 27, 22, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(33, 27, 22, 0.045) 1px, transparent 1px),
    radial-gradient(circle at 12% 12%, rgba(201, 147, 45, 0.26), transparent 28%),
    radial-gradient(circle at 84% 18%, rgba(31, 110, 136, 0.18), transparent 30%),
    var(--paper);
  background-size: 24px 24px, 24px 24px, auto, auto, auto;
}

button {
  font: inherit;
}

input {
  font: inherit;
}

.game-shell {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 720px) minmax(260px, 340px);
  gap: 28px;
  align-items: center;
  padding: 32px 0;
}

.table,
.side-panel {
  border: 2px solid rgba(43, 34, 24, 0.88);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0)),
    var(--linen);
  box-shadow: var(--shadow);
}

.table {
  padding: clamp(18px, 3vw, 34px);
  position: relative;
}

.table::before,
.side-panel::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(43, 34, 24, 0.34);
  pointer-events: none;
}

.table,
.side-panel,
.modal-panel {
  border-radius: 8px;
}

.topbar,
.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(2.2rem, 6vw, 4.6rem);
  line-height: 0.95;
}

.icon-button {
  width: 48px;
  height: 48px;
  border: 2px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: #f9f1dd;
  font-size: 1.65rem;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: #fff7e6;
  transform: rotate(-18deg) scale(1.04);
}

.status-strip {
  margin: 22px 0 18px;
  padding: 10px 12px;
  border-top: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
}

.turn-chip,
.score {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  font-weight: 800;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: inline-block;
}

.dot.red {
  background: var(--red);
}

.dot.blue {
  background: var(--blue);
}

.dot.neutral {
  background: var(--gold);
}

.controls {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  gap: 12px;
  align-items: center;
  margin: 0 0 18px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f9f1dd;
}

.mode-btn {
  min-height: 40px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}

.mode-btn + .mode-btn {
  border-left: 2px solid var(--line);
}

.mode-btn.active {
  color: #fff8e7;
  background: var(--ink);
}

.name-field {
  min-height: 44px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 248, 220, 0.46);
  font-weight: 900;
}

.name-field span {
  color: var(--muted);
  font-size: 0.86rem;
}

.name-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 900;
}

.board-wrap {
  width: min(100%, 650px);
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(8px, 1.6vw, 14px);
  aspect-ratio: 5 / 4;
  padding: clamp(10px, 2vw, 18px);
  border: 3px solid var(--line);
  background:
    linear-gradient(45deg, rgba(43, 34, 24, 0.13) 25%, transparent 25% 75%, rgba(43, 34, 24, 0.13) 75%),
    #b8884b;
  background-size: 26px 26px;
}

.cell {
  position: relative;
  border: 2px solid rgba(43, 34, 24, 0.74);
  border-radius: 8px;
  background: rgba(255, 248, 220, 0.35);
  min-width: 0;
}

.piece {
  position: absolute;
  inset: 6%;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  user-select: none;
  font-size: clamp(1.55rem, 4.8vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 0;
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}

.piece.face-down {
  color: rgba(33, 27, 22, 0.82);
  background:
    radial-gradient(circle, rgba(255, 246, 214, 0.42) 0 20%, transparent 21%),
    repeating-conic-gradient(from 12deg, #8c382b 0 16deg, #6b2822 16deg 32deg);
  box-shadow: inset 0 0 0 8px rgba(246, 214, 143, 0.33), 0 10px 0 rgba(43, 34, 24, 0.2);
}

.piece.face-down::before {
  content: "暗";
}

.piece.red {
  color: #fff4e0;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.28), transparent 28%),
    var(--red);
  box-shadow: inset 0 -10px 18px rgba(114, 29, 35, 0.42), 0 9px 0 rgba(114, 29, 35, 0.34);
}

.piece.blue {
  color: #eefaff;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.28), transparent 28%),
    var(--blue);
  box-shadow: inset 0 -10px 18px rgba(18, 62, 86, 0.44), 0 9px 0 rgba(18, 62, 86, 0.34);
}

.piece:hover {
  transform: translateY(-3px);
}

.piece.selected {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 0 0 5px rgba(249, 241, 221, 0.78), 0 0 0 9px var(--gold), 0 12px 0 rgba(43, 34, 24, 0.2);
}

.cell.valid-move::after,
.cell.valid-attack::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 8px;
  pointer-events: none;
}

.cell.valid-move::after {
  border: 4px dashed rgba(84, 120, 91, 0.92);
}

.cell.valid-attack::after {
  border: 4px solid rgba(187, 45, 45, 0.92);
}

.legend {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.legend span {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(43, 34, 24, 0.36);
  background: rgba(255, 248, 220, 0.44);
  font-size: clamp(0.78rem, 2vw, 0.98rem);
  font-weight: 800;
  white-space: nowrap;
}

.side-panel {
  position: relative;
  min-height: 520px;
  padding: 26px;
  display: grid;
  align-content: start;
  gap: 22px;
}

.rule-wheel {
  width: min(250px, 100%);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 2px solid var(--line);
  border-radius: 50%;
  position: relative;
  background:
    conic-gradient(from -90deg, rgba(187, 45, 45, 0.2), rgba(201, 147, 45, 0.28), rgba(84, 120, 91, 0.24), rgba(31, 110, 136, 0.24), rgba(187, 45, 45, 0.2)),
    rgba(255, 248, 220, 0.55);
}

.rule-wheel::after {
  content: "克";
  position: absolute;
  inset: 35%;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #fbf2d9;
  font-size: 2.2rem;
  font-weight: 900;
}

.rule-wheel span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #fff2ce;
  font-weight: 900;
  transform: rotate(calc(var(--i) * 72deg - 90deg)) translate(96px) rotate(calc(var(--i) * -72deg + 90deg));
}

.message {
  min-height: 58px;
  border-left: 5px solid var(--gold);
  padding: 10px 12px;
  background: rgba(255, 248, 220, 0.52);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.45;
}

.players {
  display: grid;
  gap: 8px;
}

.players div {
  min-height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(43, 34, 24, 0.34);
  background: rgba(255, 248, 220, 0.46);
}

.players strong,
.players span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.players span {
  color: var(--muted);
  font-weight: 900;
}

.log {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.log li {
  padding: 9px 11px;
  border-bottom: 1px solid rgba(43, 34, 24, 0.24);
  color: var(--muted);
  line-height: 1.35;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(33, 27, 22, 0.48);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  border: 2px solid var(--line);
  background: #f7edd8;
  padding: 28px;
  box-shadow: var(--shadow);
}

.modal-panel h2 {
  font-size: 2.4rem;
}

.modal-panel button {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: #fff8e7;
  background: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

@media (max-width: 860px) {
  .game-shell {
    grid-template-columns: 1fr;
    align-items: start;
    padding-top: 18px;
  }

  .side-panel {
    min-height: 0;
  }

  .rule-wheel {
    display: none;
  }
}

@media (max-width: 520px) {
  .game-shell {
    width: min(100vw - 18px, 1120px);
  }

  .table {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .status-strip,
  .controls,
  .legend {
    grid-template-columns: 1fr;
  }

  .legend {
    display: none;
  }

  .board {
    gap: 6px;
    padding: 8px;
  }

  .piece {
    inset: 5%;
  }
}
