* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a5f2a;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #fff;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* 按钮 */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  background: rgba(255,255,255,0.2);
  color: #fff;
  transition: background 0.2s;
}

.btn:hover {
  background: rgba(255,255,255,0.3);
}

.btn.primary {
  background: #f5a623;
  color: #fff;
}

.btn.primary:hover {
  background: #e09420;
}

.btn.wechat {
  background: #07c160;
}

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
}

.btn.exit-btn {
  background: #c0392b;
}

.btn.exit-btn:hover {
  background: #e74c3c;
}

.btn.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

/* 登录页 */
#login-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #1a5f2a 0%, #0d3d1a 100%);
}

.login-box {
  text-align: center;
  padding: 40px;
}

.login-box h1 {
  font-size: 48px;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.subtitle {
  font-size: 18px;
  opacity: 0.8;
  margin-bottom: 40px;
}

.login-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.login-form input {
  width: 240px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 18px;
  text-align: center;
}

.login-form input::placeholder {
  color: rgba(255,255,255,0.5);
}

.login-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 240px;
}

.login-buttons .btn {
  width: 100%;
  padding: 14px;
  font-size: 18px;
}

.tip {
  margin-top: 30px;
  font-size: 13px;
  opacity: 0.6;
}

/* 大厅 */
#lobby-screen {
  padding: 20px;
  background: linear-gradient(135deg, #1a5f2a 0%, #0d3d1a 100%);
  overflow-y: auto;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

#btn-logout {
  background: rgba(255,255,255,0.15);
  font-size: 12px;
  padding: 4px 10px;
}

.avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  background-size: cover;
  background-position: center;
}

.user-info img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  margin-bottom: 20px;
}

.join-box {
  display: flex;
  gap: 10px;
}

.join-box input {
  padding: 10px 15px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 16px;
  width: 140px;
  text-align: center;
  text-transform: uppercase;
}

.join-box input::placeholder {
  color: rgba(255,255,255,0.5);
}

.panel {
  background: rgba(0,0,0,0.4);
  border-radius: 12px;
  padding: 20px;
  margin-top: 20px;
}

.panel label {
  display: block;
  margin: 10px 0 5px;
}

.panel select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: none;
  font-size: 16px;
}

.panel-actions {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.panel-actions .btn {
  flex: 1;
}

/* 房间列表 */
.room-list-section {
  margin-top: 20px;
}

.room-list-section h3 {
  font-size: 16px;
  margin-bottom: 12px;
  opacity: 0.9;
}

.room-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-hint {
  text-align: center;
  opacity: 0.5;
  padding: 30px 0;
  font-size: 14px;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.3);
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.room-item:hover {
  background: rgba(0,0,0,0.45);
}

.room-item-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.room-item-id {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
}

.room-item-host {
  font-size: 12px;
  opacity: 0.7;
}

.room-item-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  opacity: 0.8;
}

.room-join-btn {
  margin-left: 12px;
  flex-shrink: 0;
}

/* 房间 */
#room-screen {
  padding: 15px;
  background: linear-gradient(135deg, #1a5f2a 0%, #0d3d1a 100%);
}

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

#room-id-display {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
}

.seats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  flex: 1;
  align-content: center;
}

.seat {
  background: rgba(0,0,0,0.3);
  border-radius: 12px;
  padding: 15px;
  text-align: center;
  transition: all 0.3s;
  cursor: pointer;
  position: relative;
}

.seat:hover {
  background: rgba(0,0,0,0.4);
}

.seat.occupied {
  background: rgba(245, 166, 35, 0.2);
  cursor: default;
}

.seat.ready {
  border: 2px solid #f5a623;
}

.seat.my-seat {
  border: 2px solid #4fc3f7;
  box-shadow: 0 0 8px rgba(79, 195, 247, 0.3);
}

.seat-index {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 11px;
  opacity: 0.5;
}

.seat-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  margin: 0 auto 8px;
  background-size: cover;
  background-position: center;
}

.seat-name {
  font-size: 14px;
  margin-bottom: 4px;
}

.seat-status {
  font-size: 11px;
  opacity: 0.6;
  margin-bottom: 6px;
}

.seat-action {
  display: block;
  margin: 4px auto 0;
}

.room-actions {
  display: flex;
  justify-content: center;
  gap: 15px;
  padding: 15px 0;
  flex-wrap: wrap;
}

/* 牌桌 */
#game-screen {
  position: relative;
  background: #0d7a3a;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(0,0,0,0.3);
  font-size: 13px;
  z-index: 10;
}

.game-info {
  display: flex;
  gap: 15px;
  align-items: center;
  flex-wrap: wrap;
}

#bid-info {
  color: #ffd700;
  font-size: 12px;
  background: rgba(0,0,0,0.4);
  padding: 2px 8px;
  border-radius: 4px;
}

.table {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  width: 560px;
  height: 400px;
}

.player {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  background-size: cover;
  position: relative;
}

.player-role {
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 10px;
  font-weight: bold;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  color: #fff;
  display: none;
}

.player-role.dealer {
  display: block;
  background: #e74c3c;
}

