/* =====================================================================
   应用骨架布局
   ===================================================================== */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
}

/* ---------- 顶部栏 ---------- */
.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2) 0 var(--space-3);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 300;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand__logo {
  display: flex;
  align-items: center;
  flex: none;
}
.brand__logo svg { width: 24px; height: 24px; display: block; }
.brand__name { font-size: 15px; line-height: 1; }
.brand__version { color: var(--text-faint); font-size: 11px; font-weight: 400; }

.topbar__menus { display: flex; align-items: center; gap: 2px; }
.topbar__menu-btn {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  white-space: nowrap;
  flex: none;
}
.topbar__menus { flex-wrap: nowrap; }
.topbar__menu-btn:hover,
.topbar__menu-btn.open { background: var(--bg-hover); color: var(--text); }

.doc-name {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: text;
  max-width: 240px;
}
.doc-name:hover { background: var(--bg-hover); }
.doc-name__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-name.dirty .doc-name__text::after {
  content: "未保存";
  color: var(--accent);
  margin-left: 6px;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-weak);
  vertical-align: middle;
}

/* ---------- 工作区 ---------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

/* ---------- 工具栏 ---------- */
.toolbar {
  width: var(--toolbar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;   /* iOS / iPad 惯性滚动 */
  touch-action: pan-y;                 /* 触屏只做纵向滚动，避免误触绘制 */
  scrollbar-width: none;               /* 隐藏滚动条（仍可滚动） */
  -ms-overflow-style: none;
}
.toolbar::-webkit-scrollbar { width: 0; height: 0; display: none; }
.tool-btn {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  color: var(--text-dim);
  position: relative;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tool-btn:hover { background: var(--bg-hover); color: var(--text); }
.tool-btn.active {
  background: var(--accent-weak);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(76, 141, 255, 0.35);
}
.toolbar__sep { width: 24px; height: 1px; background: var(--border); margin: 5px 0; flex: none; }
.tool-group { display: flex; flex-direction: column; gap: 4px; align-items: center; }

/* ---------- 画布区 ---------- */
.canvas-area {
  flex: 1;
  min-width: 0;
  position: relative;
  background: var(--bg-sunken);
  overflow: hidden;
}
#viewCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

/* 画布上的浮动工具条（尺寸/缩放） */
.canvas-hud {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 8px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  z-index: 50;
}
.canvas-hud .ps-number { width: 72px; height: 28px; }
.canvas-hud .hud-label { color: var(--text-dim); }

.canvas-zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  z-index: 50;
}
.canvas-zoom__value {
  min-width: 52px;
  text-align: center;
  font-family: var(--font-mono);
  color: var(--text-dim);
  cursor: pointer;
}

/* ---------- 右侧面板 ---------- */
.panels {
  width: var(--panel-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}
.panel {
  border-bottom: 1px solid var(--border);
  flex: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
/* 面板按内容自然高度排列，由 .panels 容器统一滚动，避免互相挤压裁剪 */
.panel.grow-panel { flex: none; }
.panel__head {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 var(--space-2) 0 var(--space-3);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.panel__head .icon-btn { width: 26px; height: 26px; }
.panel__head .icon-btn svg { width: 15px; height: 15px; }
.panel__body {
  padding: var(--space-2) var(--space-3) var(--space-3);
  overflow-y: auto;
  min-height: 0;
}
.panel__body.flush { padding: 0; }

/* ---------- 时间轴 ---------- */
.timeline {
  height: var(--timeline-h);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}
.timeline__bar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--border);
}
.timeline__bar .vdivider { margin: 4px; }
.timeline__frames {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-2);
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 0;
}
.frame-chip {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.frame-chip:hover { border-color: var(--border-strong); }
.frame-chip.active { border-color: var(--accent); background: var(--accent-weak); }
/* 整体变换：被选中的帧用子框明示 */
.frame-chip.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak), inset 0 0 0 1px var(--accent); background: var(--accent-weak); }
.frame-chip.selected::after {
  content: "✓";
  position: absolute; top: -6px; right: -6px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 11px; line-height: 16px; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.frame-chip { position: relative; }
.frame-chip canvas {
  width: 40px;
  height: 40px;
  flex: none;
  image-rendering: pixelated;
  border-radius: 3px;
  background-color: #ffffff;
  background-image: linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
    linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
    linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}
.frame-chip__index { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); }

