/* SuperSu PWA · 暖纸工作室设计系统
 * 变量与本地版 templates/index.html 共用一套，改这里记得同步那边
 */

:root {
  --bg-canvas: #F7F4EE;
  --bg-surface: #FAF9F5;
  --bg-raised: #FFFFFF;
  --bg-hover: #F0EDE8;
  --border: #EAE6DD;
  --border-hi: #D8D2C6;
  --text: #191713;
  --text-soft: #6E6759;
  --text-muted: #9B9484;
  --accent: #AF3E2B;
  --accent-dim: #96331F;
  --accent-soft: rgba(175, 62, 43, .08);
  --accent-glow: rgba(175, 62, 43, .12);
  --success: #5F8F73;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font: "DM Sans", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC",
          -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", ui-monospace, monospace;
  --shadow-sm: 0 1px 3px rgba(87, 76, 54, .04);
  --shadow: 0 1px 8px rgba(87, 76, 54, .06);
  --shadow-lg: 0 4px 16px rgba(87, 76, 54, .10);
  --shadow-xl: 0 16px 48px rgba(20, 18, 14, .22);
  --top-h: 56px;
  --tabs-h: 0px;
}

* { box-sizing: border-box; }

/* hidden 属性必须压过组件自己的 display —— .drawer/.dialog/.phone-shell 都写了
 * display:flex，原生 [hidden]{display:none} 会被它们盖掉，导致「隐藏」的元素
 * 仍然占位并拦截点击（实测过：抽屉关着也能挡住按钮）。 */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg-canvas);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
a { color: var(--accent); }

/* ── 启动提示条（不遮挡、不阻塞：首屏立即可用，引擎好了自动消失） ── */
.boot {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  padding: 8px 14px; border-radius: 999px; max-width: 92vw;
  background: var(--bg-raised); border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(20, 18, 14, .10);
  pointer-events: none;            /* 绝不挡住输入区 */
  transition: opacity .35s ease, visibility .35s;
}
.boot .boot-title, .boot .boot-note { display: none; }
.boot.gone { opacity: 0; visibility: hidden; pointer-events: none; }

.boot-mark {
  width: 22px; height: 22px; border-radius: 7px;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(20, 18, 14, .10);   /* 图标自带浅色底，1px 描边让它在白底上站得住 */
}
.boot-mark img { width: 100%; height: 100%; display: block; }

.boot-title { margin: 8px 0 0; font-size: 20px; font-weight: 600; letter-spacing: .01em; }
.boot-sub { margin: 0; color: var(--text-soft); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.boot-bar { width: 110px; height: 3px; margin: 0; border-radius: 99px; background: var(--border); overflow: hidden; flex-shrink: 0; }
.boot-bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .35s ease; }

.boot-note { margin: 16px 0 0; max-width: 330px; text-align: center; font-size: 12px; line-height: 1.75; color: var(--text-muted); }

/* ── 顶栏 ─────────────────────────────────────────────────────── */
.top {
  height: var(--top-h); padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-raised); border-bottom: 1px solid var(--border);
  position: relative; z-index: 20;
}
.top-left { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* 品牌徽标：顶栏 / 启动条 / 更新区共用（资源在 public/brand，构建时拷进 dist/brand） */
.brand-mark {
  width: 24px; height: 24px; border-radius: 6px;
  flex: none; display: block;
  box-shadow: 0 0 0 1px rgba(20, 18, 14, .10);
}
.brand-mark.lg { width: 40px; height: 40px; border-radius: 10px; }
.brand-mark.xs { width: 16px; height: 16px; border-radius: 4px; }

.brand { font-size: 15px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.brand-tail { font-weight: 400; font-size: 12.5px; color: var(--text-soft); margin-left: 4px; }
.brand-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.top-right { display: flex; align-items: center; gap: 8px; position: relative; }

.engine-badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: 99px;
  font-size: 12px; color: var(--text-soft);
  background: var(--bg-surface); border: 1px solid var(--border);
  white-space: nowrap;
}
.engine-badge i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); transition: background .3s; }
.engine-badge[data-state="loading"] i { background: #C9A227; animation: pulse 1.4s infinite; }
.engine-badge[data-state="ready"] i { background: var(--success); }
.engine-badge[data-state="error"] i { background: var(--accent); }

@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .3 } }

