:root {
  color-scheme: light;
  --bg: #f5efe5;
  --panel: #fffaf2;
  --panel-strong: #fff6e9;
  --ink: #25170d;
  --muted: #725f4b;
  --line: #9c6c3a;
  --board: #f4d29a;
  --board-edge: #d99a52;
  --red: #c71816;
  --black: #18120e;
  --cream: #fff1c6;
  --focus: #167f68;
  --shadow: 0 22px 60px rgba(68, 38, 7, 0.14);
  --board-inset: clamp(44px, 8.8%, 62px);
  --board-cell-x: calc((100% - var(--board-inset) - var(--board-inset)) / 8);
  --board-cell-y: calc((100% - var(--board-inset) - var(--board-inset)) / 9);
  --board-line-width: 1.5px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.9), rgba(245, 239, 229, 0.5) 52%, rgba(232, 211, 181, 0.5)),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1900px, calc(100vw - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
}

.online-bar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(255, 248, 237, 0.92);
  border: 1px solid rgba(87, 55, 19, 0.22);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.online-status {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.online-login {
  display: grid;
  grid-template-columns: minmax(150px, 220px) 112px;
  gap: 8px;
}

.online-login input,
.online-login button {
  min-height: 32px;
  min-width: 0;
  border: 1px solid rgba(37, 23, 13, 0.22);
  border-radius: 5px;
  background: #fffaf2;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.online-login input {
  padding: 0 9px;
}

.online-login button {
  cursor: pointer;
  background: var(--ink);
  color: #fff8ed;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(560px, 1fr));
  gap: 18px;
  align-items: start;
}

.game-card {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(260px, 300px);
  gap: 12px;
  align-items: stretch;
}

.game-card:first-child {
  grid-template-columns: minmax(260px, 300px) minmax(360px, 1fr);
}

.game-card:first-child .side-panel {
  order: -1;
}

.game-area,
.side-panel {
  background: rgba(255, 248, 237, 0.92);
  border: 1px solid rgba(87, 55, 19, 0.22);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.game-area {
  display: grid;
  place-items: center;
  padding: 12px;
}

.board-wrap {
  width: min(100%, 560px);
}

.board-label {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.board-title {
  margin-bottom: 6px;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}

.board-reserve {
  min-height: 56px;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) minmax(178px, 220px);
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  background: rgba(255, 246, 232, 0.84);
  border: 1px solid rgba(87, 55, 19, 0.18);
  border-radius: 7px;
}

.board-reserve h3 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}

.board {
  position: relative;
  aspect-ratio: 9 / 10;
  padding: calc(var(--board-inset) - clamp(15px, 3.2%, 24px));
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.16), transparent 18%, rgba(153, 91, 29, 0.07) 47%, transparent 72%),
    repeating-linear-gradient(90deg, rgba(135, 82, 31, 0.07) 0 1px, transparent 1px 26px),
    var(--board);
  border: 2px solid #bf7c35;
  border-radius: 14px;
  box-shadow:
    inset 0 0 0 10px rgba(235, 174, 93, 0.72),
    inset 0 0 0 15px rgba(165, 99, 38, 0.34),
    0 10px 22px rgba(99, 62, 21, 0.18);
  overflow: hidden;
}

.board::before {
  content: "";
  position: absolute;
  inset: calc(var(--board-inset) - 18px);
  border: 1px solid rgba(139, 87, 35, 0.34);
  border-radius: 8px;
  box-shadow: inset 0 0 12px rgba(111, 67, 24, 0.18);
  pointer-events: none;
}

.board-lines {
  position: absolute;
  inset: var(--board-inset);
  z-index: 0;
  pointer-events: none;
}

.board-line-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.board-line,
.palace-line {
  stroke: var(--line);
  stroke-width: var(--board-line-width);
  vector-effect: non-scaling-stroke;
  stroke-linecap: square;
}

