:root {
  --felt: #1a5c38;
  --felt-dark: #0f3d25;
  --rim: #5c3d1e;
  --rim-light: #8b6914;
  --gold: #e8c547;
  --cream: #f5e6c8;
  --danger: #c0392b;
  --danger-hover: #e74c3c;
  --panel-bg: rgba(0, 0, 0, 0.45);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --dice-size: 42px;
  --action-btn-gap: 0.5rem;
}

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

body {
  font-family: 'Noto Sans TC', system-ui, sans-serif;
  background: radial-gradient(ellipse at center, #1a2838 0%, #0a0f14 70%);
  min-height: 100vh;
  color: var(--cream);
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

img,
picture,
svg,
video,
canvas {
  -webkit-user-drag: none;
  user-drag: none;
}

body ::selection {
  background: transparent;
  color: inherit;
}

input::selection,
textarea::selection {
  background: rgba(94, 184, 255, 0.35);
  color: inherit;
}

#app {
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(0.75rem, 3vw, 1.5rem);
  padding-left: max(clamp(0.75rem, 3vw, 1.5rem), env(safe-area-inset-left, 0px));
  padding-right: max(clamp(0.75rem, 3vw, 1.5rem), env(safe-area-inset-right, 0px));
  align-items: center;
  justify-content: center;
}

.screen.active {
  display: flex;
}

#screen-lobby.active {
  position: relative;
}

.lobby-footer-meta {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  width: min(360px, calc(100vw - 2rem));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
  pointer-events: none;
}

#screen-lobby:not(.active) .lobby-footer-meta {
  display: none;
}

.lobby-version {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: rgba(232, 197, 71, 0.65);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.dev-changelog {
  pointer-events: auto;
  width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid rgba(232, 197, 71, 0.3);
  background: rgba(8, 12, 18, 0.92);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  text-align: left;
}

.dev-changelog-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold, #e8c547);
  margin-bottom: 0.35rem;
}

.dev-changelog-body {
  font-size: 0.8rem;
  line-height: 1.5;
  color: rgba(245, 230, 200, 0.9);
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.lobby-footer-meta .lobby-version {
  align-self: flex-end;
  margin-top: 0.15rem;
}

/* Lobby */
.lobby-card,
.waiting-card {
  background: linear-gradient(145deg, #2a3544, #1a222d);
  border: 1px solid rgba(232, 197, 71, 0.25);
  border-radius: 18px;
  padding: 2.15rem;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
}

.lobby-card-wide {
  max-width: 452px;
}

.rules-panel {
  width: 100%;
  text-align: left;
  margin-bottom: 1.25rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(232, 197, 71, 0.2);
  border-radius: 12px;
  padding: 0.65rem 1rem 0.85rem;
}

.rules-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--gold);
  font-size: 0.95rem;
  list-style: none;
  user-select: none;
}

.rules-panel summary::-webkit-details-marker {
  display: none;
}

.rules-panel summary::after {
  content: ' ▾';
  opacity: 0.6;
  font-size: 0.8rem;
}

.rules-panel[open] summary::after {
  content: ' ▴';
}

.rules-list {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  font-size: 0.82rem;
  line-height: 1.65;
  opacity: 0.9;
}

.rules-list li {
  margin-bottom: 0.35rem;
}

.rules-list strong {
  color: var(--gold);
  font-weight: 600;
}

.character-picker {
  width: 100%;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.character-picker-preview {
  position: relative;
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.character-picker-loading .character-picker-preview::after {
  content: '載入角色…';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  opacity: 0.65;
  pointer-events: none;
}

.character-picker-loading .character-picker-preview-face {
  visibility: hidden;
}

.character-picker-preview-face {
  width: 80px;
  height: 80px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 2px dashed rgba(232, 197, 71, 0.45);
  background: rgba(0, 0, 0, 0.3);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
}

.character-picker-preview-face:has(.character-face-img) {
  border-style: solid;
  border-color: rgba(232, 197, 71, 0.4);
  background: rgba(0, 0, 0, 0.25);
}

.character-picker-preview-face .character-face-img {
  width: 88%;
  height: 88%;
  object-fit: contain;
}

.btn-character-pick {
  min-width: 9rem;
}

.character-picker-modal {
  position: fixed;
  inset: 0;
  z-index: 88;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.72);
}

.character-picker-modal.hidden {
  display: none;
}

.character-picker-dialog {
  width: 100%;
  max-width: min(520px, calc(100vw - 2rem));
  max-height: min(88vh, 620px);
  padding: 1.15rem 1.2rem 1rem;
  border-radius: 14px;
  background: linear-gradient(160deg, #2a3544, #1a222d);
  border: 1px solid rgba(232, 197, 71, 0.28);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
}

.character-picker-dialog h3 {
  margin: 0 0 0.85rem;
  font-size: 1.1rem;
  text-align: center;
  color: var(--gold, #e8c547);
}

.character-picker-random-slot {
  display: flex;
  justify-content: center;
  margin: 0 0 0.55rem;
}

.character-picker-random-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.55rem;
  border-radius: 10px;
  border: 2px dashed rgba(232, 197, 71, 0.45);
  background: rgba(0, 0, 0, 0.3);
  font-family: inherit;
  color: var(--cream);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, background 0.15s, box-shadow 0.2s;
}

.character-picker-random-btn:hover {
  border-color: rgba(232, 197, 71, 0.65);
  background: rgba(232, 197, 71, 0.1);
}

.character-picker-random-btn.selected {
  border-style: solid;
  border-color: var(--gold);
  background: rgba(232, 197, 71, 0.14);
  box-shadow: 0 0 0 1px rgba(232, 197, 71, 0.25);
}

.character-picker-random-btn:active {
  transform: scale(0.96);
}

.character-picker-random-avatar {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--gold, #e8c547);
}

.character-picker-preview-face .character-picker-random-mark {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--gold, #e8c547);
}

.character-picker-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
  overflow-y: auto;
  padding: 0.15rem 0.1rem 0.35rem;
  margin-bottom: 0.65rem;
  -webkit-overflow-scrolling: touch;
}

.character-picker-dialog-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.character-picker-dialog-actions #btn-character-picker-cancel {
  margin-right: auto;
  flex-shrink: 0;
}

.character-picker-dialog-actions #btn-character-picker-confirm {
  flex-shrink: 0;
  min-width: 5.5rem;
}

.character-picker-grid .character-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0.45rem 0.35rem;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  font-family: inherit;
  color: var(--cream);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, background 0.15s;
}

.character-picker-grid .character-option:hover {
  border-color: rgba(232, 197, 71, 0.45);
  background: rgba(232, 197, 71, 0.08);
}

.character-picker-grid .character-option.selected {
  border-color: var(--gold);
  background: rgba(232, 197, 71, 0.14);
  box-shadow: 0 0 0 1px rgba(232, 197, 71, 0.25);
}

.character-picker-grid .character-option:active {
  transform: scale(0.96);
}

.character-picker-grid .character-option-avatar.has-char-img {
  width: 56px;
  height: 56px;
}

.character-picker-grid .character-option-avatar.is-loading {
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  animation: picker-avatar-pulse 0.9s ease-in-out infinite;
}

.character-picker-grid .character-option-avatar .character-face-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.character-picker-grid .character-option-avatar.is-loading .character-face-img {
  opacity: 0;
}

@keyframes picker-avatar-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.85; }
}

.character-option-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.character-option-avatar.has-char-img {
  width: 48px;
  height: 48px;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
}

.character-option-name {
  font-size: 0.7rem;
  opacity: 0.85;
}

.waiting-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.waiting-card h2 {
  width: 100%;
  font-size: 1.35rem;
  line-height: 1.4;
  padding-right: 2.25rem;
  box-sizing: border-box;
}

.waiting-settings-btn {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 2;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid rgba(232, 197, 71, 0.35);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--gold, #e8c547);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.waiting-settings-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(232, 197, 71, 0.6);
  transform: scale(1.05);
}

.waiting-settings-btn.hidden {
  display: none;
}

.waiting-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  margin-top: 0.25rem;
}

.waiting-actions .btn {
  width: 100%;
  display: block;
}

.waiting-actions .btn-ghost {
  margin-top: 0.25rem;
}

.title {
  font-size: 1.9rem;
  text-align: center;
  color: var(--gold);
  margin-bottom: 0.25rem;
  letter-spacing: 0.12em;
}

.subtitle {
  text-align: center;
  opacity: 0.75;
  font-size: 0.88rem;
  margin-bottom: 1.65rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  opacity: 0.8;
}

.form-group input,
.code-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  color: var(--cream);
  font-size: 1rem;
  font-family: inherit;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: 700;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.join-row {
  display: flex;
  gap: 0.5rem;
}

.join-row .code-input {
  flex: 1;
  max-width: 11.5rem;
}

.room-code-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 0.5rem;
}

.room-code-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.room-code-value {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
}

.btn-copy-room-code {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(232, 197, 71, 0.45);
  background: rgba(0, 0, 0, 0.35);
  color: var(--gold, #e8c547);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.btn-copy-room-code-icon {
  width: 1rem;
  height: 1rem;
  display: block;
}

.btn-copy-room-code-icon--ok {
  display: none;
}

.btn-copy-room-code.is-copied .btn-copy-room-code-icon--copy {
  display: none;
}

.btn-copy-room-code.is-copied .btn-copy-room-code-icon--ok {
  display: block;
  color: #7dcea0;
}

.btn-copy-room-code.is-failed {
  border-color: rgba(192, 57, 43, 0.55);
  color: #e88a7a;
}

.btn-copy-room-code:hover:not(:disabled) {
  background: rgba(232, 197, 71, 0.15);
}

.btn-copy-room-code:disabled {
  opacity: 0.65;
  cursor: default;
}

.room-badge .room-code-inline {
  margin-left: 0.25rem;
}

.room-badge .room-code-value {
  letter-spacing: 0.1em;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(180deg, #d4a82a, #9a7018);
  color: #1a1208;
  box-shadow: 0 4px 0 #5c4010;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: var(--cream);
}

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

.btn-danger {
  background: linear-gradient(180deg, var(--danger-hover), var(--danger));
  color: white;
  box-shadow: 0 4px 0 #7b241c;
}

.btn-ghost {
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
}

.error-msg {
  color: #ff6b6b;
  font-size: 0.9rem;
  margin-top: 1rem;
  text-align: center;
}

.error-msg.hidden,
.hidden {
  display: none !important;
}

.player-list {
  list-style: none;
  margin: 1.25rem 0;
  width: 100%;
  text-align: left;
}

.player-list li {
  padding: 0.6rem 1rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.player-list li .player-meta {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.player-list li .tag {
  font-size: 0.72rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.player-list li .tag-host {
  color: var(--gold);
  border: 1px solid rgba(232, 197, 71, 0.4);
}

.player-list li .tag-bot {
  color: #7ec8ff;
  border: 1px solid rgba(126, 200, 255, 0.35);
}

.player-list li .tag-spectator {
  color: #b8a0e8;
  border: 1px solid rgba(184, 160, 232, 0.4);
}

.waiting-player-row {
  position: relative;
}

.btn-remove-bot {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin: 0;
  border: 1px solid rgba(255, 120, 120, 0.45);
  border-radius: 6px;
  background: rgba(180, 50, 50, 0.25);
  color: #ffb0b0;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.btn-remove-bot:hover {
  background: rgba(200, 60, 60, 0.45);
  color: #fff;
}

.room-settings-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.72);
}

.room-settings-modal.hidden {
  display: none;
}

.room-settings-dialog {
  position: relative;
  width: 100%;
  max-width: 360px;
  padding: 1.25rem 1.35rem 1.1rem;
  border-radius: 14px;
  background: linear-gradient(160deg, #2a3544, #1a222d);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.room-settings-reset-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid rgba(232, 197, 71, 0.35);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--gold, #e8c547);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.15s;
}

.room-settings-reset-btn:hover {
  background: rgba(232, 197, 71, 0.15);
}

.room-settings-reset-btn:active {
  transform: scale(0.94);
}

.room-settings-dialog h3 {
  margin: 0 0 1rem;
  padding: 0 2rem;
  font-size: 1.15rem;
  text-align: center;
  box-sizing: border-box;
}

.room-setting-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

.room-setting-stepper {
  width: 100%;
  justify-content: center;
}

.room-setting-stepper .room-setting-input {
  flex: 1;
  max-width: 5.5rem;
  text-align: center;
  cursor: default;
  user-select: none;
}

.room-setting-step-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: var(--cream);
  font-size: 1.2rem;
  cursor: pointer;
}

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

.room-setting-input {
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.room-settings-dialog-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.5rem;
}

.room-settings-dialog-actions #btn-room-settings-cancel {
  margin-right: auto;
  flex-shrink: 0;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.room-settings-dialog-actions #btn-room-settings-save {
  flex: 0 0 auto;
  padding: 0.65rem 0.85rem;
  font-size: 0.92rem;
  white-space: nowrap;
}

.hint {
  opacity: 0.7;
  font-size: 0.9rem;
  text-align: center;
  width: 100%;
}

/* Game screen */
#screen-game {
  flex-direction: column;
  padding: 0.15rem clamp(0.5rem, 2.5vw, 1rem)
    max(6.75rem, calc(5.5rem + env(safe-area-inset-bottom, 0px)));
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* 左下：按鈕在底，點擊後內容框在按鈕上方展開 */
.game-side-dock,
.game-chat {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left, 0px));
  bottom: max(5.5rem, calc(4.5rem + env(safe-area-inset-bottom, 0px)));
  z-index: 48;
  display: none;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 0.35rem;
  pointer-events: auto;
}

