/* 拼图助手：顶栏（撤销重做导入 / 标题 / 导出中EN）+ 铺满的舞台 + 贴边的面板。
   手机竖屏：模式条在舞台顶上居中，面板是贴着页面底边的一条（上面两行调节区，下面一排功能标签）。
   宽屏（html.is-wide，由 KK.kit.shell 写上）：模式条和面板合成左上角的一块。同一份 DOM 只换位置。
   面板里每一页都是两行高，切页、切模式面板大小不变，画板不跳。 */

/* 尺寸令牌：字号只有三档（小字、正文、标题；输入框用标题档），按钮高只有一个，小标签矮一档。 */
:root {
  --text: 14px;
  --text-small: 13px;
  --text-title: 16px;
  --control: 32px;
  --chip: 28px;
  --icon: 20px;
  --row-h: 36px;
  --top-h: 48px;
  --lang-h: 28px;
  --lang-min-w: 36px;
  --lang-text: 13px;
  --win-bar-bg: #ffffff;
  --win-bar-ink: var(--ink);
}

.cl-top .kit-ibtn {
  width: 36px;
  height: 36px;
}

.cl-top .kit-ibtn::before {
  left: -4px;
  right: -4px;
  top: -4px;
  bottom: -4px;
}

/* 所有文字按钮一样高、一个字号；点击区靠伪元素扩到 44 */
.kit-btn,
.kit-btn-sm,
.btn,
.cl-tabs .kit-chip,
.kit-chip {
  min-height: var(--control);
  font-size: var(--text);
}

.kit-btn::before,
.btn::before,
.kit-chip::before {
  content: '';
  position: absolute;
  left: calc(var(--border-w) * -1);
  right: calc(var(--border-w) * -1);
  top: calc((var(--touch) - var(--control)) / -2 - var(--border-w));
  bottom: calc((var(--touch) - var(--control)) / -2 - var(--border-w));
}

.btn {
  position: relative;
}

.kit-seg-btn {
  font-size: var(--text);
}

.kit-chips {
  padding-top: calc((var(--touch) - var(--control)) / 2);
  padding-bottom: calc((var(--touch) - var(--control)) / 2);
}

.kit-toggle {
  position: relative;
  min-height: var(--control);
}

.kit-num {
  font-size: var(--text);
}

.kit-fbar-grip {
  height: var(--control);
}

.add-chip {
  font-size: var(--text-title);
}

.cl-top .kit-btn {
  padding: 0 var(--gap-2);
}

.cl-app {
  --cl-row: 36px;
  --cl-side-w: 328px;
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  background: var(--desk);
}

/* ---------- 顶栏：左右两格同宽，标题永远在整行正中 ---------- */
.cl-top {
  position: absolute;
  z-index: var(--z-rail);
  left: 0;
  top: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) calc(var(--gap-2) + env(safe-area-inset-right)) 0 calc(var(--gap-2) + env(safe-area-inset-left));
  border-bottom: 1px solid var(--top-line);
  background: var(--top-bg);
}

.cl-top-l,
.cl-top-r {
  display: flex;
  align-items: center;
  min-width: 0;
}

.cl-top-r {
  justify-content: flex-end;
}

.cl-top-l > * + *,
.cl-top-r > * + * {
  margin-left: 2px;
}

.cl-top-home {
  white-space: nowrap;
}

