/* ============================================================
   Mahjong Game - style.css
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --felt:        #1a5c1a;
  --felt-dark:   #144a14;
  --felt-light:  #226222;
  --tile-bg:     #f5f0e0;
  --tile-border: #c8b87a;
  --tile-shadow: rgba(0,0,0,0.45);
  --tile-selected: #ffe066;
  --tile-back:   #2a4a8a;
  --tile-back-border: #1a3060;
  --text-light:  #f0ead6;
  --text-muted:  #9ecf9e;
  --accent:      #d4a017;
  --error:       #e05050;
  --success:     #50c050;
  --btn-primary: #c8960c;
  --btn-hover:   #e0aa10;
  --panel-bg:    rgba(0,0,0,0.35);
  --border-radius-tile: 4px;
}

html { touch-action: manipulation; }

html, body {
  width: 100%;
  height: 100%;
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  background: var(--felt-dark);
  color: var(--text-light);
  overflow-x: hidden;
}

/* ============================================================
   LOBBY PAGE
   ============================================================ */
.lobby-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

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

.lobby-header h1 {
  font-size: 2.4rem;
  color: var(--accent);
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
  letter-spacing: 2px;
}

.lobby-header p {
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.player-info-bar {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 0.7rem 1.2rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.player-name-field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 200px;
}

.player-name-input {
  flex: 1;
  max-width: 280px;
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  font-size: 0.95rem;
}

.player-name-input:focus {
  outline: none;
  border-color: var(--accent);
}

.player-id-hint {
  font-size: 0.8rem;
  opacity: 0.85;
}

.player-info-bar span.pid {
  color: var(--accent);
  font-weight: bold;
  word-break: break-all;
}

.lobby-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.lobby-actions h2 {
  font-size: 1.3rem;
  color: var(--text-light);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 0.55rem 1.2rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  white-space: nowrap;
}

.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--btn-primary); color: #1a1a00; }
.btn-primary:hover:not(:disabled) { background: var(--btn-hover); }

.btn-secondary { background: rgba(255,255,255,0.15); color: var(--text-light); border: 1px solid rgba(255,255,255,0.25); }
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,0.25); }

