/* =========================================================
   四人麻將大賽 頁面樣式
   （按鈕、手牌、結算等共用元件在 shared/table.css）
   ========================================================= */

/* ---------------- 入口：選擇對戰方式 ---------------- */
.entry {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top)) 18px 20px;
}
.entry[hidden] { display: none; }
.entry-box {
  width: 100%;
  max-width: 440px;
  padding: 22px 20px 26px;
  border-radius: 22px;
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.18));
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  animation: modal-in 0.35s ease-out;
}
.entry-back { margin: 0 0 6px; }
.entry-title { text-align: center; margin-bottom: 18px; }
.entry-emoji { font-size: 44px; }
.entry-title h1 { margin: 4px 0; font-size: 28px; letter-spacing: 3px; }
.entry-title p { margin: 0; color: var(--text-dim); }
.entry-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
  padding: 16px;
  border-radius: 16px;
  border: 2px solid rgba(244, 201, 93, 0.6);
  background: rgba(244, 201, 93, 0.12);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}
.entry-card:active { transform: scale(0.98); }
.entry-card.online { border-color: rgba(120, 190, 255, 0.5); background: rgba(80, 150, 230, 0.12); }
.entry-card b { display: block; font-size: 18px; }
.entry-card small { color: var(--text-dim); font-size: 13px; }
.entry-icon { font-size: 34px; }
.entry-card .go { margin-left: auto; font-size: 28px; opacity: 0.6; }
.soon {
  font-style: normal;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #2f6fc4;
  color: #fff;
  vertical-align: middle;
}

/* ---------------- 選單：對手介紹 ---------------- */
.rivals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.rival {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  text-align: center;
}
.rival .avatar { font-size: 28px; }
.rival small { font-size: 11px; color: var(--text-dim); line-height: 1.35; }

/* ---------------- 好友房間 ---------------- */
.room[hidden], #room[hidden] { display: none; }
.room-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  margin-bottom: 16px;
}
.room-tab {
  border: 0;
  padding: 10px;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.room-tab[aria-selected="true"] { background: var(--gold); color: #3a2a00; }
.room-panel[hidden] { display: none; }
.room-hint { color: var(--text-dim); text-align: center; }
.room-code-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px;
  border-radius: 16px;
  background: #fffaf0;
  color: #1c2b5a;
  margin-bottom: 16px;
}
.room-code {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 6px;
  font-variant-numeric: tabular-nums;
}
.room-seats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.room-seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  border-radius: 14px;
  border: 2px dashed rgba(255, 255, 255, 0.25);
  color: var(--text-dim);
  font-size: 13px;
}
.room-seat.filled { border: 2px solid var(--gold); color: var(--text); background: rgba(244, 201, 93, 0.1); }
.room-seat span { font-size: 26px; min-height: 30px; }
.room-seat small {
  padding: 0 8px;
  border-radius: 6px;
  background: #fffaf0;
  color: #1c2b5a;
  font-weight: 800;
}
.wait-dots { display: inline-flex; gap: 5px; align-items: center; }
.wait-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: dot-bounce 1.2s infinite ease-in-out;
}
.wait-dots i:nth-child(2) { animation-delay: 0.15s; }
.wait-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce { 40% { transform: translateY(-6px); opacity: 1; } 0%, 80%, 100% { opacity: 0.4; } }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid rgba(255, 255, 255, 0.3); box-shadow: none; margin-top: 10px; }
.code-inputs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 8px;
}
.code-inputs input {
  width: 44px;
  height: 56px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  background: #fffaf0;
  color: #1c2b5a;
  font-size: 26px;
  font-weight: 800;
  text-align: center;
}
.code-inputs input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(244, 201, 93, 0.35); }
.join-msg { min-height: 22px; text-align: center; color: #ffd27a; }

/* 暱稱、房間選項、提示 */
.nick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-weight: 700;
}
.nick-row span { white-space: nowrap; }
.nick-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  background: #fffaf0;
  color: #1c2b5a;
  font-family: inherit;
  font-size: 16px; /* 16px 以上 iPhone 才不會自動放大畫面 */
  font-weight: 700;
}
.nick-row input:focus { outline: none; border-color: var(--gold); }
.room-options { margin-bottom: 14px; }
.room-note { font-size: 13px; color: var(--text-dim); text-align: center; line-height: 1.5; margin: 10px 0 0; }
.room-code-box.small { padding: 10px; }
.room-code-box.small .room-code { font-size: 28px; }
.room-seat.me b::after { content: "（你）"; font-weight: 400; color: var(--text-dim); }
/* ---------------- 對局：四人牌桌 ---------------- */
.board4 {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--side-w, 64px) 1fr var(--side-w, 64px);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top top" "left center right";
  gap: 6px;
  padding: 6px;
  overflow: hidden;
}
.seat4 {
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.15);
  border: 2px solid transparent;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.seat4.active { border-color: rgba(244, 201, 93, 0.8); box-shadow: 0 0 14px rgba(244, 201, 93, 0.35); }