.cl-title {
  margin: 0 var(--gap-1);
  color: var(--ink);
  font-size: var(--text-title);
  font-weight: var(--title-weight);
  letter-spacing: var(--title-ls);
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

/* ---------- 舞台 ---------- */
.cl-stage {
  position: absolute;
  left: 0;
  top: calc(var(--top-h) + env(safe-area-inset-top));
  right: 0;
  bottom: 0;
  overflow: hidden;
  touch-action: none;
}

.cl-canvas {
  position: absolute;
  left: 0;
  top: 0;
  touch-action: none;
}

.cl-hud {
  position: absolute;
  z-index: var(--z-content);
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.cl-side {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  pointer-events: none;
}

/* ---------- 面板 ---------- */
.cl-dock {
  flex: none;
  width: 100%;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  border-top: 1px solid var(--panel-line);
  background: var(--panel-bg);
  pointer-events: auto;
  --kit-label-w: auto;
}

.cl-dock-in {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

/* 叠在同一格的几页：只显示当前页，其余占位不显示 */
.cl-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.cl-stack > * {
  grid-area: 1 / 1;
  min-width: 0;
  visibility: hidden;
}

.cl-stack > .is-cur {
  visibility: inherit;
}

.cl-panes {
  height: calc(var(--cl-row) * 2 + var(--gap-1) + var(--gap-2) * 2);
  padding: var(--gap-2) var(--gap-3);
}

.cl-pane,
.cl-sub {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: calc(var(--cl-row) * 2 + var(--gap-1));
}

.cl-pane-layout {
  display: grid;
}

/* 一行：44 高，里面的东西竖直居中、左右排开 */
.cl-r,
.cl-rs {
  flex: none;
  height: var(--cl-row);
  align-items: center;
}

.cl-r {
  display: flex;
}

.cl-r > * + * {
  margin-left: var(--gap-2);
}

.cl-r > .kit-seg-fill,
.cl-r > .kit-slider,
.cl-r > .color-bar,
.cl-r > .cl-swatches {
  flex: 1 1 0;
  min-width: 0;
}

.cl-r > .kit-btn,
.cl-r > .kit-seg:not(.kit-seg-fill),
.cl-r > .color-button {
  flex: none;
}

.cl-r > .kit-btn {
  white-space: nowrap;
}

.cl-rs > * {
  align-self: center;
}

.cl-dock .kit-row {
  min-height: var(--control);
}

.cl-dock .kit-row-label,
.cl-label {
  flex: none;
  color: var(--ink-2);
  font-size: var(--text-small);
  font-weight: var(--font-weight);
  white-space: nowrap;
}

.cl-pane > .kit-chips,
.cl-rs > .kit-chips {
  flex: none;
  height: var(--cl-row);
}

/* ---------- 功能标签：没有外框的一排字，当前页是一块深色 ---------- */
.cl-tabbar {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--line-soft);
  padding: 0 var(--gap-2);
}

.cl-tabs {
  flex: 1 1 0;
  min-width: 0;
}

.cl-tabs .kit-chip {
  flex: 1 0 auto;
  border-color: var(--panel-bg);
  background: var(--panel-bg);
  color: var(--ink-2);
  font-size: var(--text);
  font-weight: var(--font-weight);
}

.cl-tabs .kit-chip + .kit-chip {
  margin-left: var(--gap-1);
}

.cl-tabs .kit-chip.is-on {
  border-color: var(--sel-bg);
  background: var(--sel-bg);
  color: var(--sel-ink);
}

/* ---------- 版式：缩略图一排 ---------- */
.cl-thumbs {
  display: flex;
  flex: none;
  align-items: center;
  height: var(--cl-row);
  touch-action: pan-x;
}

.cl-thumbs > .kit-chip {
  flex: none;
  margin-right: var(--gap-2);
  margin-left: 0;
  touch-action: pan-x;
}

.cl-thumb-list {
  display: flex;
  flex: none;
  align-items: center;
}

.cl-thumb {
  position: relative;
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: var(--border-w) solid var(--btn-line);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  touch-action: pan-x;
}

.cl-thumb + .cl-thumb {
  margin-left: var(--gap-2);
}

.cl-thumb.is-on {
  border-color: var(--sel-bg);
  background: var(--sel-bg);
}

.cl-thumb-cv {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- 比例：形状在左、字在右的扁钮，两排，左右滑 ---------- */
.cl-pane-ratio {
  justify-content: center;
}

.cl-ratios {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  grid-template-rows: repeat(2, var(--control));
  grid-gap: var(--gap-2);
  align-content: center;
  justify-content: start;
  height: calc(var(--cl-row) * 2 + var(--gap-1));
  touch-action: pan-x;
}

.cl-ratio {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--control);
  min-width: 64px;
  padding: 0 var(--gap-2);
  border: var(--border-w) solid var(--btn-line);
  border-radius: var(--radius-btn);
  background: var(--btn-bg);
  color: var(--ink-2);
  touch-action: pan-x;
}

.cl-ratio-pic {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.cl-ratio-box {
  display: block;
  border: 2px solid currentColor;
  border-radius: 2px;
}

.cl-ratio-box.is-auto {
  border-style: dashed;
}

.cl-ratio-text {
  margin-left: var(--gap-1);
  font-size: var(--text);
  line-height: 1.25;
  white-space: nowrap;
}

.cl-ratio.is-on {
  border-color: var(--sel-bg);
  background: var(--sel-bg);
  color: var(--sel-ink);
}

.cl-ratio:disabled {
  opacity: var(--disabled-opacity);
}

/* ---------- 背景：色块一排 ---------- */
.cl-swatches {
  display: flex;
  align-items: center;
  height: var(--cl-row);
  touch-action: pan-x;
}

.cl-swatch {
  position: relative;
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: var(--border-w) solid var(--line);
  border-radius: 50%;
  touch-action: pan-x;
}

.cl-swatch::before {
  content: '';
  position: absolute;
  left: -5px;
  right: -5px;
  top: -9px;
  bottom: -9px;
}

.cl-swatch + .cl-swatch {
  margin-left: var(--gap-2);
}

.cl-swatch.is-on {
  border-color: var(--panel-bg);
  box-shadow: 0 0 0 2px var(--sel-bg);
}

.cl-dock .color-button {
  width: var(--control);
  height: var(--control);
}

/* ---------- 涂鸦：颜色条 ---------- */
.cl-pane-pen .color-list {
  touch-action: pan-x;
}

.cl-pane-pen .color-chip {
  width: var(--control);
  height: var(--control);
}

/* ---------- 水印：文字一行 ---------- */
.cl-mark-row {
  display: flex;
  align-items: center;
}

.cl-mark-row > * + * {
  flex: none;
  margin-left: var(--gap-2);
}

/* 字段名有时收起：间距挂在它自己身上，收起后文字框贴左 */
.cl-mark-row > .cl-label {
  margin-right: var(--gap-2);
}

.cl-mark-row > .cl-mark-text {
  margin-left: 0;
}

.cl-mark-text {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  min-height: var(--control);
  box-sizing: border-box;
}

/* ---------- 没有图片时，画板中央一个导入钮（只占没被面板盖住的那块） ---------- */
.cl-empty {
  position: absolute;
  left: var(--inset-l, 0);
  right: var(--inset-r, 0);
  top: var(--inset-t, 0);
  bottom: var(--inset-b, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cl-empty .kit-btn {
  pointer-events: auto;
}

.cl-empty.is-hidden {
  display: none;
}

/* ---------- 模式页：三个钮撑满整个面板高度，图在上、字在下 ---------- */
.cl-pane-mode {
  justify-content: stretch;
}

.cl-modes {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.cl-mode {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0 var(--gap-1);
  border: var(--border-w) solid var(--btn-line);
  border-radius: var(--radius-btn);
  background: var(--btn-bg);
  color: var(--ink);
  font-size: var(--text);
  font-weight: var(--font-weight);
}

.cl-mode + .cl-mode {
  margin-left: var(--gap-2);
}

.cl-mode.is-on {
  border-color: var(--sel-bg);
  background: var(--sel-bg);
  color: var(--sel-ink);
}

.cl-mode-cv {
  display: block;
  flex: none;
  width: 44px;
  height: 33px;
  margin-bottom: var(--gap-1);
  pointer-events: none;
}

.cl-mode-text {
  line-height: 1.3;
  white-space: nowrap;
}

/* ---------- 素材栏：标题行（素材、张数、未使用 / 全部、收起）+ 一排缩略图 ---------- */
.cl-tray {
  border-bottom: 1px solid var(--line-soft);
  padding: var(--gap-1) var(--gap-3) 0;
}

.cl-tray-head {
  display: flex;
  align-items: center;
  height: calc(var(--control) + 2px);
}

.cl-tray-title {
  flex: none;
  color: var(--ink);
  font-size: var(--text-title);
  font-weight: var(--title-weight);
  letter-spacing: var(--title-ls);
}

.cl-tray-count {
  flex: 1 1 auto;
  margin-left: var(--gap-1);
  color: var(--ink-3);
  font-size: var(--text-small);
}

.cl-tray-head > .kit-seg {
  flex: none;
  margin-right: var(--gap-2);
}

.cl-tray-head .kit-btn {
  flex: none;
}

.cl-tray-body {
  position: relative;
  display: flex;
  align-items: center;
  height: 64px;
}

.cl-tray.is-folded .cl-tray-body {
  display: none;
}

.cl-tray.is-folded {
  padding-bottom: var(--gap-2);
}

.cl-tray-add {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-right: var(--gap-2);
  padding: 0;
  border: var(--border-w) dashed var(--btn-line);
  border-radius: var(--radius-btn);
  background: var(--btn-bg);
  color: var(--ink-2);
}

.cl-tray-add svg {
  width: var(--icon);
  height: var(--icon);
}

.cl-tray-list {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  min-width: 0;
  height: 100%;
  padding-top: 6px;
  touch-action: pan-x;
  overscroll-behavior: contain;
}

.cl-tray-item {
  position: relative;
  flex: none;
  width: 52px;
  height: 52px;
  margin-right: var(--gap-3);
  border-radius: var(--radius-btn);
  background: var(--surface-2);
  touch-action: pan-x;
  -webkit-touch-callout: none;
  cursor: grab;
}

.cl-tray-cv {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-btn);
  pointer-events: none;
}

.cl-tray-used {
  position: absolute;
  right: 2px;
  bottom: 2px;
  display: none;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--bar);
  color: var(--on-dark);
  font-size: var(--text-small);
  line-height: 16px;
  pointer-events: none;
}

.cl-tray-item.is-used .cl-tray-used {
  display: block;
}

.cl-tray-item.is-used .cl-tray-cv {
  opacity: 0.55;
}

.cl-tray-del {
  position: absolute;
  top: -6px;
  right: -6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1.5px solid var(--panel-bg);
  border-radius: 50%;
  background: var(--bar);
  color: var(--on-dark);
}

.cl-tray-del::before {
  content: '';
  position: absolute;
  left: -6px;
  right: -6px;
  top: -6px;
  bottom: -6px;
}

.cl-tray-del svg {
  width: 12px;
  height: 12px;
}

.cl-tray-none {
  position: absolute;
  left: 60px;
  top: 0;
  bottom: 0;
  display: none;
  align-items: center;
  margin: 0;
  color: var(--ink-3);
  font-size: var(--text-small);
  pointer-events: none;
}

.cl-tray-none.is-shown {
  display: flex;
}

.cl-ghost {
  position: fixed;
  z-index: var(--z-popover);
  left: 0;
  top: 0;
  width: 72px;
  height: 72px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-btn);
  opacity: 0.9;
  pointer-events: none;
}

/* ---------- 悬浮条：白底深色描边的一条，里面只有扁钮，选中的那个填深色 ---------- */
.kit-fbar.cl-bbar {
  padding: var(--gap-1);
  border: var(--border-w) solid var(--ink);
  border-radius: 12px;
  background: var(--panel-bg);
  color: var(--ink);
}

.cl-bbar .kit-fbar-grip {
  color: var(--ink-3);
}

.cl-bb-g {
  display: none;
  align-items: center;
}

.cl-bb-g.is-cur {
  display: flex;
}

.cl-bb-g > * + * {
  margin-left: var(--gap-1);
}

.cl-bbar .kit-btn,
.cl-bbar .kit-seg-btn {
  border: 0;
  border-radius: var(--radius-btn);
  background: var(--panel-bg);
  color: var(--ink);
  white-space: nowrap;
}

.cl-bbar .kit-seg {
  border: 0;
  border-radius: 0;
  background: var(--panel-bg);
}

.cl-bbar .kit-seg-btn {
  min-width: 0;
  padding: 0 var(--gap-3);
}

.cl-bbar .kit-seg-btn + .kit-seg-btn {
  margin-left: var(--gap-1);
}

.cl-bbar .kit-seg-btn.is-on {
  background: var(--sel-bg);
  color: var(--sel-ink);
}

/* ---------- 画线悬浮窗、悬浮窗和弹窗的外框 ---------- */
.kit-fwin,
.modal {
  border: var(--border-w) solid var(--ink);
  border-radius: 12px;
}

.kit-fwin-head,
.modal-head {
  border-bottom: 1px solid var(--line-soft);
}

.kit-fwin.kit-fwin-cut {
  width: 208px;
}

.kit-fwin-cut .kit-fwin-body {
  padding-top: var(--gap-2);
  padding-bottom: var(--gap-3);
}

.cl-cutwin {
  display: flex;
  flex-direction: column;
}

.cl-cutwin > * + * {
  margin-top: var(--gap-2);
}

.cl-cutwin-acts {
  display: flex;
}

.cl-cutwin-acts .kit-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 0 var(--gap-1);
  white-space: nowrap;
}

.cl-cutwin-acts .kit-btn + .kit-btn {
  margin-left: var(--gap-2);
}

/* ---------- 图层：一排缩略图，左边是最上面一层 ---------- */
.cl-layers {
  flex: 1 1 0;
  min-width: 0;
  touch-action: pan-x;
}

.cl-layer-list {
  display: flex;
  align-items: center;
  width: -webkit-max-content;
  width: max-content;
}

.cl-layer {
  position: relative;
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  overflow: hidden;
  border: var(--border-w) solid var(--btn-line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  touch-action: pan-x;
  -webkit-touch-callout: none;
}

.cl-layer + .cl-layer {
  margin-left: 6px;
}

.cl-layer.is-on {
  border: 2px solid var(--sel-bg);
}

.cl-layer-cv {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 长图：素材栏就是排列顺序，不标「已用」 */
.cl-tray.is-order .cl-tray-used {
  display: none;
}

.cl-tray.is-order .cl-tray-item.is-used .cl-tray-cv {
  opacity: 1;
}

/* ---------- 拖动换顺序：整排收短成一样大的小块 ---------- */
.is-sorting .cl-layer {
  width: 28px;
  height: 28px;
}

.cl-tray-list.is-sorting .cl-tray-item {
  width: 32px;
  height: 32px;
  margin-right: 6px;
}

.cl-tray-list.is-sorting .cl-tray-del {
  display: none;
}

.cl-ed-track.is-sorting {
  display: flex;
  align-items: center;
  width: -webkit-max-content !important;
  width: max-content !important;
  padding: 0 var(--gap-1);
}

.cl-ed-track.is-sorting .cl-ed-block {
  position: static;
  flex: none;
  width: 28px !important;
  height: 28px;
  margin-right: var(--gap-1);
}

.cl-ed-track.is-sorting .cl-ed-block.is-cover,
.cl-ed-track.is-sorting .cl-ed-head {
  display: none;
}

.is-lifted {
  opacity: 0.3;
}

.kk-sort-ghost {
  position: fixed !important;
  z-index: var(--z-popover);
  right: auto !important;
  bottom: auto !important;
  margin: 0 !important;
  pointer-events: none;
}

/* ---------- 空格子上的「导入」「删除格子」 ---------- */
.cl-cellbtns {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.cl-cbs {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  pointer-events: none;
}

.cl-cb {
  position: relative;
  min-height: var(--control);
  padding: 0 var(--gap-2);
  border: var(--border-w) solid var(--btn-line);
  border-radius: var(--radius-pill);
  background: var(--panel-bg);
  color: var(--ink);
  font-size: var(--text);
  font-weight: var(--font-weight);
  white-space: nowrap;
  pointer-events: auto;
}

.cl-cb + .cl-cb {
  margin-left: var(--gap-1);
}

/* ---------- 自由比例弹窗、导出弹窗、预览 ---------- */
.cl-custom {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.cl-custom-f {
  display: flex;
  flex-direction: column;
  width: 96px;
  color: var(--ink-2);
  font-size: var(--text-small);
}

.cl-custom-f > span {
  margin-bottom: var(--gap-1);
}

.cl-custom-x {
  margin: 0 var(--gap-2);
  line-height: var(--control);
  font-weight: var(--font-weight);
}

.cl-num {
  height: var(--control);
  padding: 0 var(--gap-2);
  font-size: var(--text-title);
  text-align: center;
}

.cl-export {
  display: flex;
  flex-direction: column;
}

.cl-export > * + * {
  margin-top: var(--gap-3);
}

.cl-export-pvbox {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30vh;
  max-height: 240px;
  border-radius: var(--radius-sm);
  background: var(--desk);
}

.cl-export-pv {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.cl-export-dims {
  margin: 0;
  color: var(--ink-2);
  font-size: var(--text-small);
  text-align: center;
}

.cl-preview {
  display: flex;
  justify-content: center;
}

.cl-preview-img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
}

/* ---------- 宽屏：面板是左上角的一块 ---------- */
.is-wide .cl-side {
  right: auto;
  bottom: auto;
  left: calc(var(--edge) + env(safe-area-inset-left));
  top: var(--edge);
  width: var(--cl-side-w);
  justify-content: flex-start;
  align-items: stretch;
  border: var(--border-w) solid var(--panel-line);
  border-radius: var(--radius-panel);
  background: var(--panel-bg);
  pointer-events: auto;
}

.is-wide .cl-dock {
  padding: 0;
  border-top: 0;
  border-radius: var(--radius-panel);
}

.is-wide .cl-dock-in {
  flex-direction: column-reverse;
  max-width: none;
}

.is-wide .cl-tabbar {
  position: relative;
  margin-top: var(--gap-2);
  border-top: 0;
  border-bottom: 1px solid var(--line-soft);
  padding: 0 var(--gap-3) var(--gap-1);
}

/* 标签排成 4 列 */
.is-wide .cl-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(min-content, 1fr));
  grid-gap: var(--gap-1);
  overflow: visible;
}

.is-wide .cl-tabs .kit-chip {
  min-width: 0;
  margin-left: 0;
  padding: 0 var(--gap-1);
}

/* ---------- 主页：图片 / 视频二选一；视频页是配音的载入进度和试听 ---------- */
.cl-home {
  position: fixed;
  z-index: var(--z-float);
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  background: var(--board);
  color: var(--ink);
}

.cl-home > .cl-top {
  position: relative;
  flex: none;
  height: var(--top-h);
  padding-top: 0;
}

.cl-home-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  box-sizing: border-box;
  padding: var(--gap-3) var(--gap-3) calc(var(--gap-3) + env(safe-area-inset-bottom));
}

.cl-home-view {
  flex: 1;
  min-height: 0;
}

/* 主页：图片、视频两张横卡片上下排，下面临时文件（一排 3 格的方格），最后是署名和条款链接；放不下整块往下滚 */
.cl-home-choice {
  display: flex;
  flex-direction: column;
  touch-action: pan-y;
}

/* 卡片靠上，紧接顶栏；署名在最下面 */
.cl-home-pick {
  display: flex;
  flex: none;
  flex-direction: column;
}

.cl-home-card {
  display: block;
  flex: none;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-panel);
  background: var(--desk);
  color: var(--sel-ink);
  touch-action: pan-y;
}

.cl-home-card + .cl-home-card {
  margin-top: var(--gap-3);
}

.cl-home-art {
  display: block;
  width: 100%;
  height: 118px;
  pointer-events: none;
}

@media (min-height: 760px) and (min-width: 360px) {
  .cl-home-art {
    height: 172px;
  }
}

.cl-home-name {
  display: block;
  height: 40px;
  background: var(--sel-bg);
  font-size: var(--text-title);
  font-weight: var(--title-weight);
  letter-spacing: var(--title-ls);
  line-height: 40px;
  text-align: center;
  white-space: nowrap;
}

.cl-home-foot {
  flex: none;
  margin-top: auto;
  padding-top: var(--gap-4);
}

.cl-legal {
  display: inline-block;
  color: var(--ink-2);
  font-size: var(--text-small);
  line-height: 1.6;
  text-decoration: underline;
}

.cl-home .credit {
  margin-top: var(--gap-2);
  border-top: 1px solid var(--line-soft);
}

.cl-home .credit-text {
  flex: 1 1 auto;
  overflow: hidden;
  font-size: var(--text-small);
}

.cl-drafts {
  flex: none;
  margin-top: var(--gap-4);
}

/* 矮横屏（横放的手机）：两张卡片左右排，整页不用滚 */
@media (max-height: 520px) and (min-width: 600px) {
  .cl-home-body {
    max-width: 720px;
  }

  .cl-home-pick {
    flex-direction: row;
  }

  .cl-home-card {
    flex: 1 1 0%;
    width: auto;
    min-width: 0;
  }

  .cl-home-card + .cl-home-card {
    margin-top: 0;
    margin-left: var(--gap-3);
  }
}

.cl-drafts-warn:empty,
.cl-drafts-space:empty {
  display: none;
}

.cl-drafts-warn {
  margin: 0 0 var(--gap-2);
  padding: var(--gap-2) var(--gap-3);
  border-radius: var(--radius-sm);
  background: var(--bar);
  color: var(--on-dark);
  font-size: var(--text-small);
  line-height: 1.5;
}

.cl-drafts-space {
  white-space: pre-line;
  margin: 0 0 var(--gap-3);
  color: var(--ink-2);
  font-size: var(--text-small);
  line-height: 1.5;
}

.cl-drafts-title {
  margin: 0 0 var(--gap-2);
  color: var(--ink);
  font-size: var(--text-title);
  font-weight: var(--title-weight);
  letter-spacing: var(--title-ls);
  line-height: 1.3;
  white-space: nowrap;
}

.cl-drafts-grid {
  --cols: 3;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-gap: var(--gap-3);
}

.cl-draft {
  position: relative;
  height: var(--cell, 100px);
}

.cl-draft-open {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: block;
  padding: 0;
  overflow: hidden;
  border: var(--border-w) solid var(--btn-line);
  border-radius: var(--radius-btn);
  background: var(--desk);
  touch-action: pan-y;
}

.cl-draft-img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cl-draft-kind {
  position: absolute;
  left: 4px;
  bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--bar);
  color: var(--on-dark);
  pointer-events: none;
}

.cl-draft-kind svg {
  width: 14px;
  height: 14px;
}

.cl-draft-del {
  position: absolute;
  top: -6px;
  right: -6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1.5px solid var(--panel-bg);
  border-radius: 50%;
  background: var(--bar);
  color: var(--on-dark);
}

.cl-draft-del::before {
  content: '';
  position: absolute;
  left: -10px;
  right: -10px;
  top: -10px;
  bottom: -10px;
}

.cl-draft-del svg {
  width: 12px;
  height: 12px;
}

.cl-home-video {
  display: flex;
  flex-direction: column;
}

.cl-home-state,
.cl-home-note {
  flex: none;
  margin: 0 0 var(--gap-2);
  font-size: var(--text-small);
  line-height: 1.5;
  color: var(--ink-2);
}

.cl-home-note {
  min-height: 1.5em;
}

.cl-home-bar {
  flex: none;
  height: 6px;
  margin-bottom: var(--gap-3);
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
}

.cl-home-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--bar);
}

