/* ============================================================
   游戏的「世界」· 高级感重设计（new_index.html 专用）
   液态玻璃 + 分类主题色渐变 + 三角/圆形碎片漂浮
   视觉风格参考《世界计划》官网：浅色纯色渐变 + 粉彩碎片
   ============================================================ */

/* 注册 --theme 为颜色属性，主题色切换时支持过渡动画（Chromium） */
@property --theme {
  syntax: '<color>';
  inherits: true;
  initial-value: #33aaee;
}

:root {
  --theme: #33aaee;                 /* 当前分类主题色（JS 动态切换） */
  --ink: #23302a;                   /* 主文字 */
  --ink-2: #5c6f60;                 /* 次级文字 */
  --ink-3: #8ba091;                 /* 弱化文字 */
  --glass-bg: rgba(255, 255, 255, 0.38);
  --glass-brd: rgba(255, 255, 255, 0.65);
  --shadow-soft: 0 14px 44px rgba(46, 84, 60, 0.12);
  transition: --theme 0.6s ease;    /* 主题色切换过渡（需上方 @property 注册） */
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  color: var(--ink);
  /* 主题色影响背景纯色：底部透出彩色的浅色底 */
  background-color: color-mix(in srgb, var(--theme) 15%, #ffffff);
  transition: background-color 0.6s ease, --theme 0.6s ease;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* 氛围层：顶部压白 + 粉/青对角柔光（仿世界计划官网） */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(58% 52% at 88% 6%, rgba(255, 179, 217, 0.20), transparent 70%),
    radial-gradient(52% 48% at 6% 96%, rgba(143, 232, 245, 0.22), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.30) 55%, rgba(255, 255, 255, 0.05) 100%);
}

/* ---------------- 漂浮碎片（JS 生成） ---------------- */
#frag {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}
.frag {
  position: absolute;
  opacity: 0.85;
  animation: frag-float var(--dur, 9s) ease-in-out var(--delay, 0s) infinite;
}
.frag svg { display: block; width: 100%; height: 100%; }
.frag .circle { width: 100%; height: 100%; border-radius: 50%; background: currentColor; }
@keyframes frag-float {
  0%, 100% { transform: translateY(0) rotate(var(--r0, 0deg)); }
  50%      { transform: translateY(-18px) rotate(var(--r1, 8deg)); }
}

/* ---------------- 液态玻璃通用 ---------------- */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid var(--glass-brd);
  box-shadow: var(--shadow-soft), inset 0 1px 1px rgba(255, 255, 255, 0.7);
}

.view[hidden] { display: none; }
/* 视图切换关键修复：#home/#game 用 ID 选择器写了 display:flex，优先级高于 .view[hidden]，
   必须显式压制，否则 hidden 失效、两个视图永远同时渲染（游戏视图被挤出视口，表现为"点击无反应"） */
#home[hidden], #game[hidden] { display: none; }

/* ============================================================
   视图一：展示大厅
   ============================================================ */
#home {
  position: relative;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 40px 28px;
  gap: 20px;
}

/* ---- 顶部导航（液态玻璃） ---- */
.topbar {
  flex: none;
  min-height: 64px;
  border-radius: 32px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 14px 8px 30px;
}
.logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--theme);              /* 跟随主题色 */
  transition: color 0.4s ease;
}
.cats { display: flex; gap: 6px; margin-inline: auto; }
.cat-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 9px 20px;
  border-radius: 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-2);
  background: transparent;
  transition: background 0.25s, color 0.25s, box-shadow 0.25s, transform 0.15s;
}
.cat-btn:hover { background: rgba(255, 255, 255, 0.55); }
.cat-btn:active { transform: scale(0.96); }
.cat-btn.on {
  background: var(--theme);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 5px 16px color-mix(in srgb, var(--theme) 45%, transparent);
}
.top-right { display: flex; align-items: center; gap: 10px; }
.count-pill {
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 16px;
  padding: 8px 16px;
}
.ghost-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.7);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.35);
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 16px;
  transition: background 0.25s;
  white-space: nowrap;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.6); }

/* ---- 主体：左侧 50% 信息区 + 右侧 50% 展示区 ---- */
.stage-wrap {
  flex: 1;
  display: flex;
  align-items: stretch;
  min-height: 0;
}

