* {
  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: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

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

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

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

.btn-mute {
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.85);
  color: #1d1c1c;
  box-shadow: 1px 1px 0 #1d1c1c;
}

.btn-mute.is-muted {
  opacity: 0.72;
  background: rgba(255, 255, 255, 0.55);
}

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

.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: 620px;
  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;
}

.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;
}

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

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

.rules-note {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  line-height: 1.45;
  opacity: 0.6;
}

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

.invite-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin: 0 0 1rem;
}

.invite-row[hidden] {
  display: none !important;
}

.invite-label {
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0.72;
  letter-spacing: 0.02em;
}

.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;
}

.play-area {
  display: grid;
  grid-template-columns: 196px 620px 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: 560px;
  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-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;
}

/* —— 麻将桌 —— */
.table {
  min-height: 560px;
  padding: 0.75rem 0.65rem;
  border: 3px solid #1d1c1c;
  border-radius: 0.75rem;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, 0.12), transparent 55%),
    linear-gradient(160deg, #1f7a52 0%, #145c3c 55%, #0f4a30 100%);
  box-shadow: 4px 4px 0 #1d1c1c;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  color: #fff;
}

.seat {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.seat-rival {
  align-items: center;
}

.seat-me {
  align-items: center;
  margin-top: auto;
}

.hand-row,
.meld-row,
.discard-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.18rem;
  min-height: 1.2rem;
}

.hand-row {
  gap: 0.12rem;
}

.discard-row {
  max-width: 100%;
  opacity: 0.95;
}

.table-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0;
}

.wall-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.last-discard-label {
  font-size: 0.72rem;
  opacity: 0.85;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
}

.action-bar[hidden],
.chi-picker[hidden],
.last-discard[hidden],
.last-discard-label[hidden] {
  display: none !important;
}

.btn-act {
  padding: 0.4rem 0.7rem;
  font-size: 0.88rem;
  background: #fffef5;
  color: #1d1c1c;
}

.btn-act[data-act="hu"],
.btn-act[data-act="zimo"] {
  background: #ff6b4a;
  color: #fff;
  border-color: #9a2e18;
}

.btn-act[data-act="discard"] {
  background: #fff48d;
}

.btn-pass {
  background: rgba(255, 255, 255, 0.75);
}

.chi-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  padding: 0.35rem;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 0.5rem;
}

.chi-option {
  display: flex;
  gap: 0.12rem;
  padding: 0.25rem;
  border: 2px solid #fff48d;
  border-radius: 0.4rem;
  background: rgba(255, 255, 255, 0.15);
  cursor: pointer;
}

.chi-option:hover {
  background: rgba(255, 244, 141, 0.35);
}