.player-role.idle {
  display: block;
  background: #3498db;
}

.player-role.partner {
  display: block;
  background: #27ae60;
}

.player-name {
  font-size: 11px;
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-cards-count {
  font-size: 10px;
  opacity: 0.7;
}

.player.partner {
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
}

.player.left {
  left: -110px;
  top: 50%;
  transform: translateY(-50%);
}

.player.right {
  right: -110px;
  top: 50%;
  transform: translateY(-50%);
}

.player.active .player-avatar {
  box-shadow: 0 0 8px #f5a623;
}

#play-area {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 440px;
  height: 320px;
}

.trick-seat {
  position: absolute;
  display: flex;
  gap: 3px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  max-width: 280px;
}

.trick-bottom {
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
}

.trick-top {
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
}

.trick-left {
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
  max-width: 200px;
}

.trick-right {
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  max-width: 200px;
}

/* 扑克牌 */
.card {
  width: 66px;
  height: 90px;
  background: #fff;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 5px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.15s;
  position: relative;
}

.card:hover {
  transform: translateY(-5px);
}

.card.selected {
  transform: translateY(-12px);
  box-shadow: 0 0 8px #f5a623;
}

.card .suit-top {
  text-align: left;
}

.card .suit-bottom {
  text-align: right;
  transform: rotate(180deg);
}

.card.red {
  color: #d32f2f;
}

.card.black {
  color: #212121;
}

.card.joker {
  color: #d32f2f;
}

.card-back {
  background: linear-gradient(135deg, #1e5799 0%, #2989d8 50%, #207cca 100%);
  border: 2px solid #fff;
}

/* 手牌区 */
#my-hand {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 10px;
  max-width: 95vw;
}

#my-hand .card {
  flex-shrink: 0;
}

/* 游戏操作 */
#game-actions {
  position: absolute;
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 20;
}

#timer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  font-weight: bold;
  color: #f5a623;
  text-shadow: 0 0 10px rgba(0,0,0,0.5);
  z-index: 5;
}

/* 聊天 */
#btn-toggle-chat {
  position: absolute;
  bottom: 15px;
  left: 15px;
}

#chat-panel {
  position: absolute;
  bottom: 55px;
  left: 10px;
  width: 260px;
  height: 200px;
  background: rgba(0,0,0,0.7);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  z-index: 30;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  font-size: 13px;
}

.chat-msg {
  margin-bottom: 6px;
  word-break: break-all;
}

.chat-msg .sender {
  color: #f5a623;
  margin-right: 5px;
}

.chat-input-area {
  display: flex;
  padding: 8px;
  gap: 5px;
}

.chat-input-area input {
  flex: 1;
  padding: 6px 10px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
}

/* 语音 */
#voice-controls {
  position: absolute;
  top: 50px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.4);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
}

#voice-status {
  color: #07c160;
}

#voice-status.muted {
  color: #999;
}

/* 快捷语 */
.quick-phrases {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 5px;
}

.quick-phrases span {
  background: rgba(255,255,255,0.15);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
}

.quick-phrases span:hover {
  background: rgba(255,255,255,0.25);
}

/* 结果弹窗 */
#game-result-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#game-result-overlay.hidden {
  display: none !important;
}

.result-card {
  background: #1a5f2a;
  border: 2px solid #f5a623;
  border-radius: 16px;
  padding: 24px 32px;
  text-align: center;
  min-width: 320px;
  max-width: 420px;
}

.result-card h2 {
  margin: 0 0 16px 0;
  font-size: 22px;
}

.result-card .win {
  color: #f5a623;
}

.result-card .lose {
  color: #e74c3c;
}

.result-card .draw {
  color: #3498db;
}

#result-details {
  font-size: 14px;
  line-height: 1.8;
  margin-bottom: 16px;
  text-align: left;
}

#result-details .detail-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

#result-details .detail-label {
  color: #aaa;
}

#result-details .detail-value {
  font-weight: bold;
}

#result-ready-status {
  font-size: 13px;
  color: #aaa;
  margin-bottom: 12px;
}

#btn-next-game {
  font-size: 16px;
  padding: 10px 40px;
}

#btn-next-game:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 横屏优化 */
@media (orientation: landscape) {
  .table {
    width: 700px;
    height: 460px;
  }

  .player.left {
    left: -130px;
  }

  .player.right {
    right: -130px;
  }

  .card {
    width: 66px;
    height: 90px;
    font-size: 14px;
  }

  #my-hand {
    bottom: 60px;
  }

  #lobby-screen {
    max-height: 100vh;
  }

  .room-list {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .room-item {
    flex: 1;
    min-width: 200px;
  }
}

