/*
 * OCR 对照校正界面。
 * 基础布局与主题覆盖统一放在独立样式表中，避免按需创建界面时向 DOM 注入重复 <style>。
 */
body.ocr-correction-mode {
  overflow: hidden !important;
}
.ocr-correction-root[hidden],
.ocr-correction-image-stage img[hidden],
.ocr-correction-no-preview[hidden] {
  display: none !important;
}
.ocr-correction-root {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  grid-template-rows: auto minmax(0,1fr);
  background: #eef3f9;
  color: #172234;
  font-family: system-ui,-apple-system,"Segoe UI",sans-serif;
}
.ocr-correction-root, .ocr-correction-root * {
  box-sizing: border-box;
}
.ocr-correction-header {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 12px;
  border-bottom: 1px solid #c9d4e2;
  background: #fff;
  box-shadow: 0 2px 10px rgba(29,48,75,.08);
}
.ocr-correction-title-wrap {
  min-width: 0;
  flex: 1;
}
.ocr-correction-title {
  font-size: 17px;
  font-weight: 750;
}
.ocr-correction-subtitle {
  margin-top: 2px;
  color: #62718a;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ocr-correction-header-actions {
  display: flex;
  gap: 6px;
}
.ocr-correction-root button {
  min-height: 36px;
  margin: 0 !important;
  border: 1px solid #aebbd0;
  border-radius: 9px;
  padding: 6px 10px;
  background: #fff;
  color: #172234;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  box-sizing: border-box;
}
.ocr-correction-root button:active {
  transform: translateY(1px);
}
.ocr-correction-root button.primary {
  border-color: #245dc1;
  background: #2868d5;
  color: #fff;
  font-weight: 700;
}
.ocr-correction-root button.danger-lite {
  color: #8b2635;
}
.ocr-correction-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px,1fr) minmax(300px,1fr) minmax(210px,.7fr);
  gap: 10px;
  padding: 10px;
  overflow: hidden;
}
.ocr-correction-root.manual-entry-mode .ocr-correction-workspace {
  grid-template-columns: minmax(360px,1fr) minmax(230px,.55fr);
}
.ocr-correction-root.manual-entry-mode .ocr-correction-image-card,
.ocr-correction-root.manual-entry-mode .ocr-correction-zoom {
  display: none !important;
}
.ocr-correction-root.manual-entry-mode .ocr-correction-board {
  width: min(100%, calc(100dvh - 154px), 720px);
}
.ocr-correction-card {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid #c9d4e2;
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(29,48,75,.08);
  overflow: hidden;
}
.ocr-correction-card-title {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-bottom: 1px solid #dde4ee;
  font-size: 13px;
  font-weight: 700;
}
.ocr-correction-image-body, .ocr-correction-board-body {
  min-height: 0;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 8px;
  overflow: auto;
}
.ocr-correction-image-stage {
  position: relative;
  width: min(100%, calc(100dvh - 154px));
  aspect-ratio: 1;
  background: #f4f6f9;
  border: 2px solid #263c5e;
}
.ocr-correction-image-stage img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.ocr-correction-no-preview {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #66758a;
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
}
.ocr-correction-image-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(9,minmax(0,1fr));
  grid-template-rows: repeat(9,minmax(0,1fr));
  overflow: hidden;
}
.ocr-correction-image-cell {
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-right: 1px solid rgba(31,53,84,.25) !important;
  border-bottom: 1px solid rgba(31,53,84,.25) !important;
  border-radius: 0 !important;
  background: transparent !important;
  align-self: stretch !important;
  justify-self: stretch !important;
  appearance: none;
  -webkit-appearance: none;
  transform: none !important;
}
.ocr-correction-image-cell:nth-child(9n/**/+3), .ocr-correction-image-cell:nth-child(9n/**/+6) {
  border-right-width: 2px !important;
  border-right-color: rgba(12,31,59,.65) !important;
}
.ocr-correction-image-cell:nth-child(n/**/+19):nth-child(-n/**/+27), .ocr-correction-image-cell:nth-child(n/**/+46):nth-child(-n/**/+54) {
  border-bottom-width: 2px !important;
  border-bottom-color: rgba(12,31,59,.65) !important;
}
.ocr-correction-image-cell.selected {
  outline: 3px solid #ff9d00;
  outline-offset: -3px;
  background: rgba(255,190,43,.18) !important;
}
.ocr-correction-board {
  width: min(100%, calc(100dvh - 154px));
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(9,minmax(0,1fr));
  grid-template-rows: repeat(9,minmax(0,1fr));
  grid-auto-flow: row;
  border: 3px solid #1c2c45;
  background: #fff;
  overflow: hidden;
  contain: layout paint;
}
.ocr-correction-cell {
  position: relative;
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-right: 1px solid #8b99ac !important;
  border-bottom: 1px solid #8b99ac !important;
  border-radius: 0 !important;
  display: grid;
  place-items: center;
  align-self: stretch !important;
  justify-self: stretch !important;
  background: #fff !important;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
  transform: none !important;
}
.ocr-correction-cell:nth-child(9n/**/+3), .ocr-correction-cell:nth-child(9n/**/+6) {
  border-right: 3px solid #1c2c45 !important;
}
.ocr-correction-cell:nth-child(n/**/+19):nth-child(-n/**/+27), .ocr-correction-cell:nth-child(n/**/+46):nth-child(-n/**/+54) {
  border-bottom: 3px solid #1c2c45 !important;
}
.ocr-correction-cell.selected {
  outline: 3px solid #ff9d00;
  outline-offset: -3px;
  z-index: 2;
}
.ocr-correction-cell.invalid {
  outline: 3px solid #d62f45;
  outline-offset: -3px;
  background: #fff0f2 !important;
  z-index: 3;
}
.ocr-correction-cell.invalid.selected {
  box-shadow: inset 0 0 0 2px #ff9d00;
}
.ocr-correction-cell .ocr-value {
  font-size: clamp(16px,4.2vmin,34px);
  line-height: 1;
  font-weight: 700;
}
.ocr-correction-cell.ocr-role-given .ocr-value {
  color: #111;
}
.ocr-correction-cell.ocr-role-solved .ocr-value {
  color: #1f67c9;
}
.ocr-correction-candidates {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3,1fr);
  grid-template-rows: repeat(3,1fr);
  font-size: clamp(6px,1.35vmin,11px);
  color: #40516b;
  line-height: 1;
}
.ocr-correction-candidates span {
  display: grid;
  place-items: center;
}
.ocr-correction-root.manual-entry-mode .ocr-correction-candidate-slot {
  min-width: 0;
  min-height: 0;
  border-radius: 3px;
  user-select: none;
  -webkit-user-select: none;
}
@media (hover: hover) and (pointer: fine) {
  .ocr-correction-root.manual-entry-mode .ocr-correction-mode-row {
    grid-template-columns: repeat(2,1fr);
  }
  .ocr-correction-root.manual-entry-mode .ocr-correction-mode-row [data-mode="candidate"] {
    display: none !important;
  }
  .ocr-correction-root.manual-entry-mode .ocr-correction-candidate-slot {
    cursor: pointer;
  }
  .ocr-correction-root.manual-entry-mode .ocr-correction-candidate-slot.candidate-present:hover {
    background: rgba(40,104,213,.16);
    color: #174b9e;
    font-weight: 800;
  }
  .ocr-correction-root.manual-entry-mode .ocr-correction-candidate-slot.candidate-absent:hover {
    background: rgba(214,47,69,.12);
    box-shadow: inset 0 0 0 1px rgba(214,47,69,.45);
  }
}
.ocr-correction-controls {
  min-height: 0;
  overflow: auto;
  padding: 10px;
  gap: 9px;
}
.ocr-correction-selected {
  padding: 8px 9px;
  border-radius: 9px;
  background: #eef4ff;
  color: #244979;
  font-weight: 700;
}
.ocr-correction-zoom {
  width: 100%;
  aspect-ratio: 2.5/1;
  min-height: 76px;
  border: 1px solid #b8c5d6;
  border-radius: 9px;
  background-color: #f4f6f9;
  background-repeat: no-repeat;
  image-rendering: auto;
}
.ocr-correction-mode-row {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 5px;
}
.ocr-correction-mode-row button.active {
  border-color: #245dc1;
  background: #dce9ff;
  color: #174b9e;
  font-weight: 700;
}
.ocr-correction-keypad {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 6px;
}
.ocr-correction-keypad button {
  min-height: 46px;
  font-size: 20px;
  font-weight: 700;
}
.ocr-correction-nav, .ocr-correction-edit-actions {
  display: grid;
  grid-template-columns: repeat(2,1fr);
  gap: 6px;
}
.ocr-correction-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  color: #5b6a80;
  font-size: 12px;
}
.ocr-correction-summary span {
  padding: 4px 7px;
  border-radius: 99px;
  background: #eef2f7;
}
.ocr-correction-hint {
  color: #65758c;
  font-size: 12px;
  line-height: 1.4;
}
@media (orientation: landscape) and (max-height: 800px) {
  .ocr-correction-header {
    min-height: 44px;
    padding: 5px 8px;
  }
  .ocr-correction-subtitle {
    display: none;
  }
  .ocr-correction-workspace {
    grid-template-columns: minmax(230px,34vw) minmax(250px,38vw) minmax(180px,1fr);
    gap: 6px;
    padding: 6px;
  }
  .ocr-correction-root.manual-entry-mode .ocr-correction-workspace {
    grid-template-columns: minmax(310px,1fr) minmax(190px,.48fr);
  }
  .ocr-correction-card-title {
    padding: 5px 8px;
  }
  .ocr-correction-image-body, .ocr-correction-board-body {
    padding: 4px;
  }
  .ocr-correction-image-stage, .ocr-correction-board {
    width: min(100%, calc(100dvh - 98px));
  }
  .ocr-correction-controls {
    padding: 6px;
    gap: 5px;
  }
  .ocr-correction-zoom {
    min-height: 54px;
  }
  .ocr-correction-keypad {
    grid-template-columns: repeat(5,1fr);
    gap: 4px;
  }
  .ocr-correction-keypad button {
    min-height: 34px;
    padding: 3px;
    font-size: 16px;
  }
  .ocr-correction-root button {
    min-height: 32px;
    padding: 4px 7px;
    font-size: 12px;
  }
}
@media (orientation: portrait), (max-width: 700px) {
  .ocr-correction-header {
    padding: 6px;
  }
  .ocr-correction-subtitle {
    display: none;
  }
  .ocr-correction-header-actions .ocr-correction-fullscreen {
    display: none;
  }
  .ocr-correction-workspace {
    display: block;
    overflow: auto;
    padding: 6px;
  }
  .ocr-correction-card {
    min-height: auto;
    margin-bottom: 8px;
  }
  .ocr-correction-root.manual-entry-mode .ocr-correction-board-card {
    margin-top: 0;
  }
  .ocr-correction-image-body, .ocr-correction-board-body {
    flex: none;
    overflow: visible;
    height: min(94vw,430px);
    min-height: min(94vw,430px);
  }
  .ocr-correction-image-stage, .ocr-correction-board {
    width: min(94vw,430px);
  }
  .ocr-correction-controls {
    overflow: visible;
  }
  .ocr-correction-zoom {
    max-height: 130px;
  }
  .ocr-correction-keypad {
    grid-template-columns: repeat(5,1fr);
  }
  .ocr-correction-keypad button {
    min-height: 42px;
  }
}
/* 深色与高对比主题。 */
/* 深色主题下覆盖 OCR 校正的基础分析画布。 */
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"]) .ocr-correction-root {
  background: var(--bg) !important;
  color: var(--ink) !important;
  color-scheme: dark;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"]) :is(
  .ocr-correction-header, .ocr-correction-card
) {
  border-color: var(--border) !important;
  background: var(--surface) !important;
  color: var(--ink) !important;
  box-shadow: none !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"]) :is(
  .ocr-correction-subtitle, .ocr-correction-hint, .ocr-correction-summary, .ocr-correction-no-preview
) {
  color: var(--muted) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"]) .ocr-correction-card-title {
  border-color: var(--border) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"]) :is(
  .ocr-correction-image-stage, .ocr-correction-zoom
) {
  border-color: var(--border-strong) !important;
  background-color: var(--surface-muted) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"]) .ocr-correction-board {
  border-color: var(--board-grid-strong) !important;
  background: var(--board-grid-strong) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"]) .ocr-correction-cell {
  border-color: var(--board-grid) !important;
  background: var(--board-cell-bg) !important;
  color: var(--board-candidate) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-cell.invalid {
  outline-color: #ff6f7f !important;
  background: #3b2028 !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-cell:nth-child(9n/**/+3),
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-cell:nth-child(9n/**/+6),
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-cell:nth-child(n/**/+19):nth-child(-n/**/+27),
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-cell:nth-child(n/**/+46):nth-child(-n/**/+54) {
  border-color: var(--board-grid-strong) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-cell.ocr-role-given .ocr-value {
  color: var(--board-given) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-cell.ocr-role-solved .ocr-value {
  color: var(--board-solved) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-candidates {
  color: var(--board-candidate) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"]) :is(
  .ocr-correction-selected, .ocr-correction-summary span
) {
  background: var(--accent-faint) !important;
  color: var(--accent-strong) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-root button:not(:disabled):not(.primary):not(.ocr-correction-image-cell) {
  border-color: var(--border) !important;
  background: var(--surface-soft) !important;
  color: var(--ink) !important;
}
/*
 * 左侧原始对照图上方的 81 个按钮只负责命中格与点击转发，必须保持透明。
 * 深色主题的通用按钮底色若覆盖这些按钮，会把原图逐格遮住，最终只剩网格线。
 */
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-image-cell:not(.selected) {
  background: transparent !important;
  box-shadow: none !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-image-cell.selected {
  background: rgba(255,190,43,.18) !important;
  box-shadow: none !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-root button.primary:not(:disabled) {
  border-color: #6ea8ff !important;
  background: linear-gradient(180deg, #3978d3, #285ca8) !important;
  color: #ffffff !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-root button.danger-lite:not(:disabled) {
  border-color: #86454b !important;
  background: #352027 !important;
  color: #ffaaaa !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-mode-row button.active:not(:disabled) {
  border-color: #6ea8ff !important;
  background: var(--accent-faint) !important;
  color: var(--accent-strong) !important;
}
:root:is([data-yzf-theme="dark"], [data-yzf-theme="system"][data-yzf-resolved-theme="dark"])
.ocr-correction-root button:disabled {
  border-color: var(--border) !important;
  background: var(--surface-muted) !important;
  color: var(--muted) !important;
  opacity: .62;
}
:root[data-yzf-theme="contrast"] .ocr-correction-root {
  background: #ffffff !important;
  color: #000000 !important;
}
:root[data-yzf-theme="contrast"] :is(.ocr-correction-header, .ocr-correction-card, .ocr-correction-image-stage, .ocr-correction-zoom) {
  border: 2px solid #000000 !important;
  background-color: #ffffff !important;
  color: #000000 !important;
  box-shadow: none !important;
}
:root[data-yzf-theme="contrast"] .ocr-correction-board {
  border-color: #000000 !important;
}
:root[data-yzf-theme="contrast"] .ocr-correction-cell {
  border-color: #000000 !important;
  background: #ffffff !important;
}
:root[data-yzf-theme="contrast"] .ocr-correction-cell.ocr-role-given .ocr-value {
  color: #000000 !important;
}
:root[data-yzf-theme="contrast"] .ocr-correction-cell.ocr-role-solved .ocr-value {
  color: #0037c5 !important;
}
:root[data-yzf-theme="contrast"] :is(.ocr-correction-selected, .ocr-correction-summary span) {
  border: 1px solid #000000;
  background: #ffffff !important;
  color: #000000 !important;
}
