/* style.css — H5 前端共享样式（移动端优先，深浅色自洽） */
:root {
  --brand: #16a34a;
  --brand-d: #15803d;
  --brand-soft: #dcfce7;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f5f7;
  --card: #ffffff;
  --err: #dc2626;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6e8eb;
    --muted: #9aa1ab;
    --line: #2a2f36;
    --bg: #121417;
    --card: #1b1f24;
    --brand-soft: #0f2a1c;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink); background: var(--bg);
  font-size: 16px; line-height: 1.5;
}
body { min-height: 100dvh; }
a { color: var(--brand); text-decoration: none; }
input, button, select, textarea {
  font-family: inherit; font-size: inherit; color: inherit;
}

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar .title { font-size: 17px; font-weight: 600; flex: 1; }

/* 容器 */
.wrap { max-width: 640px; margin: 0 auto; padding: 14px; }

/* 卡片 */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; }

/* 表单字段 */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.field input {
  width: 100%; padding: 12px 14px; min-height: 48px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.field input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 10px 18px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); cursor: pointer;
  font-size: 16px; font-weight: 500; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:disabled { opacity: .55; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-danger { color: var(--err); border-color: var(--line); }

/* 错误提示 */
.err {
  color: var(--err); font-size: 14px; min-height: 1em;
  margin: 4px 0 6px; padding: 8px 10px; background: rgba(220, 38, 38, .08);
  border-radius: 8px; display: none; word-break: break-word;
}
.err.show { display: block; }

/* 已写字胶囊 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-width: 40px; padding: 8px 10px; text-align: center;
  background: var(--brand-soft); color: var(--brand-d);
  border-radius: 8px; font-size: 18px;
  font-family: "KaiTi", "STKaiti", "楷体", serif;
}

.stat { display: flex; justify-content: space-between; align-items: baseline; }
.stat .num { font-size: 22px; font-weight: 700; color: var(--brand); }

/* 登录/注册居中 */
.center-screen {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 20px;
}
.center-screen .brand { font-size: 24px; font-weight: 700; color: var(--brand); margin-bottom: 4px; }
.center-screen .sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.center-screen .card { width: 100%; max-width: 380px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .82); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none;
  max-width: 90%; text-align: center; line-height: 1.4; z-index: 100;
}
#toast.show { opacity: 1; }

.row { display: flex; gap: 10px; align-items: center; }
.row > .btn { flex: 1; }

/* ---- AI 补字（FD）---- */
/* 字格 AI 角标（preview/edit 网格，.glyph-cell 由各页定义） */
.glyph-cell { position: relative; }
.glyph-cell.gen::after {
  content: 'AI'; position: absolute; top: 2px; right: 2px;
  font-size: 9px; line-height: 1; padding: 2px 3px; border-radius: 4px;
  background: var(--brand-soft); color: var(--brand-d);
  font-family: -apple-system, sans-serif;
}
/* 重新生成中：转圈 + 降透明 */
.glyph-cell.busy { opacity: .45; }
.glyph-cell.busy::before {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border: 2px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: ct-spin .8s linear infinite;
}
@keyframes ct-spin { to { transform: rotate(360deg); } }

/* 进度条 */
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--brand); transition: width .5s; }

/* 字体卡片内嵌的 AI 补字进度面板 */
.fd-panel {
  margin-top: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px;
}
.fd-panel .fd-stage { font-size: 14px; font-weight: 500; }
.fd-panel .err { display: block; margin-top: 6px; }
.fd-failed-chars { color: var(--muted); word-break: break-all; margin-top: 4px; }
.fd-panel .bar { margin-top: 8px; }
.fd-panel .fd-actions { margin-top: 10px; display: flex; gap: 8px; }

/* preview 页底部 sticky 的 AI 字操作条 */
.gen-actions {
  position: sticky; bottom: 0; z-index: 9;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; margin-top: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px;
}
.gen-actions .btn { min-height: 40px; padding: 6px 12px; font-size: 14px; flex: 1; }
.gen-actions .gen-char {
  font-family: "KaiTi", "STKaiti", "楷体", serif; font-size: 20px; min-width: 28px;
  text-align: center; color: var(--brand-d);
}

/* ===== 跨页复用组件（2026-08-19 从各页内联块下沉；页面差异用变量覆盖或页内变体）===== */

/* 模式切换按钮组（edit 矢量/位图、write 字表档位） */
.mode-switch { display: flex; gap: 8px; margin-bottom: 10px; }
.mode-btn {
  flex: 1; min-height: 40px; font-size: 15px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg);
  border-radius: 10px; color: var(--ink);
}
.mode-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }

/* 字格网格（edit 选字编辑 / preview 查看 / write 字表三页同族）。
   页面用 --glyph-size / --glyph-min / --glyph-font 覆盖；
   状态角标变体（.done / .committed / .hide / .busy 等）留各页或本文件专用节。 */
.glyph-grid {
  --glyph-size: 34px; --glyph-min: 56px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--glyph-min), 1fr));
  gap: 8px;
}
.glyph-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
  font-family: var(--glyph-font, "UF", "Microsoft YaHei", sans-serif);
  font-size: var(--glyph-size); line-height: 1;
  cursor: pointer; user-select: none; overflow: hidden; position: relative;
}
.glyph-cell.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }

/* 滑块行（preview 字号 / write 笔触） */
.size-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 150px; }
.size-row input[type=range] { flex: 1; }
.size-val { width: 2.5em; text-align: center; font-size: 14px; }

/* 状态行（加载/错误提示；min-height 防加载切换跳动） */
.status { padding: 4px 0 10px; color: var(--muted); font-size: 14px; min-height: 1em; }
.status.err { color: var(--err); }

/* 通用操作按钮基类（write sticky 操作栏 / edit 工具条 / edit 位图工具条）；
   flex 系数、min-height 微调与 .active 变体由各页覆盖 */
.act {
  flex: 1; min-height: 46px; font-size: 15px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg);
  border-radius: 10px; color: var(--ink);
}
.act:disabled { opacity: .5; cursor: not-allowed; }
.act.save { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