.cl-home-field {
  flex: none;
  display: flex;
  flex-direction: column;
  margin-bottom: var(--gap-3);
  font-size: var(--text-small);
  color: var(--ink-2);
}

.cl-home-field > span {
  margin-bottom: var(--gap-1);
}

.cl-home-grow {
  flex: 1;
  min-height: 0;
}

.cl-home-select,
.cl-home-text {
  box-sizing: border-box;
  width: 100%;
  border: 1px solid var(--btn-line);
  border-radius: var(--radius-btn);
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-title);
}

.cl-home-select {
  height: var(--control);
  padding: 0 var(--gap-2);
}

.cl-home-text {
  flex: 1;
  min-height: 0;
  padding: var(--gap-2);
  resize: none;
}

.cl-home-acts {
  flex: none;
  display: none;
  display: flex;
  justify-content: flex-end;
}

.cl-home-acts > * + * {
  margin-left: var(--gap-2);
}

.cl-home-acts .kit-btn {
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
}

.cl-home-pair {
  flex: none;
  display: flex;
}

.cl-home-pair > .cl-home-field {
  flex: 1;
  min-width: 0;
}

.cl-home-pair > .cl-home-field + .cl-home-field {
  margin-left: var(--gap-2);
}

.cl-home-opts {
  flex: none;
  display: flex;
  flex-direction: column;
}

