/* ==========================================================================
   Ars Magica 5E Definitive Edition - 中文可填写角色卡样式表
   ========================================================================== */

:root {
  --canvas: #efeee9;
  --paper: #fffdf8;
  --surface: #f6f4ef;
  --rule: #d8d3ca;
  --rule-strong: #8d867a;
  --ink-black: #282620;
  --ink-brown: #454139;
  --ink-muted: #6c665c;
  --accent-crimson: #7b303a;
  --accent-soft: #f5e9e9;
  --input-bg: #fcfaf6;
  --input-focus-bg: #ffffff;
  --font-title: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "Georgia", serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "Georgia", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

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

body {
  background: var(--canvas);
  color: var(--ink-black);
  font-family: var(--font-serif);
  font-size: 13px;
  line-height: 1.4;
  min-height: 100vh;
  padding-bottom: 60px;
}

/* ==========================================================================
   顶部固定工具栏 (打印时隐藏)
   ========================================================================== */
.app-toolbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-black);
}

.toolbar-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  background: var(--paper);
  color: var(--ink-brown);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 5px 11px;
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
}

.btn:hover {
  background: var(--surface);
  border-color: var(--rule-strong);
  color: var(--ink-black);
}

.btn.active {
  background: var(--accent-soft);
  color: var(--accent-crimson);
  font-weight: 700;
  border-color: #c7a9ab;
}

.btn-primary {
  border-color: var(--rule-strong);
  font-weight: 700;
}

.btn-danger {
  color: var(--accent-crimson);
}

.btn-danger:hover {
  background: var(--accent-crimson);
  color: #fff;
}

/* 双语显示控制 */
body.mode-cn-only .en-sub {
  display: none !important;
}

.en-sub {
  font-size: 0.78em;
  color: var(--ink-muted);
  font-weight: normal;
  margin-left: 3px;
  font-family: "Georgia", serif;
  white-space: nowrap;
}

/* ==========================================================================
   四页人物卡容器
   ========================================================================== */
.sheets-container {
  max-width: 980px;
  margin: 24px auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 0 16px;
}

.sheet-page {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 26px 30px 24px;
  overflow: hidden;
}

.page-badge {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 11px;
  color: var(--ink-muted);
  font-family: var(--font-title);
  z-index: 2;
  background: var(--paper);
  padding: 1px 8px;
}

/* ==========================================================================
   内容分区与标题
   ========================================================================== */
.panel-box {
  position: relative;
  background: transparent;
  border: 1px solid var(--rule);
  padding: 12px 16px;
  margin-bottom: 14px;
  z-index: 2;
}

/* 装饰节点不占用人物卡的阅读空间。 */
.panel-box .corner-diamond {
  display: none;
}

/* 标题样式 */
.section-title {
  font-family: var(--font-title);
  font-size: 16.5px;
  font-weight: 700;
  color: var(--ink-brown);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2px;
  line-height: 1.25;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 3px;
  margin-bottom: 6px;
}

/* ==========================================================================
   表单输入控件样式 (下划线手写风，严格统一行高与基线)
   ========================================================================== */
input[type="text"],
input[type="number"],
select,
textarea {
  font-family: var(--font-serif);
  font-size: 13px;
  color: var(--ink-black);
  background: var(--input-bg);
  border: none;
  border-bottom: 1px solid var(--rule-strong);
  padding: 1px 5px;
  height: 22px;
  line-height: 20px;
  width: 100%;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

input[type="number"] {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12.5px;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  outline: none;
  background: var(--input-focus-bg);
  border-bottom-color: var(--accent-crimson);
  box-shadow: 0 1px 0 0 var(--accent-crimson);
}

input.calc-output,
.char-table input[data-field$="_score"],
#abilitiesBody input[data-field$="_score"],
.art-table input[data-field$="_score"] {
  background: var(--accent-soft);
  font-weight: 700;
  color: var(--accent-crimson);
  border-bottom: 1px solid #9e6971;
  font-variant-numeric: tabular-nums;
}

/* 经验与伤势小方框 */
.exp-box {
  width: 24px !important;
  height: 19px !important;
  line-height: 17px !important;
  border: 1px solid var(--rule-strong) !important;
  background: var(--paper) !important;
  color: var(--ink-muted);
  text-align: center;
  font-size: 11px !important;
  padding: 0 !important;
  border-radius: 1px;
  display: inline-block;
  vertical-align: middle;
}

.check-sq {
  appearance: none;
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--rule-strong);
  background: var(--paper);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  margin: 0 2px 0 0;
  vertical-align: middle;
}