.btn-danger    { background: #a03030; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c04040; }

.btn-success   { background: #306030; color: #d0ffd0; }
.btn-success:hover:not(:disabled) { background: #407040; }

.btn-info      { background: #2060a0; color: #d0e8ff; }
.btn-info:hover:not(:disabled) { background: #3070c0; }

.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.82rem; }

/* ---------- Rooms Table ---------- */
.rooms-table-wrap {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  overflow: hidden;
}

.rooms-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.rooms-table th {
  background: rgba(0,0,0,0.4);
  color: var(--accent);
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.rooms-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: var(--text-light);
}

.rooms-table tr:last-child td { border-bottom: none; }

.rooms-table tr:hover td { background: rgba(255,255,255,0.05); }

.rooms-table .status-waiting  { color: #80d080; }
.rooms-table .status-playing  { color: #d0a040; }
.rooms-table .status-finished { color: #a08080; }

.no-rooms {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
  font-style: italic;
}

.refresh-indicator {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  padding: 0.3rem 0.6rem;
}

/* ============================================================
   GAME PAGE - Overall Layout
   ============================================================ */
.game-page {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.5);
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  z-index: 10;
}

.game-topbar h1 {
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: 1px;
}

.game-topbar .back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.game-topbar .back-link:hover { color: var(--text-light); }

.room-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- Main Board ---------- */
.board {
  display: grid;
  grid-template-areas:
    ". top ."
    "left center right"
    ". bottom .";
  grid-template-columns: 200px 1fr 200px;
  grid-template-rows: 150px 1fr 150px;
  gap: 6px;
  padding: 6px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---------- Player Areas ---------- */
.player-area {
  background: var(--panel-bg);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
  position: relative;
  min-height: 0;
  overflow: hidden;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.player-area.active-turn {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(212,160,23,0.4);
}

.player-area.my-area {
  border-color: #4a9a4a;
  background: rgba(0,60,0,0.4);
}

.player-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-align: center;
  font-weight: 600;
}

.player-label .player-name {
  color: var(--text-light);
  display: block;
  font-size: 0.8rem;
}

.player-label .player-score {
  color: var(--accent);
}

.dealer-badge {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 5px;
  background: #c8960c;
  color: #1a1a00;
  font-size: 0.72em;
  font-weight: 900;
  border-radius: 3px;
  vertical-align: middle;
  letter-spacing: 0.5px;
}

/* ---------- Area positions ---------- */
.area-top    { grid-area: top; }
.area-left   { grid-area: left; flex-direction: row; }
.area-right  { grid-area: right; flex-direction: row; }
.area-bottom { grid-area: bottom; }
.area-center { grid-area: center; }

/* ---------- Center Table ---------- */
.center-table {
  background: var(--felt);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 8px;
  gap: 6px;
  min-height: 0;
  overflow: hidden;
}

.wall-counter {
  text-align: center;
  font-size: 1rem;
  color: var(--text-muted);
}

.wall-counter span {
  color: var(--text-light);
  font-weight: bold;
  font-size: 1.2rem;
}

.discards-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
  min-height: 0;
  overflow: hidden;
}

.discard-pile {
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 4px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0;
  overflow: hidden;
  min-height: 0;
}
.discard-pile .tile { margin-right: -4px; }
.discard-pile .tile:last-child { margin-right: 0; }

.discard-pile-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  width: 100%;
  text-align: center;
  margin-bottom: 2px;
}

.last-discard-highlight {
  text-align: center;
  padding: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 30px;
}

.last-discard-highlight .tile {
  display: inline-block;
  vertical-align: middle;
}

/* Center table: last discarded tile (same size as default 36×50) */
#last-discard .tile {
  width: 36px;
  height: 50px;
}

/* ---------- TILES - Cangjie6 Oblique SVG Images ---------- */
/*
 * Tile images are Wikimedia Commons Cangjie6 oblique illustrations.
 * They render their own 3D tile body, edges, and artwork.
 * CSS only handles sizing, layout, hover/selected effects.
 */
.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 50px;
  overflow: visible; /* allow oblique SVG to render outside bounds */
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  cursor: default;
  user-select: none;
  flex-shrink: 0;
  transition: transform 0.12s, filter 0.12s;
  position: relative;
}

/* Image fills the tile span */
.tile-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

/* Text fallback (used when image is missing) */
.tile-main {
  font-size: 1.1em;
  line-height: 1;
  font-weight: 900;
  font-family: 'Noto Serif SC', 'Source Han Serif CN', 'SimSun', serif;
  color: #222;
}

/* Face-down tile — diagonal stripe pattern (no image) */
.tile-back {
  background:
    repeating-linear-gradient(
      45deg,
      #1e3a7a,
      #1e3a7a 4px,
      #2a52a8 4px,
      #2a52a8 9px
    );
  border: 2px solid #4a6ad0;
  border-right-color:  #0e2050;
  border-bottom-color: #0e2050;
  border-width: 2px 2px 3px 2px;
  border-radius: 3px;
  cursor: default;
}

/* Tile in discard pile (smaller) */
.discard-pile .tile {
  width: 26px;
  height: 36px;
  /* Discard pile tiles are static — no transform/filter transitions needed.
     The base .tile rule has transition:transform+filter which would fire
     whenever a tile is appended, causing flicker on each discard. */
  transition: none;
}

/* Tile in hand (bottom area) */
.my-hand .tile {
  width: 44px;
  height: 62px;
  cursor: pointer;
  /* Negative margin compensates for the transparent perspective edges
     of the Cangjie6 oblique SVG tiles, making them visually flush. */
  margin-right: -6px;
}
/* Last tile in hand: restore margin so the row doesn't over-extend */
.my-hand .tile:last-child {
  margin-right: 0;
}

/* Hover effect only on devices that support hover (not touch) */
@media (hover: hover) {
  .my-hand .tile:hover {
    transform: translateY(-6px);
    filter: drop-shadow(3px 8px 8px rgba(0,0,0,0.55));
  }
}

/* Selected tile: lift + gold glow.
   position:relative + z-index ensures it renders above the player label
   and other sibling elements so the drop-shadow glow is never covered. */
.my-hand .tile.selected {
  position: relative;
  z-index: 50;
  transform: translateY(-8px);
  filter: drop-shadow(0 0 3px rgba(255,255,255,0.9))
          drop-shadow(0 0 7px rgba(255,215,0,1))
          drop-shadow(0 0 14px rgba(255,175,0,0.7))
          drop-shadow(2px 8px 8px rgba(0,0,0,0.55));
}

/* Opponent hand tiles */
.opponent-hand .tile {
  width: 24px;
  height: 33px;
}

/* Claim overlay tile (larger) */
.claim-tile-display .tile {
  width: 70px;
  height: 98px;
}

/* Meld group */
.meld-group {
  display: inline-flex;
  gap: 0;
  margin-right: 4px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 2px;
  background: rgba(0,0,0,0.2);
}

/* ---------- My Hand Area ---------- */
.my-hand-area {
  grid-area: bottom;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: rgba(0,60,0,0.4);
  border: 2px solid #4a9a4a;
  border-radius: 8px;
}

.my-hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0;
  max-height: 80px;
  overflow: visible;   /* allow selected tile to rise above the container edge */
  padding: 14px 4px 4px; /* top padding absorbs the selection lift + buffer */
}

.my-melds {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

/* ---------- Opponent Hand Display ---------- */
.opponent-hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  max-width: 100%;
}

/* Left/Right player - vertical orientation */
.area-left .opponent-hand,
.area-right .opponent-hand {
  flex-direction: column;
  max-height: 100%;
  flex-wrap: nowrap;
  overflow: hidden;
}

/* ---------- Action Buttons ---------- */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.5);
  padding: 0.5rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.action-bar .btn {
  min-width: 80px;
}

#btn-discard  { background: #8b3030; color: #ffd0d0; }
#btn-discard:hover:not(:disabled) { background: #b04040; }
#btn-pung     { background: #2060a0; color: #d0e8ff; }
#btn-pung:hover:not(:disabled) { background: #3070c0; }
#btn-chow     { background: #207050; color: #d0ffd0; }
#btn-chow:hover:not(:disabled) { background: #308060; }
#btn-kong     { background: #604090; color: #e8d0ff; }
#btn-kong:hover:not(:disabled) { background: #7050a0; }
#btn-win      { background: #806010; color: #ffe8a0; }
#btn-win:hover:not(:disabled) { background: #a07818; }
#btn-skip     { background: #504040; color: #e0d0d0; }
#btn-skip:hover:not(:disabled) { background: #705050; }
#btn-start    { background: #306030; color: #d0ffd0; border: 2px solid #50a050; }
#btn-start:hover:not(:disabled) { background: #407040; }

/* ---------- Status Bar ---------- */
.status-bar {
  text-align: center;
  padding: 0.35rem 1rem;
  font-size: 0.85rem;
  background: rgba(0,0,0,0.4);
  border-top: 1px solid rgba(255,255,255,0.08);
  min-height: 2rem;
  transition: background 0.3s;
}

.status-bar.error   { background: rgba(140,0,0,0.5); color: #ffaaaa; }
.status-bar.success { background: rgba(0,80,0,0.5);  color: #aaffaa; }
.status-bar.info    { background: rgba(0,40,100,0.5); color: #aaccff; }

/* ---------- Claim Window Overlay ---------- */
.claim-overlay {
  position: fixed;
  inset: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none; /* let board remain interactive underneath */
}
.claim-overlay > * {
  pointer-events: auto; /* but the modal box itself still captures clicks */
}

.claim-overlay.hidden { display: none; }
/* Fade-in when overlay becomes visible (display:none→flex is not animatable,
   so we animate the box-shadow content instead via opacity on the inner box). */
.claim-overlay:not(.hidden) { animation: overlayFadeIn 0.15s ease; }
@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.claim-box {
  background: var(--felt-dark);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  min-width: 300px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.8), 0 0 0 1px rgba(0,0,0,0.4);
  /* 全局安全网：内容超出屏高时允许滚动 */
  max-height: 92vh;
  overflow-y: auto;
}

.claim-box h3 {
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
}

/* Countdown bar */
.claim-countdown-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: color 0.3s;
}

.claim-countdown {
  display: inline-block;
  min-width: 2ch;
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--accent);
  transition: color 0.3s;
}

.claim-countdown-bar.urgent {
  color: #ff9944;
}

.claim-countdown-bar.urgent .claim-countdown {
  color: #ff4444;
  animation: pulse-countdown 1s ease-in-out infinite;
}

@keyframes pulse-countdown {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.25); }
}

