/* ============================================================
 * 打小人 — 100% 还原参考图
 * 米白底 · 黑描边圆角大卡片 · 彩色顶栏工具 · 简笔小人 · 生成/重置双色按钮
 * 全部图案用 HTML/SVG/CSS，不调用任何生图接口
 * ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #faf5ed;
  --card: #fffefb;
  --ink: #2b2620;
  --ink-soft: #6a5e52;
  --ink-mute: #a89a8a;
  --border: #2b2620;
  --line: rgba(43, 38, 32, 0.18);
  --line-soft: rgba(43, 38, 32, 0.12);
  --coral: #f07a65;
  --coral-dark: #d8604b;
  --coral-soft: #fff6f3;
  --teal: #4a9087;
  --teal-soft: #eaf5f3;
  --gold: #c4a060;
  --gold-soft: #faf5e8;
  --blue: #5a7eb5;
  --blue-soft: #f0f4fa;
  --shadow: 0 6px 24px rgba(43, 38, 32, 0.06);
}

html, body { height: 100%; }

body.sketch-app {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans SC", -apple-system, BlinkMacSystemFont, sans-serif;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.39 0 0 0 0 0.33 0 0 0 0.045 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
  padding: 10px 14px 14px;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 10px;
  flex-shrink: 0;
  background: transparent;
  border-bottom: none;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* 汉堡菜单 */
.menu-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(43,38,32,.08);
}
.menu-btn svg { width: 24px; height: 18px; }

/* 工具：彩色描边胶囊 */
.tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tool-btn {
  font-size: 22px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 2px solid var(--line-soft);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 0 rgba(43,38,32,.06);
  transition: all .12s;
  padding: 0;
  line-height: 1;
  position: relative;
}
.tool-btn:hover { transform: translateY(-1px); border-color: var(--coral); }
.tool-btn:active { transform: translateY(1px) scale(.95); }
.tool-btn.active {
  background: var(--coral-soft);
  border-color: var(--coral);
  box-shadow: 0 2px 0 rgba(240,122,101,.2);
  transform: scale(1.1);
}
/* 工具中文名 tooltip：悬浮/聚焦时显示在按钮下方 */
.tool-btn::after {
  content: attr(data-name);
  position: absolute;
  top: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%) translateY(-3px);
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
  z-index: 3000;
}
.tool-btn:hover::after,
.tool-btn:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.settings-text-btn {
  padding: 8px 14px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  box-shadow: 0 2px 0 rgba(43,38,32,.08);
}
.settings-text-btn:hover { background: var(--bg); }
.settings-text-btn:active { transform: translateY(1px); }

/* 键盘焦点可见性：所有主要交互元素统一青色描边 */
.tool-btn:focus-visible,
.settings-text-btn:focus-visible,
.history-clear:focus-visible,
.new-villain-btn:focus-visible,
.btn-generate:focus-visible,
.btn-reset:focus-visible,
.go-btn:focus-visible,
.h-del:focus-visible,
.history-item:focus-visible,
#settingsSave:focus-visible,
#promptsSave:focus-visible,
.btn-vault:focus-visible,
.btn-clear:focus-visible,
.history-nav button:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== 主体三栏大卡片 ===== */
.main {
  display: flex;
  flex: 1;
  gap: 14px;
  overflow: hidden;
  min-height: 0;
  margin-top: 14px;
}

.panel-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 4px 6px;
  flex-shrink: 0;
}
.panel-header h3 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--ink);
  position: relative;
  padding-bottom: 0;
}
.header-deco {
  width: 20px; height: 20px;
  color: var(--ink-mute);
}
.header-deco svg { width: 100%; height: 100%; }

/* 删除未使用的 header-deco 元素时兼容 */
.panel-header:only-child h3 { margin-bottom: 0; }