.check-sq:checked {
  background: var(--accent-crimson);
  border-color: var(--accent-crimson);
}

.check-sq:checked::after {
  content: "✓";
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  line-height: 1;
}

.fatigue-table tbody tr:has(.check-sq:checked),
.wounds-table tbody tr:has(.check-sq:checked) {
  background: var(--accent-soft);
  color: var(--accent-crimson);
  font-weight: 700;
}

/* 字段行布局：垂直居中对齐，确保标签与输入下划线整齐划一 */
.field-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  min-height: 23px;
}

.field-row > input {
  flex: 1;
  min-width: 0;
}

.field-label {
  white-space: nowrap;
  font-weight: 600;
  color: var(--ink-brown);
  font-size: 12.5px;
  line-height: 22px;
  flex-shrink: 0;
}

.field-label-lg {
  font-family: var(--font-title);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink-brown);
  white-space: nowrap;
  line-height: 22px;
  flex-shrink: 0;
}

/* 括号包裹输入框 */
.paren-wrap {
  display: flex;
  align-items: center;
  width: 100%;
}
.paren-wrap::before {
  content: "(";
  color: var(--ink-muted);
  font-weight: bold;
  margin-right: 2px;
}
.paren-wrap::after {
  content: ")";
  color: var(--ink-muted);
  font-weight: bold;
  margin-left: 2px;
}

.lined-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stretch-list {
  flex: 1;
  justify-content: space-between;
}

/* ==========================================================================
   Page 1 专属布局 (三栏与双栏底部严格等高对齐)
   ========================================================================== */
.p1-header-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 10px;
  position: relative;
  z-index: 2;
}

.p1-header-fields {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.p1-header-fields .field-label,
.p1-header-fields .field-label-lg {
  min-width: 56px;
}

.ars-logo-banner {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 10px 12px;
  border-left: 1px solid var(--rule);
}

.ars-logo-title {
  font-family: var(--font-title);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink-black);
  line-height: 1.4;
}

.ars-logo-sub {
  font-size: 15px;
  color: var(--ink-muted);
  letter-spacing: 2px;
  margin-top: 6px;
}

.p1-subbar {
  display: grid;
  grid-template-columns: 1.7fr 1.05fr 0.85fr 1.15fr;
  gap: 14px;
  margin-bottom: 12px;
  position: relative;
  z-index: 2;
}

.p1-bio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.75fr;
  gap: 16px;
  align-items: stretch;
}

.bio-col {
  display: flex;
  flex-direction: column;
}

.bio-details-col {
  justify-content: space-between;
}

.bio-details-col > .field-row .field-label {
  min-width: 64px;
}

.bio-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.p1-main-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 20px;
  align-items: stretch;
}

.p1-left-col,
.p1-right-col {
  display: flex;
  flex-direction: column;
}

.vf-block {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.char-table,
.ability-table {
  width: 100%;
  border-collapse: collapse;
}

.char-table th,
.ability-table th {
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 700;
  padding-bottom: 4px;
  text-align: center;
  border-bottom: 1px solid var(--rule);
}

.char-table td {
  padding: 2.5px 3px;
  vertical-align: middle;
  height: 25px;
}

.char-name {
  font-weight: 700;
  white-space: nowrap;
  width: 30%;
}

.char-abbr {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  width: 12%;
  text-align: center;
}

.ability-table td {
  padding: 1.5px 2px;
  vertical-align: middle;
  height: 24px;
}

/* ==========================================================================
   Page 2 专属布局 (战斗、疲劳/伤势复选框、武器公式表列对齐)
   ========================================================================== */
.p2-top-grid {
  display: grid;
  grid-template-columns: 0.95fr 1.25fr;
  gap: 20px;
  align-items: stretch;
}

.p2-combat-grid {
  display: grid;
  grid-template-columns: 1fr 136px;
  gap: 20px;
  align-items: stretch;
}

.combat-lines-col {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.combat-line-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.combat-label {
  min-width: 68px;
}

.combat-indent {
  padding-left: 74px;
}

.soak-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  border-left: 1px dashed var(--rule);
  padding-left: 14px;
}

.soak-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.soak-box .big-score {
  font-size: 15px;
  font-weight: bold;
  height: 26px;
}

.p2-fatigue-wounds-grid {
  display: grid;
  grid-template-columns: 0.92fr 1.38fr;
  gap: 20px;
  align-items: stretch;
}

.fw-col {
  display: flex;
  flex-direction: column;
}

.fatigue-table,
.wounds-table,
.weapons-table,
.vis-table {
  width: 100%;
  border-collapse: collapse;
}

.fatigue-table th,
.wounds-table th,
.weapons-table th,
.vis-table th {
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 700;
  padding-bottom: 4px;
  text-align: center;
  border-bottom: 1px solid var(--rule);
}

.fatigue-table td {
  padding: 2.5px 4px;
  vertical-align: middle;
  height: 26px;
}

.wounds-table td {
  padding: 3px 4px;
  vertical-align: middle;
  height: 31px;
}

/* 伤势复选框严格左对齐成列 */
.wound-checks-cell {
  text-align: left !important;
  padding-left: 8px !important;
  white-space: nowrap;
}

/* 武器公式列：表头文字与下方输入框 1:1 严格对齐 */
.weapons-table th {
  padding: 2px 2px 5px;
  vertical-align: bottom;
}

.weapons-table td {
  padding: 3px 2px;
  vertical-align: middle;
  height: 27px;
}

.formula-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.formula-group input {
  width: 31px !important;
  height: 22px;
  padding: 1px 2px;
  font-size: 12px;
}

.formula-group .op {
  display: inline-block;
  width: 10px;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink-muted);
  font-size: 11.5px;
}

