:root {
  --bg: #0c1118;
  --bg-soft: #131b26;
  --card: #182231;
  --card-2: #223047;
  --ink: #f2f6fb;
  --ink-2: #a8b7c9;
  --ink-3: #6d7f96;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #f0b429;
  --primary: #4c8dff;
  --primary-2: #2f6fe0;
  --ok: #3ecf8e;
  --warn: #ff7b72;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
  --font: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1000px 520px at 0% -10%, rgba(76, 141, 255, 0.12), transparent 55%),
    radial-gradient(900px 480px at 100% 0%, rgba(240, 180, 41, 0.08), transparent 50%),
    var(--bg);
  min-height: 100%;
  overflow-x: hidden;
  font-size: calc(16px * var(--font-scale));
}

#app { min-height: 100%; height: 100%; }

.screen { display: none; padding: 28px 22px 40px; max-width: 1280px; margin: 0 auto; }
.screen.active { display: block; }

/* 桌面：整页不滚动，内部面板自适应 */
@media (min-width: 981px) {
  html, body { overflow: hidden; }
  #app { height: 100vh; overflow: hidden; }
  .screen.active {
    display: flex !important;
    flex-direction: column;
    height: 100vh;
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px 20px 18px;
    overflow: hidden;
    box-sizing: border-box;
  }
  /* 大厅若内容略高可内部滚，页面不滚 */
  #screen-lobby.active {
    overflow-y: auto;
  }

  .room-top { margin-bottom: 12px; flex-shrink: 0; }
  .hero { margin: 4px 0 18px; flex-shrink: 0; }
  .hero-sub { margin-top: 6px; }
  .lobby-grid { gap: 14px; }
  .card { padding: 18px; }

  .col-left.card, .col-right.card {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    padding: 16px;
    box-sizing: border-box;
  }
  .chat-form { flex-shrink: 0; }
  .turn-card { padding: 14px; }
  .player-list { gap: 6px; margin-bottom: 10px; }
  .player-item { padding: 8px 10px; }
  .actions { margin-bottom: 10px; gap: 8px; }
}
.hidden { display: none !important; }

/* ===== 简约首页 ===== */
.hero {
  text-align: center;
  margin: 8px 0 28px;
}
.hero-sub {
  color: var(--ink-3);
  font-size: calc(14px * var(--font-scale));
  letter-spacing: 0.04em;
}

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.span-2 { grid-column: 1 / -1; }

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 42%), var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel h2 {
  font-size: calc(17px * var(--font-scale));
  margin-bottom: 16px;
  font-weight: 700;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-head h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
}
.panel-head .btn,
.panel-head .btn-outline {
  width: auto !important;
  flex-shrink: 0;
  padding: 8px 16px;
  font-size: calc(13px * var(--font-scale));
  border-radius: 11px;
  line-height: 1.3;
}

.field { display: block; margin-bottom: 14px; }
.field span {
  display: block;
  font-size: calc(13px * var(--font-scale));
  color: var(--ink-2);
  margin-bottom: 8px;
}
.field input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  font-size: calc(15px * var(--font-scale));
  padding: 13px 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  border-color: rgba(76, 141, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(76, 141, 255, 0.18);
}