/* ---------- 状态栏 ---------- */
.statusbar {
  height: var(--statusbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  font-family: var(--font-mono);
}
.statusbar .sep { width: 1px; height: 12px; background: var(--border); }

/* ---------- 移动端适配 ---------- */
.only-mobile-panel { display: none; }
.panel-backdrop {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: var(--bg-overlay);
  z-index: 350;
}

/* 触屏设备（无 hover）：卡片操作按钮常显，避免够不到 */
@media (hover: none) {
  .card__actions { display: flex !important; }
  .folder-item__actions { display: flex !important; }
}

/* ---------- iPad / 平板（861 - 1024px）：保留面板但整体收窄 ---------- */
@media (max-width: 1024px) {
  :root {
    --panel-w: 232px;
    --toolbar-w: 46px;
    --timeline-h: 112px;
  }
  .tool-btn { width: 30px; height: 30px; }
  .frame-chip { width: 58px; height: 58px; }
  .frame-chip canvas { width: 36px; height: 36px; }
  .panel__body { padding: 6px 8px 10px; }
}

/* ---------- 手机 / 窄屏（≤860px）：面板改抽屉 ---------- */
@media (max-width: 860px) {
  :root {
    --panel-w: 0px;
    --timeline-h: 108px;
  }
  .panels { display: none; }
  .panels.mobile-open {
    display: flex;
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    right: 0;
    width: min(330px, 88vw);
    z-index: 400;
    box-shadow: var(--shadow-lg);
  }
  .canvas-hud { bottom: 8px; }
  .toolbar { width: 46px; }
  .tool-btn { width: 30px; height: 30px; }
  .brand__version { display: none; }
  .only-mobile-panel { display: inline-flex; }

  /* 工具选项条横向滚动，避免换行挤占画布 */
  .tool-options { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; padding: 6px 8px; }
  .tool-options::-webkit-scrollbar { height: 4px; }
  .tool-options > label { display: none; }         /* 手机上隐藏文字标签，只留控件 */
  .tool-slider { min-width: 132px; }
  .tool-options .faint { display: none; }           /* 隐藏提示语 */

  /* 状态栏精简 */
  .statusbar { font-size: 11px; gap: 8px; }

  /* 弹窗改为底部抽屉式，方便单手操作 */
  .ps-overlay { align-items: flex-end; }
  .ps-modal {
    width: 100% !important;
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(24px);
  }
  .ps-overlay.open .ps-modal { transform: translateY(0); }
  .ps-modal__foot { flex-wrap: wrap; }
  .pref-layout { flex-direction: column; height: auto; }
  .pref-nav {
    width: 100%; display: flex; gap: 6px; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--border); white-space: nowrap;
  }
  .pref-nav__head { display: none; }
  .pref-nav__item { flex: none; }

  /* 浮动窗口铺满宽度 */
  .ps-float { left: 8px !important; right: 8px !important; width: auto !important; }
}

/* ---------- 手机竖屏（≤560px） ---------- */
@media (max-width: 560px) {
  :root {
    --topbar-h: 44px;
    --toolbar-w: 80px;
    --timeline-h: 96px;
  }
  /* 工具栏改为两列换行 + 纵向滚动，触屏好点按 */
  .toolbar {
    width: var(--toolbar-w);
    flex-flow: row wrap;
    align-content: flex-start;
    justify-content: center;
    gap: 6px 4px;
    padding: 8px 3px;
  }
  .tool-group {
    flex: 0 0 100%;
    flex-flow: row wrap;
    justify-content: center;
    gap: 6px 4px;
    align-items: center;
  }
  .toolbar__sep { flex: 0 0 100%; width: 100%; margin: 4px 0; }
  .tool-btn { width: 30px; height: 30px; flex: none; }
  .frame-chip { width: 54px; height: 54px; }
  .frame-chip canvas { width: 32px; height: 32px; }
  .canvas-hud { display: none; }                    /* 尺寸调整改用菜单 */
  .canvas-zoom { right: 8px; bottom: 8px; }

  /* 顶部栏：只留 logo + 菜单 + 文件名 + 常用按钮 */
  .brand__name, .brand__version { display: none; }
  .topbar [data-icon="home"],
  .topbar [data-icon="cloud"],
  .topbar [data-icon="folder"],
  .topbar [data-icon="download"] { display: none; }
  .topbar__menus { overflow-x: auto; max-width: 40vw; }
  .topbar__menus::-webkit-scrollbar { height: 0; }
  .doc-name { max-width: 26vw; }

  /* 时间轴：不换行、可横向滚动 */
  .timeline__bar { flex-wrap: nowrap; overflow-x: auto; }
  .timeline__bar::-webkit-scrollbar { height: 0; }
  .timeline__bar .faint, .timeline__bar label, .timeline__bar .ps-check > span { white-space: nowrap; }
  .statusbar > span:nth-child(n + 4) { display: none; }  /* 只留尺寸/缩放/帧 */
  .ps-modal { max-height: 96vh; }
}

/* ---------- 安全区（iPhone 刘海 / 底部指示条） ---------- */
.statusbar {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--statusbar-h) + env(safe-area-inset-bottom, 0px));
}
.topbar { padding-left: calc(var(--space-3) + env(safe-area-inset-left, 0px)); }
.toolbar { padding-left: env(safe-area-inset-left, 0px); }

/* ---------- 桌面端（宽屏）：工具栏紧凑，超出时纵向滚动（滚动条隐藏） ---------- */
@media (min-width: 1025px) {
  .toolbar { gap: 4px; }
}
