/* 奶蛙幸存者 —— 图鉴样式（v0.31.0 起图鉴内置在 index.html 里，不再是独立页面）
 *
 * 三栏：左列表 / 中预览 / 右信息，外面套一层 `#codex` overlay。
 * 尺寸一律按 `--stage-w` / `--stage-h` 排（js/game.js 的 resize() 写进 body）：
 * 竖屏手机的「伪横屏」是把整个舞台旋转 90° 得到的，此时 vh/vw 和舞台对不上，
 * 和 char-select.css 用同一套变量才不会在手机上排成一锅粥。
 */
#codex {
  --cx-bg: #0d1117;
  --cx-panel: #141a26;
  --cx-panel-2: #161d2a;
  --cx-line: #263048;
  --cx-line-2: #33415c;
  --cx-text: #dfe6f2;
  --cx-dim: #8fa0b8;
  --cx-gold: #ffd24a;
  /* overlay 默认留 12px 安全区，图鉴要尽量多占地方 */
  padding: max(4px, var(--sa-t)) max(4px, var(--sa-r)) max(4px, var(--sa-b)) max(4px, var(--sa-l));
}

.cx {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(6px, calc(var(--stage-h, 100vh) * 1.4 / 100), 16px);
  width: 100%;
  height: 100%;
  padding: clamp(6px, calc(var(--stage-h, 100vh) * 1.6 / 100), 18px) clamp(8px, calc(var(--stage-w, 100vw) * 2 / 100), 26px) clamp(8px, calc(var(--stage-h, 100vh) * 1.8 / 100), 20px);
  border: 1px solid var(--cx-line);
  border-radius: 14px;
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(70, 110, 160, 0.18), transparent 70%),
    radial-gradient(900px 600px at 100% 110%, rgba(120, 90, 160, 0.14), transparent 70%),
    rgba(13, 17, 23, 0.96);
  color: var(--cx-text);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  overflow: hidden;
}

/* ---------------- 顶栏 ---------------- */
.cx-top {
  display: flex;
  align-items: center;
  gap: clamp(6px, calc(var(--stage-w, 100vw) * 1.4 / 100), 18px);
}

