:root {
  --bg: #0e1116;
  --felt: #3372b0;
  --felt-2: #1b4a7f;
  --rail: #e8e5dc;
  --panel: #171c24;
  --panel-2: #1f2630;
  --text: #e8eef5;
  --muted: #9aa7b4;
  --accent: #4da3ff;
  --accent-2: #2f7de1;
  --gold: #f4c542;
  --red: #e05252;
  --green: #37b26c;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;              /* 移动端：随地址栏收放动态变化 */
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 50% -10%, #1b2430 0%, var(--bg) 60%);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

.view {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 100vh;
  height: 100dvh;              /* 移动端可视高度，避免被状态栏/地址栏顶出屏幕 */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- 首页 ---------- */
#view-home { align-items: center; justify-content: center; }

.home-card {
  width: min(92vw, 360px);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid #2a3442;
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.home-card h1 { font-size: 26px; margin: 6px 0 4px; letter-spacing: 2px; }
.subtitle { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

.input {
  width: 100%;
  background: #0c1016;
  border: 1px solid #2b3644;
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border .15s;
}
.input:focus { border-color: var(--accent); }
#room-input { text-transform: uppercase; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #33404f;
  cursor: pointer;
  transition: transform .08s, background .15s, filter .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: transparent; }
.btn.block { width: 100%; margin-top: 14px; }
.btn.ghost { background: transparent; border: 1px solid #33404f; }
.btn.danger { color: #ff8f8f; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 8px; }

.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 14px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #2a3442; }

.join-row { display: flex; gap: 8px; }
.join-row .input { flex: 1; }

.hint { color: var(--muted); font-size: 12px; margin-top: 14px; min-height: 16px; }

/* ---------- 顶栏 ---------- */
#table-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid #222b36;
  background: rgba(10,14,20,.6);
  z-index: 5;
  flex: 0 0 auto;
}
.room-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.room-label { color: var(--muted); font-size: 13px; }
.room-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--gold);
}
.topbar-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.hand-indicator { color: var(--muted); font-size: 13px; }

/* 顶栏图标按钮 */
.icon-btn {
  width: 36px; height: 36px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: transparent; border: 1px solid #33404f;
  color: var(--text); font-size: 17px; line-height: 1;
  cursor: pointer; transition: filter .15s, transform .08s;
}
.icon-btn:hover { filter: brightness(1.15); }
.icon-btn:active { transform: scale(.93); }
.icon-btn.danger { color: #ff8f8f; }

/* ---------- 牌桌 ---------- */
#table-wrap { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; padding: 8px; min-height: 0; overflow: hidden; }

#table {
  position: relative;
  width: min(96vw, 1060px);
  height: clamp(240px, 54dvh, 560px);
  border-radius: 50% / 50%;
  background:
    radial-gradient(ellipse at 50% 38%, #4d90cd 0%, var(--felt) 48%, var(--felt-2) 100%);
  border: 14px solid var(--rail);
  box-shadow:
    inset 0 0 100px rgba(8, 26, 54, .6),
    inset 0 0 0 3px rgba(255, 255, 255, .25),
    0 0 0 1px rgba(0, 0, 0, .4),
    0 26px 55px rgba(0, 0, 0, .6);
}
#table::before {
  content: "";
  position: absolute;
  inset: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .16);
}

#board {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -52%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.pot { font-weight: 700; color: var(--gold); font-size: 16px; text-shadow: 0 1px 4px rgba(0,0,0,.6); min-height: 20px; }
.community { display: flex; gap: 6px; cursor: pointer; }
.phase-label { font-size: 13px; color: rgba(255,255,255,.85); text-shadow: 0 1px 3px rgba(0,0,0,.7); }

/* ---------- 扑克牌 ---------- */
.card {
  position: relative;
  width: 46px;
  height: 64px;
  background: #f7f9fc;
  border-radius: 6px;
  box-shadow: 0 2px 5px rgba(0,0,0,.4);
  display: inline-block;
  flex: 0 0 auto;
}
.card.red { color: #d32f2f; }
.card.black { color: #1a1a1a; }
.card .corner { position: absolute; top: 4px; left: 5px; font-size: 13px; line-height: 1; font-weight: 700; }
.card .center-suit { position: absolute; top: 53%; left: 50%; transform: translate(-50%, -50%); font-size: 24px; }
.card.back {
  background:
    repeating-linear-gradient(45deg, #2453a6 0 6px, #1d4490 6px 12px);
  border: 2px solid #fff;
}
.card.placeholder { background: rgba(255,255,255,.07); border: 1px dashed rgba(255,255,255,.25); box-shadow: none; }

.hole-cards { display: flex; gap: 4px; margin-top: 4px; }
.hole-cards.own { cursor: pointer; }
.hole-cards .card { width: 34px; height: 47px; }
.hole-cards .card .corner { font-size: 9px; }
.hole-cards .card .center-suit { font-size: 15px; }

/* ---------- 座位 ---------- */
#seats { position: absolute; inset: 0; pointer-events: none; }

.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 96px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(10,15,22,.55);
  border: 1px solid transparent;
  transition: border .15s, background .15s;
  text-align: center;
}
.seat.active {
  border-color: var(--gold);
  background: rgba(244,197,66,.16);
  box-shadow: 0 0 16px rgba(244,197,66,.35);
}
.seat.folded { opacity: .45; }
.seat-name { font-size: 13px; font-weight: 600; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 轮到该玩家：昵称高亮 */
.seat.active .seat-name {
  color: var(--gold);
  font-weight: 800;
  text-shadow: 0 0 10px rgba(244,197,66,.85);
}
/* 回合倒计时角标 */
.seat-timer {
  position: absolute; top: -9px; right: -9px;
  min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 11px;
  background: var(--gold); color: #1a1508;
  font-size: 12px; font-weight: 800; line-height: 22px; text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.seat-timer.urgent { background: var(--red); color: #fff; animation: seatPulse .8s ease-in-out infinite; }
@keyframes seatPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
.seat-chips { font-size: 12px; color: var(--muted); }
.seat-bet { font-size: 12px; color: var(--gold); font-weight: 700; min-height: 14px; }
.seat-bet.raise { color: #ff9f43; font-weight: 800; }
.seat-status {
  font-size: 11px; color: #ffb0b0; font-weight: 700;
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: rgba(0,0,0,.7); padding: 3px 8px; border-radius: 6px;
}
.seat-status.allin { color: var(--gold); }
.dealer-btn {
  position: absolute; top: -8px; left: -8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; color: #111; font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 5px rgba(0,0,0,.5);
}

/* ---------- 控制区 ---------- */
#controls {
  min-height: 92px;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #222b36;
  background: rgba(10,14,20,.7);
  flex: 0 0 auto;
}

#action-bar { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.action {
  border: none; border-radius: 10px; padding: 13px 20px;
  font-size: 15px; font-weight: 700; color: #fff; cursor: pointer;
  transition: transform .08s, filter .15s;
}
.action:hover { filter: brightness(1.1); }
.action:active { transform: scale(.97); }
.action.fold { background: #5a6472; }
.action.check { background: var(--green); }
.action.call { background: var(--accent-2); }
.action.raise { background: var(--red); }
.action.allin {
  background: linear-gradient(180deg, #2b2b2b, #0e0e0e);
  color: var(--gold);
  border: 1px solid var(--gold);
}
.action.next { background: var(--accent-2); }
.action.rebuy { background: var(--gold); color: #211a05; }

.waiting { color: var(--muted); font-size: 15px; }

#raise-slider {
  width: 200px;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: #141414;
  outline: 1px solid var(--gold);
  outline-offset: 1px;
}
#raise-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(180deg, #f9d878, #d4a017);
  border: 1px solid #8a6d1a;
  cursor: pointer;
}
#raise-slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(180deg, #f9d878, #d4a017);
  border: 1px solid #8a6d1a;
  cursor: pointer;
}
.raise-label { color: #c9b3ef; font-size: 13px; }

/* ---------- 大厅 ---------- */
#lobby-panel { display: flex; justify-content: center; }
.lobby-card {
  width: min(92vw, 440px);
  background: var(--panel);
  border: 1px solid #2a3442;
  border-radius: 14px;
  padding: 20px;
  text-align: center;
}
.lobby-card h2 { font-size: 19px; margin-bottom: 6px; }
.lobby-card .room-big { color: var(--gold); letter-spacing: 4px; font-family: monospace; font-size: 22px; }
.lobby-players { margin: 14px 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.lobby-player {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); padding: 8px 12px; border-radius: 8px; font-size: 14px;
}
.lobby-player .chips { margin-left: auto; color: var(--gold); font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--green); }
.dot.off { background: #6b7785; }

.lobby-player .tag { margin-left: auto; font-size: 12px; color: var(--muted); background: #2a3442; padding: 2px 8px; border-radius: 10px; }
.auto-next-toggle { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 12px; color: var(--muted); font-size: 13px; cursor: pointer; }
.auto-next-toggle input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.auto-next-toggle.inline { margin: 0; }
.spectator-banner { color: #9fc6ff; border-color: var(--accent); }

/* ---------- 战绩面板 ---------- */
.ledger-panel {
  position: fixed; right: 12px;
  top: calc(58px + env(safe-area-inset-top, 0px));
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - 134px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  width: 360px; max-width: calc(100vw - 24px);
  background: var(--panel); border: 1px solid #2a3442;
  border-radius: 12px; display: flex; flex-direction: column; z-index: 20;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.ledger-title { padding: 12px 14px; font-weight: 700; font-size: 14px; border-bottom: 1px solid #222b36; color: var(--gold); flex: 0 0 auto; }
.ledger-content { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; }
.ledger-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0; }
.ledger-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ledger-table th, .ledger-table td { padding: 5px 7px; text-align: center; border-bottom: 1px solid #222b36; white-space: nowrap; }
.ledger-table th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.ledger-table td.hand-num { color: var(--muted); }
.ledger-table td.empty { color: #3a4550; }
.ledger-content .win { color: #4cd07d; font-weight: 700; }
.ledger-content .lose { color: #ff8080; font-weight: 700; }
.ledger-content .zero { color: var(--muted); }
.ledger-totals { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid #222b36; padding-top: 10px; }
.ledger-total { background: var(--panel-2); padding: 6px 10px; border-radius: 8px; font-size: 12px; display: flex; gap: 8px; align-items: center; }

/* ---------- 公共牌放大弹窗 ---------- */
.card-modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; }
.card-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); }
.card-modal-body {
  position: relative; z-index: 1;
  background: var(--panel); border: 1px solid #2a3442; border-radius: 16px;
  padding: 22px 28px; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.card-modal-title { font-size: 15px; color: var(--muted); margin-bottom: 16px; }
.card-modal-cards { display: flex; gap: 10px; justify-content: center; margin-bottom: 18px; }
.card-modal-cards .card { width: 78px; height: 108px; }
.card-modal-cards .card .corner { font-size: 19px; }
.card-modal-cards .card .center-suit { font-size: 40px; }

/* ---------- 结果横幅 ---------- */
#result-banner {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  z-index: 8; pointer-events: none;
}
.result {
  background: rgba(0,0,0,.82); border: 1px solid var(--gold);
  color: var(--gold); font-weight: 700; font-size: 16px;
  padding: 12px 22px; border-radius: 12px; text-align: center;
  animation: pop .3s ease;
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- 聊天 ---------- */
.chat-panel {
  position: fixed; right: 12px;
  top: calc(58px + env(safe-area-inset-top, 0px));
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - 134px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  width: 280px; max-width: calc(100vw - 24px);
  background: var(--panel); border: 1px solid #2a3442;
  border-radius: 12px; display: flex; flex-direction: column; z-index: 20;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
#chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }

/* 右下角聊天悬浮按钮 */
.chat-fab {
  position: fixed; right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: 52px; height: 52px; border-radius: 50%;
  border: none; cursor: pointer;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(0,0,0,.5);
  z-index: 50;
  transition: transform .08s, filter .15s;
}
.chat-fab:hover { filter: brightness(1.1); }
.chat-fab:active { transform: scale(.93); }
.chat-msg .who { color: var(--accent); font-weight: 700; }
.chat-msg.system { color: var(--muted); }
.chat-input-row { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #222b36; }
.chat-input-row .input { font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: rgba(0,0,0,.85); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; z-index: 100; opacity: 0; transition: all .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 黑金启动页 ---------- */
.splash {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 50% 38%, rgba(244,197,66,.16) 0%, rgba(28,22,10,.98) 42%, #060504 100%),
    #060504;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  overflow: hidden;
}
/* 断线重连 / 本次会话已通过启动页 → 直接不显示 */
html.skip-splash .splash { display: none !important; }

.splash-hold {
  --p: 0;
  position: relative;
  width: 118px; height: 118px;
  border-radius: 50%;
  background: conic-gradient(#f4c542 calc(var(--p) * 360deg), rgba(244,197,66,.13) 0);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 34px rgba(244,197,66,.18);
}
.splash-hold::after {
  content: "";
  position: absolute; inset: 9px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #1e170a, #060504);
  border: 1px solid rgba(244,197,66,.35);
}

@media (max-width: 620px) {
  .card { width: 34px; height: 48px; }
  .card .corner { font-size: 9px; }
  .card .center-suit { font-size: 15px; }
  .hole-cards .card { width: 26px; height: 36px; }
  #table { height: clamp(180px, 44dvh, 430px); }
  .room-label { display: none; }
  .room-code { font-size: 15px; letter-spacing: 2px; }
  .hand-indicator { display: none; }
  #table-topbar { padding: 6px 10px; padding-top: calc(6px + env(safe-area-inset-top, 0px)); }
  .icon-btn { width: 34px; height: 34px; font-size: 16px; }
  #controls { padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px)); padding-right: 76px; }
  #action-bar { gap: 8px; }
  .action { padding: 12px 16px; font-size: 14px; }
  .chat-panel { width: min(300px, calc(100vw - 20px)); right: 10px; }
  .ledger-panel { width: min(340px, calc(100vw - 20px)); right: 10px; }
}
