/* ===== 基础 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #2563eb; --primary-dark: #1d4ed8;
  --danger: #dc2626; --success: #16a34a;
  --bg: #f1f5f9; --card: #ffffff; --text: #1e293b; --muted: #64748b; --border: #e2e8f0;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); overflow-x: hidden;
}
.hidden { display: none !important; }

/* ===== 顶部栏 ===== */
#top-bar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { font-size: 16px; font-weight: 700; }
/* top-actions 允许换行：按钮（重新上传 / 💾保存 / 模式徽章 / 🔑编辑 /
   ✅完成并发布 / 📝录入答案 / ✏️调整填空）较多时自动折行，
   保证任意窗口宽度下所有按钮都完整可见、可点击，不会溢出到屏幕外 */
.top-actions {
  display: flex; align-items: center; justify-content: flex-end;
  flex-wrap: wrap; gap: 8px 10px;
}
.page-indicator { color: var(--muted); font-size: 13px; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 8px; cursor: pointer; font-size: 14px; padding: 8px 16px;
  transition: background .15s, transform .1s; user-select: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #0ea5e9; color: #fff; }
.btn-secondary:hover { background: #0284c7; }
.btn-ghost { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #e2e8f0; }
.btn.big { min-width: 148px; padding: 12px 24px; font-size: 16px; font-weight: 600; border-radius: 10px; }
.btn.active-mode { background: #f59e0b; color: #fff; border-color: #d97706; }
.btn.btn-settings-active { background: #7c3aed; color: #fff; border-color: #6d28d9; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-add { background: #059669; color: #fff; }
.btn-add:hover { background: #047857; }
.btn-add.adding-active { background: #f59e0b; color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-success { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; }

/* ===== 编辑 / 发布模式 ===== */
.mode-badge {
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: #f1f5f9; color: #475569; border: 1px solid var(--border); white-space: nowrap;
}
.mode-badge.mode-edit { background: #ede9fe; color: #6d28d9; border-color: #c4b5fd; }
.pass-card {
  background: var(--card); border-radius: 14px; padding: 22px; width: min(92vw, 360px);
  box-shadow: 0 20px 60px rgba(15,23,42,.25);
}
.pass-card h3 { margin: 0 0 6px; }
.pass-card p { color: var(--muted); font-size: 13px; margin: 0 0 12px; line-height: 1.6; }
#pass-input {
  width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
#pass-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.pass-err { color: #dc2626; font-size: 13px; margin: 8px 0 0 !important; }
.pass-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.pass-actions .btn { padding: 8px 18px; }

/* ===== 上传面板 ===== */
#upload-panel { min-height: calc(100vh - 130px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 30px; }
.upload-box {
  background: var(--card); border: 2px dashed #cbd5e1; border-radius: 16px;
  padding: 48px 40px; text-align: center; max-width: 520px; width: 100%;
  cursor: pointer; transition: border-color .2s, background .2s;
}
.upload-box.dragover { border-color: var(--primary); background: #eff6ff; }
.upload-icon { font-size: 52px; margin-bottom: 12px; }
.upload-box h2 { font-size: 20px; margin-bottom: 8px; }
.upload-box p { color: var(--muted); font-size: 14px; line-height: 1.7; }
.upload-box .btn { margin-top: 18px; }
.drop-tip { margin-top: 14px; font-size: 13px; color: #94a3b8; }

/* 「继续上次的工作」本地存档列表 */
.saved-section {
  width: min(560px, 100%); text-align: left; background: var(--card);
  border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 8px 30px rgba(15,23,42,.05);
}
.saved-section h3 { font-size: 15px; margin: 0 0 4px; }
.saved-tip { font-size: 12px; color: var(--muted); margin: 0 0 10px; line-height: 1.6; }
#saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow: auto; }
.saved-item { display: flex; align-items: stretch; gap: 8px; }
.saved-open {
  flex: 1; display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 12px;
  border: 1px solid var(--border); background: #fff; border-radius: 10px; cursor: pointer; color: inherit;
  transition: border-color .15s, background .15s;
}
.saved-open:hover { border-color: var(--primary); background: #f5f9ff; }
.saved-name { font-weight: 600; font-size: 14px; word-break: break-all; }
.saved-meta { font-size: 12px; color: #78716c; }
.saved-del {
  width: 40px; flex: 0 0 auto; border: 1px solid var(--border); background: #fff; border-radius: 10px;
  cursor: pointer; color: #94a3b8; font-size: 14px;
}
.saved-del:hover { border-color: #fca5a5; color: #dc2626; background: #fef2f2; }
.saved-flash { background: #dcfce7 !important; color: #15803d; border-color: #86efac !important; }

/* ===== 书页区 ===== */
#book-view { padding: 20px 16px 130px; }
#page-scroll { display: flex; justify-content: center; }
/* 统一 9:16 竖版画布：容器固定宽度，图片按 9:16 高度自适应 */
#page-wrap { width: min(100%, 480px); }
#page-container { position: relative; background: var(--card); border-radius: 6px; overflow: hidden; box-shadow: 0 4px 24px rgba(15,23,42,.12); line-height: 0; }
#page-img { display: block; width: 100%; height: auto; aspect-ratio: 9 / 16; object-fit: fill; }
#fill-layer { position: absolute; inset: 0; pointer-events: none; }

/* 填空框 */
.blank-box { position: absolute; box-sizing: border-box; display: flex; align-items: center; justify-content: center; }
.blank-box input[type="text"] {
  width: 100%; height: 100%;
  border: 2px dashed var(--primary); border-radius: 6px;
  background: rgba(255,255,255,.88); text-align: center; font-size: 16px; font-weight: 600;
  color: var(--text); outline: none; font-family: inherit;
}
.blank-box input[type="text"]:focus { border-color: #93c5fd; background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.blank-box input.wrong { border-color: var(--danger); background: #fef2f2; color: var(--danger) !important; }
.blank-box input.correct-anim { border-color: var(--success); background: #f0fdf4; color: var(--success) !important; }
.blank-box input.answer-input { border-color: #f59e0b; background: #fffbeb; color: #b45309; }

/* 答案卡片 */
.answer-card {
  position: absolute; z-index: 5;
  background: #fffdf5; border: 1.5px solid #fde68a; border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
  padding: 8px 12px; font-size: 13px; line-height: 1.6;
  min-width: 170px; max-width: 280px; text-align: left; pointer-events: auto;
}
.answer-card .ans-word { font-size: 16px; font-weight: 700; color: var(--danger); }
.answer-card .ans-word.ok { color: var(--success); }
.answer-card .ans-phonetic { cursor: pointer; color: var(--primary); font-weight: 600; text-decoration: underline dotted; margin-left: 4px; }
.answer-card .ans-phonetic:hover { color: var(--primary-dark); }
.answer-card .ans-cn { color: #92400e; margin-top: 3px; line-height: 1.7; font-size: 13px; }
.answer-card .ans-cn .ans-pos {
  display: inline-block; background: #fef3c7; color: #b45309; border-radius: 4px;
  padding: 0 5px; margin-right: 5px; font-size: 12px; font-weight: 700; line-height: 1.5;
}
.answer-card .ans-cn.none { color: #78716c; font-weight: 400; font-size: 12px; }
.answer-card .ans-cn.none .ans-link { color: var(--primary); font-weight: 600; text-decoration: underline dotted; }
.answer-card .ans-cn.none .ans-link:hover { color: var(--primary-dark); }
.answer-card .ans-example { color: #57534e; margin-top: 2px; font-style: italic; }
.answer-card .ans-missing { color: #b45309; font-size: 12px; }

/* 手动 / 编辑模式 */
.blank-box.draggable { cursor: move; touch-action: none; }
.blank-box.draggable .resize-handle { touch-action: none; }
.blank-box.draggable input[type="text"] { border-color: #8b5cf6; background: rgba(139,92,246,.06); }
.blank-box.draggable input[type="text"]::placeholder { color: #c4b5fd; }
.blank-box.draggable:not(.selected)::after {
  content: attr(data-idx); position: absolute; top: -8px; left: -4px;
  font-size: 11px; font-weight: 700; color: #fff; background: #7c3aed;
  border-radius: 4px; padding: 0 4px; line-height: 1.5; pointer-events: none;
}
.blank-box .resize-handle {
  position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--primary); cursor: nwse-resize; display: none;
}
.blank-box.selected { outline: 2px solid var(--primary); border-radius: 6px; z-index: 6; }
.blank-box.selected .resize-handle { display: block; }
.blank-box.selected .resize-handle:hover { background: var(--primary-dark); transform: scale(1.15); }

/* 编辑提示条 */
.edit-tip {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #f5f3ff; border: 1px solid #ddd6fe; color: #5b21b6;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px;
}
.edit-tip > span { line-height: 1.6; }
.edit-tip .edit-tip-btns { display: flex; gap: 8px; flex-shrink: 0; }
.edit-tip .edit-tip-btns .btn { flex-shrink: 0; }

/* 翻页导航 */
#page-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 16px; }
.nav-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--card); font-size: 22px; color: var(--text); cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.08); transition: background .15s;
}
.nav-btn:hover:not(:disabled) { background: #eef2ff; }
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }
#page-num { font-size: 14px; color: var(--muted); min-width: 60px; text-align: center; }
#detect-tip { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ===== 底部固定栏 ===== */
#bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
  display: flex; justify-content: center; align-items: center; gap: 14px;
  padding: 12px 16px; background: rgba(255,255,255,.96);
  border-top: 1px solid var(--border); backdrop-filter: blur(8px);
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}
#bottom-bar .btn { flex-shrink: 1; }

/* ===== 弹窗 ===== */
.mask {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: rgba(15,23,42,.55); animation: fadeIn .2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.bingo-card, .hint-card {
  background: var(--card); border-radius: 16px; padding: 36px 44px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: popIn .3s ease;
}
@keyframes popIn { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.bingo-emoji { font-size: 64px; animation: bounce 1s infinite; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.bingo-card h2 { font-size: 26px; color: var(--success); margin: 10px 0 6px; }
.bingo-card p { color: var(--muted); margin-bottom: 20px; }
.bingo-actions { display: flex; gap: 12px; justify-content: center; }
.hint-card h3 { margin-bottom: 8px; }
.hint-card p { color: var(--muted); margin-bottom: 20px; line-height: 1.6; }

/* 加载指示 */
#loading-tip { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 300; background: #1e293b; color: #fff; padding: 10px 20px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.3); }

/* ===== 点词查词 ===== */
#word-tip {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 40;
  background: rgba(15, 23, 42, .72); color: #fff; font-size: 11px; line-height: 1;
  padding: 5px 10px; border-radius: 999px; white-space: nowrap;
  pointer-events: none; backdrop-filter: blur(2px);
}
#word-pop {
  position: fixed; z-index: 240; width: min(300px, calc(100vw - 20px));
  background: #fff; border-radius: 12px; box-shadow: 0 12px 40px rgba(15,23,42,.28);
  padding: 10px 14px; box-sizing: border-box; animation: popIn .18s ease;
  font-size: 14px; line-height: 1.6;
}
#word-pop .word-pop-head { display: flex; align-items: center; gap: 10px; border-bottom: 1px dashed #e2e8f0; padding-bottom: 6px; margin-bottom: 6px; }
#word-pop .word-pop-word { font-weight: 700; font-size: 18px; color: #1d4ed8; word-break: break-all; }
#word-pop .word-pop-ph {
  cursor: pointer; border: none; background: #eff6ff; color: #1d4ed8; font-size: 12.5px;
  border-radius: 999px; padding: 3px 10px; font-family: inherit; white-space: nowrap;
}
#word-pop .word-pop-ph:hover { background: #dbeafe; }
#word-pop .word-pop-close {
  margin-left: auto; cursor: pointer; border: none; background: none; color: #94a3b8;
  font-size: 15px; font-weight: 700; padding: 0 4px; line-height: 1;
}
#word-pop .word-pop-close:hover { color: #334155; }
#word-pop .word-pop-body { max-height: 42vh; overflow-y: auto; color: #44403c; font-size: 13.5px; }
#word-pop .word-pop-none { color: #a8a29e; font-size: 13px; }
/* 词性徽章（弹窗内复用释义渲染样式；.answer-card 内样式不变） */
.ans-pos {
  display: inline-block; background: #fef3c7; color: #b45309; border-radius: 4px;
  padding: 0 5px; margin-right: 5px; font-size: 12px; font-weight: 700; line-height: 1.5;
}

@media (max-width: 640px) {
  #bottom-bar { gap: 8px; padding: 10px 8px; }
  #bottom-bar .btn.big { min-width: 0; flex: 1 1 0; padding: 11px 6px; font-size: 14px; }
  #top-bar { flex-wrap: wrap; }
}

/* ===== 品牌 Logo ===== */
#brand { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
#brand:hover { opacity: .8; }
.brand-logo { height: 30px; width: auto; max-width: 130px; object-fit: contain; border-radius: 6px; pointer-events: none; flex: 0 0 auto; }
#logo-mask { z-index: 220; }
.logo-card {
  background: var(--card); border-radius: 14px; padding: 22px; width: min(92vw, 380px);
  box-shadow: 0 20px 60px rgba(15,23,42,.25); text-align: left;
}
.logo-card h3 { margin: 0 0 6px; }
.logo-card p { color: var(--muted); font-size: 13px; margin: 0 0 14px; line-height: 1.6; }
#logo-preview-box {
  display: flex; align-items: center; justify-content: center; width: 128px; height: 128px;
  margin: 0 auto 14px; border: 2px dashed #cbd5e1; border-radius: 14px; background: #f8fafc;
  overflow: hidden;
}
#logo-preview { max-width: 112px; max-height: 112px; object-fit: contain; }
.logo-placeholder { color: #94a3b8; font-size: 12px; }
.logo-actions { display: flex; justify-content: center; gap: 10px; margin-bottom: 4px; }
.logo-err { color: #dc2626; font-size: 13px; margin: 8px 0 0 !important; text-align: center; }
.logo-card .pass-actions { margin-top: 16px; }