/* ===== 左侧小人栏 ===== */
/* ===== 小人栏弹出动画（高级感） ===== */
@keyframes sidebarReveal {
  0% {
    opacity: 0;
    transform: translateX(-30px) scale(.92);
    filter: blur(4px);
  }
  60% {
    opacity: 1;
    transform: translateX(4px) scale(1.01);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: blur(0);
  }
}
@keyframes sidebarHide {
  0% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translateX(-30px) scale(.92);
    filter: blur(4px);
  }
}
@keyframes itemSlideIn {
  0% {
    opacity: 0;
    transform: translateX(-16px) scale(.95);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}
@keyframes headerFadeIn {
  0% { opacity: 0; transform: translateY(-8px); }
  100% { opacity: 1; transform: translateY(0); }
}

.history-sidebar {
  width: 260px;
  padding: 0 16px 16px;
  transition: width .4s cubic-bezier(.22,1,.36,1),
              padding .4s cubic-bezier(.22,1,.36,1),
              opacity .35s ease,
              margin .4s cubic-bezier(.22,1,.36,1),
              transform .4s cubic-bezier(.22,1,.36,1),
              filter .3s ease;
  animation: sidebarReveal .5s cubic-bezier(.22,1,.36,1);
}
.history-sidebar:not(.hidden) > * {
  animation: itemSlideIn .4s cubic-bezier(.22,1,.36,1) backwards;
}
.history-sidebar:not(.hidden) > .panel-header { animation: headerFadeIn .35s ease backwards; animation-delay: .05s; }
.history-sidebar:not(.hidden) > .history-list { animation-delay: .12s; }
.history-sidebar:not(.hidden) > *:nth-child(3) { animation-delay: .18s; }

.history-sidebar.hidden {
  width: 0 !important;
  padding: 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  margin: 0 !important;
  border: none !important;
  transform: translateX(-30px) scale(.92);
  filter: blur(4px);
}

.history-sidebar .panel-header {
  padding: 12px 4px 6px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: #fff;
  border: 2px solid var(--line-soft);
  border-radius: 18px;
  cursor: pointer;
  position: relative;
  transition: transform .3s cubic-bezier(.22,1,.36,1),
              box-shadow .3s cubic-bezier(.22,1,.36,1),
              border-color .25s ease,
              background .25s ease;
  box-shadow: 0 2px 0 rgba(43,38,32,.06);
}
.history-item:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 20px rgba(43,38,32,.1);
  border-color: var(--coral);
}
.history-item.active {
  background: var(--coral-soft);
  border-color: var(--coral);
  box-shadow: 0 4px 14px rgba(240,122,101,.18);
  transform: scale(1.03);
}
.history-item .h-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  overflow: hidden;
}
.history-item .h-avatar svg { width: 32px; height: 32px; }
.history-item .h-avatar img { width: 100%; height: 100%; object-fit: cover; }
.history-item .h-body { flex: 1; min-width: 0; padding-right: 22px; }
.history-item .h-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item .h-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.history-item .h-status {
  font-size: 12px;
  color: var(--ink-mute);
  margin-top: 2px;
}
.history-item .h-check {
  width: 22px; height: 22px;
  color: var(--coral);
  flex-shrink: 0;
}
.history-item .h-check svg { width: 100%; height: 100%; }

/* 单条历史删除按钮：悬浮显示 */
.h-del {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink-mute);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all .15s;
  font-family: inherit;
  padding: 0;
}
.history-item:hover .h-del,
.h-del:focus-visible { opacity: 1; }
.h-del:hover {
  border-color: var(--coral);
  color: var(--coral-dark);
  background: var(--coral-soft);
}
@media (hover: none) { .h-del { opacity: .5; } }

