:root {
  --yellow: #ffe60a;
  --ink: #17191d;
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e8eaee;
  --sub: #818a99;
  --red: #ff4f24;
  --blue: #5b7fa6;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 24, 31, .06);
}

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

/* html 根背景 = 品牌色：iOS Safari 状态栏/顶部融合区取的就是它。
   body 铺满视口遮住中间内容区，品牌色只在状态栏区和回弹时露出（零性能开销） */
html {
  -webkit-text-size-adjust: 100%;
  background: var(--yellow);
}
html.admin { background: var(--ink); }

/* body 也用品牌色：Safari 状态栏取色可能采样 body 而非 html；
   内容区的灰底由 .page-ground 承担，视觉与原来一致 */
body {
  background: var(--yellow);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font: 15px/1.7 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.page-ground {
  flex: 1 0 auto;
  background: var(--bg);
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
/* 表单控件固定 16px：小于 16px 时 iOS Safari 聚焦会强制放大页面 */
input, textarea, select { font: inherit; font-size: 16px; color: inherit; }
a { color: inherit; }

.hidden { display: none !important; }

.wrap { max-width: 680px; margin: 0 auto; padding: 0 14px; }

/* ---------- 首页头部 ---------- */

.site-header {
  background: var(--yellow);
  /* env(): 全面屏/PWA 模式下把内容推离状态栏，普通浏览器里为 0 */
  padding: calc(26px + env(safe-area-inset-top, 0px)) 0 20px;
}
.logo { font-size: 24px; font-weight: 800; letter-spacing: .5px; }
.slogan { font-size: 13px; color: rgba(0, 0, 0, .55); margin: 2px 0 14px; }
.search-box input {
  width: 100%;
  padding: 11px 18px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  outline: none;
}
.search-box input:focus { box-shadow: 3px 3px 0 rgba(23, 25, 29, .9); }

/* ---------- 工具栏 ---------- */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(245, 246, 248, .93);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 10px 0 8px;
}
/* 分类栏固定单行（可横滑），放不下时右侧出现「展开」按钮，点开下拉面板平铺全部分类 */
.cats-row { display: flex; align-items: center; gap: 8px; }
.cats {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.cats::-webkit-scrollbar { display: none; }
.cat-expand {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: -14px 0 12px -6px var(--bg);
  white-space: nowrap;
}
.cat-sheet {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: #fff;
  border-top: 1px solid var(--line);
  border-radius: 0 0 16px 16px;
  box-shadow: 0 16px 28px rgba(20, 24, 31, .16);
  max-height: 56vh; /* 兜底值，打开时 JS 会按工具栏下方的实际可用高度重算 */
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 0 18px;
}
.cat-sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; }
.cat-sheet-count { font-size: 12px; color: var(--sub); }
.cat-sort { margin-left: auto; }
.cat-sort button { padding: 3px 11px; font-size: 12px; }
.cat-sheet .cat-search { position: static; margin-bottom: 10px; }
.cat-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-mask { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, .32); z-index: 9; }
.chip {
  flex: 0 0 auto;
  padding: 5px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13px;
  color: #4a5060;
  transition: all .15s;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: var(--yellow); font-weight: 600; }
