/*
  模块说明：牌桌页样式（table.css）—— 椭圆德州桌面、座位、扑克牌牌面、公共牌、底池、操作区、行动倒计时。
  被谁使用：public/js/pages/table.js 渲染出的 .table-root 结构。
  关键设计：
  - 座位位置不写死在 CSS，而由 JS 计算椭圆坐标后写入 --x / --y（百分比），这样 2~12 人都能均匀分布。
  - 牌面支持"纯 CSS 绘制"（无图片依赖）：白底圆角 + 红黑两色 + 中间大号点数，离线可用。
  - 窄屏时自动缩小牌与座位，并让操作区固定在底部，保证手机上"点得到、看得清"。
*/

/* ============ 1. 牌桌整体 ============ */
.table-root {
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
  min-height: calc(100vh - 190px);
  padding-bottom: 92px; /* 给底部固定操作区留位置，避免遮挡公共牌 */
}

.table-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: var(--r-md);
  background: var(--c-panel); border: 1px solid var(--c-line);
}
.table-topbar__room { font-size: 14px; font-weight: 800; color: var(--c-gold-200); }
.table-topbar__meta { font-size: 12px; color: var(--c-text-dim); margin-top: 2px; }
.table-topbar__right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.ws-dot { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--c-text-dim); }
.ws-dot::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: #8a8a8a;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.4);
}
.ws-dot.is-on::before { background: var(--c-green-300); box-shadow: 0 0 8px var(--c-green-300); }
.ws-dot.is-off::before { background: var(--c-danger); box-shadow: 0 0 8px var(--c-danger); }

/* ============ 2. 椭圆桌面 ============ */
/* 座位以 felt-wrap 为定位参考（桌面与座位都在这个容器里），所以这里的 relative 是必需的 */
.felt-wrap { position: relative; width: 100%; }

.felt {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  border-radius: 48% / 46%;
  border: 8px solid transparent;
  /* 金色描边用 border-image 做不到圆角，改用两层背景 + outline 效果 */
  background:
    radial-gradient(closest-side, #1c8a62 0%, #146a4b 52%, #0b3d2c 100%);
  box-shadow:
    inset 0 0 90px rgba(0, 0, 0, 0.55),
    0 0 0 4px var(--c-gold-600),
    0 0 0 8px rgba(0, 0, 0, 0.35),
    var(--sh-3);
}
/* 桌面中心的暗色内圈：视觉焦点落在公共牌与底池上 */
.felt::after {
  content: '';
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 58%; height: 50%;
  border-radius: 50%;
  border: 1px solid rgba(212, 175, 55, 0.25);
  pointer-events: none;
}

.felt__center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: 76%; text-align: center;
}

.pot {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 14px; border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.42); border: 1px solid var(--c-gold-600);
  font-weight: 800; color: var(--c-gold-200);
}
.pot__num { font-size: 17px; color: var(--c-gold-400); }

.street-badge {
  font-size: 11.5px; letter-spacing: 1px; padding: 2px 10px; border-radius: var(--r-pill);
  border: 1px solid var(--c-line-soft); color: var(--c-text-dim); background: rgba(0, 0, 0, 0.28);
}
.board { display: flex; gap: 6px; justify-content: center; }

/* 底池筹码堆：纯装饰，用几个小圆点表示多池（主池/边池） */
.pot-chips { display: flex; gap: 4px; justify-content: center; min-height: 12px; }
.pot-chips i {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--c-gold-grad); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ============ 3. 扑克牌（CSS 绘制，无图片） ============ */
.card-face {
  position: relative;
  width: 46px; height: 64px;
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff, #eef1f0);
  color: #1b1b1b;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; line-height: 1;
  user-select: none;
}
.card-face__rank { font-size: 19px; }
.card-face__suit { font-size: 15px; margin-top: 1px; }
.card-face--red { color: #d21f3c; }
.card-face--black { color: #1b1b1b; }
.card-face.is-small { width: 30px; height: 42px; border-radius: 4px; }
.card-face.is-small .card-face__rank { font-size: 13px; }
.card-face.is-small .card-face__suit { font-size: 10px; }

/* 牌背：斜纹 + 金边，用于其他玩家的底牌 */
.card-face--back {
  background:
    repeating-linear-gradient(45deg, #1b4f8a 0 5px, #16406f 5px 10px);
  border: 1px solid var(--c-gold-600);
  color: transparent;
}
.card-face--back::after {
  content: '♠';
  position: absolute; inset: 0; display: grid; place-items: center;
  color: rgba(212, 175, 55, 0.85); font-size: 20px;
}
.card-face--back.is-small::after { font-size: 13px; }
.card-slot {
  width: 46px; height: 64px; border-radius: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.18);
}
.card-slot.is-small { width: 30px; height: 42px; border-radius: 4px; }

/* ============ 4. 座位（坐标由 JS 写入 CSS 变量） ============ */
.pt-seat {
  position: absolute;
  left: var(--x, 50%); top: var(--y, 50%);
  transform: translate(-50%, -50%);
  width: 128px;
  padding: 6px 6px 5px;
  border-radius: var(--r-md);
  border: 1px solid var(--c-line-soft);
  background: rgba(4, 26, 18, 0.82);
  text-align: center;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}
.pt-seat.is-turn {
  border-color: var(--c-gold-400);
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.55), 0 0 22px rgba(212, 175, 55, 0.45);
  transform: translate(-50%, -50%) scale(1.04);
}
.pt-seat.is-folded { opacity: 0.42; filter: grayscale(0.7); }
.pt-seat.is-empty { opacity: 0.5; border-style: dashed; }
.pt-seat.is-me { border-color: var(--c-gold-500); background: rgba(20, 70, 50, 0.9); }
.pt-seat.is-winner { animation: winner-pulse 1s ease-in-out 3; }
@keyframes winner-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(87, 199, 155, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(87, 199, 155, 0.85); }
}