/* 清空历史按钮 */
.history-clear {
  padding: 4px 10px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.history-clear:hover { border-color: var(--coral); color: var(--coral-dark); }
.history-clear:active { transform: translateY(1px); }
.history-clear.armed {
  background: var(--coral);
  border-color: var(--coral-dark);
  color: #fff;
}

.new-villain-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 14px 16px;
  margin-top: 12px;
  flex-shrink: 0;
  background: transparent;
  border: 2px dashed var(--line);
  border-radius: 18px;
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  transition: transform .3s cubic-bezier(.22,1,.36,1),
              box-shadow .3s cubic-bezier(.22,1,.36,1),
              border-color .25s ease,
              background .25s ease;
  font-family: inherit;
}
.new-villain-btn:hover {
  border-color: var(--coral);
  background: var(--coral-soft);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(240,122,101,.1);
}
.new-villain-btn:active { transform: translateY(0); }
.new-villain-btn .plus {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  font-size: 18px; font-weight: 600;
}

.sidebar-slogan {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 14px 4px 4px;
}
.slogan-icon {
  width: 28px; height: 28px;
  color: var(--coral);
  flex-shrink: 0;
}
.slogan-icon svg { width: 100%; height: 100%; }
.slogan-title { font-size: 12px; font-weight: 700; color: var(--ink); }
.slogan-sub { font-size: 11px; color: var(--ink-mute); margin-top: 2px; }

/* ===== 中间舞台 ===== */
.stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 20px 14px;
}
.stage:focus {
  outline: 3px solid var(--coral);
  outline-offset: -3px;
}

/* 舞台名牌：当前小人的名字 */
.stage-nameplate {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 5px 16px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(43,38,32,.08);
  white-space: nowrap;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: nameplateIn .4s cubic-bezier(.22,1,.36,1);
}
.stage-nameplate.hidden { display: none; }
@keyframes nameplateIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(.9); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* 连击徽章（显示在小人头部上方） */
.combo-badge {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  pointer-events: none;
  background: var(--coral);
  color: #fff;
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 15px;
  letter-spacing: 1px;
  box-shadow: 0 4px 14px rgba(240,122,101,.45);
  white-space: nowrap;
}
.combo-badge.pop { animation: comboPop .3s cubic-bezier(.22,1,.36,1); }
.combo-badge.hot {
  background: #ff8c42;
  font-size: 17px;
  box-shadow: 0 4px 18px rgba(255,140,66,.55);
}
@keyframes comboPop {
  0% { transform: translateX(-50%) scale(.4) rotate(-6deg); opacity: 0; }
  60% { transform: translateX(-50%) scale(1.25) rotate(3deg); opacity: 1; }
  100% { transform: translateX(-50%) scale(1) rotate(0); }
}

/* 首次拖拽引导提示 */
.drag-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(43,38,32,.35);
  white-space: nowrap;
  animation: hintBounce 1.6s ease infinite;
}
@keyframes hintBounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-6px); }
}

.stage-deco {
  position: absolute;
  inset: 50px 20px auto 20px;
  bottom: 120px;
  pointer-events: none;
  z-index: 0;
  color: var(--ink-soft);
  opacity: .45;
}
.stage-deco svg { width: 100%; height: 100%; }

.character-area {
  position: relative;
  width: min(420px, 90%);
  height: min(480px, 88%);
  z-index: 3;
  user-select: none;
  flex: 1;
  /* 地面阴影椭圆 + 顶部柔光：给小人"落地"感 */
  background:
    radial-gradient(ellipse 56% 7% at 50% 93%, rgba(43,38,32,.12), transparent 72%),
    radial-gradient(ellipse 40% 5% at 50% 93%, rgba(43,38,32,.08), transparent 70%);
}

.char-img {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}
.char-img.show { opacity: 1; }

.dragging-tool {
  position: fixed;
  font-size: 44px;
  pointer-events: none;
  z-index: 1000;
  display: none;
  /* 位置由 JS 通过 transform 设置，避免 left/top 触发布局 */
  top: 0;
  left: 0;
  will-change: transform;
}

