/* 掼蛋 —— 全部样式。
   骨架沿用象棋那版（顶栏 / 主体 / 侧栏 / 对话框 / 浮动提示 / 开场页都是同一套），
   把木纹棋盘换成牌桌绿，棋子换成扑克牌。
   单一暗色主题，不跟随系统 —— 牌桌就该是暗的。 */

:root {
  /* 下面这几个由 JS 在 layout() 里实时写入，这里只是占位默认值 */
  --card-w: 62px;   --card-h: 87px;   --overlap: 26px;  --sliver: 24px;  --hand-h: 87px;
  --table-w: 620px; --table-h: 560px;

  --bg-1: #12251b;
  --bg-2: #1d3527;
  --felt-1: #1f4a35;
  --felt-2: #143224;

  --panel: rgba(255, 252, 244, 0.055);
  --panel-line: rgba(210, 232, 214, 0.16);
  --text: #eef0e6;
  --text-dim: #9bae9f;
  --gold: #e2b552;

  --red-ink: #b1352a;
  --black-ink: #23201d;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 50% -10%, #2a5540 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px clamp(14px, 3vw, 36px) 26px;
  padding-top: max(18px, env(safe-area-inset-top));
  padding-bottom: max(26px, env(safe-area-inset-bottom));
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-family: "Kaiti SC", "STKaiti", KaiTi, "楷体", "Songti SC", serif;
  font-size: 26px;
  letter-spacing: 3px;
  color: var(--gold);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.level-badge {
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid rgba(226, 181, 82, 0.4);
  background: rgba(226, 181, 82, 0.12);
  color: var(--gold);
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: 16px;
  letter-spacing: 1px;
  white-space: nowrap;
}

.btn, select, .icon-btn, .chat-form input, .lobby-join input, .lobby-options input {
  padding: 7px 12px;
  white-space: nowrap;
  border-radius: 9px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background .16s, border-color .16s, transform .1s;
}

.icon-btn { padding: 7px 10px; }

.btn:hover:not(:disabled), .icon-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(226, 181, 82, 0.42);
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(150deg, rgba(226, 181, 82, 0.28), rgba(226, 181, 82, 0.14));
  border-color: rgba(226, 181, 82, 0.55);
  color: #f6e6c2;
}

.btn-danger { border-color: rgba(200, 70, 58, 0.5); color: #ffb0a5; }

.icon-btn[aria-pressed="false"] { opacity: 0.45; }

.field { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-dim); }
.field input, .field select { min-width: 0; }

/* ---------- 主体布局 ---------- */

.main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(16px, 2.5vw, 34px);
}

.board-area { display: flex; justify-content: center; }

.board-wrap {
  position: relative;
  width: var(--table-w);
  height: var(--table-h);
  max-width: 100%;
}

.board-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 18px;
}

.layer, .hand-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* 侧栏和牌桌等高封顶：否则复盘一长，侧栏会把整页撑出滚动条，
   面板自己也不会在内部滚动 */
