/* 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; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--bg-canvas);
  transition: opacity .45s ease, visibility .45s;
}
.boot.gone { opacity: 0; visibility: hidden; pointer-events: none; }

.boot-mark {
  width: 46px; height: 46px; border-radius: 13px;
  background: var(--accent);
  display: grid; place-items: center;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.boot-dot { width: 13px; height: 13px; border-radius: 50%; background: #fff; opacity: .92; }

.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: 13px; font-variant-numeric: tabular-nums; }

.boot-bar { width: 224px; height: 3px; margin-top: 12px; border-radius: 99px; background: var(--border); overflow: hidden; }
.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; }

.seal {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 600; line-height: 24px; text-align: center;
  flex: none; user-select: none;
}

.brand { font-size: 15px; font-weight: 700; letter-spacing: .01em; }
.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, .wx-bar {
  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-bar { border-bottom: 0; border-top: 1px solid var(--border); gap: 22px; justify-content: flex-end; }
.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;
}
@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; }
.d-thumb { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.d-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 4px; padding: 10px; color: var(--text-muted); }
.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); }

.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-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; }

/* ── 更新入口（右下角）─────────────────────────────────────────── */
.upd-btn {
  position: fixed; right: 16px; bottom: calc(16px + var(--tabs-h));
  z-index: 70;
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 99px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text-soft);
  font-size: 12px;
  transition: border-color .15s, color .15s, box-shadow .15s;
}
.upd-btn:hover { border-color: var(--border-hi); color: var(--text); box-shadow: var(--shadow-lg); }
.upd-ver { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: -.01em; }

.upd-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.6s infinite;
}

.upd-card {
  position: fixed; right: 16px; bottom: calc(58px + var(--tabs-h));
  z-index: 71; width: min(320px, calc(100vw - 32px));
  padding: 14px 16px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  animation: upd-in .22s ease;
}
@keyframes upd-in { from { transform: translateY(8px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }
.upd-card b { display: block; font-size: 13px; color: var(--text); margin-bottom: 4px; }
.upd-card p { margin: 0 0 12px; font-size: 12.5px; line-height: 1.65; color: var(--text-soft); }
.upd-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 900px) {
  .upd-btn { right: 12px; bottom: calc(12px + var(--tabs-h)); }
  .upd-card { right: 12px; bottom: calc(54px + var(--tabs-h)); }
}

/* ── 移动端 ───────────────────────────────────────────────────── */
.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; }
  .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; }
}