.claim-tile-display {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.claim-tile-display .tile {
  width: 52px;
  height: 72px;
  font-size: 1rem;
}

.claim-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── 手机端声索弹窗：竖横屏通用紧凑布局 ────────────────────
   目标：整个弹窗高度 ≤ 200px，无需滚动即可看到所有按钮。
   策略：
   1. 删除冗余的 h3 标题（"Claim Tile?" 明显无需说明）
   2. 删除 "Tile: xxx" 文字段落（牌面图已能表达）
   3. 牌面图 + 倒计时 并排显示（节省 ~60px 高度）
   4. 缩小所有字号、间距、按钮高度
   ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .claim-box {
    /* 紧凑 flex 列，子元素均匀间距 */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem;
    min-width: unset;
    width: min(96vw, 360px);
    max-height: 88vh;
    overflow-y: auto;
  }

  /* h3 "Claim Tile?" — 全宽占一行，但缩小；可以用 display:none 彻底隐藏 */
  .claim-box h3 {
    width: 100%;
    font-size: 0.9rem;
    margin: 0;
    display: none;       /* 去掉标题，省出一行高度 */
  }

  /* 倒计时栏：与牌面图并排（保持 row 方向，避免"s"换行）
     隐藏冗长的"自动跳过 / Auto-skip in"文字，只保留数字 + "s" */
  .claim-countdown-bar {
    flex: 1;
    flex-direction: row;   /* ← 保持横向，消除"s"换行问题 */
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    margin: 0;
    font-size: 0.72rem;
    gap: 2px;
    min-width: 60px;
  }
  /* 隐藏长标签"自动跳过 / Auto-skip in"（第一个 label span），保留"s" */
  .claim-countdown-bar .claim-countdown-label:first-child { display: none; }

  /* 倒计时数字缩小 */
  .claim-countdown { font-size: 1.1rem; }

  /* 牌面图：不再独占一行，固定宽度与倒计时并排 */
  .claim-tile-display {
    flex: 0 0 auto;
    margin: 0;
  }
  .claim-tile-display .tile {
    width: 40px !important;
    height: 56px !important;
  }
  .claim-tile-display .tile .tile-img {
    width: 40px !important;
    height: 56px !important;
  }

  /* "Tile: xxx" 文字段落 — 隐藏（牌面图已表达） */
  .claim-box > p { display: none; }

  /* 操作按钮区：全宽，按钮稍小以容纳多口吃牌 */
  .claim-actions {
    width: 100%;
    gap: 6px;
    justify-content: center;
  }
  .claim-actions .btn {
    min-height: 38px;
    min-width: 60px;
    padding: 0.25rem 0.55rem;
    font-size: 0.82rem;
    touch-action: manipulation;
  }

  /* 倒计时条紧凑 */
  .claim-countdown-bar { padding: 0; }

  /* ── 游戏结束弹窗按钮（竖屏手机）──────────────────────────
     三个按钮（Close / Play Again 再来一局 / Back to Lobby）在
     345px 内容宽里横排放不下，改为纵向堆叠，各自全宽。 */
  .modal-box {
    padding: 1.2rem 1rem;
    width: min(96vw, 380px);
  }
  .modal-box h2 { font-size: 1.3rem; }
  .modal-box .winner-name { font-size: 1rem; }
  .modal-actions {
    flex-direction: column;
    gap: 8px;
    margin-top: 1rem;
  }
  .modal-actions .btn {
    width: 100%;
    padding: 0.55rem 1rem;
    font-size: 0.88rem;
    touch-action: manipulation;
  }
}

