/* styles.css —— CatsUp app 壳样式。created 2026-09-06 by Claude Fable 5.1
   z band 表（家族约定：z 数字只在这里）：menu 300 / notice 400 / help 500 / err 900 */
:root {
  --bg: #f2f0ea;
  --panel: #ffffff;
  --ink: #2a2a2a;
  --muted: #8a8780;
  --line: #ddd9d0;
  --accent: #2b6cb0;
  --accent-soft: #e3edf9;
  --danger: #c0392b;
  --z-menu: 300;
  --z-notice: 400;
  --z-help: 500;
  --z-err: 900;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang SC", "Noto Sans CJK SC", sans-serif; font-size: 14px;
  touch-action: manipulation; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; display: block; }
svg.ico use { color: inherit; }

#app { position: relative; height: 100%; }
#stage { position: absolute; inset: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; display: block; }

/* HUD（user 2026-09-06「hud 在视口里面…以后转 VR 会无疼」；2026-09-07 二稿：更游戏化——顶上空、左右两根竖栏、
   栏=弱玻璃无边框，文字（状态/版本）无背景只描白边；画布满屏，空白全部透给场景） */
.hud { position: absolute; z-index: 5; display: flex; align-items: center; gap: 2px; padding: 4px;
  background: rgba(255,255,255,.55); border-radius: 12px; box-shadow: 0 1px 6px rgba(0,0,0,.05);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.hud-rail { flex-direction: column; gap: 2px; padding: 4px; }
/* 左柱：☰ 叠在工具上、撤销/重做叠在工具下，整柱左居中（user 2026-09-07 终形：「工具居中，三条杠 stack 在工具上面不分离，undo redo stack 在工具下面」）*/
.hud-rail-tools { left: calc(10px + var(--safe-left)); top: 50%; transform: translateY(-50%); }
.hud-rail-tools > .tb-btn { width: 48px; }
.rail-tools { display: flex; flex-direction: column; gap: 2px; }
.hud-rail-right { right: calc(10px + var(--safe-right)); top: calc(10px + var(--safe-top)); }
/* 文字类 HUD：无背景、白描边（游戏字幕式），指针穿透 */
.hud-text { position: absolute; z-index: 5; pointer-events: none; font-size: 12px; color: #4a4a4a; line-height: 1.45;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 1px 3px rgba(255,255,255,.9); }
.hud-bl { bottom: calc(10px + var(--safe-bottom)); left: calc(10px + var(--safe-left)); max-width: min(62vw, 720px); }
.hud-br { bottom: calc(10px + var(--safe-bottom)); right: calc(10px + var(--safe-right)); }
.tb-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; cursor: pointer; color: var(--ink); }
.tb-btn:hover { background: rgba(0,0,0,.06); }
.tb-btn:active, .tb-btn.is-open { background: var(--accent-soft); color: var(--accent); }
.tb-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.tb-danger { color: var(--danger); }

.tool { width: 48px; height: 46px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border: 0; border-radius: 9px; background: transparent; cursor: pointer; color: #444; padding: 0; }
.tool .ico { width: 22px; height: 22px; }
.tool-label { font-size: 10px; line-height: 1; color: var(--muted); }
.tool:hover { background: rgba(0,0,0,.06); }
.tool.active { background: var(--accent); color: #fff; }
.tool.active .tool-label { color: #e7f0fb; }

#marquee { position: fixed; z-index: 5; border: 1px dashed #666; background: rgba(43,108,176,.08); pointer-events: none; }
#tip { position: fixed; z-index: var(--z-notice); padding: 2px 7px; font-size: 12px; background: rgba(255,255,255,.95);
  border: 1px solid #888; border-radius: 4px; pointer-events: none; white-space: nowrap; }
/* 状态行=RPG 对话框：最多两行，超出省略（user 2026-09-07「左下角的状态显示…相当于 rpg 游戏的对话，超出了怎么办」）*/
#hint { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; white-space: normal; overflow-wrap: anywhere; }
.build { color: var(--muted); font-variant-numeric: tabular-nums; }

/* 调试日志 sheet（debug-log-sheet.ts；WeebPaint diag-log 同款）：<pre> 豁免全局 user-select:none，长按/拖选可复制 */
.debug-log-sheet { width: min(720px, 100%); }
.debug-log-pre { max-height: 50vh; overflow: auto; margin: 0 0 4px; padding: 8px; border-radius: 8px; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word; text-align: left; background: rgba(127,127,127,.12); touch-action: pan-y;
  -webkit-touch-callout: default; -webkit-user-select: text; user-select: text; cursor: text; }

/* 弹出菜单 */
.popup-menu { position: fixed; z-index: var(--z-menu); min-width: 220px; max-width: min(92vw, 360px); padding: 6px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.14); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 6px 10px; border: 0; border-radius: 7px;
  background: transparent; text-align: left; cursor: pointer; }
.menu-item:hover { background: #f3f0ea; }
.menu-item:disabled { opacity: .45; cursor: default; }
.menu-item .ico, .ico-gap { width: 20px; height: 20px; flex: 0 0 20px; }
.menu-label { flex: 1; }
.menu-hint { font-size: 11px; color: var(--muted); }
.menu-check { color: var(--accent); }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--line); }

/* 通知栈（底部居中；一条栈一个样式） */
#noticeStack { position: fixed; left: 50%; bottom: calc(40px + var(--safe-bottom)); transform: translateX(-50%); z-index: var(--z-notice);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 560px); }   /* 定宽：fixed 元素 shrink-to-fit 会在长句 + 按钮时坍成 min-content（中文逐字折行，v0.5.2 崩溃通知截图） */
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 9px 10px 9px 14px; border-radius: 10px; max-width: 100%;
  background: #2f2f2f; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: 13px; }
.toast-info { background: #24405e; }
.toast-warning { background: #7a4d00; }
.toast-error { background: #7a1f16; }
.toast-text { flex: 1; }
.toast-actions { display: flex; gap: 6px; }
.toast-btn { padding: 5px 10px; border: 1px solid rgba(255,255,255,.4); border-radius: 6px; background: transparent; color: #fff; cursor: pointer; white-space: nowrap; }
.toast-btn.primary { background: #fff; color: #222; border-color: #fff; }
.toast-x { border: 0; background: transparent; color: rgba(255,255,255,.7); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px; }

/* 帮助 sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: var(--z-help); background: rgba(0,0,0,.25); display: grid; place-items: center; padding: 16px; }
.sheet { width: min(560px, 100%); max-height: 86vh; overflow: auto; background: var(--panel); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.25); padding: 10px 16px 16px; touch-action: pan-y; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.kv dt { color: var(--accent); font-weight: 600; white-space: nowrap; }
.kv dd { margin: 0; color: #444; }

/* 早期错误条 */
.err-banner { position: fixed; left: 0; right: 0; top: 0; z-index: var(--z-err); padding: 10px 14px; background: #b3261e; color: #fff; font-size: 13px; white-space: pre-wrap; }

@media (max-width: 640px) {
  .tool { width: 44px; height: 42px; }
  .tool-label { display: none; }
  .hud-bl { max-width: min(80vw, 720px); }
}
@media (max-height: 560px) {
  .hud-rail-tools { gap: 0; }
  .tool { height: 38px; } .tool-label { display: none; }
}

/* ---- 宿主自己在图库/sheet 里用到的 token ---- */
:root {
  --bg-0: #f4f4f2;
  --bg-1: #ebebe8;
  --paper: #ffffff;
  --ink-muted: #7a7a76;
  --line-strong: #c4c4bf;
  --overlay: rgba(0,0,0,.28);
  --font-ui: system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Noto Sans CJK SC', sans-serif;
  --z-busy: 700;
}
/* ---- @internal/gallery / workbench-elements 需要的宿主 token（2026-09-20 转正纪元；包只用 var()，值归宿主） ---- */
:root {
  --bg-soft: #ececea;
  --enc: #c98a00;
  --info: #4c7fb5;
  --ink-soft: #6b6b66;
  --shadow: 0 12px 40px rgba(0,0,0,.25);
  --tile-aspect: 1 / 1;
  --tile-min: 148px;
  --tile-min-narrow: 120px;
  --warn: #b7791f;
  --z-modal: 600;
  --z-overlay: 250;   /* 图库全屏：在 HUD(5) 之上、菜单(300) 之下 */
  --z-popover: var(--z-menu);
  --z-toast: var(--z-notice);
}

/* ---- 转正纪元（2026-09-20）：标题胶囊 / 图库容器 / sheet 模态 / busy ---- */
/* smart save 钮（三条杠下面，对齐 WeebPaint topSaveBtn；user 2026-09-20「最顶上那个 title 意义不明，可以不要」）：
   状态全交给 [data-state]，按钮永远可点（synced 的灰只是「没什么可存」的视觉，不是禁用）。 */
#btnSave { position: relative; }
#btnSave[data-state="none"] { opacity: .45; }
#btnSave[data-state="local-only"], #btnSave[data-state="cloud-off"] { color: var(--muted); }
#btnSave[data-state="dirty"] { color: var(--accent); }
#btnSave[data-state="dirty"]::after { content: ""; position: absolute; right: 7px; top: 7px; width: 7px; height: 7px; border-radius: 50%; background: #b7791f; }
#btnSave[data-state="unpushed"] { color: #b7791f; }
#btnSave[data-state="synced"] { color: #2f7d4f; }
#btnSave[data-state="saving"] .ico { animation: save-pulse 1s ease-in-out infinite; }
@keyframes save-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.gallery-full { position: fixed; inset: 0; z-index: var(--z-overlay); display: flex; flex-direction: column; background: var(--bg-0); color: var(--ink); font-family: var(--font-ui); }
.gallery-full[hidden] { display: none; }
.gallery-chrome { display: flex; align-items: center; gap: 6px; padding: max(env(safe-area-inset-top, 0px), 8px) 12px 8px; border-bottom: 1px solid var(--line); }
.gallery-chrome-title { font-weight: 600; }
.gallery-chrome .top-spacer { flex: 1 1 auto; }
.gallery-trashbar { display: flex; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.gallery-trashbar[hidden] { display: none; }
.gallery-mount { flex: 1 1 auto; overflow: auto; padding: 0 0 12px; display: flex; flex-direction: column; min-height: 0; }
.sheet-modal { width: min(440px, 100%); }
.sheet-title { margin: 4px 0 8px; font-size: 16px; font-weight: 600; }
.sheet-message { margin: 0 0 10px; font-size: 14px; color: #4a4a4a; white-space: pre-wrap; }
.sheet-message.warning { color: #b7791f; }
.sheet-input { width: 100%; box-sizing: border-box; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 10px; font: inherit; font-size: 15px; margin-bottom: 8px; }
.sheet-error { margin: 0 0 8px; font-size: 13px; color: var(--danger); }
.sheet-choices { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 4px; }
.sheet-choice { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--paper); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.sheet-choice.primary { background: var(--accent); color: #fff; border-color: transparent; }
.sheet-choice.danger { color: var(--danger); }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.busy-overlay { position: fixed; inset: 0; z-index: var(--z-busy); background: rgba(0,0,0,.25); display: grid; place-items: center; cursor: default; }
.busy-overlay[hidden] { display: none; }
.busy-card { width: min(320px, 90vw); text-align: center; }