.cl-home-opts > .kit-slider {
  margin-bottom: var(--gap-3);
}

/* ---------- 视频页：预览舞台与字幕字体 ---------- */
@font-face {
  font-family: 'KK Subtitle';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/subtitle-cjk-400.woff2') format('woff2');
}

@font-face {
  font-family: 'KK Subtitle';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/subtitle-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'KK Subtitle';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/subtitle-cjk-700.woff2') format('woff2');
}

@font-face {
  font-family: 'KK Subtitle';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/subtitle-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'KK Subtitle';
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url('../assets/fonts/subtitle-cjk-900.woff2') format('woff2');
}

@font-face {
  font-family: 'KK Subtitle';
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url('../assets/fonts/subtitle-latin-900.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- 视频页：和拼图页同一个结构——预览铺满，面板贴底（宽屏是左上角一块） ---------- */
.cl-home.is-video .cl-home-body {
  max-width: none;
  padding: 0;
}

.cl-home-video {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.cl-mv-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.cl-mv-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--desk);
}

/* 预览下面：播放钮和时间一条，再下面是时间轴 */
.cl-mv-transport {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 var(--gap-3);
  border-top: 1px solid var(--panel-line);
  background: var(--panel-bg);
}

.cl-mv-play {
  flex: none;
}

.cl-ed-time {
  flex: none;
  color: var(--ink-2);
  font-size: var(--text-small);
  white-space: nowrap;
}

.cl-mv-main > .cl-ed-strip {
  flex: none;
  margin: 0 var(--gap-3) var(--gap-2);
}

.cl-mv-dock {
  flex: none;
  border-top: 1px solid var(--panel-line);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--panel-bg);
}

