/* ════════════════════════════════════════════════════════
   自娱自乐小打小闹 — 浅色雾霾蓝主题
   ════════════════════════════════════════════════════════ */

:root {
  --bg: #e8eef5;
  --bg-soft: #f0f4f9;
  --panel: #ffffff;
  --panel-2: #f5f8fb;
  --border: #d0dae6;
  --border-strong: #a8c0d8;
  --accent: #5b9bd5;
  --accent-bright: #4a90d9;
  --accent-light: #e3f0fd;
  --accent-glow: rgba(91, 155, 213, 0.25);
  --text: #2c3e50;
  --text-secondary: #5a6d7e;
  --text-muted: #8a9bab;
  --success: #4caf7d;
  --warning: #e8a838;
  --danger: #e06c6c;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(91, 155, 213, 0.08);
  --shadow-lg: 0 8px 32px rgba(91, 155, 213, 0.12);
  --font-ui: "Space Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Courier New", monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 30% 0%, rgba(91, 155, 213, 0.06), transparent),
    radial-gradient(ellipse 50% 40% at 80% 100%, rgba(120, 180, 220, 0.05), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ════════════════════════════════════════════════════════
   上下布局
   ════════════════════════════════════════════════════════ */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* ── 顶部栏 ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #7eb8da);
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px solid rgba(255,255,255,0.7);
  border-radius: 3px;
}
.app-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
}

/* ── 控制面板（自动换行） ── */
.control-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 36vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  align-content: flex-start;
}
.control-strip::-webkit-scrollbar { width: 5px; }
.control-strip::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.control-group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  flex: 1 1 220px;
  min-width: 200px;
  max-width: 340px;
}
.control-group.group-import {
  flex: 1.4 1 280px;
  max-width: 380px;
}
.control-group.group-format {
  flex: 2 1 320px;
  max-width: 440px;
}
.group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* 复选框网格（外观组两列） */
.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 10px;
  margin-bottom: 8px;
}

/* ════════════════════════════════════════════════════════
   通用控件
   ════════════════════════════════════════════════════════ */

.field {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}
.field > span {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}
.field input[type="text"],
.field input[type="search"],
.field input[type="number"],
.field select {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.12);
}
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' stroke='%235a6d7e' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
  cursor: pointer;
}
.field-hint {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
}
.field-label-with-value {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.field-label-with-value output {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
}

/* 双下拉 */
.dual-select {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.custom-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.custom-inputs .field input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.custom-inputs .field input:focus {
  border-color: var(--accent);
}
.stock-info {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: -2px;
  margin-bottom: 8px;
  padding: 5px 8px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent);
}

/* 画幅按钮组 */
.format-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.format-btn {
  padding: 4px 9px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-ui);
}
.format-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.format-btn.active {
  background: linear-gradient(135deg, var(--accent), #7eb8da);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
  font-weight: 600;
}

/* 拖拽上传区 */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 12px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  margin-bottom: 8px;
}
.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-light);
}
.drop-zone input { display: none; }
.drop-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7eb8da);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  font-weight: 300;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.drop-title { font-size: 12px; font-weight: 600; color: var(--text); }
.drop-subtitle { font-size: 10px; color: var(--text-muted); }

/* 分段控件 */
.segmented {
  display: flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
  margin-bottom: 6px;
}
.segmented label {
  flex: 1;
  position: relative;
  cursor: pointer;
}
.segmented input { position: absolute; opacity: 0; }
.segmented span {
  display: block;
  text-align: center;
  padding: 4px 2px;
  font-size: 11px;
  color: var(--text-secondary);
  border-radius: 4px;
  transition: all 0.15s;
}
.segmented input:checked + span {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(91, 155, 213, 0.1);
}

/* 复选框行 */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.checkbox-row input[type="checkbox"] {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: 3px;
  background: var(--panel);
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
  flex-shrink: 0;
}
.checkbox-row input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox-row input[type="checkbox"]:checked::after {
  content: "✓";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.checkbox-row input[type="checkbox"]:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* 滑块 */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px var(--accent-glow);
  border: 2px solid var(--panel);
}
input[type="range"]:disabled { opacity: 0.4; }

