:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --panel-soft: #f0f4f1;
  --ink: #172025;
  --muted: #667176;
  --line: #d9e0dc;
  --accent: #137c72;
  --accent-strong: #0f625b;
  --accent-soft: #dff3ed;
  --amber: #b36a17;
  --danger: #b83a42;
  --shadow: 0 18px 50px rgba(20, 32, 34, 0.14);
  color-scheme: light;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Yu Gothic UI", "Meiryo", "Noto Sans JP", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) 30px;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #24322f;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.1;
}

.brand-subtitle {
  margin-top: 3px;
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 1px;
}

.divider {
  width: 1px;
  height: 28px;
  margin: 0 3px;
  background: var(--line);
  flex: 0 0 auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.btn:hover {
  border-color: #b9c8c2;
  background: #f9fbfa;
}

.btn:disabled {
  cursor: default;
  opacity: 0.45;
}

.btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

.btn.command {
  padding: 0 12px;
}

.btn.primary {
  padding: 0 14px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.btn.icon-btn {
  width: 36px;
  min-width: 36px;
  padding: 0;
}

.btn.compact {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
}

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

.btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(360px, 1fr) 292px;
  min-height: 0;
}

.page-panel,
.options-panel {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
}

.page-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
}

.object-panel-view {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--panel);
}

.object-panel-view[hidden] {
  display: none;
}

.object-panel-tools {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8faf9;
}

.object-order-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.object-order-actions .btn {
  width: 100%;
}