.stage-hint {
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.8;
  margin-top: 10px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  animation: hintFadeIn .5s ease;
}
.stage-hint.hidden { display: none; }
@keyframes hintFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.hint-art {
  width: 150px;
  height: 130px;
  color: var(--ink-soft);
  opacity: .9;
  background: rgba(255,255,255,.65);
  border: 1.5px dashed var(--line);
  border-radius: 22px;
  padding: 6px;
  box-shadow: 0 4px 14px rgba(43,38,32,.05);
}
.hint-art svg { width: 100%; height: 100%; }
.hint-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--ink);
}
.hint-steps {
  display: flex;
  gap: 16px;
  margin-top: 4px;
  flex-wrap: wrap;
  justify-content: center;
}
.hint-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}
.hint-step span {
  width: 20px; height: 20px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--coral-dark);
  flex-shrink: 0;
}
.stage-hint-arrow {
  width: 48px; height: 30px;
  margin: 8px auto 0;
  color: var(--ink-soft);
}
.stage-hint-arrow svg { width: 100%; height: 100%; }

/* ===== 生成中加载遮罩 ===== */
.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(250,245,237,.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.stage-loading.hidden { display: none; }.loading-ring {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--coral);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 1px;
  animation: loadingPulse 1.2s ease infinite alternate;
}
@keyframes loadingPulse {
  from { opacity: .5; }
  to { opacity: 1; }
}

.round-info {
  margin-top: auto;
  padding: 6px 0;
  color: var(--ink-mute);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.round-pips { display: flex; gap: 5px; }
.round-pip {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--line);
  transition: background .25s ease, transform .25s ease;
}
.round-pip.done {
  background: var(--coral);
  transform: scale(1.15);
}

/* ===== 右侧信息栏 ===== */
.info-panel {
  width: 300px;
  padding: 0 14px 10px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: visible;
  justify-content: space-between;
}

.info-tip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--ink-soft);
  margin: 0 4px 8px;
  line-height: 1.45;
}
.info-tip svg { width: 14px; height: 14px; flex-shrink: 0; }

.info-panel label {
  display: block;
  margin-bottom: 4px;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 600;
}

.info-panel .area-label {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 4px;
}

.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 4px;
}
.form-row label { flex: 1; min-width: 0; margin-bottom: 0; }

.info-panel input,
.info-panel textarea {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.35;
}
.info-panel input::placeholder,
.info-panel textarea::placeholder,
.modal-box input::placeholder,
.modal-box textarea::placeholder {
  color: var(--ink-mute);
  opacity: 1;
}
.info-panel textarea {
  resize: none;
  flex: 1;
  min-height: 0;
}
.info-panel input:focus,
.info-panel textarea:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(240,122,101,.12);
}
.info-panel input:focus,
.info-panel select:focus,
.info-panel textarea:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(240,122,101,.12);
}

.info-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  flex-shrink: 0;
}

.btn-generate,
.btn-reset {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 8px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
}
.btn-generate .btn-icon,
.btn-reset .btn-icon { width: 18px; height: 18px; display: flex; align-items: center; }
.btn-generate .btn-icon svg,
.btn-reset .btn-icon svg { width: 100%; height: 100%; }

.btn-generate {
  background: var(--coral);
  color: #fff;
  border-color: var(--coral-dark);
}
.btn-generate:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-generate:disabled { opacity: .55; cursor: not-allowed; filter: grayscale(.4); }

.btn-reset {
  background: #fff;
  color: var(--ink);
}
.btn-reset:hover { background: var(--bg); }

.status-msg {
  margin-top: 6px;
  font-size: 11px;
  color: var(--coral-dark);
  min-height: 16px;
  max-height: 2.6em;
  overflow: hidden;
  text-align: center;
  flex-shrink: 0;
}

