/* 字词与排版类页面的共用样式（v3.59.0）
 *
 * 只放「多个页面都要用」的东西：排版预览、字格、竖排、注音。
 * 单个页面独有的参数面板样式写在各页自己的 <style> 里。
 */

/* ---------------------------------------------------------------- 排版预览 */
.tx-preview {
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  line-height: 1.9;
  color: var(--text);
  word-break: break-word;
  min-height: 120px;
  max-height: 460px;
  overflow: auto;
}
.tx-preview:empty::before {
  content: "处理结果会显示在这里";
  color: var(--text-faint);
  font-size: 13px;
}
.tx-preview p { margin: 0 0 .6em; }
.tx-preview p:last-child { margin-bottom: 0; }
/* 首行缩进两字：用 text-indent，比插全角空格干净 */
.tx-preview.indent p { text-indent: 2em; }

/* 对比视图：左边原文右边结果 */
.tx-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 780px) { .tx-split { grid-template-columns: 1fr; } }

.tx-side { min-width: 0; }
.tx-side > .lb {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.tx-side > .lb b { color: var(--text); font-size: 12.5px; font-weight: 600; }
.tx-side textarea { min-height: 220px; }

/* 标出被改动的位置 */
.tx-diff mark {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 2px;
  padding: 0 1px;
}

/* ---------------------------------------------------------------- 注音 */
.tx-ruby {
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 22px;
  line-height: 2.2;
  word-break: break-word;
  max-height: 520px;
  overflow: auto;
}
.tx-ruby ruby {
  ruby-align: center;
}
.tx-ruby rt {
  /* 拼音是拉丁字母，同样字号下比汉字宽不少，压到三分之一出头才不会把字距撑开 */
  font-size: .34em;
  color: var(--accent-dark);
  font-family: var(--mono);
  letter-spacing: .02em;
  line-height: 1.2;
}
/* 打印或复制到 Word 时不希望注音被拆开 */
.tx-ruby rt::after { content: ""; }

/* ---------------------------------------------------------------- 字格 */
.zi-board {
  display: grid;
  gap: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  width: 100%;
  box-sizing: border-box;
  overflow: auto;
}
.zi-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 1px solid #c8cdd6;
  margin: -1px 0 0 -1px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  line-height: 1;
  color: var(--text);
  box-sizing: border-box;
}
:root[data-theme="dark"] .zi-cell { border-color: #333a46; }

/* 田字格：一横一竖 */
.zi-cell.tian::before,
.zi-cell.tian::after {
  content: "";
  position: absolute;
  background: #d8dce4;
  pointer-events: none;
}
.zi-cell.tian::before { left: 0; right: 0; top: 50%; height: 1px; }
.zi-cell.tian::after { top: 0; bottom: 0; left: 50%; width: 1px; }

/* 米字格：田字加两条斜线 */
.zi-cell.mi::before,
.zi-cell.mi::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .85;
}
.zi-cell.mi::before {
  background:
    linear-gradient(to right, transparent calc(50% - .5px), #d8dce4 calc(50% - .5px), #d8dce4 calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to bottom, transparent calc(50% - .5px), #d8dce4 calc(50% - .5px), #d8dce4 calc(50% + .5px), transparent calc(50% + .5px));
}
.zi-cell.mi::after {
  background:
    linear-gradient(45deg, transparent calc(50% - .5px), #d8dce4 calc(50% - .5px), #d8dce4 calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(-45deg, transparent calc(50% - .5px), #d8dce4 calc(50% - .5px), #d8dce4 calc(50% + .5px), transparent calc(50% + .5px));
}
:root[data-theme="dark"] .zi-cell.mi::before,
:root[data-theme="dark"] .zi-cell.mi::after { opacity: .3; }
:root[data-theme="dark"] .zi-cell.tian::before,
:root[data-theme="dark"] .zi-cell.tian::after { background: #333a46; }

/* 回宫格：外面留一圈，中间再套一个内框 */
.zi-cell.hui::before {
  content: "";
  position: absolute;
  inset: 18%;
  border: 1px dashed #d8dce4;
  pointer-events: none;
}
:root[data-theme="dark"] .zi-cell.hui::before { border-color: #333a46; }

/* 描红：浅灰字，供临摹 */
.zi-cell.trace { color: #c9ced8; }
:root[data-theme="dark"] .zi-cell.trace { color: #4a5361; }
.zi-cell.ghost { color: transparent; }
.zi-cell .py {
  position: absolute;
  top: 3px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: var(--text-faint);
  font-family: var(--mono);
  line-height: 1;
  letter-spacing: 0;
}

/* 字帖的打印：只留字格，一页切 4 行左右 */
@media print {
  .hero, .panel:not(#print-area), footer, .tool-more, .toast, .no-print { display: none !important; }
  #print-area { border: 0 !important; padding: 0 !important; }
  .zi-cell { border-color: #999 !important; font-size: 52px; }
  .zi-cell.ghost { color: transparent !important; }
  .zi-cell.trace { color: #ccc !important; }
}

/* ---------------------------------------------------------------- 竖排 */
.vt-board {
  display: flex;
  flex-direction: row-reverse;
  justify-content: center;
  align-items: flex-start;
  gap: 6px;
  padding: 22px 18px;
  min-height: 260px;
  background: #faf7f0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: "Songti SC", "SimSun", serif;
}
:root[data-theme="dark"] .vt-board { background: #1a1a1a; border-color: #333; }
.vt-col {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 26px;
  line-height: 1.35;
  letter-spacing: .12em;
  color: #1f1c17;
  white-space: nowrap;
  padding: 0 2px;
}
:root[data-theme="dark"] .vt-col { color: #e8e3d8; }
.vt-col.rule { border-left: 1px solid rgba(0, 0, 0, .14); }
:root[data-theme="dark"] .vt-col.rule { border-left-color: rgba(255, 255, 255, .16); }
.vt-seal-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  align-self: stretch;
  padding-left: 6px;
  min-width: 40px;
}
.vt-seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-bottom: 4px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: #b23a2e;
  border-radius: 3px;
  writing-mode: horizontal-tb;
  letter-spacing: .02em;
  line-height: 1.15;
  text-align: center;
  padding: 2px;
  box-sizing: border-box;
}

/* ---------------------------------------------------------------- 汉字卡片 */
.hz-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding: 16px 18px;
  background: var(--panel-sunken);
  border-radius: var(--radius-sm);
}
.hz-big {
  font-size: 62px;
  line-height: 1;
  font-family: "Songti SC", "SimSun", serif;
  color: var(--text);
  min-width: 76px;
  text-align: center;
}
.hz-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-dim); }
.hz-meta b { color: var(--text); font-weight: 600; }
.hz-meta .py { font-family: var(--mono); color: var(--accent-dark); }

/* 字列表：按笔画数或部首分组时用，密排小方块 */
.hz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 4px;
}
.hz-chip {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text);
  font-family: "Songti SC", "SimSun", serif;
  padding: 0;
  transition: border-color .12s, background .12s;
}
.hz-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.hz-chip.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.hz-chip.miss { opacity: .4; }

/* 笔画数横条 */
.hz-bars {
  display: grid;
  /* 27 档笔画平分整行；窄屏按 26px 折成两行 */
  grid-template-columns: repeat(auto-fit, minmax(26px, 1fr));
  gap: 4px 3px;
  align-items: end;
}
.hz-bars button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 3px 0 0;
  min-width: 0;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-dim);
  background: none;
  border: 0;
  border-bottom: 2px solid var(--border-strong);
  cursor: pointer;
}
.hz-bars button i {
  display: block;
  width: 100%;
  background: var(--text-faint);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}
.hz-bars button:hover { color: var(--text); border-bottom-color: var(--accent); }
.hz-bars button:hover i { background: var(--accent); }
.hz-bars button.on { color: var(--accent-dark); font-weight: 700; border-bottom-color: var(--accent); }
.hz-bars button.on i { background: var(--accent); }

/* ---------------------------------------------------------------- 词条 */
.wy-list { display: flex; flex-direction: column; gap: 0; }
.wy-item {
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
  line-height: 1.7;
  font-size: 14px;
}
.wy-item:last-child { border-bottom: 0; }
.wy-item .q { color: var(--text); }
.wy-item .a { color: var(--accent-dark); font-weight: 600; }
.wy-item .sep { color: var(--text-faint); margin: 0 6px; }
.wy-item .tag {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--panel-sunken);
  border-radius: 999px;
  vertical-align: 1px;
}
.wy-item mark { background: var(--accent-soft); color: var(--accent-dark); border-radius: 2px; padding: 0 1px; }

/* ---------------------------------------------------------------- 五笔键位 */
.wb-map {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
}
.wb-map > div {
  padding: 6px 8px;
  background: var(--panel-sunken);
  border-radius: 4px;
  line-height: 1.5;
}
.wb-map b { color: var(--accent-dark); }
.wb-map span { color: var(--text-dim); }

@media (max-width: 560px) {
  .tx-preview { padding: 12px 13px; font-size: 14.5px; }
  .tx-ruby { padding: 14px; font-size: 19px; line-height: 2.3; }
  .hz-big { font-size: 48px; min-width: 58px; }
  .hz-grid { grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); }
  .vt-col { font-size: 21px; }
  .wb-map { grid-template-columns: repeat(2, 1fr); }
  .zi-cell { font-size: 30px; }
}

/* ---------------------------------------------------------------- 窄屏按钮组 */
/* 各页自带的 .seg 是 inline-flex 不换行，手机上 8 个按钮会被压成竖排文字。
   用 .panel 提高特异性覆盖页面里的定义，比逐页去改省事，也不会漏。 */
.panel .seg { flex-wrap: wrap; }
@media (max-width: 640px) {
  .panel .seg { width: 100%; }
  .panel .seg button { flex: 1 1 auto; min-width: 66px; }
  .panel .seg button { border-right: 0; border-bottom: 1px solid var(--border); }
  .panel .seg button:last-child { border-bottom: 0; }
}