.seat-top { grid-area: top; padding: 4px 8px; display: flex; flex-direction: column; gap: 3px; }
.seat-left { grid-area: left; }
.seat-right { grid-area: right; }
.count {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}
.seat4 .pts { color: var(--text-dim); }
.seat4 .pts b { color: var(--gold); font-variant-numeric: tabular-nums; }
.seat-top .pts { margin-left: auto; }

/* 上方對家的牌背 */
.seat-top .backs {
  display: flex;
  justify-content: center;
  gap: 1px;
  --tile-w: var(--back-w, 16px);
  --tile-h: var(--back-h, 21px);
}
.backs.revealed { flex-wrap: wrap; }

/* 左右兩家：直立排列 */
.seat-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 3px;
  font-size: 12px;
  text-align: center;
  overflow: hidden;
}
.seat-side .avatar { font-size: 22px; }
.seat-side .nm { font-size: 13px; }
.seat-side .backs {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0;
}
.seat-side .backs.revealed {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  --tile-w: var(--tiny-w, 16px);
  --tile-h: var(--tiny-h, 21px);
}
.side-back {
  width: calc(var(--side-w, 64px) * 0.42);
  height: 7px;
  border-radius: 2px;
  background: linear-gradient(90deg, #f3e8cc 0 22%, #3a9a68 22%);
  box-shadow: 1px 1px 0 #1e6b45;
}
.seat-left .side-back { background: linear-gradient(270deg, #f3e8cc 0 22%, #3a9a68 22%); }

/* 副露、花牌：小牌 */
.seat4 .melds, .seat4 .flowers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  --tile-w: var(--tiny-w, 16px);
  --tile-h: var(--tiny-h, 21px);
}
.seat4 .flowers { gap: 1px; }
.seat-top .meld-row { justify-content: center; }

/* ---------------- 中央：牌河 + 羅盤 ---------------- */
.center4 {
  grid-area: center;
  min-height: 0;
  display: grid;
  grid-template-columns: calc(var(--rv-w, 20px) * 2 + 6px) 1fr calc(var(--rv-w, 20px) * 2 + 6px);
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "rt rt rt" "rl cp rr" "rb rb rb";
  gap: 4px;
  padding: 6px;
  border-radius: 16px;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.07), rgba(0, 0, 0, 0.18));
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.06);
}
.river4 {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 2px;
  min-height: calc(var(--rv-h, 27px) + 4px);
  overflow: hidden;
  --tile-w: var(--rv-w, 20px);
  --tile-h: var(--rv-h, 27px);
}
.river-top { grid-area: rt; justify-content: center; align-content: flex-end; min-height: calc(var(--rv-h, 27px) * 2 + 6px); }
.river-bottom { grid-area: rb; justify-content: center; min-height: calc(var(--rv-h, 27px) * 2 + 6px); }
.river-left { grid-area: rl; justify-content: flex-start; }
.river-right { grid-area: rr; justify-content: flex-end; }
.river4 .mj-tile.last {
  outline: 2px solid #ffd54a;
  outline-offset: 1px;
  animation: last-pulse 1s ease-in-out infinite alternate;
}