/* 左侧 50% 区域：信息卡保持固定宽高并居中 */
.info-side {
  flex: 0 0 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

/* 左侧信息卡（液态玻璃） */
.panel {
  position: relative;
  flex: none;
  width: 470px;
  border-radius: 28px;
  padding: 38px 42px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 100%;
  overflow: auto;
}
/* 右上角灰色序号：当前游戏 / 分类总数 */
.game-index {
  position: absolute;
  top: 42px;
  right: 42px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-3);
  pointer-events: none;
}
.cat-tag {
  align-self: flex-start;
  font-size: 13px;
  font-weight: 700;
  color: color-mix(in srgb, var(--theme) 72%, #1e2b22);
  background: color-mix(in srgb, var(--theme) 16%, transparent);
  padding: 5px 14px;
  border-radius: 13px;
}
.game-name { margin: 2px 0 0; font-size: 34px; font-weight: 800; letter-spacing: 0.01em; }
.game-desc { margin: 0; font-size: 15px; line-height: 1.75; color: var(--ink-2); }
.divider { border: 0; height: 1px; margin: 6px 0; background: rgba(70, 95, 75, 0.14); }
.sec-label { margin: 4px 0 0; font-size: 15px; font-weight: 700; }
/* 玩法文本定高（最多两行）：信息卡整体高度随之固定，切游戏不再跳动 */
.sec-text { margin: 0; font-size: 14px; line-height: 1.7; color: var(--ink-2); height: 48px; overflow: hidden; }
.records { display: flex; gap: 12px; margin-top: 4px; }
.rec {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 16px;
  padding: 12px 18px;
}
.rec-k { font-size: 12px; font-weight: 500; color: var(--ink-3); }
.rec-v { font-size: 20px; font-weight: 800; }
.controls { display: flex; gap: 14px; align-items: center; margin-top: auto; padding-top: 16px; }
.arrow-btn {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.8);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s, background 0.25s, box-shadow 0.25s;
}
.arrow-btn:hover { background: #fff; transform: translateY(-2px); box-shadow: 0 8px 18px rgba(46, 84, 60, 0.14); }
.arrow-btn:active { transform: scale(0.94); }
.arrow-btn svg { width: 20px; height: 20px; }
.play-btn {
  flex: 1;
  height: 52px;
  border: 0;
  border-radius: 26px;
  cursor: pointer;
  background: var(--theme);
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--theme) 45%, transparent);
  transition: transform 0.18s, filter 0.2s, box-shadow 0.25s;
}
.play-btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.play-btn:active { transform: scale(0.97); }

/* 右侧展示区（轮盘式切换） */
.stage { position: relative; flex: 1; min-width: 0; }
.card {
  position: absolute;
  background: #fff;
  border-radius: 24px;
  padding: 12px;
  box-shadow: 0 20px 48px rgba(46, 84, 60, 0.14);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.5s cubic-bezier(0.25, 0.9, 0.3, 1.15), box-shadow 0.3s, opacity 0.3s;
}
/* 未选中的图片笼罩 40% 灰色（主层透明无罩），轮盘转动时同步淡入淡出 */
.card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(128, 128, 128, 0.4);
  opacity: 1;
  transition: opacity 0.45s ease;
  z-index: 2;
  pointer-events: none;
}
.card-main::after { opacity: 0; }
/* 轮盘绕位卡：瞬移到新槽位（禁用过渡）并先隐形，换图后再淡入 */
.card.no-anim, .card.no-anim::after { transition: none; }
.card.ghost { opacity: 0; }
/* img 需提层：absolute 定位的 .card-fallback 绘制顺序高于静态 img，不提层会盖住预览图 */
.card img { position: relative; z-index: 1; display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 14px; }
.card-fallback {
  position: absolute;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: #a8b8ac;
  background: #eef4ee;
  border-radius: 14px;
}
.card-main {
  z-index: 3;
  width: min(600px, 78%);
  aspect-ratio: 29 / 18;
  left: 4%;
  top: 50%;
  translate: 0 -50%;
  transform: rotate(-2deg);
  border: 2px solid color-mix(in srgb, var(--theme) 45%, #ffffff);
}
.card-main:hover { transform: rotate(-2deg) translateY(-6px); box-shadow: 0 28px 60px rgba(46, 84, 60, 0.20); }
.card-prev { z-index: 2; width: 56%; aspect-ratio: 26 / 15; right: 8%; top: 3%; transform: rotate(-7deg); opacity: 0.9; }
.card-next { z-index: 1; width: 56%; aspect-ratio: 26 / 15; right: 1%; bottom: 2%; transform: rotate(6deg); opacity: 0.9; }
.card-prev:hover, .card-next:hover { opacity: 1; }
.card[hidden] { display: none; }
.img-in { animation: img-in 0.38s ease; }
@keyframes img-in {
  from { opacity: 0.2; transform: scale(1.04); }
  to   { opacity: 1;   transform: scale(1); }
}
/* 底部中央提示（相对 #home 定位） */
.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  z-index: 5;
  pointer-events: none;
  white-space: nowrap;
}

