:root {
  --bg: #0a0a0f;
  --bg-card: #16161f;
  --accent: #ff5722;
  --accent-2: #ff9800;
  --text: #f5f5f7;
  --text-dim: #8a8a95;
  --safe: #4caf50;
  --radius: 20px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  min-height: 100dvh;
  position: relative;
}

/* 頂部按鈕群組：語言切換與隱私合規盾牌按鈕 */
.lang-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.compliance-toggle {
  position: fixed;
  top: 16px;
  right: 88px; /* 釘選於語言按鈕左側 */
  z-index: 100;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 0.15s, border-color 0.15s;
}

.compliance-toggle:active {
  transform: scale(0.95);
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding: 56px 20px 24px;
  animation: fade-in 0.25s ease;
}

.screen.active {
  display: flex;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.game-title {
  font-size: clamp(28px, 8vw, 42px);
  font-weight: 900;
  text-align: center;
  margin: 24px 0 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.mode-choose {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 32px;
}

.mode-grid {
  display: grid;
  gap: 16px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  align-content: center;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: transform 0.15s, border-color 0.15s;
}

.mode-card:active {
  transform: scale(0.98);
}

.mode-card.solo {
  border-left: 4px solid var(--safe);
}

.mode-card.online {
  border-left: 4px solid var(--accent);
}

.mode-emoji {
  font-size: 36px;
}

.mode-name {
  font-size: 20px;
  font-weight: 700;
}

.mode-desc {
  font-size: 14px;
  color: var(--text-dim);
}

.btn-back {
  position: absolute;
  top: 16px;
  left: 16px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
}

.input-row {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}

input {
  flex: 1;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}

input:focus {
  border-color: var(--accent);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
}

.btn-primary {
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
  font-size: 16px;
}

.btn-secondary {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  max-height: 240px;
  overflow-y: auto;
}

.player-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: 12px;
  margin-bottom: 8px;
}

.player-list li .num {
  display: inline-block;
  width: 24px;
  height: 24px;
  background: var(--accent);
  border-radius: 50%;
  text-align: center;
  line-height: 24px;
  font-size: 12px;
  font-weight: 700;
  margin-right: 10px;
}

.player-list li .del {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
}

.player-list.compact li {
  padding: 8px 12px;
  font-size: 14px;
}

.hint {
  color: var(--text-dim);
  font-size: 13px;
  min-height: 20px;
  text-align: center;
}

.btn-cta {
  margin-top: auto;
  padding: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.5px;
}

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

.pass-screen {
  justify-content: center;
  text-align: center;
}

.pass-label {
  color: var(--text-dim);
  font-size: 16px;
  margin: 0;
}

.pass-name {
  font-size: clamp(48px, 16vw, 84px);
  font-weight: 900;
  margin: 16px 0 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.pass-tip {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 32px;
}

/* ---- 數字輸入畫面（極限壓迫與分級張力） ---- */
[data-screen="solo_input"] {
  justify-content: flex-start;
  padding-top: 28px;
  padding-bottom: 32px;
  overflow-y: auto;
}

#inputWhoTurn,
.range-badge,
.big-input,
.error,
#soloSubmitBtn {
  width: 100%;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

/* 鍵盤彈起時頂部固定膠囊提示 */
.range-mini {
  display: none;
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 18px;
  background: rgba(22, 22, 31, 0.94);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 87, 34, 0.35);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-2);
  z-index: 90;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.range-mini.show {
  display: block;
}

/* 安全範圍卡片 */
.range-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, rgba(255, 87, 34, 0.08), rgba(255, 152, 0, 0.04));
  border: 1px solid rgba(255, 87, 34, 0.25);
  padding: 14px 28px;
  border-radius: 20px;
  margin-top: 8px;
  margin-bottom: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.range-badge span {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  font-weight: 600;
}

.range-badge strong {
  color: var(--accent-2);
  font-size: clamp(34px, 9vw, 46px);
  font-weight: 900;
  letter-spacing: 2px;
  line-height: 1.1;
  text-shadow: 0 0 20px rgba(255, 152, 0, 0.3);
}

/* 核心拉桿輸入框 */
.big-input {
  padding: 18px;
  text-align: center;
  background: var(--bg-card);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 3px;
  outline: none;
  margin-bottom: 8px;
  transition: font-size 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  -moz-appearance: textfield;
}

.big-input::-webkit-outer-spin-button,
.big-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.big-input:focus {
  font-size: 52px;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 87, 34, 0.18);
  transform: scale(1.02);
}

.big-input::placeholder {
  font-size: 18px;
  font-weight: 400;
  color: rgba(138, 138, 149, 0.6);
  letter-spacing: 1px;
}

/* 基礎合規與不合規狀態 */
.big-input.in-range {
  border-color: var(--safe);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.25);
}

.big-input.out-of-range {
  border-color: #ff5252;
  box-shadow: 0 0 0 3px rgba(255, 82, 82, 0.25);
}

/* ---- 三級張力分層設計 ---- */

