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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  min-height: 100vh;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

header {
  position: relative;
  text-align: center;
  margin-bottom: 1.5rem;
}

.github-link {
  position: absolute;
  top: 0;
  right: 0;
  color: #86868b;
  transition: color 0.2s;
}

.github-link:hover {
  color: #1d1d1f;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: #86868b;
  font-size: 0.95rem;
}

.notice {
  color: #86868b;
  font-size: 0.8rem;
  margin-top: 0.4rem;
}

/* Drop zones */
.drop-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.drop-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 2rem 1rem;
  min-height: 140px;
  border: 2px dashed #c7c7cc;
  border-radius: 14px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
}

.drop-zone:hover {
  border-color: #007aff;
  background: #f0f5ff;
}

.drop-zone.dragover {
  border-color: #007aff;
  background: #e0edff;
  transform: scale(1.01);
}

.drop-zone.loaded {
  border-color: #34c759;
  border-style: solid;
  background: #f0faf3;
}

.drop-icon {
  font-size: 2rem;
}

.drop-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.drop-hint {
  font-size: 0.8rem;
  color: #86868b;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 1rem;
  min-height: 44px;
}

/* Stamp thumbnails */
.stamp-thumbs {
  display: flex;
  gap: 6px;
  margin-right: auto;
  flex-wrap: wrap;
}

.stamp-thumb-wrap {
  position: relative;
  display: inline-block;
  cursor: pointer;
}

.stamp-thumb {
  width: 56px;
  height: 56px;
  border: 2px solid #e5e5ea;
  border-radius: 8px;
  padding: 3px;
  background: #fff;
  cursor: pointer;
  object-fit: contain;
  transition: border-color 0.15s;
}

.stamp-thumb-wrap:hover .stamp-thumb {
  border-color: #007aff;
}

.stamp-thumb-wrap.selected .stamp-thumb {
  border-color: #007aff;
  box-shadow: 0 0 0 2px rgba(0,122,255,0.25);
}

.stamp-thumb-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  background: #ff3b30;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  font-size: 10px;
  line-height: 12px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0;
}

.stamp-thumb-wrap:hover .stamp-thumb-del {
  opacity: 1;
}

/* Action buttons */
.action-btn {
  padding: 0.65rem 1.5rem;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: #e8e8ed;
  color: #1d1d1f;
  transition: background 0.2s;
}

.action-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.action-btn:not(:disabled):hover {
  background: #d1d1d6;
}

.action-btn.primary {
  background: #007aff;
  color: #fff;
}

.action-btn.primary:not(:disabled):hover {
  background: #0066d6;
}

/* Viewer */
.viewer-container {
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.canvas-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  background: #e8e8ed;
  border-radius: 8px;
  overflow: hidden;
  min-height: 400px;
}

#pdf-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.stamp-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Stamp overlay items */
.stamp-item {
  position: absolute;
  pointer-events: auto;
  cursor: move;
  user-select: none;
  border: 2px dashed transparent;
  transition: border-color 0.15s;
}

.stamp-item:hover,
.stamp-item.active {
  border-color: #007aff;
}

.stamp-item img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.stamp-item .resize-handle {
  position: absolute;
  background: #007aff;
  opacity: 0;
  transition: opacity 0.15s;
}

.stamp-item:hover .resize-handle,
.stamp-item.active .resize-handle {
  opacity: 1;
}

.resize-handle-br {
  bottom: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: nwse-resize;
}

.resize-handle-r {
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 24px;
  border-radius: 4px;
  cursor: ew-resize;
}

.resize-handle-b {
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 8px;
  border-radius: 4px;
  cursor: ns-resize;
}

.stamp-item .delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: #ff3b30;
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.stamp-item:hover .delete-btn,
.stamp-item.active .delete-btn {
  opacity: 1;
}

.stamp-item .size-label {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: #007aff;
  background: rgba(255,255,255,0.92);
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.stamp-item:hover .size-label,
.stamp-item.active .size-label {
  opacity: 1;
}

/* Page nav */
.page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.page-nav button {
  padding: 0.5rem 1.1rem;
  border: 1px solid #c7c7cc;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
}

.page-nav button:disabled {
  opacity: 0.4;
  cursor: default;
}

.page-nav button:not(:disabled):hover {
  background: #f0f5ff;
  border-color: #007aff;
}

#page-info {
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 60px;
  text-align: center;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
  font-size: 0.9rem;
  color: #86868b;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid #e8e8ed;
  border-top-color: #007aff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Utility */
.hidden {
  display: none !important;
}

/* Mobile */
@media (max-width: 600px) {
  .drop-row {
    flex-direction: column;
  }

  .drop-zone {
    min-height: 100px;
    padding: 1.5rem 1rem;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: center;
  }
}