.pt-seat__head { display: flex; align-items: center; gap: 6px; justify-content: center; }
.pt-seat__avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  border: 1px solid var(--c-line);
  background: rgba(0, 0, 0, 0.4); display: grid; place-items: center;
  font-size: 13px; font-weight: 800; color: var(--c-gold-200); overflow: hidden;
}
.pt-seat__avatar img { width: 100%; height: 100%; object-fit: cover; }
.pt-seat__name {
  font-size: 12px; font-weight: 700; color: var(--c-white);
  max-width: 78px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pt-seat__stack { font-size: 12px; color: var(--c-gold-400); font-weight: 800; margin-top: 2px; }
.pt-seat__status {
  display: inline-block; margin-top: 2px; padding: 0 6px;
  font-size: 10.5px; border-radius: var(--r-pill);
  border: 1px solid var(--c-line-soft); color: var(--c-text-dim);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pt-seat__status.is-action { border-color: var(--c-gold-500); color: var(--c-gold-200); background: rgba(212, 175, 55, 0.14); }
.pt-seat__status.is-fold { border-color: rgba(217, 74, 74, 0.6); color: #ffb4b4; }
.pt-seat__status.is-allin { border-color: #ff8a3d; color: #ffbe8a; background: rgba(255, 138, 61, 0.14); }
.pt-seat__cards { display: flex; gap: 3px; justify-content: center; margin-bottom: 4px; }
.pt-seat__bet {
  position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; color: var(--c-gold-200);
  background: rgba(0, 0, 0, 0.55); border: 1px solid var(--c-gold-600);
  border-radius: var(--r-pill); padding: 0 7px; white-space: nowrap;
}
.pt-seat__dealer {
  position: absolute; right: -8px; top: -8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--c-gold-grad); color: var(--c-text-dark);
  display: grid; place-items: center; font-size: 11px; font-weight: 900;
  border: 1px solid var(--c-gold-600); box-shadow: var(--sh-1);
}
.pt-seat__off {
  position: absolute; left: -6px; top: -8px;
  font-size: 10px; padding: 0 5px; border-radius: var(--r-pill);
  background: rgba(217, 74, 74, 0.85); color: #fff;
}
/* 本地玩家底牌放大显示（heros cards 放在桌面下方中央） */
.hero-cards { display: flex; gap: 8px; justify-content: center; }
.hero-cards .card-face { width: 58px; height: 80px; }
.hero-cards .card-face__rank { font-size: 24px; }
.hero-cards .card-face__suit { font-size: 18px; }

/* ============ 5. 操作区（底部固定，拇指可及） ============ */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(6, 40, 28, 0.86), rgba(4, 26, 18, 0.98));
  border-top: 2px solid var(--c-line);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
}
.action-bar__meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--c-text-dim); }
.action-bar__actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.action-bar__actions .btn { flex: 1 1 0; min-width: 78px; min-height: 48px; font-size: 15px; }
.action-bar__waiting {
  text-align: center; font-size: 13px; color: var(--c-text-dim); padding: 10px 0;
}

/* 行动倒计时进度条：宽度由 JS 每 100ms 更新，剩 25% 变红提醒 */
.timer-bar { height: 8px; border-radius: var(--r-pill); background: rgba(0, 0, 0, 0.45); overflow: hidden; }
.timer-bar > i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--c-green-300), var(--c-gold-400));
  transition: width 0.1s linear, background 0.2s;
}
.timer-bar.is-urgent > i { background: linear-gradient(90deg, #ff8a3d, var(--c-danger)); }

/* 加注面板（内嵌在操作区上方，不用弹窗以免遮挡牌桌） */
.raise-panel {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; border-radius: var(--r-md);
  border: 1px solid var(--c-line); background: rgba(9, 46, 33, 0.96);
}
.raise-panel__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.raise-panel__value { font-weight: 900; color: var(--c-gold-400); font-size: 17px; }
.raise-panel__quick { display: flex; gap: 6px; flex-wrap: wrap; }
.range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: transparent; cursor: pointer;
}
.range::-webkit-slider-runnable-track { height: 8px; border-radius: var(--r-pill); background: rgba(0, 0, 0, 0.5); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -9px;
  border-radius: 50%; background: var(--c-gold-grad); border: 1px solid var(--c-gold-600);
  box-shadow: var(--sh-1);
}
.range::-moz-range-track { height: 8px; border-radius: var(--r-pill); background: rgba(0, 0, 0, 0.5); }
.range::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: var(--c-gold-400); border: 1px solid var(--c-gold-600); }
.raise-panel__row { display: flex; gap: 8px; }
.raise-panel__row .btn { flex: 1 1 0; }

