/* 制作剪纸页面样式 */

/* ========== 基础样式 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent; /* 移除移动端点击高亮 */
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #f5f5f5;
  overflow: hidden;
  height: 100vh;
  -webkit-user-select: none;
  user-select: none;
}

/* ========== 头部样式 ========== */
.papercut-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(253, 246, 227, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(231, 229, 228, 0.5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.papercut-header-left,
.papercut-header-center,
.papercut-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.papercut-header-center {
  flex: 1;
  justify-content: center;
  position: relative;
}

.papercut-header-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: transparent;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  color: #333;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* 优化触摸响应 */
}

.papercut-header-btn:hover {
  background: #f5f5f5;
  border-color: #d0d0d0;
}

.papercut-header-btn:active {
  transform: scale(0.95);
}

.papercut-header-btn-primary {
  background: #E60012;
  color: #fff;
  border-color: #E60012;
}

.papercut-header-btn-primary:hover {
  background: #cc0010;
  border-color: #cc0010;
}

.papercut-header-btn-primary:active {
  transform: scale(0.95);
  background: #b30010;
}

.papercut-header-btn i {
  font-size: 16px;
}

/* ========== 折数选择器 ========== */
.folds-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  padding: 8px;
  border-radius: 9999px;
  border: 1px solid rgba(231, 229, 228, 0.5);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  pointer-events: auto;
}

.folds-label {
  font-size: 12px;
  color: #999;
  font-weight: 400;
  white-space: nowrap;
  margin-right: 4px;
  pointer-events: none;
  user-select: none;
}

.fold-btn {
  /* 允许"不折叠"这种较长文本 */
  min-width: 32px;
  width: auto;
  height: 32px;
  padding: 0 10px;
  background: #f5f5f5;
  border: none;
  border-radius: 9999px;
  color: #666;
  font-size: 14px;
  font-weight: 700;
  font-family: 'Noto Serif SC', serif;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  pointer-events: auto;
  position: relative;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.fold-btn:hover:not(.active) {
  background: #e8e8e8;
  color: #333;
  transform: scale(1.05);
}

.fold-btn:active:not(.active) {
  transform: scale(0.95);
}

.fold-btn.active {
  background: #E60012;
  color: #fff;
  box-shadow: 0 2px 8px rgba(230, 0, 18, 0.3);
  transform: scale(1.05);
  font-weight: 700;
}

.fold-btn.active:hover {
  background: #E60012;
  color: #fff;
  box-shadow: 0 2px 12px rgba(230, 0, 18, 0.4);
}

.fold-btn.active:active {
  transform: scale(1.0);
}

.fold-input {
  width: 60px;
  height: 32px;
  padding: 0 8px;
  background: #f5f5f5;
  border: 1px solid rgba(231, 229, 228, 0.5);
  border-radius: 9999px;
  color: #666;
  font-size: 14px;
  font-weight: 700;
  font-family: 'Noto Serif SC', serif;
  text-align: center;
  transition: all 0.3s ease;
  outline: none;
}

.fold-input:hover {
  background: #e8e8e8;
  border-color: rgba(231, 229, 228, 0.8);
}

.fold-input:focus {
  background: #fff;
  border-color: #E60012;
  box-shadow: 0 0 0 2px rgba(230, 0, 18, 0.1);
}

.fold-input::placeholder {
  color: #999;
  font-weight: 400;
}

/* 隐藏数字输入框的上下箭头 */
.fold-input::-webkit-inner-spin-button,
.fold-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.fold-input[type=number] {
  -moz-appearance: textfield;
}

.fold-confirm-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  background: #E60012;
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(230, 0, 18, 0.3);
}

.fold-confirm-btn:hover {
  background: #cc0010;
  box-shadow: 0 2px 12px rgba(230, 0, 18, 0.4);
  transform: scale(1.05);
}

.fold-confirm-btn:active {
  transform: scale(0.95);
}