/* 照片列表 */
.photo-list-section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-secondary);
  list-style: none;
}
.photo-list-section > summary::-webkit-details-marker { display: none; }
.photo-list-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-light);
  padding: 1px 6px;
  border-radius: 8px;
}
.photo-list {
  list-style: none;
  max-height: 100px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.photo-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  cursor: grab;
  transition: background 0.15s;
}
.photo-list-item:hover { background: var(--bg-soft); }
.photo-list-item.drag-over { background: var(--accent-light); }
.photo-thumb {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.photo-thumb-blank {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  border: 1px dashed var(--border);
}
.photo-name {
  flex: 1;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.photo-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 1px 4px;
  border-radius: 3px;
  transition: all 0.15s;
}
.photo-remove:hover { color: var(--danger); background: rgba(224, 108, 108, 0.1); }

/* 按钮 */
.primary-button {
  padding: 7px 16px;
  background: linear-gradient(135deg, var(--accent), #7eb8da);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-ui);
  box-shadow: 0 2px 8px var(--accent-glow);
}
.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--accent-glow);
}
.primary-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
.text-button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-ui);
}
.text-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.text-button:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-button {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.icon-button:hover { border-color: var(--accent); color: var(--accent); }

/* ════════════════════════════════════════════════════════
   预览区
   ════════════════════════════════════════════════════════ */

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.counter {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-light);
  padding: 3px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.zoom-field {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--text-muted);
}
.zoom-field input { width: 70px; }

.preview-wrap {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  position: relative;
}
.preview-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.preview-wrap::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

#previewCanvas {
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(91, 155, 213, 0.15);
  cursor: default;
  transition: width 0.1s, height 0.1s;
  flex-shrink: 0;
  background: #fff;
}

/* 空状态 */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.empty-state.is-hidden { display: none; }
.empty-inner {
  text-align: center;
  color: var(--text-muted);
}
.empty-inner .empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 10px;
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}
.empty-inner h3 { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.empty-inner p { font-size: 11px; }

/* ════════════════════════════════════════════════════════
   帧操作菜单
   ════════════════════════════════════════════════════════ */

.frame-menu {
  position: fixed;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 5px;
  min-width: 150px;
  box-shadow: var(--shadow-lg);
}
.frame-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-align: left;
  font-family: var(--font-ui);
  transition: background 0.15s;
}
.frame-menu button:hover { background: var(--accent-light); color: var(--accent); }
.menu-icon {
  width: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--accent);
}

/* ════════════════════════════════════════════════════════
   弹窗通用
   ════════════════════════════════════════════════════════ */

.crop-modal,
.frame-export-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.crop-modal[hidden],
.frame-export-modal[hidden] { display: none; }
.crop-backdrop,
.frame-export-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 62, 80, 0.4);
  backdrop-filter: blur(3px);
}
.crop-container,
.frame-export-container {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.crop-header,
.frame-export-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.crop-header h3,
.frame-export-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.frame-export-header p { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.crop-close,
.frame-export-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.crop-close:hover,
.frame-export-close:hover { background: var(--bg-soft); color: var(--text); }
.crop-body,
.frame-export-body {
  padding: 16px;
  overflow: auto;
  flex: 1;
}
.crop-footer,
.frame-export-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

/* 裁切 */
.crop-preview-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
}
.crop-overlay {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(44, 62, 80, 0.4);
  cursor: move;
}
.crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 2px;
}
.crop-handle.nw { top: -5px; left: -5px; cursor: nwse-resize; }
.crop-handle.ne { top: -5px; right: -5px; cursor: nesw-resize; }
.crop-handle.sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.crop-handle.se { bottom: -5px; right: -5px; cursor: nwse-resize; }

/* 单帧导出 */
.frame-export-body {
  display: flex;
  gap: 16px;
  min-width: 540px;
}
.frame-export-preview-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  min-height: 260px;
  max-height: 440px;
  overflow: hidden;
}
.frame-export-preview-wrap canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.frame-export-controls {
  width: 190px;
  flex-shrink: 0;
}
.frame-export-info {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent);
}
.frame-export-info strong {
  display: block;
  font-size: 12px;
  color: var(--accent);
  font-family: var(--font-mono);
}
.frame-export-info p { font-size: 10px; color: var(--text-muted); margin-top: 3px; }

/* 索引图导出警告 */
.export-warning {
  padding: 8px 16px;
  font-size: 11px;
  color: var(--warning);
  background: rgba(232, 168, 56, 0.06);
  border-top: 1px solid var(--border);
}

/* ════════════════════════════════════════════════════════
   通知
   ════════════════════════════════════════════════════════ */

.notice {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 12px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s;
  z-index: 3000;
  pointer-events: none;
}
.notice.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 加载态 */
.preview-wrap.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 响应式 */
@media (max-width: 768px) {
  .control-group { min-width: 160px; }
  .frame-export-body { flex-direction: column; min-width: auto; }
  .frame-export-controls { width: 100%; }
  .app-title { font-size: 13px; }
  .checkbox-grid { grid-template-columns: 1fr; }
}
