:root {
  --ink: #211712;
  --muted: #765f52;
  --paper: #f7ead3;
  --panel: #fff7e7;
  --line: #6f3425;
  --accent: #b83226;
  --accent-dark: #771d17;
  --black-piece: #24201d;
  --radius: 8px;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 248, 232, 0.86), rgba(232, 198, 154, 0.72)),
    repeating-linear-gradient(90deg, rgba(97, 49, 30, 0.07) 0 1px, transparent 1px 44px),
    #ecd0a2;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

.loading-view,
.empty-state {
  padding: 32px;
  border: 1px dashed rgba(111, 52, 37, 0.38);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 247, 231, 0.68);
}

.lobby-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(360px, 1.28fr);
  gap: 22px;
  min-height: calc(100dvh - 48px);
}

.brand-panel,
.control-panel,
.game-side {
  border: 1px solid rgba(111, 52, 37, 0.26);
  border-radius: var(--radius);
  background: rgba(255, 247, 231, 0.86);
  box-shadow: 0 24px 70px rgba(86, 39, 22, 0.18);
}

.brand-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(28px, 5vw, 64px);
  position: relative;
  overflow: hidden;
}

.brand-panel::after {
  content: "";
  position: absolute;
  inset: auto -18% -28% auto;
  width: 320px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 34px solid rgba(184, 50, 38, 0.09);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  margin-bottom: 26px;
  border-radius: 50%;
  color: var(--accent);
  background:
    radial-gradient(circle at 35% 22%, #fff7df, #d99a5e 64%, #8a3e25);
  border: 3px solid #7c251e;
  box-shadow: inset 0 3px 5px rgba(255, 255, 255, 0.65), 0 14px 30px rgba(119, 29, 23, 0.22);
  font-size: 38px;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-dark);
  font-weight: 800;
}

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

.brand-panel h1 {
  max-width: 7.6em;
  margin-bottom: 18px;
  font-size: clamp(36px, 4.4vw, 62px);
  line-height: 1.08;
  letter-spacing: 0;
}

.lead {
  max-width: 32em;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.8;
}

.quick-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.quick-stats span,
.lock-badge {
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(111, 52, 37, 0.24);
  background: rgba(255, 255, 255, 0.48);
}

.control-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  padding: 18px;
}

.create-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(111, 52, 37, 0.32);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 50, 38, 0.14);
}

.primary-button,
.secondary-button,
.ghost-button,
.join-actions button {
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 900;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.primary-button {
  color: #fff9ed;
  background: linear-gradient(180deg, #cf4334, #8c241c);
  box-shadow: 0 10px 22px rgba(119, 29, 23, 0.24);
}

.secondary-button,
.join-actions button {
  color: var(--accent-dark);
  background: #fff8e9;
  border-color: rgba(111, 52, 37, 0.28);
}

.ghost-button {
  color: var(--muted);
  background: transparent;
  border-color: rgba(111, 52, 37, 0.24);
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.join-actions button:active {
  transform: translateY(1px) scale(0.99);
}

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

.section-title,
.room-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.section-title h2 {
  margin-bottom: 14px;
  font-size: 24px;
}

.section-title span {
  color: var(--muted);
  font-weight: 800;
}

.rooms-list {
  display: grid;
  gap: 12px;
  max-height: calc(100dvh - 228px);
  overflow: auto;
  padding-right: 4px;
}

.room-card {
  padding: 16px;
  border: 1px solid rgba(111, 52, 37, 0.22);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(255, 242, 213, 0.72));
}

.room-card h3 {
  margin-bottom: 5px;
  font-size: 19px;
}

.room-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.seat-grid span {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: var(--radius);
  background: rgba(128, 79, 46, 0.08);
  color: var(--muted);
  font-size: 12px;
}

.seat-grid strong {
  color: var(--ink);
  font-size: 14px;
}

.join-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 10px;
}

.join-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.game-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  min-height: calc(100dvh - 48px);
}

.game-side {
  position: sticky;
  top: 20px;
  padding: 18px;
}

.room-title h1 {
  margin: 18px 0 4px;
  font-size: 28px;
}

.room-title p {
  color: var(--muted);
}

.room-code {
  border: 0;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--accent-dark);
  background: rgba(184, 50, 38, 0.1);
  font-weight: 900;
}