.cl-mv-panes {
  height: 212px;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--gap-2) var(--gap-3);
  box-sizing: border-box;
}

.cl-mv-dock > .cl-tabbar {
  max-width: 480px;
  margin: 0 auto;
}

.cl-mv-canvas {
  display: block;
  flex: none;
}

/* 配音载入中 / 失败：叠在预览上面一条，不占一行 */
.cl-mv-status {
  position: absolute;
  z-index: 2;
  left: var(--gap-2);
  right: var(--gap-2);
  top: var(--gap-2);
  padding: var(--gap-2) var(--gap-3);
  border-radius: var(--radius-sm);
  background: var(--bar);
  color: var(--on-dark);
  pointer-events: none;
}

.cl-mv-status .cl-home-state {
  margin: 0;
  color: var(--on-dark);
}

.cl-mv-status .cl-home-bar {
  margin: var(--gap-1) 0 0;
  background: #55575c;
}

.cl-mv-status .cl-home-bar i {
  background: var(--on-dark);
}

.cl-mv-stage > .cl-home-note {
  position: absolute;
  z-index: 2;
  left: var(--gap-2);
  right: var(--gap-2);
  bottom: var(--gap-2);
  min-height: 0;
  margin: 0;
  padding: var(--gap-1) var(--gap-2);
  border-radius: var(--radius-sm);
  background: var(--bar);
  color: var(--on-dark);
  cursor: pointer;
}

