/* Apple 风格 APNG 制作器 - 双栏布局 */

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

body {
  background-color: #f5f5f7;
  color: #1d1d1f;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  min-height: 100vh;
}

::selection {
  background: #1d1d1f;
  color: #fff;
}

*:focus {
  outline: none;
}

input[type="number"]::-webkit-inner-spin-button {
  opacity: 0.5;
}

/* ===== 布局 ===== */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 24px 0;
}

/* ===== 主区域: 双栏 ===== */
.main {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

/* 左栏: 预览 */
.panel-preview {
  flex: 1;
  min-width: 0;
}

.preview-area {
  position: relative;
  background: #fff;
  border: 2px dashed #d2d2d7;
  border-radius: 16px;
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  overflow: hidden;
}

.preview-area:hover,
.preview-area.dragover {
  border-color: #0071e3;
  background: #f8fbff;
}

.preview-area.has-frames {
  border-style: solid;
  border-color: #e8e8ed;
  cursor: default;
  padding: 12px;
}

.preview-area.has-frames:hover {
  border-color: #d2d2d7;
  background: #fff;
}

/* 上传占位 */
.upload-placeholder {
  text-align: center;
  padding: 40px 20px;
  pointer-events: none;
}

.upload-icon {
  margin-bottom: 14px;
}

.upload-text {
  font-size: 15px;
  color: #1d1d1f;
  font-weight: 500;
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 12px;
  color: #86868b;
}

/* 预览图 */
.preview-img {
  max-width: 100%;
  max-height: 380px;
  border-radius: 10px;
  display: block;
  margin: 0 auto;
}

/* ===== 右栏: 设置 ===== */
.panel-settings {
  width: 300px;
  flex-shrink: 0;
}

.settings-card {
  background: #fff;
  border: 1px solid #e8e8ed;
  border-radius: 16px;
  padding: 24px;
}

.settings-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 17px;
  font-weight: 600;
  color: #1d1d1f;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}

/* 语言切换 */
.lang-btn {
  background: #e8e8ed;
  border: none;
  border-radius: 8px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  color: #1d1d1f;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
}

.lang-btn:hover {
  background: #d2d2d7;
}

.lang-btn.lang-en {
  background: #0071e3;
  color: #fff;
}

.lang-btn.lang-en:hover {
  background: #0062c4;
}

/* 网站 Logo */
.site-logo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: #1d1d1f;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 18px;
  opacity: 0.85;
  transition: opacity 0.2s ease;
}

.site-logo:hover {
  opacity: 1;
}

.setting-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.setting-row:last-child {
  margin-bottom: 0;
}

.setting-field {
  flex: 1;
  min-width: 0;
}

.setting-field label {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  color: #86868b;
  font-weight: 500;
  margin-bottom: 6px;
  white-space: nowrap;
}

/* 问号提示 */
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #d2d2d7;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  cursor: help;
  flex-shrink: 0;
  line-height: 1;
  position: relative;
  transition: background 0.2s ease;
}

.tip:hover {
  background: #0071e3;
}

.tip::after {
  content: attr(data-tip);
  position: absolute;
  top: 50%;
  left: calc(100% + 8px);
  transform: translateY(-50%);
  background: #1d1d1f;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  padding: 8px 12px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
  line-height: 1.4;
  width: 200px;
  text-align: left;
}

.tip:hover::after {
  opacity: 1;
}

.setting-field input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: #1d1d1f;
  background: #fafafa;
  transition: border-color 0.3s ease, background 0.3s ease;
}

.setting-field input[type="number"]:focus {
  border-color: #0071e3;
  background: #fff;
}

.setting-field input[type="number"]::placeholder {
  color: #aeaeb2;
}

/* 带单位的输入框 */
.input-unit {
  position: relative;
}

.input-unit input {
  padding-right: 36px !important;
}

.input-unit .unit {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: #aeaeb2;
  pointer-events: none;
}