.status-box {
  display: grid;
  gap: 8px;
  margin: 18px 0;
  padding: 16px;
  border-radius: var(--radius);
  color: #fff9ed;
  background: linear-gradient(135deg, #853123, #4b241c);
}

.status-box.black {
  background: linear-gradient(135deg, #2b2928, #111);
}

.status-box span {
  opacity: 0.82;
}

.status-box strong {
  font-size: 24px;
}

.status-box em {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 6px;
  color: #ffe0b3;
  background: rgba(255, 255, 255, 0.12);
  font-style: normal;
  font-weight: 900;
}

.players-box,
.actions-box,
.history-box {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.players-box div,
.history-list div {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border-radius: var(--radius);
  background: rgba(128, 79, 46, 0.08);
}

.players-box span,
.history-list span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.history-box h2 {
  margin: 8px 0 0;
  font-size: 18px;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow: auto;
}

.history-list p {
  color: var(--muted);
}

.game-main {
  display: grid;
  place-items: center;
  min-height: calc(100dvh - 48px);
}

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

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 10;
  border-radius: var(--radius);
  padding: 7.3%;
  background:
    linear-gradient(90deg, rgba(77, 34, 18, 0.06), rgba(255, 255, 255, 0.1), rgba(77, 34, 18, 0.08)),
    repeating-linear-gradient(93deg, rgba(115, 59, 29, 0.14) 0 7px, rgba(255, 229, 176, 0.1) 7px 17px),
    #d89b55;
  border: 10px solid #74351f;
  box-shadow:
    inset 0 0 0 4px rgba(255, 228, 176, 0.38),
    0 24px 70px rgba(86, 39, 22, 0.34);
}

.board-svg {
  position: absolute;
  inset: 7.3%;
  width: 85.4%;
  height: 85.4%;
  overflow: visible;
}

.board-svg line {
  stroke: var(--line);
  stroke-width: 0.025;
  stroke-linecap: round;
}

.river {
  position: absolute;
  left: 7.3%;
  right: 7.3%;
  top: 45.7%;
  height: 8.6%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  color: rgba(111, 52, 37, 0.56);
  font-size: clamp(20px, 4.3vw, 40px);
  font-weight: 900;
  letter-spacing: 0;
  pointer-events: none;
}

.point-zone,
.piece {
  position: absolute;
  left: calc(7.3% + var(--x) * 0.854);
  top: calc(7.3% + var(--y) * 0.854);
  transform: translate(-50%, -50%);
}

.point-zone {
  z-index: 2;
  width: 8.8%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.point-zone.last-point::after,
.point-zone.selected-point::after {
  content: "";
  position: absolute;
  inset: 26%;
  border-radius: 50%;
  background: rgba(184, 50, 38, 0.25);
}

.point-zone.selected-point::after {
  inset: 18%;
  border: 2px solid rgba(184, 50, 38, 0.75);
  background: rgba(255, 248, 223, 0.22);
}

.piece {
  z-index: 3;
  display: grid;
  place-items: center;
  width: 9.6%;
  min-width: 36px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid #64271a;
  color: var(--accent);
  background:
    radial-gradient(circle at 34% 22%, #fffbe9 0 17%, #e8b874 42%, #b66a35 74%, #6f2e1d 100%);
  box-shadow:
    inset 0 3px 5px rgba(255, 255, 255, 0.62),
    inset 0 -5px 9px rgba(72, 29, 18, 0.24),
    0 9px 14px rgba(67, 30, 19, 0.33);
  font-size: clamp(19px, 3.8vw, 34px);
  font-weight: 900;
}

.piece span {
  display: grid;
  place-items: center;
  width: 75%;
  aspect-ratio: 1;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: rgba(255, 245, 218, 0.38);
}

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

.piece.can-play {
  outline: 3px solid rgba(255, 248, 222, 0.58);
}

.piece.selected {
  box-shadow:
    inset 0 3px 5px rgba(255, 255, 255, 0.62),
    inset 0 -5px 9px rgba(72, 29, 18, 0.24),
    0 0 0 5px rgba(184, 50, 38, 0.3),
    0 12px 18px rgba(67, 30, 19, 0.34);
}

.piece.drop {
  animation: pieceDrop 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes pieceDrop {
  0% {
    transform: translate(-50%, -78%) scale(1.08);
    filter: brightness(1.08);
  }
  70% {
    transform: translate(-50%, -47%) scale(0.98);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 32px));
  transform: translate(-50%, 18px);
  padding: 12px 16px;
  border-radius: var(--radius);
  color: #fff9ed;
  background: rgba(33, 23, 18, 0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1050px) {
  .lobby-layout,
  .game-layout {
    grid-template-columns: 1fr;
  }

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

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

  .primary-button {
    grid-column: span 2;
  }

  .game-side {
    position: static;
  }

  .game-main {
    min-height: auto;
  }

  .board-wrap {
    width: min(96vw, 720px);
    min-width: 0;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .brand-panel,
  .control-panel,
  .game-side {
    padding: 14px;
  }

  .brand-panel h1 {
    font-size: 38px;
  }

  .create-form,
  .join-form,
  .seat-grid {
    grid-template-columns: 1fr;
  }

  .primary-button {
    grid-column: auto;
  }

  .join-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .board {
    border-width: 6px;
  }

  .piece {
    min-width: 29px;
    font-size: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