/* 输入框 + 小按钮同行 */
/* 字号设置 */
.font-size-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.font-size-label {
  color: var(--ink-3);
  font-size: calc(13px * var(--font-scale));
  flex-shrink: 0;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: calc(13px * var(--font-scale));
  padding: 8px 12px;
  cursor: pointer;
  line-height: 1.2;
}
.seg button + button {
  border-left: 1px solid var(--line);
}
.seg button:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
}
.seg button.active {
  background: rgba(76, 141, 255, 0.22);
  color: var(--ink);
  font-weight: 600;
}
.seg.compact button {
  padding: 7px 10px;
  font-size: calc(12px * var(--font-scale));
}
.room-top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.inline-field input {
  flex: 1;
  min-width: 0;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font-size: calc(15px * var(--font-scale));
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.inline-field input:focus {
  border-color: rgba(76, 141, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(76, 141, 255, 0.15);
}

.hint {
  margin-top: 12px;
  color: var(--ink-3);
  font-size: calc(13px * var(--font-scale));
  line-height: 1.55;
}

/* 统一按钮：首页同款「蓝边空心」 */
.btn,
.btn-outline {
  appearance: none;
  border: 1.5px solid rgba(76, 141, 255, 0.75);
  background: transparent;
  color: var(--primary);
  border-radius: 12px;
  padding: 11px 18px;
  font-size: calc(15px * var(--font-scale));
  font-weight: 650;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.12s, opacity 0.15s;
  white-space: nowrap;
}
.btn:hover,
.btn-outline:hover {
  background: rgba(76, 141, 255, 0.12);
  border-color: var(--primary);
}
.btn:active,
.btn-outline:active {
  transform: translateY(0);
  background: rgba(76, 141, 255, 0.18);
}
.btn:disabled,
.btn-outline:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: transparent;
  transform: none;
}

.btn.primary {
  border-color: rgba(76, 141, 255, 0.95);
  color: #8eb8ff;
  font-weight: 700;
}
.btn.primary:hover {
  background: rgba(76, 141, 255, 0.18);
}

.btn.ghost {
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--ink-2);
}
.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.28);
  color: var(--ink);
}

.btn.warn {
  border-color: rgba(255, 123, 114, 0.8);
  color: #ff9b94;
}
.btn.warn:hover {
  background: rgba(255, 123, 114, 0.12);
  border-color: var(--warn);
}

/* 行内小按钮（与输入框同行） */
.inline-field .btn-outline {
  width: auto;
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: calc(14px * var(--font-scale));
  border-radius: 12px;
}

.room-list { display: flex; flex-direction: column; gap: 10px; min-height: 80px; }
.room-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.room-item:hover {
  border-color: rgba(76, 141, 255, 0.28);
  background: rgba(76, 141, 255, 0.06);
}
.room-item .info { flex: 1; min-width: 0; }
.room-item .name {
  font-weight: 650;
  font-size: calc(15px * var(--font-scale));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.room-item .meta {
  margin-top: 4px;
  color: var(--ink-3);
  font-size: calc(12px * var(--font-scale));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-item .ops { display: flex; gap: 8px; }
.room-item .ops .btn { width: auto; padding: 8px 13px; font-size: calc(13px * var(--font-scale)); }
.empty {
  color: var(--ink-3);
  text-align: center;
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 14px;
}
.empty-sm {
  color: var(--ink-3);
  text-align: center;
  padding: 12px;
  font-size: calc(12px * var(--font-scale));
}

.lan-footer {
  margin-top: 32px;
  text-align: center;
  color: var(--ink-3);
  font-size: calc(13px * var(--font-scale));
}
.lan-urls {
  margin-top: 10px;
  color: var(--ink-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: calc(12px * var(--font-scale));
}
.lan-urls span {
  display: inline-block;
  margin: 4px 6px;
  padding: 7px 11px;
  background: var(--bg-soft);
  border-radius: 9px;
  border: 1px solid var(--line);
}

/* ===== Room / Game ===== */
.room-top {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.room-top .btn,
.room-top .btn-outline {
  width: auto !important;
  flex-shrink: 0;
  padding: 7px 11px;
  font-size: calc(12px * var(--font-scale));
  border-radius: 10px;
  white-space: nowrap;
}

/* 对局页按钮整体压小，便于侧栏收纳 */
#screen-room .btn,
#screen-room .btn-outline {
  padding: 8px 12px;
  font-size: calc(13px * var(--font-scale));
  border-radius: 10px;
  font-weight: 600;
}
#screen-room .actions .btn,
#screen-room .actions .btn-outline {
  padding: 7px 12px;
  font-size: calc(12.5px * var(--font-scale));
}
#screen-room .dice-box .btn {
  padding: 8px 12px;
  font-size: calc(13px * var(--font-scale));
}
#screen-room .chat-form .btn {
  padding: 8px 12px;
  font-size: calc(12.5px * var(--font-scale));
}
#screen-room .room-top-actions .seg button {
  padding: 6px 9px;
  font-size: calc(11.5px * var(--font-scale));
}
.room-title {
  flex: 1 1 180px;
  min-width: 0;
  overflow: hidden;
}
.room-title .title-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}
.room-title .title {
  font-size: calc(20px * var(--font-scale));
  font-weight: 750;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-title .room-id {
  flex-shrink: 0;
  font-size: calc(13px * var(--font-scale));
  font-weight: 600;
  color: var(--ink-3);
  white-space: nowrap;
}
.role-badge {
  flex-shrink: 0;
  padding: 8px 15px;
  border-radius: 999px;
  background: rgba(76, 141, 255, 0.16);
  color: var(--primary);
  font-size: calc(13px * var(--font-scale));
  font-weight: 700;
  border: 1px solid rgba(76, 141, 255, 0.25);
  white-space: nowrap;
}
.role-badge.spectator {
  background: rgba(240, 180, 41, 0.14);
  color: var(--accent);
  border-color: rgba(240, 180, 41, 0.28);
}

/* ===== 三栏布局：左玩家/聊天 · 中棋盘 · 右掷骰/记录 ===== */
.game-layout {
  display: grid;
  grid-template-columns: 250px minmax(280px, 1fr) 280px;
  gap: 14px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
  max-height: 100%;
}

.col-left, .col-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}
.col-left h2, .col-right h3, .history h3, .chat h3 {
  font-size: calc(13px * var(--font-scale));
  letter-spacing: 0.06em;
  color: var(--ink-2);
  margin-bottom: 10px;
  font-weight: 650;
  flex-shrink: 0;
}

