/* ================================================================
   工具箱扩展 —— 移动端界面 & 工具内部适配
   ----------------------------------------------------------------
   · 上半部分：工具总览/单个工具的界面（.tbx-grid / .tbx-card …）
     这些是我新写的，只给「工具箱扩展」用
   · 下半部分：工具内部（宿主原样式在 toolbox.css 里，已作用域到 .tbx）
     原来那套是给桌面宽屏设计的，这里做手机上的收窄与触摸适配
   ================================================================ */

/* ---------- 1) 工具总览 ---------- */
.tbx-badge {
  font-size: 11px; font-weight: normal; color: var(--primary);
  background: rgba(76, 175, 80, 0.12);
  border-radius: 8px; padding: 1px 8px; margin-left: 6px; vertical-align: 2px;
}
.tbx-input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  margin-bottom: 10px;
}
.tbx-input:focus { border-color: var(--primary); }

.tbx-chips {
  display: flex; flex-wrap: wrap; gap: 7px;
  margin-bottom: 14px;
}
.tbx-chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.tbx-chip.on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.tbx-sec-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700;
  margin: 18px 2px 10px;
  color: var(--text);
}
.tbx-sec-title:first-child { margin-top: 4px; }
.tbx-sec-n {
  font-size: 12px; font-weight: normal;
  color: var(--text-light);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}

.tbx-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 560px) {
  .tbx-grid { grid-template-columns: repeat(3, 1fr); }
}

.tbx-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s;
}
.tbx-card:active { transform: scale(0.97); }
.tbx-ico { font-size: 20px; line-height: 1; margin-bottom: 7px; }
.tbx-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  line-height: 1.35; margin-bottom: 4px;
  display: flex; align-items: center; flex-wrap: wrap; gap: 5px;
}
.tbx-tag {
  font-size: 10px; font-weight: normal;
  color: var(--primary); background: rgba(76, 175, 80, 0.12);
  border-radius: 5px; padding: 0 5px;
}
.tbx-desc {
  font-size: 11.5px; color: var(--text-light);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 2) 单个工具的头部 ---------- */
.tbx-head {
  display: flex; align-items: center; gap: 8px;
  margin: 0 2px 6px;
}
.tbx-head-ic { font-size: 22px; line-height: 1; }
.tbx-head-name { font-size: 17px; font-weight: 700; color: var(--text); }
.tbx-head-cat {
  font-size: 11px; color: var(--text-light);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 9px; margin-left: auto;
}
.tbx-desc-line {
  font-size: 12px; color: var(--text-light); line-height: 1.6;
  margin: 0 2px 12px;
}

/* ---------- 3) 工具内部：手机适配 ---------- */
/* 宿主原来给 .pane 包了边框和背景，我这里用自己的容器 */
.tbx {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  overflow-x: hidden;
}
.tbx * { max-width: 100%; }

/* 它的 .row 是横排；手机上要能换行，不然控件被挤扁 */
.tbx .row {
  flex-wrap: wrap !important;
  gap: 8px !important;
}
.tbx .row > label {
  flex: 0 0 auto;
  min-width: 0;
}
.tbx .row > input,
.tbx .row > select,
.tbx .row > textarea {
  flex: 1 1 140px;
  min-width: 0;
}

/* 按钮触摸目标别太小 */
.tbx .btn,
.tbx button {
  min-height: 34px;
  touch-action: manipulation;
}

/* 输入框字号 ≥16px，否则 iOS/部分 WebView 聚焦时会自动放大页面 */
.tbx input[type="text"],
.tbx input[type="number"],
.tbx input[type="search"],
.tbx input[type="date"],
.tbx input[type="datetime-local"],
.tbx textarea,
.tbx select {
  font-size: 16px !important;
}

/* 画布：宽度跟着容器走，别溢出 */
.tbx canvas {
  max-width: 100% !important;
  height: auto !important;
  touch-action: manipulation;
}