.icon-btn {
  width: 30px; height: 30px; border-radius: var(--radius);
  color: var(--text-soft); font-size: 16px; line-height: 1;
  display: grid; place-items: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.menu {
  position: absolute; top: 38px; right: 0; min-width: 158px; padding: 5px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); z-index: 30;
}
.menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm); font-size: 13px; color: var(--text-soft); }
.menu button:hover { background: var(--bg-hover); color: var(--text); }
.menu button[disabled] { opacity: .45; cursor: default; }
.menu button[disabled]:hover { background: none; color: var(--text-soft); }

/* ── 主体两栏 ─────────────────────────────────────────────────── */
.stage {
  height: calc(100% - var(--top-h) - var(--tabs-h));
  display: grid;
  grid-template-columns: minmax(340px, 620px) 1fr;
}
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-edit { border-right: 1px solid var(--border); }
.pane-head { height: 44px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; flex: none; gap: 8px; }
.pane-title { font-size: 12px; font-weight: 600; color: var(--text-soft); letter-spacing: .04em; flex: none; }
.pane-meta { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; flex: none; }
.pane-actions { display: flex; align-items: center; gap: 8px; }

.input {
  flex: 1; width: 100%; min-height: 0; padding: 4px 16px 16px;
  border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font-family: var(--font); font-size: 14.5px; line-height: 1.85;
}
.input::placeholder { color: var(--text-muted); opacity: .9; }

.parse-bar {
  flex: none; min-height: 38px; padding: 8px 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-muted); background: var(--bg-surface);
}
.parse-hint { color: var(--text-muted); }
.chip-stat {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 99px;
  background: var(--bg-raised); border: 1px solid var(--border);
  color: var(--text-soft); font-size: 11.5px;
}
.chip-stat b { color: var(--accent); font-weight: 600; }

/* ── 预览 ─────────────────────────────────────────────────────── */
.preview-wrap { flex: 1; min-height: 0; padding: 0 16px 6px; display: flex; justify-content: center; overflow: hidden; }
.phone-shell {
  width: 100%; max-width: 420px; height: 100%;
  display: flex; flex-direction: column;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); overflow: hidden;
}
.wx-nav {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; height: 40px; font-size: 12px; color: var(--text-soft);
  background: var(--bg-surface); border-bottom: 1px solid var(--border);
}
.wx-nav-title { font-weight: 600; color: var(--text); max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { flex: 1; width: 100%; border: 0; background: #fff; }

.preview-empty { align-self: center; display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; text-align: center; }
.preview-empty b { color: var(--text-soft); font-size: 14px; font-weight: 600; }

.preview-wrap.web .phone-shell { max-width: 100%; border-radius: var(--radius); }

/* ── 风格条 ───────────────────────────────────────────────────── */
.style-bar {
  flex: none; height: 60px; padding: 0 10px;
  border-top: 1px solid var(--border); background: var(--bg-surface);
  display: flex; align-items: center; gap: 6px;
  /* 右侧留出悬浮「更新」按钮的位置，否则会盖住「全部风格」 */
  padding-right: 96px;
}
.style-caps { flex: 1; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 4px 2px; }
.style-caps::-webkit-scrollbar { display: none; }

.cap {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px 0 8px; border-radius: 99px;
  background: var(--bg-raised); border: 1px solid var(--border);
  color: var(--text-soft); font-size: 12.5px; white-space: nowrap;
  transition: border-color .15s, color .15s, background .15s;
}
.cap:hover { border-color: var(--border-hi); color: var(--text); }
.cap[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.cap-sw { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0,0,0,.08); flex: none; position: relative; overflow: hidden; }
.cap-sw::after { content: ""; position: absolute; inset: 50% 0 0 0; background: var(--sw2, transparent); }

.style-scroll { width: 24px; height: 34px; border-radius: var(--radius-sm); color: var(--text-muted); font-size: 16px; display: grid; place-items: center; }
.style-scroll:hover { background: var(--bg-hover); color: var(--text); }
.style-more { flex: none; height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border-hi); color: var(--text-soft); font-size: 12.5px; }
.style-more:hover { background: var(--bg-hover); color: var(--text); }

/* ── 按钮 ─────────────────────────────────────────────────────── */
.primary-btn {
  height: 32px; padding: 0 16px; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 500;
  transition: background .15s, opacity .15s;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-dim); }
