/* “词典”栏目的版式。所有类名都以 dx- 开头，不影响网站其他部分。颜色取自 theme.css，深色模式随网站切换。 */
#v-dict {
  --latin: "Source Serif 4", var(--f-lat);
  --d0: #27457f; --d1: #9B2B20; --d2: #4F6B3A; --d3: #8A6420; --d4: #5E4B7D;
  /* 占满页头以下的整个窗口；--head-h 由 js/pages/dict.js 按页头实际高度设定 */
  height: calc(100vh - var(--head-h, 56px));
  height: calc(100dvh - var(--head-h, 56px));
  width: 100%; min-height: 0;
  font-family: var(--f-zh); font-size: 16px; line-height: 1.75;
}
body.in-dict .site-foot { display: none; }
.dx-panel {
  height: 100%; display: grid; grid-template-rows: auto 1fr; min-height: 0;
  /* 与各栏目版心（.wrap）同宽 */
  max-width: 92rem; margin: 0 auto;
  padding: 14px max(16px, env(safe-area-inset-right, 0px)) 16px max(16px, env(safe-area-inset-left, 0px));
}

/* ---------- 词典顶栏 ---------- */
.dx-head {
  border: 1px solid var(--rule); border-radius: 6px 6px 0 0; background: var(--sheet);
  padding: 12px 18px 10px;
  display: grid; grid-template-columns: auto 1fr; column-gap: 24px; row-gap: 8px; align-items: center;
}
.dx-search { grid-column: 2; grid-row: 1; display: flex; gap: 10px; align-items: stretch; min-width: 0; }
.dx-qwrap { flex: 1; min-width: 0; position: relative; display: flex; }
.dx-q {
  flex: 1; min-width: 0; padding-right: 42px !important; font-family: var(--latin); font-size: 22px; letter-spacing: .01em;
  padding: 5px 14px; color: var(--ink); background: var(--sheet);
  border: 1px solid var(--rule); border-bottom: 2px solid var(--lapis); border-radius: 2px; outline: none;
}
.dx-q:focus { border-bottom-color: var(--seal); }
.dx-q::placeholder { color: var(--ink-soft); opacity: .7; font-family: var(--f-zh); font-size: 16px; }
.dx-mode { font: inherit; font-size: 15px; padding: 0 10px; background: var(--sheet); border: 1px solid var(--rule); border-radius: 2px; color: var(--ink); }
.dx-filters {
  grid-column: 2; grid-row: 2; display: flex; flex-wrap: wrap; gap: 6px 24px; align-items: center;
  font-size: 14px; color: var(--ink-soft); font-family: var(--f-ui);
}
.dx-grp { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.dx-segbtn { font: inherit; font-size: 13px; padding: 1px 12px; cursor: pointer; border-radius: 2px; background: transparent; color: var(--ink-soft); border: 1px solid var(--rule); }
.dx-segbtn[aria-pressed="true"] { background: var(--lapis); border-color: var(--lapis); color: var(--sheet); }
.dx-segbtn + .dx-segbtn { margin-left: -10px; }
.dx-toggle, .dx-one { display: inline-flex; align-items: center; gap: 7px; user-select: none; }
.dx-toggle { cursor: pointer; }
.dx-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.dx-toggle .dx-seal { opacity: .3; }
.dx-toggle input:checked + .dx-seal { opacity: 1; }
.dx-toggle input:checked ~ .dx-name, .dx-one .dx-name { color: var(--ink); }
.dx-toggle input:focus-visible + .dx-seal { outline: 2px solid var(--seal); outline-offset: 2px; }
.dx-n { font-variant-numeric: tabular-nums; font-size: 12px; }
.dx-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-soft); cursor: pointer;
}
.dx-clear:hover { background: var(--paper); color: var(--ink); }
.dx-clear[hidden] { display: none; }
.dx-tools { margin-left: auto; order: 1; display: inline-flex; gap: 16px; white-space: nowrap; }
.dx-legend-btn, .dx-spine-btn { background: none; border: 0; padding: 0; font: inherit; font-size: 14px; color: var(--lapis); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.dx-legend { grid-column: 2; font-size: 14px; color: var(--ink); background: var(--paper); border: 1px solid var(--rule); padding: 10px 14px; display: none; }
.dx-legend.open { display: block; }
.dx-legend h3 { margin: 0 0 4px; font-size: 14px; }
.dx-legend dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 2px 16px; margin: 0 0 6px; }
.dx-legend dt { display: inline; font-family: var(--latin); font-size: 16px; }
.dx-legend dd { display: inline; margin: 0 0 0 6px; color: var(--ink-soft); }
.dx-legend p { margin: 6px 0 0; color: var(--ink-soft); }