/* 牌面 · 传统麻将图 */
.tile {
  position: relative;
  width: 40px;
  height: 56px;
  border-radius: 5px;
  border: 1.5px solid #2a2a2a;
  background:
    linear-gradient(165deg, #fffef9 0%, #f7f0de 72%, #efe6cf 100%);
  box-shadow:
    1px 1px 0 rgba(0, 0, 0, 0.2),
    inset 0 0 0 1px rgba(255, 255, 255, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
  color: #1d1c1c;
  overflow: hidden;
  padding: 2px;
}

.tile--sm {
  width: 28px;
  height: 40px;
  border-radius: 4px;
  padding: 1px;
}

.tile--back {
  background: linear-gradient(145deg, #2a6fb0, #1a4f88);
  border-color: #0d2f52;
  padding: 0;
}

.tile--back::after {
  content: "";
  width: 62%;
  height: 58%;
  border: 1.5px solid rgba(255, 244, 141, 0.55);
  border-radius: 2px;
}

.tile--clickable {
  cursor: pointer;
  transition: transform 0.12s ease;
}

.tile--clickable:hover {
  transform: translateY(-4px);
}

.tile--selected {
  transform: translateY(-10px);
  outline: 2px solid #fff48d;
  outline-offset: 1px;
  z-index: 2;
}

.tile--drawn {
  margin-left: 0.45rem;
  box-shadow: 0 0 0 2px #ff6b4a;
}

.tile--fresh {
  outline: 3px solid #39ff88;
  outline-offset: 1px;
  box-shadow:
    0 0 0 1px rgba(20, 90, 40, 0.85),
    0 0 10px rgba(57, 255, 136, 0.55);
  z-index: 3;
  animation: fresh-pulse 1.2s ease-in-out infinite;
}

@keyframes fresh-pulse {
  0%,
  100% {
    outline-color: #39ff88;
  }
  50% {
    outline-color: #a8ffc8;
  }
}

.tile-face {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.tile-face svg {
  width: 88%;
  height: 88%;
  display: block;
}

.tile-face--wan {
  gap: 0;
}

.tile-wan-num {
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
  color: #1a1a1a;
}

.tile-wan-mark {
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1;
  color: #c62828;
  margin-top: 1px;
}

.tile--sm .tile-wan-num {
  font-size: 0.95rem;
}

.tile--sm .tile-wan-mark {
  font-size: 0.55rem;
}

.tile--red .tile-wan-num {
  color: #c62828;
}

.tile-face--honor {
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
}

.tile--sm .tile-face--honor {
  font-size: 1.05rem;
}

.tile-honor--zhong {
  color: #c62828;
}

.tile-honor--fa {
  color: #1b7a36;
}

.tile-honor--bai {
  width: 62%;
  height: 62%;
  border: 2.5px solid #1d1c1c;
  border-radius: 2px;
  box-sizing: border-box;
}

.tile--sm .tile-honor--bai {
  border-width: 2px;
}

.tile-honor--wind {
  color: #1a1a1a;
}

.meld-group {
  display: flex;
  gap: 0.08rem;
  margin: 0 0.2rem;
  padding: 0.12rem;
  border-radius: 0.3rem;
  background: rgba(0, 0, 0, 0.18);
}

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

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

.victory-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  border-radius: 0.75rem;
  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.08);
  border-radius: 0.75rem;
}

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

.victory-title,
.defeat-title,
.board-toast-text {
  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.75rem;
  pointer-events: none;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.14);
}

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

.defeat-title {
  border-color: rgba(255, 255, 255, 0.65);
  background: rgba(29, 28, 28, 0.78);
}

.board-toast {
  position: absolute;
  inset: 0;
  z-index: 18;
  border-radius: 0.75rem;
  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 {
  font-size: 1.1rem;
  line-height: 1.45;
  max-width: 88%;
  white-space: normal;
}

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

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

.callout-glyph {
  margin: 0;
  min-width: 4.5rem;
  padding: 0.55rem 1.15rem;
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  font-size: 3.4rem;
  font-weight: 900;
  line-height: 1;
  color: #fff48d;
  text-align: center;
  text-shadow: 0 3px 0 #1d1c1c, 0 6px 18px rgba(0, 0, 0, 0.45);
  background: rgba(29, 28, 28, 0.82);
  border: 3px solid #fff48d;
  border-radius: 0.85rem;
  box-shadow: 4px 4px 0 #1d1c1c;
  animation: callout-pop 0.45s cubic-bezier(0.34, 1.45, 0.64, 1);
}

.callout-layer.is-discard .callout-glyph {
  font-size: 2.2rem;
  letter-spacing: 0.04em;
  color: #fff;
  border-color: #39ff88;
}

.callout-layer.is-hu .callout-glyph,
.callout-layer.is-zimo .callout-glyph {
  color: #ff6b4a;
  border-color: #ff6b4a;
  font-size: 3.8rem;
}

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

.hand-row--revealed {
  padding: 0.2rem 0.15rem;
  border-radius: 0.4rem;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 244, 141, 0.35);
}

.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.75rem;
}

.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;
}

.leave-room-layer {
  position: absolute;
  inset: 0;
  z-index: 23;
  border-radius: 0.75rem;
  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;
}

.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: 900px) {
  .app {
    max-width: 520px;
  }

  .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%;
  }

  .chat-panel {
    height: 260px;
  }

  .table {
    min-height: 460px;
  }

  .tile {
    width: 34px;
    height: 48px;
  }

  .tile--sm {
    width: 24px;
    height: 34px;
  }

  .tile-wan-num {
    font-size: 1.15rem;
  }

  .tile-face--honor {
    font-size: 1.3rem;
  }

  .callout-glyph {
    font-size: 2.8rem;
  }

  .callout-layer.is-discard .callout-glyph {
    font-size: 1.85rem;
  }

  .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.75rem 0.75rem 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;
  }
}