.formula-header span {
  display: inline-block;
  width: 31px;
  text-align: center;
  font-size: 11px;
  color: var(--ink-brown);
  font-weight: 700;
  line-height: 1.2;
}

.formula-header span.op {
  width: 10px;
  color: var(--ink-muted);
}

.formula-header span.res {
  color: var(--accent-crimson);
}

.equipment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 18px;
}

/* ==========================================================================
   Page 3 专属布局 (学派四行对齐、施法公式符号居中、魔宠三栏等高)
   ========================================================================== */
.p3-hermetic-top {
  display: grid;
  grid-template-columns: 1fr 1.12fr;
  gap: 20px;
  align-items: stretch;
}

.hermetic-col {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hermetic-col:first-child .field-label {
  min-width: 64px;
}

.hermetic-col:last-child .field-label {
  min-width: 74px;
}

.arts-three-col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
}

.art-table {
  width: 100%;
  border-collapse: collapse;
}

.art-table th {
  font-size: 11px;
  color: var(--ink-muted);
  padding-bottom: 4px;
  text-align: center;
  border-bottom: 1px solid var(--rule);
}

.art-table td {
  padding: 2.5px 3px;
  vertical-align: middle;
  height: 26px;
}

.p3-casting-lab-grid {
  display: grid;
  grid-template-columns: 1.06fr 1fr;
  gap: 22px;
  align-items: stretch;
}

.casting-left-col,
.casting-right-col {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.calc-blocks-stack {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
  gap: 8px;
}

.casting-formulas-note {
  font-size: 11.5px;
  background: var(--surface);
  border-left: 3px solid var(--rule);
  padding: 6px 8px;
  margin-bottom: 8px;
  line-height: 1.45;
}

.calc-block {
  margin-bottom: 4px;
}

.calc-block-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink-brown);
  margin-bottom: 2px;
}

.calc-subnote {
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: normal;
}

/* 公式运算行：运算符与输入框高度严格居中对齐 */
.calc-equation {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.calc-equation .eq-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.calc-equation .eq-col span {
  font-size: 10.5px;
  color: var(--ink-muted);
  margin-top: 2px;
  line-height: 1.2;
}

.calc-equation .eq-op {
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-brown);
  padding: 0 2px;
  flex-shrink: 0;
}

.calc-equation .eq-op-wide {
  padding: 0 6px;
}

.vis-table td {
  padding: 2px 3px;
  vertical-align: middle;
  height: 24px;
}

.p3-familiar-grid {
  display: grid;
  grid-template-columns: 0.9fr 0.9fr 1.6fr;
  gap: 16px;
  align-items: stretch;
}

.fam-stats-col {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.fam-stats-col .field-label {
  min-width: 38px;
}

.fam-bond-col {
  display: flex;
  flex-direction: column;
}

.cords-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}

/* ==========================================================================
   Page 4 专属布局 (法术卡片网格对齐)
   ========================================================================== */
.spells-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
}