/* 发牌动画：新手牌时给公共牌/底牌一个"从中心飞出"的过渡 */
@keyframes deal-in {
  from { opacity: 0; transform: translateY(-18px) rotate(-8deg) scale(0.7); }
  to { opacity: 1; transform: none; }
}
.deal-anim { animation: deal-in 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.2) both; }
/* 依次发牌：用 nth-child 制造节奏差，纯 CSS 无需 JS 定时器 */
.board .deal-anim:nth-child(1) { animation-delay: 0.02s; }
.board .deal-anim:nth-child(2) { animation-delay: 0.1s; }
.board .deal-anim:nth-child(3) { animation-delay: 0.18s; }
.board .deal-anim:nth-child(4) { animation-delay: 0.26s; }
.board .deal-anim:nth-child(5) { animation-delay: 0.34s; }

/* 桌面聊天/系统消息（房间内公开聊天，避免私聊被用于交易沟通） */
.table-log {
  max-height: 108px; overflow-y: auto;
  padding: 8px 10px; border-radius: var(--r-md);
  border: 1px solid var(--c-line-soft); background: rgba(0, 0, 0, 0.26);
  font-size: 12.5px; color: var(--c-text-dim);
}
.table-log__line { padding: 1px 0; }
.table-log__line b { color: var(--c-gold-200); }
.chat-row { display: flex; gap: 8px; }
.chat-row .input { flex: 1 1 auto; min-height: 38px; }

/* ============ 6. 窄屏自适应 ============ */
@media (max-width: 760px) {
  .felt { aspect-ratio: 4 / 3; border-radius: 44% / 40%; }
  .card-face { width: 36px; height: 50px; }
  .card-face__rank { font-size: 15px; }
  .card-face__suit { font-size: 12px; }
  .card-slot { width: 36px; height: 50px; }
  .pt-seat { width: 104px; padding: 5px 4px 4px; }
  .pt-seat__avatar { width: 24px; height: 24px; font-size: 11px; }
  .pt-seat__name { font-size: 11px; max-width: 62px; }
  .pt-seat__stack { font-size: 11px; }
  .hero-cards .card-face { width: 48px; height: 66px; }
  .action-bar__actions .btn { min-width: 62px; min-height: 44px; font-size: 14px; }
}
@media (max-width: 400px) {
  .pt-seat { width: 88px; }
  .card-face { width: 30px; height: 42px; }
  .card-slot { width: 30px; height: 42px; }
  .board { gap: 4px; }
}

/* ============ 7. 手机横屏适配（浏览器与打包后的 APP 通用） ============ */
/*
 * 关于"强制横屏"：
 *   网页受浏览器安全限制，**无法直接旋转手机屏幕**。可行的两条路：
 *     ① 用户点顶栏「横屏」按钮 → 进入全屏后调用 screen.orientation.lock('landscape')
 *        （Chrome for Android 支持；iOS Safari 不支持，需用户手动转屏）
 *     ② 打包成安卓 APP 时，在 AndroidManifest.xml 的 Activity 上声明
 *        android:screenOrientation="landscape" —— 这是唯一能"一打开就横屏"的办法
 *   下面这组样式负责"横过来之后把版面真正用起来"：
 *   牌桌拉宽、日志收窄、操作区贴底，不再出现竖屏那种上下挤压。
 */
@media (orientation: landscape) and (max-height: 560px) {
  .table-root { padding: 4px 10px 0; }
  .felt { aspect-ratio: 21 / 9; border-radius: 50% / 44%; max-height: 60vh; }
  .pt-seat { width: 108px; padding: 4px; }
  .pt-seat__avatar { width: 22px; height: 22px; font-size: 10px; }
  .pt-seat__name { font-size: 11px; max-width: 72px; }
  .pt-seat__stack { font-size: 11px; }
  .card-face { width: 32px; height: 44px; }
  .card-slot { width: 32px; height: 44px; }
  .card-face__rank { font-size: 14px; }
  .card-face__suit { font-size: 11px; }
  .hero-cards .card-face { width: 40px; height: 56px; }
  .table-topbar { padding: 4px 8px; }
  .table-log { max-height: 84px; }
  .action-bar { padding: 4px 8px 6px; }
  .action-bar__actions .btn { min-width: 64px; min-height: 40px; font-size: 14px; }
  .raise-panel { padding: 6px 8px; }
}

/* 只在手机/触屏上出现的控件（桌面端隐藏，保证电脑界面不变） */
.only-mobile { display: none; }
@media (max-width: 900px), (pointer: coarse) {
  .only-mobile { display: inline-flex; }
}
