:root {
  --bg: #0f1320;
  --card: #1b2233;
  --accent: #8be9fd;
  --text: #e8eef7;
  --muted: #8a93a8;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body, #app { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; border: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5fb8d6);
  color: #0f1320; border-radius: 999px; padding: 10px 18px; font-weight: 700; font-size: 14px;
}
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 8px 16px; font-size: 13px; }
.loading { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); }

/* Gallery */
.page { min-height: 100%; padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); }
.page h1 { font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.page .sub { color: var(--muted); font-size: 13px; margin-top: 6px; line-height: 1.5; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 18px; }
.tpl { background: var(--card); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 8px; border: 1px solid rgba(255,255,255,.05); transition: transform .12s; }
.tpl:active { transform: scale(.97); }
.tpl .emoji { font-size: 40px; }
.tpl .name { font-size: 16px; font-weight: 700; }
.tpl .cat { font-size: 11px; color: var(--accent); background: rgba(139,233,253,.12); padding: 2px 8px; border-radius: 999px; align-self: flex-start; }
.tpl .desc { font-size: 12px; color: var(--muted); line-height: 1.5; min-height: 36px; }
.tpl .use { margin-top: auto; font-size: 13px; font-weight: 600; color: var(--accent); }

/* Editor */
.editor { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--card); border-bottom: 1px solid rgba(255,255,255,.06); }
.back { background: transparent; color: var(--accent); font-size: 26px; line-height: 1; padding: 0 4px; }
.title { flex: 1; font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share { padding: 8px 14px; font-size: 13px; }
.stage { flex: 1; position: relative; background: #05070d; }
.preview { width: 100%; height: 100%; border: none; background: #fff; }
.fab {
  position: fixed; right: 18px; bottom: calc(22px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #5fb8d6); color: #0f1320;
  font-size: 24px; box-shadow: 0 8px 22px rgba(0,0,0,.45); z-index: 20;
  touch-action: none; -webkit-user-select: none; user-select: none; cursor: grab;
}
.fab:active { transform: scale(.94); }

/* Chat sheet */
.sheet-mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; display: flex; align-items: flex-end; }
.sheet { width: 100%; height: 100vh; height: 100dvh; background: var(--bg); border-radius: 0; display: flex; flex-direction: column; overflow: hidden; animation: up .2s ease; }
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-head { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.06); padding-top: calc(14px + env(safe-area-inset-top)); }
.head-actions { display: flex; align-items: center; gap: 10px; }
.modelchip { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 12px;
  color: var(--accent); background: rgba(139,233,253,.14); border: 1px solid rgba(139,233,253,.25);
  padding: 5px 10px; border-radius: 999px; }
.modelchip .aimode-badge { margin: 0; padding: 0; background: none; color: inherit; }
.modelmenu { position: absolute; right: 14px; top: calc(100% - 4px); z-index: 40; min-width: 220px; max-height: 42vh; overflow-y: auto;
  background: var(--card); border: 1px solid rgba(255,255,255,.1); border-radius: 12px; padding: 8px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5); }
.mm-title { font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 8px 4px; }
.mm-modes { display: flex; gap: 6px; padding: 0 4px 4px; }
.mm-modes button { flex: 1; font-size: 12px; font-weight: 600; padding: 7px 6px; border-radius: 8px;
  background: rgba(255,255,255,.06); color: var(--text); }
.mm-modes button.on { background: var(--accent); color: #0f1320; }
.mm-modes button:disabled { opacity: .45; }
.mm-item { font-size: 13px; padding: 9px 10px; border-radius: 8px; cursor: pointer; word-break: break-all; }
.mm-item:hover { background: rgba(255,255,255,.06); }
.mm-item.on { background: rgba(139,233,253,.16); color: var(--accent); font-weight: 600; }
.close { background: transparent; color: var(--muted); font-size: 18px; }
.chat { flex: 1; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.8; background: var(--card); padding: 14px; border-radius: 12px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }
.bubble { max-width: 82%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.msg.user .bubble { background: var(--accent); color: #0f1320; border-bottom-right-radius: 4px; }
.msg.assistant .bubble {
  background: var(--card); border-bottom-left-radius: 4px;
  max-height: 28vh; overflow-y: auto; overscroll-behavior: contain;
}
.msg.assistant .bubble::-webkit-scrollbar { width: 5px; }
.msg.assistant .bubble::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 3px; }
.thinking { color: var(--muted); font-style: italic; }
.inputbar { display: flex; align-items: flex-end; gap: 8px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(255,255,255,.06); }
.inputbar textarea { flex: 1 1 auto; width: 100%; min-width: 0; background: var(--card); border: 1px solid rgba(255,255,255,.08);
  color: var(--text); border-radius: 16px; padding: 10px 14px; font-size: 14px; line-height: 1.5;
  font-family: inherit; outline: none; resize: none; overflow-y: auto; max-height: 22vh; }
.inputbar textarea::placeholder { color: var(--muted); }
.inputbar .btn-primary { flex: 0 0 auto; padding: 10px 20px; }

/* Share modal */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal { background: var(--card); border-radius: 16px; padding: 22px; width: 100%; max-width: 340px; text-align: center; }
.modal h3 { font-size: 18px; margin-bottom: 8px; }
.modal p { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.linkbox { background: #0f1320; border-radius: 10px; padding: 12px; font-size: 12px; word-break: break-all; color: var(--accent); margin-bottom: 14px; }
.modal .btn-primary { width: 100%; margin-bottom: 10px; }

/* 顶栏图标按钮 */
.iconbtn { background: transparent; color: var(--accent); font-size: 18px; padding: 4px 8px; border-radius: 10px; }
.iconbtn:active { background: rgba(139,233,253,.15); }

/* 配置面板 */
.cfg-body { flex: 1; overflow-y: auto; padding: 16px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.cfg-row { display: flex; flex-direction: column; gap: 8px; }
.cfg-row label { font-size: 13px; color: var(--muted); }
.cfg-row input[type=range] { width: 100%; accent-color: var(--accent); }
.cfg-row input[type=color] { width: 100%; height: 38px; background: var(--card); border: 1px solid rgba(255,255,255,.1); border-radius: 10px; }
.cfg-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.lvl-opt { background: var(--card); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 11px 14px; font-size: 14px; }
.lvl-opt.on { border-color: var(--accent); color: var(--accent); font-weight: 700; }

/* 代码编辑器 */
.codearea { width: 100%; height: 46vh; background: #0b0e16; color: #cfe8ef; border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; padding: 12px; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5; resize: none; outline: none; }
.cfg-actions { margin-top: 12px; }
.cfg-actions .btn-primary { width: 100%; }

/* AI 设置：分段控件 + 模式徽标 */
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 10px; background: #0b0e16; color: var(--muted);
  border: 1px solid rgba(255,255,255,.08); font-size: 13px; font-weight: 600; }
.seg button.on { background: linear-gradient(135deg, var(--accent), #5fb8d6); color: #0f1320; border-color: transparent; }
.seg button:disabled { opacity: .4; }
.aimodel { width: 100%; padding: 9px 10px; border-radius: 10px; background: #0b0e16; color: var(--text);
  border: 1px solid rgba(255,255,255,.1); font-size: 14px; outline: none; }
.aimode-badge { font-size: 11px; font-weight: 600; color: var(--accent); background: rgba(139,233,253,.14);
  padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }

/* 画廊顶部登录态 */
.gallery-head { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.btn-ghost.sm, .btn-primary.sm { padding: 7px 14px; font-size: 13px; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user .uname { font-size: 13px; color: var(--text); }
.section-title { font-size: 13px; color: var(--muted); margin: 18px 0 10px; font-weight: 700; letter-spacing: .5px; }
.section-title .muted { color: var(--muted); font-weight: 400; }

/* 我的游戏列表 */
.mygames { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.mygame { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid rgba(255,255,255,.06);
  border-radius: 12px; padding: 10px 12px; }
.mygame .mg-main { flex: 1; min-width: 0; }
.mygame .mg-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mygame .mg-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.btn-ghost.danger { color: #ff8a8a; border-color: rgba(255,138,138,.5); }

/* 登录/注册弹窗：改为居中卡片，避免移动端输入框被软键盘遮挡 */
.sheet-mask.auth-mask {
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.auth-sheet {
  width: 100%;
  max-width: 360px;
  height: auto;
  max-height: 92vh;
  border-radius: 16px;
  overflow-y: auto;
  animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.auth-seg { display: flex; gap: 6px; padding: 14px 16px 0; }
.auth-seg button { flex: 1; padding: 9px 6px; border-radius: 10px; background: #0b0e16; color: var(--muted);
  border: 1px solid rgba(255,255,255,.08); font-size: 13px; font-weight: 600; }
.auth-seg button.on { background: linear-gradient(135deg, var(--accent), #5fb8d6); color: #0f1320; border-color: transparent; }
.auth-body { gap: 12px; }
.auth-body input { width: 100%; padding: 12px 14px; border-radius: 10px; background: #0b0e16; color: var(--text);
  border: 1px solid rgba(255,255,255,.1); font-size: 16px; outline: none; -webkit-user-select: text; user-select: text; }
.auth-msg { color: #ff8a8a; font-size: 12px; min-height: 16px; }
.auth-sheet .cfg-actions .btn-primary { width: 100%; }

/* 回退版本面板 */
.ver-opt { background: var(--card); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 11px 14px; }
.ver-opt:active { border-color: var(--accent); }
.ver-title { font-size: 14px; font-weight: 700; }
.ver-sub { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 系统提示（回退等）*/
.msg.system { justify-content: center; }
.sysnote { font-size: 12px; color: var(--accent); background: rgba(139,233,253,.1); padding: 6px 12px; border-radius: 999px; }

/* FAB 拖拽态 */
.fab.dragging { cursor: grabbing; transform: scale(1.05); transition: none; }
.fab.dragging:active { transform: scale(1.05); }