.room-dock:not([hidden]) {
  display: flex;
}

body.room-ui-waiting .room-dock:not([hidden]) {
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
}

body.room-ui-game .room-dock:not([hidden]) {
  bottom: max(5.5rem, calc(4.5rem + env(safe-area-inset-bottom, 0px)));
}

.game-side-dock-panel {
  display: none;
  flex-direction: column;
  width: min(400px, 72vw);
  min-height: min(380px, calc(100vh - 13rem));
  max-height: min(520px, calc(100vh - 9rem));
  border-radius: 10px;
  border: 1px solid rgba(232, 197, 71, 0.45);
  background: linear-gradient(165deg, #2a4a3a 0%, #1e3d2e 55%, #163528 100%);
  backdrop-filter: blur(8px);
  overflow: hidden;
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.game-side-dock.is-open .game-side-dock-panel {
  display: flex;
}

.game-side-dock-triggers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.game-dock-trigger {
  position: relative;
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid rgba(139, 105, 20, 0.55);
  background: linear-gradient(180deg, #2d4a38 0%, #1a3d28 100%);
  color: var(--cream);
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.game-dock-trigger-badge {
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #e74c3c;
  border: 1.5px solid rgba(12, 18, 14, 0.9);
  box-shadow: 0 0 6px rgba(231, 76, 60, 0.85);
  pointer-events: none;
}

html.game-layout-mobile .game-dock-trigger-badge {
  top: 0.12rem;
  right: 0.12rem;
}

.game-dock-trigger:hover {
  border-color: var(--gold);
  background: linear-gradient(180deg, #3a5c48 0%, #245238 100%);
}

.game-dock-trigger.is-active {
  border-color: var(--gold);
  background: linear-gradient(180deg, #4a7058 0%, #2d5a42 100%);
  color: #fff8e8;
}

.game-dock-trigger-icon {
  display: none;
  line-height: 1;
}

.game-dock-trigger-text {
  line-height: 1.2;
}

/* 網頁版：本局紀錄旁投擲道具 */
.game-toss-tools {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.15rem;
}

html.game-layout-mobile .game-toss-tools {
  display: none !important;
}

.game-toss-tools.hidden {
  display: none !important;
}

.game-toss-picker-wrap {
  position: relative;
}

.game-toss-icon-btn {
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(139, 105, 20, 0.55);
  background: linear-gradient(180deg, #3d5c4a 0%, #243d30 100%);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-toss-icon-btn:hover,
.game-toss-icon-btn.is-open {
  border-color: var(--gold);
}

.game-toss-picker-menu {
  position: absolute;
  bottom: calc(100% + 0.35rem);
  left: 0;
  display: flex;
  gap: 0.25rem;
  padding: 0.35rem;
  border-radius: 10px;
  border: 1px solid rgba(232, 197, 71, 0.45);
  background: linear-gradient(165deg, #2a4a3a 0%, #163528 100%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  z-index: 52;
}

.game-toss-picker-menu.hidden {
  display: none;
}

.game-toss-pick {
  width: 2rem;
  height: 2rem;
  padding: 0.15rem;
  border-radius: 50%;
  border: 1px solid transparent;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toss-picker-icon,
.toss-pick-icon {
  width: 1.35rem;
  height: 1.35rem;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.toss-picker-icon.toss-icon-lg,
.toss-pick-icon.toss-icon-lg {
  width: 1.52rem;
  height: 1.52rem;
}

.game-toss-pick:hover,
.game-toss-pick.is-selected {
  border-color: var(--gold);
  background: rgba(232, 197, 71, 0.15);
}

.game-toss-send-btn {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid rgba(139, 105, 20, 0.55);
  background: linear-gradient(180deg, #4a7058 0%, #2d5a42 100%);
  color: var(--cream);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.game-toss-send-btn:hover:not(:disabled) {
  border-color: var(--gold);
}

.game-toss-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.game-toss-send-btn.is-aiming {
  border-color: #e8a050;
  background: linear-gradient(180deg, #6a5030 0%, #4a3820 100%);
  color: #fff4d8;
}

.game-toss-send-btn.is-toss-penalty {
  border-color: rgba(192, 57, 43, 0.55);
  background: linear-gradient(180deg, #5a3530 0%, #3a2220 100%);
  color: #e8b0a8;
}

html.toss-aim-active.toss-rate-penalty #screen-game.active .seat-character-wrap:not(.empty)[data-player-id]:not(.is-you) {
  cursor: not-allowed;
  opacity: 0.72;
  outline-color: rgba(192, 57, 43, 0.45);
}

html.toss-aim-active #screen-game.active .seat-character-wrap:not(.empty)[data-player-id]:not(.is-you) {
  cursor: crosshair;
  outline: 2px dashed rgba(232, 197, 71, 0.75);
  outline-offset: 3px;
  border-radius: 10px;
}

html.toss-aim-active #screen-game.active .seat-character-wrap.is-you {
  opacity: 0.55;
}

.toss-fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 120;
  overflow: hidden;
}

.toss-fx-fly {
  position: fixed;
  left: 0;
  top: 0;
  line-height: 0;
  pointer-events: none;
  will-change: transform;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
  z-index: 121;
}

.toss-fx-fly .toss-fx-icon {
  width: 3.15rem;
  height: 3.15rem;
  object-fit: contain;
  display: block;
}

.toss-fx-pop {
  position: fixed;
  left: 0;
  top: 0;
  line-height: 0;
  pointer-events: none;
  animation: toss-pop 0.45s ease-out forwards;
  z-index: 121;
}

.toss-fx-pop .toss-fx-icon {
  width: 2.8rem;
  height: 2.8rem;
  object-fit: contain;
  display: block;
}

@keyframes toss-pop {
  0% {
    transform: translate(var(--tx), var(--ty)) translate(-50%, -50%) scale(0.4);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) translate(-50%, -50%) scale(1.35);
    opacity: 0;
  }
}

.game-dock-pane {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.game-dock-pane.is-active {
  display: flex;
}

.game-history-list {
  margin: 0;
  padding: 0.5rem 0.55rem 0.6rem;
  list-style: none;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(232, 197, 71, 0.35) transparent;
  background: rgba(0, 0, 0, 0.22);
}

.game-history-empty {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  opacity: 0.55;
  text-align: center;
}

.game-history-item {
  margin: 0;
  padding: 0.4rem 0.45rem;
  border-radius: 8px;
  font-size: 0.74rem;
  line-height: 1.35;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.game-history-item--bid {
  border-left: 3px solid rgba(100, 200, 255, 0.65);
}

.game-history-item--drink {
  border-left: 3px solid rgba(232, 197, 71, 0.75);
}

.game-history-item--drink-positive {
  border-left-color: rgba(120, 220, 160, 0.75);
}

.game-history-item--drink-negative {
  border-left-color: rgba(255, 140, 120, 0.75);
}

.game-history-item .hist-drink-title {
  display: block;
  margin-bottom: 0.2rem;
}

.game-history-item .hist-drink-desc {
  display: block;
  opacity: 0.92;
  line-height: 1.4;
}

.game-history-item .hist-time {
  display: block;
  font-size: 0.65rem;
  opacity: 0.5;
  margin-bottom: 0.12rem;
}

.game-history-item .hist-body strong {
  color: var(--cream, #f5f0e6);
  font-weight: 600;
}

.game-history-item .hist-bid-row {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  vertical-align: middle;
  margin: 0 0.1rem;
}

.game-history-item .hist-bid-qty {
  white-space: nowrap;
}

.game-history-item .hist-bid-row .die.die-pips.mini {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  flex-shrink: 0;
  display: inline-grid;
  vertical-align: middle;
}

.game-history-item .hist-bid-row .die.mini.die-pips .pip {
  width: 4px;
  height: 4px;
}

.game-history-item .hist-sub {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  opacity: 0.78;
}

.game-history-item .hist-highlight {
  color: var(--gold, #e8c547);
  font-weight: 700;
}

.game-history-item--challenge {
  border-left-color: rgba(231, 76, 60, 0.75);
}

.game-history-item--reveal {
  border-left-color: rgba(155, 89, 182, 0.8);
}

.game-history-item--coin {
  border-left-color: rgba(241, 196, 15, 0.85);
}

.game-history-item .hist-coin-heads {
  color: #7dcea0;
  font-weight: 700;
}

.game-history-item .hist-coin-tails {
  color: #f1948a;
  font-weight: 700;
}

.game-history-item .hist-tag {
  font-size: 0.62rem;
  opacity: 0.65;
  margin-left: 0.2rem;
}

html.game-layout-mobile .game-side-dock-panel {
  min-height: min(200px, 32vh);
  max-height: min(280px, 42vh);
}

html.game-layout-mobile .game-side-dock-triggers {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  max-width: none;
}

html.game-layout-mobile .game-dock-trigger {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  min-width: 0;
  padding: 0;
  font-size: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

html.game-layout-mobile .game-dock-trigger-icon {
  display: block;
  font-size: 1.15rem;
}

html.game-layout-mobile .game-dock-trigger-text {
  display: none;
}

html.game-layout-mobile body.room-ui-waiting .room-dock:not([hidden]) {
  bottom: max(0.65rem, env(safe-area-inset-bottom, 0px));
}

html.game-layout-mobile body.room-ui-game .room-dock:not([hidden]) {
  /* --mobile-action-bar-h 由 JS 依 #action-bar 實際高度寫入 */
  bottom: calc(var(--mobile-action-bar-h, 9rem) + 0.2rem);
  z-index: 54;
}

html.game-layout-mobile .game-history-item {
  font-size: 0.7rem;
}

html.game-layout-mobile .game-history-item .hist-drink-desc {
  font-size: 0.68rem;
}

.game-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.55rem 0.65rem;
  font-size: 0.84rem;
  line-height: 1.4;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.22);
}

.game-chat-line {
  margin: 0 0 0.4rem;
  word-break: break-word;
  color: var(--cream);
}

.game-chat-name {
  font-weight: 700;
}

/* 六座位各一色（與牌桌座位 index 對應） */
.game-chat-line--seat-0 .game-chat-name {
  color: #6eb5ff;
}

.game-chat-line--seat-1 .game-chat-name {
  color: #ff9f5a;
}

.game-chat-line--seat-2 .game-chat-name {
  color: #c89bff;
}

.game-chat-line--seat-3 .game-chat-name {
  color: #ff7eb8;
}

.game-chat-line--seat-4 .game-chat-name {
  color: #f0e06a;
}

.game-chat-line--seat-5 .game-chat-name {
  color: #5ce0b0;
}

.game-chat-line-you .game-chat-name {
  text-shadow: 0 0 10px currentColor;
}

.game-chat-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem;
  border-top: 1px solid rgba(232, 197, 71, 0.25);
  background: rgba(15, 30, 22, 0.65);
}

#game-chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid rgba(139, 105, 20, 0.5);
  background: var(--cream);
  color: #1a2838;
  font-size: 0.85rem;
  font-family: inherit;
}

#game-chat-input::placeholder {
  color: rgba(26, 40, 56, 0.55);
}

#game-chat-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(232, 197, 71, 0.35);
}

#game-chat-send {
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
  white-space: nowrap;
  border-color: rgba(232, 197, 71, 0.4);
  background: rgba(232, 197, 71, 0.15);
  color: var(--cream);
}

.game-header {
  position: relative;
  z-index: 40;
  text-align: center;
  width: 100%;
  margin: 0 0 0.35rem;
  flex-shrink: 0;
  /* 全寬標題列勿擋住左上設定、右上離開 */
  pointer-events: none;
}

.game-header :is(button, a, input, select, textarea, label) {
  pointer-events: auto;
}

.room-badge {
  font-size: 0.8rem;
  opacity: 0.6;
  letter-spacing: 0.1em;
}

.drunk-status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
  max-width: 100%;
}

.drunk-status-bar.hidden {
  display: none;
}

.drunk-card {
  flex: 1 1 200px;
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  text-align: left;
}

.drunk-card.drunk-positive {
  border-color: rgba(46, 204, 113, 0.45);
  background: rgba(46, 204, 113, 0.12);
}

.drunk-card.drunk-negative {
  border-color: rgba(231, 76, 60, 0.45);
  background: rgba(231, 76, 60, 0.12);
}

.drunk-card.drunk-neutral {
  border-color: rgba(241, 196, 15, 0.4);
  background: rgba(241, 196, 15, 0.1);
}

.drunk-card-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold, #e8c547);
}

.drunk-card-desc {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.35;
}

.drunk-card-extra {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.35;
}

.wine-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  font-size: 0.72rem;
  margin-left: 0.2rem;
  opacity: 0.95;
  vertical-align: middle;
}

.wine-icon {
  width: 1.05em;
  height: 1.05em;
  object-fit: contain;
  vertical-align: -0.12em;
  display: inline-block;
  flex-shrink: 0;
}

.wine-icon--btn {
  width: 1.15rem;
  height: 1.15rem;
  vertical-align: middle;
  margin-right: 0.15rem;
}

.wine-icon--badge {
  width: 0.95em;
  height: 0.95em;
}

.wine-icon--dock {
  width: 0.9em;
  height: 0.9em;
}

.wine-icon--seat {
  width: 0.85em;
  height: 0.85em;
}

.wine-icon--mobile {
  width: 1rem;
  height: 1rem;
  vertical-align: -0.2em;
}

.wine-icon--overlay {
  width: 1.25rem;
  height: 1.25rem;
  vertical-align: -0.25em;
}

html:not(.game-layout-mobile) .wine-icon--badge {
  width: 1.2em;
  height: 1.2em;
}

html:not(.game-layout-mobile) .wine-icon--dock {
  width: 1.15em;
  height: 1.15em;
}

html:not(.game-layout-mobile) .wine-icon--seat {
  width: 1.1em;
  height: 1.1em;
}

html:not(.game-layout-mobile) .wine-icon--btn {
  width: 1.35rem;
  height: 1.35rem;
}

html:not(.game-layout-mobile) .wine-icon--overlay {
  width: 1.5rem;
  height: 1.5rem;
}

html:not(.game-layout-mobile) .wine-badge {
  font-size: 0.82rem;
}

.wine-count {
  font-weight: 700;
}

.seat-mobile-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}

.mobile-stat-wine {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.die.die-drowsy {
  background: linear-gradient(145deg, #4a5568, #2d3748);
  color: #f6e05e;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.05em;
}

.die.die-borrowed {
  background: linear-gradient(145deg, #5d4e37, #3d3428);
  color: #a0aec0;
  border: 1px dashed rgba(160, 174, 192, 0.55);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.04em;
  opacity: 0.92;
}

.die.die-illusion {
  background: linear-gradient(145deg, #9f7aea, #6b46c1);
  color: #faf5ff;
  border: 1px dashed rgba(255, 255, 255, 0.45);
  box-shadow: 0 2px 0 #553c9a, 0 0 10px rgba(159, 122, 234, 0.45);
  opacity: 0.88;
}

.die.die-illusion.wild {
  color: #fef3c7;
}

.die.die-god {
  background: linear-gradient(145deg, #ffd56a, #d4a017);
  color: #fff8e1;
  border: 1px solid rgba(255, 240, 180, 0.95);
  box-shadow: 0 3px 0 #a67c00, 0 0 14px rgba(255, 215, 90, 0.5);
}

.die.die-god.wild {
  color: #fffef5;
}

.action-bar > .btn {
  flex: 0 0 auto;
  align-self: center;
  width: auto;
}

.action-bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--action-btn-gap);
  align-items: center;
  justify-content: center;
}

.action-bar-actions .action-btn {
  flex: 0 0 auto;
}

.action-btn {
  width: 96px;
  height: 48px;
  padding: 0;
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
  background: #161b22;
  border: 1px solid transparent;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.btn-call {
  background: #d6a21d;
  color: #2b1d00;
  border-color: #d6a21d;
}

.btn-call:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-drink {
  background: #111827;
  color: #ffd27a;
  border-color: #9b6a25;
}

.btn-drink:hover:not(:disabled) {
  filter: brightness(1.08);
  border-color: #b88030;
}

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

.btn-open {
  background: #111827;
  color: #ffd2cc;
  border-color: #d95c55;
}

.btn-open:hover:not(:disabled) {
  filter: brightness(1.08);
  border-color: #e87068;
}

.connection-banner {
  margin: 0.35rem 0 0;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  background: rgba(220, 160, 40, 0.2);
  border: 1px solid rgba(255, 200, 80, 0.45);
  color: #ffe08a;
  font-size: 0.88rem;
  text-align: center;
}

.game-message {
  font-size: 1.05rem;
  margin: 0.35rem 0;
  min-height: 1.5em;
  color: var(--gold);
}

.game-message.message-opening {
  font-size: 1.2rem;
  font-weight: 700;
  animation: message-opening-pulse 0.9s ease-in-out infinite;
}

@keyframes message-opening-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.03); }
}

.current-bid {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.4);
  padding: 0.4rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(232, 197, 71, 0.4);
}

.bid-value {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold);
}

.bid-value .bid-qty {
  line-height: 1;
}

.bid-value .die.die-pips.mini {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

/* Table */
.table-wrap {
  width: 100%;
  aspect-ratio: 1;
  max-height: min(78vw, 560px);
  margin: 0.65rem auto 0.2rem;
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.table-felt {
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at 50% 45%, var(--felt) 0%, var(--felt-dark) 85%);
  border-radius: 50%;
  position: relative;
  box-shadow:
    inset 0 0 60px rgba(0, 0, 0, 0.4),
    0 12px 40px rgba(0, 0, 0, 0.6);
}

.table-rim {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 14px solid var(--rim);
  box-shadow:
    inset 0 0 20px rgba(0, 0, 0, 0.5),
    0 0 0 4px var(--rim-light);
  pointer-events: none;
}

.seats {
  position: absolute;
  inset: 5% 8% -1% 8%;
}

.seat {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  overflow: visible;
}

.seat-edge-bottom {
  flex-direction: column-reverse;
  align-items: center;
}

.seat-edge-top {
  flex-direction: column;
  align-items: center;
}

.seat-edge-left {
  flex-direction: row;
  align-items: center;
}

.seat-edge-right {
  flex-direction: row-reverse;
  align-items: center;
}

.seat-character-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.seat-character-wrap.empty {
  display: none;
}

.seat-character-wrap.is-you .character-seat-name {
  color: #9fd4ff;
}

.seat-character-wrap.active-turn .seat-avatar {
  box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(232, 197, 71, 0.45);
}

.seat-character-wrap.dead {
  filter: grayscale(0.9) brightness(0.55);
  opacity: 0.65;
}

/* 頭巾兄弟：角色背後彩虹愛心 */
.bandana-heart-bg {
  position: absolute;
  left: 50%;
  z-index: 0;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  color: #ff5c9a;
  background: linear-gradient(160deg, #ff6b9d 0%, #ffd166 28%, #4ade80 52%, #38bdf8 76%, #c084fc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 6px rgba(255, 90, 160, 0.7));
}

@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .bandana-heart-bg {
    -webkit-text-fill-color: #ff5c9a;
    color: #ff5c9a;
    background: none;
  }
}

.seat-character-wrap.bandana-brother {
  position: relative;
}

.seat-character-wrap.bandana-brother .bandana-heart-bg {
  top: -6px;
  transform: translateX(-50%);
  font-size: 4.75rem;
}

.seat-character-wrap.bandana-brother .character-avatar.seat-avatar {
  position: relative;
  z-index: 1;
}

.mobile-player-char.bandana-brother-char {
  position: relative;
  overflow: visible;
  background: transparent;
  border-color: transparent;
}

.mobile-player-char.bandana-brother-char .bandana-heart-bg {
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 3.6rem;
}

.mobile-player-char.bandana-brother-char .mobile-player-avatar,
.mobile-player-char.bandana-brother-char .char-icon-img {
  position: relative;
  z-index: 1;
}

.character-avatar {
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  border: 3px solid rgba(255, 255, 255, 0.25);
}

.character-avatar.seat-avatar {
  width: 44px;
  height: 44px;
  font-size: 1.45rem;
  border-width: 2px;
}

.character-seat-name {
  font-size: 0.62rem;
  font-weight: 600;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.88;
}

/* 右下角角色 */
/* Debug tools (DEBUG=1 only, top-left below volume) */
.debug-tools {
  position: fixed;
  top: 4rem;
  left: 1rem;
  bottom: auto;
  z-index: 130;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding-top: max(0px, env(safe-area-inset-top, 0px));
  padding-left: max(0px, env(safe-area-inset-left, 0px));
}

.debug-tools.hidden {
  display: none !important;
}

.debug-tools-toggle {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid rgba(180, 120, 255, 0.45);
  background: rgba(40, 20, 50, 0.92);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.debug-tools-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(180, 120, 255, 0.35);
  background: rgba(20, 12, 28, 0.96);
  min-width: 220px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

.debug-tools-panel.hidden {
  display: none;
}

.debug-tools-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(200, 160, 255, 0.95);
}

.debug-tools-label {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.7);
}

.debug-drunk-select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 0.85rem;
}

.btn-debug-heads,
.btn-debug-action {
  width: 100%;
  font-size: 0.82rem;
  margin-top: 0.35rem;
}

.btn-debug-heads.active {
  border-color: rgba(46, 204, 113, 0.7);
  background: rgba(46, 204, 113, 0.2);
  color: #9fefb0;
}

.debug-tools-panel :disabled {
  opacity: 0.45;
}

.debug-coin-chances {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 11rem;
  overflow-y: auto;
}

.debug-coin-chances li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  font-size: 0.78rem;
  line-height: 1.35;
}

.debug-coin-name {
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
}

.debug-coin-pct {
  color: rgba(232, 197, 71, 0.95);
  font-weight: 700;
}

.debug-coin-meta {
  flex: 1 1 100%;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.5);
}