.chip i { font-style: normal; font-size: 11px; color: var(--sub); margin-left: 5px; }
.chip.active i { color: rgba(255, 230, 10, .7); }
.sub-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.total { font-size: 12px; color: var(--sub); }
.sort-seg { background: #e9ebf0; border-radius: 999px; padding: 3px; display: flex; }
.sort-seg button { padding: 4px 13px; border-radius: 999px; font-size: 13px; color: #5a6172; }
.sort-seg button.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- 词条卡片 ---------- */

.list { padding-top: 4px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 15px 16px;
  margin: 12px 0;
}
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.term { font-size: 18px; font-weight: 800; word-break: break-word; overflow-wrap: anywhere; min-width: 0; }
.tag { font-size: 11px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.tag.plain { background: #eef0f4; color: #5a6172; }
.meaning {
  margin: 8px 0 2px;
  color: #2c313a;
  white-space: pre-wrap;
  word-break: break-word;
}
.meaning.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 10px; flex-wrap: wrap; }
.votes { display: flex; gap: 8px; }
.vote {
  font-size: 13px;
  padding: 5px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fafbfc;
  color: #5a6172;
  transition: all .15s;
}
.vote.like.active { background: #fff0eb; border-color: var(--red); color: var(--red); font-weight: 600; }
.vote.dislike.active { background: #eef3f8; border-color: var(--blue); color: var(--blue); font-weight: 600; }
.meta { font-size: 12px; color: var(--sub); text-align: right; }
.report-btn {
  font-size: 12px;
  color: #b3bac6;
  padding: 5px 4px;
  align-self: center;
}
.report-btn:hover { color: var(--red); }
.report-reasons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin-top: 8px;
  font-weight: 400;
}
.reason-item { display: flex; align-items: center; gap: 7px; font-size: 14px; padding: 3px 0; cursor: pointer; }
.reason-item input { accent-color: var(--red); width: 16px; height: 16px; margin: 0; }
.report-tag { font-size: 11px; padding: 2px 9px; border-radius: 999px; background: #ffe9e2; color: var(--red); white-space: nowrap; }

/* 一词多义：同一张卡片里并列多个含义；同义黑话；搜索高亮 */
.sense + .sense { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 4px; }
.sense-head { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.sense-head + .meaning { margin-top: 6px; }
.sense-idx {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--yellow);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sense-count { font-size: 11px; padding: 2px 9px; border-radius: 999px; background: var(--ink); color: var(--yellow); white-space: nowrap; }
.aliases { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--sub); }
.alias { font-size: 12px; padding: 1px 10px; border-radius: 999px; background: #f2f4f7; color: #4a5060; border: 1px solid transparent; }
.alias:hover { border-color: #c6ccd6; }
mark { background: #fff1a8; color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- 投稿分类选择器 ---------- */

.field-label { font-size: 13px; font-weight: 600; margin-top: 12px; }
.cat-picker { position: relative; margin-top: 5px; }
.cat-picker-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid #d8dce3;
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
}
.cat-picker-btn.placeholder { color: #9aa1ad; }
.cat-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 24, 31, .14);
  z-index: 5;
  max-height: 240px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
}
.cat-search {
  position: sticky;
  top: 0;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  outline: none;
}
.cat-search:focus { border-color: var(--ink); background: #fff; }
.cat-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
}
.cat-option:hover { background: #f2f4f7; }
.cat-option.picked { background: #fff7c2; font-weight: 600; }
.cat-option.create { color: #b45309; font-weight: 600; }

.list-status { text-align: center; color: var(--sub); font-size: 14px; padding: 34px 0; }
.load-more {
  display: block;
  margin: 6px auto 34px;
  padding: 9px 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
  color: #4a5060;
}

.site-footer { text-align: center; font-size: 12px; color: var(--sub); padding: 10px 14px 110px; }
.site-footer a { color: var(--sub); }

/* ---------- 悬浮提交按钮 ---------- */

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  background: var(--ink);
  color: var(--yellow);
  font-size: 15px;
  font-weight: 700;
  padding: 13px 22px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(23, 25, 29, .35);
  z-index: 20;
}
.fab:active { transform: scale(.96); }

/* ---------- 提交弹窗 ---------- */

/* 弹窗 = 可滚动的内容区 + 固定在底部的按钮栏：表单再长，「提交」也始终可见 */
dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(92vw, 440px);
  max-height: 86vh;
  overflow: hidden;
  margin: auto;
}
dialog[open] { display: flex; } /* 只在打开时改 display，否则会盖掉浏览器对未打开 dialog 的隐藏 */
dialog > form { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 22px 22px 4px;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { font-size: 18px; }
.dialog-tip { font-size: 12px; color: var(--sub); margin: 2px 0 6px; }
dialog label { display: block; font-size: 13px; font-weight: 600; margin-top: 12px; }
dialog input, dialog textarea, dialog select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  border: 1px solid #d8dce3;
  border-radius: 10px;
  background: #fff;
  outline: none;
  font-weight: 400;
}
dialog input:focus, dialog textarea:focus, dialog select:focus { border-color: var(--ink); }
dialog textarea { resize: vertical; }
.req { color: var(--red); }
.field-hint { display: block; font-size: 12px; color: #d97706; font-weight: 400; margin-top: 4px; min-height: 0; }
.form-error { font-size: 13px; color: var(--red); min-height: 20px; margin-top: 8px; }
.dialog-actions {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 22px 16px;
  background: #fff;
  border-top: 1px solid var(--line);
}

.btn { padding: 9px 20px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.btn.primary { background: var(--ink); color: var(--yellow); }
.btn.primary:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: #eef0f4; color: #4a5060; }
.btn.block { display: block; width: 100%; }
.btn.small { padding: 5px 14px; font-size: 13px; }
.btn.ok { background: #16a34a; color: #fff; }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger-outline { background: #fff; border: 1px solid var(--red); color: var(--red); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 999px;
  z-index: 100;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  max-width: 90vw;
}

/* ---------- 管理后台 ---------- */

.admin-body { background: var(--ink); }
.admin-top { background: var(--ink); color: var(--yellow); padding: calc(13px + env(safe-area-inset-top, 0px)) 0 13px; }
.admin-top .row { display: flex; justify-content: space-between; align-items: center; }
.top-link {
  color: var(--yellow);
  font-size: 13px;
  text-decoration: underline;
  margin-left: 12px;
}
.admin-main { padding-bottom: 40px; }

.login-card {
  max-width: 340px;
  margin: 70px auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 26px;
}
.login-card h2 { font-size: 17px; margin-bottom: 14px; }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d8dce3;
  border-radius: 10px;
  outline: none;
}
.login-card input:focus { border-color: var(--ink); }

.tabs { display: flex; gap: 6px; margin: 16px 0 4px; flex-wrap: wrap; }
.tabs button { padding: 7px 15px; border-radius: 10px; font-size: 14px; color: #5a6172; background: #eceef2; }
.tabs button.active { background: var(--ink); color: var(--yellow); font-weight: 600; }
.badge {
  display: inline-block;
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  padding: 3px 7px;
  vertical-align: 1px;
}

.a-card .term { font-size: 17px; }
.a-card select {
  padding: 5px 10px;
  border: 1px solid #d8dce3;
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  max-width: 190px;
}
.new-cat-mark { font-size: 11px; color: #d97706; background: #fef3c7; padding: 2px 8px; border-radius: 999px; }
.a-meta { font-size: 12.5px; color: var(--sub); margin-top: 8px; word-break: break-all; }
.a-reason { font-size: 13px; color: var(--red); margin-top: 6px; }
.a-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.a-card.editing input, .a-card.editing textarea, .a-card.editing select {
  display: block;
  width: 100%;
  max-width: none;
  margin: 6px 0;
  padding: 9px 12px;
  border: 1px solid #d8dce3;
  border-radius: 10px;
  outline: none;
}
.a-card.editing textarea { resize: vertical; }

/* 后台：搜索框、录入表单、批量预览 */
.admin-search {
  width: 100%;
  margin-top: 12px;
  padding: 9px 16px;
  border: 1px solid #d8dce3;
  border-radius: 999px;
  background: #fff;
  outline: none;
}
.admin-search:focus { border-color: var(--ink); }
.seg { display: inline-flex; background: #e4e7ec; border-radius: 999px; padding: 3px; margin-top: 14px; }
.seg button { padding: 5px 18px; border-radius: 999px; font-size: 13px; color: #5a6172; }
.seg button.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.entry-form label { display: block; font-size: 13px; font-weight: 600; margin-top: 12px; }
.entry-form input, .entry-form textarea, .entry-form select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  border: 1px solid #d8dce3;
  border-radius: 10px;
  background: #fff;
  outline: none;
  font-weight: 400;
}
.entry-form input:focus, .entry-form textarea:focus, .entry-form select:focus { border-color: var(--ink); }
.entry-form textarea { resize: vertical; }
.entry-tip {
  font-size: 12.5px;
  color: #5a6172;
  line-height: 1.9;
  background: #fafbfc;
  border: 1px dashed #d8dce3;
  border-radius: 10px;
  padding: 10px 12px;
}
.entry-tip code { background: #eceef2; padding: 1px 6px; border-radius: 4px; color: var(--ink); font-size: 12px; }
.batch-summary { font-size: 13px; font-weight: 600; margin-top: 14px; }
.batch-errors { margin-top: 6px; font-size: 12.5px; color: var(--red); }
.batch-errors li { margin: 4px 0 4px 18px; word-break: break-all; }
.batch-table-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; margin-top: 10px; }
.batch-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.batch-table th, .batch-table td { text-align: left; padding: 6px 9px; border-bottom: 1px solid var(--line); vertical-align: top; word-break: break-word; }
.batch-table th { position: sticky; top: 0; background: #f5f6f8; font-weight: 600; white-space: nowrap; }
.a-aliases { font-size: 12.5px; color: #5a6172; margin-top: 4px; }
.a-hint { font-size: 12px; color: #d97706; background: #fef3c7; padding: 3px 10px; border-radius: 8px; margin-top: 8px; display: inline-block; }

.cat-list { padding: 6px 16px; }
.cat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.cat-row:last-child { border-bottom: none; }
.cat-name { font-weight: 600; }
.cat-info { font-size: 12.5px; color: var(--sub); flex: 1; }
.cat-ops { display: flex; gap: 8px; }

/* ---------- 桌面端适配 ---------- */

@media (min-width: 900px) {
  .wrap { max-width: 1080px; padding: 0 24px; }

  .site-header { padding: calc(44px + env(safe-area-inset-top, 0px)) 0 30px; }
  .logo { font-size: 32px; }
  .slogan { font-size: 14px; margin-bottom: 18px; }
  .search-box input { max-width: 560px; padding: 13px 20px; font-size: 16px; }

  .cat-expand:hover { border-color: #c6ccd6; }
  .cat-sheet { max-height: 60vh; padding: 18px 0 22px; }
  .chip:hover:not(.active) { border-color: #c6ccd6; background: #fdfdfe; }
  .sort-seg button:hover:not(.active) { color: var(--ink); }

  .list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
    padding-top: 16px;
  }
  .card { margin: 0; padding: 18px 20px; }
  .card:hover { box-shadow: 0 4px 14px rgba(20, 24, 31, .1); }
  .term { font-size: 19px; }
  .vote:hover { border-color: #c6ccd6; }
  .fab { right: 40px; bottom: 40px; }
  .fab:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(23, 25, 29, .4); }
  .load-more:hover { border-color: #c6ccd6; }
  .site-footer { padding-bottom: 40px; }

  /* 后台保持单列，宽度收窄便于阅读 */
  .admin-main, .admin-top .wrap { max-width: 860px; }
  .admin-list { display: block; }
  .admin-main .card { margin: 12px 0; }
}