.river-label {
  position: absolute;
  top: 50%;
  z-index: 0;
  color: rgba(112, 78, 43, 0.72);
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Noto Serif CJK SC", "Songti SC", "SimSun", serif;
  font-size: clamp(22px, 5vw, 42px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.1em;
  text-shadow: 0 1px 0 rgba(255, 237, 190, 0.8);
  transform: translate(-50%, -50%);
  white-space: nowrap;
  user-select: none;
}

.river-label.chu {
  left: 28%;
}

.river-label.han {
  left: 72%;
}

.intersection {
  position: absolute;
  z-index: 1;
  width: var(--board-cell-x);
  height: var(--board-cell-y);
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.intersection::after {
  content: "";
  width: clamp(11px, 2vw, 16px);
  height: clamp(11px, 2vw, 16px);
  border-radius: 50%;
  background: transparent;
  transition: background 120ms ease, transform 120ms ease;
}

.intersection.legal-target::after {
  background: rgba(22, 127, 104, 0.68);
  transform: scale(1.12);
}

.intersection.drop-target::after {
  background: rgba(192, 112, 29, 0.72);
  transform: scale(1.12);
}

.intersection.capture-burst::before {
  content: "";
  position: absolute;
  width: min(88%, 62px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 237, 170, 0.8) 0 18%, rgba(212, 46, 26, 0.34) 36%, rgba(212, 46, 26, 0) 70%);
  animation: square-capture-burst 460ms ease-out;
  pointer-events: none;
}

.intersection.selected .piece {
  box-shadow: 0 0 0 4px rgba(22, 127, 104, 0.32), inset 0 0 0 2px currentColor;
  transform: translateY(-1px);
}

.piece {
  position: absolute;
  width: min(80%, 55px);
  aspect-ratio: 1;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 34% 26%, rgba(255, 255, 255, 0.88), transparent 28%),
    radial-gradient(circle at 50% 50%, transparent 58%, currentColor 59% 62%, transparent 63% 70%, currentColor 71% 74%, transparent 75%),
    var(--cream);
  box-shadow:
    inset 0 0 0 3px rgba(255, 248, 221, 0.92),
    0 2px 0 rgba(255, 255, 255, 0.66),
    0 5px 9px rgba(46, 27, 9, 0.26);
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Noto Serif CJK SC", "Songti SC", "SimSun", serif;
  font-size: clamp(18px, 2.8vw, 27px);
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 0.5px 0 rgba(255, 245, 212, 0.78);
  transition: box-shadow 140ms ease, transform 140ms ease;
  will-change: transform;
}

.piece.red {
  color: var(--red);
}

.piece.black {
  color: var(--black);
}

.side-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1;
}

h2 {
  margin-bottom: 10px;
  font-size: 16px;
}