/* ============================================================
   加载过渡层：预览图滑到正中 + 进度条 +「加载游戏中...」
   ============================================================ */
#loader {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  background: rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
  backdrop-filter: blur(10px) saturate(1.3);
  opacity: 0;
  transition: opacity 0.45s ease;
}
#loader[hidden] { display: none; }
#loader.show { opacity: 1; }
#loader.fade-out { opacity: 0; }
.load-card {
  width: min(520px, 46vw);
  aspect-ratio: 29 / 18;
  background: #fff;
  border-radius: 24px;
  padding: 12px;
  box-shadow: 0 24px 60px rgba(46, 84, 60, 0.20);
  overflow: hidden;
  /* FLIP：JS 先瞬移到主卡位置，再过渡回正中 */
  transition: transform 0.65s cubic-bezier(0.25, 0.9, 0.3, 1.1);
}
.load-card img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 14px; }
.load-bar {
  width: min(420px, 56vw);
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.8);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease 0.25s, transform 0.4s ease 0.25s;
}
#loader.show .load-bar { opacity: 1; transform: none; }
.load-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: var(--theme);
  box-shadow: 0 0 12px color-mix(in srgb, var(--theme) 55%, transparent);
  transition: width 0.25s ease;
}
.load-text {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease 0.35s, transform 0.4s ease 0.35s;
}
#loader.show .load-text { opacity: 1; transform: none; }
/* 「加载游戏中」后的跳动省略号 */
.load-text::after { content: ''; display: inline-block; width: 1.4em; text-align: left; animation: load-dots 1.2s steps(4) infinite; }
@keyframes load-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75%, 100% { content: '...'; }
}

/* 开始游戏后：主页面元素向边缘淡出（导航向上、信息卡向左、展示区向右、提示淡出） */
#home .topbar, #home .info-side, #home .stage, #home .stage-hint {
  transition: transform 0.55s ease, opacity 0.55s ease;
}
#home.is-loading .topbar { transform: translateY(-140%); opacity: 0; }
#home.is-loading .info-side { transform: translateX(-90px); opacity: 0; }
#home.is-loading .stage { transform: translateX(90px); opacity: 0; }
#home.is-loading .stage-hint { opacity: 0; }

/* ============================================================
   视图二：游戏视图（iframe 隔离，沿用旧版框架）
   ============================================================ */
#game {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 40px 24px;
  gap: 16px;
}
.gamebar {
  flex: none;
  min-height: 60px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px 8px 14px;
  /* 初始隐藏，加载完成后向下淡入 */
  transform: translateY(-26px);
  opacity: 0;
  transition: transform 0.5s ease 0.1s, opacity 0.5s ease 0.1s;
}
#game.reveal .gamebar { transform: none; opacity: 1; }
.bar-sep { color: var(--ink-3); opacity: 0.6; user-select: none; }
.bar-item { font-size: 15px; color: var(--ink-2); white-space: nowrap; }
.bar-item b { color: var(--ink); font-weight: 700; }
.game-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.6);
  /* 初始隐藏，加载完成后向上淡入 */
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.5s ease 0.22s, transform 0.5s ease 0.22s;
}
#game.reveal .game-container { opacity: 1; transform: none; }
.game-frame {
  display: block;
  border: 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(46, 84, 60, 0.16);
  transform-origin: center center;
}
.err { display: flex; flex-direction: column; gap: 14px; align-items: center; color: var(--ink-2); }
.err p { margin: 0; }