/* ========== 画布容器 ========== */
.papercut-canvas-container {
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 80px;
  display: flex;
  align-items: stretch;
  justify-content: center; /* 改为居中，确保单栏时居中 */
  /* 背景用透明，便于看到“纸张之外是透明区域”（保存 PNG 也会是透明） */
  background: transparent;
  overflow: hidden;
}

.papercut-canvas-wrapper {
  position: relative;
  width: 100%;
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  touch-action: none;
  overflow: hidden;
}

.papercut-canvas-wrapper.preview-mode {
  width: 50%; /* 强制宽度 */
  flex: 0 0 50%; /* 禁止伸缩，固定50% */
}

.papercut-canvas-wrapper.expand-mode {
  width: 0;
  overflow: hidden;
}

/* 让主画布与路径覆盖层严格重叠并居中（否则会出现“在预览区画线/坐标偏移”） */
#papercut-canvas,
#path-overlay-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  touch-action: none; /* 禁止触摸默认行为，仅在画布上 */
}

#papercut-canvas {
  z-index: 1;
}

#path-overlay-canvas {
  z-index: 2;
  pointer-events: auto;
}

/* ========== 预览面板 ========== */
.papercut-preview-panel {
  width: 0; /* 默认隐藏 */
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fdf6e3;
  border-left: 1px solid rgba(231, 229, 228, 0.5);
  padding: 0;
  transition: width 0.3s ease;
  overflow: hidden;
  position: relative;
}

.papercut-preview-panel.show {
  width: 50%; /* 显示时占一半 */
  padding: 20px;
}

.preview-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
  text-align: center;
  width: 100%;
  padding: 8px 0;
  border-bottom: 1px solid rgba(231, 229, 228, 0.5);
  flex-shrink: 0;
  display: none; /* 默认隐藏 */
}

.papercut-preview-panel.show .preview-title {
  display: block; /* 预览面板显示时才显示标题 */
}

/* 展开模式：预览面板全屏显示 */
.papercut-canvas-wrapper.expand-mode + .papercut-preview-panel.show {
  width: 100%;
  border-left: none;
}

#preview-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

/* ========== 工具栏 ========== */
.papercut-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: rgba(253, 246, 227, 0.95);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(231, 229, 228, 0.5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
  gap: 16px;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.toolbar-btn {
  min-width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  background: #fff;
  border: none;
  border-radius: 24px;
  color: #666;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

.toolbar-btn span {
  font-size: 14px;
  font-weight: 500;
}

.toolbar-btn:hover:not(:disabled) {
  background: #f5f5f5;
  color: #E60012;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toolbar-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar-btn-danger {
  color: #E60012;
}

.toolbar-btn-danger:hover:not(:disabled) {
  background: #ffe5e5;
  color: #E60012;
  transform: scale(1.05);
}

.toolbar-btn.active {
  background: #E60012;
  color: #fff;
  border-color: #E60012;
}

/* ========== 工具栏组 ========== */
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border-left: 1px solid #e5e5e5;
  border-right: 1px solid #e5e5e5;
  margin: 0 4px;
}

.toolbar-label {
  min-width: 40px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  user-select: none;
}

/* ========== 工具选择器 ========== */
.tool-selector {
  display: flex;
  gap: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  padding: 8px;
  border-radius: 9999px;
  border: 1px solid rgba(231, 229, 228, 0.5);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: #666;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.tool-btn-icon {
  padding: 6px;
  border-radius: 8px;
  background: transparent;
  transition: all 0.3s ease;
}

.tool-btn:hover {
  color: #333;
  transform: scale(1.05);
}

.tool-btn:hover .tool-btn-icon {
  background: rgba(0, 0, 0, 0.05);
}

.tool-btn.active {
  color: #E60012;
  transform: scale(1.05);
}

.tool-btn.active .tool-btn-icon {
  background: rgba(255, 33, 33, 0.1);
  color: #E60012;
}

.tool-btn i {
  font-size: 18px;
}

.tool-btn span {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ========== 创建弹窗 ========== */
.create-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.create-modal-overlay.show {
  display: flex;
  opacity: 1;
}

.create-modal {
  background: #fff;
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.create-modal-overlay.show .create-modal {
  transform: scale(1);
}

.create-modal-title {
  padding: 24px;
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #333;
  border-bottom: 1px solid #e5e5e5;
  background: #fafafa;
}

.create-modal-section {
  padding: 24px;
  border-bottom: 1px solid #e5e5e5;
}

.create-modal-section:last-of-type {
  border-bottom: none;
}

.create-modal-section-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
}

.create-modal-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* 颜色选择项 */
#paper-color-choices .create-modal-choice {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  text-indent: -9999px;
  overflow: hidden;
}

#paper-color-choices .create-modal-choice:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#paper-color-choices .create-modal-choice.active {
  border-color: #E60012;
  box-shadow: 0 0 0 3px rgba(230, 0, 18, 0.2), 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* 类型和折数选择项 */
#paper-type-choices .create-modal-choice,
#paper-folds-choices .create-modal-choice {
  padding: 12px 24px;
  background: #f5f5f5;
  border: 2px solid transparent;
  border-radius: 8px;
  color: #666;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

#paper-type-choices .create-modal-choice:hover,
#paper-folds-choices .create-modal-choice:hover {
  background: #e8e8e8;
  color: #333;
}