/* ===== 设置弹窗（高级弹出动画） ===== */
@keyframes modalOverlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalOverlayOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes modalBoxIn {
  0% {
    opacity: 0;
    transform: translateY(28px) scale(.92);
    filter: blur(6px);
  }
  60% {
    opacity: 1;
    transform: translateY(-4px) scale(1.01);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}
@keyframes modalBoxOut {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translateY(16px) scale(.94);
    filter: blur(4px);
  }
}
@keyframes modalFieldIn {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(43,38,32,.42);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-overlay.show {
  display: flex;
  animation: modalOverlayIn .28s ease both;
}
.modal-overlay.closing {
  animation: modalOverlayOut .22s ease both;
}
.modal-box {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 22px;
  padding: 26px 24px 22px;
  width: 440px;
  max-width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow:
    0 24px 60px rgba(43,38,32,.18),
    0 4px 0 rgba(43,38,32,.08);
  transform-origin: center center;
}
.modal-box-wide { width: 660px; }
.modal-overlay.show .modal-box {
  animation: modalBoxIn .42s cubic-bezier(.22,1,.36,1) both;
}
.modal-overlay.closing .modal-box {
  animation: modalBoxOut .22s ease both;
}
.modal-overlay.show .modal-box > * {
  animation: modalFieldIn .35s cubic-bezier(.22,1,.36,1) both;
}
.modal-overlay.show .modal-box > h2 { animation-delay: .04s; }
.modal-overlay.show .modal-box > fieldset:nth-of-type(1) { animation-delay: .08s; }
.modal-overlay.show .modal-box > fieldset:nth-of-type(2) { animation-delay: .14s; }
.modal-overlay.show .modal-box > .modal-actions { animation-delay: .2s; }

.modal-box h2 {
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 3px;
  margin-bottom: 18px;
}
fieldset {
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
  background: rgba(255,255,255,.55);
  transition: border-color .2s ease, box-shadow .2s ease;
}
fieldset:focus-within {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(240,122,101,.1);
}
legend { font-weight: 700; color: var(--ink-soft); font-size: 13px; padding: 0 6px; }
.modal-box code {
  display: inline-block;
  padding: 1px 6px;
  margin: 1px 0;
  background: var(--gold-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  color: var(--ink);
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.modal-box label { display: block; margin-bottom: 8px; font-size: 12.5px; color: var(--ink-soft); }
.modal-box input {
  display: block; width: 100%;
  margin-top: 4px; padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: inherit; font-size: 13px;
  background: #fff;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.modal-box textarea {
  display: block; width: 100%;
  margin-top: 4px; padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: inherit; font-size: 13px;
  line-height: 1.5;
  background: #fff;
  resize: vertical;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.modal-box input:focus,
.modal-box textarea:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(240,122,101,.12);
  transform: translateY(-1px);
}
.modal-actions { text-align: right; margin-top: 4px; }
.settings-warning {
  font-size: 11px;
  color: var(--coral-dark);
  background: var(--coral-soft);
  border: 1px solid var(--coral);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 14px;
  line-height: 1.5;
}
.btn-clear {
  display: inline-flex;
  align-items: center;
  padding: 10px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-right: 8px;
  transition: all .12s;
}
.btn-clear:hover { background: var(--bg); border-color: var(--ink-soft); }

/* 口令保护 UI */
.vault-fieldset { margin-top: 10px; }
.vault-hint { font-size: 11px; color: var(--ink-soft); margin: 0 0 8px; line-height: 1.5; }
.vault-hint.vault-locked { color: var(--coral-dark); font-weight: 600; }
.vault-actions { display: flex; gap: 8px; margin-top: 6px; }
.btn-vault {
  padding: 8px 14px;
  border: 2px solid var(--teal);
  border-radius: 12px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all .12s;
}
.btn-vault:hover { background: var(--teal); color: #fff; }

/* 重试按钮 */
.retry-btn {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 12px;
  border: 1.5px solid var(--coral);
  border-radius: 8px;
  background: var(--coral);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all .12s;
}
.retry-btn:hover { filter: brightness(1.1); }
#settingsSave,
#promptsSave {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  border: 2px solid var(--coral-dark);
  border-radius: 14px;
  background: var(--coral);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(43,38,32,.15);
  transition: all .12s;
}
#settingsSave:hover,
#promptsSave:hover { filter: brightness(1.05); transform: translateY(-1px); }
#settingsSave:active,
#promptsSave:active { transform: translateY(1px); }

/* ===== 滚动条 ===== */
.history-list::-webkit-scrollbar,
.info-panel::-webkit-scrollbar,
.modal-box::-webkit-scrollbar { width: 5px; }
.history-list::-webkit-scrollbar-thumb,
.info-panel::-webkit-scrollbar-thumb,
.modal-box::-webkit-scrollbar-thumb { background: rgba(43,38,32,.15); border-radius: 4px; }

/* ===== 响应式 ===== */
@media (max-width: 960px) {
  .history-sidebar { width: 210px; }
  .info-panel { width: 260px; }
  .character-area { width: min(340px, 88%); height: min(400px, 85%); }
  .tool-btn { width: 38px; height: 38px; font-size: 20px; }
}
@media (max-width: 720px) {
  .main { flex-direction: column; overflow: auto; -webkit-overflow-scrolling: touch; }
  .history-sidebar, .info-panel { width: 100%; height: auto; min-height: 0; }
  .stage { min-height: 420px; }
  .tools { flex-wrap: wrap; gap: 6px; }
  .tool-btn { width: 36px; height: 36px; font-size: 18px; border-radius: 8px; }
  .topbar-left { gap: 8px; }
  .history-list { max-height: 190px; }
  .hint-steps { flex-direction: column; gap: 6px; }
  .hint-art { width: 120px; height: 105px; }
  .settings-text-btn { padding: 7px 10px; font-size: 13px; }
  /* 触屏无 hover：隐藏工具名 tooltip，避免点击闪现 */
  .tool-btn::after { display: none; }
  /* 移动端排序：默认「信息表单 → 舞台 → 小人栏」；游戏中「舞台」优先置顶 */
  .history-sidebar { order: 3; }
  .stage { order: 2; }
  .info-panel { order: 1; }
  body.playing .stage { order: 1; }
  body.playing .history-sidebar { order: 2; }
  body.playing .info-panel { order: 3; }
}

/* ===== 动画 ===== */
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-6px,2px); }
  40% { transform: translate(5px,-2px); }
  60% { transform: translate(-4px,2px); }
  80% { transform: translate(3px,-1px); }
}
.character-area.shake .char-img.show {
  animation: shake 0.4s ease;
}