/* ============================================================
   结算面板
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 60, 48, 0.28);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(420px, calc(100vw - 48px));
  border-radius: 26px;
  padding: 34px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* 调高不透明度：盖过背后游戏画面，保证结算内容清晰可读 */
  background: rgba(255, 255, 255, 0.88);
}
.m-name { margin: 0; font-size: 20px; font-weight: 800; }
.m-score { margin: 0; font-size: 40px; font-weight: 800; color: color-mix(in srgb, var(--theme) 80%, #1e2b22); }
.m-newbest { margin: 0; font-size: 14px; font-weight: 700; color: #e8a020; }
.m-best { margin: 0; font-size: 14px; color: var(--ink-2); }
.m-history {
  list-style: none;
  margin: 6px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid rgba(70, 95, 75, 0.14);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 150px;
  overflow: auto;
}
.m-history li { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); }
.m-history li.empty { justify-content: center; color: var(--ink-3); }
.m-actions { display: flex; gap: 12px; margin-top: 14px; }
.btn-primary {
  flex: 1;
  height: 46px;
  border: 0;
  border-radius: 23px;
  cursor: pointer;
  background: var(--theme);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--theme) 40%, transparent);
  transition: transform 0.18s, filter 0.2s;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: scale(0.97); }
.m-actions .ghost-btn { flex: 1; height: 46px; font-size: 15px; border-radius: 23px; }

/* ============================================================
   移动端（≤900px 堆叠布局；≤640px 游戏铺满，与旧版断点一致）
   ============================================================ */
@media (max-width: 900px) {
  body { overflow: auto; }
  /* 页面尽量 100vh 不滚动：flex 让展示区填满剩余高度 */
  #home { height: 100vh; min-height: 0; padding: 12px 12px 10px; gap: 10px; }

  /* 导航栏一行：隐藏 logo 与计数，只留分类按钮 + 清空 */
  .topbar { flex-wrap: nowrap; border-radius: 24px; padding: 8px 12px; gap: 8px; }
  .logo { display: none; }
  .cats { order: 0; width: auto; margin: 0; justify-content: flex-start; flex-wrap: nowrap; gap: 6px; flex: 1 1 auto; min-width: 0; }
  .cat-btn { padding: 8px 12px; font-size: 14px; white-space: nowrap; }
  .top-right { order: 1; width: auto; margin-left: auto; flex: none; }
  .count-pill { display: none; }
  #btnClear { flex: none; padding: 7px 12px; font-size: 13px; }

  /* 主体：展示区在上、信息卡在下，flex 填满剩余空间 */
  .stage-wrap { flex-direction: column-reverse; gap: 12px; flex: 1 1 auto; min-height: 0; }
  .info-side { flex: none; width: 100%; }
  .panel { width: 100%; padding: 20px; align-self: stretch; max-height: 64vh; overflow: auto; }
  .game-name { font-size: 24px; }
  .game-index { top: 24px; right: 22px; }

  /* 展示区：普通左右轮播，选中占 80% 宽，手势滑动 */
  .stage { flex: 1 1 auto; min-height: 160px; overflow: hidden; position: relative; }
  .card {
    top: 0; bottom: auto;
    height: 100%;
    aspect-ratio: auto;
    border-radius: 20px;
    padding: 10px;
  }
  .card-main {
    left: 50%; width: 80%;
    translate: none;
    transform: translateX(-50%);
  }
  .card-main:hover { transform: translateX(-50%); }
  .card-prev { left: 0; right: auto; width: 80%; transform: translateX(-60%); opacity: 0.7; }
  .card-next { left: 0; right: auto; bottom: auto; width: 80%; transform: translateX(60%); opacity: 0.7; }
  .card-prev:hover, .card-next:hover { opacity: 1; }

  .stage-hint { display: none; }
  #game { padding: 10px 10px 14px; }
  /* 游戏页导航栏一行：删前缀文本，只留数据，左（返回）中（游戏名）右（最佳成绩） */
  .gamebar { border-radius: 22px; gap: 10px; flex-wrap: nowrap; justify-content: space-between; }
  .bar-sep { display: none; }
  .bar-label { display: none; }
  .bar-item { font-size: 13px; white-space: nowrap; }
  .bar-title { flex: 1 1 auto; text-align: center; }
  .bar-best { text-align: right; }
}

@media (max-width: 640px) {
  /* 与旧版一致：窄屏下游戏容器去内边距，iframe 铺满 */
  .game-container { border-radius: 0; border: 0; background: transparent; }
  .game-frame { border-radius: 0; box-shadow: none; }
}