.sheet-actions {
  margin-top: 14px;
  text-align: center;
}

.spell-card {
  border: 1px solid var(--rule);
  background: var(--paper);
  padding: 7px 10px;
  border-radius: 2px;
}

.spell-card .field-row {
  margin-bottom: 3px;
  min-height: 21px;
}

.spell-card input[type="text"],
.spell-card input[type="number"] {
  height: 20px;
  line-height: 18px;
  font-size: 12.5px;
}

.spell-row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.spell-row-3col {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 6px;
}

/* 页脚版权声明 */
.sheet-footer {
  text-align: center;
  font-size: 10.5px;
  color: var(--ink-muted);
  font-style: italic;
  margin-top: 8px;
  position: relative;
  z-index: 2;
}

/* ==========================================================================
   术语速查与施法矩阵侧边抽屉 (Modal / Drawer)
   ========================================================================== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 38, 32, 0.35);
  z-index: 2000;
  display: none;
  justify-content: flex-end;
}

.drawer-overlay.open {
  display: flex;
}

.drawer-panel {
  width: min(720px, 95vw);
  background: var(--paper);
  color: var(--ink-black);
  height: 100%;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--rule);
}

.drawer-header {
  padding: 14px 18px;
  background: var(--paper);
  color: var(--ink-black);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--rule);
}

.drawer-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}

.glossary-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.glossary-controls input {
  flex: 1;
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--rule);
  padding: 6px 10px;
  height: 32px;
  border-radius: 4px;
}

.glossary-controls select {
  width: auto;
  background: #fff;
  border: 1px solid var(--rule);
  padding: 4px 10px;
  height: 32px;
  border-radius: 4px;
}

.glossary-result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.glossary-result-table th,
.glossary-result-table td {
  border-bottom: 1px solid var(--rule);
  padding: 6px 8px;
  text-align: left;
}

.glossary-result-table th {
  background: var(--surface);
  color: var(--ink-brown);
}

/* 5x10 秘艺施法速查矩阵 */
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  margin-top: 8px;
  text-align: center;
}

.matrix-table th,
.matrix-table td {
  border: 1px solid var(--rule);
  padding: 4px 3px;
}

.matrix-table th {
  background: var(--surface);
  color: var(--ink-brown);
}

/* 屏幕上的规则辅助信息不改变纸卡字段。 */
.rules-controls { background: var(--paper); border: 1px solid var(--rule); padding: 12px 16px; border-radius: 4px; }
.rules-controls summary { cursor: pointer; font-weight: bold; }
.rules-controls p { margin-top: 8px; font-size: 12px; line-height: 1.6; }
.rules-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 16px; margin-top: 12px; }
.rules-grid label { display: flex; flex-direction: column; gap: 4px; }
.rules-grid input { width: 100%; }
.rules-grid output { padding: 4px; min-height: 24px; }
.check-option, .ritual-label, .carried-label { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-size: 11px; }
.check-option { margin-top: 8px; }
input[type="checkbox"] { flex: none; }
.spell-reference { font-size: 11px; margin-top: 4px; }
.spell-reference summary { cursor: pointer; color: var(--ink-muted); }
.spell-reference div { white-space: pre-wrap; line-height: 1.6; padding: 5px; }
.spell-reference[hidden] { display: none; }
.glossary-result-table td { overflow-wrap: anywhere; }
.glossary-result-table td:last-child { min-width: 120px; }
#glossaryCount { font-size: 12px; color: var(--ink-muted); margin-bottom: 6px; }