.debug-coin-chance-muted {
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.78rem;
}

.debug-coin-override {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.debug-coin-override input[type='range'] {
  flex: 1 1 auto;
  min-width: 0;
}

.debug-coin-chance-value {
  flex: 0 0 auto;
  min-width: 2.75rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: rgba(232, 197, 71, 0.95);
  text-align: right;
}

.debug-coin-override-btns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.btn-debug-coin-preset {
  width: 100%;
  font-size: 0.78rem;
  margin-top: 0;
  padding: 0.35rem 0.4rem;
}

.debug-coin-override-status {
  margin: 0.35rem 0 0.15rem;
  font-size: 0.75rem;
  color: rgba(200, 160, 255, 0.9);
  line-height: 1.35;
}

/* App settings (top-left gear, all screens) */
.sfx-settings {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  left: 1rem;
  bottom: auto;
  z-index: 130;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding-left: max(0px, env(safe-area-inset-left, 0px));
}

.sfx-settings-toggle {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(232, 197, 71, 0.35);
  background: rgba(10, 15, 20, 0.92);
  color: var(--gold, #e8c547);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sfx-settings-icon {
  font-size: 1.2rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

.sfx-settings-toggle[aria-expanded='true'] .sfx-settings-icon {
  transform: rotate(45deg);
}

.sfx-settings-toggle:hover {
  border-color: rgba(232, 197, 71, 0.65);
  background: rgba(255, 255, 255, 0.08);
  transform: scale(1.05);
}

.sfx-settings-panel {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid rgba(232, 197, 71, 0.25);
  background: rgba(10, 15, 20, 0.95);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  min-width: 220px;
}

.sfx-settings-panel.hidden {
  display: none;
}

.sfx-settings-heading {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gold, #e8c547);
}

.sfx-settings-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sfx-settings-row > label {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.75);
}

.sfx-settings-slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sfx-settings-slider-wrap input[type='range'] {
  flex: 1;
  min-width: 0;
  accent-color: var(--gold, #e8c547);
}

.sfx-settings-row--toggle {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.sfx-settings-label {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.75);
}

.sfx-toggle-btn {
  flex-shrink: 0;
  min-width: 2.75rem;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sfx-toggle-btn:hover {
  border-color: rgba(232, 197, 71, 0.5);
  background: rgba(255, 255, 255, 0.08);
}

.sfx-toggle-btn.is-on {
  border-color: rgba(232, 197, 71, 0.65);
  background: rgba(232, 197, 71, 0.18);
  color: var(--gold, #e8c547);
}

.sfx-volume-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gold, #e8c547);
  min-width: 2.5rem;
  text-align: right;
}

.character-dock {
  position: fixed;
  right: 1rem;
  bottom: 5.75rem;
  z-index: 55;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  pointer-events: none;
}

.character-dock.hidden {
  display: none;
}

.dock-speech {
  max-width: 160px;
  padding: 0.5rem 0.75rem;
  background: rgba(0, 0, 0, 0.82);
  border: 2px solid rgba(232, 197, 71, 0.5);
  border-radius: 12px 12px 4px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: right;
  white-space: pre-line;
  animation: speech-pop 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.dock-speech-bid {
  border-color: rgba(212, 168, 42, 0.7);
  color: #ffeaa7;
}

.dock-speech-challenge {
  border-color: rgba(231, 76, 60, 0.75);
  color: #ff9f8a;
  animation: speech-pop 0.35s ease, speech-shake 0.5s ease 0.1s;
}

.dock-speech-listen {
  border-color: rgba(100, 180, 255, 0.5);
  color: #b8dcff;
}

.dock-speech-nervous {
  border-color: rgba(180, 120, 255, 0.5);
  color: #e0c8ff;
}

@keyframes speech-pop {
  from {
    opacity: 0;
    transform: scale(0.7) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes speech-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.dock-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
  font-size: 3rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  border: 4px solid rgba(255, 255, 255, 0.3);
  transition: filter 0.3s, border-color 0.3s;
}

.dock-avatar.dead {
  filter: grayscale(0.85) brightness(0.5);
  opacity: 0.7;
}

.dock-avatar.dock-my-turn {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(232, 197, 71, 0.35), 0 8px 28px rgba(0, 0, 0, 0.5);
  animation: dock-idle-bob 2s ease-in-out infinite;
}

.dock-avatar.has-char-img {
  background: transparent !important;
  border: none;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
}

.dock-avatar.has-char-img .character-ring {
  display: none;
}

.dock-avatar.has-char-img.dock-my-turn {
  border: none;
  box-shadow: none;
  filter: drop-shadow(0 0 12px rgba(232, 197, 71, 0.55));
  animation: dock-idle-bob 2s ease-in-out infinite;
}

@keyframes dock-idle-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.dock-avatar.react-bid {
  animation: dock-react-bid 0.55s cubic-bezier(0.34, 1.5, 0.64, 1);
}

.dock-avatar.react-challenge {
  animation: dock-react-challenge 0.65s ease !important;
}

.dock-avatar.react-listen {
  animation: dock-react-listen 0.5s ease;
}

.dock-avatar.react-nervous {
  animation: dock-react-nervous 0.6s ease-in-out;
}

@keyframes dock-react-bid {
  0% { transform: scale(1) rotate(0); }
  30% { transform: scale(1.15) rotate(-8deg) translateY(-12px); }
  60% { transform: scale(1.08) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes dock-react-challenge {
  0%, 100% { transform: translateX(0) scale(1); }
  15% { transform: translateX(-14px) scale(1.1) rotate(-6deg); }
  30% { transform: translateX(14px) scale(1.12) rotate(6deg); }
  45% { transform: translateX(-10px) scale(1.08); }
  60% { transform: translateX(10px) scale(1.08); }
}

@keyframes dock-react-listen {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05) translateX(-6px); }
}

@keyframes dock-react-nervous {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-6deg); }
  40% { transform: rotate(6deg); }
  60% { transform: rotate(-4deg); }
  80% { transform: rotate(4deg); }
}

.character-ring {
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

.character-avatar.has-char-img {
  background: transparent !important;
  border: none;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
}

.character-avatar.has-char-img.seat-avatar {
  width: 52px;
  height: 52px;
}

.character-avatar.has-char-img .character-ring {
  display: none;
}

.character-face {
  position: relative;
  z-index: 1;
  width: 72%;
  height: 72%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  border-radius: 0;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.35));
}

.character-avatar.has-char-img .character-face,
.dock-avatar.has-char-img .character-face {
  width: 100%;
  height: 100%;
}

.character-face-img,
.char-icon-img,
.panel-char-icon-img,
.waiting-char-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 0;
  background: transparent;
}

.panel-char-icon {
  display: inline-flex;
  width: 1.75rem;
  height: 1.75rem;
  vertical-align: middle;
  overflow: visible;
  border-radius: 0;
  flex-shrink: 0;
  background: transparent;
}

.waiting-player-line {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.waiting-char-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.dock-name {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.85;
  text-align: right;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-felt.table-flash-bid {
  animation: table-pulse-gold 0.55s ease;
}

.table-felt.table-flash-challenge {
  animation: table-pulse-red 0.65s ease;
}

.table-felt.opening-pulse {
  animation: table-opening-pulse 1s ease-in-out infinite;
}

@keyframes table-opening-pulse {
  0%, 100% {
    box-shadow:
      inset 0 0 60px rgba(0, 0, 0, 0.4),
      0 12px 40px rgba(0, 0, 0, 0.6);
  }
  50% {
    box-shadow:
      inset 0 0 80px rgba(231, 76, 60, 0.35),
      0 0 48px rgba(231, 76, 60, 0.35),
      0 12px 40px rgba(0, 0, 0, 0.6);
  }
}

@keyframes table-pulse-gold {
  0%, 100% { box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.4), 0 12px 40px rgba(0, 0, 0, 0.6); }
  50% {
    box-shadow:
      inset 0 0 80px rgba(232, 197, 71, 0.25),
      0 0 40px rgba(232, 197, 71, 0.2),
      0 12px 40px rgba(0, 0, 0, 0.6);
  }
}

@keyframes table-pulse-red {
  0%, 100% { box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.4), 0 12px 40px rgba(0, 0, 0, 0.6); }
  40% {
    box-shadow:
      inset 0 0 70px rgba(192, 57, 43, 0.35),
      0 0 36px rgba(231, 76, 60, 0.25),
      0 12px 40px rgba(0, 0, 0, 0.6);
  }
}

.char-fox,
.character-option-avatar.char-fox,
.character-avatar.char-fox { background: linear-gradient(145deg, #e74c3c, #922b21); }
.char-wolf,
.character-option-avatar.char-wolf,
.character-avatar.char-wolf { background: linear-gradient(145deg, #5d6d7e, #2c3e50); }
.char-dog,
.character-option-avatar.char-dog,
.character-avatar.char-dog { background: linear-gradient(145deg, #d4a574, #8b6914); }
.char-cat,
.character-option-avatar.char-cat,
.character-avatar.char-cat { background: linear-gradient(145deg, #8e44ad, #4a235a); }
.char-rabbit,
.character-option-avatar.char-rabbit,
.character-avatar.char-rabbit { background: linear-gradient(145deg, #ecf0f1, #95a5a6); }
.char-rat,
.character-option-avatar.char-rat,
.character-avatar.char-rat { background: linear-gradient(145deg, #7f8c8d, #566573); }
.char-panda,
.character-option-avatar.char-panda,
.character-avatar.char-panda { background: linear-gradient(145deg, #ecf0f1, #95a5a6); }
.char-bear,
.character-option-avatar.char-bear,
.character-avatar.char-bear { background: linear-gradient(145deg, #6e4c2e, #3e2723); }
.char-koala,
.character-option-avatar.char-koala,
.character-avatar.char-koala { background: linear-gradient(145deg, #a1887f, #6d4c41); }
.char-lion,
.character-option-avatar.char-lion,
.character-avatar.char-lion { background: linear-gradient(145deg, #f39c12, #d35400); }
.char-tiger,
.character-option-avatar.char-tiger,
.character-avatar.char-tiger { background: linear-gradient(145deg, #e67e22, #a04000); }
.char-deer,
.character-option-avatar.char-deer,
.character-avatar.char-deer { background: linear-gradient(145deg, #d68910, #9a5f0a); }
.char-pig,
.character-option-avatar.char-pig,
.character-avatar.char-pig { background: linear-gradient(145deg, #f8b4c4, #c06c84); }
.char-owl,
.character-option-avatar.char-owl,
.character-avatar.char-owl { background: linear-gradient(145deg, #5d4e6d, #2c1f3d); }
.char-eagle,
.character-option-avatar.char-eagle,
.character-avatar.char-eagle { background: linear-gradient(145deg, #5d6d7e, #2e4053); }
.char-frog,
.character-option-avatar.char-frog,
.character-avatar.char-frog { background: linear-gradient(145deg, #27ae60, #145a32); }
.char-turtle,
.character-option-avatar.char-turtle,
.character-avatar.char-turtle { background: linear-gradient(145deg, #16a085, #0e6655); }
.char-monkey,
.character-option-avatar.char-monkey,
.character-avatar.char-monkey { background: linear-gradient(145deg, #d68910, #9a5f0a); }
.char-raccoon,
.character-option-avatar.char-raccoon,
.character-avatar.char-raccoon { background: linear-gradient(145deg, #6c757d, #495057); }
.char-dragon,
.character-option-avatar.char-dragon,
.character-avatar.char-dragon { background: linear-gradient(145deg, #27ae60, #145a32); }
.char-bot,
.character-option-avatar.char-bot,
.character-avatar.char-bot { background: linear-gradient(145deg, #3498db, #1a5276); }

.character-avatar.has-char-img,
.character-option-avatar.has-char-img,
.dock-avatar.has-char-img,
.panel-char-icon,
.waiting-char-icon {
  background: transparent !important;
}

/* 6 seats around table — pos 0 = bottom */
.seat-pos-0 {
  bottom: -10%;
  left: 50%;
  transform: translateX(-50%);
  width: 82%;
}

.seats-players-2 .seat-pos-0,
.seats-players-2 .seat-pos-1,
.seats-players-3 .seat-pos-0 {
  width: 52%;
  max-width: 240px;
}

.seats-players-2 .seat-pos-1 {
  width: 52%;
  max-width: 240px;
}

.seats-players-3 .seat-pos-2,
.seats-players-3 .seat-pos-3 {
  top: 14%;
  width: 36%;
  max-width: 190px;
}

.seats-players-3 .seat-pos-2 {
  left: 1%;
}

.seats-players-3 .seat-pos-3 {
  right: 1%;
}

.seat-pos-1 {
  top: -5%;
  left: 50%;
  transform: translateX(-50%);
  width: 68%;
}

.seat-pos-2 {
  top: 14%;
  left: -2%;
  width: 42%;
}

.seat-pos-3 {
  top: 14%;
  right: -2%;
  width: 42%;
}

.seat-pos-4 {
  bottom: 11%;
  left: -2%;
  width: 42%;
}

.seat-pos-5 {
  bottom: 11%;
  right: -2%;
  width: 42%;
}

.table-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  width: 40%;
}

.center-info {
  font-size: 0.75rem;
  opacity: 0.65;
}

.player-panel .dice-pip-sum {
  font-size: 0.82rem;
  font-weight: 700;
  color: #5eb8ff;
  text-shadow: 0 0 8px rgba(94, 184, 255, 0.4);
  letter-spacing: 0.02em;
}

.player-panel {
  background: var(--panel-bg);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 0.4rem 0.5rem 0.55rem;
  min-width: calc(6 * 26px + 5 * 3px + 1rem);
  max-width: 100%;
  overflow: visible;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.table-felt .player-panel .dice-grid .die.hidden-die::after {
  font-size: 0.7rem;
}

.player-panel.dead {
  opacity: 0.55;
  filter: grayscale(0.85);
}

.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
}

.life-coin {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  background: transparent;
  border: none;
}

.life-coin-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.player-panel.empty {
  opacity: 0.25;
  border-style: dashed;
}

.player-panel.active-turn {
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(232, 197, 71, 0.35);
}

.player-panel.disconnected {
  opacity: 0.5;
  filter: grayscale(0.6);
}

.player-panel.is-you:not(.active-turn) {
  border-color: rgba(100, 200, 255, 0.5);
}

.player-panel.is-you.active-turn {
  border-color: var(--gold);
  box-shadow: 0 0 22px rgba(232, 197, 71, 0.5);
}

.player-name {
  font-weight: 600;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}

.badge-you {
  font-size: 0.65rem;
  background: rgba(100, 200, 255, 0.3);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.badge-offline {
  font-size: 0.65rem;
  color: #ff6b6b;
}

.dice-count {
  font-size: 0.7rem;
  opacity: 0.65;
  margin-bottom: 0.3rem;
  text-align: center;
}

.dice-out-text {
  display: block;
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.5;
}

.dice-grid {
  display: grid;
  grid-template-columns: repeat(6, var(--grid-die-size, 26px));
  grid-auto-rows: auto;
  gap: 3px;
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 4px 2px 8px;
  overflow: visible;
}

/* 上下座位：發牌動畫 translateY 需要額外留白，避免被框裁切 */
.seat-pos-0 .dice-grid,
.seat-pos-1 .dice-grid {
  padding: 8px 2px 14px;
}

.seat-pos-1 .dice-grid {
  padding-top: 14px;
  padding-bottom: 8px;
}

.seat-pos-0 .player-panel,
.seat-pos-1 .player-panel {
  padding-top: 0.5rem;
  padding-bottom: 0.75rem;
}

.dice-grid--table {
  --grid-die-size: 26px;
}

.dice-grid--dock {
  --grid-die-size: 34px;
  margin-bottom: 0.25rem;
}

.dice-grid.illusion-dice {
  --grid-die-size: 22px;
}

/* 右下角 dock 維持原尺寸，避免幻術骰縮小後格線錯位 */
.dice-grid--dock.illusion-dice,
.dice-grid--dock:has(.die-illusion) {
  --grid-die-size: 34px;
}

.dice-grid--dock .die.die-illusion {
  box-shadow: 0 3px 0 #553c9a, 0 0 10px rgba(159, 122, 234, 0.45);
}

.character-dock .dice-grid--dock {
  justify-content: flex-end;
  align-items: end;
  margin-left: auto;
  margin-right: 0;
}

.dice-grid > .die {
  width: var(--grid-die-size, 26px);
  height: var(--grid-die-size, 26px);
  font-size: calc(var(--grid-die-size, 26px) * 0.28);
  border-radius: 6px;
}

.dice-grid--dock > .die {
  font-size: calc(var(--grid-die-size, 34px) * 0.3);
}

.dice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.die {
  width: var(--dice-size);
  height: var(--dice-size);
  background: linear-gradient(145deg, #fffef5, #e8e0c8);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a1a;
  box-shadow:
    0 3px 0 #b8b0a0,
    inset 0 1px 0 #fff;
  position: relative;
}

/* 點數骰（1–6），不需圖片 */
.die.die-pips {
  font-size: 0;
  padding: 5px;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0;
  place-items: center;
}

.die.die-pips .pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  display: block;
}

.die.mini.die-pips {
  padding: 3px;
}

.die.mini.die-pips .pip {
  width: 5px;
  height: 5px;
}

.pip-tl { grid-column: 1; grid-row: 1; }
.pip-tc { grid-column: 2; grid-row: 1; }
.pip-tr { grid-column: 3; grid-row: 1; }
.pip-ml { grid-column: 1; grid-row: 2; }
.pip-c { grid-column: 2; grid-row: 2; }
.pip-mr { grid-column: 3; grid-row: 2; }
.pip-bl { grid-column: 1; grid-row: 3; }
.pip-bc { grid-column: 2; grid-row: 3; }
.pip-br { grid-column: 3; grid-row: 3; }

.die.wild.die-pips {
  color: #c0392b;
}

/* 魔術師強制變成的 1（藍色點，與萬能紅色區分） */
.die.die-magician.die-pips {
  color: #2980b9;
}

.die.die-magician.die-pips .pip {
  background: currentColor;
  box-shadow: 0 0 6px rgba(52, 152, 219, 0.65);
}

.die.die-god.die-pips .pip {
  background: #fff8e1;
  box-shadow: 0 0 8px rgba(255, 246, 210, 0.7);
}

.die.wild {
  color: #c0392b;
}

.die.hidden-die {
  background: linear-gradient(145deg, #4a5568, #2d3748);
  color: transparent;
  box-shadow: 0 3px 0 #1a202c;
}

.die.hidden-die::after {
  content: '?';
  color: rgba(255, 255, 255, 0.4);
  font-size: 1rem;
}

.die.hidden-die.die-god {
  background: linear-gradient(145deg, #ffd56a, #d4a017);
  border: 1px solid rgba(255, 240, 180, 0.95);
  box-shadow: 0 3px 0 #a67c00, 0 0 12px rgba(255, 215, 90, 0.45);
}

.die.hidden-die.die-god::after {
  color: rgba(255, 255, 255, 0.85);
}

.die.mini {
  width: 28px;
  height: 28px;
  font-size: 0.85rem;
}

.die-pop {
  animation: die-pop-in 0.45s cubic-bezier(0.34, 1.4, 0.64, 1) backwards;
}

@keyframes die-pop-in {
  0% {
    opacity: 0;
    transform: scale(0.3) rotate(-12deg) translateY(20px);
  }
  70% {
    transform: scale(1.08) rotate(4deg) translateY(-4px);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0) translateY(0);
  }
}

.die.hidden-die.die-pop {
  animation-name: die-shake-in;
}

@keyframes die-shake-in {
  0% {
    opacity: 0;
    transform: scale(0.5) rotate(0);
  }
  40% {
    transform: scale(1.05) rotate(-8deg);
  }
  70% {
    transform: scale(1) rotate(8deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.player-panel.active-turn .dice-grid .die {
  animation: die-turn-glow 1.5s ease-in-out infinite;
}

@keyframes die-turn-glow {
  0%, 100% { box-shadow: 0 3px 0 #b8b0a0, inset 0 1px 0 #fff; }
  50% {
    box-shadow: 0 3px 0 #b8b0a0, inset 0 1px 0 #fff, 0 0 10px rgba(232, 197, 71, 0.35);
  }
}

.dice-grid--dock.active-turn {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 8px;
  box-shadow: 0 0 18px rgba(232, 197, 71, 0.45);
}

/* Action bar */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(0deg, rgba(10, 15, 20, 0.98), rgba(10, 15, 20, 0.85));
  border-top: 1px solid rgba(232, 197, 71, 0.2);
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: var(--action-btn-gap);
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.action-bar.waiting-turn {
  opacity: 0.72;
}

.bid-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.bid-controls label {
  font-size: 0.8rem;
  opacity: 0.7;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.stepper input {
  width: 48px;
  text-align: center;
  padding: 0.4rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.4);
  color: var(--cream);
  font-size: 1.1rem;
  font-weight: 700;
}

.bid-qty-stepper #bid-qty {
  cursor: default;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

.step-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: var(--cream);
  font-size: 1.2rem;
  cursor: pointer;
}

.bid-value-picker {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.pip-btn {
  padding: 3px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  line-height: 0;
  font: inherit;
}

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

.pip-btn.active {
  border-color: var(--gold);
  background: rgba(232, 197, 71, 0.2);
}

.pip-btn .die.die-pips {
  width: 38px;
  height: 38px;
  pointer-events: none;
  box-shadow:
    0 2px 0 #b8b0a0,
    inset 0 1px 0 #fff;
}

.btn-leave-floating {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top, 0px));
  right: max(1rem, env(safe-area-inset-right, 0px));
  z-index: 130;
  pointer-events: auto;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.7);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Overlays */
.opening-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.opening-overlay.hidden {
  display: none;
}

.opening-big-text {
  font-size: clamp(2.5rem, 10vw, 4rem);
  font-weight: 800;
  color: #ff6b5b;
  text-shadow:
    0 0 40px rgba(231, 76, 60, 0.8),
    0 4px 0 #7b241c;
  animation: opening-text-pop 0.5s cubic-bezier(0.34, 1.5, 0.64, 1),
    opening-text-shake 0.6s ease 0.45s;
}

@keyframes opening-text-pop {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes opening-text-shake {
  0%, 100% { transform: translateX(0) scale(1); }
  20% { transform: translateX(-12px) scale(1.05); }
  40% { transform: translateX(12px) scale(1.05); }
  60% { transform: translateX(-8px) scale(1.02); }
  80% { transform: translateX(8px) scale(1.02); }
}

.reveal-overlay,
.gameover-overlay,
.drink-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.drink-overlay {
  z-index: 105;
}

.drink-overlay.hidden {
  display: none;
}

.drink-overlay.cinematic-mode {
  display: block;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.drink-overlay.cinematic-mode .drink-reveal-card {
  display: none;
}

.drink-effect-cinematic {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 106;
  overflow: hidden;
}

.drink-effect-cinematic.hidden {
  display: none;
}

.drink-effect-cinematic-stage {
  position: fixed;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 0;
  opacity: 0;
  isolation: isolate;
  will-change: transform, opacity;
}

.drink-effect-cinematic-stage::before,
.drink-effect-cinematic-stage::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  z-index: 0;
  pointer-events: none;
}

/* 內圈：較亮、較集中 */
.drink-effect-cinematic-stage::before {
  width: 112%;
  height: 120%;
  filter: blur(14px);
  opacity: 1;
}

/* 外圈：大範圍暈光 */
.drink-effect-cinematic-stage::after {
  width: 175%;
  height: 190%;
  filter: blur(40px);
  opacity: 1;
}

.drink-effect-cinematic-stage.drunk-glow-negative::before {
  background: radial-gradient(
    ellipse at center,
    rgba(255, 90, 70, 0.95) 0%,
    rgba(231, 76, 60, 0.75) 28%,
    rgba(192, 57, 43, 0.45) 52%,
    transparent 78%
  );
}

.drink-effect-cinematic-stage.drunk-glow-negative::after {
  background: radial-gradient(
    ellipse at center,
    rgba(231, 76, 60, 0.65) 0%,
    rgba(192, 57, 43, 0.4) 35%,
    transparent 72%
  );
}

.drink-effect-cinematic-stage.drunk-glow-positive::before {
  background: radial-gradient(
    ellipse at center,
    rgba(120, 255, 170, 0.92) 0%,
    rgba(46, 204, 113, 0.72) 28%,
    rgba(39, 174, 96, 0.42) 52%,
    transparent 78%
  );
}

.drink-effect-cinematic-stage.drunk-glow-positive::after {
  background: radial-gradient(
    ellipse at center,
    rgba(46, 204, 113, 0.62) 0%,
    rgba(39, 174, 96, 0.38) 35%,
    transparent 72%
  );
}

.drink-effect-cinematic-stage.drunk-glow-neutral::before {
  background: radial-gradient(
    ellipse at center,
    rgba(255, 230, 100, 0.92) 0%,
    rgba(241, 196, 15, 0.72) 28%,
    rgba(243, 156, 18, 0.42) 52%,
    transparent 78%
  );
}

.drink-effect-cinematic-stage.drunk-glow-neutral::after {
  background: radial-gradient(
    ellipse at center,
    rgba(241, 196, 15, 0.6) 0%,
    rgba(243, 156, 18, 0.36) 35%,
    transparent 72%
  );
}

.drink-effect-cinematic-img {
  position: relative;
  z-index: 1;
  display: block;
  width: min(360px, 66vw);
  height: auto;
  max-height: 48vh;
  object-fit: contain;
  border-radius: 1.15rem;
  -webkit-mask-image:
    linear-gradient(to right, transparent, #000 7%, #000 93%, transparent),
    linear-gradient(to bottom, transparent, #000 7%, #000 93%, transparent);
  mask-image:
    linear-gradient(to right, transparent, #000 7%, #000 93%, transparent),
    linear-gradient(to bottom, transparent, #000 7%, #000 93%, transparent);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.55));
}

.drink-effect-cinematic-stage.drunk-glow-negative .drink-effect-cinematic-img {
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 28px rgba(255, 90, 70, 0.85))
    drop-shadow(0 0 56px rgba(231, 76, 60, 0.6))
    drop-shadow(0 0 82px rgba(192, 57, 43, 0.4));
}

.drink-effect-cinematic-stage.drunk-glow-positive .drink-effect-cinematic-img {
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 28px rgba(120, 255, 170, 0.8))
    drop-shadow(0 0 56px rgba(46, 204, 113, 0.58))
    drop-shadow(0 0 82px rgba(39, 174, 96, 0.38));
}

.drink-effect-cinematic-stage.drunk-glow-neutral .drink-effect-cinematic-img {
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 28px rgba(255, 230, 100, 0.78))
    drop-shadow(0 0 56px rgba(241, 196, 15, 0.55))
    drop-shadow(0 0 82px rgba(243, 156, 18, 0.36));
}

.drink-effect-cinematic-stage.is-run {
  animation-name: drunk-effect-fly;
  animation-timing-function: cubic-bezier(0.22, 0.85, 0.32, 1);
  animation-fill-mode: forwards;
}

@keyframes drunk-effect-fly {
  0% {
    transform: translate(calc(-38vw - 50%), -50%);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  32% {
    transform: translate(-50%, -50%);
    opacity: 1;
  }
  44% {
    transform: translate(-50%, -50%);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%);
    opacity: 0;
  }
}

html.drink-cinematic-active .drunk-status-bar {
  position: relative;
  z-index: 111;
}

.drink-reveal-card {
  background: linear-gradient(145deg, #3d2a4a, #1a222d);
  border: 2px solid rgba(200, 120, 255, 0.45);
  border-radius: 16px;
  padding: 2rem 1.75rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  animation: reveal-card-in 0.45s ease-out;
  box-shadow: 0 0 48px rgba(160, 80, 220, 0.35);
}

.drink-reveal-card.drunk-positive {
  border-color: rgba(46, 204, 113, 0.55);
  box-shadow: 0 0 40px rgba(46, 204, 113, 0.25);
}

.drink-reveal-card.drunk-negative {
  border-color: rgba(231, 76, 60, 0.55);
  box-shadow: 0 0 40px rgba(231, 76, 60, 0.25);
}

.drink-reveal-card.drunk-neutral {
  border-color: rgba(241, 196, 15, 0.5);
  box-shadow: 0 0 40px rgba(241, 196, 15, 0.2);
}

.drink-reveal-emoji {
  font-size: 3rem;
  margin: 0 0 0.5rem;
  animation: drink-emoji-shake 0.6s ease-in-out infinite;
}

@keyframes drink-emoji-shake {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

.drink-reveal-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
  color: var(--gold, #e8c547);
}

.drink-effect-name {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0 0 0.5rem;
  color: var(--cream, #f5f0e6);
}

.drink-effect-desc {
  font-size: 1rem;
  line-height: 1.5;
  margin: 0 0 0.75rem;
  color: rgba(255, 255, 255, 0.88);
}

.drink-effect-extra {
  font-size: 0.95rem;
  font-weight: 700;
  color: #ff9f7a;
  margin: 0 0 1.25rem;
}

.drink-effect-extra.hidden {
  display: none;
}

.drink-dismiss-countdown {
  margin: 0.5rem 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: rgba(255, 220, 140, 0.92);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.drink-dismiss-countdown.hidden {
  display: none;
}

.drink-reveal-card .btn {
  min-width: 140px;
}

.reveal-card,
.gameover-card {
  background: linear-gradient(145deg, #2a3544, #1a222d);
  border: 1px solid rgba(232, 197, 71, 0.3);
  border-radius: 16px;
  padding: 2rem;
  max-width: 520px;
  width: 100%;
  text-align: center;
}

.reveal-overlay .reveal-card {
  max-width: min(96vw, 680px);
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}

.reveal-dice-grid {
  overflow: visible;
}

.reveal-overlay.reveal-active .reveal-card {
  animation: reveal-card-in 0.45s ease-out;
}

@keyframes reveal-card-in {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.reveal-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1.25rem;
  flex-wrap: wrap;
  margin: 1.25rem 0 1rem;
  padding: 1rem 0.5rem;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 14px;
  border: 1px solid rgba(232, 197, 71, 0.25);
}

.reveal-stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
}

.reveal-stat-label {
  font-size: 0.8rem;
  opacity: 0.75;
  margin-bottom: 0.25rem;
}

.reveal-stat-num {
  font-size: 3.25rem;
  font-weight: 800;
  line-height: 1;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}

.reveal-stat-num.highlight {
  color: var(--gold);
  text-shadow: 0 0 24px rgba(232, 197, 71, 0.45);
  animation: reveal-num-pulse 1.2s ease-in-out infinite;
}

@keyframes reveal-num-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.reveal-stat-suffix {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold);
  margin-top: 0.2rem;
}

.reveal-stat-vs {
  font-size: 1.1rem;
  font-weight: 700;
  opacity: 0.45;
}

.reveal-stat-call .reveal-stat-num {
  color: #a8c4e8;
}

.reveal-detail {
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 1rem;
  padding: 0 0.5rem;
}

.reveal-detail.verdict-fail {
  color: #ff9f7a;
}

.reveal-detail.verdict-win {
  color: #8be8a8;
}

.reveal-wait-hint,
.reveal-countdown {
  margin: 1rem 0 0;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
}

.reveal-countdown {
  margin-top: 0.35rem;
  color: rgba(255, 220, 140, 0.9);
  font-variant-numeric: tabular-nums;
}

#btn-confirm-reveal,
#btn-flip-coin {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0.75rem auto 0;
}

#coin-countdown {
  margin-bottom: 0;
}

.reveal-row-pop {
  animation: reveal-row-in 0.4s ease-out backwards;
}

.reveal-row-pop:nth-child(2) { animation-delay: 0.08s; }
.reveal-row-pop:nth-child(3) { animation-delay: 0.16s; }
.reveal-row-pop:nth-child(4) { animation-delay: 0.24s; }
.reveal-row-pop:nth-child(5) { animation-delay: 0.32s; }
.reveal-row-pop:nth-child(6) { animation-delay: 0.4s; }

@keyframes reveal-row-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.reveal-dice-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
  width: 100%;
  text-align: left;
}

.reveal-players-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem 0.75rem;
}

.reveal-player-card {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.55rem 0.35rem 0.85rem;
  border-radius: 10px;
  min-width: 0;
  overflow: visible;
  box-sizing: border-box;
}

.reveal-player-name {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  padding: 0 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.reveal-player-dice {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
  overflow: visible;
  box-sizing: border-box;
  padding: 6px 0 10px;
}

.reveal-dice-line {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: visible;
  padding: 2px 0;
}

.reveal-dice-line .die {
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  font-size: clamp(0.5rem, 1.8vw, 0.75rem);
  box-sizing: border-box;
}

.reveal-dice-line .die.die-pips .pip {
  width: 5px;
  height: 5px;
}

.coin-flip-section {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(232, 197, 71, 0.2);
}

.coin-flip-section.hidden {
  display: none;
}

#reveal-dice-section.hidden {
  display: none;
}

.coin-prompt {
  margin: 0.75rem 0 1rem;
  opacity: 0.9;
  line-height: 1.5;
}

.coin-prompt:empty {
  display: none;
  margin: 0;
}

.coin-visual {
  width: 5.5rem;
  height: 5.5rem;
  margin: 0.5rem auto;
  display: inline-block;
  transform-style: preserve-3d;
  perspective: 400px;
  position: relative;
}

.coin-visual .coin-face-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
}

.coin-visual.coin-idle {
  animation: coin-float 2s ease-in-out infinite;
}

@keyframes coin-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.coin-visual.flipping {
  animation: coin-spin 1s cubic-bezier(0.45, 0.05, 0.2, 1);
}

.coin-visual.flipping .coin-face-img {
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.45));
}

.coin-visual.coin-landed {
  animation: coin-land 0.5s cubic-bezier(0.34, 1.5, 0.64, 1);
}

.coin-visual.heads {
  filter: drop-shadow(0 0 16px rgba(244, 208, 63, 0.7));
}

.coin-visual.tails {
  filter: grayscale(0.35) drop-shadow(0 0 12px rgba(180, 60, 60, 0.45));
}

@keyframes coin-spin {
  0% {
    transform: rotateY(0deg) scale(1) translateY(0);
  }
  25% {
    transform: rotateY(360deg) scale(1.2) translateY(-28px);
  }
  50% {
    transform: rotateY(720deg) scale(1.15) translateY(-12px);
  }
  75% {
    transform: rotateY(1080deg) scale(1.1) translateY(-20px);
  }
  100% {
    transform: rotateY(1440deg) scale(1) translateY(0);
  }
}

@keyframes coin-land {
  0% { transform: scale(1.3); }
  60% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

.coin-result {
  min-height: 1.5em;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gold);
  margin: 0.75rem 0;
}

.coin-result.fail {
  color: #ff8a8a;
}

.life-coin.pending {
  animation: coin-pulse 1s ease-in-out infinite;
}

@keyframes coin-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.gameover-card h2 {
  color: var(--gold);
  margin-bottom: 1.5rem;
}

.elimination-card .elimination-emoji {
  font-size: 3rem;
  margin: 0 0 0.5rem;
}

.elimination-card h2 {
  margin-bottom: 0.75rem;
}

.elimination-desc {
  font-size: 1.15rem;
  line-height: 1.55;
  margin: 0 0 1.5rem;
  color: rgba(255, 255, 255, 0.9);
}

#elimination-overlay {
  z-index: 106;
}

/* —— Tablet / narrow desktop —— */
@media (max-width: 900px) {
  :root {
    --dice-size: 34px;
  }

  .lobby-card,
  .lobby-card-wide,
  .waiting-card {
    max-width: min(100%, 420px);
    padding: 1.65rem 1.25rem;
  }

  .table-wrap {
    max-height: min(72vw, 480px);
  }

  .seat-pos-0 {
    width: 90%;
  }

  .seat-pos-1 {
    width: 76%;
  }

  .seat-pos-2,
  .seat-pos-3,
  .seat-pos-4,
  .seat-pos-5 {
    width: 44%;
  }

  .player-panel {
    min-width: min(100%, calc(6 * 22px + 5 * 3px + 0.75rem));
    padding: 0.35rem 0.4rem 0.45rem;
  }

  .dice-grid {
    grid-template-columns: repeat(6, var(--grid-die-size, 22px));
    gap: 2px;
  }

  .game-message {
    font-size: 0.95rem;
  }

  .drunk-card {
    flex: 1 1 100%;
    max-width: 100%;
  }

  .action-bar {
    padding: 0.75rem 0.65rem 0.85rem;
    gap: var(--action-btn-gap);
  }

  .bid-controls {
    gap: 0.5rem;
  }
}

/* —— Phone —— */
@media (max-width: 600px) {
  :root {
    --dice-size: 28px;
  }

  .title {
    font-size: 1.55rem;
    letter-spacing: 0.08em;
  }

  .subtitle {
    margin-bottom: 1.25rem;
    font-size: 0.85rem;
  }

  .lobby-card,
  .lobby-card-wide,
  .waiting-card {
    padding: 1.35rem 1rem;
    border-radius: 16px;
  }

  #screen-lobby.active {
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding-top: 0.85rem;
    padding-bottom: 1rem;
  }

  .lobby-footer-meta {
    position: static;
    width: 100%;
    max-width: min(480px, 100%);
    margin: 0.85rem auto 0;
    align-items: stretch;
    pointer-events: none;
  }

  .lobby-footer-meta .dev-changelog {
    max-height: 28vh;
    overflow-y: auto;
  }

  .join-row {
    flex-wrap: wrap;
  }

  .join-row .code-input {
    flex: 1 1 100%;
    max-width: none;
  }

  .join-row .btn {
    flex: 1 1 auto;
    min-width: 5rem;
  }

  .char-carousel-btn {
    width: 2.35rem;
    height: 2.35rem;
    font-size: 1.45rem;
  }

  .player-list {
    max-height: min(40vh, 280px);
    overflow-y: auto;
    margin: 0.85rem 0;
  }

  .player-list li {
    padding: 0.5rem 0.65rem;
    flex-wrap: wrap;
  }

  .room-settings-dialog {
    max-width: min(360px, calc(100vw - 1.5rem));
    padding: 1.1rem 1rem;
  }

  .room-settings-dialog-actions {
    flex-wrap: wrap;
    row-gap: 0.4rem;
  }

  .room-settings-dialog-actions #btn-room-settings-cancel {
    margin-right: 0;
  }

  .room-settings-dialog-actions #btn-room-settings-save {
    flex: 1 1 auto;
    min-width: 5.5rem;
    padding: 0.6rem 0.85rem;
    font-size: 0.88rem;
  }

  html.game-layout-mobile #screen-game.active {
    padding-bottom: calc(12rem + env(safe-area-inset-bottom, 0px));
  }

  .game-header {
    margin-bottom: 0.2rem;
  }

  .game-message {
    font-size: 0.88rem;
    margin: 0.25rem 0;
  }

  .current-bid {
    padding: 0.3rem 0.65rem;
    font-size: 0.9rem;
  }

  .table-wrap {
    max-height: min(68vw, 360px);
    margin-top: 0.35rem;
  }

  .seat-pos-0 {
    width: 96%;
    bottom: -8%;
  }

  .seat-pos-1 {
    width: 82%;
    top: -4%;
  }

  .seat-pos-2,
  .seat-pos-3,
  .seat-pos-4,
  .seat-pos-5 {
    width: 46%;
  }

  .seats-players-2 .seat-pos-0,
  .seats-players-2 .seat-pos-1,
  .seats-players-3 .seat-pos-0 {
    width: 58%;
    max-width: 200px;
  }

  .seats-players-3 .seat-pos-2,
  .seats-players-3 .seat-pos-3 {
    width: 42%;
    max-width: 160px;
  }

  .player-panel {
    min-width: 0;
    max-width: 100%;
    padding: 0.3rem 0.35rem 0.4rem;
    border-radius: 10px;
  }

  .player-name {
    font-size: 0.72rem;
  }

  .dice-grid {
    grid-template-columns: repeat(6, var(--grid-die-size, 20px));
    gap: 2px;
    padding: 3px 1px 6px;
  }

  .character-avatar.seat-avatar {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .character-seat-name {
    max-width: 48px;
    font-size: 0.55rem;
  }

  .sfx-settings {
    top: max(0.35rem, env(safe-area-inset-top, 0px));
    left: max(0.35rem, env(safe-area-inset-left, 0px));
  }

  .sfx-settings-panel {
    min-width: 0;
    width: min(220px, calc(100vw - 1rem));
  }

  .debug-tools {
    top: calc(max(0.35rem, env(safe-area-inset-top, 0px)) + 2.85rem);
    left: max(0.35rem, env(safe-area-inset-left, 0px));
  }

  .debug-tools-panel {
    min-width: 0;
    width: min(240px, calc(100vw - 1rem));
    max-height: 50vh;
    overflow-y: auto;
  }

  .btn-leave-floating {
    top: max(0.5rem, env(safe-area-inset-top, 0px));
    right: max(0.5rem, env(safe-area-inset-right, 0px));
    font-size: 0.78rem;
    padding: 0.35rem 0.6rem;
  }

  .game-chat,
  .game-side-dock {
    width: min(260px, calc(100vw - 5.75rem));
  }

  body.room-ui-game .room-dock:not([hidden]) {
    bottom: max(5.25rem, calc(4.75rem + env(safe-area-inset-bottom, 0px)));
    left: max(0.35rem, env(safe-area-inset-left, 0px));
  }

  body.room-ui-waiting .room-dock:not([hidden]) {
    left: max(0.35rem, env(safe-area-inset-left, 0px));
  }

  .game-chat-messages {
    min-height: 100px;
  }

  .character-dock {
    right: max(0.35rem, env(safe-area-inset-right, 0px));
    bottom: max(5.25rem, calc(4.85rem + env(safe-area-inset-bottom, 0px)));
    max-width: calc(100vw - 0.75rem);
  }

  .dock-avatar {
    width: 64px;
    height: 64px;
    font-size: 1.9rem;
    border-width: 3px;
  }

  .dock-speech {
    max-width: min(130px, calc(100vw - 6rem));
    font-size: 0.75rem;
    padding: 0.4rem 0.55rem;
  }

  .dock-name {
    max-width: 72px;
    font-size: 0.72rem;
  }

  .action-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.55rem 0.45rem max(0.6rem, env(safe-area-inset-bottom, 0px));
    gap: var(--action-btn-gap);
  }

  .bid-controls {
    width: 100%;
    justify-content: center;
    gap: 0.35rem 0.45rem;
  }

  .bid-value-picker {
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
  }

  .pip-btn .die.die-pips.mini {
    width: 28px;
    height: 28px;
  }

  .action-bar > .btn {
    width: 100%;
    max-width: 100%;
    align-self: stretch;
  }

  #btn-challenge {
    order: 10;
  }

  .reveal-dice-line .die.die-pips .pip {
    width: 4px;
    height: 4px;
  }

  .reveal-card,
  .gameover-card,
  .drink-reveal-card,
  .elimination-card {
    max-width: calc(100vw - 1.5rem);
    padding: 1.35rem 1rem;
  }

  .reveal-stat-num {
    font-size: 2.5rem;
  }
}

/* —— Very small phone —— */
@media (max-width: 400px) {
  :root {
    --dice-size: 24px;
  }

  .room-settings-dialog-actions #btn-room-settings-save {
    flex: 1 1 100%;
  }

  .table-wrap {
    max-height: min(62vw, 300px);
  }

  .seat-pos-2,
  .seat-pos-3 {
    width: 50%;
  }

  .seat-pos-4,
  .seat-pos-5 {
    width: 48%;
    bottom: 9%;
  }

  .step-btn {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .stepper input {
    width: 40px;
    font-size: 1rem;
  }

  .game-chat {
    width: min(220px, calc(100vw - 4.5rem));
  }

  .dock-avatar {
    width: 56px;
    height: 56px;
  }
}

/* —— Short viewport (landscape phone) —— */
@media (max-height: 520px) and (orientation: landscape) {
  .screen {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  #screen-lobby.active {
    justify-content: flex-start;
  }

  .lobby-footer-meta .dev-changelog {
    max-height: 22vh;
  }

  .table-wrap {
    max-height: min(52vh, 280px);
  }

  #screen-game {
    padding-bottom: max(5.5rem, calc(4.5rem + env(safe-area-inset-bottom, 0px)));
  }

  .character-dock {
    bottom: max(4.5rem, calc(4rem + env(safe-area-inset-bottom, 0px)));
  }

  body.room-ui-game .room-dock:not([hidden]) {
    bottom: max(4.5rem, calc(4rem + env(safe-area-inset-bottom, 0px)));
  }

  .game-side-dock-panel {
    max-height: min(200px, 38vh);
  }

  .action-bar {
    padding-top: 0.4rem;
    padding-bottom: max(0.4rem, env(safe-area-inset-bottom, 0px));
  }
}

/* ============================================================
   手機專用遊戲版面（html.game-layout-mobile，≤600px 由 JS 切換）
   ============================================================ */
html.game-layout-mobile {
  --mobile-action-h: 11.5rem;
}

html.game-layout-mobile #screen-game.active {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0.35rem 0.45rem calc(var(--mobile-action-h) + 0.5rem);
  max-width: 100%;
  overflow-x: hidden;
}

html.game-layout-mobile .character-dock,
html.game-layout-mobile #dock-dice-grid {
  display: none !important;
}

html.game-layout-mobile .mobile-players-board {
  position: relative;
}

html.game-layout-mobile .mobile-players-board > .dock-speech {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -110%);
  max-width: min(260px, calc(100vw - 1.5rem));
  text-align: center;
  z-index: 5;
}

.die.die-num {
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(145deg, #f5f0e6, #d4cfc4);
  color: #1a2838;
  box-shadow: 0 3px 0 #b8b0a0, inset 0 1px 0 #fff;
}

.die.die-num.mini {
  font-size: 0.82rem;
}

.die.die-num.wild {
  color: #c0392b;
}

.die.die-num.die-magician {
  color: #2980b9;
}

.die.die-num.die-god {
  color: #fff8e1;
}

.mobile-player-card.react-bid,
.mobile-player-card.react-challenge,
.mobile-player-card.react-listen,
.mobile-player-card.react-nervous {
  animation: mobile-card-react 0.35s ease;
}

@keyframes mobile-card-react {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

html.game-layout-mobile #screen-game.active .game-header {
  flex-shrink: 0;
  margin: 0 0 0.2rem;
}

html.game-layout-mobile #screen-game.active .game-message {
  font-size: 0.82rem;
  line-height: 1.35;
  margin: 0.15rem 0;
  min-height: 0;
}

html.game-layout-mobile #screen-game.active .drunk-status-bar {
  flex-wrap: wrap;
  overflow-x: visible;
  justify-content: center;
  margin-top: 0.3rem;
}

html.game-layout-mobile #screen-game.active .drunk-card {
  flex: 1 1 100%;
  width: 100%;
  max-width: min(100%, 340px);
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

html.game-layout-mobile #screen-game.active .drunk-card-title,
html.game-layout-mobile #screen-game.active .drunk-card-desc,
html.game-layout-mobile #screen-game.active .drunk-card-extra {
  text-align: center;
}

html.game-layout-mobile .drink-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

html.game-layout-mobile .drink-reveal-card {
  margin-left: auto;
  margin-right: auto;
  max-width: min(calc(100vw - 2rem), 360px);
  text-align: center;
}

html.game-layout-mobile .drink-reveal-card h2,
html.game-layout-mobile .drink-effect-name,
html.game-layout-mobile .drink-effect-desc,
html.game-layout-mobile .drink-effect-extra {
  text-align: center;
}

html.game-layout-mobile .drink-reveal-card .btn {
  margin-left: auto;
  margin-right: auto;
  display: block;
}

html.game-layout-mobile #screen-game.active .current-bid {
  margin: 0.2rem auto 0;
  font-size: 0.82rem;
}

/* 手機不顯示圓桌 */
html.game-layout-mobile #screen-game.active .table-wrap {
  display: none !important;
}

/* 玩家列表 */
html.game-layout-mobile .mobile-players-board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0.2rem 0 0.35rem;
}

html.game-layout-mobile .mobile-players-board.hidden {
  display: none !important;
}

.mobile-players-board {
  display: none;
}

.mobile-board-summary {
  flex-shrink: 0;
  text-align: center;
  font-size: 0.78rem;
  opacity: 0.75;
  margin: 0 0 0.4rem;
}

.mobile-player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  -webkit-overflow-scrolling: touch;
}

html.game-layout-mobile .mobile-player-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: auto;
  align-content: start;
  align-items: start;
  gap: 0.45rem 0.55rem;
  flex-direction: unset;
}

.mobile-player-card {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

html.game-layout-mobile .mobile-player-card {
  align-self: start;
  height: auto;
  min-height: 0;
}

.mobile-player-card.is-you {
  border-color: rgba(100, 200, 255, 0.45);
}

.mobile-player-card.active-turn {
  border-color: var(--gold, #e8c547);
  box-shadow: 0 0 14px rgba(232, 197, 71, 0.28);
}

.mobile-player-card.dead {
  opacity: 0.55;
}

.mobile-player-card.disconnected {
  opacity: 0.65;
}

.mobile-player-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  width: 100%;
  max-width: 100%;
}

.mobile-player-head {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0.4rem;
  max-width: 100%;
}

.mobile-player-char {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-player-avatar {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  object-fit: contain;
}

.mobile-player-info {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  height: 44px;
  max-height: 44px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

html.game-layout-mobile .mobile-player-head {
  flex: 0 0 auto;
  height: 44px;
  max-height: 44px;
  overflow: hidden;
  align-items: flex-start;
}

html.game-layout-mobile .mobile-player-main {
  height: auto;
  min-height: 0;
}

.mobile-player-name {
  font-weight: 700;
  font-size: 0.9rem;
  display: block;
  line-height: 1.25;
  word-break: break-word;
}

.mobile-player-tag {
  font-size: 0.62rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: rgba(100, 200, 255, 0.25);
  color: #9fd4ff;
}

.mobile-player-tag.offline {
  background: rgba(255, 100, 100, 0.2);
  color: #ff9f9f;
}

.mobile-player-stats {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem 0.5rem;
  margin-top: 0.12rem;
  font-size: 0.75rem;
  line-height: 1.15;
  color: rgba(245, 230, 200, 0.92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.game-layout-mobile .mobile-player-name {
  font-size: 0.82rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.game-layout-mobile .mobile-player-name .mobile-player-tag {
  display: inline;
  vertical-align: baseline;
}

.mobile-stat-dice {
  font-weight: 600;
  color: var(--gold, #e8c547);
}

.mobile-dice-pip-sum {
  font-weight: 700;
  color: #5eb8ff;
  text-shadow: 0 0 8px rgba(94, 184, 255, 0.4);
  letter-spacing: 0.02em;
}

.mobile-stat-wine {
  opacity: 0.9;
}

.mobile-player-hint {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  opacity: 0.65;
  text-align: center;
}

.mobile-player-dice {
  flex: 0 0 auto;
  width: fit-content;
  max-width: 100%;
  align-self: center;
  min-width: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-player-dice--empty {
  display: none;
}

.mobile-player-dice .dice-grid {
  --grid-die-size: 22px;
  width: auto;
  max-width: 100%;
  margin: 0;
  padding: 2px 0;
  grid-template-columns: repeat(6, var(--grid-die-size));
  gap: 2px;
  justify-content: center;
}

html.game-layout-mobile .mobile-player-dice .die.die-pips.mini,
html.game-layout-mobile .mobile-player-dice .die.mini {
  width: var(--grid-die-size);
  height: var(--grid-die-size);
}

html.game-layout-mobile .mobile-player-dice .die.die-pips .pip {
  width: 4px;
  height: 4px;
}

html.game-layout-mobile .mobile-player-dice .die.die-drowsy.mini {
  font-size: 0.7rem;
  line-height: 1;
}

/* 叫骰 + 喝酒 / 開盅 */
html.game-layout-mobile #screen-game.active .action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 53;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--action-btn-gap);
  padding: 0.4rem 0.45rem max(0.45rem, env(safe-area-inset-bottom, 0px));
  max-height: none;
  overflow: visible;
}

html.game-layout-mobile #screen-game.active .bid-controls {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 0.5rem;
}

html.game-layout-mobile #screen-game.active .bid-controls > label {
  font-size: 0.75rem;
  width: auto;
}

html.game-layout-mobile #screen-game.active .bid-value-picker {
  flex: 1 1 100%;
  justify-content: center;
  flex-wrap: wrap;
}

html.game-layout-mobile #screen-game.active .action-bar-actions {
  display: flex;
  flex-wrap: nowrap;
  width: 100%;
  gap: var(--action-btn-gap);
}

html.game-layout-mobile #screen-game.active .action-bar-actions .action-btn {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: none;
  height: 48px;
}

html.game-layout-mobile body.room-ui-game .room-dock:not([hidden]) {
  width: min(240px, calc(100vw - 3.5rem));
}

html.game-layout-mobile body.room-ui-waiting .room-dock:not([hidden]) {
  width: min(240px, calc(100vw - 3.5rem));
}

html.game-layout-mobile .game-side-dock-panel {
  width: min(240px, calc(100vw - 3.5rem));
  min-height: min(160px, 26vh);
  max-height: min(180px, 28vh);
}

html.game-layout-mobile .btn-leave-floating,
html.game-layout-mobile .sfx-settings,
html.game-layout-mobile .debug-tools {
  z-index: 130;
}

/* 開盅結算：一排兩人，最多三排 */
html.game-layout-mobile .reveal-dice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 0.55rem;
  margin-top: 1rem;
  max-height: min(46vh, 340px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

html.game-layout-mobile .reveal-players-row {
  display: contents;
}

html.game-layout-mobile .reveal-player-card {
  padding: 0.45rem 0.3rem 0.65rem;
}

html.game-layout-mobile .reveal-player-name {
  font-size: 0.78rem;
  margin-bottom: 0.3rem;
}

html.game-layout-mobile .reveal-dice-line {
  gap: 1px;
}

html.game-layout-mobile .reveal-dice-line .die.die-pips .pip {
  width: 3px;
  height: 3px;
}

html.game-layout-mobile .reveal-stats {
  margin: 0.85rem 0 0.65rem;
  padding: 0.65rem 0.35rem;
  gap: 0.5rem 0.75rem;
}

html.game-layout-mobile .reveal-stat-num {
  font-size: 2.25rem;
}

html.game-layout-mobile .reveal-overlay .reveal-card {
  max-width: calc(100vw - 1rem);
  padding: 1.1rem 0.75rem;
}
