:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-sub: #f7f7f7;
  --line: #d6d6d6;
  --line-soft: #e0e0e0;
  --btn-line: #949494;
  --text: #1f1f1f;
  --sub: #5c5c5c;
  --accent: #1f5fcc;       /* アクセントの青 */
  --accent-text: #ffffff;
  --norm-bg: #e6f0fc;      /* 全角・半角を統一して変えた箇所 */
  --norm-line: #2b6cb0;
  --edit-bg: #e1f3e7;      /* 自分で直した箇所 */
  --edit-line: #1e7a45;
  --glow-bg: #ffdb5c;      /* 選んだ箇所 */
  --glow-line: #c99700;
  --hl-line: #d9a400;
  --warn-bg: #fff4e2;
  --warn-line: #b86a00;
  --warn-text: #7a4500;
  --ok: #1e7a45;
  --error-bg: #ffe066;     /* エラーの帯 */
  --error-line: #d9b300;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Noto Sans JP', 'Noto Sans', 'Yu Gothic UI', sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6;
  display: flex; flex-direction: column;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }

.btn {
  border: 1px solid var(--btn-line); background: var(--panel); border-radius: 4px;
  height: 36px; padding: 0 14px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: #f2f2f2; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 500; }
.btn.primary:hover { background: #184ca3; border-color: #184ca3; }
.btn.big { height: 44px; padding: 0 28px; font-size: 15px; }
.btn.small { height: 32px; padding: 0 8px; gap: 4px; }
.btn.strong { border-color: var(--sub); font-weight: 700; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* エラーの帯（黄色地に黒文字） */
.error-band {
  flex: none; min-height: 64px; padding: 10px 24px; display: flex; gap: 12px; align-items: center;
  background: var(--error-bg); border-bottom: 1px solid var(--error-line); color: #1a1a1a;
}
.error-band .ic { flex: none; }
.error-band #error-text { flex: 1 1 auto; font-size: 15px; font-weight: 500; }
.error-band .btn { height: 44px; padding: 0 20px; border-color: #6b6b6b; background: transparent; color: #1a1a1a; font-weight: 500; }
.error-band .btn:hover { background: rgba(0, 0, 0, .06); }

/* 画面1 */
.screen-load { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 24px; }
.dropzone {
  flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  border: 1.5px dashed #bdbdbd; border-radius: 4px; background: #fafafa; text-align: center; padding: 24px;
}
.dropzone.over { border-color: var(--accent); background: #eef3fc; }
.dz-main { font-size: 20px; font-weight: 500; line-height: 1.4; margin: 0; }
.dz-sub { color: var(--sub); margin: 0; font-size: 14px; line-height: 1.5; }
.dropzone .btn { margin-top: 8px; }

/* 画面2 */
.screen-check { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; height: 52px; padding: 0 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: none;
}
.vsep { width: 1px; height: 24px; background: var(--line); }
.spacer { flex: 1; }
.progress-wrap { display: flex; align-items: center; gap: 10px; }
.progress { white-space: nowrap; }
.progress strong { font-size: 16px; font-weight: 700; }
.bar { width: 120px; height: 6px; border-radius: 3px; background: #e3e3e3; overflow: hidden; display: block; }
.bar i { display: block; height: 6px; width: 0; background: #3a3a3a; }
.bar.full i { background: var(--ok); }
#done {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--ok);
  border-radius: 4px; background: #e9f6ee; color: #17633a; font-size: 14px; font-weight: 700;
}
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; padding: 0 4px; }
.switch input { position: absolute; opacity: 0; }
.track { width: 36px; height: 20px; background: #9a9a9a; border-radius: 10px; position: relative; transition: background .15s; }
.track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + .track { background: var(--norm-line); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--text); outline-offset: 2px; }

.cols { flex: 1; min-height: 0; display: grid; grid-template-columns: 460px minmax(0, 1fr) 440px; }
.col { min-height: 0; overflow: auto; }
.col-left { display: flex; flex-direction: column; overflow: hidden; border-right: 1px solid var(--line); background: #ececec; }
.img-tools { display: flex; gap: 4px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; flex: none; }
.pdf-page { height: 32px; border: 1px solid var(--btn-line); border-radius: 4px; background: var(--panel); padding: 0 8px; }
.viewport { flex: 1; min-height: 0; overflow: auto; background: #ececec; position: relative; }
.stage { position: relative; margin: 0 auto; }
.content { position: absolute; left: 50%; top: 50%; transform-origin: center center; }
.content img { display: block; width: 100%; height: 100%; user-select: none; background: #fff; box-shadow: 0 0 0 1px #d3cec0; }
.hl {
  position: absolute; border: 2px solid var(--hl-line); background: rgba(255, 214, 0, .28);
  border-radius: 2px; pointer-events: none;
}

/* 中央 */
.col-center { background: #fff; border-right: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.col-right { background: var(--panel-sub); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.block {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 12px;
  display: flex; gap: 12px; cursor: pointer;
}
.block.sel { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.block-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.block-text { font-size: 16px; line-height: 1.8; white-space: pre-wrap; word-break: break-word; outline: none; min-height: 1.8em; cursor: text; }
.block-actions { flex: 0 0 158px; display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.block-actions .btn { height: 32px; padding: 0 10px; }
.block-actions .btn.manual { color: #6b6b6b; border: 1px dashed #b5b5b5; background: transparent; }
.unres {
  align-self: flex-start; display: inline-flex; align-items: center; height: 26px; padding: 0 8px;
  border: 1px solid var(--warn-line); border-radius: 4px; background: var(--warn-bg); color: var(--warn-text); font-weight: 500;
}
.removed-note { margin: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-sub); color: var(--sub); }
.chg-norm { background: var(--norm-bg); border-bottom: 2px dotted var(--norm-line); padding: 0 1px; }
.chg-edit { background: var(--edit-bg); border-bottom: 2px solid var(--edit-line); padding: 0 1px; }
.glow { background: var(--glow-bg); box-shadow: 0 0 0 1px var(--glow-line); border-radius: 2px; padding: 0 1px; }

/* 右 */
.empty { color: var(--sub); text-align: center; padding: 24px 8px; }
.item { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.item.sel { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.item .top { display: flex; gap: 10px; align-items: stretch; }
.item .crop-box {
  flex: 0 0 96px; height: 56px; display: flex; align-items: center; justify-content: center; overflow: hidden;
  border: 1px solid #d3cec0; border-radius: 2px; background: #fffdf6;
}
.item .crop { max-width: 100%; max-height: 100%; object-fit: contain; }
.item .info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; justify-content: space-between; gap: 4px; }
.item .read { font-family: 'Noto Sans Mono', 'Noto Sans JP', monospace; font-size: 22px; font-weight: 500; line-height: 1.3; word-break: break-all; margin: 0; }
.item .meta { display: flex; flex-wrap: wrap; align-items: center; column-gap: 10px; row-gap: 4px; color: var(--sub); }
.item .reason { display: inline-flex; align-items: center; gap: 4px; }
.item .alts { display: inline-flex; align-items: center; gap: 6px; }
.item .alts .btn { height: 26px; padding: 0 6px; font-family: 'Noto Sans Mono', 'Noto Sans JP', monospace; }
.item .actions { display: flex; gap: 8px; }
.item .retype {
  flex: 1 1 auto; min-width: 0; height: 36px; border: 1px solid var(--btn-line); border-radius: 4px; padding: 0 10px; background: var(--panel);
  font-family: 'Noto Sans Mono', 'Noto Sans JP', monospace;
}
.item.done { flex-direction: row; align-items: center; gap: 10px; padding: 6px 10px; border-color: var(--line-soft); background: #efefef; }
.item.done .crop-box { flex: 0 0 104px; height: 32px; background: #f7f7f4; border-color: var(--line); }
.item.done .final { flex: 1 1 auto; min-width: 0; font-family: 'Noto Sans Mono', 'Noto Sans JP', monospace; font-size: 15px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.done .state { display: inline-flex; align-items: center; gap: 4px; color: var(--sub); white-space: nowrap; }
.item.done .btn { height: 32px; padding: 0 10px; }
.divider { height: 1px; margin: 4px 0; background: var(--line); flex: none; }

/* 読み取り中 */
.reading { position: fixed; inset: 0; background: rgba(20, 20, 20, .62); z-index: 40; display: flex; align-items: center; justify-content: center; }
.reading-box { text-align: center; color: #fff; font-weight: 500; }
.reading-box p { margin: 16px 0 0; font-size: 16px; }
.spinner { width: 40px; height: 40px; border: 3px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin 0.9s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ポップアップ */
.modal-back { position: fixed; inset: 0; background: rgba(20, 20, 20, .5); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; }
#confirm-modal { z-index: 45; background: rgba(20, 20, 20, .45); }
.chart-modal {
  background: var(--panel); border: 1px solid #c8c8c8; border-radius: 4px; width: min(1120px, 100%); height: min(720px, 100%);
  display: flex; flex-direction: column; overflow: hidden;
}
.chart-head { flex: none; height: 52px; display: flex; align-items: flex-end; justify-content: space-between; padding: 0 12px 0 16px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; height: 52px; align-items: flex-end; }
.tabs button {
  height: 44px; padding: 0 16px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: transparent;
  color: var(--sub); font-weight: 500; font-size: 15px; cursor: pointer;
}
.tabs button.on { color: var(--accent); font-weight: 700; border-bottom-color: var(--accent); }
.close {
  align-self: center; width: 36px; height: 36px; padding: 0; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--btn-line); border-radius: 4px; background: var(--panel); cursor: pointer;
}
.close:hover { background: #f2f2f2; }
.chart-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 420px; }
.chart-preview-wrap { min-width: 0; min-height: 0; overflow: auto; background: #f2f2f2; border-right: 1px solid var(--line); padding: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.chart-preview { background: #fff; border: 1px solid var(--line); padding: 24px; overflow: auto; max-width: 100%; color: #1f1f1f; }
.chart-preview svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.chart-note { color: var(--warn-text); font-size: 12px; margin: 0; }
.chart-edit { display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 0; overflow: auto; padding: 16px; }
.chart-edit hr { border: 0; height: 1px; background: var(--line-soft); margin: 0; flex: none; }
.chart-edit .two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; color: #3a3a3a; }
.field input, .table-style input[type=text], .table-style input[type=number] {
  height: 34px; width: 100%; min-width: 0; border: 1px solid var(--btn-line); border-radius: 4px; padding: 0 10px; background: var(--panel);
}
.grid { display: grid; gap: 4px; }
.grid input { height: 34px; min-width: 0; width: 100%; border: 1px solid #bdbdbd; border-radius: 4px; padding: 0 8px; background: #fff; text-align: center; }
.grid input.head { font-weight: 700; background: #f2f2f2; }
.table-style { display: flex; flex-direction: column; gap: 8px; }
.table-style hr { margin-bottom: 4px; }
.srow { display: flex; align-items: center; gap: 8px; color: #3a3a3a; }
.srow > span:first-child { flex: 0 0 104px; }
.srow input[type=color] { flex: 0 0 34px; width: 34px; height: 34px; padding: 2px; border: 1px solid var(--btn-line); border-radius: 4px; background: #fff; cursor: pointer; }
.srow .mono { font-family: 'Noto Sans Mono', monospace; }
.srow input[type=text].mono { flex: 1 1 auto; }
.srow input.num { width: 88px; flex: none; text-align: right; }
.srow .px { flex: none; }
.seg { flex: 1 1 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.seg button { height: 34px; border: 1px solid #bdbdbd; border-radius: 4px; background: #fff; cursor: pointer; }
.seg button[aria-checked="true"] { border: 2px solid var(--text); font-weight: 700; }
.grow { flex: 1 1 auto; }
.chart-foot { padding-top: 12px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; flex: none; }
.chart-foot .btn { height: 40px; padding: 0 20px; font-size: 14px; }

.confirm-box { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 24px; width: min(440px, 100%); display: flex; flex-direction: column; gap: 20px; }
.confirm-box p { margin: 0; font-size: 16px; font-weight: 500; line-height: 1.6; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.confirm-actions .btn { padding: 0 18px; }

/* 一瞬の表示 */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1f1f1f; color: #fff; padding: 12px 20px; border-radius: 4px; white-space: nowrap; }