.object-list {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.object-list-empty {
  padding: 18px 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

.object-list-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  margin-bottom: 4px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: #fff;
  cursor: grab;
  user-select: none;
}

.object-list-item:hover {
  border-color: #c7d4cf;
  background: #f5f8f7;
}

.object-list-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.object-list-item.grouped {
  box-shadow: inset 3px 0 0 #6d7fba;
}

.object-list-item.drag-before {
  box-shadow: inset 0 3px 0 var(--accent);
}

.object-list-item.drag-after {
  box-shadow: inset 0 -3px 0 var(--accent);
}

.object-list-icon {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.object-list-icon svg {
  width: 16px;
  height: 16px;
}

.object-list-name {
  overflow: hidden;
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.object-list-level {
  color: var(--muted);
  font-size: 10px;
}

.options-panel {
  overflow-y: auto;
  border-left: 1px solid var(--line);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h1,
.section-title h2 {
  margin: 0;
  font-size: 15px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-actions,
.annotation-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.annotation-tools {
  margin: 0 0 10px;
}

.annotation-tool {
  color: var(--accent-strong);
}

.annotation-tool.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.text-format-controls {
  display: flex;
  gap: 4px;
  margin: 0 0 10px;
}

.format-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.page-list {
  position: relative;
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.selection-marquee {
  position: fixed;
  z-index: 30;
  border: 1px solid var(--accent);
  background: rgba(73, 179, 157, 0.16);
  pointer-events: none;
}

.page-panel-tools {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8faf9;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f0;
}

.segmented button {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.segmented button.active {
  background: #fff;
  color: var(--accent-strong);
  box-shadow: 0 1px 3px rgba(20, 32, 34, 0.12);
}

.selection-summary {
  min-height: 18px;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 800;
}

.document-item {
  position: relative;
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.document-item:hover {
  border-color: #aec4bd;
}

.document-item.selected {
  background: #f5fbf9;
}

.document-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(19, 124, 114, 0.14);
}

.document-item.drop-target {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(179, 106, 23, 0.14);
}

.document-item.drop-target.drop-before {
  box-shadow: 0 -4px 0 var(--amber), 0 0 0 2px rgba(179, 106, 23, 0.14);
}

.document-item.drop-target.drop-after {
  box-shadow: 0 4px 0 var(--amber), 0 0 0 2px rgba(179, 106, 23, 0.14);
}

.document-item.drop-target.drop-before::before,
.document-item.drop-target.drop-after::after {
  position: absolute;
  right: 8px;
  z-index: 4;
  padding: 1px 5px;
  border: 1px solid var(--amber);
  border-radius: 3px;
  background: #fffdf7;
  color: #805012;
  content: "ここに挿入";
  font-size: 10px;
  font-weight: 800;
}

.document-item.drop-target.drop-before::before { top: -22px; }
.document-item.drop-target.drop-after::after { bottom: -22px; }
}

.document-item.dragging,
.page-item.dragging {
  opacity: 0.58;
}

.document-item.cut-pending {
  opacity: 0.52;
}

.document-header {
  display: grid;
  grid-template-columns: 24px 58px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  cursor: pointer;
}

.document-thumb {
  display: grid;
  place-items: center;
  width: 58px;
  height: 76px;
  overflow: hidden;
  border: 1px solid #cdd8d4;
  border-radius: 6px;
  background: #f9faf9;
}

.document-thumb canvas {
  max-width: 100%;
  max-height: 100%;
}

.document-meta {
  min-width: 0;
}

.document-name {
  overflow: hidden;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-count {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.document-order-controls {
  display: grid;
  gap: 4px;
}

.document-order-controls .btn {
  width: 30px;
  min-width: 30px;
  min-height: 28px;
}

.document-range {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: #f8faf9;
}

.document-range input {
  min-height: 32px;
}

.extraction-help,
.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.selection-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.selection-actions .btn {
  width: 100%;
}

.preview-page-controls {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.document-range .btn {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
}

.page-item {
  display: grid;
  grid-template-columns: 28px 74px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  width: 100%;
  margin-bottom: 8px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.page-item:hover {
  border-color: #aec4bd;
}

.page-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(19, 124, 114, 0.14);
}

.page-item.selected {
  background: #f5fbf9;
}

.page-item.drop-target {
  border-color: var(--amber);
}

.page-check {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.thumb-wrap {
  display: grid;
  place-items: center;
  width: 74px;
  height: 96px;
  overflow: hidden;
  border: 1px solid #cdd8d4;
  border-radius: 6px;
  background: #f9faf9;
}

.thumb-wrap canvas {
  max-width: 100%;
  max-height: 100%;
}

.page-meta {
  min-width: 0;
}

.page-number {
  font-size: 13px;
  font-weight: 800;
}

.page-source {
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-rotation {
  margin-top: 6px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
}

.preview-panel {
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: #e8ece9;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid #ced8d4;
  background: #f8faf9;
}

.current-page {
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.zoom-control svg {
  width: 18px;
  height: 18px;
}

.zoom-control input {
  width: 150px;
  accent-color: var(--accent);
}

.preview-scroll {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 28px;
  touch-action: pan-y pinch-zoom;
}

.page-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 280px;
  min-height: 420px;
  margin: 0 auto;
}

.page-stage.has-page {
  min-width: 0;
  min-height: 0;
}

#previewCanvas {
  display: none;
  background: #fff;
  box-shadow: var(--shadow);
}

.annotation-layer {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  pointer-events: none;
  z-index: 4;
}

.highlight-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  display: none;
  overflow: hidden;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.highlight-layer .text-mark.highlight {
  position: absolute;
  border-radius: 2px;
}

.text-selection-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  display: none;
  pointer-events: none;
}

.text-selection-layer.active {
  display: block;
  pointer-events: auto;
  cursor: text;
  user-select: text;
}

.page-stage.annotation-interacting .text-selection-layer {
  visibility: hidden;
  pointer-events: none;
}

.text-selection-layer .direct-text-target {
  color: transparent;
  cursor: text;
  pointer-events: auto;
}

.text-selection-layer .direct-text-target:hover {
  outline: 1px solid rgba(19, 124, 114, 0.76);
  background: rgba(19, 124, 114, 0.1);
}

.direct-text-popover {
  width: min(320px, calc(100vw - 20px));
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.direct-text-popover p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.direct-text-fallback {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.direct-text-fallback select {
  width: 100%;
}

.direct-text-convert-field {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
}

.direct-text-convert-field select {
  width: 100%;
}

.direct-text-actions {
  margin-top: 8px;
}

.direct-text-guide {
  padding: 8px;
  border: 1px solid #c8d5d0;
  background: #f5f8f7;
}

.direct-text-format {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
}

.direct-text-format .button-row {
  align-items: center;
}

.direct-text-bold-option {
  display: flex;
  flex: 1 1 150px;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.direct-text-bold-option select {
  min-width: 0;
  width: 100%;
}

.compact-color {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.direct-text-font-hint {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.selection-status {
  min-height: 16px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.recovery-prompt {
  position: fixed;
  right: 16px;
  bottom: 42px;
  z-index: 70;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  width: min(520px, calc(100vw - 32px));
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
}

.recovery-prompt[hidden] {
  display: none;
}

.recovery-prompt > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.recovery-prompt strong {
  font-size: 13px;
}

.recovery-prompt span {
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 620px) {
  .recovery-prompt {
    grid-template-columns: 1fr 1fr;
  }

  .recovery-prompt > div {
    grid-column: 1 / -1;
  }
}

.text-selection-menu {
  position: fixed;
  z-index: 45;
  display: flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(20, 32, 34, 0.2);
}

.text-selection-menu button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
}

.text-selection-menu button:hover { background: var(--accent-soft); }
.text-selection-menu svg { width: 17px; height: 17px; }
.text-selection-menu input[type="color"] {
  width: 18px;
  min-width: 18px;
  height: 24px;
  min-height: 24px;
  margin: 3px 0;
  padding: 1px;
  border: 0;
  border-radius: 3px;
}

.text-selection-layer span {
    position: absolute;
    color: transparent;
    white-space: pre;
    line-height: 1;
    font-size: calc(var(--font-height, 1em) * var(--total-scale-factor, 1));
    font-kerning: none;
    text-size-adjust: none;
    transform: scaleX(var(--scale-x, 1));
    transform-origin: 0 0;
  }

.text-selection-layer span::selection {
  background: rgba(47, 112, 223, 0.44);
  color: transparent;
}

.shape-tool-menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: -4px 0 10px;
}

.shape-tool-menu[hidden] { display: none; }

.stamp-tool-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: -4px 0 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.stamp-tool-menu[hidden] { display: none; }

.stamp-add-button {
  grid-column: 1 / -1;
  justify-content: center;
}

.stamp-preset-item {
  position: relative;
  min-width: 0;
}

.stamp-preset {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}

.stamp-preset-item .stamp-preset {
  width: 100%;
  height: 100%;
  padding-bottom: 28px;
}

.stamp-preset-actions {
  position: absolute;
  right: 4px;
  bottom: 4px;
  display: flex;
  gap: 3px;
}

.stamp-preset-actions .btn {
  width: 24px;
  min-width: 24px;
  min-height: 22px;
  padding: 0;
  background: #fff;
}

.stamp-preset:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stamp-preset img {
  display: block;
  width: 100%;
  aspect-ratio: 18 / 7;
  object-fit: contain;
}

.annotation-option-label {
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

#annotationSection > #textSettingsSection {
  margin: 10px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}

.comment-color-swatches {
  display: flex;
  gap: 6px;
  margin: -2px 0 10px;
}

.comment-color-swatches[hidden] { display: none; }
.comment-color-swatches button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--swatch);
}

.shape-tool-menu .btn {
  justify-content: flex-start;
  gap: 6px;
  padding: 0 8px;
  font-size: 11px;
}

.direct-comment-editor {
  position: absolute;
  z-index: 5;
  min-width: 120px;
  max-width: 220px;
  padding: 5px 7px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  outline: 0;
  white-space: pre-wrap;
}

.crop-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  display: none;
  pointer-events: none;
}

.crop-shade {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 37, 0.26);
  pointer-events: none;
}

.crop-selection {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 9999px rgba(23, 32, 37, 0.24);
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}

.crop-handle {
  position: absolute;
  width: 13px;
  height: 13px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(20, 32, 34, 0.24);
  pointer-events: auto;
}

.crop-handle.nw {
  left: -7px;
  top: -7px;
  cursor: nwse-resize;
}

.crop-handle.ne {
  right: -7px;
  top: -7px;
  cursor: nesw-resize;
}

.crop-handle.sw {
  left: -7px;
  bottom: -7px;
  cursor: nesw-resize;
}

.crop-handle.se {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
}

.annotation {
  position: absolute;
  padding: 2px 4px;
  border: 1px dashed transparent;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  line-height: 1.25;
  white-space: pre;
  transform-origin: left top;
  pointer-events: auto;
  user-select: none;
}

.annotation:hover,
.annotation.active {
  border-color: var(--accent);
  background: rgba(223, 243, 237, 0.54);
}

.annotation.comment {
  max-width: 190px;
  padding: 5px 7px;
  border: 1px solid currentColor;
  white-space: pre-wrap;
}

.comment-pin {
  position: absolute;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid #9f7a20;
  border-radius: 3px;
  background: #fff3a3;
  color: #594616;
  cursor: pointer;
  pointer-events: auto;
}

.comment-pin::after { content: ""; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; }

.comment-popover {
  position: fixed;
  z-index: 60;
  width: min(300px, calc(100vw - 24px));
  padding: 10px;
  border: 1px solid #b59a54;
  border-radius: 6px;
  background: #fff9dc;
  box-shadow: 0 8px 24px rgba(20, 32, 34, 0.24);
}

.comment-popover-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; color: #594616; font-size: 12px; font-weight: 800; }
.comment-popover-head button { display:grid; place-items:center; width:26px; height:26px; border:0; background:transparent; color:inherit; }
.comment-popover textarea { min-height: 110px; margin: 0; background: #fffef6; }

.text-mark {
  position: absolute;
  z-index: 1;
  pointer-events: none;
}

.annotation-shape,
.annotation-freehand,
.annotation.comment,
.annotation {
  cursor: move;
}

.annotation-shape,
.annotation-freehand {
  position: absolute;
  z-index: 2;
  pointer-events: auto;
  touch-action: none;
}

.annotation-shape.active,
.annotation-freehand.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.annotation.active.multi-selected,
.annotation-shape.active.multi-selected,
.annotation-freehand.active.multi-selected,
.comment-pin.active.multi-selected {
  outline-color: #6d7fba;
}

.annotation-shape.highlight {
  border: 0;
}

.annotation-shape.ellipse {
  border-radius: 50%;
}

.shape-text-content {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  padding: 8px;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.25;
  pointer-events: none;
}

.shape-text-lines {
  display: block;
  width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.shape-text-editor {
  z-index: 7;
  display: block;
  width: 100%;
  height: 100%;
  resize: none;
  cursor: text;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: rgba(255, 255, 255, 0.2);
  caret-color: currentColor;
  pointer-events: auto;
  user-select: text;
}

.line-endpoint-handle {
  position: absolute;
  z-index: 7;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-strong), 0 1px 4px rgba(20, 32, 34, 0.25);
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}

.line-endpoint-handle.start {
  background: #fff;
  border-color: var(--accent);
}

.shape-text-options {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.shape-text-options-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.shape-text-options-head strong { font-size: 12px; }
.shape-text-options-head span { color: var(--muted); font-size: 11px; }

.annotation-resize-handle {
  position: absolute;
  z-index: 6;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(20, 32, 34, 0.25);
}

.annotation-resize-handle.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.annotation-resize-handle.n { left: calc(50% - 6px); top: -7px; cursor: ns-resize; }
.annotation-resize-handle.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.annotation-resize-handle.e { right: -7px; top: calc(50% - 6px); cursor: ew-resize; }
.annotation-resize-handle.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.annotation-resize-handle.s { left: calc(50% - 6px); bottom: -7px; cursor: ns-resize; }
.annotation-resize-handle.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.annotation-resize-handle.w { left: -7px; top: calc(50% - 6px); cursor: ew-resize; }

.annotation-rotate-handle {
  position: absolute;
  left: calc(50% - 7px);
  top: -34px;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: grab;
  pointer-events: auto;
  z-index: 5;
}

.annotation-rotate-handle::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 12px;
  width: 2px;
  height: 18px;
  background: var(--accent);
}

.annotation-rotate-handle:active { cursor: grabbing; }

.annotation-vertex-handle,
.callout-tip-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #e05b45;
  box-shadow: 0 0 0 1px #9f3325;
  cursor: move;
  pointer-events: auto;
  z-index: 6;
}

.callout-tip-handle {
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-strong);
}

#previewCanvas.text-placement { cursor: text; }
#previewCanvas.insert-placement { cursor: crosshair; }
#previewCanvas.redaction-placement { cursor: crosshair; }

.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 142px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(20, 32, 34, 0.2);
}

.context-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  text-align: left;
}

.context-menu button:hover { background: var(--accent-soft); }
.context-menu button.danger { color: var(--danger); }
.context-menu button:disabled { opacity: 0.42; pointer-events: none; }
.context-menu svg { width: 16px; height: 16px; }

.annotation-freehand {
  overflow: visible;
}

.redaction-box {
  position: absolute;
  z-index: 2;
  min-width: 4px;
  min-height: 4px;
  border: 1px solid #111;
  background: #000;
  cursor: move;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.redaction-box:hover,
.redaction-box.active {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  width: min(360px, 86%);
  min-height: 240px;
  border: 1px dashed #b7c4bf;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

.empty-state svg {
  width: 32px;
  height: 32px;
}

.empty-state p {
  max-width: 300px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.55;
}

.empty-state.error {
  border-color: rgba(184, 58, 66, 0.6);
  background: rgba(255, 246, 246, 0.9);
  color: var(--danger);
}

.option-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.section-title svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.section-title .section-action {
  margin-left: auto;
}

.page-number-preview {
  position: absolute;
  z-index: 2;
  padding: 0;
  border: 0;
  outline: 1px dashed transparent;
  color: #1f292d;
  font-family: Arial, sans-serif;
  line-height: 1;
  white-space: nowrap;
  cursor: move;
  pointer-events: auto;
  user-select: none;
  touch-action: none;
}

.page-number-preview:hover,
.page-number-preview.dragging {
  outline-color: var(--accent);
  background: rgba(255, 255, 255, 0.78);
}

.watermark-preview {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #1f292d;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  white-space: pre-wrap;
  pointer-events: none;
  user-select: none;
}

.watermark-preview.diagonal {
  transform: rotate(-28deg);
}

img.watermark-preview {
  object-fit: contain;
}

.page-number-tokens {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.token-btn {
  gap: 6px;
  width: 100%;
  min-width: 0;
  font-size: 11px;
}

.token-btn code {
  font-size: 12px;
  font-weight: 900;
}

.status-pill {
  margin-left: auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.status-pill.ok {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-pill.warn {
  background: #fff1db;
  color: var(--amber);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  font-weight: 800;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
}

input[type="color"] {
  min-height: 34px;
  padding: 3px;
}

.color-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.color-picker-trigger {
  width: 34px;
  height: 28px;
  padding: 4px;
  border: 1px solid #aebbb7;
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}

.color-picker-trigger::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
  background: var(--selected-color, #000);
}

.color-picker-trigger.none::before {
  background: linear-gradient(135deg, #fff 43%, #d64045 44%, #d64045 56%, #fff 57%);
}

.color-palette {
  position: fixed;
  z-index: 80;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 238px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(20, 32, 34, 0.22);
}

.color-palette button,
.color-palette input[type="color"] {
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  margin: 0;
  padding: 0;
  border: 1px solid #aebbb7;
  border-radius: 4px;
  background: var(--swatch, #fff);
  cursor: pointer;
}

.color-palette button.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.color-palette input[type="color"] {
  background: conic-gradient(#e33, #ed3, #3b6, #39e, #83e, #e33);
}

.color-palette input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.color-palette input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 2px; }

.color-palette .no-color {
  display: grid;
  place-items: center;
  color: #b83a42;
  background: #fff;
}

.color-palette .no-color svg { width: 15px; height: 15px; }

.color-picker.compact .color-picker-trigger { width: 22px; height: 24px; padding: 3px; }
.text-selection-menu .color-picker { align-self: center; }

#annotationStrokeGrid,
#annotationFillGrid,
#shapeOpacityGrid,
#arrowOptions,
#calloutOptions,
#polygonOptions,
#freehandOptions,
#imageOptions,
#commentOptions,
#textBoxOptions {
  padding-top: 8px;
  border-top: 1px solid #e5ece9;
}

input[type="range"] {
  display: block;
  width: 100%;
  min-height: 24px;
  padding: 0;
  accent-color: var(--accent);
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.field-grid {
  display: grid;
  gap: 10px;
}

.field-grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.button-row {
  display: flex;
  gap: 8px;
}

.grow {
  flex: 1;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

#statusText {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-version {
  margin-left: auto;
  white-space: nowrap;
}

#busyProgress {
  display: none;
  width: 120px;
  height: 8px;
  margin-left: 0;
  accent-color: var(--accent);
}

.busy #busyProgress {
  display: block;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 44px;
  z-index: 10;
  display: none;
  max-width: min(560px, calc(100vw - 28px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 14px 40px rgba(20, 32, 34, 0.18);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
  transform: translateX(-50%);
}

.toast.show {
  display: block;
}

.toast.error {
  border-color: rgba(184, 58, 66, 0.35);
  background: #fff6f6;
  color: var(--danger);
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 37, 0.38);
}

.dialog-backdrop.hidden {
  display: none;
}

.dialog-backdrop[hidden] {
  display: none;
}

.password-dialog {
  width: min(420px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.password-dialog h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.password-dialog p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
}

.dialog-error {
  min-height: 20px;
  margin: 2px 0 12px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.local-font-dialog {
  display: grid;
  gap: 10px;
  width: min(520px, 100%);
}

.local-font-dialog h2,
.local-font-dialog p,
.local-font-dialog .dialog-error {
  margin: 0;
}

.local-font-dialog select {
  width: 100%;
  min-height: 280px;
  font-family: "Segoe UI", sans-serif;
}

.drop-active {
  outline: 3px solid rgba(19, 124, 114, 0.28);
  outline-offset: -3px;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100%;
    height: auto;
    grid-template-rows: auto auto 30px;
  }

  .topbar,
  .workspace {
    align-items: stretch;
  }

  .topbar {
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .page-panel,
  .options-panel {
    border: 0;
  }

  .page-panel {
    max-height: 330px;
    border-bottom: 1px solid var(--line);
  }

  .preview-panel {
    min-height: 560px;
  }
}


/* Online trial: output controls and print output are intentionally unavailable. */
.trial-badge {
  align-items: center;
  background: #fff7df;
  border: 1px solid #e7b94f;
  border-radius: 10px;
  color: #684b05;
  display: inline-flex;
  gap: 8px;
  padding: 6px 10px;
}

.trial-badge > span {
  display: grid;
  line-height: 1.15;
}

.trial-badge small {
  font-size: 11px;
  margin-top: 3px;
}

.trial-notice {
  background: #fff7df;
  border-top: 1px solid #e7b94f;
  color: #684b05;
  font-size: 12px;
  padding: 7px 16px;
  text-align: center;
}

.trial-mode .option-section:has(#passwordEnabled),
.trial-mode .option-section:has(#compressionMode),
.trial-mode .option-section:has(#watermarkEnabled),
.trial-mode .option-section:has(#metadataCleanEnabled) {
  display: none;
}

.trial-mode .page-stage::after {
  color: rgba(155, 101, 0, 0.25);
  content: "ONLINE TRIAL  •  書き出し不可";
  font-size: clamp(14px, 2.2vw, 28px);
  font-weight: 800;
  left: 50%;
  letter-spacing: 0.08em;
  pointer-events: none;
  position: absolute;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  top: 50%;
  transform: translate(-50%, -50%) rotate(-24deg);
  white-space: nowrap;
  z-index: 30;
}

@media print {
  .trial-mode * {
    display: none !important;
  }

  .trial-mode::before {
    content: "オンライン体験版は印刷できません。";
    display: block !important;
    font: 18px sans-serif;
    padding: 40px;
  }
}