/* 1. 提醒 (diff <= 12)：微警示 */
[data-screen="solo_input"].warn .big-input {
  border-color: rgba(255, 193, 7, 0.5);
}

/* 2. 高壓 (diff <= 6)：常規心跳脈衝 */
[data-screen="solo_input"].danger .big-input {
  border-color: rgba(255, 87, 34, 0.7);
  animation: pulse-danger 1.4s infinite;
}

@keyframes pulse-danger {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 87, 34, 0.4); }
  50%      { box-shadow: 0 0 0 14px rgba(255, 87, 34, 0); }
}

/* 3. 必爆/死局 (diff <= 2)：急促紅光警報 */
[data-screen="solo_input"].critical .big-input {
  border-color: rgba(255, 82, 82, 0.95);
  animation: pulse-critical 0.7s infinite;
}

@keyframes pulse-critical {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.6); transform: scale(1); }
  50%      { box-shadow: 0 0 0 18px rgba(255, 82, 82, 0); transform: scale(1.015); }
}

/* 消除優先級打架：高危狀態下輸入合法，轉為「刀尖跳舞」的警示黃色 */
[data-screen="solo_input"].danger .big-input.in-range,
[data-screen="solo_input"].critical .big-input.in-range {
  border-color: #ffc107 !important;
  box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.35) !important;
  animation: none;
}

.error {
  color: #ff5252;
  font-size: 14px;
  min-height: 20px;
  text-align: center;
}

.boom-screen {
  justify-content: center;
  text-align: center;
  background: radial-gradient(circle at center, #2a0505 0%, var(--bg) 70%);
  position: relative;
  overflow: hidden;
}

.boom-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 87, 34, 0.4), transparent 60%);
  animation: boom-pulse 1.6s ease-out forwards;
  pointer-events: none;
}

@keyframes boom-pulse {
  0% { opacity: 0; transform: scale(0.3); }
  30% { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(1.6); }
}

.boom-title {
  font-size: clamp(32px, 10vw, 48px);
  margin: 0 0 20px;
}

.boom-loser-label, .boom-number-label {
  color: var(--text-dim);
  font-size: 13px;
  margin: 8px 0 0;
}

.boom-loser-name {
  font-size: 32px;
  margin: 4px 0 16px;
  color: var(--accent-2);
}

.boom-number {
  font-size: 72px;
  font-weight: 900;
  color: var(--accent);
  margin: 4px 0 20px;
  text-shadow: 0 0 40px var(--accent);
}

.penalty-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
}

.penalty-title {
  color: var(--accent-2);
  font-weight: 700;
  margin: 0 0 8px;
}

.penalty-text {
  font-size: 16px;
  line-height: 1.5;
  margin: 0;
}

.host-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.qrcode-box {
  background: white;
  padding: 12px;
  border-radius: 12px;
  width: fit-content;
  margin: 12px auto;
}

.big-range {
  font-size: 48px;
  font-weight: 900;
  text-align: center;
  color: var(--accent-2);
  margin: 24px 0;
}

.turn-callout {
  text-align: center;
  font-size: 20px;
  margin-bottom: 20px;
}

.admin-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
}

.range-pill {
  display: inline-block;
  padding: 8px 18px;
  background: var(--bg-card);
  border-radius: 999px;
  font-size: 22px;
  font-weight: 800;
  color: var(--accent-2);
  margin: 0 auto;
}

.play-header {
  text-align: center;
  margin-bottom: 24px;
}

.turn-status-box {
  text-align: center;
  margin: 20px 0;
}

.reaction-bar {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 16px;
}

.reaction-btn {
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  font-size: 18px;
  cursor: pointer;
  color: var(--text);
}

.reaction-btn:disabled {
  opacity: 0.3;
}

#reactionLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.reaction-bubble {
  position: absolute;
  bottom: 30px;
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 20px;
  font-size: 16px;
  animation: bubble-float 2.5s ease-out forwards;
}

@keyframes bubble-float {
  0% { transform: translateY(0) scale(0.8); opacity: 0; }
  15% { transform: translateY(-15px) scale(1.1); opacity: 1; }
  100% { transform: translateY(-90px) scale(1); opacity: 0; }
}

/* Modal 底層與彈片 (支援合規彈窗與代打彈層) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: flex-end; /* 手機端預設貼底由下而上 */
  justify-content: center;
  z-index: 1000;
  padding: 0;
}

.modal-sheet {
  background: var(--bg-card);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6);
  animation: sheet-up 0.25s ease-out;
}

@keyframes sheet-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* 💻 關鍵改動：桌面端與平板自動完美置中 */
@media (min-width: 600px) {
  .modal-overlay {
    align-items: center; /* 電腦端垂直置中 */
    padding: 20px;
  }
  .modal-sheet {
    border-radius: 20px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.75);
  }
}

.modal-btns {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

/* Toast 提示條 */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-msg {
  background: rgba(22, 22, 31, 0.95);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  animation: toast-in 0.3s ease forwards;
}

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