.sidebar {
  flex: 0 0 300px;
  max-width: 300px;
  max-height: var(--table-h);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- 计分板 ---------- */

.scoreboard {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
}

.score-side { flex: 1; display: flex; align-items: baseline; gap: 8px; }
.score-side.them { justify-content: flex-end; }
.score-name { font-size: 12px; color: var(--text-dim); }

.score-level {
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: 24px;
  line-height: 1;
  color: var(--gold);
}

.score-side.mine .score-level { color: #8fd6a5; }
.score-vs { font-size: 11px; color: var(--text-dim); }

.score-side .a-tries {
  font-size: 11px;
  color: #ffab9c;
  border: 1px solid rgba(217, 80, 63, 0.4);
  border-radius: 999px;
  padding: 1px 6px;
}

/* ---------- 状态条 ---------- */

.status {
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  font-size: 14px;
  text-align: center;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.status.urgent { border-color: rgba(226, 74, 58, 0.45); color: #ffb3a6; }
.status.over { border-color: rgba(226, 181, 82, 0.45); color: var(--gold); }
.status.review { border-color: rgba(120, 160, 220, 0.4); color: #b6cdf2; }

/* ---------- 牌 ---------- */

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-w) * 0.11);
  background: linear-gradient(158deg, #fdf7e8 0%, #f4ead2 62%, #e3d3b2 100%);
  border: 1px solid rgba(120, 92, 52, 0.5);
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.42),
    0 1px 2px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  color: var(--black-ink);
  font-family: Georgia, "Times New Roman", serif;
  will-change: transform;
  transition: transform 0.22s var(--ease), box-shadow 0.14s, opacity 0.2s;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
}

.card[data-red="1"] { color: var(--red-ink); }

/* 左上角索引：点数在上、花色在下，竖着排。
   叠牌时只有这一条竖带露在外面，所以两样信息都得挤进来。 */
.card-index {
  position: absolute;
  left: calc(var(--card-w) * 0.05);
  top: calc(var(--card-w) * 0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  width: calc(var(--sliver) - 4px);
}

.card-index b {
  font-size: calc(var(--sliver) * 0.74);
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* 「10」是唯一两位数的点数，缩一号才塞得进窄边 */
.card[data-ten="1"] .card-index b {
  font-size: calc(var(--sliver) * 0.54);
  letter-spacing: -1px;
}

.card-index i {
  font-style: normal;
  font-size: calc(var(--sliver) * 0.6);
  margin-top: 1px;
}

/* 中间的大花色，只有完全露出来的牌看得到，主要是好看 */
.card-pip {
  position: absolute;
  right: calc(var(--card-w) * 0.10);
  bottom: calc(var(--card-w) * 0.06);
  font-size: calc(var(--card-w) * 0.46);
  line-height: 1;
  opacity: 0.75;
}

.card.joker .card-index b,
.card.joker .card-index i {
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: calc(var(--sliver) * 0.56);
}
.card.joker .card-pip { font-size: calc(var(--card-w) * 0.36); opacity: 0.55; }

/* 逢人配：红桃级牌，给它一圈金边，一眼能挑出来 */
.card.wild {
  border-color: rgba(226, 181, 82, 0.9);
  box-shadow:
    0 0 0 2px rgba(226, 181, 82, 0.55),
    0 3px 6px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

/* 「配」字必须待在露出来的那条窄边里 —— 标在右上角的话，叠牌时会被下一张牌
   整个盖住，等于白标。所以它跟在索引区（点数+花色）下面，一起挤在左边缘。 */
.card.wild::after {
  content: "配";
  position: absolute;
  left: calc(var(--card-w) * 0.05);
  top: calc(var(--sliver) * 1.55);
  width: calc(var(--sliver) - 4px);
  text-align: center;
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: calc(var(--sliver) * 0.5);
  font-weight: 700;
  color: #8a6410;
  background: rgba(226, 181, 82, 0.32);
  border-radius: 3px;
  line-height: 1.35;
}

.card.selected {
  box-shadow:
    0 0 0 3px rgba(240, 194, 90, 1),
    0 0 18px 4px rgba(226, 181, 82, 0.6),
    0 8px 14px rgba(0, 0, 0, 0.45);
  z-index: 5;
}

.card.playable:hover { filter: brightness(1.06); }
.card.dimmed { filter: brightness(0.62) saturate(0.7); }

/* 牌背：对手手上的牌 */
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.05) 0 4px, transparent 4px 8px),
    linear-gradient(158deg, #8c2f28 0%, #6d221d 60%, #521915 100%);
  border-color: rgba(255, 220, 190, 0.28);
  cursor: default;
}
.card.back .card-index, .card.back .card-pip { display: none; }

/* 打出去的牌不再可点 */
.table-card { pointer-events: none; }

.card.dealing { animation: deal-in 0.34s var(--ease) backwards; }

@keyframes deal-in {
  from { opacity: 0; transform: translate(var(--from-x), var(--from-y)) scale(0.6) rotate(8deg); }
}

.card.leaving { opacity: 0; transform: scale(0.8) translateY(-20px); }

.hand-layer.no-anim .card { transition: none !important; }

/* 拖动排序 */
.card.dragging {
  z-index: 30;
  transition: none;                 /* 跟手，别有延迟 */
  box-shadow:
    0 0 0 2px rgba(226, 181, 82, 0.85),
    0 10px 22px rgba(0, 0, 0, 0.5);
  filter: brightness(1.08);
}

/* 拖动过程中别让浏览器把手势当成滚动/选中 */
.hand-layer .card { touch-action: none; -webkit-user-drag: none; }
.hand-layer.dragging { cursor: grabbing; }
.hand-layer.dragging .card { cursor: grabbing; }

/* ---------- 座位（三个对手） ---------- */

.seat-view {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: rgba(10, 24, 17, 0.72);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}

.seat-view.top { top: 10px; left: 50%; transform: translateX(-50%); }
.seat-view.left { left: 10px; top: 17%; transform: translateY(-50%); }
.seat-view.right { right: 10px; top: 17%; transform: translateY(-50%); }

.seat-view .who { color: var(--text); }
.seat-view .count { color: var(--gold); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.seat-view .tag { font-size: 11px; color: var(--text-dim); }

.seat-view.turn {
  border-color: rgba(226, 181, 82, 0.6);
  box-shadow: 0 0 0 1px rgba(226, 181, 82, 0.2), 0 0 16px rgba(226, 181, 82, 0.18);
}

.seat-view.mate .who { color: #8fd6a5; }
.seat-view.away { opacity: 0.5; }
.seat-view.idle .who::after { content: " 💤"; }

.seat-view .lowcards {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(217, 80, 63, 0.28);
  color: #ffc7bd;
  font-size: 11px;
  animation: blink 1s steps(2, end) infinite;
}

/* ---------- 出牌区 ---------- */

.play-zone { position: absolute; width: 0; height: 0; }

.play-zone .card { position: absolute; transition: none; }
.play-zone .pass-mark { position: absolute; transform: translate(-50%, -50%); }

.pass-mark {
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: rgba(10, 24, 17, 0.8);
  color: var(--text-dim);
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: 16px;
  letter-spacing: 2px;
  animation: pop-in 0.18s var(--ease) backwards;
}

.combo-tag {
  position: absolute;
  top: calc(var(--card-h) * 0.5 + 7px);
  left: 0;
  transform: translateX(-50%);
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(8, 20, 14, 0.7);
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ---------- 出牌按钮条 ---------- */

.play-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--hand-h) + 24px);
  display: flex;
  gap: 10px;
  pointer-events: auto;
  z-index: 8;
}

.play-bar .btn { padding: 9px 22px; font-size: 15px; white-space: nowrap; }

/* 进贡 / 还贡的挑牌提示条。和出牌按钮同一个位置，两者不会同时出现 */
.pick-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--hand-h) + 24px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(226, 181, 82, 0.45);
  background: rgba(12, 26, 18, 0.94);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  z-index: 9;
  max-width: calc(var(--table-w) - 24px);
}

.pick-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-bar .btn { flex: none; }
.pick-bar .btn { padding: 8px 18px; white-space: nowrap; }

/* 挑牌时，不能选的牌压暗且点不动 —— 规则直接画在牌面上，不用去读说明。
   注意不能压太狠：这个模式存在的意义就是让人对着**整手牌**权衡该给哪张，
   压到看不清点数就本末倒置了。0.68 是既能区分、又还读得清的档位。 */
.card.unpickable { filter: brightness(0.68) saturate(0.6); cursor: default; }

/* 反过来，能选的牌给一圈暖光把它们托出来。
   用 .candidate 而不是 .playable —— 后者正常出牌时每张牌都有，会让整手牌一起发光 */
.card.candidate {
  box-shadow:
    0 0 0 1px rgba(226, 181, 82, 0.55),
    0 0 12px 1px rgba(226, 181, 82, 0.25),
    0 3px 6px rgba(0, 0, 0, 0.42);
}

/* ---------- 侧栏：座位表 ---------- */

.seat-list { display: flex; flex-direction: column; gap: 6px; }

.seat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  font-size: 13px;
}