.primary-btn:disabled { opacity: .4; cursor: not-allowed; }

.ghost-btn {
  height: 30px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); color: var(--text-soft); font-size: 12px;
}
.ghost-btn:hover { border-color: var(--border-hi); color: var(--text); }

/* ── 抽屉 ─────────────────────────────────────────────────────── */
.drawer-mask { position: fixed; inset: 0; z-index: 40; background: rgba(20, 18, 14, .28); backdrop-filter: blur(1px); }
.drawer {
  position: fixed; top: 0; right: 0; z-index: 50;
  width: min(560px, 94vw); height: 100%;
  background: var(--bg-canvas); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  display: flex; flex-direction: column;
  animation: slide-in .22s ease;
}

/* 选风格模式：抽屉「让位」而不是盖住预览 —— 桌面端把主区右推 460px，
   编辑器收起、预览留在左侧，点卡片可以直接看到效果（不重叠、不关闭） */
body.browsing .stage { grid-template-columns: 1fr; padding-right: 460px; }
body.browsing .pane-edit { display: none; }
body.browsing .drawer { width: 460px; }
body.browsing .drawer-mask { display: none; }

@media (max-width: 900px) {
  /* 手机宽度不够，只能浮层：恢复遮罩与编辑器，抽屉盖在上面 */
  body.browsing .stage { padding-right: 0; }
  body.browsing .pane-edit { display: flex; }
  body.browsing .drawer { width: min(560px, 94vw); }
  body.browsing .drawer-mask { display: block; }
}
@keyframes slide-in { from { transform: translateX(24px); opacity: .4 } to { transform: translateX(0); opacity: 1 } }

.drawer-head {
  flex: none; height: var(--top-h); padding: 0 12px 0 20px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border); background: var(--bg-raised);
}
.drawer-head b { font-size: 14px; flex: none; }

.drawer-search {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-surface); color: var(--text); font-family: inherit; font-size: 13px;
  outline: 0;
}
.drawer-search:focus { border-color: var(--border-hi); }
.drawer-search::-webkit-search-cancel-button { filter: grayscale(1); }

.drawer-filters { flex: none; padding: 12px 16px 4px; display: flex; gap: 6px; flex-wrap: wrap; }
.fchip {
  height: 28px; padding: 0 12px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--bg-raised);
  color: var(--text-soft); font-size: 12.5px;
}
.fchip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.drawer-grid {
  flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px 28px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  gap: 10px; align-content: start;
}

.d-card {
  display: flex; flex-direction: column; min-height: 118px;
  border-radius: var(--radius-lg); border: 1px solid var(--border);
  background: var(--bg-raised); overflow: hidden; text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.d-card:hover { border-color: var(--border-hi); box-shadow: var(--shadow); }
.d-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

.d-prev { height: 84px; background: var(--bg-hover); overflow: hidden; position: relative; }
/* 图片必须在占位层之上：占位层是 absolute，晚于 img 渲染会盖住真实缩略图 */
.d-thumb { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; position: relative; z-index: 1; }
.d-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 4px; padding: 10px; color: var(--text-muted); z-index: 0; }
.d-fallback i { display: block; height: 5px; border-radius: 2px; background: currentColor; opacity: .18; }
.d-fallback i:nth-child(1) { width: 62%; opacity: .5; height: 7px; }
.d-fallback i:nth-child(3) { width: 88%; }
.d-fallback i:nth-child(4) { width: 74%; }

