/* ============================================================
   游戏大厅 — 简约蓝色主题
   ============================================================ */
:root {
  --brand: #185FA5;
  --brand-dark: #0C447C;
  --brand-tint: #E6F1FB;
  --bg: #F7FAFC;
  --card: #FFFFFF;
  --text: #1A2B3C;
  --text-2: #64748B;
  --border: #E2E8F0;
  --success: #1D9E75;
  --radius: 12px;
}

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

[hidden] { display: none !important; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  overscroll-behavior: none; /* 禁止下拉刷新/弹性滚动，避免干扰游戏手势 */
}

.view {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 56px;
}

/* ---------- 按钮 ---------- */
.btn-ghost {
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand-dark); }

.btn-primary {
  padding: 9px 22px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--brand-dark); }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 20px;
}
.site-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--brand-dark);
}
.site-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }

/* ---------- 分类筛选 ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.filter {
  padding: 5px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.filter:hover { border-color: var(--brand); color: var(--brand-dark); }
.filter.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- 卡片网格 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(15, 60, 110, .12);
  border-color: var(--brand);
}
.thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: var(--brand-tint);
}
.thumb-fallback {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-tint);
  color: var(--brand-dark);
  font-weight: 600;
  font-size: 15px;
}
.card-body { padding: 12px 14px 14px; }
.card-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.cat-tag {
  font-size: 11px;
  color: var(--brand);
  background: var(--brand-tint);
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 500;
}
.card-desc { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.card-best {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--brand-dark);
}

/* ---------- 游戏视图 ---------- */
#game.view {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: 20px;
  padding-bottom: 20px;
}
.gamebar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.game-title { font-size: 20px; font-weight: 600; color: var(--brand-dark); }
.game-best { margin-left: auto; font-size: 13px; color: var(--text-2); }
.game-container {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.game-frame {
  border: none;
  display: block;
  max-width: 100%;
  background: transparent;
  transform-origin: center center;
}
.game-frame.fade-in { animation: gf-in .25s ease; }
@keyframes gf-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- 结算面板 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 40, 70, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(15, 40, 70, .25);
}
.m-name { font-size: 14px; color: var(--text-2); }
.m-score { font-size: 40px; font-weight: 700; color: var(--brand-dark); margin: 6px 0 2px; }
.m-newbest { color: var(--success); font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.m-best { font-size: 13px; color: var(--text-2); margin-bottom: 16px; }
.m-history {
  list-style: none;
  text-align: left;
  border-top: 1px solid var(--border);
  margin-bottom: 20px;
  max-height: 176px;
  overflow-y: auto;
}
.m-history li {
  display: flex;
  justify-content: space-between;
  padding: 8px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
}
.m-actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- 空态 / 提示 ---------- */
.empty { text-align: center; color: var(--text-2); font-size: 14px; padding: 40px 0; }
.loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  background: var(--card);
  border-radius: var(--radius);
}
.err { text-align: center; padding: 60px 0; }
.err p { color: var(--text-2); margin-bottom: 16px; }

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
  .view { padding: 20px 14px 40px; }
  .site-title { font-size: 22px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .modal-card { padding: 22px; }
  /* 手机端游戏视图铺满：去掉容器内边距（与 app.js 的 pad=0 一致）
     高度用 100dvh（动态视口）而非 100vh：100vh 在手机上包含浏览器
     地址栏占用的空间，会导致游戏内容底部被挤出屏幕；
     dvh 始终等于当前可视高度，内容自动避开顶部地址栏。
     padding-bottom:40px 使居中的游戏内容视觉上向上偏移约 20px
     （0~50px 范围内），避免内容偏下 */
  #game.view { padding: 0 0 40px; height: 100dvh; }
  .game-container { padding: 0; }
  /* 内边距清零后 gamebar 贴顶，补回上边距（左右留 12px） */
  .gamebar { padding: 10px 12px 0; }
}
