:root {
  --bg: #0f1320;
  --panel: #161b2c;
  --panel-2: #1d2338;
  --text: #e6e9f4;
  --muted: #a8b0c9;
  --accent: #4f8ef7;
  --accent-2: #7aa4ff;
  --win: #17c964;
  --lose: #f31260;
  --warn: #f5a524;
  --border: #273052;
  /* 云雾颜色变量（默认银河） */
  --nebula1: rgba(122, 164, 255, 0.14);
  --nebula2: rgba(213, 82, 160, 0.12);
  --nebula3: rgba(79, 142, 247, 0.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-y: auto;
}

.layout { display: grid; grid-template-columns: 320px 1fr; min-height: 100vh; position: relative; z-index: 1; }
/* 顶部工具栏 */
.toolbar { position: relative; display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 12px; min-height: 96px; }
.toolbar .balance { position: absolute; left: 0; right: auto; top: 0; margin: 0; }
.brand-box { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.user-id { font-size: 14px; color: var(--muted); margin-top: 6px; }


.sidebar {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border-right: 1px solid var(--border);
  padding: 20px 24px; /* 适度右移，但保留可用宽度 */
}
.brand { font-weight: 900; letter-spacing: 1.5px; margin-bottom: 0; font-size: 36px; line-height: 1; color: var(--warn); 
  text-shadow: 0 0 8px rgba(245,165,36,0.45), 0 0 16px rgba(245,165,36,0.35), 0 0 28px rgba(245,165,36,0.25);
  animation: goldGlow 2.4s ease-in-out infinite alternate;
}
/* 金色 U 文案样式 */
.gold-u { color: var(--warn); font-weight: 800; letter-spacing: 1px; }
.gold-u { text-shadow: 0 0 8px rgba(245,165,36,0.45), 0 0 16px rgba(245,165,36,0.35), 0 0 28px rgba(245,165,36,0.25); }
.balance { background: #12162a; border: 1px solid var(--border); padding: 10px; border-radius: 8px; margin-bottom: 16px; display: inline-flex; align-items: center; gap: 8px; }
.balance .u-logo { height: 80px; width: auto; display: inline-block; }
.sidebar-title { margin: 14px 0 8px; font-size: 14px; color: var(--muted); }
.log-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.log-item { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.log-item { gap: 8px; white-space: nowrap; }
.log-item .ts, .log-item .room, .log-item .result, .log-item .amt { white-space: nowrap; display: inline-block; }
.log-item .ts { color: #9ca3af; }
.log-item .room { color: var(--text); }
.log-item .result.win { color: var(--win); font-weight: 600; }
.log-item .result.lose { color: var(--lose); font-weight: 600; }
.log-item .amt.plus { color: var(--win); }
.log-item .amt.minus { color: var(--lose); }
.amount-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.amount-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.amount-btn {
  width: 100%;
  background: #11162b;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .18s ease, transform .18s ease, background .18s ease;
}
.amount-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.amount-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79, 142, 247, 0.25) inset; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }

.main { padding: 24px; }
.view-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.view-header h2 { margin: 0; }
.view-header .sub { color: var(--muted); }

/* 允许在房间视图进行双指缩放（在部分移动端浏览器需要显式声明） */
#roomView { touch-action: pinch-zoom; }

/* 进入房间时整体禁用页面滚动（防止出现上下/左右滑动）；采用安全视口高度避免底部遮挡 */
body.in-room {
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;   /* 回退 */
  height: 100dvh;  /* 动态视口高度（现代浏览器） */
  height: 100svh;  /* 安全视口高度（iOS Safari） */
  touch-action: none;
}
body.in-room .layout {
  height: 100vh;
  height: 100dvh;
  height: 100svh;
}
body.in-room #roomView {
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
}

/* 大厅标题（用户ID）靠右显示 */
#lobby .view-header { justify-content: flex-end; }

.rooms-grid { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 18px; max-width: 1280px; margin: 0 auto; grid-auto-rows: 1fr; }
.room-card {
  background: linear-gradient(180deg, #12162a 0%, #0e1326 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  height: 240px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}
.room-card .title { font-weight: 700; font-size: 16px; display: flex; align-items: baseline; justify-content: space-between; }
.room-card .title .room-num { font-size: 20px; font-weight: 800; }
.room-card .meta { color: var(--muted); font-size: 13px; }
.room-status { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.room-status .pc { color: var(--muted); font-size: 12px; }
.room-status .cd { color: var(--warn); font-size: 12px; }
/* 英文副标题（柔和、占一行） */
.sub-en { display: block; font-size: 11px; color: var(--muted); opacity: .85; line-height: 1.2; }
/* 提现按钮内的英文副标题使用白色 */
.withdraw-btn .sub-en { color: #fff; opacity: 1; }
/* 大厅房间状态闪烁灯（无文字） */
.status-dot, .badge {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-block;
  animation: blink 1.2s ease-in-out infinite;
  padding: 0;
  border: none;
  font-size: 0; /* 隐藏任何文字 */
  margin-right: 8px;
  flex-shrink: 0;
}
.status-dot.waiting, .badge.waiting { background: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.40), 0 0 12px rgba(37,99,235,.60); }
.status-dot.in_progress, .badge.in_progress { background: #d97706; box-shadow: 0 0 0 2px rgba(217,119,6,.40), 0 0 12px rgba(217,119,6,.60); }
.status-dot.cooldown, .badge.cooldown { background: #4b5563; box-shadow: 0 0 0 2px rgba(75,85,99,.40), 0 0 10px rgba(75,85,99,.55); }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .28; } }

/* 居中弹窗（NO TRX!） */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  width: min(92vw, 420px);
  background: #0b1220;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(0,0,0,0.45);
  color: #d1d5db;
  padding: 22px 22px 18px;
}
/* 充值弹窗更宽一点 */
.modal-box.wide {
  width: min(94vw, 560px);
}
.modal-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.modal-title-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.modal-title-row .modal-title { margin-bottom: 0; }
.modal-note { font-size: 13px; color: #9ca3af; }
.modal-desc { font-size: 14px; color: #9ca3af; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; }
.modal-actions .btn { min-width: 90px; }
.room-card .title { font-weight: 600; }
.room-card .meta { color: var(--muted); font-size: 13px; }
.room-card .actions { margin-top: auto; display: flex; }
.room-card .btn { width: 100%; }

/* 大厅房间卡的迷你翻牌预览 */
.mini-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; }
.mini-card {
  height: 22px;
  border-radius: 6px;
  background: #0f1430;
  border: 1px solid var(--border);
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.mini-card.joined { background: #e6e9f4; border-color: #e6e9f4; }
.mini-card.user-seat { border-color: rgba(245,165,36,.65); box-shadow: 0 0 0 2px rgba(245,165,36,.55), 0 0 10px rgba(245,165,36,.30); }
.mini-card.flipped.win { background: rgba(23,201,100,.18); border-color: rgba(23,201,100,.6); box-shadow: 0 0 0 2px rgba(23,201,100,.25) inset; }
.mini-card.flipped.lose { background: rgba(243,18,96,.16); border-color: rgba(243,18,96,.6); box-shadow: 0 0 0 2px rgba(243,18,96,.25) inset; }

/* 确保用户本人迷你方块在开奖/冷却时保持金色边框 */
.mini-card.user-seat.flipped.win,
.mini-card.user-seat.flipped.lose {
  border-color: rgba(245,165,36,.65);
  box-shadow: 0 0 0 2px rgba(245,165,36,.55), 0 0 10px rgba(245,165,36,.30);
}

/* 中心红色立体倒计时覆盖层 */
.countdown-overlay { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.countdown-overlay .num {
  color: #ef4444; /* 鲜红 */
  font-weight: 800; /* 加粗 */
  font-size: 58px; /* 更大 */
  text-shadow:
    0 2px 0 #a10000,
    0 6px 12px rgba(255, 48, 48, 0.6),
    0 10px 24px rgba(255, 48, 48, 0.35);
  filter: drop-shadow(0 10px 18px rgba(255, 48, 48, 0.25));
  animation: pop 700ms ease-in-out infinite alternate, blink 1.2s ease-in-out infinite; /* 闪烁+呼吸 */
}

@keyframes pop {
  from { transform: scale(0.94); }
  to { transform: scale(1.06); }
}

/* 金色发光呼吸效果 */
@keyframes goldGlow {
  from {
    text-shadow: 0 0 8px rgba(245,165,36,0.45), 0 0 16px rgba(245,165,36,0.35), 0 0 28px rgba(245,165,36,0.25);
  }
  to {
    text-shadow: 0 0 14px rgba(245,165,36,0.65), 0 0 28px rgba(245,165,36,0.50), 0 0 40px rgba(245,165,36,0.40);
  }
}

.btn {
  background: #12162a;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .18s ease, transform .18s ease, background .18s ease;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn.primary { background: linear-gradient(180deg, #153164 0%, #12254a 100%); border-color: #234a8f; }
.btn.primary:disabled { opacity: 0.6; cursor: not-allowed; }

.controls { display: flex; gap: 8px; margin-bottom: 8px; }
.controls { flex-wrap: wrap; }
.status { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; color: var(--muted); }
.result-info { color: var(--text); font-weight: 600; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 18px; align-items: start; max-width: none; margin: 0 auto; }

.card { width: 100%; aspect-ratio: 3/4; perspective: 900px; }
.card .inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .6s ease; }
.card.flipped .inner { transform: rotateY(180deg); }
.card .face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 12px; border: 1px solid var(--border); display: grid; place-items: center; }
.card .front { background: radial-gradient(220px 140px at 50% 30%, #19223f 0%, #11162b 70%); color: var(--muted); font-size: 48px; }
.card .back { transform: rotateY(180deg); font-weight: 700; font-size: 18px; letter-spacing: .5px; }
.card .back.win { background: linear-gradient(180deg, rgba(23, 201, 100, .15) 0%, rgba(23, 201, 100, .05) 100%); border-color: rgba(23, 201, 100, .45); color: var(--win); box-shadow: 0 0 0 2px rgba(23, 201, 100, .25) inset; }
.card .back.lose { background: linear-gradient(180deg, rgba(243, 18, 96, .12) 0%, rgba(243, 18, 96, .05) 100%); border-color: rgba(243, 18, 96, .45); color: var(--lose); box-shadow: 0 0 0 2px rgba(243, 18, 96, .25) inset; }
.label { text-align: center; font-size: 12px; color: var(--muted); margin-top: 6px; }
.label.user-label { color: var(--warn); font-weight: 700; text-shadow: 0 0 8px rgba(245,165,36,0.35), 0 0 16px rgba(245,165,36,0.25); }
/* 用户本人卡片的金色发光边框 */
.card.user-card .face {
  border-color: rgba(245,165,36,.65);
  box-shadow: 0 0 0 2px rgba(245,165,36,.28) inset, 0 0 14px rgba(245,165,36,.25);
}

.hidden { display: none; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  /* 中等屏：固定 3 列，避免出现 2 列且右侧留白 */
  .card-grid { grid-template-columns: repeat(3, minmax(140px, 1fr)); max-width: 960px; gap: 14px; }
}

/* 桌面端：分级固定列数以避免水平溢出与裁切 */
@media (min-width: 1024px) and (max-width: 1279px) {
  /* 1024–1279px：4 列 */
  .card-grid { grid-template-columns: repeat(4, minmax(160px, 1fr)); max-width: 980px; }
}
@media (min-width: 1280px) {
  /* ≥1280px：5 列，10 张卡牌 2 行完整可见 */
  .card-grid { grid-template-columns: repeat(5, minmax(160px, 1fr)); max-width: 1200px; }
}

/* 小屏手机：房间视图自适应为 2 列，并压缩边距 */
@media (max-width: 640px) {
  .main { padding: 12px; }
  .view-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  /* 小屏：固定 2 列，卡片尺寸与间距更紧凑 */
  .card-grid { grid-template-columns: repeat(2, minmax(120px, 1fr)); max-width: 560px; gap: 10px; }
  .card .front { font-size: clamp(24px, 10vw, 40px); }
  .card .back { font-size: clamp(14px, 4.2vw, 18px); }
  .label { font-size: 11px; margin-top: 4px; }
}
  /* 进入房间后，隐藏不必要区域，腾出空间以适配整屏显示 */
  body.in-room .toolbar { display: none; }
  body.in-room .sidebar { display: none; }
  body.in-room #roomView { height: 100vh; overflow: hidden; }
  body.in-room .main { padding: 8px; }
  /* 进入房间时去掉左侧 320px 轨道，主区占满宽度 */
  body.in-room .layout { grid-template-columns: 1fr; }
/* 以上为进入房间后的布局约束，移除多余的闭合括号以避免后续样式被浏览器忽略 */

/* Authentication UI */
.auth-box { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.auth-row { display: flex; gap: 6px; align-items: center; }
.auth-label { font-size: 12px; color: var(--muted); }
.auth-input { height: 28px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: #12162a; color: var(--text); }
.auth-status { font-size: 12px; color: var(--muted); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }

/* 桌面端保持 5 列，确保 10 张卡牌两行完整可见；移动端与中屏使用上面的自适应规则 */
/* 说明：去掉先前的 auto-fit 强制覆盖，避免某些分辨率下仅渲染 1–2 列导致内容被 overflow:hidden 裁切。*/

/* 终端修正：在房间视图中强制居中栅格并以高优先级断点覆盖，避免左侧堆叠与右侧空白 */
@media (min-width: 1280px) {
  /* 桌面宽屏：限制容器最大宽度，避免卡片过大导致第二行不完整 */
  #roomView .card-grid { grid-template-columns: repeat(5, minmax(150px, 1fr)) !important; justify-content: center; max-width: 1200px; margin: 0 auto; gap: 14px; }
}
@media (min-width: 1024px) and (max-width: 1279px) {
  /* 桌面普通屏：4 列并限制容器宽度，确保两行完整显示 */
  #roomView .card-grid { grid-template-columns: repeat(4, minmax(150px, 1fr)) !important; justify-content: center; max-width: 980px; margin: 0 auto; gap: 14px; }
}
@media (min-width: 641px) and (max-width: 960px) {
  #roomView .card-grid { grid-template-columns: repeat(3, minmax(140px, 1fr)) !important; justify-content: center; max-width: none; }
}
@media (max-width: 640px) {
  /* 手机端房间视图：前两行 4 列，第三行 2 列（每张跨 2 列） */
  #roomView .card-grid { grid-template-columns: repeat(4, minmax(72px, 1fr)) !important; justify-content: center; gap: 10px; max-width: none; }
  /* 第三行保持卡牌等宽，分别居中于第2、3列 */
  #roomView .card-grid > div:nth-child(9)  { grid-column: 2; }
  #roomView .card-grid > div:nth-child(10) { grid-column: 3; }
}