#paper-type-choices .create-modal-choice.active,
#paper-folds-choices .create-modal-choice.active {
  background: #E60012;
  color: #fff;
  border-color: #E60012;
}

.create-modal-actions {
  padding: 20px 24px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #fafafa;
  border-top: 1px solid #e5e5e5;
}

.create-modal-btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.create-modal-btn-cancel {
  background: #f5f5f5;
  color: #666;
}

.create-modal-btn-cancel:hover {
  background: #e8e8e8;
  color: #333;
}

.create-modal-btn-confirm {
  background: #E60012;
  color: #fff;
}

.create-modal-btn-confirm:hover {
  background: #cc0010;
}

/* ========== 响应式设计 ========== */
@media (max-width: 768px) {
  .papercut-header {
    padding: 0 8px;
    height: 48px;
  }

  .papercut-header-btn span {
    display: none;
  }

  .papercut-header-btn {
    padding: 6px;
    min-width: 36px;
  }

  .papercut-header-btn i {
    font-size: 18px;
  }

  .papercut-header-left,
  .papercut-header-right {
    gap: 4px;
  }

  .papercut-header-center {
    position: fixed;
    bottom: 64px;
    left: 0;
    right: 0;
    top: auto;
    height: 40px;
    background: rgba(253, 246, 227, 0.95);
    backdrop-filter: blur(8px);
    padding: 4px 8px;
    z-index: 999;
    border-top: 1px solid rgba(231, 229, 228, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    flex: none;
  }

  .folds-selector {
    position: static;
    transform: none;
    top: auto;
    left: auto;
  }

  .papercut-canvas-container {
    top: 48px;
    bottom: 104px; /* 64px toolbar + 40px fold selector */
  }

  .papercut-toolbar {
    height: 64px;
    padding: 0 12px;
    gap: 8px;
  }

  .toolbar-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .tool-btn span {
    display: none;
  }

  .tool-btn {
    padding: 8px 12px;
  }

  .create-modal {
    width: 95%;
    max-height: 95vh;
  }

  .create-modal-section {
    padding: 20px;
  }

  .papercut-canvas-wrapper.preview-mode {
    width: 100%;
  }

  .papercut-preview-panel.show {
    width: 100%;
    top: 0;
    z-index: 1500;
  }

  .papercut-preview-panel.show ~ .papercut-canvas-wrapper {
    display: none;
  }

  /* 折数选择器移动端适配 */
  .folds-selector {
    gap: 6px;
    padding: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: calc(100vw - 24px);
  }

  .folds-label {
    font-size: 11px;
    margin-right: 4px;
  }

  .fold-btn {
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
    flex-shrink: 0;
  }

  .fold-input {
    width: 50px;
    height: 28px;
    padding: 0 6px;
    font-size: 12px;
    flex-shrink: 0;
  }

  .fold-confirm-btn {
    width: 28px;
    height: 28px;
    font-size: 14px;
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  .papercut-header {
    padding: 0 6px;
    height: 44px;
  }

  .papercut-header-btn {
    padding: 5px;
    min-width: 32px;
  }

  .papercut-header-btn i {
    font-size: 16px;
  }

  .papercut-canvas-container {
    top: 44px;
    bottom: 98px; /* 60px toolbar + 38px fold selector */
  }

  .papercut-header-center {
    bottom: 60px;
    height: 38px;
    padding: 3px 6px;
  }

  .papercut-toolbar {
    height: 60px;
    padding: 0 8px;
    gap: 6px;
  }

  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    gap: 6px;
  }

  .toolbar-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .tool-btn {
    padding: 6px 10px;
    font-size: 16px;
  }

  /* 折数选择器小屏幕适配 */
  .folds-selector {
    gap: 4px;
    padding: 4px;
    position: static;
    transform: none;
    margin: 0 auto;
    border-radius: 20px;
  }

  .folds-label {
    font-size: 10px;
    margin-right: 2px;
  }

  .fold-btn {
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    font-size: 11px;
  }

  .fold-input {
    width: 45px;
    height: 26px;
    padding: 0 4px;
    font-size: 11px;
  }

  .fold-confirm-btn {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }

  /* 弹窗适配 */
  .create-modal {
    width: 98%;
    max-height: 98vh;
    padding: 16px;
  }

  .create-modal-title {
    font-size: 18px;
    margin-bottom: 16px;
  }

  .create-modal-section {
    padding: 16px;
  }

  .create-modal-section-title {
    font-size: 13px;
    margin-bottom: 10px;
  }

  #paper-color-choices .create-modal-choice {
    width: 36px;
    height: 36px;
  }

  .create-modal-choices {
    gap: 8px;
  }

  #paper-type-choices .create-modal-choice,
  #paper-folds-choices .create-modal-choice {
    padding: 8px 12px;
    font-size: 12px;
  }

  .modal-fold-input {
    width: 130px !important;
    padding: 6px 10px !important;
    font-size: 12px !important;
  }

  .create-modal-actions {
    gap: 8px;
  }

  .create-modal-btn {
    padding: 10px 20px;
    font-size: 13px;
  }
}