.col-left .player-list { flex-shrink: 0; }
.col-left .actions { flex-shrink: 0; }
.col-left .spectators { flex-shrink: 0; margin-bottom: 0; }
.col-left .chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.col-left .chat-log {
  flex: 1;
  min-height: 80px;
  max-height: none;
}

.col-right .turn-card { flex-shrink: 0; margin-bottom: 0; }
.col-right .history {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.col-right .history-list {
  flex: 1;
  min-height: 60px;
  max-height: none;
}

/* 棋盘卡：填满中间列，画布等比 */
.col-mid.board-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  height: 100%;
}

/* ===== 规则弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.hidden { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 16, 0.72);
  backdrop-filter: blur(6px);
}
.modal-card {
  position: relative;
  width: min(480px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 8px;
}
.modal-head h2 {
  font-size: calc(18px * var(--font-scale));
  font-weight: 750;
}
.modal-close {
  appearance: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  color: var(--ink-2);
  font-size: calc(22px * var(--font-scale));
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}
.modal-body {
  padding: 8px 20px 22px;
}
.modal-body .rule-list {
  margin: 0 0 0 18px;
}

.player-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.player-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 13px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  min-width: 0;
}
.player-item.active {
  border-color: rgba(240, 180, 41, 0.5);
  background: rgba(240, 180, 41, 0.1);
}
.player-item .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12);
}
.player-item .nm {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: calc(14px * var(--font-scale));
  font-weight: 650;
}
.player-item .nm-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-item .color-tag {
  font-style: normal;
  flex-shrink: 0;
  font-size: calc(11px * var(--font-scale));
  font-weight: 600;
  color: var(--ink-3);
}
.player-item .st {
  flex-shrink: 0;
  font-size: calc(11px * var(--font-scale));
  color: var(--ink-3);
  white-space: nowrap;
}
.player-item.offline { opacity: 0.45; }

.actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.spectators h3 { display: flex; gap: 8px; align-items: center; }
.spectator-list { color: var(--ink-3); font-size: calc(13px * var(--font-scale)); line-height: 1.6; }

/* Board */
.board-wrap {
  position: relative;
  padding: 12px;
  overflow: hidden;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.04), transparent 55%),
    var(--card);
  box-sizing: border-box;
}
#board {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  /* 由 JS 按容器宽高设定画布像素，避免页面出滚动条 */
}
.board-overlay {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(12, 17, 24, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.25s;
  z-index: 5;
}
.board-overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-inner { text-align: center; padding: 20px; }
#overlay-title { font-size: calc(30px * var(--font-scale)); font-weight: 800; margin-bottom: 8px; }
#overlay-sub { color: var(--ink-2); font-size: calc(14px * var(--font-scale)); line-height: 1.5; }

/* Side panel */
.turn-card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 16px;
  margin-bottom: 16px;
}
.turn-label { color: var(--ink-3); font-size: calc(12px * var(--font-scale)); letter-spacing: 0.04em; }
.turn-color { font-size: calc(22px * var(--font-scale)); font-weight: 800; margin: 6px 0 14px; }
.dice-box { display: flex; align-items: center; gap: 12px; }
.dice {
  width: 58px;
  height: 58px;
  border-radius: 15px;
  background: linear-gradient(160deg, #ffffff, #dce6f1);
  color: #17202c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(28px * var(--font-scale));
  font-weight: 850;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.1), 0 6px 16px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}