/* ---------- Game Over Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
}
.modal-overlay > * {
  pointer-events: auto;
}

.modal-overlay.hidden { display: none; }
.modal-overlay:not(.hidden) { animation: overlayFadeIn 0.2s ease; }

.modal-box {
  background: var(--felt-dark);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 2.5rem;
  text-align: center;
  max-width: 500px;
  width: 92%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.8), 0 0 0 1px rgba(0,0,0,0.4);
}

.modal-box h2 {
  color: var(--accent);
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}

.modal-box .winner-name {
  font-size: 1.2rem;
  color: var(--text-light);
  margin-bottom: 1rem;
}

.scores-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.scores-table th, .scores-table td {
  padding: 0.4rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.scores-table th { color: var(--text-muted); font-size: 0.85rem; }
.scores-table td { color: var(--text-light); }
.scores-table tr.winner-row td { color: #ffd700; font-weight: bold; }
.scores-table td.chip-gain  { color: #4caf50; font-weight: bold; }
.scores-table td.chip-loss  { color: #f44336; }
.scores-table td.chip-zero  { color: var(--text-muted); }

/* ---------- End-game winning tile highlight ---------- */
.tile.tile-winning {
  outline: 2px solid #f0c040;
  outline-offset: 2px;
  filter: drop-shadow(0 0 6px rgba(240, 192, 64, 0.95))
          drop-shadow(0 0 2px rgba(240, 192, 64, 0.7));
  position: relative;
  z-index: 1;
}

