:root {
  --indigo: #4f46e5;
  --indigo-dark: #4338ca;
  --indigo-light: #eef2ff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f7f8fb;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(31,41,55,.05);
}

* { box-sizing: border-box; }

html {
  margin: 0;
  padding: 0;
  /* 防止 .app-header 用 100vw 突破容器时（有纵向滚动条时 100vw > 可用宽度）触发横向滚动条 */
  overflow-x: hidden;
}

body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}

/* ===== 流式根容器：占满屏幕高度 ===== */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  background: var(--bg);
}

/* ===== 顶部标题 ===== */
.app-header {
  flex: 0 0 auto;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  padding: 14px max(16px, calc((100vw - 1180px) / 2 + 16px));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { flex: 0 0 auto; }
.brand-text h1 { font-size: 18px; margin: 0; color: var(--ink); }
.brand-sub { margin: 2px 0 0; font-size: 14px; color: var(--muted); }

/* ===== 广告位 ===== */
.ad-slot {
  display: none;
}
.ad-slot:not(:empty) {
  flex: 0 0 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  max-height: 60px;
  margin: 10px 16px;
  /* border: 1px dashed #c7c7c7;
  background: #f0f0f0; */
  color: var(--muted);
  font-size: 14px;
  border-radius: 8px;
}
.ad-slot:empty + .app-main {
  padding-top: 20px;
}

/* ===== 主功能区：左右分栏 ===== */
.app-main {
  flex: 1 1 auto;
  display: flex;
  gap: 16px;
  padding: 0 16px 16px;
  align-items: flex-start;
}
.visually-h2 {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.panel-left { flex: 0 0 360px; }
.panel-right { flex: 1 1 auto; min-width: 0; }

/* ===== 上传区 ===== */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 24px 16px;
  border: 2px dashed #c7cbe0;
  border-radius: var(--radius);
  background: var(--indigo-light);
  color: var(--indigo-dark);
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--indigo); outline: none; }
.dropzone.dragover { border-color: var(--indigo); background: #e0e7ff; }
.dz-icon { color: var(--indigo); }
.dz-title { margin: 4px 0 0; font-size: 15px; color: var(--ink); }
.dz-link { color: var(--indigo); font-weight: 600; }
.dz-hint { margin: 0; font-size: 14px; color: var(--muted); }

/* ===== 原图预览 ===== */
.origin-preview { margin-top: 14px; text-align: center; }
.origin-canvas-wrap {
  position: relative;
  display: inline-block;
  border-radius: 10px;
  overflow: hidden;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%) -8px 0/16px 16px,
    linear-gradient(-45deg, #eee 25%, transparent 25%) -8px 0/16px 16px,
    linear-gradient(45deg, transparent 75%, #eee 75%) 0 0/16px 16px,
    linear-gradient(-45deg, transparent 75%, #eee 75%) 0 0/16px 16px,
    #fff;
}
#originCanvas { display: block; width: 240px; height: 240px; }
.safe-ring {
  position: absolute;
  inset: 10%;
  border: 2px dashed rgba(79,70,229,.8);
  border-radius: 50%;
  pointer-events: none;
}
.origin-meta { margin: 8px 0 0; font-size: 14px; color: var(--muted); }

/* ===== 设置 ===== */
.settings {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 12px 12px;
}
.settings > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 8px 0;
  font-size: 15px;
}
.field { margin-top: 12px; }
.field > label, .field-title { display: block; font-size: 14px; margin-bottom: 6px; color: var(--ink); }
.field-inline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.field-inline > label { margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { width: 16px; height: 16px; }
input[type="range"] { width: 100%; accent-color: var(--indigo); }
input[type="color"] { width: 40px; height: 28px; border: 1px solid var(--line); border-radius: 6px; padding: 0; cursor: pointer; }

.size-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.size-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  background: #fafafa;
}
.size-chip input { accent-color: var(--indigo); }

/* ===== 操作按钮 ===== */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn {
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--indigo); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--indigo-dark); }
.btn-secondary { background: #fff; color: var(--indigo); border-color: var(--indigo); }
.btn-secondary:not(:disabled):hover { background: var(--indigo-light); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-mini { font-size: 13px; padding: 4px 10px; background: var(--indigo); color: #fff; }

.status-bar {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--muted);
  min-height: 20px;
}
.status-bar a {
  color: var(--indigo);
  font-weight: 600;
  text-decoration: none;
}
.status-bar a:hover { text-decoration: underline; }

/* ===== 右侧场景预览 ===== */
.scene-preview { margin-bottom: 16px; }
.scene-label { font-size: 14px; color: var(--muted); }
.scene-row { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 8px; }
.scene-item { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.phone-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  display: flex; align-items: center; justify-content: center;
}
.phone-icon.squircle { border-radius: 22%; }
.phone-icon.square { border-radius: 8px; }
.phone-icon canvas { width: 72px; height: 72px; }

/* ===== 图标网格 ===== */
.grid-title { font-size: 15px; margin: 4px 0 10px; }
.grid-count { color: var(--muted); font-weight: 400; font-size: 14px; }
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 12px;
}
.grid-empty { grid-column: 1 / -1; color: var(--muted); font-size: 14px; margin: 0; }
.icon-cell {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
  background: #fff;
}
.icon-cell canvas {
  width: 72px; height: 72px;
  background:
    linear-gradient(45deg, #f0f0f0 25%, transparent 25%) -6px 0/12px 12px,
    linear-gradient(-45deg, #f0f0f0 25%, transparent 25%) -6px 0/12px 12px,
    linear-gradient(45deg, transparent 75%, #f0f0f0 75%) 0 0/12px 12px,
    linear-gradient(-45deg, transparent 75%, #f0f0f0 75%) 0 0/12px 12px;
  border-radius: 6px;
}
.icon-cell .icon-name { display: block; font-size: 13px; color: var(--muted); margin: 6px 0 6px; }
.icon-cell .icon-dl { font-size: 13px; color: var(--indigo); background: none; border: none; cursor: pointer; padding: 0; }
.icon-cell .icon-dl:hover { text-decoration: underline; }
.icon-cell.maskable { border-color: var(--indigo); }
.icon-cell.maskable .badge { display: inline-block; font-size: 12px; background: var(--indigo-light); color: var(--indigo-dark); border-radius: 4px; padding: 1px 6px; }

/* ===== manifest 片段 ===== */
.manifest-box { margin-top: 18px; }
.manifest-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 14px; }
#manifestText {
  width: 100%;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
  background: #0f172a;
  color: #e2e8f0;
}

/* ===== 文章内容 ===== */
.article-content {
  flex: 1 1 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0 16px 16px;
  padding: 20px;
  overflow-y: auto;
}
.article-content h2 { font-size: 20px; margin-top: 0; }
.article-content h3 { font-size: 16px; margin: 18px 0 8px; }
.article-content p, .article-content li { font-size: 15px; }
.article-content .lead { color: #374151; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 10px; }
.faq-item { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.faq-item:first-of-type { border-top: none; }

/* ===== 页脚 ===== */
.app-footer {
  flex: 0 0 auto;
  text-align: center;
  padding: 16px;
  font-size: 14px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.app-footer p { margin: 4px 0; }
.app-footer a { color: var(--muted); margin: 0 6px; text-decoration: none; }
.app-footer a:hover { color: var(--indigo); text-decoration: underline; }

/* ===== 移动端 TabBar：默认隐藏（PC） ===== */
.tab-bar { display: none; }

/* ================= 移动端 ================= */
@media (max-width: 820px) {
  /* 给固定 TabBar + iPhone 底部安全区留位 */
  .app-container { padding-bottom: calc(50px + env(safe-area-inset-bottom, 0px)); }

  /* 页头顶部补偿 iPhone 刘海 / 状态栏安全区（standalone PWA 模式下生效） */
  .app-header {
    padding-top: max(14px, env(safe-area-inset-top, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-bottom: 14px;
  }

  .brand-text h1 { font-size: 16px; }

  /* 主区垂直堆叠 */
  .app-main { flex-direction: column; padding-bottom: 8px; }
  .panel-left, .panel-right { flex: 1 1 auto; width: 100%; }
  #originCanvas { width: 200px; height: 200px; }

  /* 文章可滚动占满 */
  .article-content { margin-bottom: 8px; }

  /* 底部 TabBar 固定
     高度 = 50px 按钮区 + iPhone 底部安全区（Home 指示条区域）
     padding-bottom 把按钮推到 50px 区域内，不被安全区遮住 */
  .tab-bar {
    order: 999;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(50px + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: flex-start; /* 按钮紧贴顶部，安全区在底部 */
    background: var(--card);
    border-top: 1px solid var(--line);
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .tab-btn {
    flex: 1 1 0;
    height: 50px;
    border: none;
    background: none;
    font-size: 14px;
    color: var(--muted);
    cursor: pointer;
  }
  .tab-btn.active { color: var(--indigo); font-weight: 600; }

  /* 教程/关于等 tab 激活时，main 彻底收缩，把高度让给文章 */
  body.tab-article .app-main { flex: 0 0 0; height: 0; overflow: hidden; padding-top: 0; padding-bottom: 0; }
  body.tab-article .article-content { flex: 1 1 auto; }
}

@media (min-width: 821px) {
  /* PC 端始终展示所有文章，隐藏 hidden 由 JS 控制；这里保证 main 与文章并存 */
  .article-content[hidden] { display: none; }
}
