:root {
  color-scheme: dark;
  --bg: #151a1d;
  --panel: #20272a;
  --panel-soft: #2a3336;
  --ink: #eef7f3;
  --muted: #a8b9b4;
  --line: #38464a;
  --accent: #69e6c1;
  --accent-strong: #98f5d9;
  --amber: #d7b25a;
  --danger: #ff8a7a;
  --shadow: 0 22px 48px rgba(0, 0, 0, 0.42);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:not(:disabled):hover {
  border-color: #71d9bc;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(240px, 320px) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(32, 39, 42, 0.96);
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(105, 230, 193, 0.48);
  border-radius: var(--radius);
  background: #263a37;
  object-fit: cover;
}

.brand h1,
.panel-heading h2,
.settings-section h2,
.empty-state h2 {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar,
.tool-strip,
.page-actions,
.page-meter,
.button-grid {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar.compact {
  gap: 6px;
}

.searchbar {
  min-width: 0;
}

.searchbar input {
  width: 100%;
  min-width: 84px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151a1d;
  padding: 0 10px;
  color: var(--ink);
}

.compact-select {
  height: 38px;
  min-width: 74px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151a1d;
  color: var(--ink);
  padding: 0 8px;
  font-weight: 700;
}

.searchbar output,
#searchCount,
#annotationCount,
#reviewStatus,
#clipboardStatus,
#signatureStatus,
#ocrStatus {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.command,
.tool,
.icon-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  font-weight: 650;
  white-space: nowrap;
}

.command {
  padding: 0 12px;
}

.command.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #10201d;
}

.command.danger-action {
  border-color: var(--danger);
  background: var(--danger);
  color: #1f0d0b;
}

.command.full {
  width: 100%;
}

.ocr-output {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151a1d;
  color: var(--ink);
  padding: 10px;
  line-height: 1.45;
}

.button-grid {
  flex-wrap: wrap;
}

.button-grid .command {
  flex: 1 1 86px;
}

.compact-buttons {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
}

.compact-buttons .icon-button {
  width: 100%;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.icon-button.danger,
.danger {
  color: var(--danger);
}

.tool-strip {
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(21, 26, 29, 0.96);
}

.tool {
  min-width: 86px;
  padding: 0 10px;
}

.tool.active {
  border-color: var(--accent);
  background: #243d38;
  color: var(--accent-strong);
}

.divider {
  width: 1px;
  height: 24px;
  background: var(--line);
}

svg.lucide {
  width: 18px;
  height: 18px;
  stroke-width: 2.1;
  flex: 0 0 auto;
}

.main-layout {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr) 292px;
  min-height: 0;
}

.left-panel,
.right-panel {
  min-height: 0;
  overflow: auto;
  border-color: var(--line);
  background: var(--panel);
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  border-left: 1px solid var(--line);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px;
}

.panel-heading.inline {
  padding: 0;
}

.panel-heading h2,
.settings-section h2 {
  font-size: 14px;
  line-height: 1.25;
}

#pageCountBadge {
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.page-actions {
  padding: 0 14px 12px;
}

.page-range-panel {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
  border-bottom: 1px solid var(--line);
}

.page-range-panel .field {
  gap: 6px;
}

.page-range-panel input {
  height: 36px;
}

.page-range-actions {
  display: grid;
  gap: 8px;
}

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

.page-selection-tools .command {
  min-width: 0;
  min-height: 34px;
  padding: 0 8px;
}

#pageSelectionStatus {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.page-range-actions .command {
  min-width: 0;
  min-height: 36px;
  padding: 0 8px;
}

.page-range-actions .command span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.thumbnail-list {
  display: grid;
  gap: 10px;
  padding: 0 14px 18px;
}

.thumbnail-item {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #1b2225;
  text-align: left;
}

.thumbnail-item.active {
  border-color: var(--accent);
  background: #263a37;
}

.thumbnail-item.selected-page {
  border-color: var(--accent-strong);
  background: #203c36;
  box-shadow: inset 3px 0 0 var(--accent);
}

.thumbnail-check {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #10201d;
  font-size: 11px;
  font-weight: 900;
}

.thumbnail-item.selected-page .thumbnail-check {
  display: inline-flex;
}

.thumbnail-item canvas {
  width: 52px;
  height: 68px;
  border: 1px solid #536166;
  background: #ffffff;
  object-fit: contain;
}

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

.thumbnail-meta strong,
.thumbnail-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thumbnail-meta strong {
  font-size: 13px;
}