.dx-seal { display: inline-grid; place-items: center; width: 22px; height: 22px; font-size: 13px; line-height: 1; font-weight: 600; color: #fff; border-radius: 2px; flex: none; font-family: var(--f-zh); }
.dx-seal.d0 { background: var(--d0); } .dx-seal.d1 { background: var(--d1); }
.dx-seal.d2 { background: var(--d2); } .dx-seal.d3 { background: var(--d3); }
.dx-seal.d4 { background: var(--d4); }

/* ---------- 左栏与结果 ---------- */
.dx-main {
  display: grid; grid-template-columns: minmax(150px, 200px) 1fr; min-height: 0;
  border: 1px solid var(--rule); border-top: 0; border-radius: 0 0 6px 6px; overflow: hidden;
}
.dx-main.two { grid-template-columns: minmax(230px, 290px) 1fr; }
.dx-spine { background: var(--scroll); color: var(--scroll-ink); display: flex; min-height: 0; overflow: hidden; }
.dx-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.dx-pane + .dx-pane { border-left: 1px solid var(--scroll-rule); }
.dx-lbl { padding: 12px 16px 0; font-size: 12px; color: var(--scroll-soft); letter-spacing: .2em; }
.dx-script { flex: 1; min-height: 0; padding: 18px 16px; overflow-x: auto; overflow-y: hidden; display: flex; justify-content: center; }
.dx-v { writing-mode: vertical-lr; font-family: var(--f-mong); font-size: 50px; line-height: 1.3; max-height: 100%; }
.dx-main.two .dx-v { font-size: 40px; }
.dx-empty { writing-mode: vertical-lr; font-size: 14px; letter-spacing: .3em; color: var(--scroll-soft); }
.dx-foot { border-top: 1px solid var(--scroll-rule); padding: 10px 16px 14px; font-size: 13px; color: var(--scroll-soft); }
.dx-tl { font-family: var(--latin); }
.dx-foot .dx-tl { font-size: 16px; color: var(--scroll-ink); word-break: break-word; line-height: 1.3; }
.dx-from { font-size: 12px; margin-top: 2px; }
.dx-copy { margin-top: 8px; background: none; border: 1px solid var(--scroll-rule); color: var(--scroll-ink); font: inherit; font-size: 12px; padding: 2px 10px; border-radius: 2px; cursor: pointer; }
.dx-copy:hover { border-color: var(--scroll-ink); }

.dx-results { overflow-y: auto; min-height: 0; padding: 0 0 60px; }
.dx-status { position: sticky; top: 0; z-index: 2; background: var(--paper); padding: 10px 26px 8px; font-size: 14px; color: var(--ink-soft); border-bottom: 1px solid var(--rule); }
.dx-status b { color: var(--ink); font-weight: 600; }
.dx-ms { opacity: .6; }
.dx-list { padding: 0 26px; }

.dx-entry { display: grid; grid-template-columns: 52px 1fr; column-gap: 18px; padding: 20px 0 18px 12px; margin-left: -15px; border-bottom: 1px solid var(--rule); border-left: 3px solid transparent; }
.dx-entry.sel { border-left-color: var(--seal); }
.dx-col { font-family: var(--f-mong); writing-mode: vertical-lr; font-size: 26px; line-height: 1.3; color: var(--lapis); max-height: 230px; justify-self: center; overflow: hidden; }
.dx-body { min-width: 0; }
.dx-headline { display: flex; align-items: baseline; gap: 6px 16px; flex-wrap: wrap; margin-bottom: 6px; }
.dx-headline .dx-tl { font-size: 24px; line-height: 1.25; letter-spacing: .01em; color: var(--ink); cursor: pointer; background: none; border: 0; padding: 0; text-align: left; }
.dx-headline .dx-tl:hover { color: var(--seal); }
.dx-aux { font-size: 14px; color: var(--ink-soft); }
.dx-cyr { font-family: var(--latin); font-size: 16px; color: var(--ink); }
.dx-ipa { font-family: var(--latin); }
.dx-sense { display: grid; grid-template-columns: 22px 1fr; column-gap: 12px; padding: 7px 0; }
.dx-sense + .dx-sense { border-top: 1px dashed var(--rule); }
.dx-sense .dx-seal { margin-top: 4px; }
.dx-wait { color: var(--ink-soft); font-size: 14px; }
.dx-src { font-size: 12px; color: var(--ink-soft); margin-right: 8px; white-space: nowrap; }
.dx-src i { font-family: var(--latin); font-style: normal; }
.dx-alt { font-family: var(--latin); font-size: 15px; color: var(--ink-soft); margin-right: 8px; }
/* 清文鉴的释义（满文、日文或汉文）另起一行 */
.dx-ex { display: block; margin-top: 2px; }
.dx-eq { display: block; margin-top: 2px; font-size: 14px; color: var(--ink-soft); }
.dx-k { margin-right: 6px; }
.dx-w { font-family: var(--latin); font-size: 15.5px; cursor: pointer; }
.dx-eq .dx-w { font-size: 16px; color: var(--ink); }
.dx-w:hover { color: var(--seal); text-decoration: underline; text-underline-offset: 3px; }
.dx-mn { font-family: var(--f-mong); font-size: 17px; cursor: pointer; }
.dx-mn.plain { cursor: auto; }
.dx-mn:not(.plain):hover { color: var(--seal); }
#v-dict mark { background: color-mix(in srgb, var(--seal) 18%, transparent); color: inherit; padding: 0 1px; }

/* 翻页 */
.dx-status { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
.dx-pg-mini { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dx-pg-mini button {
  width: 28px; height: 26px; padding: 0; font: inherit; font-size: 17px; line-height: 1; cursor: pointer;
  background: var(--sheet); color: var(--lapis); border: 1px solid var(--rule); border-radius: 2px;
}
.dx-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin: 26px 0 4px; font-variant-numeric: tabular-nums; }
.dx-pager button {
  min-width: 36px; height: 34px; padding: 0 10px; font: inherit; font-size: 14px; cursor: pointer;
  background: var(--sheet); color: var(--lapis); border: 1px solid var(--rule); border-radius: 2px;
}
.dx-pager button:hover:not([disabled]), .dx-pg-mini button:hover:not([disabled]) { border-color: var(--lapis); }
.dx-pager button[aria-current="page"] { background: var(--lapis); border-color: var(--lapis); color: var(--sheet); cursor: default; }
.dx-pager button[disabled], .dx-pg-mini button[disabled] { opacity: .35; cursor: default; }
.dx-gap { color: var(--ink-soft); padding: 0 2px; }
@media (max-width: 760px) {
  .dx-pager { gap: 4px; }
  .dx-pager button { min-width: 32px; height: 32px; padding: 0 8px; }
}
.dx-note { padding: 36px 0; color: var(--ink-soft); max-width: 36em; }
.dx-note h2 { font-size: 18px; color: var(--ink); margin: 0 0 8px; font-weight: 600; }
.dx-note p { margin: 0 0 10px; }
.dx-eg { font-family: var(--latin); font-size: 17px; color: var(--lapis); cursor: pointer; margin-right: 14px; }
.dx-eg.zh { font-family: var(--f-zh); }
.dx-eg:hover { color: var(--seal); }
#v-dict :focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }

@media (max-width: 760px) {
  #v-dict { font-size: 15px; }
  .dx-panel { padding: 0; }
  .dx-head { grid-template-columns: 1fr auto; padding: 8px 12px; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0; }
  .dx-main { border: 0; border-radius: 0; }
  .dx-filters { min-width: 0; }
  .dx-tools { flex-wrap: wrap; }
  .dx-search { grid-column: 1 / -1; grid-row: 2; }
  .dx-filters, .dx-legend { grid-column: 1 / -1; grid-row: auto; }
  .dx-q { font-size: 19px; }
  /* 手机上原文栏压成一行：原文横排，右边一个复制按钮，把屏幕留给查询结果 */
  .dx-main, .dx-main.two { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .dx-pane { flex-direction: row; align-items: center; min-width: 0; }
  .dx-lbl { display: none; }
  .dx-script { padding: 6px 12px; justify-content: flex-start; align-items: center; overflow-x: auto; scrollbar-width: none; }
  .dx-script::-webkit-scrollbar { display: none; }
  .dx-v, .dx-main.two .dx-v, .dx-empty { writing-mode: horizontal-tb; white-space: nowrap; max-height: none; }
  .dx-v, .dx-main.two .dx-v { font-size: 24px; line-height: 40px; }
  .dx-empty { font-size: 13px; letter-spacing: .1em; line-height: 40px; }
  .dx-foot { flex: none; border-top: 0; padding: 0 12px 0 0; }
  .dx-foot .dx-tl, .dx-from { display: none; }
  .dx-copy { margin-top: 0; }
  .dx-main.two .dx-copy { display: none; }
  .dx-status { padding: 8px 14px; }
  .dx-list { padding: 0 14px 0 17px; }
  .dx-entry { grid-template-columns: 34px 1fr; column-gap: 12px; }
  .dx-col { font-size: 20px; max-height: 160px; }
  .dx-headline .dx-tl { font-size: 21px; }
}
/* 收起左栏：结果占满宽度 */
.dx-nospine .dx-spine { display: none; }
.dx-nospine .dx-main, .dx-nospine .dx-main.two { grid-template-columns: 1fr; }
@media (max-width: 760px) {
  .dx-nospine .dx-main, .dx-nospine .dx-main.two { grid-template-rows: 1fr; }
  /* 手机上顶栏尽量紧凑：词条数不显示 */
  .dx-n { display: none; }
  .dx-filters { gap: 4px 16px; }
  .dx-grp { gap: 4px 10px; }
}
.dx-results { overscroll-behavior: contain; }
/* 输入框获得焦点时已有朱红底线，不再加外框 */
#v-dict .dx-q:focus-visible { outline: none; }
/* 有两组选项时（满汉蒙）：“转写规则”跟在第一组后面，第二组另起一行 */
.dx-grp + .dx-grp { order: 2; width: 100%; }

/* ---------- 藏文词典 ---------- */
.dx-entry.nocol { grid-template-columns: 1fr; padding-left: 16px; }
.dx-bo { font-family: var(--f-bo); font-size: 26px; line-height: 1.6; color: var(--lapis); }
.dx-headline .dx-bo + .dx-tl { font-size: 18px; color: var(--ink-soft); }
.dx-bo-in { font-family: var(--f-bo); font-size: 1.15em; line-height: 1.6; cursor: pointer; }
.dx-bo-in.plain { cursor: auto; }
.dx-bo-in:not(.plain):hover { color: var(--seal); }
.dx-v.h { writing-mode: horizontal-tb; font-family: var(--f-bo); font-size: 34px; line-height: 1.7; max-height: none; overflow-wrap: anywhere; }
/* 词典很多时的来源面板 */
.dx-pick { font: inherit; font-size: 13px; padding: 1px 12px; cursor: pointer; border-radius: 2px; background: var(--sheet); color: var(--lapis); border: 1px solid var(--rule); }
.dx-pick[aria-expanded="true"] { border-color: var(--lapis); }
.dx-dictpanel { grid-column: 1 / -1; max-height: 46vh; overflow-y: auto; border: 1px solid var(--rule); background: var(--paper); padding: 10px 14px; font-family: var(--f-ui); }
.dx-dictpanel[hidden] { display: none; }
.dx-pgroup + .dx-pgroup { margin-top: 10px; }
.dx-pgroup h4 { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.dx-pgroup h4 button { font: inherit; font-size: 12px; font-weight: 400; background: none; border: 0; padding: 0; color: var(--lapis); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.dx-pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 4px 18px; }
.dx-pgrid .dx-toggle { align-items: flex-start; font-size: 13px; color: var(--ink-soft); }
.dx-pgrid .dx-seal { margin-top: 1px; }
.dx-pgrid .dx-name { flex: 1; min-width: 0; color: var(--ink); line-height: 1.4; }
.dx-pgrid .dx-name small { display: block; color: var(--ink-soft); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dx-pgrid input:not(:checked) ~ .dx-name { color: var(--ink-soft); }
.dx-pnote { margin: 10px 0 0; font-size: 12px; color: var(--ink-soft); }
@media (max-width: 760px) {
  .dx-dictpanel { max-height: 50vh; }
  .dx-v.h { font-size: 26px; }
  .dx-bo { font-size: 22px; }
}
@media (max-width: 760px) {
}

/* ---------- 左上角的词典切换：按数据来源分行 ---------- */
.dx-left { grid-column: 1; grid-row: 1 / span 2; align-self: center; }
.dx-tabs { display: grid; grid-template-columns: auto auto; justify-content: start; align-items: center; gap: 6px 10px; font-family: var(--f-ui); }
.dx-tabrow { display: contents; }
.dx-tabsrc {
  justify-self: end; font-size: 12px; line-height: 1.4; white-space: nowrap; text-decoration: none;
  color: var(--ink-soft); padding: 1px 7px; border: 1px solid var(--rule); border-radius: 2px;
}
.dx-tabrow.cur .dx-tabsrc { color: var(--seal); border-color: var(--seal); font-weight: 600; }
a.dx-tabsrc:hover { border-color: var(--seal); }
.dx-tablist { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.dx-tablist a {
  font-size: .88rem; line-height: 1.3; padding: .28rem .7rem; border-radius: 4px;
  color: var(--ink); text-decoration: none; border: 1px solid var(--rule); background: var(--sheet); white-space: nowrap;
}
.dx-tablist a:hover { border-color: var(--lapis); }
.dx-tablist a[aria-current="page"] { background: var(--lapis); border-color: var(--lapis); color: var(--sheet); }
@media (max-width: 760px) {
  .dx-left { grid-column: 1 / -1; grid-row: 1; }
  .dx-tabs { width: 100%; grid-template-columns: auto 1fr; }
  .dx-tabsrc { justify-self: start; }
  .dx-tablist a { padding: .26rem .55rem; font-size: .85rem; }
  .dx-search { grid-row: 2; }
}

/* ---------- 手机：整页滚动，上方内容随滑动收放 ----------
   页头、词典顶栏、原文栏、结果数一行依次吸顶，四者一起上移 --hide 像素：
   往下滑时 --hide 一次设为前三者的总高，结果数一行移到最上；快速往上滑时 --hide 回到 0。
   加 dx-anim 时有动画，时长 --hide-ms 随滑动快慢而定。--hide 由 js/pages/dict.js 设定。
   --sh、--dh、--sp 分别是页头、词典顶栏、原文栏的高度，也由 dict.js 量出。 */
@media (max-width: 760px) {
  #v-dict { height: auto; }
  .dx-panel { height: auto; display: block; }
  .dx-main { display: block; overflow: visible; }
  .dx-results { overflow: visible; min-height: 0; padding-bottom: 48px; }
  .dx-head { position: sticky; top: var(--sh, 0px); z-index: 7; }
  .dx-spine { position: sticky; top: calc(var(--sh, 0px) + var(--dh, 0px)); z-index: 6; }
  .dx-status { top: calc(var(--sh, 0px) + var(--dh, 0px) + var(--sp, 0px)); z-index: 5; }
  body.in-dict .site-head, body.in-dict .dx-head, body.in-dict .dx-spine, body.in-dict .dx-status {
    transform: translateY(calc(-1 * var(--hide, 0px)));
  }
  body.in-dict.dx-anim .site-head, body.in-dict.dx-anim .dx-head, body.in-dict.dx-anim .dx-spine, body.in-dict.dx-anim .dx-status {
    transition: transform var(--hide-ms, 300ms) ease-out;
  }
}

/* 释义一栏不许撑宽页面：长书名可换行，过长的词（梵文长词、成串的藏文）在必要时断开。
   否则手机上整页会被撑宽，可以缩小到屏幕以外（藏文词典里最常见） */
.dx-sense > div, .dx-body, .dx-headline { min-width: 0; }
.dx-sense > div { overflow-wrap: anywhere; }
.dx-src { white-space: normal; }

/* ---------- 藏文词典：简称章、语种分段、长释义折叠 ---------- */
.dx-sense.tagged { grid-template-columns: 4.6em minmax(0, 1fr); }
.dx-tag {
  width: 100%; height: auto; min-height: 22px; padding: 2px 3px; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  font-family: var(--f-ui); line-height: 1.15; text-align: center; overflow-wrap: anywhere;
}
.dx-sense.tagged .dx-tag { align-self: start; margin-top: 3px; }
.dx-tag b { font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.dx-tag small { font-size: 10px; font-weight: 400; opacity: .9; }
.dx-pgrid .dx-tag { width: 4.6em; flex: none; cursor: auto; }
.dx-sgroup { margin: 12px 0 2px; font-family: var(--f-ui); font-size: 12px; color: var(--ink-soft); letter-spacing: .1em; }
.dx-sgroup span { margin-left: 6px; letter-spacing: 0; }
.dx-sgroup + .dx-sense { border-top: 0; }
.dx-fn { display: none; font-family: var(--f-ui); font-size: 12px; color: var(--ink-soft); }
.dx-sense.showfn .dx-fn { display: block; margin-bottom: 2px; }
.dx-defbox.folded { max-height: var(--fold-h, 8em); overflow: hidden; }
.dx-fold { background: none; border: 0; padding: 0; margin-top: 2px; font: inherit; font-family: var(--f-ui); font-size: 13px; color: var(--lapis); cursor: pointer; }
.dx-fold:hover { text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 760px) {
  .dx-sense.tagged { grid-template-columns: 4.2em minmax(0, 1fr); column-gap: 10px; }
}