.bubble-layer {
  position: absolute; inset: 0;
  pointer-events: none; overflow: visible; z-index: 50;
}
.speech-bubble {
  position: absolute; max-width: 200px;
  padding: 10px 14px;
  background: #fff;
  border: 2px solid var(--coral);
  border-radius: 16px 18px 16px 4px;
  font-size: 13px; color: var(--ink);
  box-shadow: 0 3px 12px rgba(43,38,32,.08);
  animation: bubbleIn .25s ease;
}
@keyframes bubbleIn {
  from { opacity:0; transform: scale(.75) translateY(6px); }
  to { opacity:1; transform: scale(1) translateY(0); }
}
.speech-bubble.fade-out { animation: bubbleOut .4s ease forwards; }
@keyframes bubbleOut { to { opacity:0; transform: scale(.85); } }

.curse-text {
  position: absolute;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
  color: var(--coral-dark);
  text-shadow: 0 1px 2px rgba(255,255,255,.9);
  pointer-events: none;
  z-index: 100;
  animation: curseFloat 2.5s ease-out forwards;
}
@keyframes curseFloat {
  0% { opacity:0; transform: translate(-50%,-100%) scale(.6); }
  15% { opacity:1; transform: translate(-50%,-120%) scale(1.08); }
  30% { transform: translate(-50%,-140%) scale(1); }
  100% { opacity:0; transform: translate(-50%,-300%) scale(1); }
}

