/* ==========================================================================
   Inkpad — 编辑器样式（移动优先）
   ========================================================================== */
@import url("style.css");

html, body { height: 100%; }

body.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

/* ---------- 顶部应用栏 ---------- */
.app-header {
  flex: none;
  min-height: 54px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(170%) blur(14px);
  border-bottom: 1px solid var(--line);
  z-index: 40;
}
.app-header .brand { font-size: 15px; }
.app-header__title {
  min-width: 0; flex: 1 1 auto;
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; font-weight: 700; color: var(--ink-2);
}
.app-header__title span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-header__actions { display: flex; align-items: center; gap: 7px; flex: none; }
/* 站点 Logo：仅桌面端显示的纯文字标识（随语言切换），非链接 */
.app-logo { display: none; }
/* 移动端隐藏帮助与全屏按钮，桌面端在下方媒体查询中恢复 */
#btnHelp, #btnFullscreen { display: none; }

@media (min-width: 768px) {
  .app-header { padding: 0 18px; }
  /* 去掉返回首页的品牌链接；标题已移入编辑区第一行，头部不再显示标题 */
  .app-header .brand { display: none; }
  .app-header__title { display: none; }
  /* PC 端标题单击即可改名，故隐藏重命名（铅笔）按钮 */
  #btnRename { display: none; }
  /* 文字 Logo：随语言切换，纯展示不可点击 */
  .app-logo {
    display: block; flex: none;
    font-size: 15px; font-weight: 800; color: var(--ink);
    letter-spacing: -0.01em; white-space: nowrap;
  }
  /* 帮助及其后的按钮整体靠右，右边缘与编辑区右边缘对齐 */
  .app-header__actions { margin-left: auto; }
  /* 帮助内容在移动端不易触达，帮助弹窗改由文档列表侧栏进入，故仅桌面端显示该按钮 */
  #btnHelp { display: inline-flex; }
  #btnFullscreen { display: inline-flex; }
}
/* 移动端去掉返回首页的品牌按钮，把宽度让给文档名和操作按钮 */
@media (max-width: 767px) {
  .app-header .brand { display: none; }
  /* 标题占据剩余空间，语言选择放到操作区最右侧并压缩为圆形图标按钮，多留空间给文档名 */
  #langSelect { order: 99; }
  .app-header__actions #langSelect {
    width: 32px; min-width: 32px; height: 32px; max-width: 32px;
    padding: 0; border-radius: 50%;
    font-size: 0; color-scheme: light;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M3 12h18'/%3E%3Cpath d='M12 3a15 15 0 0 1 0 18a15 15 0 0 1 0-18'/%3E%3C/svg%3E");
    background-position: center; background-size: 17px 17px;
  }
  /* select 本体隐藏文字只显图标，但 option 会继承 font-size，
     需显式恢复字号与配色，否则移动端原生下拉列表里看不到任何语言名 */
  .app-header__actions #langSelect option {
    font-size: 13.5px; line-height: 1.5; color: #1c1e26; background: #fff;
  }
}

