* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", "PingFang SC", "Hiragino Sans GB", sans-serif;
  background: linear-gradient(135deg, #ff8a7a, #fff4b0, #fff48d);
  color: #1d1c1c;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.header {
  text-align: center;
  margin-bottom: 0.75rem;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 800;
}

.subtitle {
  margin: 0.35rem 0 0;
  opacity: 0.65;
  font-size: 0.9rem;
}

.room-bar {
  display: none;
}

.board-column {
  display: none;
}

.players-side {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 196px;
  min-width: 0;
}

.board-center {
  grid-column: 2;
  grid-row: 1;
  width: 450px;
  max-width: 100%;
}

.player-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
  padding: 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.82);
  border: 2px solid #1d1c1c;
  border-radius: 0.65rem;
  box-shadow: 2px 2px 0 #1d1c1c;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.45;
}

.players-side .undo-prompt {
  margin-top: 0.15rem;
}

.players-side .undo-meta {
  margin: 0;
}

.player-bar.is-active {
  outline: 2px solid #ff6b4a;
  outline-offset: 1px;
}

.player-bar.is-me {
  background: rgba(255, 249, 196, 0.92);
}

.player-bar-name {
  font-weight: 800;
}

.player-bar-sep {
  opacity: 0.55;
}

.player-bar-wins {
  color: #c62828;
}

.player-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  flex-shrink: 0;
}

.player-bar-actions .btn-bar-action {
  box-sizing: border-box;
  width: 4.55rem;
  height: 1.72rem;
  margin: 0;
  padding: 0 0.15rem;
  font-size: 0.64rem;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.player-bar-actions .btn-undo {
  width: 4.55rem;
  margin-top: 0;
  padding: 0 0.15rem;
  background: #fff;
  color: #1d1c1c;
}

.btn-leave-room {
  background: #fff;
  color: #c62828;
  border-color: #c62828;
}

.btn-leave-room[hidden] {
  display: none !important;
}

.status {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 0.5rem;
}

.btn {
  padding: 0.45rem 0.85rem;
  border: 2px solid #1d1c1c;
  border-radius: 0.5rem;
  background: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 2px 2px 0 #1d1c1c;
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary {
  font-size: 0.85rem;
}

.btn-undo {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.5rem;
  font-size: 0.85rem;
  background: #fff;
  color: #1d1c1c;
}

.undo-prompt {
  margin-top: 0.55rem;
  padding: 0.5rem;
  border: 2px dashed #ff6b4a;
  border-radius: 0.5rem;
  background: rgba(255, 244, 141, 0.65);
}

.undo-prompt-text {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.4;
  font-weight: 600;
}

.undo-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.undo-prompt[hidden],
.undo-actions[hidden] {
  display: none !important;
}

.btn-undo-act {
  flex: 1;
  font-size: 0.75rem;
  padding: 0.35rem 0.4rem;
}

.undo-meta {
  margin: 0;
  font-size: 0.75rem;
  color: #c62828;
  font-weight: 700;
  line-height: 1.35;
}

/* 电脑端：左玩家 | 中棋盘 | 右聊天 */
.play-area {
  display: grid;
  grid-template-columns: 196px 450px 260px;
  grid-template-rows: auto;
  gap: 0.75rem;
  align-items: start;
  justify-content: center;
}

.board-wrap {
  position: relative;
  width: 100%;
}

.chat-panel {
  grid-column: 3;
  grid-row: 1;
  width: 260px;
  height: 500px;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.82);
  border: 3px solid #1d1c1c;
  border-radius: 1rem;
  box-shadow: 4px 4px 0 #1d1c1c;
  min-width: 0;
}

.chat-header {
  padding: 0.65rem 0.75rem 0.45rem;
  border-bottom: 2px solid rgba(29, 28, 28, 0.12);
}

.chat-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 800;
}

.chat-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  opacity: 0.6;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.55rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.82rem;
  line-height: 1.45;
  scroll-behavior: smooth;
}

.chat-messages:empty::before {
  content: "暂无消息";
  opacity: 0.45;
  font-size: 0.78rem;
  text-align: center;
  margin-top: 1rem;
}

.chat-bubble {
  max-width: 88%;
  padding: 0.45rem 0.6rem;
  border-radius: 0.75rem;
  border: 2px solid #1d1c1c;
  background: #fff;
  word-break: break-word;
}

.chat-bubble--me {
  align-self: flex-end;
  background: #fff9c4;
  border-color: #c9a800;
  border-bottom-right-radius: 0.2rem;
}

.chat-bubble--other {
  align-self: flex-start;
  border-bottom-left-radius: 0.2rem;
}

.chat-bubble-name {
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0.75;
}

.chat-bubble-text {
  word-break: break-word;
}

.chat-form {
  display: flex;
  gap: 0.35rem;
  padding: 0.55rem 0.65rem;
  border-top: 2px solid rgba(29, 28, 28, 0.12);
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 2px solid #1d1c1c;
  border-radius: 0.45rem;
  font: inherit;
  font-size: 0.82rem;
  background: #fff;
}

.chat-input:disabled {
  opacity: 0.5;
  background: #f5f5f5;
}

.btn-chat-send {
  flex: 0 0 auto;
  padding: 0.4rem 0.55rem;
  font-size: 0.78rem;
  background: #1d1c1c;
  color: #fff48d;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  border: 3px solid #1d1c1c;
  border-radius: 0.5rem;
  background: #dcb35c;
  cursor: pointer;
  touch-action: manipulation;
}