.dice-box .btn { width: auto; flex: 1; }

/* 投掷记录 */
.history { margin-bottom: 16px; }
.history-list {
  max-height: 180px;
  overflow-y: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: calc(12px * var(--font-scale));
  color: var(--ink-2);
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}
.history-item .hi-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.history-item .hi-name {
  font-weight: 650;
  color: var(--ink);
  min-width: 2em;
  max-width: 4.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}
.history-item .hi-dice {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--card-2);
  color: var(--ink);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.history-item .hi-msg {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-3);
}

/* 规则 */
.rule-list {
  margin: 0 0 18px 18px;
  color: var(--ink-2);
  font-size: calc(13px * var(--font-scale));
  line-height: 1.65;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rule-list strong { color: var(--accent); font-weight: 700; }

.chat-log {
  height: 140px;
  overflow-y: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  font-size: calc(13px * var(--font-scale));
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-log .msg { color: var(--ink-2); line-height: 1.45; word-break: break-word; }
.chat-log .msg .who { color: var(--ink); font-weight: 650; margin-right: 6px; }
.chat-form { display: flex; gap: 8px; }
.chat-form input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  padding: 10px 12px;
  font-size: calc(13px * var(--font-scale));
  outline: none;
}
.chat-form .btn { width: auto; padding: 10px 13px; font-size: calc(13px * var(--font-scale)); }

/* ===== 中央 3D 骰子动画 ===== */
.dice-stage {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(8, 12, 18, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dice-stage.hidden { display: none !important; }
.dice-stage-inner { text-align: center; }
.dice-stage-label {
  font-size: calc(18px * var(--font-scale));
  font-weight: 700;
  margin-bottom: 28px;
  letter-spacing: 0.08em;
}

.dice-scene {
  width: 180px;
  height: 180px;
  margin: 0 auto 28px;
  perspective: 700px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.dice-scene::after {
  content: "";
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 90px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  filter: blur(8px);
}

/* 3D 骰子旁的大号点数，保证能看清 */
.dice-big-num {
  position: absolute;
  right: -8px;
  top: -8px;
  min-width: 48px;
  height: 48px;
  padding: 0 10px;
  border-radius: 14px;
  background: rgba(240, 180, 41, 0.95);
  color: #1a1408;
  font-size: calc(28px * var(--font-scale));
  font-weight: 850;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.35;
  transform: scale(0.85);
  transition: opacity 0.2s, transform 0.25s;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.dice-big-num.show {
  opacity: 1;
  transform: scale(1);
}

.dice-cube {
  width: 100px;
  height: 100px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(0deg) rotateY(0deg);
  transition: transform 0.75s cubic-bezier(0.2, 0.85, 0.25, 1);
}

.dice-cube.rolling {
  transition: transform 0.1s linear;
}

.dice-cube.settled {
  transition: transform 0.7s cubic-bezier(0.18, 0.9, 0.28, 1);
}

.dice-cube .face {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 16px;
  background: linear-gradient(145deg, #ffffff 0%, #e8eef6 55%, #cfd9e6 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.7),
    inset 0 -6px 12px rgba(0, 0, 0, 0.08);
  display: block;
}

/* 六面对照：1前 2右 3后 4左 5上 6下 */
.dice-cube .f1 { transform: translateZ(50px); }
.dice-cube .f2 { transform: rotateY(90deg) translateZ(50px); }
.dice-cube .f3 { transform: rotateY(180deg) translateZ(50px); }
.dice-cube .f4 { transform: rotateY(-90deg) translateZ(50px); }
.dice-cube .f5 { transform: rotateX(90deg) translateZ(50px); }
.dice-cube .f6 { transform: rotateX(-90deg) translateZ(50px); }

.pip {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a5568, #1a2230);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.25);
}
.pip.c  { top: 41px; left: 41px; }
.pip.tl { top: 16px; left: 16px; }
.pip.tr { top: 16px; left: 66px; }
.pip.ml { top: 41px; left: 16px; }
.pip.mr { top: 41px; left: 66px; }
.pip.bl { top: 66px; left: 16px; }
.pip.br { top: 66px; left: 66px; }

.dice-stage-note {
  color: var(--ink-2);
  font-size: calc(18px * var(--font-scale));
  letter-spacing: 0.14em;
  min-height: 1.5em;
  font-weight: 600;
}
.dice-stage-note.pop {
  animation: note-pop 0.35s ease;
}
@keyframes note-pop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(24, 34, 49, 0.97);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 12px 18px;
  border-radius: 13px;
  font-size: calc(14px * var(--font-scale));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  max-width: min(420px, 90vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 移动端：掷骰 → 棋盘 → 玩家 → 记录 → 聊天，全部通栏 ===== */
@media (max-width: 980px) {
  .game-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    gap: 12px;
  }

  .col-left, .col-right { display: contents; }

  .turn-card,
  .board-wrap,
  .player-list,
  .actions,
  .spectators,
  .history,
  .chat {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0;
    box-sizing: border-box;
    margin-bottom: 0;
  }

  /* 左列标题「玩家」在 list 上方 */
  .turn-card { order: 1; }
  .board-wrap { order: 2; }
  .col-left > h2 { order: 3; margin-bottom: 8px; }
  .player-list { order: 4; }
  .actions { order: 5; }
  .spectators { order: 6; }
  .history { order: 7; }
  .chat { order: 8; }

  .lobby-grid {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 12px;
  }
  .lobby-grid > .card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .span-2 { grid-column: auto; }
}

@media (max-width: 560px) {
  .screen { padding: 14px 12px 28px; width: 100%; box-sizing: border-box; }
  .card {
    padding: 16px;
    width: 100%;
    box-sizing: border-box;
  }
  .room-top { flex-wrap: wrap; width: 100%; }
  .room-top-actions {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }
  .seg button { padding: 8px 10px; }
  .seg.compact button { padding: 8px 9px; }
  .dice-scene { width: 130px; height: 130px; }
  .dice-cube, .dice-cube .face { width: 84px; height: 84px; }
  .dice-cube .face { border-radius: 14px; }
  .dice-cube .f1 { transform: translateZ(42px); }
  .dice-cube .f2 { transform: rotateY(90deg) translateZ(42px); }
  .dice-cube .f3 { transform: rotateY(180deg) translateZ(42px); }
  .dice-cube .f4 { transform: rotateY(-90deg) translateZ(42px); }
  .dice-cube .f5 { transform: rotateX(90deg) translateZ(42px); }
  .dice-cube .f6 { transform: rotateX(-90deg) translateZ(42px); }
  .pip { width: 14px; height: 14px; }
  .pip.c  { top: 35px; left: 35px; }
  .pip.tl { top: 12px; left: 12px; }
  .pip.tr { top: 12px; left: 58px; }
  .pip.ml { top: 35px; left: 12px; }
  .pip.mr { top: 35px; left: 58px; }
  .pip.bl { top: 58px; left: 12px; }
  .pip.br { top: 58px; left: 58px; }
}