.thumbnail-meta span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.canvas-scroll {
  position: relative;
  min-height: 0;
  overflow: auto;
  padding: 28px;
  background:
    linear-gradient(90deg, rgba(105, 230, 193, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(105, 230, 193, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
}

.empty-state {
  display: grid;
  min-height: calc(100vh - 160px);
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.empty-state h2 {
  color: var(--ink);
  font-size: 22px;
}

.empty-state p {
  max-width: 420px;
  margin: 0;
  line-height: 1.6;
}

.empty-icon {
  display: grid;
  width: 66px;
  height: 66px;
  place-items: center;
  border: 1px solid rgba(105, 230, 193, 0.42);
  border-radius: var(--radius);
  background: #263a37;
  color: var(--accent);
}

.empty-icon svg {
  width: 30px;
  height: 30px;
}

.page-stage {
  display: flex;
  min-width: max-content;
  justify-content: center;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  will-change: opacity, transform;
}

.page-stage.hidden,
.hidden {
  display: none;
}

.page-stage.turn-exit-next {
  opacity: 0.18;
  transform: translateY(-22px) scale(0.985);
}

.page-stage.turn-exit-prev {
  opacity: 0.18;
  transform: translateY(22px) scale(0.985);
}

.page-stage.turn-enter-next {
  opacity: 0;
  transform: translateY(22px) scale(0.985);
}

.page-stage.turn-enter-prev {
  opacity: 0;
  transform: translateY(-22px) scale(0.985);
}

.page-surface {
  position: relative;
  box-shadow: var(--shadow);
  background: #ffffff;
}

#pdfCanvas {
  display: block;
}

#vectorLayer,
#annotationLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#vectorLayer {
  pointer-events: none;
  overflow: visible;
}

#annotationLayer {
  pointer-events: auto;
}

.annotation-item {
  position: absolute;
  user-select: none;
  touch-action: none;
}

.annotation-item.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.annotation-text {
  min-width: 44px;
  min-height: 24px;
  padding: 5px 7px;
  background: rgba(21, 26, 29, 0.72);
  white-space: pre-wrap;
  line-height: 1.3;
}

.annotation-stamp {
  display: grid;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: var(--radius);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-align: center;
}

.annotation-highlight {
  border-radius: 3px;
}

.annotation-rect {
  background: transparent;
}

.annotation-media {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.vector-annotation {
  pointer-events: stroke;
}

.vector-annotation.selected {
  filter: drop-shadow(0 0 0 var(--accent)) drop-shadow(0 0 5px rgba(105, 230, 193, 0.8));
}

.resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #10201d;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.42);
}

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

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

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

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

.compact-actions .command {
  min-height: 34px;
  padding: 0 8px;
}

.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.page-jump input {
  width: 58px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151a1d;
  color: var(--ink);
  text-align: center;
  font-weight: 700;
}

.right-panel {
  padding-bottom: 18px;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.field,
.field-grid {
  display: grid;
  gap: 7px;
}

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

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151a1d;
  color: var(--ink);
}

.field input {
  height: 38px;
  padding: 0 10px;
}

.field input[type="color"] {
  padding: 4px;
}

.field textarea {
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
}

.page-meter {
  justify-content: space-between;
}

#pageIndicator,
#zoomValue {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.review-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.compact-list {
  display: grid;
  gap: 8px;
}

.compact-list:empty::before {
  content: "まだありません";
  color: var(--muted);
  font-size: 13px;
}

.list-button {
  display: grid;
  width: 100%;
  gap: 4px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #1b2225;
  text-align: left;
}

.list-button.active {
  border-color: var(--accent);
  background: #263a37;
}

.list-button strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-button span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.check-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.stamp-preset {
  min-height: 38px;
  border-radius: var(--radius);
  font-weight: 800;
}

.stamp-preset.active {
  border-color: var(--accent);
  background: #243d38;
  color: var(--accent-strong);
}

.signature-canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfa;
  touch-action: none;
}

.field-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.image-tray {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.image-tray.empty {
  display: none;
}

.image-tray-item {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 1 / 1;
}

.image-tray-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.image-tray-pick {
  display: block;
  width: 100%;
  height: 100%;
  padding: 4px;
  border: 0;
  border-radius: 0;
  background-color: #20272a;
  background-image:
    linear-gradient(45deg, #313c3f 25%, transparent 25%),
    linear-gradient(-45deg, #313c3f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #313c3f 75%),
    linear-gradient(-45deg, transparent 75%, #313c3f 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.image-tray-pick img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-tray-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(16, 24, 22, 0.78);
  color: var(--ink);
  font-size: 13px;
  line-height: 1;
}

#annotationLayer.show-transparency .annotation-image,
#annotationLayer.show-transparency .annotation-signature {
  background-image:
    linear-gradient(45deg, rgba(120, 140, 135, 0.55) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(120, 140, 135, 0.55) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(120, 140, 135, 0.55) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(120, 140, 135, 0.55) 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
}

.search-marker {
  pointer-events: none;
  fill: rgba(159, 243, 215, 0.22);
  stroke: rgba(159, 243, 215, 0.7);
  stroke-width: 1.5;
}

.search-marker.active {
  fill: rgba(105, 230, 193, 0.34);
  stroke: rgba(105, 230, 193, 0.95);
  stroke-width: 2.5;
}

.modal {
  width: min(560px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
  color: var(--ink);
}

.modal.wide {
  width: min(860px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.66);
}

.modal-card {
  display: grid;
  gap: 18px;
  margin: 0;
  padding: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-heading {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.modal-heading > svg {
  width: 42px;
  height: 42px;
  padding: 9px;
  border: 1px solid rgba(105, 230, 193, 0.42);
  border-radius: var(--radius);
  background: #263a37;
  color: var(--accent);
}

.modal-heading h2,
.preview-details h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.modal-heading p,
.preview-details p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

#confirmMessage {
  white-space: pre-line;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.save-preview-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 260px;
  gap: 16px;
  align-items: start;
}

.preview-frame {
  display: grid;
  min-height: 320px;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151a1d;
}

#savePreviewCanvas {
  max-width: 100%;
  height: auto;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.38);
}

.preview-details {
  display: grid;
  gap: 12px;
}

.preview-details dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.preview-details dl > div {
  display: grid;
  gap: 3px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.preview-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.preview-details dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .main-layout {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .right-panel {
    display: block;
    grid-column: 1 / -1;
    max-height: 380px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 760px) {
  .save-preview-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .left-panel {
    max-height: 190px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .thumbnail-list {
    grid-auto-flow: column;
    grid-auto-columns: 168px;
    overflow-x: auto;
  }

  .right-panel {
    max-height: none;
  }

  .canvas-scroll {
    min-height: 62vh;
    padding: 18px;
  }

  .tool {
    min-width: 72px;
  }

  .command span,
  .tool span {
    display: none;
  }
}
