/* 元素图文 · 南山 · 共享主题层
   维度：style(paper|minimal) × mode(light|dark) × orient(h|v) */

:root {
  --font-body: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --font-title: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif SC", "Songti SC", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;

  --ink: #2a2620;
  --ink-soft: #6d6356;
  --ink-faint: #9a8f80;
  --surface: #f5ecd8;
  --surface-edge: #e6d8ba;
  --accent: #8c2b22;
  --ui-bg: #faf6ec;
  --ui-border: rgba(120, 100, 70, 0.18);
  --ui-hover: rgba(140, 110, 70, 0.09);
  --ui-active: #fbf2df;   /* 列表项悬停/选中：实色，深色下改深 */

  --fs-body: 17px;
  --lh-body: 1.95;
}

/* 极简 */
body[data-style="minimal"] {
  --surface: #ffffff;
  --surface-edge: #ececec;
  --ink: #1d1d1f;
  --ink-soft: #6e6e73;
  --ink-faint: #a1a1a6;
  --accent: #b03a2e;
  --ui-bg: #ffffff;
  --ui-border: rgba(0, 0, 0, 0.08);
  --ui-hover: rgba(0, 0, 0, 0.04);
  --ui-active: #f2f2f2;
}

/* 深色 */
body[data-mode="dark"] {
  --ink: #e7dfcd;
  --ink-soft: #a49b8a;
  --ink-faint: #7b7367;
  --surface: #1b1a17;
  --surface-edge: #2a2823;
  --accent: #c8705f;
  --ui-bg: #141413;
  --ui-border: rgba(255, 255, 255, 0.1);
  --ui-hover: rgba(255, 255, 255, 0.06);
  --ui-active: #2e2b25;
}
body[data-mode="dark"][data-style="minimal"] {
  --surface: #17171a;
  --surface-edge: #26262a;
  --ink: #e8e8ea;
  --ink-soft: #9a9aa0;
  --ui-active: #2b2b30;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--ui-bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

/* html 层拿不到 body 上的主题变量，单独给画布底色兜底 */
html[data-mode="light"] { background-color: #faf6ec; }
html[data-mode="light"][data-style="minimal"] { background-color: #ffffff; }
html[data-mode="dark"] { background-color: #141413; }
html[data-mode="dark"][data-style="minimal"] { background-color: #17171a; }

/* ---------- 卡片 ---------- */
.card {
  position: relative;   /* 暗角叠层（::after）靠它定位，压在纸面视野上不随列滚动 */
  display: flex;
  flex-direction: column;
  background: var(--ui-bg);
}

.paper {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 26px 24px 20px;
  background-color: var(--surface);
  overflow: hidden;
  isolation: isolate;
}

.paper > * { flex: 0 0 auto; }

/* 标题与作者默认各自成行（竖排、整页）；浮层横排改为同一行，见 popup.css */
.head { display: contents; }

/* 纸面纹理：靠 data-texture 切换
   默认「颗粒」是等向细噪声，像复印纸的纸粉；
   「纤维」把噪声在 x 方向压到极低频率、y 方向保持高频，颗粒被拉成横向细丝，
   再叠一层低频斑驳模拟纸浆厚薄 */
body[data-style="paper"] .paper::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='250' height='250' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 250px 250px;
  mix-blend-mode: multiply;
  opacity: 0.3;
}
body[data-style="paper"][data-texture="fiber"] .paper::before {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='s'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.005 0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='600' height='600' filter='url(%23s)' opacity='0.55'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.0375' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  background-size: 600px 600px, 240px 240px;
  opacity: 0.45;
}
/* 洒金笺：细颗粒上撒碎金，金点用 multiply 压进纸色里，不抢字 */
body[data-style="paper"][data-texture="gold"] .paper::before {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cg fill='%23b08a2e'%3E%3Ccircle cx='123.4' cy='77.1' r='1.15' opacity='0.82'/%3E%3Cellipse cx='184.0' cy='218.6' rx='2.51' ry='1.73' opacity='0.6' transform='rotate(147 184.0 218.6)'/%3E%3Cpolygon points='6.5,85.1 11.3,81.3 9.9,84.9' opacity='0.46'/%3E%3Ccircle cx='298.2' cy='309.9' r='2.37' opacity='0.58'/%3E%3Cellipse cx='85.3' cy='218.9' rx='2.58' ry='1.78' opacity='0.5' transform='rotate(150 85.3 218.9)'/%3E%3Cpolygon points='14.0,275.2 18.4,271.7 17.1,274.9' opacity='0.54'/%3E%3Ccircle cx='229.7' cy='231.6' r='1.09' opacity='0.72'/%3E%3Cellipse cx='44.1' cy='287.3' rx='2.8' ry='1.93' opacity='0.84' transform='rotate(13 44.1 287.3)'/%3E%3Cpolygon points='87.2,76.3 89.0,74.8 88.5,76.2' opacity='0.68'/%3E%3Ccircle cx='139.9' cy='251.4' r='0.99' opacity='0.61'/%3E%3Cellipse cx='38.9' cy='34.8' rx='1.35' ry='0.93' opacity='0.71' transform='rotate(101 38.9 34.8)'/%3E%3Cpolygon points='76.0,33.5 78.0,31.9 77.4,33.4' opacity='0.83'/%3E%3Ccircle cx='129.8' cy='170.0' r='1.32' opacity='0.46'/%3E%3Cellipse cx='10.4' cy='148.8' rx='1.68' ry='1.16' opacity='0.77' transform='rotate(10 10.4 148.8)'/%3E%3Cpolygon points='225.6,218.3 230.0,214.8 228.7,218.1' opacity='0.79'/%3E%3Ccircle cx='309.9' cy='223.2' r='2.24' opacity='0.62'/%3E%3Cellipse cx='224.6' cy='32.3' rx='2.45' ry='1.69' opacity='0.69' transform='rotate(25 224.6 32.3)'/%3E%3Cpolygon points='300.6,82.1 303.8,79.6 302.8,81.9' opacity='0.74'/%3E%3Ccircle cx='215.4' cy='132.5' r='1.58' opacity='0.84'/%3E%3Cellipse cx='91.0' cy='71.2' rx='2.8' ry='1.93' opacity='0.56' transform='rotate(83 91.0 71.2)'/%3E%3Cpolygon points='252.7,199.9 256.9,196.6 255.6,199.7' opacity='0.57'/%3E%3Ccircle cx='141.8' cy='30.8' r='1.73' opacity='0.54'/%3E%3Cellipse cx='75.5' cy='150.4' rx='1.83' ry='1.26' opacity='0.85' transform='rotate(140 75.5 150.4)'/%3E%3Cpolygon points='179.2,55.2 182.0,53.0 181.2,55.1' opacity='0.54'/%3E%3C/g%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='250' height='250' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 260px 260px, 250px 250px;
  opacity: 0.58;
}
/* 连史纸：极净的细颗粒 + 一缕极淡横向丝痕 + 零星杂质点 */
body[data-style="paper"][data-texture="lianshi"] .paper::before {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cellipse cx='175.9' cy='27.1' rx='2.85' ry='2.06' fill='%236b5a38' opacity='0.85' transform='rotate(135 175.9 27.1)'/%3E%3Cpolygon points='199.6,253.6 206.2,250.3 203.9,254.2' fill='%235f5030' opacity='0.84'/%3E%3Ccircle cx='110.7' cy='40.4' r='2.32' fill='%236b5a38' opacity='0.87'/%3E%3Cellipse cx='22.9' cy='76.7' rx='2.54' ry='1.71' fill='%238b7a55' opacity='0.81' transform='rotate(8 22.9 76.7)'/%3E%3Cellipse cx='207.4' cy='160.1' rx='3.16' ry='1.91' fill='%236b5a38' opacity='0.62' transform='rotate(17 207.4 160.1)'/%3E%3Cellipse cx='182.2' cy='60.7' rx='2.72' ry='1.65' fill='%236b5a38' opacity='0.76' transform='rotate(55 182.2 60.7)'/%3E%3Cellipse cx='189.4' cy='82.5' rx='2.04' ry='1.52' fill='%238b7a55' opacity='0.79' transform='rotate(52 189.4 82.5)'/%3E%3Ccircle cx='125.3' cy='57.7' r='2.06' fill='%235f5030' opacity='0.61'/%3E%3Ccircle cx='167.5' cy='71.2' r='1.53' fill='%237d6a45' opacity='0.73'/%3E%3Cellipse cx='11.4' cy='255.8' rx='1.73' ry='1.29' fill='%237d6a45' opacity='0.65' transform='rotate(6 11.4 255.8)'/%3E%3Ccircle cx='149.3' cy='141.0' r='1.61' fill='%237d6a45' opacity='0.66'/%3E%3Ccircle cx='135.2' cy='234.8' r='1.21' fill='%236b5a38' opacity='0.68'/%3E%3Ccircle cx='47.3' cy='116.5' r='1.29' fill='%238b7a55' opacity='0.63'/%3E%3Cellipse cx='211.0' cy='181.5' rx='3.3' ry='2.46' fill='%238b7a55' opacity='0.81' transform='rotate(153 211.0 181.5)'/%3E%3Cellipse cx='14.3' cy='218.2' rx='3.59' ry='2.14' fill='%238b7a55' opacity='0.66' transform='rotate(148 14.3 218.2)'/%3E%3Cpolygon points='130.1,13.2 137.5,9.5 134.9,14.0' fill='%238b7a55' opacity='0.73'/%3E%3Cpolygon points='209.8,95.6 215.2,92.9 213.3,96.2' fill='%238b7a55' opacity='0.79'/%3E%3Cellipse cx='218.2' cy='126.6' rx='1.93' ry='1.3' fill='%237d6a45' opacity='0.73' transform='rotate(22 218.2 126.6)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.42' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='250' height='250' filter='url(%23n)' opacity='0.62'/%3E%3C/svg%3E");
  background-size: 260px 260px, 250px 250px;
  opacity: 0.36;
}
/* 暗角挂在卡片上而不是纸面上：纸面是横向滚动容器，挂在纸上的叠层会跟着列一起滑走，
   滑到左边时暗角只剩右边一小块。卡片本身不滚，叠层就永远贴着当前视野 */
body[data-style="paper"][data-vignette="1"] .card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 52%, rgba(122, 98, 62, 0.05) 100%);
}
body[data-mode="dark"][data-style="paper"] .paper::before { opacity: 0.22; mix-blend-mode: screen; }
body[data-mode="dark"][data-style="paper"][data-texture="fiber"] .paper::before { opacity: 0.3; }
body[data-mode="dark"][data-style="paper"][data-texture="gold"] .paper::before { opacity: 0.38; }
body[data-mode="dark"][data-style="paper"][data-vignette="1"] .card::after { background: radial-gradient(ellipse at 50% 45%, transparent 46%, rgba(0, 0, 0, 0.2) 100%); }

/* 背景 */
body[data-bg]:not([data-bg="none"]) .paper {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* 自定义背景图：压在纯色/渐变背景之上 */
body[data-bg-image="1"][data-bg] .paper {
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
body[data-bg="warm"] .paper { background-image: linear-gradient(158deg, #fcf4e0 0%, #f1e1c2 55%, #e7d3ac 100%); }
body[data-bg="cool"] .paper { background-image: linear-gradient(158deg, #f0f3f2 0%, #e2e8e6 55%, #d4ddda 100%); }
body[data-bg="ink"] .paper { background-image: linear-gradient(158deg, #54554f 0%, #2d2e29 55%, #1c1d19 100%); --ink: #eee7d6; --ink-soft: #c3baa6; --ink-faint: #9d947f; }
body[data-bg="dusk"] .paper { background-image: linear-gradient(158deg, #82594b 0%, #523830 55%, #34231f 100%); --ink: #f7ecdb; --ink-soft: #d9c3ae; --ink-faint: #b39983; }

/* 深色模式下，暖黄 / 冷灰仍是浅底纸：纸面文字回到墨色，否则深色主题的浅字压在浅底上看不清 */
body[data-mode="dark"][data-bg="warm"] .paper,
body[data-mode="dark"][data-bg="cool"] .paper {
  --ink: #2a2620;
  --ink-soft: #5f5748;
  --ink-faint: #8b8271;
  --accent: #8c2b22;
}
/* 浅底纸上的宣纸噪点与暗角按浅色纸处理（深色纸才用提亮/加深的那一套） */
body[data-mode="dark"][data-bg="warm"] .paper::before,
body[data-mode="dark"][data-bg="cool"] .paper::before {
  mix-blend-mode: multiply;
  opacity: 0.3;
}
body[data-mode="dark"][data-bg="warm"][data-vignette="1"] .card::after,
body[data-mode="dark"][data-bg="cool"][data-vignette="1"] .card::after {
  background: radial-gradient(ellipse at 50% 45%, transparent 52%, rgba(122, 98, 62, 0.05) 100%);
}

/* ---------- 文字 ---------- */
.title {
  position: relative;
  margin: 0;
  font-family: var(--font-title);
  font-weight: 500;
  color: var(--ink);
  font-size: var(--fs-title-user, 1em);
  line-height: 1.35;
  letter-spacing: 0.06em;
  text-align: var(--align, center);
}

/* 悬停标题：沿阅读方向浮出所属诗库 —— 横排在标题右侧，竖排在标题同列的下方 */
.title[data-pool]::after {
  content: attr(data-pool);
  position: absolute;
  white-space: nowrap;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: .04em;
  text-align: center;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: 6px;
  padding-block: 3px;
  padding-inline: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .1);
  opacity: 0;
  pointer-events: none;
  /* 延迟一点点淡出，给鼠标从标题挪到标签的路上留出容错 */
  transition: opacity .15s ease .12s;
  z-index: 6;
}
/* 显示时允许指针停在标签上（否则一挪过去就消失），点击即复制来源 */
.title[data-pool]:hover::after { opacity: 1; pointer-events: auto; transition-delay: 0s; }

/* 位置用物理属性区分方向，避免逻辑属性在横排/竖排间算错 */
.card[data-orient="h"] .title[data-pool]::after {
  left: 100%;
  top: 50%;
  margin-left: 6px;
  transform: translateY(-50%);
}
.card[data-orient="v"] .title[data-pool]::after {
  top: 100%;
  left: 50%;
  margin-top: 6px;
  transform: translateX(-50%);
}

/* 标题与标签之间那段空隙（标签固定让开 34px）用一块透明区域连起来，鼠标才能一路移到标签上 */
.title[data-pool]:hover::before {
  content: '';
  position: absolute;
  z-index: 5;
}
.card[data-orient="h"] .title[data-pool]:hover::before { left: 100%; top: 0; bottom: 0; width: 62px; }
.card[data-orient="v"] .title[data-pool]:hover::before { top: 100%; left: 0; right: 0; height: 62px; }

/* 横排：标题盒子收成文字宽度，提示才能贴住这一行的末尾 */
.card[data-orient="h"] .title[data-pool] { width: fit-content; }
body[data-align="left"] .card[data-orient="h"] .title[data-pool] { margin-inline-end: auto; }
body[data-align="center"] .card[data-orient="h"] .title[data-pool] { margin-inline: auto; }
body[data-align="right"] .card[data-orient="h"] .title[data-pool] { margin-inline-start: auto; }

/* 标题悬停的搜索按钮：排在来源诗库标签前面，标签顺势让出位置 */
.title-search {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  writing-mode: horizontal-tb;
  border: 1px solid var(--surface-edge);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  /* 外圈同色衬底：按钮压在文字上时，把圆形之外的字也盖住 */
  box-shadow: 0 0 0 4px var(--surface), 0 2px 10px rgba(0, 0, 0, .12);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, color .15s ease, border-color .15s ease;
  z-index: 6;
}
.title-search.on { opacity: 1; pointer-events: auto; }
.title-search:hover { color: var(--accent); border-color: var(--accent); }
.title-search svg {
  width: 14px;
  height: 14px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}
.card[data-orient="h"] .title-search {
  left: 100%;
  top: 50%;
  margin-left: 34px;
  transform: translateY(-50%);
}
.card[data-orient="v"] .title-search {
  top: 100%;
  left: 50%;
  margin-top: 34px;
  transform: translateX(-50%);
}
/* 标签后移，不和搜索按钮叠在一起（覆盖上面 6px 的贴边距离） */
.card[data-orient="h"] .title[data-pool]::after { margin-left: 62px; }
.card[data-orient="v"] .title[data-pool]::after { margin-top: 62px; }
/* 快捷搜索关掉后没有按钮要避让，来源标签贴回标题旁边 */
body[data-quick-search="0"] .card[data-orient="h"] .title[data-pool]::after { margin-left: 6px; }
body[data-quick-search="0"] .card[data-orient="v"] .title[data-pool]::after { margin-top: 6px; }

/* 本地搜索贴着标题（6px），古诗文网排在它外侧（34px） */
.card[data-orient="h"] .title-search.alt { margin-left: 6px; }
.card[data-orient="v"] .title-search.alt { margin-top: 6px; }

/* 正文首句悬停浮出的搜索按钮：横排贴这句右侧，竖排贴这句下方 */
.line-search {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  writing-mode: horizontal-tb;
  border: 1px solid var(--surface-edge);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  /* 外圈同色衬底：按钮压在文字上时，把圆形之外的字也盖住 */
  box-shadow: 0 0 0 4px var(--surface), 0 2px 10px rgba(0, 0, 0, .12);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: scale(.92);
  transition: opacity .15s ease, transform .15s ease, color .15s ease, border-color .15s ease;
  z-index: 7;
}
.line-search.on { opacity: 1; pointer-events: auto; transform: scale(1); }
.line-search:hover { color: var(--accent); border-color: var(--accent); }
.line-search svg { width: 14px; height: 14px; display: block; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; }
/* 古诗文网搜索按钮用网站自己的图标 */
.line-search img, .title-search img { width: 14px; height: 14px; display: block; object-fit: contain; }

/* 关掉「快捷搜索」：连残留的悬浮/划词按钮一起藏起来。
   新渲染本就不会再创建，这条只兜住「关开关时还没来得及重绘」那一瞬 */
body[data-quick-search="0"] .title-search,
body[data-quick-search="0"] .line-search { display: none; }

.byline {
  margin-top: 10px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  text-align: var(--align, center);
}

.body {
  margin-top: 10px;
  font-family: var(--font-body);
  font-size: var(--fs-body-user, var(--fs-body));
  line-height: var(--lh-body);
  color: var(--ink);
  text-align: var(--align, center);
}

.body p {
  margin: 0;
  text-indent: 0;
}

/* 分句：内部不折行，句末才是换行点；能并排就并排 */
.body .clause {
  display: inline-block;
  white-space: nowrap;
}

.note {
  margin-top: 16px;
  padding-top: 12px;
  font-family: var(--font-body);
  font-size: 12.5px;
  line-height: 1.85;
  color: var(--ink-faint);
  text-align: left;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
.note.open {
  max-height: 260px;
  overflow-y: auto;
  border-top: 1px solid var(--ui-border);
}
/* 序：比注释更克制，且不占太多纵向空间 */
.note.preface {
  font-size: 12px;
  letter-spacing: 0.02em;
}
.note.preface.open {
  max-height: 150px;
  margin-top: 10px;
}

/* 竖排里赏析是横排块：展开时挂在"赏析"按钮下方，不占列宽、不撑宽纸张 */
.card[data-orient="v"] .note {
  writing-mode: horizontal-tb;
  position: fixed;
  top: var(--note-top, 64px);
  left: var(--note-left, 18px);
  right: auto;
  bottom: auto;
  z-index: 6;
  width: 0;
  max-width: min(26em, 46vw);
  max-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 34px -18px rgba(50, 40, 26, 0.55);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.card[data-orient="v"] .note.open {
  width: min(26em, 46vw);
  max-height: 42vh;
  padding: 12px 16px;
  border: 1px solid var(--ui-border);
  overflow-y: auto;
  opacity: 1;
}

/* 尺寸档位 */
.card[data-size="s"] { --paper-h: 250px; --fs-body: 17px; }
.card[data-size="m"] { --paper-h: 370px; --fs-body: 17px; }
.card[data-size="l"] { --paper-h: 460px; --fs-body: 16px; }

/* ---------- 竖排 ---------- */
.card[data-orient="v"] .paper {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  justify-content: flex-start;
  flex-direction: column;
  overflow-x: auto;
  overflow-y: hidden;
  height: var(--paper-h);
  padding: 22px 24px 22px;
}

/* 竖排水平对齐：竖排从右往左排，主轴起点在右侧，故靠右 = flex-start，靠左 = flex-end */
body[data-align="right"] .card[data-orient="v"] .paper { justify-content: flex-start; }
/* 居中用 safe：内容超出纸面时退回起点（右侧），避免标题列被居中挤出视野 */
body[data-align="center"] .card[data-orient="v"] .paper { justify-content: safe center; }
body[data-align="left"] .card[data-orient="v"] .paper { justify-content: flex-end; }

/* 文字块容器：默认不生成盒子（等价旧结构），竖排垂直居中时作为整块参与对齐 */
.piece { display: contents; }

/* 竖排垂直居中：整块文字在纸面里上下居中，块内各列仍从顶部起排、水平方向仍靠右 */
body[data-v-align="center"] .card[data-orient="v"] .paper {
  align-items: center;
}
body[data-v-align="center"] .card[data-orient="v"] .paper > .piece {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.card[data-orient="v"] .title {
  font-size: var(--fs-title-user, 20px);
  line-height: 1.5;
  margin: 0 0 0 8px;
  text-align: start;
  writing-mode: vertical-rl;
}

/* 长题序拆成两列：段与段在竖排里各占一列 */
.card[data-orient="v"] .title-seg {
  display: block;
}

.card[data-orient="v"] .byline {
  margin: 0 0 0 calc(var(--col-gap, 0px) + 8px);
  padding-top: 0;
  font-size: 14px;
  align-self: flex-start;
}

.card[data-orient="v"] .body {
  margin: 0 0 0 22px;
  font-size: var(--fs-body-user, 18px);
  line-height: var(--lh-v, var(--lh-body-user, 2.15));
  text-align: start;
}

.card[data-orient="v"] .body .clause {
  display: block;
  margin: 0 0 0 var(--col-gap, 0px);
}

/* 生僻字注音：正文之后，虚线分隔，正文排版不变。
   逻辑属性 border-block-start 在横排是顶边、竖排是右边（靠正文那一侧） */
/* 小字注音要清晰：正文是宋/楷，注音换成字面更大的无衬线（有霞鹜文楷就先用它，
   缺字自然回落到黑体），颜色用 ink-soft 而非最淡的一档 */
.gloss {
  margin-block-start: 12px;
  padding-block-start: 8px;
  border-block-start: 1px dashed var(--ui-border);
  font-family: "LXGW WenKai", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--ink-soft);
  text-align: var(--align, center);
  letter-spacing: 0;
}
.gloss-item {
  display: inline-block;
  margin-inline-start: 0.5em;
  padding-inline: 0.1em;
  white-space: nowrap;
}
/* 有注音的字：左侧一道 2px 朱红短竖（用背景画，不占布局宽度，长度只到字高的七成） */
.tone {
  background-image: linear-gradient(var(--accent, #8c2b22), var(--accent, #8c2b22));
  background-size: 2px 0.8em;
  background-position: 0 65%;
  background-repeat: no-repeat;
}
/* 正文上的自定义毛笔光标：笔尖（16,30）就是热点，加载不了就退回文本光标。
   只在展开页用，图标弹窗和打印台沿用系统光标；关掉注音或关掉「点击单字注音」时也退回文本光标 */
body[data-gloss="1"][data-gloss-click="1"]:not([data-surface="popup"]):not([data-surface="print"]) .card[data-orient="h"] .paper .body,
body[data-gloss="1"][data-gloss-click="1"]:not([data-surface="popup"]):not([data-surface="print"]) .card[data-orient="v"] .paper .body {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 1024 1024'%3E%3Cpath d='M987.03251705 614.40486662l-295.2193961 291.45863981c2.31767572 21.38383725-0.76527029 48.10270109-22.36775603 69.98943045-24.57610752 24.90408023-132.1512392 82.2774842-223.41518267-18.95683731 0 0 43.97024175 1.92410783 60.67499849-35.98956671 21.82113421-71.51997102 72.41643042-84.48583508 108.99634802-83.65497026L914.22251938 542.55692285c20.05008031-19.83143183 52.67245798-19.83143182 72.78813283 0 20.07194515 19.83143181 20.07194516 52.01651193 0.02186485 71.84794376z' fill='%23a87a3a'/%3E%3Cpath d='M534.21117971 932.10134359C522.36042354 956.63372079 506.70518071 968.87804486 506.70518071 968.87804486c44.97602538 34.28410673 121.34999635-1.11510787 138.49204944-16.9234046 30.26097227-28.05262078 12.35364829-59.6910791 12.11313496-59.90972817l-24.24813418-23.98575601c0 0.02186485-70.57978136-11.10735074-98.85105122 64.04218751z' fill='%23a3372a'/%3E%3Cpath d='M681.55849929 868.08102095l36.42686368-35.92397161-24.24813417-23.96389114-36.42686368 35.92397158c0-0.02186485 22.0397833 21.75553966 24.24813416 23.96389117z' fill='%238c6127'/%3E%3C/svg%3E") 22 42, text;
}

/* 悬停/点击的底纹：固定定位盖在字上，不参与排版 */
.char-hover,
.char-flash {
  position: fixed;
  z-index: 55;
  pointer-events: none;
  border-radius: 2px;
}
.char-hover {
  background: color-mix(in srgb, var(--accent, #8c2b22) 16%, transparent);
}
.char-flash {
  background: var(--accent, #8c2b22);
  opacity: 1;
  animation: char-flash 700ms ease-out forwards;
}
@keyframes char-flash {
  0% { opacity: .62; }
  100% { opacity: 0; }
}

/* 《说文》没有这个字时的提示：点处冒出一个「无」，慢慢放大、淡出、消散 */
.gloss-void {
  position: fixed;
  z-index: 9999;
  translate: -50% -50%;
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  color: var(--accent, #8c2b22);
  pointer-events: none;
  user-select: none;
  opacity: 0;
  animation: gloss-void 1.6s cubic-bezier(.16, .84, .3, 1) forwards;
}
@keyframes gloss-void {
  0% { opacity: 0; transform: scale(1) translateY(0); }
  15% { opacity: .95; transform: scale(1.15) translateY(-6px); }
  100% { opacity: 0; transform: scale(3) translateY(-26px); }
}
/* 没有条目时整块收起（::before 不算 :empty，故方块不会孤零零留着）。
   .gloss-out 是回收动画进行中的临时状态，这时它已经空了但还要撑住尺寸 */
.gloss:empty:not(.gloss-out) {
  display: none;
}
/* 字与反切之间只留一线，不要整格空开；字头用朱红，与开头的方块呼应 */
.gloss-char {
  color: var(--accent, #8c2b22);
}
.gloss-fanqie {
  margin-inline-start: 0.35em;
  letter-spacing: 0.15em;
}
/* 借异体字头取反切时，小字标出那个字头（如 辉 借 暉） */
.gloss-via {
  margin-inline-start: 0.3em;
  font-size: 0.92em;
  color: var(--ink-faint);
  letter-spacing: 0;
}
.gloss-via::before { content: "「"; }
.gloss-via::after { content: "」"; }
/* 注音开头一个朱红色小方块（印章意味），横排在本行行首、竖排在该列顶端 */
.gloss::before {
  content: "";
  display: inline-block;
  width: 0.52em;
  height: 0.52em;
  margin-inline-start: 0.35em;
  margin-inline-end: 0.35em;
  background: var(--accent, #8c2b22);
  vertical-align: 0.05em;
}
/* 竖排：注音自成相邻一列，跟着正文竖排，虚线落在该列的右侧 */
.card[data-orient="v"] .gloss {
  flex: 0 0 auto;
  /* 交叉轴（纵向）对齐跟随诗词区：默认靠上，vAlign=center 时随整块居中。
     render.js 的 fitGlossHeight 按正文最长列高设显式 height（封顶纸面内高），
     所以这里不再用 stretch——否则会覆盖 paper 的 align-items:center，把注音钉在顶部。
     vertical-rl 下 extra 内容换成下一列（横向），不会把正文顶上去 */
  align-self: flex-start;
  writing-mode: vertical-rl;
  text-orientation: upright;
  /* 竖排里 text-align 走 inline 轴（纵向）。居中会让新增条目把整列顶上移下，
     一列快满时叠加换列就是上下抖动；改为从列顶起排，追加末尾条目不动前面 */
  text-align: start;
  position: relative;
  margin: 0 0 0 16px;
  /* 印章回到流内，占第一列列首的 inline 空间；新列由 JS 插同尺寸透明 .gloss-gap，
     各列字首因此对齐。竖排下 padding-top 走 inline 轴，这里不再需要额外留白 */
  padding: 0 12px 0 0;
  font-size: 13px;
  line-height: 2.15;
  letter-spacing: 0.04em;
  max-height: 100%;
  overflow: hidden;
}
/* 诗词区垂直居中时注音也居中：paper 的 align-items:center 作用于所有直接子项，
   但 .gloss 上的 align-self 会覆盖它，故在此显式对齐 */
body[data-v-align="center"] .card[data-orient="v"] .gloss {
  align-self: center;
}
/* 竖排印章回到流内：第一列的 ::before 照常占位、顶低本列字首。
   新列用 .gloss-gap 做同尺寸的透明占位（见 render.js 的 syncGlossGaps），
   于是每列字首都从同一高度起排，印章也跟着第一列走、不会脱节 */
.card[data-orient="v"] .gloss .gloss-gap {
  content: "";
  display: inline-block;
  width: 0.52em;
  height: 0.52em;
  margin-inline-start: 0.35em;
  margin-inline-end: 0.35em;
  vertical-align: 0.05em;
  background: transparent;
}

/* 竖排一列放不下时：标题/正文各自保持自然宽度，横向溢出交给纸面滚动，
   否则 flex 会把标题列压成零宽（列数一多就看不到标题和作者） */
.card[data-orient="v"] .paper > .head,
.card[data-orient="v"] .paper > .body,
.card[data-orient="v"] .paper > .note,
body[data-v-align="center"] .card[data-orient="v"] .paper > .piece > .head,
body[data-v-align="center"] .card[data-orient="v"] .paper > .piece > .body {
  flex: 0 0 auto;
}

/* 横排：兜底横向滚动，应对无标点的超长句 */
.card[data-orient="h"] .paper { overflow-x: auto; }

/* 逗号换行：横排里每个逗号段独占一行（竖排列本身一段，无需额外规则） */
body[data-break="comma"] .card[data-orient="h"] .body .clause { display: block; }

/* 词谱断行：命中词牌模板时每行独占一处（横排一行、竖排一列），上下阕之间空一行 */
.card[data-lines="1"][data-orient="h"] .body .clause { display: block; }
.stanza-gap { height: 1.4em; }
.card[data-orient="v"] .stanza-gap { width: 1.4em; height: 0; }

/* 横排最大高度约束交给容器 */
.card[data-orient="h"] .paper {
  min-height: var(--paper-h);
  max-height: var(--paper-h);
  overflow-y: hidden;
}