.cx-back {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.42em 0.9em;
  border-radius: 0.6em;
  border: 1px solid var(--cx-line-2);
  background: var(--cx-panel-2);
  color: #ffe9ad;
  text-decoration: none;
  font-family: inherit;
  font-size: clamp(12px, calc(var(--stage-h, 100vh) * 1.7 / 100), 15px);
  white-space: nowrap;
  cursor: pointer;
}
.cx-back:hover { border-color: var(--cx-gold); color: #fff3c9; }
.cx-back:focus-visible { outline: 0.16em solid #ffd98a; outline-offset: 0.15em; }

.cx-title {
  margin: 0;
  font-size: clamp(18px, calc(var(--stage-h, 100vh) * 3 / 100), 30px);
  letter-spacing: 0.16em;
  text-shadow: 0 2px 10px rgba(255, 210, 74, 0.25);
}

.cx-sub {
  color: var(--cx-dim);
  font-size: clamp(10px, calc(var(--stage-h, 100vh) * 1.5 / 100), 13px);
  letter-spacing: 0.06em;
}

.cx-tabs {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.cx-tab {
  padding: 0.42em 1.2em;
  border-radius: 999px;
  border: 1px solid var(--cx-line-2);
  background: var(--cx-panel-2);
  color: var(--cx-dim);
  font-size: clamp(12px, calc(var(--stage-h, 100vh) * 1.7 / 100), 15px);
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.cx-tab:hover { color: var(--cx-text); border-color: #4b5b7c; }
.cx-tab.on {
  background: var(--cx-gold);
  border-color: var(--cx-gold);
  color: #2a2110;
  font-weight: 700;
}
.cx-tab:focus-visible { outline: 0.16em solid #ffd98a; outline-offset: 0.15em; }

/* ---------------- 主体三栏 ---------------- */
.cx-main {
  display: grid;
  grid-template-columns:
    clamp(120px, calc(var(--stage-w, 100vw) * 13 / 100), 210px)
    minmax(0, 1fr)
    clamp(196px, calc(var(--stage-w, 100vw) * 25 / 100), 360px);
  gap: clamp(6px, calc(var(--stage-w, 100vw) * 1.2 / 100), 16px);
  min-height: 0;
}

/* 左：列表 */
.cx-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--cx-line-2) transparent;
  -webkit-overflow-scrolling: touch;
}
.cx-list::-webkit-scrollbar { width: 6px; }
.cx-list::-webkit-scrollbar-thumb { background: var(--cx-line-2); border-radius: 99px; }

.cx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--cx-line);
  background: var(--cx-panel);
  color: var(--cx-text);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, transform 0.14s;
}
.cx-item:hover { border-color: #4b5b7c; transform: translateX(2px); }
.cx-item.on {
  border-color: var(--cx-gold);
  background: #212a3a;
  box-shadow: inset 0 0 0 1px rgba(255, 210, 74, 0.55);
}
.cx-item img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}
.cx-item .cx-thumb {
  display: block;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}
.cx-txt { display: flex; flex-direction: column; min-width: 0; }
.cx-txt .nm {
  font-size: clamp(12px, calc(var(--stage-h, 100vh) * 1.7 / 100), 14px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cx-txt .sub {
  font-size: clamp(9px, calc(var(--stage-h, 100vh) * 1.25 / 100), 11px);
  color: var(--cx-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 中：画布 + 动作按钮 */
.cx-stage {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: clamp(6px, calc(var(--stage-h, 100vh) * 1.2 / 100), 14px);
  border-radius: 12px;
  border: 1px solid var(--cx-line);
  background: var(--cx-panel);
}

.cx-canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background:
    radial-gradient(circle at 50% 38%, #1d2534 0%, #0c1018 72%);
  overflow: hidden;
}

#cxCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  aspect-ratio: 3 / 2;
}

.cx-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.cx-act {
  padding: 0.34em 0.9em;
  border-radius: 999px;
  border: 1px solid var(--cx-line-2);
  background: var(--cx-panel-2);
  color: var(--cx-dim);
  font-size: clamp(11px, calc(var(--stage-h, 100vh) * 1.5 / 100), 13px);
  font-family: inherit;
  cursor: pointer;
}
.cx-act:hover { color: var(--cx-text); border-color: #4b5b7c; }
.cx-act.on { background: #2f3b52; border-color: #8fd0ff; color: #eaf3ff; }

.cx-play {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--cx-dim);
  font-size: clamp(10px, calc(var(--stage-h, 100vh) * 1.4 / 100), 12px);
}
.cx-play button {
  padding: 0.3em 0.85em;
  border-radius: 6px;
  border: 1px solid var(--cx-line-2);
  background: var(--cx-panel-2);
  color: var(--cx-text);
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}
.cx-play button:hover { border-color: var(--cx-gold); }
.cx-play input[type="range"] {
  width: clamp(58px, calc(var(--stage-w, 100vw) * 7 / 100), 92px);
  accent-color: var(--cx-gold);
  vertical-align: middle;
}
#cxFrame { min-width: 72px; text-align: center; color: #b9c6da; }

/* 右：信息 */
.cx-info {
  overflow-y: auto;
  padding: clamp(8px, calc(var(--stage-h, 100vh) * 1.6 / 100), 18px);
  border-radius: 12px;
  border: 1px solid var(--cx-line);
  background: var(--cx-panel);
  scrollbar-width: thin;
  scrollbar-color: var(--cx-line-2) transparent;
  -webkit-overflow-scrolling: touch;
}
.cx-info::-webkit-scrollbar { width: 6px; }
.cx-info::-webkit-scrollbar-thumb { background: var(--cx-line-2); border-radius: 99px; }

.cx-info h2 {
  margin: 0 0 6px;
  font-size: clamp(18px, calc(var(--stage-h, 100vh) * 2.5 / 100), 24px);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.cx-tag {
  font-size: clamp(10px, calc(var(--stage-h, 100vh) * 1.35 / 100), 12px);
  font-weight: 400;
  padding: 0.2em 0.7em;
  border-radius: 999px;
  background: rgba(255, 210, 74, 0.14);
  border: 1px solid rgba(255, 210, 74, 0.35);
  color: #ffe09a;
}
.cx-desc {
  margin: 0 0 10px;
  color: #b9c6da;
  font-size: clamp(12px, calc(var(--stage-h, 100vh) * 1.6 / 100), 14px);
  line-height: 1.65;
}
.cx-sec {
  margin: 14px 0 8px;
  padding-left: 8px;
  border-left: 3px solid var(--cx-gold);
  font-size: clamp(12px, calc(var(--stage-h, 100vh) * 1.6 / 100), 14px);
  color: #ffe9ad;
  letter-spacing: 0.06em;
}
.cx-stats,
.cx-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.cx-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 9px;
  border-radius: 7px;
  background: #1b2231;
  border: 1px solid #232c40;
  font-size: clamp(11px, calc(var(--stage-h, 100vh) * 1.5 / 100), 13px);
}
.cx-stat .k { color: var(--cx-dim); }
.cx-stat .v { color: #9fe08a; font-weight: 700; font-variant-numeric: tabular-nums; }
.cx-grid .cx-stat .v { color: #ffd9a0; }

.cx-skill {
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: #18202e;
  border: 1px solid #24304a;
}
.cx-skill b {
  display: block;
  margin-bottom: 4px;
  color: #ffd98a;
  font-size: clamp(12px, calc(var(--stage-h, 100vh) * 1.6 / 100), 14px);
}
.cx-skill p {
  margin: 0;
  color: #b9c6da;
  font-size: clamp(11px, calc(var(--stage-h, 100vh) * 1.5 / 100), 13px);
  line-height: 1.62;
}
.cx-tip {
  margin: 0;
  color: #a9b8cc;
  font-size: clamp(11px, calc(var(--stage-h, 100vh) * 1.5 / 100), 13px);
  line-height: 1.65;
}
.cx-meta {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--cx-line);
  color: var(--cx-dim);
  font-size: clamp(10px, calc(var(--stage-h, 100vh) * 1.4 / 100), 12px);
}
.cx-muted { color: var(--cx-dim); font-size: 13px; }

/* ---------------- 语音 ---------------- */
.cx-voice {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--cx-line);
}
.cx-voice-btn {
  padding: 0.42em 1.1em;
  border-radius: 999px;
  border: 1px solid rgba(255, 210, 74, 0.45);
  background: rgba(255, 210, 74, 0.12);
  color: #ffe9ad;
  font-family: inherit;
  font-size: clamp(11px, calc(var(--stage-h, 100vh) * 1.5 / 100), 13px);
  cursor: pointer;
  white-space: nowrap;
}
.cx-voice-btn:hover { background: rgba(255, 210, 74, 0.2); border-color: var(--cx-gold); }
.cx-voice-btn:focus-visible { outline: 0.16em solid #ffd98a; outline-offset: 0.15em; }
.cx-voice-btn:disabled { opacity: 0.5; cursor: default; }
.cx-voice-tip { color: var(--cx-dim); font-size: clamp(10px, calc(var(--stage-h, 100vh) * 1.4 / 100), 12px); }

/* 舞台又矮又窄（手机横屏 / 小窗口）时，把顶栏那行说明藏掉，并把动作按钮压扁，把高度让给三栏内容 */
@media (max-height: 430px) {
  .cx-title, .cx-tab, .cx-back { white-space: nowrap; }
  .cx-sub { display: none; }
  .cx-act { padding: 0.2em 0.7em; }
  .cx-actions { gap: 4px; }
  .cx-play { gap: 5px; }
  .cx-play button { padding: 0.22em 0.7em; }
}
