:root {
  --bg: #151726;
  --card: rgba(24, 27, 46, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f5fb;
  --mute: #a8adc6;
  --accent: #ffb547;
  --accent2: #ff7a59;
  --ok: #5fd68a;
  --err: #ff8080;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.btn { font: inherit; border: 1px solid var(--line); background: rgba(255,255,255,0.08); color: var(--text);
  padding: 10px 18px; border-radius: 12px; cursor: pointer; font-weight: 700; transition: transform .08s, background .15s; }
.btn:hover { background: rgba(255,255,255,0.16); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; color: #2a1606; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { width: 100%; padding: 15px; font-size: 18px; border-radius: 14px; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.ghost { background: transparent; }

/* ---------- home ---------- */
#home { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(21,23,38,0.35), rgba(21,23,38,0.85)); overflow-y: auto; }
.home-card { width: min(420px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  padding: 26px 24px 20px; backdrop-filter: blur(10px); box-shadow: 0 20px 60px rgba(0,0,0,.45); text-align: center; }
.logo { font-size: 44px; line-height: 1; }
h1 { margin: 8px 0 6px; font-size: 30px; letter-spacing: 2px; }
.tag { margin: 0 0 18px; color: var(--mute); font-size: 14px; line-height: 1.6; }
.field { display: flex; flex-direction: column; text-align: left; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--mute); }
input { font: inherit; font-size: 16px; color: var(--text); background: rgba(0,0,0,0.3); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 14px; outline: none; }
input:focus { border-color: var(--accent); }
.or { margin: 18px 0 10px; color: var(--mute); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 700; }
.msg { margin: 12px 0 0; font-size: 14px; color: var(--err); line-height: 1.5; }
.game-strip { display: flex; gap: 8px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.game-strip figure { margin: 0; width: 110px; }
.game-strip img { width: 110px; height: 66px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.game-strip figcaption { font-size: 12px; color: var(--mute); margin-top: 4px; }

/* ---------- room HUD ---------- */
.room-card { position: fixed; left: max(12px, env(safe-area-inset-left)); top: max(12px, env(safe-area-inset-top));
  width: 250px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; backdrop-filter: blur(8px); }
.code-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--mute); flex-wrap: wrap; }
.code-line b { color: var(--accent); font-size: 22px; letter-spacing: 3px; }
#playerList { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 6px; }
#playerList li { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 6px 8px; border-radius: 10px; background: rgba(255,255,255,0.05); }
#playerList li.empty { color: var(--mute); font-size: 12px; }
#playerList .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#playerList .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#playerList .pill { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: rgba(255,181,71,0.2); color: var(--accent); }
.help { position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); font-size: 13px; color: var(--mute);
  background: rgba(0,0,0,0.35); padding: 6px 14px; border-radius: 999px; white-space: nowrap; pointer-events: none; }
.prompt { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 10px 12px; backdrop-filter: blur(8px); box-shadow: 0 12px 40px rgba(0,0,0,.45); max-width: calc(100% - 32px); }
.prompt img { width: 86px; height: 52px; object-fit: cover; border-radius: 10px; flex: none; }
.ptext { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ptext b { font-size: 16px; }
.ptext small { color: var(--mute); font-size: 12px; }
.prompt .btn.primary { padding: 12px 20px; font-size: 16px; white-space: nowrap; }
.wait { color: var(--mute); font-size: 13px; max-width: 180px; }
.banner { position: fixed; left: 50%; top: 56px; transform: translateX(-50%); background: rgba(255,181,71,0.16); color: var(--accent);
  border: 1px solid rgba(255,181,71,0.4); padding: 8px 14px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }
#joy { position: fixed; left: max(24px, env(safe-area-inset-left)); bottom: max(24px, env(safe-area-inset-bottom)); width: 130px; height: 130px;
  border-radius: 50%; background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.18); display: none; touch-action: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: rgba(255,255,255,0.35); pointer-events: none; }
body.touch #joy { display: block; }

/* ---------- 战绩 / 排行榜 ---------- */
.my-stats { margin-top: 14px; font-size: 13px; color: var(--mute); line-height: 1.7; }
.my-stats b { color: var(--accent); font-size: 15px; }
.my-stats .per { font-size: 12px; }
.board-card { position: fixed; right: max(12px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top));
  width: 280px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px 8px; backdrop-filter: blur(8px); }
.board-head { all: unset; cursor: pointer; display: flex; width: 100%; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 15px; padding: 2px 2px 6px; box-sizing: border-box; }
.board-head b { font-weight: 700; }
.board-card.collapsed .board-head { padding-bottom: 2px; }
.board-head i { font-style: normal; color: var(--mute); transition: transform .15s; }
.board-card.collapsed .board-head i { transform: rotate(-90deg); }
.board-card.collapsed table, .board-card.collapsed .board-note { display: none; }
#boardTable { width: 100%; border-collapse: collapse; font-size: 13px; }
#boardTable th { color: var(--mute); font-weight: 400; font-size: 11px; text-align: right; padding: 2px 4px; }
#boardTable th:nth-child(2), #boardTable td:nth-child(2) { text-align: left; }
#boardTable td { text-align: right; padding: 5px 4px; border-top: 1px solid var(--line); white-space: nowrap; }
#boardTable td:nth-child(2) { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
#boardTable td:first-child { color: var(--mute); }
#boardTable tr.top td:first-child { color: var(--accent); }
#boardTable tr.me td:nth-child(2) { color: var(--accent); font-weight: 700; }
#boardTable .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.board-note { margin: 6px 2px 0; font-size: 11px; color: var(--mute); }

/* ---------- game layer ---------- */
#gameLayer { position: fixed; inset: 0; background: #000; z-index: 10; }
#gameFrame { width: 100%; height: 100%; border: 0; display: block; }
/* 放在右侧中间，避开各游戏左上 / 右上 / 底部的按钮 */
.back { position: fixed; right: max(6px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); z-index: 11;
  background: rgba(0,0,0,0.45); opacity: .7; writing-mode: vertical-rl; padding: 10px 6px; letter-spacing: 2px; }
.back:hover { opacity: 1; }

/* ---------- misc ---------- */
#busy { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(10,11,20,0.7); }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: rgba(0,0,0,0.75); padding: 8px 16px; border-radius: 999px; font-size: 14px; animation: fade 3s forwards; }
@keyframes fade { 0% { opacity: 0; transform: translateY(6px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

@media (max-width: 640px) {
  /* 窄屏：收起时只是一个小奖杯按钮；展开时盖在房间名单上面 */
  .board-card { width: min(280px, calc(100vw - 24px)); padding: 6px 8px; z-index: 5; }
  .board-card.collapsed { width: auto; padding: 6px 10px; }
  .board-card.collapsed .lbl, .board-card.collapsed .board-head i { display: none; }
  .board-card.collapsed .board-head { padding: 2px 0; font-size: 18px; }
  #boardTable { font-size: 12px; }
  #boardTable td:nth-child(2) { max-width: 90px; }
  .room-card { width: 200px; padding: 10px; }
  .code-line b { font-size: 18px; }
  #playerList li { font-size: 12px; padding: 4px 6px; }
  .help { display: none; }
  .prompt img { display: none; }
  .wait { max-width: 140px; }
}
@media (max-height: 480px) {
  .board-card { width: 220px; padding: 4px 8px; }
  #boardTable td { padding: 3px 4px; }
  .board-note { display: none; }
  .room-card { width: 190px; padding: 8px; }
  #playerList { margin: 6px 0; gap: 3px; }
  #playerList li { padding: 3px 6px; font-size: 12px; }
  .help { display: none; }
}
