/* 工具箱页：4 列图标网格 */
.tb-head {
  flex: none;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.tb-head__title { font-size: 22px; font-weight: 700; letter-spacing: .5px; margin-bottom: 12px; }

.tb-main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 14px calc(20px + var(--safe-b)); }

.tb-group { margin-top: 18px; }
.tb-group__title {
  display: flex; align-items: center;
  font-size: 15px; font-weight: 700;
  margin-bottom: 6px;
}
.tb-group__count { margin-left: 6px; font-size: 11px; font-weight: 400; color: var(--text-3); }

.tb-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px 4px;
  padding: 8px 0 4px;
}
.tb-item {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 0; text-align: center;
  transition: transform .12s ease;
}
.tb-item:active { transform: scale(.9); }
.tb-item__ico {
  width: 46px; height: 46px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
}
.tb-item__ico svg { width: 24px; height: 24px; }
.tb-item__name { font-size: 12px; color: var(--text-2); line-height: 1.3; }
.tb-item[hidden] { display: none; }
.tb-group[hidden] { display: none; }

.tb-empty {
  margin: 60px 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}
.tb-empty[hidden] { display: none; }

/* 底部返回 */
.tb-foot {
  flex: none;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: #fff;
  border-top: 1px solid var(--line);
}
.tb-back {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  border-radius: 22px;
  background: #f2f3f8;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  transition: transform .12s ease, background .12s ease;
}
.tb-back:active { transform: scale(.98); background: #e8eaf2; }
.tb-back__ico { width: 18px; height: 18px; fill: var(--brand); }

/* ===================== 工具弹窗（居中、略偏上） ===================== */
.sheet { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 0 0 var(--app-bottom, 0px); }
.sheet[hidden] { display: none; }
.sheet__mask { position: absolute; inset: 0; background: rgba(16, 18, 30, .45); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0 } }
.sheet__panel {
  position: relative;
  width: calc(100% - 40px);
  max-width: 340px;
  max-height: calc(100% - 40px);                 /* 预留上方空间，保证顶部不出屏 */
  margin-bottom: 34px;                            /* 视觉上比正中略高，避开 App 底栏 */
  display: flex; flex-direction: column;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  animation: popIn .22s cubic-bezier(.22, .8, .3, 1);
}
@keyframes popIn { from { opacity: 0; transform: scale(.9) } }
.sheet__head {
  flex: none;
  display: flex; align-items: center;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet__title { font-size: 16px; font-weight: 700; }
.sheet__close { margin-left: auto; width: 28px; height: 28px; }
.sheet__close svg { width: 100%; height: 100%; fill: #a8adbc; }
.sheet__body {
  flex: 1;
  min-height: 0;                        /* 允许在 flex 容器内收缩，超出时内部滚动 */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px;
}

/* ===================== 表单控件 ===================== */
.f { margin-bottom: 12px; }
.f__label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.f__input, .f__select, .f__textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f8fc;
  font-size: 14px;
}
.f__textarea { min-height: 88px; resize: vertical; line-height: 1.6; }
.f__input:focus, .f__select:focus, .f__textarea:focus { border-color: #c9bef7; background: #fff; }
.f__select { appearance: none; background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23a8adbc'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; background-size: 20px; padding-right: 32px; }
.f__row { display: flex; gap: 10px; }
.f__row > * { flex: 1; min-width: 0; }

.f__range { width: 100%; accent-color: var(--brand); }
.f__hint { font-size: 11px; color: var(--text-3); margin-top: 4px; }

.chk { display: flex; flex-wrap: wrap; gap: 8px; }
.chk__item {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 16px;
  font-size: 12px;
  color: var(--text-2);
}
.chk__item input { accent-color: var(--brand); margin: 0; }
.chk__item.is-on { border-color: #c9bef7; background: #f6f3ff; color: var(--brand); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px;
  border-radius: 20px;
  background: #f2f3f8;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: transform .1s ease, opacity .1s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn--main { width: 100%; background: var(--grad); color: #fff; box-shadow: 0 4px 12px rgba(110, 90, 240, .28); }
.btn--row { display: flex; gap: 10px; }
.btn--row .btn { flex: 1; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 12px; border-radius: 16px; }
.btn--danger { color: #ef4444; }

.drop {
  padding: 26px 14px;
  border: 1px dashed #d7dbe8;
  border-radius: 12px;
  background: #fafbff;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.drop.is-on { border-color: var(--brand); background: #f6f3ff; }
.drop__big { display: block; font-size: 14px; color: var(--text-2); margin-bottom: 4px; }

.result {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f7f8fc;
  font-size: 14px;
  word-break: break-all;
  white-space: pre-wrap;
}
.result--big { font-size: 22px; font-weight: 700; letter-spacing: .5px; }
.result__k { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }

.pv { display: block; max-width: 100%; border-radius: 10px; background: #f0f1f6; }
.canvas-box { position: relative; display: inline-block; max-width: 100%; touch-action: none; }
.canvas-box canvas { display: block; max-width: 100%; border-radius: 10px; }
.canvas-box__mask { position: absolute; inset: 0; pointer-events: none; }

.bar { height: 6px; border-radius: 3px; background: #eef0f6; overflow: hidden; margin-top: 8px; }
.bar__in { height: 100%; width: 0; background: var(--grad); transition: width .2s; }

.list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list__it { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; width: 100%; }
.list__it:last-child { border-bottom: 0; }
.list__t { flex: 1; min-width: 0; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list__d { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.list__x { flex: none; font-size: 12px; color: var(--text-3); }

.note-item { padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 9px; }
.note-item__t { font-size: 11px; color: var(--text-3); margin-bottom: 4px; display: flex; }
.note-item__t b { margin-left: auto; font-weight: 400; color: #c3c7d2; }
.note-item__c { font-size: 14px; white-space: pre-wrap; word-break: break-word; }

.seg { display: flex; padding: 3px; background: #f2f3f8; border-radius: 10px; margin-bottom: 12px; }
.seg__b { flex: 1; padding: 7px 0; border-radius: 8px; font-size: 13px; color: var(--text-2); text-align: center; }
.seg__b.is-on { background: #fff; color: var(--brand); font-weight: 600; box-shadow: 0 1px 4px rgba(20, 24, 50, .08); }

.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.keys button { height: 46px; border-radius: 12px; background: #f2f3f8; font-size: 18px; font-weight: 500; }
.keys button:active { background: #e5e7f0; }
.keys .k-fn { background: #e9e2fd; color: var(--brand); font-size: 15px; }
.keys .k-op { background: #dcd2fb; color: #5b3fd6; font-size: 18px; }
.keys .k-eq { background: var(--grad); color: #fff; }

.warn { padding: 10px 12px; border-radius: 10px; background: #fff6e8; color: #b4700a; font-size: 12px; line-height: 1.6; }
.err { padding: 10px 12px; border-radius: 10px; background: #fdecec; color: #d63b3b; font-size: 12px; line-height: 1.6; }
.warn[hidden], .err[hidden] { display: none; }

.cam { position: relative; width: 100%; aspect-ratio: 3/4; background: #000; border-radius: 12px; overflow: hidden; }
.cam video { width: 100%; height: 100%; object-fit: cover; }
.lamp { position: fixed; inset: 0; z-index: 50; background: #fff; pointer-events: none; }
.lamp[hidden] { display: none; }
