:root {
  --bg-1: #6c4b28;
  --bg-2: #3f2a17;
  --paper: rgba(255, 248, 235, 0.94);
  --paper-strong: #f7ecd6;
  --wood: #e1b978;
  --wood-dark: #8a5a27;
  --wood-deep: #5a3718;
  --ink: #2f1f12;
  --ink-soft: #6b533c;
  --line: rgba(87, 51, 24, 0.16);
  --accent: #9b5d2f;
  --accent-deep: #6f3f1d;
  --red: #a11f12;
  --black: #1d1916;
  --shadow: rgba(12, 7, 4, 0.28);
  --board-width: min(100%, 880px);
  --piece-size: clamp(3.4rem, 7.1vw, 4.95rem);
  --radius: 30px;
  color-scheme: light;
  font-family: "KaiTi", "STKaiti", "FangSong", "SimSun", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(255, 231, 180, 0.28), transparent 24%),
    radial-gradient(circle at bottom right, rgba(255, 209, 141, 0.18), transparent 20%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
}

button,
a {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--accent-deep);
}

.page-shell {
  width: min(1440px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.4rem 0 2.2rem;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1.35rem;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 0.35rem;
  color: rgba(250, 231, 202, 0.82);
  font-size: 0.78rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p,
ul {
  margin: 0;
}

h1 {
  color: #fff8ea;
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  line-height: 1;
  text-shadow: 0 18px 28px rgba(14, 8, 3, 0.24);
}

.header-copy {
  margin-top: 0.75rem;
  max-width: 54rem;
  color: rgba(255, 244, 224, 0.8);
  line-height: 1.72;
  font-size: 1rem;
}

.turn-chip {
  padding: 0.95rem 1.3rem;
  border-radius: 999px;
  background: rgba(255, 247, 230, 0.12);
  border: 1px solid rgba(255, 226, 180, 0.24);
  color: #fff4de;
  box-shadow: 0 24px 40px -28px rgba(0, 0, 0, 0.72);
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.95fr);
  gap: 1.2rem;
  align-items: start;
}

.board-panel,
.panel {
  border-radius: var(--radius);
  border: 1px solid rgba(255, 232, 193, 0.14);
  background: var(--paper);
  box-shadow:
    0 24px 60px -28px var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(10px);
}

.board-panel {
  padding: 1.2rem;
}

.board-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.board-meta h2,
.panel h2 {
  margin-bottom: 0.45rem;
  font-size: 1.55rem;
}

#status-message,
.selection-empty,
.event-log,
.rule-list,
.asset-note {
  color: var(--ink-soft);
  line-height: 1.7;
}

.board-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.7rem;
}

.action-button {
  border: none;
  border-radius: 999px;
  padding: 0.84rem 1.25rem;
  cursor: pointer;
  background: linear-gradient(135deg, #b16a2f, #7c451d);
  color: #fff8ee;
  box-shadow: 0 16px 30px -22px rgba(70, 38, 15, 0.96);
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
}

.action-button:hover {
  transform: translateY(-1px);
  filter: saturate(1.04);
}

.action-button:active {
  transform: translateY(0);
}

.action-button--ghost {
  background: rgba(111, 63, 29, 0.08);
  color: var(--accent-deep);
  box-shadow: none;
}

.launch-help {
  margin-top: 1rem;
  padding: 0.95rem 1rem;
  border-radius: 18px;
  border: 1px solid rgba(161, 31, 18, 0.18);
  background: rgba(161, 31, 18, 0.08);
  color: #7c2116;
  line-height: 1.7;
}

.launch-help code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92em;
}

.is-hidden {
  display: none;
}

.board-surface {
  --board-grid-left: 5.6941%;
  --board-grid-top: 5.0898%;
  --board-grid-step-x: 11.0818%;
  --board-grid-step-y: 9.98%;
  --board-hit-width: 11.8%;
  --board-hit-height: 10.8%;
  position: relative;
  width: var(--board-width);
  aspect-ratio: 902.383 / 1002;
  margin: 1rem auto 0;
  border-radius: 34px;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(255, 246, 220, 0.4), transparent 24%),
    linear-gradient(145deg, #f2d3a0, #dfb06b);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.48),
    inset 0 0 0 12px rgba(108, 68, 32, 0.08),
    0 28px 42px -28px rgba(0, 0, 0, 0.65);
}

.board-surface::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("./assets/xiangqi-gmchess/board.svg") center / 100% 100% no-repeat;
}