.cl-mv-stage > .cl-home-note:empty {
  display: none;
}

.cl-mv-empty {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cl-mv-status {
  display: flex;
  align-items: center;
}

.cl-mv-status-in {
  flex: 1 1 auto;
  min-width: 0;
}

.cl-mv-retry {
  flex: none;
  margin-left: var(--gap-2);
  pointer-events: auto;
}

/* ---------- 视频页的页签：一次显示一页，页签内容高度固定，放不下在里面滚 ---------- */
.cl-mv-pane {
  display: none;
  height: 100%;
  touch-action: pan-y;
  overflow-x: hidden;
  overflow-y: auto;
}

.cl-home-video[data-page="style"] [data-tab="style"],
.cl-home-video[data-page="edit"] [data-tab="edit"],
.cl-home-video[data-page="look"] [data-tab="look"],
.cl-home-video[data-page="sound"] [data-tab="sound"],
.cl-home-video[data-page="dub"] [data-tab="dub"] {
  display: block;
}

.cl-home-video[data-page="text"] [data-tab="text"] {
  display: flex;
  flex-direction: column;
}

.cl-mv-textpage > .cl-home-text {
  flex: 1 0 auto;
  height: 100%;
  min-height: 56px;
}

.cl-mv-style {
  display: flex;
  flex-direction: column;
}

.cl-mv-style > * {
  flex: none;
  margin-bottom: var(--gap-2);
}

.cl-mv-row .cl-home-select {
  flex: 1;
  min-width: 0;
  width: auto;
}

.cl-mv-row .kit-seg {
  flex: 1;
  min-width: 0;
}

.cl-mv-reset {
  display: flex;
  justify-content: flex-end;
  padding-right: 8px;
}

/* ---------- 剪辑：时间轴和操作按钮 ---------- */
.cl-ed,
.cl-mv-look,
.cl-mv-tracks {
  display: flex;
  flex-direction: column;
}

.cl-ed > *,
.cl-mv-look > .kit-seg {
  flex: none;
  margin-bottom: var(--gap-2);
}

.cl-ed-name {
  margin: 0 0 var(--gap-1);
  color: var(--ink);
  font-size: var(--text-title);
  font-weight: var(--title-weight);
  letter-spacing: var(--title-ls);
  line-height: 22px;
}

.cl-ed-name:empty {
  display: none;
}

.cl-ed > .cl-ed-seconds {
  margin-bottom: var(--gap-1);
}

.cl-ed-strip {
  position: relative;
  height: 52px;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  overscroll-behavior: contain;
  border-radius: var(--radius-btn);
  background: var(--surface-2);
  scrollbar-width: none;
}

.cl-ed-strip::-webkit-scrollbar {
  display: none;
}

.cl-ed-track {
  position: relative;
  height: 100%;
}

.cl-ed-block {
  position: absolute;
  top: 4px;
  bottom: 4px;
  box-sizing: border-box;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
  border: 1px solid var(--btn-line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-small);
  white-space: nowrap;
  touch-action: pan-x;
  -webkit-touch-callout: none;
}

.cl-ed-block.is-held {
  border-style: dashed;
}

.cl-ed-block.is-cover {
  background: var(--surface-3);
}

.cl-ed-block.is-cover {
  align-items: center;
  justify-content: center;
}

.cl-ed-block.is-sel {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--ink);
}