/* ==========================================================================
   打印与导出 PDF 专属样式 (@media print)
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 6mm;
  }

  body {
    background: none !important;
    padding: 0 !important;
    min-height: 0;
    font-size: 11px;
    line-height: 1.2;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app-toolbar, .drawer-overlay, .no-print {
    display: none !important;
  }

  .sheets-container {
    display: block;
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
  }

  .sheet-page {
    box-shadow: none !important;
    margin: 0 !important;
    padding: 12px 14px !important;
    overflow: visible;
    page-break-after: always;
    break-after: page;
    break-inside: avoid;
    border-width: 1px;
  }

  .sheet-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .panel-box {
    margin-bottom: 6px !important;
    padding: 6px 8px !important;
    box-shadow: none;
  }

  .section-title { font-size: 13px; margin-bottom: 4px; }
  .section-header-row { margin-bottom: 4px; padding-bottom: 2px; }
  .sheet-footer { font-size: 8px; margin-top: 5px; }
  .page-badge { font-size: 8px; top: 1px; right: 10px; z-index: 5; padding: 0 4px; }
  .ars-logo-title { font-size: 17px; }
  .ars-logo-sub { font-size: 12px; }
  .ars-logo-banner { padding: 5px; }

  input[type="text"], input[type="number"], select, textarea {
    height: 17px;
    line-height: 15px;
    font-size: 10.5px;
    padding: 0 2px;
  }
  .field-row { min-height: 18px; margin-bottom: 2px; gap: 3px; }
  .field-label, .field-label-lg { font-size: 10.5px; line-height: 17px; }
  .en-sub { font-size: 7.5px; white-space: normal; }
  .field-label .en-sub, .field-label-lg .en-sub {
    display: inline;
    line-height: inherit;
    margin-left: 2px;
  }
  .exp-box { height: 16px !important; line-height: 14px !important; font-size: 9px !important; }
  .check-sq { width: 12px; height: 12px; }
  .lined-list { gap: 2px; }

  .p1-header-grid { gap: 12px; margin-bottom: 5px; }
  .p1-subbar { gap: 7px; margin-bottom: 6px; }
  .p1-bio-grid, .p1-main-grid, .p2-top-grid, .p2-combat-grid,
  .p2-fatigue-wounds-grid, .p3-hermetic-top, .p3-casting-lab-grid,
  .p3-familiar-grid, .arts-three-col { gap: 10px; }
  .bio-two-col { gap: 5px; }
  .char-table td, .ability-table td, .art-table td, .vis-table td {
    height: 20px;
    padding: 1px 2px;
  }
  .char-table th, .ability-table th, .art-table th, .vis-table th,
  .fatigue-table th, .wounds-table th, .weapons-table th {
    font-size: 9px;
    padding-bottom: 3px;
  }
  .char-name .en-sub { display: block; font-size: 7px; line-height: 8px; margin-left: 0; }
  .char-abbr { font-size: 9px; }
  .p2-combat-grid { grid-template-columns: 1fr 100px; }
  .combat-lines-col { gap: 4px; }
  .combat-indent { padding-left: 64px; }
  .soak-box { gap: 4px; padding-left: 8px; }
  .soak-box .big-score { height: 20px; font-size: 12px; }
  .fatigue-table td, .wounds-table td, .weapons-table td { padding: 2px; height: 23px; }
  .formula-group { gap: 1px; }
  .formula-group input { width: 24px !important; height: 18px; font-size: 10px; }
  .formula-header span { width: 24px; font-size: 9px; }
  .formula-group .op, .formula-header span.op { width: 7px; font-size: 9px; }
  .equipment-grid { gap: 3px 10px; }
  .table-scroll { overflow: visible !important; }
  .weapons-table { min-width: 0; }
  .calc-block-header { font-size: 11px; }
  .calc-subnote { font-size: 8px; }
  .calc-blocks-stack { gap: 5px; }
  .calc-equation { gap: 4px; }
  .calc-equation .eq-op { height: 17px; font-size: 11px; }
  .calc-equation .eq-col span { font-size: 9px; margin-top: 1px; }
  .casting-formulas-note { font-size: 9px; padding: 4px 5px; margin-bottom: 5px; line-height: 1.3; }
  .spells-grid { gap: 2px 8px; }
  .spell-card { padding: 3px 5px; break-inside: avoid; }
  .spell-card .field-row { min-height: 16px; margin-bottom: 0; }
  .spell-card input[type="text"], .spell-card input[type="number"] {
    height: 16px;
    line-height: 14px;
    font-size: 10.5px;
  }
  .spell-card .field-label { font-size: 10px; line-height: 10px; }
  #page-4 { padding-top: 8px !important; padding-bottom: 8px !important; break-inside: auto; }
  .spell-row-2col, .spell-row-3col { gap: 4px; }
  .spell-row-3col .field-row { display: block; }
  .spell-row-3col .field-label { display: block; line-height: 10px; }
  #page-2 .panel-box { padding-top: 4px !important; padding-bottom: 4px !important; }
  #page-2 .ability-table td { height: 18px; padding-top: 0; padding-bottom: 0; }
  #page-2 .fatigue-table td, #page-2 .wounds-table td { height: 21px; padding-top: 1px; padding-bottom: 1px; }
  #page-2 .equipment-grid input { height: 15px; line-height: 13px; }
  #page-2 .equipment-grid { row-gap: 2px; }
}

.weapons-table th:last-child, .weapons-table td:last-child { min-width: 40px; }

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

/* 屏幕阅读尺寸独立于 A4 打印尺寸。 */
@media screen {
  html { scroll-padding-top: 150px; }

  body {
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
  }

  .app-toolbar {
    padding: 10px max(20px, calc((100vw - 1168px) / 2));
    gap: 8px;
  }

  .toolbar-nav {
    width: 100%;
    gap: 4px;
    padding-bottom: 8px;
    padding-right: 110px;
    border-bottom: 1px solid var(--rule);
  }

  .toolbar-nav .btn {
    border-color: transparent;
    font-size: 14px;
    font-weight: 600;
  }

  .toolbar-nav .btn:hover,
  .toolbar-nav .btn:focus-visible {
    background: var(--accent-soft);
    color: var(--accent-crimson);
  }

  .toolbar-actions { width: 100%; gap: 6px; }
  #btnOpenGlossary { position: absolute; top: 10px; right: max(20px, calc((100vw - 1168px) / 2)); }
  #btnExportJson { margin-left: auto; }
  .btn { min-height: 32px; padding: 5px 10px; line-height: 1.4; }
  #slotSelect { width: auto; max-width: 180px; height: 32px; }

  .sheets-container { max-width: 1200px; gap: 24px; }
  .sheet-page { padding: 32px; scroll-margin-top: 18px; }
  .panel-box { padding: 16px 18px; margin-bottom: 18px; }
  .page-badge { top: 10px; right: 24px; font-family: var(--font-ui); }
  .section-title { font-size: 19px; color: var(--ink-black); margin-bottom: 10px; padding-bottom: 6px; letter-spacing: 0; }
  .section-header-row { flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
  .ars-logo-title { font-size: 23px; }
  .ars-logo-sub { font-size: 14px; letter-spacing: 1px; }

  input[type="text"], input[type="number"], select, textarea {
    min-width: 0;
    height: 28px;
    line-height: 24px;
    font-family: var(--font-ui);
    font-size: 14px;
    border-radius: 2px 2px 0 0;
  }

  input[type="number"] { font-family: var(--font-mono); }
  input::placeholder { color: var(--ink-muted); opacity: 1; font-weight: 400; }
  .field-row { min-width: 0; min-height: 28px; margin-bottom: 6px; }
  .field-label, .field-label-lg { font-size: 13px; line-height: 1.45; font-weight: 500; }
  .field-label-lg { font-size: 15px; font-weight: 600; }
  .en-sub { white-space: normal; }
  .field-label:has(> .en-sub), .field-label-lg:has(> .en-sub),
  .field-label > strong:has(> .en-sub) {
    display: inline-grid;
    grid-template-columns: auto auto;
    justify-content: start;
    align-items: baseline;
  }
  .field-label .en-sub, .field-label-lg .en-sub {
    display: block;
    grid-row: 2;
    grid-column: 1 / -1;
    margin-left: 0;
    line-height: 1.25;
  }
  .char-name .en-sub { display: block; margin-left: 0; }

  .p1-header-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px; }
  .p1-subbar { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1.05fr) minmax(0, .85fr) minmax(0, 1.15fr); }
  .p1-bio-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.75fr); }
  .p1-main-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 24px; }
  .p2-top-grid { grid-template-columns: minmax(0, .95fr) minmax(0, 1.25fr); }
  .p2-combat-grid { grid-template-columns: minmax(0, 1fr) 136px; }
  .p2-fatigue-wounds-grid { grid-template-columns: minmax(0, .92fr) minmax(0, 1.38fr); }
  .p3-hermetic-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr); }
  .p3-casting-lab-grid { grid-template-columns: minmax(0, 1.06fr) minmax(0, 1fr); gap: 24px; }
  .p3-familiar-grid { grid-template-columns: minmax(0, .9fr) minmax(0, .9fr) minmax(0, 1.6fr); }
  .arts-three-col, .cords-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bio-two-col, .equipment-grid, .spells-grid, .spell-row-2col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .spell-row-3col { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) minmax(0, 1fr); }
  .p1-main-grid > *, .p2-top-grid > *, .p2-fatigue-wounds-grid > *,
  .p3-casting-lab-grid > *, .p3-familiar-grid > *, .spells-grid > * { min-width: 0; }

  .bio-details-col .field-label, .p3-hermetic-top .field-label { color: var(--ink-muted); }
  .bio-details-col > .field-row .field-label { min-width: 68px; }
  .bio-two-col .field-row { flex-wrap: wrap; }
  .bio-two-col .field-row > input { flex-basis: 50px; }
  input[data-field="character_name"] { font-size: 20px; font-weight: 650; height: 36px; }

  .char-table th, .ability-table th, .art-table th, .vis-table th,
  .fatigue-table th, .wounds-table th, .weapons-table th { font-size: 12px; font-weight: 500; padding-bottom: 7px; }
  .char-table td, .ability-table td, .art-table td, .vis-table td { height: 32px; padding: 2px 3px; }
  .char-table tbody tr + tr, .ability-table tbody tr + tr, .art-table tbody tr + tr { border-top: 1px solid var(--surface); }
  .char-table input[data-field$="_score"], #abilitiesBody input[data-field$="_score"],
  .art-table input[data-field$="_score"] { font-size: 17px; }
  .exp-box { width: 26px !important; height: 22px !important; line-height: 20px !important; font-size: 12px !important; }
  .lined-list { gap: 6px; }

  input.calc-output { text-align: center; font-size: 16px; }
  .soak-box .big-score { height: 32px; font-size: 20px; }
  .fatigue-table td, .wounds-table td { height: 34px; }
  .check-sq { width: 18px; height: 18px; border-radius: 2px; }
  .check-sq:checked::after { font-size: 13px; }
  .fw-col { overflow-x: auto; }
  .wounds-table { min-width: 440px; }
  .weapons-table { min-width: 960px; }
  .weapons-table td { padding: 6px 3px; }
  .weapons-table input[data-field$="_name"] { font-weight: 600; }
  .weapons-table input[data-field$="_ability"] { font-size: 12px; color: var(--ink-muted); }
  .formula-group input { height: 27px; font-size: 12px; }
  .formula-group input.calc-output { font-size: 15px; }
  .formula-header span { color: var(--ink-muted); font-weight: 400; }
  .formula-header span.res { font-weight: 700; color: var(--accent-crimson); }
  .calc-block-header { font-size: 14px; }
  .calc-blocks-stack { gap: 12px; }
  .calc-equation .eq-op { height: 28px; }
  .calc-equation .eq-col span { font-size: 12px; text-align: center; }
  .calc-subnote { font-size: 12px; }
  .casting-formulas-note { font-size: 12px; line-height: 1.65; color: var(--ink-muted); border-left-width: 2px; }
  .section-title:has(.check-option) { flex-wrap: wrap; }
  .check-option { white-space: normal; }

  .spells-grid { gap: 16px; }
  .spell-card { padding: 14px; border-radius: 4px; }
  .spell-card .field-row { min-height: 28px; margin-bottom: 5px; }
  .spell-card input[type="text"], .spell-card input[type="number"] { height: 28px; line-height: 24px; font-size: 14px; }
  .spell-card input[data-field$="_name"] { font-weight: 650; font-size: 16px; }
  .spell-card input.calc-output { font-size: 17px; }
  .spell-row-3col .field-row { flex-direction: column; align-items: stretch; gap: 2px; }
  .spell-row-3col .field-row > input { flex: auto; }
  .spell-card input[data-field$="_exp"], .spell-reference { color: var(--ink-muted); font-size: 12px; }
  .spell-reference summary { padding-block: 4px; }
  .sheet-footer { font-family: var(--font-ui); font-style: normal; font-size: 11px; margin-top: 12px; }

  .rules-controls { padding: 14px 18px; }
  .rules-controls summary { font-size: 14px; }
  .rules-controls p { font-size: 13px; color: var(--ink-muted); }
  #ruleSummary { padding: 10px 12px; background: var(--accent-soft); border-left: 3px solid var(--accent-crimson); color: var(--accent-crimson); font-weight: 600; }
  #resistanceResult { font-family: var(--font-mono); font-size: 18px; color: var(--accent-crimson); font-weight: 700; }
  .rules-controls .btn { margin-top: 8px; }
  #houseDefaultsStatus { font-size: 12px; color: var(--ink-muted); }

  .drawer-panel { width: min(780px, 95vw); }
  .drawer-header { gap: 12px; }
  .drawer-header h2 { font-family: var(--font-title); font-size: 21px; }
  .glossary-controls input, .glossary-controls select { height: 36px; }
  .glossary-result-table { font-size: 14px; }
  .glossary-result-table td { padding-block: 10px; }
  #castingMatrixWrap { overflow-x: auto; }
  .matrix-table { min-width: 640px; font-size: 13px; font-variant-numeric: tabular-nums; }
  .matrix-table td { padding: 7px 4px; }
  .matrix-table tbody tr:hover { background: var(--surface); }

  input[type="text"]:focus-visible,
  input[type="number"]:focus-visible,
  :is(input, select, textarea, button, a, summary):focus-visible {
    outline: 2px solid var(--accent-crimson);
    outline-offset: 2px;
  }

  input[type="text"]:focus, input[type="number"]:focus { box-shadow: none; }
  input[data-field], summary { scroll-margin-block: 18px; }
}