.history-nav {
  position: absolute;
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(43,38,32,.85);
  padding: 7px 14px; border-radius: 22px;
  z-index: 20; backdrop-filter: blur(6px);
}
.history-nav button {
  padding: 5px 12px; border: none; border-radius: 12px;
  background: var(--coral); color: #fff;
  font-size: 12px; cursor: pointer;
}
.history-nav button:disabled { background: #7a7068; color: #ccc; cursor: not-allowed; }
.history-nav #histExit { background: #8a8078; }
.history-nav #histRound { color: #f4ebe3; font-size: 12px; min-width: 48px; text-align: center; }

/* ===== 游戏结算覆盖层（小人磕头认罪后） ===== */
.game-over-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(250,245,237,.4);
  animation: overlayFade .3s ease;
}
@keyframes overlayFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.stage.viewing-history .game-over-overlay { display: none; }
.game-over-card {
  background: var(--card);
  border: 2.5px solid var(--border);
  border-radius: 22px;
  padding: 22px 26px 20px;
  text-align: center;
  max-width: 330px;
  width: 100%;
  box-shadow: 0 16px 44px rgba(43,38,32,.18), 0 3px 0 rgba(43,38,32,.08);
  animation: gameOverPop .45s cubic-bezier(.22,1,.36,1);
}
@keyframes gameOverPop {
  0% { opacity: 0; transform: scale(.8) translateY(16px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.game-over-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--ink);
}
.game-over-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
}
.game-over-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 16px 0 18px;
}
.go-stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--coral);
  line-height: 1.2;
}
.go-stat-label {
  font-size: 11px;
  color: var(--ink-mute);
  margin-top: 3px;
}
.game-over-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.go-btn {
  padding: 9px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border: 2px solid var(--border);
  transition: all .12s;
}
.go-primary {
  background: var(--coral);
  color: #fff;
  border-color: var(--coral-dark);
}
.go-primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.go-secondary { background: #fff; color: var(--ink); }
.go-secondary:hover { background: var(--bg); transform: translateY(-1px); }
.go-btn:active { transform: translateY(1px); }

/* ===== 投掷动画 ===== */
.thrown-tool {
  position: absolute;
  font-size: 36px;
  pointer-events: none;
  z-index: 80;
  transform: translate(-50%, -50%);
  filter: drop-shadow(2px 4px 6px rgba(0,0,0,.25));
  will-change: left, top, transform;
}
.thrown-tool.exploded {
  animation: explodePulse 0.5s ease-out forwards;
}
@keyframes explodePulse {
  0%   { transform: translate(-50%,-50%) scale(1); }
  30%  { transform: translate(-50%,-50%) scale(2.8); }
  100% { transform: translate(-50%,-50%) scale(1.5); opacity: 0; }
}
.thrown-tool.stuck {
  animation: stuckWiggle 0.3s ease;
}
@keyframes stuckWiggle {
  0%,100% { transform: translate(-50%,-50%) scale(1) rotate(0); }
  25%     { transform: translate(-50%,-50%) scale(1.1) rotate(-8deg); }
  75%     { transform: translate(-50%,-50%) scale(1.1) rotate(8deg); }
}
.burst-particle {
  position: absolute;
  font-size: 20px;
  pointer-events: none;
  z-index: 81;
  transform: translate(-50%, -50%);
  will-change: left, top, opacity, transform;
}
.puff-particle {
  position: absolute;
  font-size: 24px;
  pointer-events: none;
  z-index: 81;
  transform: translate(-50%, -50%);
  will-change: left, top, opacity, transform;
}

.sidebar-show { display: none; }
.history-empty { color: var(--ink-mute); text-align: center; padding: 40px 8px; font-size: 13px; }

/* ===== 无障碍：减少动效 ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .character-area.shake .char-img.show { animation: none; }
  .modal-overlay.show .modal-box,
  .modal-overlay.show .modal-box > * { animation: none; }
  .history-sidebar { animation: none; }
}