h3 {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.reference-thumb {
  width: 54px;
  height: 60px;
  border-radius: 5px;
  object-fit: cover;
  border: 1px solid rgba(37, 23, 13, 0.22);
}

.status-block,
.panel-section {
  padding: 14px;
  background: var(--panel-strong);
  border: 1px solid rgba(87, 55, 19, 0.18);
  border-radius: 8px;
}

.turn-badge {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 5px;
  padding: 0 10px;
  background: var(--black);
  color: var(--cream);
  font-size: 13px;
  font-weight: 800;
}

.turn-badge[data-side="red"] {
  background: var(--red);
}

.status-text {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.clock-side {
  min-height: 76px;
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 1px solid rgba(37, 23, 13, 0.18);
  border-radius: 7px;
  background: #fffaf2;
}

.clock-side.active {
  border-color: var(--focus);
  box-shadow: inset 4px 0 0 var(--focus);
}

.clock-side.expired {
  border-color: var(--red);
  background: #fff1ed;
}

.clock-side.ready {
  border-color: rgba(22, 127, 104, 0.42);
}

.clock-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.clock-time {
  justify-self: end;
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.seat-status {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.seat-controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 68px;
  gap: 5px;
}

.seat-button,
.ready-button,
.bot-select {
  min-height: 28px;
  min-width: 0;
  border: 1px solid rgba(37, 23, 13, 0.22);
  border-radius: 5px;
  background: #fffaf2;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.seat-button,
.ready-button {
  cursor: pointer;
}

.ready-button {
  background: var(--focus);
  color: #fff8ed;
}

.seat-button:disabled,
.ready-button:disabled,
.bot-select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.match-footer {
  margin-top: 18px;
  display: flex;
  justify-content: center;
}

.match-footer button {
  min-width: 180px;
  min-height: 44px;
  border: 1px solid rgba(37, 23, 13, 0.22);
  border-radius: 6px;
  background: var(--ink);
  color: #fff8ed;
  cursor: pointer;
  font-weight: 800;
}

.reserve-list {
  min-height: 38px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.reserve-piece {
  width: 32px;
  height: 32px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 50%, transparent 58%, currentColor 60% 64%, transparent 65%),
    var(--cream);
  cursor: pointer;
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Noto Serif CJK SC", "Songti SC", "SimSun", serif;
  font-size: 17px;
  font-weight: 800;
  box-shadow: 0 3px 7px rgba(46, 27, 9, 0.16);
}

.reserve-piece:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.reserve-piece.red {
  color: var(--red);
}

.reserve-piece.black {
  color: var(--black);
}

.reserve-piece.selected-reserve {
  box-shadow: 0 0 0 4px rgba(192, 112, 29, 0.24), 0 3px 7px rgba(46, 27, 9, 0.16);
}

.piece.move-flash {
  animation: piece-settle 420ms cubic-bezier(0.2, 0.9, 0.22, 1);
}

.piece.capture-flash {
  animation: piece-capture 520ms ease-out;
}

.piece.check-flash {
  animation: piece-check 680ms ease-in-out 3;
}

@keyframes piece-settle {
  0% {
    transform: translateY(-12px) scale(0.84);
    filter: brightness(1.2) saturate(1.1);
  }

  58% {
    transform: translateY(2px) scale(1.08);
  }

  78% {
    transform: translateY(-2px) scale(0.98);
  }

  100% {
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }
}

@keyframes piece-capture {
  0% {
    box-shadow:
      0 0 0 0 rgba(199, 24, 22, 0.34),
      inset 0 0 0 3px rgba(255, 248, 221, 0.92),
      0 5px 9px rgba(46, 27, 9, 0.26);
    transform: rotate(-3deg) scale(1);
  }

  42% {
    box-shadow:
      0 0 0 10px rgba(199, 24, 22, 0.2),
      inset 0 0 0 3px rgba(255, 248, 221, 0.92),
      0 6px 12px rgba(46, 27, 9, 0.28);
    transform: rotate(2deg) scale(1.16);
  }

  72% {
    box-shadow:
      0 0 0 17px rgba(199, 24, 22, 0),
      inset 0 0 0 3px rgba(255, 248, 221, 0.92),
      0 6px 12px rgba(46, 27, 9, 0.28);
    transform: rotate(0deg) scale(0.97);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes square-capture-burst {
  0% {
    opacity: 0.95;
    transform: scale(0.42);
  }

  72% {
    opacity: 0.55;
    transform: scale(1.26);
  }

  100% {
    opacity: 0;
    transform: scale(1.5);
  }
}

@keyframes piece-check {
  0%,
  100% {
    box-shadow:
      inset 0 0 0 3px rgba(255, 248, 221, 0.92),
      0 5px 9px rgba(46, 27, 9, 0.26);
  }

  50% {
    box-shadow:
      0 0 0 7px rgba(199, 24, 22, 0.32),
      0 0 18px rgba(199, 24, 22, 0.32),
      inset 0 0 0 3px rgba(255, 248, 221, 0.92),
      0 7px 14px rgba(46, 27, 9, 0.32);
    transform: scale(1.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  .piece,
  .piece.move-flash,
  .piece.capture-flash,
  .piece.check-flash,
  .intersection.capture-burst::before {
    animation: none;
    transition: none;
  }
}

.empty-text {
  color: var(--muted);
  font-size: 14px;
}

.move-section {
  flex: 1;
  min-height: 160px;
}

.move-list {
  max-height: 210px;
  margin: 0;
  padding-left: 22px;
  overflow: auto;
  color: var(--muted);
  line-height: 1.6;
}

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

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

  .game-card {
    grid-template-columns: 1fr;
  }

  .game-card:first-child {
    grid-template-columns: 1fr;
  }

  .game-area {
    padding: 10px;
  }

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

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 12px, 520px);
    margin: 6px auto;
    gap: 8px;
  }

  .game-area,
  .side-panel {
    border-radius: 6px;
  }

  .board {
    --board-inset: 38px;
    --board-line-width: 1.25px;
  }

  .board-reserve {
    grid-template-columns: 62px minmax(0, 1fr);
  }

  .clock-side {
    grid-column: 1 / -1;
    grid-template-columns: 48px 1fr;
  }

  .side-panel {
    padding: 12px;
  }

  .reference-thumb {
    width: 54px;
    height: 60px;
  }
}