@media screen and (min-width: 901px) and (max-width: 1199px) {
  html { scroll-padding-top: 190px; }
  .sheet-page { padding: 30px 22px; }
  .p1-bio-grid { gap: 12px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.9fr); }
  .bio-details-col .bio-two-col { grid-template-columns: 1fr; gap: 0; }
}

@media screen and (max-width: 900px) {
  html { scroll-padding-top: 0; }
  .p1-header-grid,
  .p1-subbar,
  .p1-bio-grid,
  .p1-main-grid,
  .p2-top-grid,
  .p2-combat-grid,
  .p2-fatigue-wounds-grid,
  .p3-hermetic-top,
  .arts-three-col,
  .p3-casting-lab-grid,
  .p3-familiar-grid,
  .spells-grid,
  .equipment-grid {
    grid-template-columns: 1fr;
  }
  .rules-grid { grid-template-columns: 1fr; }
  .app-toolbar { position: relative; padding: 10px; }
  #btnOpenGlossary { right: 10px; }
  .toolbar-actions, .toolbar-nav { gap: 5px; }
  .sheets-container { padding: 0 8px; margin-top: 12px; gap: 18px; }
  .sheet-page { padding: 30px 14px 16px; }
  .panel-box { padding: 10px; }
  .p1-main-grid > *, .p2-top-grid > *, .p3-casting-lab-grid > *,
  .p3-familiar-grid > *, .spells-grid > * { min-width: 0; }
  .table-scroll .weapons-table { min-width: 940px; }
  .fw-col { min-width: 0; overflow-x: auto; }
  .wounds-table { min-width: 440px; }
  .spell-row-2col .field-row, .spell-row-3col .field-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }
  .spell-row-2col .field-label, .spell-row-3col .field-label {
    white-space: normal;
    line-height: 18px;
  }
  .spell-card .en-sub { white-space: normal; }
  .ars-logo-banner { border-left: 0; border-top: 1px solid var(--rule); padding-top: 16px; }
  .section-title { flex-wrap: wrap; }
  .check-option { align-items: flex-start; }
  .glossary-controls input { min-width: 0; flex-basis: 100%; }
  .drawer-body { padding: 14px 10px; }
  .glossary-result-table th:first-child { width: 72px !important; }
  .glossary-controls { flex-wrap: wrap; }
  .glossary-result-table { table-layout: fixed; }
  .glossary-result-table td { overflow-wrap: anywhere; }
  .combat-indent {
    padding-left: 0;
  }
  .soak-box {
    border-left: none;
    border-top: 1px dashed var(--rule);
    padding-left: 0;
    padding-top: 8px;
    flex-direction: row;
    justify-content: space-around;
  }
}

@media screen and (max-width: 480px) {
  .toolbar-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar-nav .btn { font-size: 12px; padding-inline: 4px; }
  .btn { min-height: 36px; }
  #slotSelect { height: 36px; max-width: 160px; }
  .panel-box { padding: 12px 8px; }
  .sheet-page { padding-inline: 10px; }
  .spell-card { padding: 10px 8px; }
  .field-label, .field-label-lg { white-space: normal; }
  .char-table { table-layout: fixed; }
  .char-name { width: 27%; white-space: normal; }
  .char-abbr { width: 13%; }
  .p1-header-fields .bio-two-col { grid-template-columns: 1fr; }
  .calc-equation { gap: 3px; }
  .calc-equation .eq-op-wide { padding-inline: 2px; }
  .calc-equation .eq-col span { overflow-wrap: anywhere; }
  .calc-block-header { flex-wrap: wrap; gap: 2px 8px; }
  .drawer-header { padding: 12px; }
  .drawer-header h2 { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, input, select, textarea { transition: none; }
}