/* 颜色选择器 */
.color-picker-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.color-swatch-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.color-checker-bg {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background-image:
    linear-gradient(45deg, #e8e8ed 25%, transparent 25%),
    linear-gradient(-45deg, #e8e8ed 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e8ed 75%),
    linear-gradient(-45deg, transparent 75%, #e8e8ed 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  border-radius: 8px;
  pointer-events: none;
}

.color-swatch {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  z-index: 1;
  pointer-events: none;
}

.color-swatch-wrap input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  background: none;
  opacity: 0;
  z-index: 2;
}

.color-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-controls input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  font-size: 12px;
  font-family: monospace;
  color: #1d1d1f;
  background: #fafafa;
  transition: border-color 0.3s ease;
}

.color-controls input[type="text"]:focus {
  border-color: #0071e3;
  background: #fff;
}

.opacity-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.opacity-label {
  font-size: 12px;
  color: #86868b;
  white-space: nowrap;
  min-width: 3em;
}

.opacity-control input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, transparent, #000);
  border-radius: 2px;
  cursor: pointer;
}

.opacity-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #d2d2d7;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  cursor: pointer;
}

.opacity-value {
  font-size: 11px;
  color: #86868b;
  min-width: 36px;
  text-align: right;
  font-family: monospace;
}

/* ===== 操作按钮 ===== */
.action-buttons {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  padding: 13px 20px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
}

.btn-loading {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

.btn-clear {
  background: transparent;
  color: #ff3b30;
  border: 1px solid #ff3b30;
  font-weight: 500;
}

.btn-clear:hover {
  background: #ff3b30;
  color: #fff;
}

.btn-preview {
  background: #0071e3;
  color: #fff;
}

.btn-preview:hover:not(:disabled) {
  background: #0077ed;
}

.btn-download {
  background: #1d1d1f;
  color: #fff;
}

.btn-download:hover:not(:disabled) {
  background: #2d2d2f;
}

.btn.loading {
  opacity: 0.7;
  pointer-events: none;
}

/* ===== 帧列表 ===== */
.frames-panel {
  margin-top: 16px;
  background: #fff;
  border: 1px solid #e8e8ed;
  border-radius: 16px;
  padding: 16px;
}

.frames-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.frames-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: #1d1d1f;
}

.btn-add {
  padding: 6px 14px;
  background: transparent;
  color: #0071e3;
  border: 1px solid #0071e3;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
}

.btn-add:hover {
  background: #0071e3;
  color: #fff;
}

.frames-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

/* 帧卡片 */
.frame-card {
  position: relative;
  width: 110px;
  flex-shrink: 0;
  background: #fafafa;
  border: 1px solid #e8e8ed;
  border-radius: 10px;
  padding: 8px;
  cursor: grab;
  transition: box-shadow 0.2s ease, opacity 0.2s ease, border-color 0.2s ease;
  user-select: none;
}

.frame-card:active {
  cursor: grabbing;
}

.frame-card.dragging {
  opacity: 0.4;
}

.frame-card.drag-over {
  border-color: #0071e3;
  box-shadow: 0 0 0 2px rgba(0,113,227,0.15);
}

.frame-card.active {
  border-color: #0071e3;
  background: #f0f8ff;
}

.frame-thumb {
  width: 100%;
  height: 76px;
  object-fit: contain;
  background: #f5f5f7;
  border-radius: 6px;
  display: block;
}

.frame-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  gap: 4px;
}

.frame-index {
  font-size: 11px;
  color: #86868b;
  font-weight: 500;
  min-width: 18px;
}

/* 拖拽手柄 */
.frame-drag {
  font-size: 12px;
  color: #c7c7cc;
  cursor: grab;
  flex-shrink: 0;
  margin-right: 2px;
  user-select: none;
}

.frame-card:active .frame-drag {
  cursor: grabbing;
}