.board-surface::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 16%),
    radial-gradient(circle at 70% 30%, rgba(255, 255, 255, 0.14), transparent 18%);
  pointer-events: none;
}

.board-grid {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.cell {
  position: absolute;
  left: calc(var(--board-grid-left) + var(--col) * var(--board-grid-step-x));
  top: calc(var(--board-grid-top) + var(--row) * var(--board-grid-step-y));
  width: var(--board-hit-width);
  height: var(--board-hit-height);
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
}

.cell:focus {
  outline: none;
}

.cell:focus-visible::before {
  box-shadow: 0 0 0 0.22rem rgba(246, 223, 175, 0.74);
}

.cell::before {
  content: "";
  position: absolute;
  width: 86%;
  height: 86%;
  border-radius: 50%;
  transition: background-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.cell:hover::before {
  background: rgba(130, 82, 39, 0.08);
}

.cell.is-selected::before {
  background: radial-gradient(circle, rgba(195, 132, 43, 0.28), rgba(195, 132, 43, 0.08) 64%, transparent 72%);
}

.cell.is-inspected:not(.is-selected)::before {
  background: radial-gradient(circle, rgba(68, 46, 22, 0.2), transparent 70%);
}

.cell.is-legal-target::after {
  content: "";
  position: absolute;
  width: 0.82rem;
  height: 0.82rem;
  border-radius: 50%;
  background: rgba(90, 55, 24, 0.72);
  box-shadow: 0 0 0 0.18rem rgba(255, 240, 213, 0.7);
}

.cell.is-legal-target.has-piece::after {
  width: calc(var(--piece-size) * 0.96);
  height: calc(var(--piece-size) * 0.96);
  border: 3px solid rgba(127, 75, 31, 0.82);
  background: rgba(255, 255, 255, 0.02);
  box-shadow: 0 0 0 0.25rem rgba(255, 231, 182, 0.52);
}

.piece {
  position: relative;
  z-index: 1;
  width: min(var(--piece-size), 100%);
  height: min(var(--piece-size), 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.piece-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 12px 12px rgba(48, 25, 9, 0.22));
}

.cell.is-selected .piece-image {
  filter:
    drop-shadow(0 0 0.45rem rgba(255, 225, 160, 0.9))
    drop-shadow(0 14px 12px rgba(48, 25, 9, 0.26));
}

.cell.is-inspected:not(.is-selected) .piece-image {
  filter:
    drop-shadow(0 0 0.35rem rgba(103, 73, 39, 0.45))
    drop-shadow(0 14px 12px rgba(48, 25, 9, 0.22));
}

.river-script {
  position: absolute;
  left: 14.2%;
  top: 49.85%;
  width: 71.6%;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  color: rgba(96, 58, 28, 0.6);
  font-size: clamp(1.85rem, 3.5vw, 3rem);
  letter-spacing: 0.36em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  pointer-events: none;
  z-index: 1;
}

.board-note {
  margin-top: 1rem;
  color: var(--ink-soft);
  line-height: 1.72;
}

.sidebar {
  display: grid;
  gap: 1rem;
}

.panel {
  padding: 1.15rem;
}

.piece-identity {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.piece-avatar {
  width: 4.6rem;
  height: 4.6rem;
  padding: 0.3rem;
  border-radius: 1.3rem;
  background: linear-gradient(145deg, rgba(255, 248, 233, 0.92), rgba(235, 211, 171, 0.9));
  border: 1px solid rgba(120, 74, 34, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.piece-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.piece-meta {
  margin-top: 0.28rem;
  color: var(--ink-soft);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.72rem;
  margin-bottom: 1rem;
}

.metric-pill {
  padding: 0.75rem 0.85rem;
  border-radius: 18px;
  background: rgba(188, 129, 56, 0.08);
  border: 1px solid rgba(111, 63, 29, 0.1);
}

.metric-pill span {
  display: block;
  color: var(--ink-soft);
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
}

.metric-pill strong {
  font-size: 1.24rem;
}

.stack-card {
  padding: 0.95rem 1rem;
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(255, 250, 240, 0.9), rgba(244, 230, 204, 0.82));
  border: 1px solid rgba(120, 74, 34, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.stack-card + .stack-card {
  margin-top: 0.85rem;
}

.stack-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.stack-head h4 {
  font-size: 1.08rem;
  margin-bottom: 0.18rem;
}

.stack-head p {
  color: var(--ink-soft);
  line-height: 1.6;
}

.stack-total {
  font-size: 1.18rem;
  white-space: nowrap;
}

.stack-list {
  padding-left: 1.15rem;
  color: var(--ink-soft);
  line-height: 1.72;
}

.selection-empty {
  min-height: 6rem;
}

.rule-list {
  padding-left: 1.15rem;
}

.asset-link {
  display: inline-flex;
  margin-top: 0.75rem;
  text-decoration: none;
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(21, 13, 6, 0.52);
  backdrop-filter: blur(8px);
}

.modal.is-hidden {
  display: none;
}

.modal-card {
  width: min(480px, 100%);
  padding: 1.4rem;
  border-radius: 28px;
  background: rgba(255, 247, 232, 0.96);
  border: 1px solid rgba(120, 74, 34, 0.14);
  box-shadow: 0 26px 60px -30px rgba(0, 0, 0, 0.5);
}

.modal-card h2 {
  margin-bottom: 0.7rem;
}

#modal-body {
  margin-bottom: 1rem;
  color: var(--ink-soft);
  line-height: 1.72;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .page-shell {
    width: min(100vw - 1rem, 100%);
    padding-top: 1rem;
  }

  .topbar,
  .board-meta {
    flex-direction: column;
    align-items: stretch;
  }

  .board-actions {
    justify-content: flex-start;
  }

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

  .metric-strip {
    grid-template-columns: 1fr 1fr;
  }

  .river-script {
    left: 12.8%;
    width: 74.4%;
    font-size: clamp(1.3rem, 4.6vw, 2.2rem);
    letter-spacing: 0.24em;
  }
}

@media (max-width: 560px) {
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .stack-head {
    flex-direction: column;
  }
}

.content-stack {
  display: grid;
  gap: 1.2rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-copy {
  color: var(--ink-soft);
  line-height: 1.7;
}

.identity-card {
  padding: 1rem;
  border-radius: 22px;
  border: 1px solid rgba(111, 63, 29, 0.14);
  background: rgba(255, 250, 242, 0.82);
}

.field-label {
  display: block;
  margin-bottom: 0.55rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.field-row {
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

.field-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.88rem 1rem;
  border-radius: 16px;
  border: 1px solid rgba(111, 63, 29, 0.2);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

.field-hint,
.table-copy,
.seat-copy,
.table-note,
.session-error,
.status-banner {
  color: var(--ink-soft);
  line-height: 1.7;
}

.field-hint {
  margin-top: 0.7rem;
}

.table-grid,
.room-seats {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.table-grid {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.table-card,
.seat-card {
  padding: 1rem;
  border-radius: 24px;
  border: 1px solid rgba(111, 63, 29, 0.14);
  background: rgba(255, 252, 247, 0.84);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.table-card--self,
.seat-card--self {
  border-color: rgba(161, 31, 18, 0.28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 14px 28px -24px rgba(161, 31, 18, 0.7);
}

.seat-card--ready {
  background: rgba(245, 252, 239, 0.9);
}

.table-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  background: rgba(111, 63, 29, 0.1);
  color: var(--accent-deep);
}

.status-tag--playing {
  background: rgba(161, 31, 18, 0.12);
  color: var(--red);
}

.status-tag--finished {
  background: rgba(56, 96, 42, 0.12);
  color: #2f6a2b;
}

.seat-list {
  display: grid;
  gap: 0.7rem;
  margin-top: 0.9rem;
}

.seat-pill {
  display: grid;
  gap: 0.22rem;
  padding: 0.8rem 0.95rem;
  border-radius: 18px;
  background: rgba(111, 63, 29, 0.06);
}

.seat-pill--occupied {
  background: rgba(111, 63, 29, 0.1);
}

.seat-pill--self {
  outline: 1px solid rgba(161, 31, 18, 0.28);
}

.seat-pill strong,
.seat-pill span,
.seat-pill em {
  font-style: normal;
}

.seat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.95rem;
}

.status-banner {
  margin-top: 0.95rem;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  border: 1px solid rgba(111, 63, 29, 0.14);
  background: rgba(255, 250, 242, 0.78);
}

.status-banner--soft {
  margin-bottom: 0.9rem;
}

.session-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.session-item {
  padding: 0.8rem 0.9rem;
  border-radius: 18px;
  background: rgba(111, 63, 29, 0.06);
}

.session-item span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--ink-soft);
  font-size: 0.84rem;
}

.session-error {
  margin-top: 0.85rem;
  color: #8a2417;
}

@media (max-width: 780px) {
  .field-row,
  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

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