.seat-row.mine { border-color: rgba(143, 214, 165, 0.4); }
.seat-row.turn { border-color: rgba(226, 181, 82, 0.55); }
.seat-row .dot { width: 8px; height: 8px; border-radius: 50%; background: #7d7166; flex: none; }
.seat-row .dot.online { background: #4caf72; }
.seat-row .dot.bot { background: #7aa7d9; }
.seat-row .dot.away { background: #d9503f; }
.seat-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-row .cards { color: var(--gold); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.seat-row .flag { font-size: 11px; color: var(--text-dim); }

/* ---------- 标签页 ---------- */

.side-panel {
  flex: 1;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  overflow: hidden;
}

.tabs { display: flex; border-bottom: 1px solid var(--panel-line); }

.tab {
  flex: 1;
  padding: 9px 0;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: color .15s, box-shadow .15s;
}

.tab.active { color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }

.badge {
  margin-left: 5px;
  padding: 0 6px;
  border-radius: 999px;
  background: #d9503f;
  color: #fff;
  font-size: 11px;
}

.tab-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- 复盘 ---------- */

.replay-scroll { flex: 1; overflow-y: auto; padding: 8px; }

.replay { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; }

.replay:empty::after {
  content: "本局打完之后才能看记录";
  display: block;
  text-align: center;
  padding: 26px 10px;
  color: rgba(155, 174, 159, 0.6);
  line-height: 1.7;
}

.replay .deal-head {
  margin-top: 8px;
  padding: 5px 7px;
  border-radius: 6px;
  background: rgba(226, 181, 82, 0.1);
  color: var(--gold);
  font-size: 12px;
}
.replay .deal-head:first-child { margin-top: 0; }

.replay .trick-head {
  margin-top: 5px;
  color: rgba(155, 174, 159, 0.75);
  font-size: 11px;
}

.replay .move { display: flex; gap: 6px; padding: 2px 7px; border-radius: 5px; }
.replay .move .who { flex: none; width: 52px; color: var(--text-dim); }
.replay .move.us .who { color: #8fd6a5; }
.replay .move .what { flex: 1; }
.replay .move.pass .what { color: rgba(155, 174, 159, 0.65); }
.replay .move.bomb .what { color: #ffab6b; }

/* ---------- 聊天 ---------- */

.chat-scroll { flex: 1; overflow-y: auto; padding: 9px; display: flex; flex-direction: column; gap: 6px; }

.chat-scroll:empty::after {
  content: "还没有消息";
  margin: auto;
  color: rgba(155, 174, 159, 0.55);
  font-size: 12px;
}

.chat-msg {
  max-width: 86%;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 13px;
  line-height: 1.45;
  animation: pop-in-cap 0.2s var(--ease) backwards;
}

.chat-msg .from { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 2px; }
.chat-msg.mine { align-self: flex-end; background: rgba(226, 181, 82, 0.16); }

.quick-chat {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 7px 9px 0;
}

.quick-chat button {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.quick-chat button:hover { color: var(--text); border-color: rgba(226, 181, 82, 0.42); }

.chat-form { display: flex; gap: 6px; padding: 8px 9px 9px; }
.chat-form input { flex: 1; cursor: text; }

/* ---------- 控制区 ---------- */

.controls { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.controls .btn { padding: 10px 6px; text-align: center; white-space: nowrap; }

.hint {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.85;
  color: rgba(155, 174, 159, 0.75);
  text-align: center;
}

kbd {
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

/* ---------- 房间栏与连接状态 ---------- */

.room-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 6px 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  font-size: 13px;
}

.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: #7d7166; }
.conn-dot[data-status="online"] { background: #4caf72; }
.conn-dot[data-status="connecting"] { background: var(--gold); animation: blink 1s steps(2, end) infinite; }
.conn-dot[data-status="offline"] { background: #d9503f; animation: blink 1s steps(2, end) infinite; }

.conn-text { color: var(--text-dim); }

.room-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--gold);
}

/* ---------- 开场页 ---------- */

.lobby {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 700px at 50% -10%, #2a5540 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
}

.lobby-card { width: min(430px, 100%); display: flex; flex-direction: column; gap: 12px; }

.lobby-title {
  margin: 0;
  text-align: center;
  font-family: "Kaiti SC", "STKaiti", KaiTi, "楷体", serif;
  font-size: 44px;
  letter-spacing: 8px;
  color: var(--gold);
}

.lobby-sub { margin: 0 0 8px; text-align: center; color: var(--text-dim); font-size: 14px; }

.lobby-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 15px 18px;
  border-radius: 14px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .16s, border-color .16s, transform .1s;
}

.lobby-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); border-color: rgba(226, 181, 82, 0.45); }
.lobby-btn:active:not(:disabled) { transform: translateY(1px); }
.lobby-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.lobby-btn.primary {
  background: linear-gradient(150deg, rgba(226, 181, 82, 0.26), rgba(226, 181, 82, 0.12));
  border-color: rgba(226, 181, 82, 0.5);
}

.lobby-btn-main { font-size: 16px; }
.lobby-btn-sub { font-size: 12.5px; color: var(--text-dim); }

.lobby-join { display: flex; gap: 8px; }

.lobby-join input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 17px;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  cursor: text;
}

.lobby-options { display: flex; gap: 12px; }
.lobby-options .field { flex: 1; }
.lobby-options input { flex: 1; cursor: text; }

.lobby-note {
  margin: 0;
  min-height: 18px;
  text-align: center;
  font-size: 12.5px;
  color: #ff9c8c;
}

.lobby-note.info { color: var(--text-dim); }

/* ---------- 对话框 ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 14, 10, 0.62);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  animation: fade-in 0.2s;
}

.modal {
  width: min(430px, 100%);
  padding: 26px 26px 20px;
  border-radius: 16px;
  border: 1px solid var(--panel-line);
  background: linear-gradient(165deg, #1e3a2b, #14261c);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.65);
  text-align: center;
  animation: rise 0.26s var(--ease);
}

.modal-icon { font-size: 40px; line-height: 1; margin-bottom: 10px; }
.modal-icon:empty { display: none; }

.modal h2 {
  margin: 0 0 8px;
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: 24px;
  letter-spacing: 2px;
  color: var(--gold);
}

.modal p { margin: 0; color: var(--text-dim); font-size: 14px; line-height: 1.7; }

.modal-body { margin-top: 14px; text-align: left; }
.modal-body:empty { display: none; }

.modal-actions { margin-top: 20px; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* 结算表 */
.result-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.result-table td { padding: 6px 4px; border-bottom: 1px solid rgba(210, 232, 214, 0.08); }
.result-table tr:last-child td { border-bottom: 0; }
.result-table .place { width: 44px; color: var(--gold); font-family: "Kaiti SC", KaiTi, serif; }
.result-table .who.mine { color: #8fd6a5; }
.result-table .team { text-align: right; color: var(--text-dim); font-size: 12px; }

/* 出牌歧义选择器 */
.combo-choices { display: flex; flex-direction: column; gap: 8px; }

.combo-choice {
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.combo-choice:hover { border-color: rgba(226, 181, 82, 0.5); background: rgba(255,255,255,0.09); }

/* ---------- 浮动提示 ---------- */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: max(26px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: rgba(12, 26, 18, 0.96);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 13.5px;
  animation: toast-in 0.22s var(--ease);
}

.toast.leaving { animation: toast-out 0.3s ease-in forwards; }

/* ---------- 动画 ---------- */

@keyframes pop-in { from { opacity: 0; transform: scale(0.4); } }
@keyframes pop-in-cap { from { opacity: 0; transform: scale(0.3); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.96); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---------- 滚动条 ---------- */

.replay-scroll::-webkit-scrollbar, .chat-scroll::-webkit-scrollbar { width: 7px; }
.replay-scroll::-webkit-scrollbar-thumb, .chat-scroll::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: rgba(210, 232, 214, 0.16);
}

/* ---------- 竖屏提示（手机只支持横屏） ---------- */

.rotate-hint { display: none; }

/* 显隐由 JS 挂在 <html> 上的 class 控制，不用媒体查询。
   原因是踩过一次坑：微信内置浏览器**根本不跟着手机转**，页面永远是竖屏，
   `@media (orientation: portrait)` 因此永远成立，人就被锁死在提示页出不来了。
   Safari/Chrome 开了系统的方向锁定也一样。
   所以这里既要 JS 判断（好调试、能兜底），也必须给一个「就这样竖着玩」的出口 ——
   一道没有出口的墙，只要判断条件有一次不成立，就是彻底打不开。 */
html.want-landscape .rotate-hint {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
  text-align: center;
  overflow-y: auto;
  background:
    radial-gradient(900px 600px at 50% 20%, #2a5540 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
}

html.want-landscape .lobby,
html.want-landscape .app,
html.want-landscape .toast-stack,
html.want-landscape .modal-backdrop { display: none !important; }

.rotate-hint .btn { margin-top: 4px; padding: 11px 26px; font-size: 15px; }

.rotate-note {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.8;
  color: rgba(155, 174, 159, 0.72);
}

.rotate-diag {
  margin: 2px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: rgba(155, 174, 159, 0.45);
}

.rotate-hint .rotate-icon {
  font-size: 56px;
  line-height: 1;
  animation: rotate-nudge 2.2s ease-in-out infinite;
}

.rotate-hint h2 {
  margin: 0;
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: 26px;
  letter-spacing: 3px;
  color: var(--gold);
}

.rotate-hint p { margin: 0; color: var(--text-dim); font-size: 14px; line-height: 1.7; }

@keyframes rotate-nudge {
  0%, 55%, 100% { transform: rotate(0deg); }
  70%, 90% { transform: rotate(90deg); }
}

/* ---------- 顶栏里的紧凑状态与比分 ---------- */
/* 侧栏收进抽屉之后，「轮到谁」和比分必须还留在外面 —— 它们是打牌时唯一
   非看不可的两条信息。宽屏时藏起来，因为侧栏里已经有完整版了。 */

.topbar-status, .topbar-score { display: none; }

/* ---------- 抽屉（矮窗口 / 横屏手机） ---------- */

.drawer-backdrop { display: none; }
.drawer-close { display: none; }
/* ☰ 只在侧栏收成抽屉时才有意义；宽屏上侧栏就在旁边杵着，多一个按钮是噪音 */
#btnPanel { display: none; }

/* ---------- 窄屏 ---------- */

@media (max-width: 900px) {
  .main { flex-direction: column; align-items: center; }
  .sidebar { flex: none; width: 100%; max-width: var(--table-w); max-height: none; }
  .side-panel { min-height: 180px; max-height: 260px; }
  .topbar h1 { font-size: 22px; }
  .room-bar { order: 3; width: 100%; justify-content: center; }
  .lobby-title { font-size: 36px; }
}

/* 窄屏：文案已经够短了，保持横排一行；只把内边距收一收，别挡住桌面 */
@media (max-width: 560px) {
  .pick-bar { padding: 7px 8px 7px 13px; gap: 9px; }
  .pick-text { font-size: 13px; }
  .pick-bar .btn { padding: 7px 14px; font-size: 14px; }
}

/* ---------- 矮窗口：侧栏收成抽屉 ----------
   横屏手机只有三百多像素高，侧栏那一列（计分板 + 状态 + 复盘 + 座位表 + 控制区）
   根本塞不下，硬塞就只剩一条缝给牌桌。所以把整个侧栏原样推到屏幕右侧当抽屉，
   点顶栏的 ☰ 才滑出来 —— DOM 一个字没动，只是换了个定位方式。 */

@media (max-height: 560px) {
  /* 开场页：横屏手机只有三百多像素高，原来的间距会把标题和昵称栏挤出屏幕。
     收紧之后正常能放下；真放不下（比如 SE 横屏 320px）也还能滚，不至于点不到按钮。 */
  .lobby {
    align-items: flex-start;
    overflow-y: auto;
    padding: 14px 24px 20px;
  }
  .lobby-card { gap: 8px; }
  .lobby-title { font-size: 27px; letter-spacing: 5px; }
  .lobby-sub { margin-bottom: 2px; font-size: 12.5px; }
  .lobby-btn { padding: 10px 15px; gap: 1px; }
  .lobby-btn-main { font-size: 15px; }
  .lobby-btn-sub { font-size: 11.5px; }
  .lobby-join input { padding: 9px 12px; font-size: 15px; }
  .lobby-note { min-height: 0; }

  .app { gap: 8px; padding: 8px clamp(8px, 1.5vw, 18px) 10px; }

  .topbar { gap: 10px; flex-wrap: nowrap; }
  .topbar h1 { font-size: 17px; letter-spacing: 1px; }
  .topbar-actions { gap: 7px; }
  .level-badge { padding: 4px 9px; font-size: 14px; }
  #btnPanel { display: block; }

  .topbar-status {
    display: block;
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--text-dim);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-status.urgent { color: #ffb3a6; }
  .topbar-status.over { color: var(--gold); }

  .topbar-score {
    display: block;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    color: var(--text-dim);
    white-space: nowrap;
  }

  .main { align-items: flex-start; }
  .board-area { flex: 1; }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 55;
    width: min(330px, 88vw);
    max-width: none;
    max-height: none;
    height: 100%;
    padding: 44px 12px 12px;
    overflow-y: auto;
    background: linear-gradient(165deg, #1c3527, #12251b);
    border-left: 1px solid var(--panel-line);
    box-shadow: -18px 0 48px rgba(0, 0, 0, 0.55);
    transform: translateX(100%);
    transition: transform 0.24s var(--ease);
  }

  .sidebar.open { transform: none; }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 54;
    background: rgba(6, 14, 10, 0.5);
    animation: fade-in 0.2s;
  }
  .drawer-backdrop.hidden { display: none; }

  .drawer-close {
    display: block;
    position: absolute;
    top: 10px;
    right: 12px;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--panel-line);
    background: var(--panel);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
  }

  .side-panel { min-height: 200px; }
  .hint { display: none; }          /* 触摸设备上没有快捷键可言 */
}

@media (pointer: coarse) {
  .btn, .icon-btn, select { min-height: 44px; }
  .tab { min-height: 42px; }
  .quick-chat button { min-height: 34px; }
}

/* 矮窗口上把触摸的最小高度收一收，否则顶栏一行就吃掉八分之一屏幕 */
@media (max-height: 560px) and (pointer: coarse) {
  .btn, .icon-btn, select { min-height: 34px; }
  .tab { min-height: 36px; }
  .play-bar .btn, .pick-bar .btn { min-height: 38px; }
}