.frame-delay-input {
  width: 48px;
  padding: 2px 4px;
  border: 1px solid #e8e8ed;
  border-radius: 4px;
  font-size: 11px;
  text-align: center;
  font-family: inherit;
  color: #1d1d1f;
  background: #fff;
}

.frame-delay-input:focus {
  border-color: #0071e3;
}

.frame-delay-ms {
  font-size: 10px;
  color: #aeaeb2;
}

.frame-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
  font-family: inherit;
}

.frame-card:hover .frame-delete {
  opacity: 1;
}

.frame-delete:hover {
  background: #d63031;
}

/* 帧数角标 */
.frame-badge {
  position: absolute;
  bottom: 42px;
  left: 8px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 4px;
  pointer-events: none;
}

/* 尺寸警告 */
.frame-warn {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ff9500;
  color: #fff;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  cursor: help;
  font-family: inherit;
}

/* 帧统计 */
.frames-stats {
  margin-top: 12px;
  font-size: 12px;
  color: #86868b;
  text-align: center;
}

/* ===== 预设尺寸 ===== */
.setting-field.full {
  flex: none;
  width: 100%;
}

.preset-sizes {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-btn {
  padding: 6px 12px;
  border: 1px solid #d2d2d7;
  border-radius: 6px;
  background: #fafafa;
  font-size: 11px;
  font-family: inherit;
  color: #1d1d1f;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-btn:hover {
  border-color: #0071e3;
  color: #0071e3;
  background: #f0f8ff;
}

.preset-btn.active {
  border-color: #0071e3;
  background: #0071e3;
  color: #fff;
}

/* ===== 整体速度 ===== */
.speed-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.speed-wrap input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, #d2d2d7, #0071e3);
  border-radius: 2px;
  cursor: pointer;
}

.speed-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #d2d2d7;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  cursor: pointer;
}

.speed-value {
  font-size: 12px;
  color: #1d1d1f;
  font-weight: 600;
  min-width: 32px;
  text-align: right;
  font-family: monospace;
}

/* ===== 底部 ===== */
.footer {
  text-align: center;
  padding: 32px 24px;
  color: #86868b;
  font-size: 12px;
}

/* ===== 加载中 ===== */
.loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.8);
  border-radius: 16px;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #86868b;
  z-index: 2;
}

.loading-overlay.show {
  display: flex;
}

/* ===== 移动端适配 ===== */
@media only screen and (max-width: 768px) {
  .app {
    padding: 16px 12px 0;
  }

  .main {
    flex-direction: column;
  }

  .panel-settings {
    width: 100%;
  }

  .preview-area {
    min-height: 220px;
  }

  .preview-img {
    max-height: 260px;
  }

  .action-buttons {
    flex-direction: row;
  }

  .action-buttons .btn {
    flex: 1;
  }

  .frames-list {
    gap: 8px;
  }

  .frame-card {
    width: 100px;
  }

  .frame-thumb {
    height: 66px;
  }
}

@media only screen and (max-width: 480px) {
  .settings-card {
    padding: 16px;
  }

  .setting-row {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
  }

  .preset-sizes {
    justify-content: center;
  }

  .color-picker-wrap {
    flex-direction: row;
    align-items: flex-start;
  }

  .color-controls {
    flex: 1;
  }

  .frames-panel {
    padding: 16px;
  }
}

/* ===== 自定义确认对话框 ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.modal-box {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  padding: 28px 24px 20px;
  width: 280px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
  text-align: center;
}

.modal-text {
  font-size: 15px;
  color: #1d1d1f;
  margin-bottom: 24px;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-btn {
  flex: 1;
  padding: 11px 0;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-cancel {
  background: #e8e8ed;
  color: #1d1d1f;
}

.modal-cancel:hover {
  background: #d2d2d7;
}

.modal-ok {
  background: #ff3b30;
  color: #fff;
}

.modal-ok:hover {
  background: #d63031;
}