.d-body { padding: 7px 9px 8px; display: flex; align-items: center; gap: 6px; }
.d-name { flex: 1; min-width: 0; font-size: 12px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-fav { flex: none; width: 20px; height: 20px; border-radius: var(--radius-sm); color: var(--text-muted); font-size: 13px; display: grid; place-items: center; }
.d-fav:hover { background: var(--bg-hover); color: var(--accent); }
.d-fav[data-on="1"] { color: var(--accent); }

/* ── 2A 族折叠（与本地版 templates/index.html 一致）：族代表卡 + 12 色调色点 ── */
.d-family-card .d-name { color: var(--accent); }
.d-badge { position: absolute; right: 8px; bottom: 8px; z-index: 2; padding: 1px 7px; border-radius: 99px; background: var(--accent); color: #fff; font-size: 10px; }
.d-count { flex: none; font-size: 10px; color: var(--text-muted); }
.d-fold { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 12px; }
.d-fold > .d-card { max-width: 200px; }
.d-tone-strip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; }
.d-tone { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 5px; width: 46px; background: none; border: none; padding: 0; cursor: pointer; }
.d-tone-dot { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border); transition: box-shadow .12s ease; }
.d-tone:hover .d-tone-dot { border-color: var(--border-hi); }
.d-tone[aria-pressed="true"] .d-tone-dot { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.d-tone-name { font-size: 10px; color: var(--text-muted); white-space: nowrap; }
.d-tone[aria-pressed="true"] .d-tone-name { color: var(--accent); font-weight: 600; }

.drawer-empty { grid-column: 1 / -1; padding: 40px 0; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── 对话框 ───────────────────────────────────────────────────── */
.dialog-mask { position: fixed; inset: 0; z-index: 60; background: rgba(20, 18, 14, .3); }
.dialog {
  position: fixed; z-index: 61; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(460px, 92vw); max-height: 82vh; overflow: auto;
  background: var(--bg-raised); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  display: flex; flex-direction: column;
}
.dialog-head { flex: none; height: 52px; padding: 0 12px 0 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.dialog-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dialog-body { padding: 16px 20px 20px; font-size: 13px; line-height: 1.8; color: var(--text-soft); }
.dialog-body p { margin: 0 0 12px; }
.dialog-body strong { color: var(--text); }
.about-links { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding-top: 6px; border-top: 1px solid var(--border); }

/* ── toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--tabs-h));
  transform: translateX(-50%) translateY(8px);
  z-index: 90; max-width: 78vw; padding: 9px 16px; border-radius: 99px;
  background: #241F19; color: #F7F4EE; font-size: 13px;
  box-shadow: var(--shadow-xl);
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--accent); }
.toast.ok { background: #2F4A3B; }

/* ── 移动端 ───────────────────────────────────────────────────── */
.tabs { display: none; }

@media (max-width: 900px) {
  :root { --tabs-h: 52px; }
  .stage { grid-template-columns: 1fr; }
  .pane-edit, .pane-preview { display: none; }
  .stage[data-tab="edit"] .pane-edit, .stage[data-tab="preview"] .pane-preview { display: flex; }
  .preview-wrap { padding: 0 10px 6px; }
  .phone-shell { max-width: 100%; }
  .input { padding: 4px 14px 14px; font-size: 15px; }
  .pane-head { padding: 0 14px; }
  .parse-bar { padding: 8px 14px; }
  .style-bar { padding: 0 92px 0 8px; }
  .brand-sub { display: none; }
  .brand-tail { display: none; }   /* 窄屏顶栏挤，系统名只留 SuperSu */
  .tabs {
    display: grid; grid-template-columns: 1fr 1fr; height: var(--tabs-h);
    background: var(--bg-raised); border-top: 1px solid var(--border);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  }
  .tabs button { color: var(--text-muted); font-size: 12.5px; }
  .tabs button[aria-pressed="true"] { color: var(--accent); font-weight: 600; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* build: 2026-10-18 增量更新验证版 r3（改动本行会触发新 BUILD_ID） */

/* ── AI 工具面板（纯前端 BYOK：Key 只存本机） ───────────────── */
.ai-mask { position: fixed; inset: 0; background: rgba(20, 18, 14, .28); z-index: 120; }
.ai-sheet {
  position: fixed; top: 0; right: 0; bottom: 0; width: 360px; max-width: 92vw;
  z-index: 121; padding: 18px 20px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg-raised); border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(20, 18, 14, .12);
}
.ai-head { display: flex; align-items: center; justify-content: space-between; }
.ai-tip { margin: 0; font-size: 12px; line-height: 1.7; color: var(--text-muted); }
.ai-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-soft); }
.ai-field input {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-canvas); color: var(--text); font: inherit; font-size: 13px;
}
.ai-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-btn {
  height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font: inherit; font-size: 12px; cursor: pointer;
}
.ai-btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.ai-btn:disabled { opacity: .55; cursor: default; }
.ai-sep { height: 1px; background: var(--border); margin: 6px 0; }
.ai-out {
  margin-top: 4px; padding: 10px 12px; border-radius: 8px;
  background: var(--bg-canvas); border: 1px solid var(--border);
  font-size: 13px; line-height: 1.8; white-space: pre-wrap;
}