/* 规则弹窗 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal.hidden {
  display: none !important;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background: #1a5f2a;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 85%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.modal-header h2 {
  font-size: 18px;
  margin: 0;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 15px 20px;
  font-size: 13px;
  line-height: 1.6;
}

.modal-body h3 {
  font-size: 15px;
  margin: 15px 0 8px;
  color: #f5a623;
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}

.modal-body th,
.modal-body td {
  padding: 6px 8px;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.modal-body th {
  background: rgba(0, 0, 0, 0.2);
  font-weight: 600;
}

.modal-body pre {
  background: rgba(0, 0, 0, 0.2);
  padding: 10px;
  border-radius: 6px;
  font-size: 12px;
  overflow-x: auto;
}

.modal-body p {
  margin: 6px 0;
}

.modal-body ul {
  margin: 6px 0 6px 20px;
}

.modal-body li {
  margin: 3px 0;
}

/* 已出牌记录 */
.history-trick {
  margin-bottom: 15px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

.history-trick-header {
  font-size: 12px;
  color: #f5a623;
  margin-bottom: 6px;
}

.history-plays {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-play {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-play-seat {
  font-size: 11px;
  min-width: 40px;
  opacity: 0.8;
}

.history-play-cards {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

#bottom-info {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 5;
}

.bottom-label {
  font-size: 12px;
  color: #f5a623;
  background: rgba(0,0,0,0.5);
  padding: 2px 8px;
  border-radius: 4px;
}

.bottom-cards {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  justify-content: center;
}

.card.unplayed {
  background: #ddd;
  color: #999;
  opacity: 0.5;
  filter: grayscale(100%);
  box-shadow: none;
}

/* 小屏幕 */
@media (max-width: 360px) {
  .card {
    width: 66px;
    height: 90px;
    font-size: 14px;
  }

  .table {
    width: 460px;
    height: 340px;
  }

  .player.partner {
    top: -40px;
  }

  .player.left {
    left: -90px;
  }

  .player.right {
    right: -90px;
  }

  #play-area {
    width: 360px;
    height: 260px;
  }

  .seat-avatar {
    width: 40px;
    height: 40px;
  }
}

/* ====== 手机横屏游戏模式：半牌+重叠 ====== */
body.mobile-game #game-screen {
  overflow: hidden;
}

body.mobile-game .game-header {
  padding: 3px 6px;
  font-size: 11px;
  gap: 4px;
}

body.mobile-game .game-header .btn {
  padding: 3px 6px;
  font-size: 10px;
}

body.mobile-game .game-info {
  gap: 6px;
}

body.mobile-game #bid-info {
  font-size: 10px;
}

body.mobile-game .table {
  width: 520px;
  height: 300px;
  top: 30px;
}

body.mobile-game .player {
  gap: 2px;
}

body.mobile-game .player-avatar {
  width: 24px;
  height: 24px;
}

body.mobile-game .player-name {
  font-size: 9px;
  max-width: 40px;
}

body.mobile-game .player-cards-count {
  font-size: 8px;
}

body.mobile-game .player.partner {
  top: -30px;
}

body.mobile-game .player.left {
  left: -70px;
}

body.mobile-game .player.right {
  right: -70px;
}

body.mobile-game #play-area {
  width: 300px;
  height: 200px;
}

body.mobile-game .trick-seat .card {
  width: 36px;
  height: 48px;
  font-size: 10px;
  padding: 2px 3px;
  border-radius: 3px;
}

body.mobile-game #my-hand {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0;
  padding: 4px 8px;
  max-width: 100vw;
  flex-wrap: nowrap;
}

body.mobile-game #my-hand .card {
  width: 36px;
  height: 48px;
  font-size: 9px;
  padding: 2px 3px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-left: -10px;
  cursor: pointer;
  transition: transform 0.1s, margin-top 0.1s;
}

body.mobile-game #my-hand .card:first-child {
  margin-left: 0;
}

body.mobile-game #my-hand .card:hover {
  transform: translateY(-3px);
}

body.mobile-game #my-hand .card.selected {
  transform: translateY(-8px);
  box-shadow: 0 0 6px #f5a623;
}

body.mobile-game #game-actions {
  bottom: 8px;
  gap: 6px;
}

body.mobile-game #game-actions .btn {
  padding: 5px 10px;
  font-size: 12px;
}

body.mobile-game #btn-toggle-chat {
  bottom: 8px;
  left: 8px;
}

body.mobile-game #chat-panel {
  bottom: 40px;
  left: 5px;
  width: 180px;
  height: 140px;
}

body.mobile-game #chat-messages {
  font-size: 11px;
}

body.mobile-game #chat-input {
  font-size: 11px;
}

body.mobile-game #voice-controls {
  top: 30px;
  right: 5px;
  padding: 3px 8px;
  font-size: 10px;
}

body.mobile-game #timer {
  font-size: 32px;
}

body.mobile-game #bottom-info {
  bottom: 5px;
}

body.mobile-game .bottom-label {
  font-size: 10px;
}

body.mobile-game .bottom-cards .card {
  width: 30px;
  height: 40px;
  font-size: 8px;
  padding: 2px;
}

body.mobile-game .result-card {
  padding: 16px 20px;
  min-width: 240px;
}

body.mobile-game .result-card h2 {
  font-size: 18px;
}

body.mobile-game #result-details {
  font-size: 12px;
}

body.mobile-game .modal-content {
  max-width: 95vw;
  max-height: 90vh;
}

body.mobile-game .modal-body {
  font-size: 12px;
}