/* 超小屏幕适配 */
@media (max-width: 360px) {
  .folds-selector {
    gap: 3px;
    padding: 3px;
  }

  .folds-label {
    display: none; /* 超小屏幕隐藏标签 */
  }

  .fold-btn {
    min-width: 24px;
    height: 24px;
    padding: 0 5px;
    font-size: 10px;
  }

  .fold-input {
    width: 40px;
    height: 24px;
    font-size: 10px;
  }

  .fold-confirm-btn {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }

  .toolbar-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .tool-btn {
    padding: 5px 8px;
    font-size: 14px;
  }
}

/* iPad 竖屏适配 (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
  .papercut-header {
    padding: 0 16px;
  }

  .papercut-header-right {
    gap: 8px;
  }

  .papercut-header-btn {
    padding: 6px 12px;
    font-size: 13px;
  }

  .papercut-header-btn span {
    display: inline;
  }

  .folds-selector {
    gap: 6px;
  }

  .fold-btn {
    min-width: 32px;
    height: 32px;
    font-size: 13px;
  }

  .papercut-preview-panel.show {
    width: 50%;
  }

  .create-modal {
    width: 80%;
    max-width: 500px;
  }
}

/* iPad 横屏适配 */
@media (min-width: 1024px) and (max-width: 1366px) {
  .papercut-header {
    padding: 0 20px;
  }

  .papercut-header-btn {
    padding: 8px 14px;
  }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
  .papercut-header-btn {
    min-height: 44px;
    min-width: 44px;
  }

  .toolbar-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .tool-btn {
    min-height: 44px;
    padding: 8px 14px;
  }

  .fold-btn {
    min-height: 36px;
    min-width: 36px;
  }
}

