/* ========== 基础 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f4f6fa;
  color: #333;
  font-size: 14px;
  /* 应用壳：工具栏/页脚自然高，.layout 吃满剩余视口，页面整体永不滚出 100vh */
  display: flex; flex-direction: column; min-height: 100vh;
}
button, input { font-family: inherit; font-size: inherit; }
input { border: 1px solid #d9dee7; border-radius: 6px; padding: 6px 8px; background: #fff; }
input:focus { outline: none; border-color: #4a90e2; box-shadow: 0 0 0 2px rgba(74,144,226,0.2); }
kbd { background: #eee; border: 1px solid #ccc; border-radius: 4px; padding: 0 5px; font-size: 12px; }

/* 关键：[hidden] 必须能盖过 .btn{display:inline-flex} 等作者样式，否则 hidden 属性对按钮无效（浏览器默认 [hidden]{display:none} 会被类选择器覆盖）。 */
[hidden] { display: none !important; }

/* ========== 按钮 ========== */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid #d9dee7;
  background: #fff; color: #333; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: background 0.15s, transform 0.1s;
}
.btn:hover { background: #f0f3f8; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: #4a90e2; border-color: #4a90e2; color: #fff; }
.btn.primary:hover { background: #3b7fd1; }
.btn.danger { color: #e74c3c; border-color: #f5c6c2; }
.btn.danger:hover { background: #fdecea; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.icon { padding: 4px 8px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ========== 家长门 ========== */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, #fff6d5 0%, #ffe3ec 50%, #d9f3ff 100%);
  display: flex; align-items: center; justify-content: center;
}
.gate[hidden] { display: none; }
.gate-card {
  background: #fff; border-radius: 20px; padding: 36px 32px; width: 340px;
  text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.gate-emoji { font-size: 3rem; }
.gate-card h2 { margin: 8px 0; color: #ff6f61; }
.gate-card p { color: #666; margin: 6px 0; }
.gate-q { font-size: 1.8rem; font-weight: bold; color: #333; margin: 14px 0 !important; }
.gate-card input { width: 100%; font-size: 1.3rem; text-align: center; padding: 10px; }
.gate-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.gate-error { color: #e74c3c; min-height: 1.4em; }

/* ========== 工具栏 ========== */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: #fff; border-bottom: 1px solid #e3e7ee;
  flex-wrap: wrap; flex-shrink: 0;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar h1 { font-size: 1.2rem; color: #333; }
.status { font-size: 12px; color: #2ecc71; background: #eafaf1; padding: 3px 10px; border-radius: 999px; }
.status.dirty { color: #e67e22; background: #fdf2e6; }
.toolbar-user { display: flex; align-items: center; gap: 8px; }
.user-chip { font-size: 12px; color: #4a5b7a; background: #eef3fb; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }

/* ========== 登录层 ========== */
.login-card { width: 360px; }
.login-field { text-align: left; margin: 12px 0; }
.login-field label { display: block; font-size: 13px; color: #666; margin-bottom: 4px; }
.login-field input { text-align: left; }
.new-user-result { margin-top: 10px; padding: 10px 12px; background: #fff8e6; border: 1px solid #ffe3a3; border-radius: 10px; font-size: 14px; word-break: break-all; text-align: left; }

.tabs { display: flex; gap: 4px; background: #f0f3f8; padding: 4px; border-radius: 10px; }
.tab { border: none; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: #666; }
.tab.active { background: #fff; color: #333; font-weight: bold; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* ========== 账号页 ========== */
.accounts-page { padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; max-width: 1100px; margin: 0 auto; }
.accounts-page[hidden], .layout[hidden] { display: none; }
.accounts-page h2 { font-size: 1.05rem; margin-bottom: 8px; }
.muted { color: #888; font-size: 13px; line-height: 1.6; margin-bottom: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pin-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pin-form input { width: 180px; }
.profile-table .p-avatar { font-size: 1.8rem; }
.profile-table .p-name { font-weight: bold; }
.progress-bar { height: 8px; background: #eef1f6; border-radius: 999px; overflow: hidden; margin-top: 4px; }
.progress-bar > span { display: block; height: 100%; background: #4a90e2; border-radius: 999px; }
.profile-modal-card { width: 400px; }
.profile-modal-card h2 { color: #333; }
.avatar-pick { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 14px 0; }
.avatar-pick button { font-size: 1.5rem; background: #f5f6f8; border: 2px solid transparent; border-radius: 10px; padding: 4px 0; cursor: pointer; }
.avatar-pick button.selected { border-color: #4a90e2; background: #e8f1fc; }
.profile-modal-card input { text-align: left !important; font-size: 1rem !important; }

/* ========== 布局 ========== */
:root { --icp-h: 40px; }
/* 视口分配交给 flex，不再用 100vh 硬减魔法数（写死 56px 与实际 57px 的偏差就是永久滚动条的来源） */
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 260px; flex-shrink: 0; background: #fff; border-right: 1px solid #e3e7ee;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto;
}
.sidebar-head { display: flex; justify-content: space-between; align-items: center; font-weight: bold; }
.sidebar-head small { color: #999; font-weight: normal; }
.sidebar-tip { font-size: 12px; color: #888; line-height: 1.6; margin-top: auto; }

.cat-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.cat-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; border-left: 4px solid var(--c, #ccc);
}
.cat-item:hover { background: #f0f3f8; }
.cat-item.active { background: #e8f1fc; font-weight: bold; }
.cat-item .ci-emoji { font-size: 1.3rem; width: 28px; text-align: center; }
.cat-item .ci-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .ci-name small { display: block; font-weight: normal; color: #888; font-size: 12px; }
.cat-item .ci-count { font-size: 12px; color: #999; background: #f0f0f0; padding: 1px 7px; border-radius: 999px; }

.content { flex: 1; padding: 18px 22px; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.panel { background: #fff; border-radius: 14px; border: 1px solid #e6eaf0; padding: 16px 18px; box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 6px 18px -10px rgba(16,24,40,.12); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 1.05rem; }
.panel-head small { color: #999; font-weight: normal; }
.panel-actions { display: flex; gap: 8px; align-items: center; }
#word-filter { width: 230px; height: 34px; padding: 0 14px; border-radius: 999px; background: #f7f9fc; border-color: #e3e7ee; }
#word-filter:focus { background: #fff; }

/* 分类表单 */
.cat-form { display: flex; gap: 20px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: #8a94a6; font-weight: 600; letter-spacing: .02em; }
.field.actions { flex-direction: row; gap: 6px; margin-left: auto; }
.emoji-input { width: 70px; font-size: 1.5rem; text-align: center; padding: 2px 6px; }
#f-cat-color { width: 60px; height: 36px; padding: 2px; }
.cat-form .field > input:not([type="color"]) { min-width: 130px; height: 36px; }

/* 词库只读（家长）：隐藏输入框与分类操作，直接用文本/色块展示 */
.cat-form .ro-field { display: none; }
.cat-form.readonly .ro-field { display: inline-flex; align-items: center; }
/* 图标预览框：inline-flex 下 text-align 对匿名文本项无效，用 justify-content 让 Emoji 水平居中 */
.cat-form.readonly .ro-field.pic-preview { justify-content: center; }
.cat-form.readonly input { display: none !important; }
.cat-form.readonly .field.actions { display: none; }
.ro-field.ro-text { min-height: 30px; font-size: 15px; color: #333; }
.ro-field.ro-color { min-width: 60px; height: 34px; justify-content: center; border-radius: 8px; border: 1px solid #d7dbe0; font-size: 12px; color: #444; }
.word-table .ro-word, .word-table .ro-zh, .word-table .ro-sentence { color: #333; }

/* ========== 单词表 ========== */
.table-wrap { border: 1px solid #eef1f5; border-radius: 10px; overflow: auto; max-height: calc(100vh - 250px - var(--icp-h)); }
.word-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.word-table th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-size: 12px; color: #6b7280; font-weight: 600;
  padding: 10px 12px; background: #f7f9fc; border-bottom: 1px solid #e3e7ee;
}
.word-table td { padding: 10px 12px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
.word-table tbody tr:nth-child(even) td { background: #fbfcfe; }
.word-table tbody tr:last-child td { border-bottom: none; }
.word-table tr:hover td { background: #f1f6ff; }
.word-table tr.highlight td { background: #fff8e1; }
.word-table input { width: 100%; }
.word-table .idx { color: #a3aab8; font-size: 12px; font-variant-numeric: tabular-nums; }

.pic-cell { display: flex; align-items: center; gap: 6px; }
.pic-preview {
  width: 42px; height: 42px; flex-shrink: 0; font-size: 1.7rem; line-height: 42px; text-align: center;
  background: #f7f8fa; border-radius: 8px; overflow: hidden;
}
.pic-preview img { width: 100%; height: 100%; object-fit: contain; }
.pic-cell input { width: 60px; text-align: center; }
.pic-cell .btn { padding: 4px 6px; }

.row-actions { display: flex; gap: 4px; }
.empty-tip { text-align: center; color: #999; padding: 30px 0; }

/* ========== Toast ========== */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px);
  background: #333; color: #fff; padding: 10px 18px; border-radius: 999px;
  opacity: 0; transition: all 0.25s; pointer-events: none; z-index: 200; font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #e74c3c; }

/* ========== 小屏 ========== */
@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; height: auto; max-height: 260px; }
  .sidebar-tip { display: none; }
  .two-col { grid-template-columns: 1fr; }
}

/* ========== ICP 备案页脚（固定 40px，与 :root --icp-h 联动） ========== */
.icp {
  height: var(--icp-h); box-sizing: border-box; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; color: #9aa4b0;
}
.icp a { color: inherit; text-decoration: none; }
.icp a:hover { text-decoration: underline; }