.cl-ed-tile {
  display: block;
  flex: none;
  height: 100%;
  background-color: var(--surface-3);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  pointer-events: none;
}

.cl-ed-block > span {
  position: absolute;
  top: 2px;
  left: 2px;
  padding: 0 var(--gap-1);
  border-radius: 4px;
  background: var(--ink);
  color: var(--board);
  line-height: 16px;
  pointer-events: none;
}

.cl-ed-block.is-cover > span {
  position: static;
  padding: 0;
  background: none;
  color: var(--ink);
}

.cl-ed-track.is-sorting .cl-ed-tile {
  width: 28px !important;
}

.cl-ed-track.is-sorting .cl-ed-tile + .cl-ed-tile,
.cl-ed-track.is-sorting .cl-ed-block > span {
  display: none;
}

.cl-ed-head {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--board);
  pointer-events: none;
}

.cl-ed-tools,
.cl-mv-acts {
  display: flex;
  flex-wrap: wrap;
}

.cl-ed-tools .kit-btn,
.cl-mv-acts .kit-btn {
  margin: 0 var(--gap-1) var(--gap-1) 0;
}

.cl-mv-track {
  margin-bottom: var(--gap-2);
  padding: var(--gap-2);
  border: 1px solid var(--btn-line);
  border-radius: var(--radius-btn);
}