/* 表格：手机上允许横向滚动，别把布局撑破 */
.tbx table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* 拖拽区：手机上点一下就能选文件，顺手把提示改成触摸友好的 */
.tbx .drop {
  padding: 18px 12px !important;
  text-align: center;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 它的 .chips 是一排按钮，手机上要换行 */
.tbx .chips {
  flex-wrap: wrap !important;
  gap: 6px !important;
}

/* 大段说明文字收一收 */
.tbx .hint { font-size: 12.5px !important; line-height: 1.6; }
.tbx .stat { font-size: 12.5px !important; }

/* 双列布局在手机上压成一列 */
.tbx .cards,
.tbx .grid2,
.tbx .cols2 {
  grid-template-columns: 1fr !important;
  display: block !important;
}
.tbx .cards > * { margin-bottom: 10px; }

/* 内嵌 iframe 型工具 */
.tbx-frame {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

/* ---------- 4) 大图预览在手机上的尺寸 ---------- */
@media (max-width: 560px) {
  #lightbox .lb-bar { flex-wrap: wrap; }
  #lightbox .lb-img-wrap { padding: 10px; }
}

/* ---------- 5) 主 App 里嵌的那个 https 工具箱页面 ----------
   为什么是 iframe：主页面跑在 file://（为了不让 wgbh.cn 的接口挂），
   而加密/哈希/录制类工具需要【安全上下文】才有 crypto.subtle / getUserMedia。
   把工具箱放进 https 源的 iframe，它自己就是安全上下文。 */
.tbx-app-frame {
  width: 100%;
  height: calc(100dvh - var(--tabbar-h) - 78px - env(safe-area-inset-top));
  min-height: 380px;
  border: 0;
  border-radius: 12px;
  background: var(--bg);
  display: block;
}

/* 去重提示条 */
.tbx-hide-note {
  font-size: 12px;
  color: var(--text-light);
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: 9px;
  padding: 8px 12px;
  margin-bottom: 10px;
  line-height: 1.6;
}

/* ---------- v0.81：工具箱状态条 ----------
   为什么需要它：0.80 三个分类空白，但界面完全不报错，根本看不出卡在哪一步。
   现在把加载状态直接显示出来：加载中 / 已接入 N 个 / 加载失败（可点重试）。 */
.tbx-status {
  font-size: 12px;
  color: var(--text-light);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 12px;
  margin: 0 2px 10px;
  line-height: 1.6;
}
.tbx-status.ok { color: var(--primary-dark); border-color: rgba(76, 175, 80, 0.35); background: rgba(76, 175, 80, 0.07); }
.tbx-status.err { color: #c62828; border-color: #ef9a9a; background: #fdecea; cursor: pointer; font-weight: 600; }

/* ---------- v0.82：标题后面的工具数小字（原状态条已取消） ---------- */
.tool-count {
  font-size: 12px;
  font-weight: normal;
  color: var(--text-light);
  margin-left: 2px;
}

/* ================================================================
   v0.83：游戏面板
   ----------------------------------------------------------------
   游戏套用了宿主的 .pane > .pbody 结构（gameLayoutPane 按这两个类找卡片重排），
   但宿主的 .pane 是「整屏 flex」设计，而我们的容器在可滚动的 #view 里，
   直接套会被 display:none 掉、或者塌成 0 高。
   所以这里给游戏面板单独定：
     · 显式 display:flex + 一个【有界高度】
       （gameFitCanvas 要量 .gm-stage 的宽高，高度不确定就量出 0 → 画布没尺寸）
   ================================================================ */
.tbx .pane.tbx-game {
  display: flex !important;
  flex-direction: column;
  flex: none !important;
  height: calc(100dvh - 170px);
  min-height: 380px;
  overflow: hidden !important;
}
.tbx .pane.tbx-game > .pbody {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}
/* gameLayoutPane 会给 .pbody 加上 gm-body（宿主那套 flex 布局） */
.tbx .pane.tbx-game > .pbody.gm-body {
  display: flex;
  flex-direction: column;
  padding: 10px 12px 0;
}

/* ★ 手机上最关键的一条：宿主给右侧信息栏留了 208~300px，
   在 360px 宽的屏幕上会把画布挤成一条缝。窄屏改成「画布在上、状态横排在下面」。 */
@media (max-width: 620px) {
  .tbx .gm-main { flex-direction: column !important; gap: 8px !important; }
  .tbx .gm-side {
    flex: 0 0 auto !important;
    max-height: 96px;
    overflow-y: auto;
    flex-direction: row !important;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 6px 14px !important;
    padding: 8px 10px !important;
    font-size: 13px;
  }
  .tbx .gm-side .stat { font-size: 13px !important; }
  .tbx .gm-bar { flex-wrap: wrap; gap: 6px; padding: 8px 0 10px; }
  .tbx .gm-stage { padding: 2px 0 !important; }
}