#board.is-disabled {
  cursor: not-allowed;
  opacity: 0.92;
}

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 0.5rem;
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  text-align: center;
  padding: 1rem;
  pointer-events: none;
}

.board-overlay[hidden] {
  display: none !important;
}

.victory-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  border-radius: 0.5rem;
  pointer-events: none;
  overflow: hidden;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.victory-layer[hidden] {
  display: none !important;
}

.victory-layer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.12);
  border-radius: 0.5rem;
}

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.victory-title {
  position: relative;
  z-index: 2;
  margin: 0;
  padding: 0.55rem 1rem;
  font-size: 1.25rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  background: rgba(29, 28, 28, 0.72);
  border-radius: 999px;
  border: 2px solid #fff48d;
  animation: victory-pop 0.55s cubic-bezier(0.34, 1.4, 0.64, 1);
  text-align: center;
  white-space: nowrap;
}

@keyframes victory-pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.defeat-layer {
  position: absolute;
  inset: 0;
  z-index: 19;
  border-radius: 0.5rem;
  pointer-events: none;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.28);
}

.defeat-layer[hidden] {
  display: none !important;
}

.defeat-title {
  margin: 0;
  padding: 0.55rem 1rem;
  font-size: 1.25rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  background: rgba(29, 28, 28, 0.78);
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.65);
  animation: victory-pop 0.55s cubic-bezier(0.34, 1.4, 0.64, 1);
  text-align: center;
  white-space: nowrap;
}

.board-toast {
  position: absolute;
  inset: 0;
  z-index: 18;
  border-radius: 0.5rem;
  pointer-events: none;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.22);
}

.board-toast[hidden] {
  display: none !important;
}

.board-toast-text {
  margin: 0;
  padding: 0.55rem 1rem;
  font-size: 1.1rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  background: rgba(29, 28, 28, 0.78);
  border-radius: 999px;
  border: 2px solid #fff48d;
  animation: victory-pop 0.55s cubic-bezier(0.34, 1.4, 0.64, 1);
  text-align: center;
  line-height: 1.45;
  max-width: 88%;
}

.undo-board-layer {
  position: absolute;
  inset: 0;
  z-index: 21;
  border-radius: 0.5rem;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.42);
  padding: 1rem;
}

.undo-board-layer[hidden] {
  display: none !important;
}

.undo-board-panel {
  max-width: 92%;
  padding: 0.85rem 1rem;
  background: rgba(29, 28, 28, 0.88);
  border: 2px solid #fff48d;
  border-radius: 0.75rem;
  box-shadow: 3px 3px 0 #1d1c1c;
  text-align: center;
}

.undo-board-wait,
.undo-board-text {
  margin: 0 0 0.75rem;
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.45;
}

.undo-board-wait[hidden],
.undo-board-respond[hidden] {
  display: none !important;
}

.undo-board-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: center;
  flex-wrap: wrap;
}

.undo-board-actions .btn-undo-act {
  min-width: 5.5rem;
}

.leave-room-layer {
  position: absolute;
  inset: 0;
  z-index: 23;
  border-radius: 0.5rem;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.48);
  padding: 1rem;
}

.leave-room-layer[hidden] {
  display: none !important;
}

.leave-room-panel {
  max-width: 92%;
  padding: 0.95rem 1.1rem;
  background: rgba(29, 28, 28, 0.92);
  border: 2px solid #fff48d;
  border-radius: 0.75rem;
  box-shadow: 3px 3px 0 #1d1c1c;
  text-align: center;
}

.leave-room-text {
  margin: 0 0 0.85rem;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.45;
}

.leave-room-panel .btn-board-action {
  margin: 0;
}

.board-action {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 0.5rem;
}

.board-action[hidden] {
  display: none !important;
}

.btn-board-action {
  padding: 0.7rem 1.6rem;
  font-size: 1.05rem;
  background: #1d1c1c;
  color: #fff48d;
  border: 2px solid #fff48d;
  box-shadow: 3px 3px 0 #1d1c1c;
}

.btn-board-action.is-ready {
  background: #4caf50;
  color: #fff;
  border-color: #2e7d32;
}

.btn-board-action:disabled {
  opacity: 1;
  cursor: default;
  transform: none;
  box-shadow: 3px 3px 0 #1d1c1c;
}

.board-chat-ticker {
  display: none;
}

.hint {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.82rem;
  opacity: 0.65;
  line-height: 1.6;
}

.hint a {
  color: inherit;
}

/* 手机端：玩家在上、棋盘在中、聊天在下 */
@media (max-width: 760px) {
  .app {
    max-width: 480px;
  }

  .play-area {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .players-side,
  .board-center,
  .chat-panel {
    grid-column: auto;
    grid-row: auto;
    width: 100%;
  }

  .players-side {
    width: 100%;
  }

  .chat-panel {
    height: 280px;
  }

  .board-chat-ticker {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 3;
    pointer-events: none;
    padding: 0.4rem 0.55rem;
    border-radius: 0.5rem 0.5rem 0 0;
    background: linear-gradient(
      to bottom,
      rgba(29, 28, 28, 0.78) 0%,
      rgba(29, 28, 28, 0.45) 100%
    );
  }

  .board-chat-ticker[hidden] {
    display: none !important;
  }

  .board-chat-ticker-msg {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
    word-break: break-word;
    opacity: 1;
    transition: opacity 0.5s ease;
  }

  .board-chat-ticker.is-fading .board-chat-ticker-msg {
    opacity: 0;
  }
}