/* ---------- Han Breakdown Table ---------- */
.han-section {
  margin: 0.8rem 0 1rem;
  text-align: left;
}
.han-section.hidden { display: none; }

.han-section-title {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
}

.han-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.han-table td {
  padding: 0.28rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: var(--text-light);
}

.han-table td:last-child {
  text-align: right;
  font-weight: 700;
  color: #f0d060;
  min-width: 3ch;
}

.han-table tfoot .han-total-row td {
  border-top: 1px solid rgba(255,255,255,0.2);
  border-bottom: none;
  padding-top: 0.45rem;
  font-weight: 900;
  color: var(--accent);
}

/* ---------- New-game deal transition ---------- */
/* Applied briefly when a new hand is dealt (dealer rotation / restart).
   Fades the board out, then tile-by-tile dealing animation plays. */
.board-wrapper {
  transition: opacity 0.15s ease;
}
.board-wrapper.board-dealing {
  opacity: 0;
  transition: none; /* instant dim so dealing starts from invisible */
}

/* ── Deal-in keyframes (four player directions) ── */
@keyframes deal-from-bottom {
  0%   { opacity: 0; transform: translateY(55px) scale(0.65) rotateX(70deg); }
  60%  { opacity: 1; transform: translateY(-5px) scale(1.08) rotateX(0deg); }
  100% { opacity: 1; transform: translateY(0)   scale(1)    rotateX(0deg); }
}
@keyframes deal-from-top {
  0%   { opacity: 0; transform: translateY(-45px) scale(0.65); }
  60%  { opacity: 1; transform: translateY(4px)   scale(1.08); }
  100% { opacity: 1; transform: translateY(0)     scale(1); }
}
@keyframes deal-from-left {
  0%   { opacity: 0; transform: translateX(-45px) scale(0.65); }
  60%  { opacity: 1; transform: translateX(4px)   scale(1.08); }
  100% { opacity: 1; transform: translateX(0)     scale(1); }
}
@keyframes deal-from-right {
  0%   { opacity: 0; transform: translateX(45px) scale(0.65); }
  60%  { opacity: 1; transform: translateX(-4px) scale(1.08); }
  100% { opacity: 1; transform: translateX(0)    scale(1); }
}