.cl-mv-track-name {
  margin: 0 0 var(--gap-1);
  font-size: var(--text-small);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

/* 行标签：行高放够，字的上沿不顶出标签框 */
.cl-app .kit-row-label,
.cl-home .kit-row-label,
.cl-label {
  line-height: 1.5;
}

/* 提示条在悬浮条下面，不叠在它上面 */
.cl-app .toast {
  --toast-top: calc(var(--top-h) + 72px);
}

.cl-tray-head .kit-seg-btn,
.cl-r .kit-seg-btn {
  white-space: nowrap;
}

/* 矮屏手机：素材缩略图小一档，把高度留给画板 */
@media (max-height: 700px) and (max-width: 699px) {
  .cl-tray-body {
    height: 56px;
  }

  .cl-tray-item,
  .cl-tray-add {
    width: 44px;
    height: 44px;
  }

  .cl-tray {
    padding-top: var(--gap-1);
  }
}

/* 声音下拉：去掉浏览器自带的外观，右边一个自己画的箭头（文字框同一个类，不画箭头） */
select.cl-home-select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: calc(var(--gap-2) * 2 + 10px);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.cl-bbar.is-tight .kit-btn,
.cl-bbar.is-tight .kit-seg-btn {
  padding: 0 var(--gap-2);
}

.cl-bbar.is-tight .kit-seg-btn {
  min-width: 0;
}

.cl-pane-bg .kit-seg-btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 var(--gap-1);
  white-space: nowrap;
}

/* 矮屏：页签内容矮一档，预览仍有高度 */
@media (max-height: 700px) and (orientation: portrait) {
  .cl-mv-panes {
    height: 164px;
  }
}

@media (max-height: 520px) and (orientation: portrait) {
  .cl-mv-panes {
    height: 104px;
  }
}

/* 空格太窄：「导入」「删除格子」上下排，两个一样宽 */
.cl-cbs.is-col {
  flex-direction: column;
  align-items: stretch;
}

.cl-cbs.is-col > .cl-cb + .cl-cb {
  margin-top: var(--gap-1);
  margin-left: 0;
}

/* 视频页的内容区：竖着排，预览占剩下的高度 */
.cl-home.is-video .cl-home-video {
  display: flex;
  flex-direction: column;
}

/* 宽屏（电脑、平板横放、手机横放）：面板是左上角一块，标签在上；预览在右边剩下的地方 */
.is-wide .cl-home.is-video .cl-home-video {
  padding-left: calc(328px + var(--edge) * 2);
}

.is-wide .cl-mv-dock {
  position: absolute;
  z-index: 3;
  left: var(--edge);
  top: var(--edge);
  bottom: var(--edge);
  width: 328px;
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
  padding-bottom: 0;
  border: var(--border-w) solid var(--panel-line);
  border-radius: var(--radius-panel);
}

.is-wide .cl-mv-dock > .cl-tabbar {
  margin: var(--gap-2) 0 0;
  max-width: none;
  border-top: 0;
  border-bottom: 1px solid var(--line-soft);
  padding: 0 var(--gap-3) var(--gap-1);
}

.is-wide .cl-mv-dock .cl-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(min-content, 1fr));
  grid-gap: var(--gap-1);
  overflow: visible;
}

.is-wide .cl-mv-dock .cl-tabs .kit-chip {
  min-width: 0;
  margin-left: 0;
  padding: 0 var(--gap-2);
}

.is-wide .cl-mv-panes {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-width: none;
  margin: 0;
}

.is-wide .cl-mv-main {
  padding: var(--edge) var(--edge) var(--edge) 0;
}

.is-wide .cl-mv-stage {
  border-radius: var(--radius-panel);
}

.is-wide .cl-mv-transport {
  border-top: 0;
  padding: 0;
}

.is-wide .cl-mv-main > .cl-ed-strip {
  margin: 0;
}

/* 矮的横屏：预览优先 */
@media (max-height: 440px) and (orientation: landscape) {
  .is-wide .cl-mv-main {
    padding-top: var(--gap-2);
    padding-bottom: var(--gap-2);
  }

  .is-wide .cl-mv-transport {
    height: 40px;
  }
}