/* 视觉隐藏但可被搜索引擎/读屏读取（如页面 H1） */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- 通用小按钮 ---------- */
.tb {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; min-width: 34px; padding: 0 9px; flex: none;
  border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: var(--ink-2);
  font-size: 13.5px; font-weight: 650; cursor: pointer; white-space: nowrap;
  transition: background .15s var(--ease), color .15s var(--ease),
    border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.tb:hover { background: var(--surface); color: var(--ink); border-color: var(--line); }
.tb:active { transform: translateY(1px); }
.tb[aria-pressed="true"] {
  background: var(--grad-soft); color: var(--brand-1); border-color: var(--line-2);
}
.tb[disabled] { opacity: .35; cursor: not-allowed; }
.tb[disabled]:hover { background: transparent; border-color: transparent; color: var(--ink-2); }
.tb--solid {
  background: var(--grad); color: #fff; padding: 0 14px;
  box-shadow: 0 8px 18px -10px color-mix(in srgb, var(--brand-1) 80%, transparent);
}
.tb--solid:hover { background: var(--grad); color: #fff; border-color: transparent; }
.tb--labelled { padding: 0 13px; }
.tb--danger:hover { color: #e11d48; border-color: color-mix(in srgb, #e11d48 40%, transparent); }

/* 保存格式下拉 */
.tb-select {
  -webkit-appearance: none; appearance: none;
  height: 34px; padding: 0 26px 0 11px; flex: none;
  border: 1px solid var(--line); border-radius: 999px;
  background-color: transparent; color: var(--ink-2);
  font: inherit; font-size: 13.5px; font-weight: 650; cursor: pointer;
  max-width: 160px; white-space: nowrap;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.tb-select:hover { background-color: var(--surface); border-color: var(--line); color: var(--ink); }
.tb-select:focus-visible { outline: 2px solid var(--brand-1); outline-offset: 1px; }

.tb-divider { width: 1px; height: 20px; background: var(--line); margin: 0 3px; flex: none; }

/* ---------- 工具栏（始终换行显示，不横向滚动） ---------- */
.toolbar {
  flex: none;
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 3px; row-gap: 5px;
  padding: 7px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.toolbar__scroll {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 3px; row-gap: 5px;
  flex: 1 1 auto; min-width: 0;
}
.toolbar__right {
  flex: none; display: flex; align-items: center; gap: 4px;
  margin-left: auto;
}

@media (min-width: 768px) {
  .toolbar { padding: 8px 18px; }
}

.select {
  height: 34px; border-radius: 10px; padding: 0 10px;
  border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); font-size: 13px; font-weight: 650; cursor: pointer;
}

/* ---------- 主区域 ---------- */
.app-main {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
}
@media (min-width: 768px) {
  .app-main {
    flex-direction: row;
    padding: 14px 18px 16px;
    gap: 14px;
    position: relative;
  }
  /* 行号槽的上内边距必须与编辑器文本层一致，否则行号会整体偏移 */
  .gutter { padding: 20px 9px 70px 0; }
}

/* ==========================================================================
   文档列表侧栏
   移动端：从左滑出的抽屉，叠加在编辑器之上
   桌面端：常驻的左列，可收起
   ========================================================================== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 85;
  width: min(88vw, 320px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform .26s var(--ease), visibility .26s var(--ease);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body.sidebar-visible .sidebar { transform: none; visibility: visible; }

.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 84;
  background: rgba(8, 9, 14, .5);
  backdrop-filter: blur(2px);
  animation: fade .18s var(--ease);
}
.sidebar-backdrop[hidden] { display: none; }

.sidebar__head {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 10px 11px 16px;
  border-bottom: 1px solid var(--line);
}
.sidebar__title {
  font-size: 11px; font-weight: 800; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-3);
}
.sidebar__close { display: grid; }

.sidebar__search {
  flex: none;
  position: relative;
  display: flex; align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.sidebar__search-icon {
  position: absolute; left: 24px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); pointer-events: none;
}
.sidebar__search-input {
  flex: 1 1 auto; min-width: 0; width: 100%;
  padding: 7px 28px 7px 30px;
  border: 1px solid var(--line-2); border-radius: 9px;
  background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 13px;
  outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.sidebar__search-input:focus {
  border-color: var(--brand-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-1) 18%, transparent);
}
.sidebar__search-input::placeholder { color: var(--ink-3); }
.sidebar__search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.sidebar__search-clear {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; display: grid; place-items: center;
  border: none; border-radius: 50%; background: transparent; color: var(--ink-3);
  cursor: pointer;
}
.sidebar__search-clear:hover { background: color-mix(in srgb, var(--ink) 12%, transparent); color: var(--ink); }

.sidebar__foot {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px; font-weight: 650; color: var(--ink-3);
}

.tabs {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: stretch;
  gap: 2px; padding: 8px;
  background: none; border: none;
  overflow-x: hidden; overflow-y: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { width: 8px; }
.tabs::-webkit-scrollbar-thumb {
  background: var(--line-2); border-radius: 4px;
  border: 2px solid var(--surface); background-clip: padding-box;
}

.tab {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "name close"
    "meta meta";
  align-items: center;
  column-gap: 6px; row-gap: 2px;
  width: 100%; max-width: none;
  padding: 8px 6px 8px 12px;
  border: 1px solid transparent; border-radius: 10px;
  background: var(--surface); color: var(--ink-2);
  /* 移动端长按改名时不弹出系统的选择/共享菜单 */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  font-size: 13px; font-weight: 650; cursor: pointer;
  text-align: left;
  transition: background .15s var(--ease), color .15s var(--ease),
    border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab[aria-selected="true"] {
  background: var(--grad-soft); color: var(--ink); border-color: var(--line-2);
}
.tab__name {
  grid-area: name; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tab__meta {
  grid-area: meta;
  font-size: 11px; font-weight: 650; letter-spacing: .01em;
  color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tab[aria-selected="true"] .tab__meta { color: color-mix(in srgb, var(--brand-1) 55%, var(--ink-3)); }

/* 搜索命中后的正文片段 + 高亮 */
.tab.is-searching { grid-template-areas: "name close" "snippet snippet"; }
.tab__snippet {
  grid-area: snippet;
  margin-top: 2px;
  font-size: 11.5px; font-weight: 550; line-height: 1.35;
  color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: none;
}
.tab.is-searching .tab__snippet { display: block; }
.tab.is-searching .tab__meta { display: none; }
.tab__snippet mark, mark {
  background: color-mix(in srgb, var(--brand-1) 34%, transparent);
  color: var(--ink); border-radius: 3px; padding: 0 1px;
}

.tab__close {
  grid-area: close;
  width: 20px; height: 20px; border: none; border-radius: 50%; flex: none;
  background: transparent; color: var(--ink-3); cursor: pointer;
  display: grid; place-items: center; font-size: 15px; line-height: 1;
}
.tab__close:hover { background: color-mix(in srgb, var(--ink) 12%, transparent); color: var(--ink); }

/* 条目内联改名 */
.tab.tab--editing {
  background: var(--surface-2); border-color: var(--brand-1);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand-1) 22%, transparent);
}
.tab__input {
  grid-area: name;
  width: auto; min-width: 0;
  border: none; border-bottom: 1.5px solid var(--brand-1);
  border-radius: 0; background: transparent; color: var(--ink);
  font: inherit; padding: 0 0 2px; margin: 0;
  outline: none;
  /* 改名的输入框本身要能选字 / 编辑 */
  -webkit-user-select: text; user-select: text; -webkit-touch-callout: default;
}
.tab__input::selection { background: color-mix(in srgb, var(--brand-1) 30%, transparent); }
/* 避免 iOS 聚焦输入框时自动放大页面 */
@media (max-width: 720px) { .tab__input { font-size: 16px; } }

/* 头部文件名内联改名 */
.doc-title__input {
  flex: 1 1 auto; min-width: 0; width: 100%;
  border: none; border-bottom: 1.5px solid var(--brand-1);
  border-radius: 0; background: transparent; color: var(--ink);
  font: inherit; padding: 0 0 2px; margin: 0; outline: none;
  /* 改名的输入框本身要能选字 / 编辑 */
  -webkit-user-select: text; user-select: text; -webkit-touch-callout: default;
}
.doc-title__input::selection { background: color-mix(in srgb, var(--brand-1) 30%, transparent); }
/* 编辑态下放宽裁切，避免下边框被 .app-header__title span 的 overflow:hidden 切掉 */
#docTitle.editing { overflow: visible; }
/* 避免 iOS 聚焦输入框时自动放大页面 */
@media (max-width: 720px) { .doc-title__input { font-size: 16px; } }

.tab-add {
  flex: none; width: 100%; height: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 10px;
  border: 1px dashed var(--line-2);
  background: transparent; color: var(--ink-2);
  font-size: 13px; font-weight: 650; cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.tab-add:hover { background: var(--surface-2); color: var(--ink); border-style: solid; }
/* 新建按钮位于搜索框上方、作为侧栏直接子元素时，补上独立边距 */
.sidebar > .tab-add { margin: 9px 12px; width: auto; }
.tab-add__icon { font-size: 17px; line-height: 1; }
.tab-add__label { display: inline; }

/* ---------- 桌面端：抽屉变回常驻左列 ---------- */
@media (min-width: 768px) {
  .sidebar {
    position: static; z-index: auto;
    transform: none; visibility: visible;
    width: auto; flex: 0 0 246px; min-width: 0; min-height: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    overflow: hidden;
    transition: none;
    padding: 0;
  }
  /* 桌面端用 display 切换，收起后编辑器占满整行 */
  body:not(.sidebar-visible) .sidebar { display: none; }

  /* 抽屉专用的遮罩与关闭按钮在桌面端没有意义 */
  .sidebar-backdrop { display: none !important; }
  .sidebar__close { display: none; }
  .sidebar__head { padding: 12px 12px 10px 16px; }
}

/* ---------- 编辑区 ---------- */
.editor-wrap {
  position: relative;
  flex: 1 1 auto; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
  /* 输入层、高亮层与行号槽必须共用同一套排版参数，否则会错位 */
  --ed-font: var(--mono);
  --ed-size: 14px;
  --ed-lh: 1.65;
}
/* gutter 与正文并排，保证行号与正文首行对齐 */
.editor__row { flex: 1 1 auto; min-height: 0; min-width: 0; display: flex; }

/* ---------- 标题行（仅桌面端，作为编辑区第一行） ---------- */
.editor__title { display: none; }
@media (min-width: 768px) {
  .editor__title {
    display: block; flex: none;
    padding: 18px 22px 2px;
  }
  .editor__title-input {
    width: 100%; margin: 0; padding: 0;
    border: none; background: transparent; color: var(--ink);
    font-family: var(--ed-font);
    font-size: 22px; font-weight: 800; line-height: 1.35;
    outline: none; caret-color: var(--brand-1);
  }
  .editor__title-input::placeholder { color: var(--ink-3); }
}
@media (min-width: 768px) {
  .editor-wrap {
    border-radius: var(--radius);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-1);
    overflow: hidden;
  }
}

/* ---------- 右侧广告区 ---------- */
.ad-zone { display: none; }
.ad-toggle { display: none; }
@media (min-width: 768px) {
  .ad-zone {
    flex: 0 0 var(--ad-w, 300px);
    display: flex; flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    overflow: hidden; min-height: 0;
  }
  .ad-zone__body {
    flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
    padding: 12px; gap: 10px;
  }
  .ad-zone__label { display: none; }
  .ad-zone__slot {
    flex: 1 1 auto; min-height: 0; display: grid; place-items: center;
    border: 1px dashed var(--line-2); border-radius: 10px;
    color: var(--ink-3); background: color-mix(in srgb, var(--ink) 3%, transparent);
    font-size: 12px; text-align: center; padding: 12px; word-break: break-word;
  }
  .ad-toggle {
    position: absolute; top: 50%; transform: translateY(-50%);
    inset-inline-end: calc(var(--ad-w, 300px) + 14px);
    z-index: 6; width: 22px; height: 64px;
    display: grid; place-items: center;
    border: 1px solid var(--line); border-radius: 8px;
    background: var(--surface); color: var(--ink-3); cursor: pointer;
    box-shadow: var(--shadow-1);
    transition: inset-inline-end .2s var(--ease), background .15s, color .15s;
  }
  .ad-toggle:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink); }
  .ad-toggle svg { transition: transform .2s var(--ease); }
  body.ad-hidden .ad-zone { display: none; }
  body.ad-hidden .ad-toggle { inset-inline-end: 0; }
  body.ad-hidden .ad-toggle svg { transform: rotate(180deg); }
  body.zen .ad-toggle { display: none; }
  body.zen .sidebar { display: none; }
  body.zen .ad-zone { display: none; }
}

.gutter {
  flex: none; width: 52px; overflow: hidden;
  padding: 16px 9px 60px 0;
  text-align: right;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  font-family: var(--ed-font);
  font-size: var(--ed-size);
  line-height: var(--ed-lh);
  color: var(--ink-3);
  user-select: none;
}
.gutter__inner { will-change: transform; }
.gutter__line--active { color: var(--ink); font-weight: 700; }

.editor { flex: 1 1 auto; min-width: 0; position: relative; }

/* 输入层与高亮层共用的排版 */
.editor__text {
  box-sizing: border-box;
  margin: 0;
  padding: 16px 16px 60px;
  font-family: var(--ed-font);
  font-size: var(--ed-size);
  line-height: var(--ed-lh);
  tab-size: 4;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
  border: none;
}
@media (min-width: 768px) { .editor__text { padding: 20px 22px 70px; } }

.editor__highlight {
  position: absolute; inset: 0; z-index: 0;
  overflow: hidden;
  color: transparent;
  background: transparent;
  pointer-events: none;
  user-select: none;
}
.editor__highlight mark {
  background: color-mix(in srgb, var(--brand-1) 22%, transparent);
  color: transparent;
  border-radius: 3px;
}
.editor__highlight mark.is-current {
  background: color-mix(in srgb, var(--brand-1) 50%, transparent);
  box-shadow: 0 0 0 1px var(--brand-1) inset;
}

.editor__area {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  background: transparent;
  color: var(--ink);
  outline: none; resize: none;
  caret-color: var(--brand-1);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.editor__area::placeholder { color: var(--ink-3); }

.editor--wrap .editor__text {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.editor--bold .editor__text { font-weight: 700; }
.editor--italic .editor__text { font-style: italic; }
.editor--underline .editor__text { text-decoration: underline; }

body.hide-gutter .gutter { display: none; }

/* ---------- 状态栏 ---------- */
.statusbar {
  flex: none;
  display: flex; align-items: center; gap: 13px;
  min-height: 34px; padding: 4px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  font-size: 12px; font-weight: 600; color: var(--ink-3);
  overflow-x: auto; white-space: nowrap;
  scrollbar-width: none;
}
.statusbar::-webkit-scrollbar { display: none; }
.statusbar__item { display: inline-flex; align-items: center; gap: 5px; flex: none; }
.statusbar__item b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.statusbar__spacer { margin-left: auto; }
.statusbar__save { display: inline-flex; align-items: center; gap: 7px; }
.statusbar__save::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--brand-1); flex: none;
}
.statusbar__save[data-state="saving"]::before { background: #f59e0b; animation: pulse 1s infinite; }
.statusbar__save[data-state="saved"]::before { background: #22c55e; }
.statusbar__save[data-state="error"]::before { background: #ef4444; }
@keyframes pulse { 50% { opacity: .3; } }

/* 窄屏隐藏次要统计项 */
@media (max-width: 640px) {
  .statusbar__item[data-compact="hide"] { display: none; }
}

/* ---------- 弹出面板（桌面：气泡；移动：底部抽屉） ---------- */
.popover {
  position: fixed; z-index: 80;
  min-width: 260px; max-width: min(380px, calc(100vw - 24px));
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  animation: pop .16s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } }
.popover[hidden] { display: none; }
.popover__title {
  font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 11px;
}
.popover__row { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.popover__row:last-child { margin-bottom: 0; }
.popover__row > label:first-child {
  font-size: 13px; font-weight: 650; color: var(--ink-2); flex: none; width: 58px;
}
.popover__row .select { flex: 1 1 auto; min-width: 0; }
.popover__row .tb { flex: 1 1 auto; }
.popover__row .tb:not(.tb--grow) { flex: 0 1 auto; }

@media (max-width: 720px) {
  .popover {
    left: 0 !important; right: 0; top: auto !important; bottom: 0;
    width: 100%; max-width: none;
    max-height: 72dvh; overflow-y: auto;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    animation: sheetUp .24s var(--ease);
  }
  @keyframes sheetUp { from { transform: translateY(101%); } }
  .popover::before {
    content: ""; display: block; width: 40px; height: 4px; border-radius: 999px;
    background: var(--line-2); margin: -6px auto 14px;
  }
  .popover__row > label:first-child { width: 62px; }
}

/* ---------- 输入控件 ---------- */
.input {
  width: 100%; height: 36px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 10px;
  background: var(--bg); color: var(--ink); font-size: 14px;
  font-family: inherit;
}
.input:focus { outline: 2.5px solid var(--brand-1); outline-offset: -1px; border-color: transparent; }

/* ---------- 查找替换 ---------- */
.findbar {
  position: absolute; z-index: 70;
  top: 12px; right: 14px;
  width: min(430px, calc(100% - 28px));
  padding: 13px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  animation: pop .16s var(--ease);
}
.findbar[hidden] { display: none; }
@media (max-width: 720px) {
  .findbar {
    top: 10px; left: 10px; right: 10px; width: auto;
    padding: 12px;
    max-height: calc(100% - 20px); overflow-y: auto;
  }
}

.findbar__grid { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.findbar__field { position: relative; display: flex; align-items: center; }
.findbar__field .input { padding-right: 82px; }
.findbar__fieldactions {
  position: absolute; right: 3px; top: 3px; bottom: 3px;
  display: flex; align-items: center; gap: 2px;
}
.findbar__fieldactions .tb { height: 30px; min-width: 30px; width: 30px; padding: 0; }
.findbar__count {
  font-size: 12px; font-weight: 700; color: var(--ink-3);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.findbar__count[data-state="none"] { color: #e11d48; }
.findbar__opts {
  display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap;
  margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--line);
}
.findbar__opts label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.findbar__opts input[type="checkbox"] { accent-color: var(--brand-1); width: 15px; height: 15px; }
.findbar__row2 { display: flex; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
.findbar__row2 .input { flex: 1 1 140px; min-width: 0; }

/* ---------- Emoji / 字符映射网格 ---------- */
.charmap {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 5px;
  max-height: 42dvh; overflow-y: auto; padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 720px) { .charmap { max-height: 240px; } }
.charmap button {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: 9px;
  background: var(--surface-2); color: var(--ink);
  font-size: 17px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
  padding: 0;
}
.charmap button:hover { background: var(--grad-soft); border-color: var(--line-2); }

.emoji-tabs { display: flex; gap: 6px; margin-bottom: 11px; flex-wrap: wrap; }
.emoji-tabs button {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 5px 12px;
  font-size: 12.5px; font-weight: 650; cursor: pointer;
}
.emoji-tabs button[aria-pressed="true"] {
  background: var(--grad-soft); color: var(--brand-1); border-color: var(--line-2);
}

/* ---------- 模态框 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 95;
  display: grid; place-items: end center;
  background: rgba(8, 9, 14, .5);
  backdrop-filter: blur(3px);
  padding: 0;
  animation: fade .16s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.modal[hidden] { display: none; }
.modal__panel {
  width: 100%; max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  animation: sheetUp .24s var(--ease);
}
@media (min-width: 720px) {
  .modal { place-items: center; padding: 24px; }
  .modal__panel {
    width: min(620px, 100%); max-height: min(80dvh, 700px);
    border-radius: var(--radius);
    animation: pop .18s var(--ease);
  }
}
.modal__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal__head h2 { font-size: 16px; margin: 0; }
.modal__body {
  padding: 16px 18px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.modal__body h3 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--ink-3); margin: 22px 0 8px; font-weight: 800;
}
.modal__body h3:first-child { margin-top: 0; }
.modal__body table { width: 100%; border-collapse: collapse; font-size: 14px; }
.modal__body td {
  padding: 8px 0; border-bottom: 1px solid var(--line);
  color: var(--ink-2); vertical-align: top;
}
.modal__body td:first-child { width: 46%; color: var(--ink); font-weight: 600; }
.modal__body td:last-child { text-align: right; }
.modal__body kbd {
  font-family: var(--mono); font-size: 12px; padding: 3px 8px; border-radius: 7px;
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-bottom-width: 2px; color: var(--ink); white-space: nowrap;
}
.modal__body p strong { color: var(--ink); }

/* ---------- 打印输出 ---------- */
.print-only { display: none; }
@media print {
  body.app { height: auto; display: block; overflow: visible; background: #fff; }
  body::before { display: none; }
  .app-header, .toolbar, .sidebar, .tabs, .statusbar, .gutter, .findbar, .popover, .modal { display: none !important; }
  .app-main { padding: 0; }
  .editor-wrap { display: block; border: none; box-shadow: none; overflow: visible; }
  .editor { display: none; }
  .print-only {
    display: block;
    font-family: var(--mono); font-size: 11.5pt; line-height: 1.55;
    white-space: pre-wrap; word-wrap: break-word; color: #000;
  }
}

/* 窄屏使用更短的标签，工具栏靠换行完整显示，不需要横向滚动 */
.tb__label--short { display: none; }
@media (max-width: 620px) {
  .tb__label:not(.tb__label--short) { display: none; }
  .tb__label--short { display: inline; }
  .tb { padding: 0 8px; font-size: 13px; }
  .toolbar__scroll { gap: 2px; }
}

/* ---------- 移动端：工具栏收纳（参考 onlinenotepad.org 的简洁顶栏） ----------
   默认只保留高频按钮（New / Open / Save / Undo / Redo / Find），
   低频按钮全部收进 ⋯ 底部抽屉，工具栏不再折行，编辑区最大化。 */
.only-mobile { display: none; }

@media (max-width: 767px) {
  /* 单行横向滚动，不再换行占据高度 */
  .toolbar,
  .toolbar__scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar,
  .toolbar__scroll::-webkit-scrollbar { display: none; }

  /* 标记为低频的按钮与分隔线隐藏（可在 ⋯ 抽屉里使用） */
  .toolbar [data-mobile="hide"] { display: none; }

  /* 右侧清空按钮同样收进抽屉 */
  .toolbar__right { display: none; }

  /* ⋯ 按钮只在移动端出现 */
  #btnMore { display: inline-flex; flex: none; }

  /* 抽屉里的菜单项始终显示文字标签（覆盖 620px 的图标化规则） */
  #morePop .tb__label { display: inline; }
  #morePop .popover__row .tb { flex: 0 1 auto; }
}