.tile.deal-in-bottom {
  animation: deal-from-bottom 0.38s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.tile.deal-in-top {
  animation: deal-from-top    0.30s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.tile.deal-in-left {
  animation: deal-from-left   0.30s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.tile.deal-in-right {
  animation: deal-from-right  0.30s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* Shimmer on the center table when dealing starts */
@keyframes deal-shimmer {
  0%   { box-shadow: 0 0 0   0   rgba(255,215,0,0); }
  40%  { box-shadow: 0 0 28px 8px rgba(255,215,0,0.55); }
  100% { box-shadow: 0 0 0   0   rgba(255,215,0,0); }
}
.center-table.dealing-shimmer {
  animation: deal-shimmer 0.7s ease-out both;
}

/* ---------- Speech toggle button ---------- */
#btn-speech {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text-light);
  padding: 0.25rem 0.55rem;
  font-size: 1.05rem;
  line-height: 1;
  min-width: unset;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
#btn-speech:hover { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.35); }
#btn-speech:active { transform: scale(0.94); }
#btn-speech.muted { opacity: 0.45; }

/* ---------- Modal Actions ---------- */
.modal-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ---------- Connection Status ---------- */
.conn-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  background: #888;
}

.conn-indicator.connected    { background: #50c050; }
.conn-indicator.disconnected { background: #e05050; }
.conn-indicator.connecting   { background: #d0a030; animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

/* ---------- Responsive adjustments ---------- */
@media (max-width: 1200px) {
  .board {
    grid-template-columns: 160px 1fr 160px;
    grid-template-rows: 130px 1fr 130px;
  }
}

@media (max-width: 900px) {
  .board {
    grid-template-columns: 120px 1fr 120px;
    grid-template-rows: 110px 1fr 110px;
  }
  .my-hand .tile {
    width: 36px;
    height: 52px;
  }
  .my-hand .tile .tile-main { font-size: 1.3em; }
  .my-hand .tile .tile-sub  { font-size: 0.55em; }
}

/* Utility */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.flex-center { display: flex; align-items: center; justify-content: center; }

/* ============================================================
   MOBILE RESPONSIVE - max-width: 600px
   ============================================================ */
@media (max-width: 600px) {
  /* ── Fix 1: 隐藏顶栏 Room/Player UUID，腾出空间给"← 返回大厅"按钮 ── */
  #room-info { display: none; }
  #topbar h1 { font-size: 0.85rem; letter-spacing: 0; }

  /* ── Fix 2: 侧边栏（70px）放不下玩家标签，直接隐藏，保留手牌显示 ── */
  #area-left .player-label,
  #area-right .player-label { display: none; }

  /* ── Fix 4: 底部 grid row 用 auto 自适应内容高度，避免手牌溢出进 action-bar ── */
  .board-wrapper {
    grid-template-columns: 70px 1fr 70px;
    grid-template-rows: auto 1fr auto; /* 原 90px 1fr 90px → auto 让内容定高 */
  }

  /* Compact player areas */
  .player-area { padding: 3px; }

  /* Topbar compact */
  #topbar { padding: 4px 8px; font-size: 0.8rem; }
  #status-bar { padding: 4px 8px; font-size: 0.8rem; }

  /* ── Fix 5: action-bar z-index 兜底，确保按钮始终在手牌之上 ── */
  #action-bar {
    gap: 4px;
    padding: 4px 4px 6px;
    flex-wrap: wrap;
    position: relative;
    z-index: 10;
  }
  #action-bar .btn {
    min-height: 44px;
    min-width: 72px;
    font-size: 0.85rem;
    padding: 0.5rem 0.7rem;
    touch-action: manipulation;
  }

  /* Hand area: horizontal scroll, allow tile lift */
  .my-hand {
    overflow-x: auto;
    overflow-y: visible;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
    gap: 2px;
  }

  /* Smaller hand tiles on mobile */
  .my-hand .tile {
    width: 32px !important;
    height: 46px !important;
  }
  .my-hand .tile .tile-img {
    width: 32px !important;
    height: 46px !important;
  }

  /* Reduced lift for selected tile on mobile */
  .my-hand .tile.selected {
    transform: translateY(-6px);
  }

  /* Allow selected tile to overflow bottom area */
  #area-bottom {
    overflow: visible;
  }

  /* ── Fix 3: 我的副露牌（my-melds）手机端统一尺寸，与手牌协调 ── */
  #my-melds .tile {
    width: 28px !important;
    height: 40px !important;
  }
  #my-melds .tile .tile-img {
    width: 28px !important;
    height: 40px !important;
  }

  /* Smaller discard tiles */
  .discard-pile .tile {
    width: 20px !important;
    height: 28px !important;
  }

  /* 声索弹窗在 600px 宽度断点的旧规则已迁移至上方 @media(max-width:900px) 统一处理 */

  /* ── 大厅页竖屏适配 ────────────────────────────────────── */
  .lobby-container {
    padding: 1rem 0.5rem;
  }
  .lobby-header h1 { font-size: 1.4rem; letter-spacing: 0; }
  .lobby-header p  { font-size: 0.8rem; }

  /* Player ID bar：UUID 截断，不撑开页面 */
  .player-info-bar {
    padding: 0.5rem 0.8rem;
    gap: 0.5rem;
    font-size: 0.78rem;
    flex-wrap: wrap;
  }
  .player-info-bar span.pid {
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.7rem;
  }

  /* Create Room 按钮与标题同行 */
  .lobby-actions { flex-wrap: wrap; gap: 0.5rem; }
  .lobby-actions h2 { font-size: 1rem; }

  /* 房间表格：允许横滑 + 缩小字体和内边距 */
  .rooms-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .rooms-table { font-size: 0.78rem; }
  .rooms-table th { padding: 0.5rem 0.6rem; font-size: 0.72rem; }
  .rooms-table td { padding: 0.45rem 0.6rem; }
  /* 按钮在 Action 列紧凑 */
  .rooms-table .btn { padding: 0.25rem 0.6rem; font-size: 0.75rem; }
}
