* { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", sans-serif;
  background: linear-gradient(135deg, #1a472a 0%, #2d5a3d 50%, #1e3d2e 100%);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  color: #e8e4d9;
  overscroll-behavior: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
.conn-status {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: #c41e3a; color: #fff; text-align: center; padding: 10px;
  font-size: 14px; font-weight: 600;
  padding-top: max(10px, env(safe-area-inset-top));
}
.conn-status.hidden { display: none !important; }
#app {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
@media (min-width: 769px) {
  #app { padding: 20px; padding-bottom: 20px; }
}

/* 大厅 */
#lobby {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
}
.lobby-card {
  background: rgba(30, 50, 40, 0.9);
  border-radius: 16px;
  padding: 40px;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  border: 2px solid rgba(200, 180, 120, 0.3);
}
.lobby-card h1 { font-size: 28px; margin-bottom: 8px; text-align: center; }
.subtitle { color: #b8b4a8; font-size: 14px; margin-bottom: 12px; text-align: center; }
.voice-hint { color: #c9a227; font-size: 12px; margin-bottom: 24px; text-align: center; }
.voice-hint.hidden { display: none !important; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 14px; color: #c8c4b8; }
.form-group input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid rgba(200,180,120,0.4);
  border-radius: 10px;
  background: rgba(20,35,28,0.8);
  color: #e8e4d9;
  font-size: 16px; /* 防止 iOS 输入时自动缩放 */
  min-height: 48px;
}
.btn-row { margin: 20px 0; }
.btn {
  padding: 14px 24px;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: #c9a227; color: #1a2e22; }
.btn-primary:hover:not(:disabled) { background: #ddb62e; transform: translateY(-1px); }
.btn-secondary { background: #4a6b52; color: #e8e4d9; width: 100%; }
.btn-secondary:hover:not(:disabled) { background: #5a7b62; }
.btn-action { background: #8b7355; color: #fff; }
.btn-action:hover { background: #9c8366; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.divider { text-align: center; margin: 20px 0; color: #888; }
.error { color: #e55; margin-top: 12px; font-size: 14px; }
.hidden { display: none !important; }

/* 房间等待 */
#roomWait {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
}
.room-card {
  background: rgba(30, 50, 40, 0.9);
  border-radius: 16px;
  padding: 40px;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  border: 2px solid rgba(200, 180, 120, 0.3);
}
.room-card h2 { margin-bottom: 16px; }
.room-mode-label { margin-left: 8px; font-size: 14px; color: #b8b4a8; }
.room-mode-label.mode-1p { color: #64b5f6; font-weight: 600; }
.room-mode-label.mode-2p { color: #7cb342; font-weight: 600; }
.room-mode-label.mode-3p { color: #ffb74d; font-weight: 600; }
.player-list {
  margin: 20px 0;
  min-height: 120px;
}
.player-item {
  padding: 10px 16px;
  background: rgba(50, 70, 55, 0.6);
  border-radius: 8px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.player-item.ready { border-left: 4px solid #c9a227; }

/* 游戏区域 */
#gameArea {
  max-width: 1000px;
  margin: 0 auto;
}
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.room-id { font-size: 15px; color: #c9a227; font-weight: 600; }
.scores {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.score-item {
  background: rgba(30, 50, 40, 0.8);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
}
.score-item.me { border: 2px solid #c9a227; }
.score-item.current-turn { border: 2px solid #228b22; background: rgba(34,139,34,0.2); }
.game-info { font-size: 14px; color: #b8b4a8; }
.game-info-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.voice-toggle {
  font-size: 14px; color: #b8b4a8; cursor: pointer; user-select: none;
  padding: 8px 12px; min-height: 44px; display: inline-flex; align-items: center;
}
.voice-toggle input { margin-right: 6px; vertical-align: middle; }

.table {
  background: linear-gradient(180deg, #2a4a35 0%, #1e3d2e 100%);
  border-radius: 20px;
  padding: 30px;
  min-height: 400px;
  position: relative;
  border: 4px solid #8b7355;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}

.opponents {
  display: flex;
  justify-content: space-around;
  margin-bottom: 8px;
  min-height: 48px;
}
.opponent-area {
  text-align: center;
}
.opponent-area .name { font-size: 10px; margin-bottom: 0; color: #b8b4a8; }
.opponent-area .opponent-score { font-size: 11px; color: #a09880; margin-bottom: 4px; }
.opponent-area .opponent-exposed {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin-bottom: 4px;
  min-height: 0;
}
.opponent-area .opponent-exposed-group {
  display: inline-flex;
  gap: 2px;
  align-items: center;
}
.opponent-area .opponent-exposed-group .exposed-label {
  font-size: 10px;
  color: #c9a227;
  margin-right: 2px;
  flex-shrink: 0;
}
.opponent-area .opponent-exposed-group .tile-mini {
  width: 11px;
  height: 14px;
  font-size: 8px;
  padding: 0;
  line-height: 14px;
}
.opponent-area .hand-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
}
.opponent-area .opponent-hand-count {
  font-size: 12px;
  color: #b8a070;
  font-weight: 500;
}
.opponent-area .tile-back {
  width: 16px;
  height: 22px;
  background: linear-gradient(135deg, #8b4513, #654321);
  border-radius: 2px;
  border: 1px solid #5a3a1a;
}

.center-area {
  text-align: center;
  margin: 12px 0;
}
.discard-piles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  min-height: 80px;
  margin-bottom: 8px;
  background: rgba(20, 35, 28, 0.5);
  border-radius: 8px;
  padding: 10px;
}
.discard-pile {
  min-height: 50px;
}
.discard-pile .pile-label { font-size: 10px; color: #c9a227; margin-bottom: 4px; }
.discard-pile .pile-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.discard-pile .tile-mini,
.pile-tiles .tile {
  width: 20px;
  height: 26px;
  font-size: 10px;
  font-weight: bold;
  padding: 0;
  line-height: 24px;
  text-shadow: 0 0 1px #fff, 0 1px 2px rgba(0,0,0,0.3);
  -webkit-font-smoothing: antialiased;
}
.last-discard { font-size: 12px; color: #ffd700; }

.my-area { margin-top: 20px; }
.my-score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.my-score { font-size: 12px; color: #b8a070; margin: 0; }
.my-area-room { font-size: 11px; color: #c9a227; font-weight: 600; }
.my-exposed {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  min-height: 50px;
}
.my-hand {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 70px;
}

/* 麻将牌 - 自己的手牌/明牌缩小 */
.my-hand .tile,
.my-exposed .tile {
  width: 44px;
  height: 58px;
  font-size: 14px;
  border-radius: 6px;
}
.my-hand .tile-unicode,
.my-exposed .tile-unicode {
  font-size: 38px;
  line-height: 1;
}
/* 麻将牌 - 基础尺寸（用于未缩放的场景） */
.tile {
  position: relative;
  width: 60px;
  height: 80px;
  background: linear-gradient(180deg, #f5f0e0 0%, #e8e0cc 100%);
  border-radius: 8px;
  border: 2px solid #c4a574;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  color: #333;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow: hidden;
}
.tile:hover { transform: translateY(-4px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.tile:active { transform: translateY(-2px) scale(0.98); }
.tile.selected { border-color: #c9a227; box-shadow: 0 0 0 3px rgba(201,162,39,0.5); transform: translateY(-4px); }
/* 刚摸到的新牌：金色描边 + 外发光 + 轻微脉动，一眼可辨 */
.tile-just-drawn {
  transform: scale(1.15);
  z-index: 5;
  border: 3px solid #ffd700 !important;
  box-shadow:
    0 0 0 2px rgba(255, 215, 0, 0.6),
    0 0 20px 4px rgba(255, 215, 0, 0.5),
    0 6px 20px rgba(0, 0, 0, 0.4);
  animation: tile-new-pulse 1.2s ease-in-out infinite;
}
.tile-just-drawn::after {
  content: '';
  display: none;
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 11px;
  font-weight: bold;
  color: #1a2e22;
  background: #ffd700;
  padding: 1px 4px;
  border-radius: 4px;
  line-height: 1.2;
  pointer-events: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
@keyframes tile-new-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.6), 0 0 20px 4px rgba(255, 215, 0, 0.5), 0 6px 20px rgba(0, 0, 0, 0.4); }
  50%  { box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.9), 0 0 28px 8px rgba(255, 215, 0, 0.6), 0 6px 20px rgba(0, 0, 0, 0.4); }
}
.tile.wan { color: #c41e3a; }
.tile.bing { color: #228b22; }
.tile.tiao { color: #1e90ff; }
.tile.feng, .tile.jian { color: #333; }
.tile.discarded { opacity: 0.9; cursor: default; }
.tile.tile-unicode {
  font-size: 52px;
  line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
/* 条子：优先 Noto 渲染，保持与万饼相同大小 */
.tile.tile-unicode.tiao {
  font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}
.tile-mini.tile-unicode.tiao, .pile-tiles .tile-unicode.tiao {
  font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}
.tile-mini.tile, .pile-tiles .tile {
  width: 40px; height: 54px; font-size: 14px; min-width: 40px;
  line-height: 52px;
  font-weight: bold;
  text-shadow: 0 0 1px #fff, 0 1px 2px rgba(0,0,0,0.2);
  -webkit-font-smoothing: antialiased;
}
.pile-tiles .tile-unicode {
  font-size: 36px;
  line-height: 50px;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
/* 弃牌区牌面缩小 */
.discard-piles .pile-tiles .tile,
.discard-piles .tile-mini,
.discard-pile .pile-tiles .tile,
.discard-pile .tile-mini {
  width: 20px;
  height: 26px;
  font-size: 10px;
  min-width: 20px;
  line-height: 24px;
}
.discard-piles .pile-tiles .tile-unicode,
.discard-pile .pile-tiles .tile-unicode {
  font-size: 22px;
  line-height: 24px;
}

.action-bar {
  margin-top: 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.action-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.turn-hint { color: #c9a227; font-size: 14px; }
.turn-hint.prompt-highlight { color: #ffd700; font-weight: bold; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.8; } }
.btn-win { background: #c41e3a !important; color: #fff !important; font-weight: bold; }
.btn-kong { background: #228b22 !important; color: #fff !important; }
.btn-pong { background: #1e90ff !important; color: #fff !important; }
.btn-highlight { background: #8b4513 !important; color: #ffd700 !important; }

.game-over {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20, 35, 28, 0.65);
  padding: 40px;
  border-radius: 16px;
  border: 3px solid rgba(201, 162, 39, 0.8);
  text-align: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}
.game-over h2 { margin-bottom: 16px; color: #c9a227; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.game-over p, .game-over .score-summary { text-shadow: 0 1px 2px rgba(0,0,0,0.4); }
.game-over .score-summary { margin: 12px 0; line-height: 1.8; }
.game-over .next-round-hint { margin: 12px 0; color: #b8b4a8; font-size: 14px; }
.game-over #btnReadyNext { margin-top: 8px; }

/* 手机端适配 - 触控优先、大按钮、易读 */
@media (max-width: 768px) {
  #app { padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); overflow-x: hidden; }
  #gameArea { padding-bottom: env(safe-area-inset-bottom); }
  .lobby-card, .room-card { padding: 24px 20px; }
  .lobby-card h1 { font-size: 24px; }
  .btn-row .btn { min-height: 52px; font-size: 15px; padding: 14px 16px; }
  .btn-row { display: flex; flex-direction: column; gap: 12px; }
  .btn-row .btn { width: 100%; }
  .room-card #btnReady { width: 100%; min-height: 52px; }
  .game-header {
    margin-bottom: 8px;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .game-info-row {
    order: -1;
    flex-shrink: 0;
    gap: 8px;
    display: flex;
    align-items: center;
  }
  .game-info { display: none; }
  .scores .score-item { padding: 4px 8px; font-size: 12px; }
  .table { padding: 12px; min-height: 200px; }
  .action-bar {
    margin-top: 8px;
    margin-bottom: 8px;
  }
  
  .opponents {
    margin-bottom: 8px;
    min-height: 56px;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .opponent-area {
    min-width: 0;
    flex: 1 1 30%;
    max-width: 120px;
    padding: 6px 4px;
    background: rgba(20, 35, 28, 0.4);
    border-radius: 8px;
    border: 1px solid rgba(201, 162, 39, 0.25);
  }
  .opponent-area .name {
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 0;
    color: #e8e0c8;
  }
  .opponent-area .opponent-score {
    font-size: 11px;
    color: #a09880;
    margin-bottom: 4px;
  }
  .opponent-area .opponent-exposed {
    gap: 6px;
    margin-bottom: 6px;
    justify-content: flex-start;
  }
  .opponent-area .opponent-exposed-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px;
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
  }
  .opponent-area .opponent-exposed-group .exposed-label {
    font-size: 11px;
    font-weight: bold;
    color: #c9a227;
    margin-right: 4px;
  }
  .opponent-area .opponent-exposed-group .tile-mini {
    width: 18px;
    height: 24px;
    font-size: 16px;
    line-height: 24px;
    min-width: 18px;
    overflow: hidden;
  }
  .opponent-area .hand-preview {
    min-height: 18px;
  }
  .opponent-area .opponent-hand-count {
    font-size: 11px;
  }
  .opponent-area .tile-back {
    width: 12px;
    height: 16px;
    border-radius: 2px;
  }
  
  .discard-piles {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    min-height: 85px;
    padding: 6px;
    margin-bottom: 6px;
  }
  .discard-pile {
    min-height: 50px;
    padding: 4px;
  }
  .discard-pile .pile-label {
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 4px;
    color: #e8e0c8;
  }
  .pile-tiles .tile, .discard-pile .tile-mini,
  .discard-piles .pile-tiles .tile, .discard-piles .tile-mini {
    width: 22px;
    height: 28px;
    min-width: 22px;
    line-height: 26px;
    overflow: hidden;
  }
  .pile-tiles .tile-unicode, .discard-pile .tile-unicode,
  .discard-piles .pile-tiles .tile-unicode {
    font-size: 24px;
    line-height: 26px;
  }
  .center-area { margin: 6px 0; }
  .last-discard { font-size: 13px; font-weight: bold; color: #ffd700; }

  .scores { gap: 4px; flex-wrap: wrap; }
  .score-item { padding: 4px 8px; font-size: 12px; }
  
  .my-area { margin-top: 10px; }
  .my-score-row { margin-bottom: 4px; }
  .my-score { font-size: 11px; }
  .my-area-room { font-size: 10px; }
  .my-exposed { margin-bottom: 8px; min-height: 44px; }
  .my-hand { min-height: 80px; gap: 4px; padding-bottom: 4px; }
  .my-hand .tile, .my-exposed .tile {
    width: 41px;
    height: 54px;
    min-width: 41px;
    border-radius: 8px;
    overflow: hidden;
  }
  .my-hand .tile-unicode, .my-exposed .tile-unicode {
    font-size: 34px;
    line-height: 1;
    max-height: 50px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
    -webkit-font-smoothing: antialiased;
  }
  .my-hand .tile:active { transform: translateY(-2px) scale(0.98); }
  
  .action-bar {
    margin-top: 8px;
    margin-bottom: 8px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .action-buttons .btn {
    min-height: 48px;
    padding: 12px 18px;
    font-size: 15px;
  }
  .turn-hint { font-size: 14px; font-weight: 600; line-height: 1.4; flex: 1 1 100%; }
  .turn-hint.prompt-highlight { font-size: 15px; }
  
  .game-over {
    left: 12px; right: 12px;
    width: auto;
    max-width: none;
    transform: translateY(-50%);
    padding: 24px 20px;
    max-height: 85vh;
    overflow-y: auto;
  }
}