/* 羅盤：顯示四家門風、輪到誰、圈風、剩餘牌數、骰子 */
.compass {
  grid-area: cp;
  align-self: center;
  justify-self: center;
  position: relative;
  width: min(100%, 170px);
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  background: linear-gradient(160deg, #134d33, #0b3424);
  border: 2px solid rgba(244, 201, 93, 0.45);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.5), 0 4px 10px rgba(0, 0, 0, 0.3);
}
.cw {
  position: absolute;
  width: 22px;
  height: 22px;
  line-height: 22px;
  font-size: 13px;
  text-align: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-dim);
  font-family: "Noto Serif TC", "PMingLiU", serif;
  font-weight: 800;
  transition: all 0.3s;
}
.cw-bottom { bottom: 4px; left: 50%; transform: translateX(-50%); }
.cw-top { top: 4px; left: 50%; transform: translateX(-50%); }
.cw-left { left: 4px; top: 50%; transform: translateY(-50%); }
.cw-right { right: 4px; top: 50%; transform: translateY(-50%); }
.cw.dealer { box-shadow: 0 0 0 2px #c0281c; }
.cw.turn { background: var(--gold); color: #3a2a00; box-shadow: 0 0 12px rgba(244, 201, 93, 0.9); }
.compass-mid {
  position: absolute;
  inset: 27px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.15;
  white-space: nowrap;
}
.compass-mid b { color: var(--gold); font-size: 13px; }
.compass-mid .wall { color: #fff; font-weight: 700; }

/* 骰子 */
.dice { display: flex; gap: 3px; margin: 2px 0; }
.die {
  width: 14px;
  height: 14px;
  padding: 2px;
  border-radius: 4px;
  background: #fffaf0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  box-shadow: 1px 1px 0 #bfa972;
}
.die i { display: block; }
.die i.pip { border-radius: 50%; background: #1c2b5a; margin: 0.5px; }
.die.red i.pip { background: #c0281c; }
.dice.rolling .die { animation: dice-roll 0.9s ease-out; }
.dice.rolling .die:nth-child(2) { animation-delay: 0.08s; }
.dice.rolling .die:nth-child(3) { animation-delay: 0.16s; }
@keyframes dice-roll {
  0% { transform: translateY(-14px) rotate(0); }
  30% { transform: translateY(2px) rotate(220deg); }
  55% { transform: translateY(-5px) rotate(300deg); }
  80% { transform: translateY(0) rotate(350deg); }
  100% { transform: rotate(360deg); }
}

/* ---------------- 下方：你的座位 ---------------- */
.seat-me {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  margin: 4px 6px 0;
  padding: 4px 8px;
  font-size: 13px;
}
.seat-me .avatar { font-size: 18px; }
.seat-me .pts { margin-left: auto; }
.seat-me .melds, .seat-me .flowers {
  justify-content: flex-start;
  --tile-w: var(--small-w, 24px);
  --tile-h: var(--small-h, 32px);
}
.turn-line {
  min-height: 18px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
}
.claim-timer {
  height: 4px;
  margin: 0 12px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
.claim-timer[hidden] { display: none; }
.claim-timer i { display: block; height: 100%; background: var(--gold); transform-origin: left; }
@keyframes claim-count { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* 喊牌大字：出現在喊牌那一家的位置 */
.announce.pos-0 { top: 62%; left: 50%; }
.announce.pos-1 { top: 42%; left: 74%; }
.announce.pos-2 { top: 22%; left: 50%; }
.announce.pos-3 { top: 42%; left: 26%; }

/* ---------------- 結算：四家分數表 ---------------- */
.score-table .sub td { color: #8a6d1a; font-size: 13px; }
.standings {
  width: 100%;
  margin: 6px 0 4px;
  border-collapse: collapse;
  font-size: 14px;
}
.standings th { font-size: 12px; color: #999; font-weight: 600; padding: 2px 6px; }
.standings td { padding: 5px 6px; border-top: 1px solid #eee2c6; }
.standings td:not(:first-child), .standings th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.standings tr.me td { background: #fff3cf; font-weight: 700; }
.standings .plus { color: #1b7a3d; font-weight: 700; }
.standings .minus { color: #c0281c; }
.podium { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.podium-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #f6efdc;
  font-size: 16px;
  animation: modal-in 0.4s ease-out backwards;
}
.podium-row:nth-child(2) { animation-delay: 0.1s; }
.podium-row:nth-child(3) { animation-delay: 0.2s; }
.podium-row:nth-child(4) { animation-delay: 0.3s; }
.podium-row.me { background: #ffe9a8; box-shadow: 0 0 0 2px #e0a800; }
.podium-row .medal { font-size: 24px; }
.podium-row b { margin-left: auto; font-size: 18px; color: #1b5e3a; }

/* ---------------- 手機橫放：畫面比較矮 ---------------- */
@media (orientation: landscape) and (max-height: 500px) {
  .seat-top .backs { display: none; }
  .seat-top { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .seat-side .backs { display: none; }
  .river-top, .river-bottom { min-height: calc(var(--rv-h, 27px) + 4px); }
  .compass { width: min(100%, 120px); }
  .compass-mid { inset: 26px; }
  .turn-line { display: none; }
  .seat-me { margin-top: 2px; padding: 2px 8px; }
}
