:root {
  --primary: #667eea;
  --primary-dark: #5568d3;
  --secondary: #764ba2;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-bg: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --shadow: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--text);
  line-height: 1.6;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 50%, rgba(255,255,255,0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(255,255,255,0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px;
  position: relative;
  z-index: 1;
}

.header {
  text-align: center;
  margin-bottom: 35px;
  color: white;
}

.header h1 {
  font-size: 2.3rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-shadow: 0 4px 20px rgba(0,0,0,0.3);
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 1rem;
  opacity: 0.95;
  text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.tool-section {
  margin-bottom: 35px;
}

.section-title {
  color: white;
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 15px;
  padding-left: 8px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
}

.tool-card-mini {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.3);
}

.tool-card-mini::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--bg-gradient);
  transform: scaleX(0);
  transition: transform 0.3s;
  transform-origin: left;
}

.tool-card-mini:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  background: rgba(255, 255, 255, 1);
}

.tool-card-mini:hover::before {
  transform: scaleX(1);
}

.tool-card-mini .tool-icon {
  width: 42px;
  height: 42px;
  background: var(--bg-gradient);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
  color: white;
  font-weight: bold;
  font-size: 12px;
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.tool-card-mini h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.tool-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 1000;
  overflow-y: auto;
  padding: 15px;
}

.tool-modal-content {
  background: white;
  max-width: 750px;
  max-height: 90vh;
  margin: 20px auto;
  border-radius: 18px;
  padding: 30px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalSlideIn 0.3s ease-out;
  overflow-y: auto;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(-30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.tool-modal-content h2 {
  margin-bottom: 20px;
  color: var(--text);
  font-size: 1.5rem;
}

.tool-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: #f7fafc;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 10;
}

.tool-modal-close:hover {
  background: #e2e8f0;
  color: var(--text);
  transform: rotate(90deg);
}

.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 7px; font-weight: 500; color: var(--text); font-size: 0.9rem; }
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 10px 13px;
  border: 2px solid var(--border);
  border-radius: 9px;
  font-size: 13px;
  transition: all 0.3s;
  font-family: inherit;
  background-color: #f7fafc;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
  background-color: white;
}
.form-textarea { min-height: 80px; resize: vertical; }

.btn {
  background: var(--bg-gradient);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 9px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 13px;
  margin-right: 7px;
  margin-bottom: 7px;
}
.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #cbd5e0; }
.btn-copy { padding: 5px 11px; font-size: 0.8em; background: #e2e8f0; color: var(--text); margin: 0; }

.result-area {
  background: #f7fafc;
  border: 2px dashed var(--border);
  border-radius: 9px;
  padding: 12px;
  margin-top: 10px;
  min-height: 45px;
  word-break: break-all;
  white-space: pre-wrap;
  transition: all 0.3s;
  font-size: 0.85rem;
}
.result-area.has-content { border-color: var(--primary); background: #eef2ff; }
.result-header { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; margin-bottom: 7px; }

.tabs { display: flex; margin-bottom: 16px; border-bottom: 2px solid var(--border); }
.tab {
  padding: 9px 16px;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-light);
  font-weight: 500;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  font-size: 0.9rem;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.4s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 9px;
  padding: 22px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: #f7fafc;
  font-size: 0.9rem;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: #eef2ff;
  transform: scale(1.01);
}
.drop-zone input[type="file"] { display: none; }

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.9);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: 20px;
}
.modal-content { max-width: 90%; max-height: 90%; position: relative; }
.modal-content img { max-width: 100%; max-height: 90vh; display: block; border-radius: 8px; }
.modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  width: 32px;
  height: 32px;
  background: white;
  border-radius: 50%;
  border: none;
  font-size: 22px;
  cursor: pointer;
}

/* 字幕拼图预览 */
.subtitle-stitch-preview-container {
  position: relative;
  background: #f7fafc;
  border: 2px dashed var(--border);
  border-radius: 9px;
  height: 280px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  cursor: pointer;
  margin-bottom: 10px;
}
/* 九宫格预览 */
#gridPreview {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  margin-top: 10px;
  display: none;
  object-fit: contain;
}
/* 图片压缩预览 */
#compressPreview {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  margin-top: 10px;
  display: none;
  object-fit: contain;
}
/* 图片隐写预览 */
#imgEncryptPreview {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  margin-top: 10px;
  display: none;
  object-fit: contain;
}
/* 像素化预览 */
.pixelator-preview-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f7fafc;
  border-radius: 8px;
  height: 280px;
  padding: 8px;
  overflow: auto;
  position: relative;
  border: 1px solid var(--border);
}
/* 三色图预览 */
.venn-canvas-container {
  background-color: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  height: 320px;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: center;
}
#vennCanvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  background-color: white;
  object-fit: contain;
}
/* 二维码预览 */
#qrResult {
  margin: 20px 0;
  text-align: center;
  min-height: 220px;
  display: flex;
  justify-content: center;
  align-items: center;
}
#qrResult canvas {
  max-width: 200px;
  max-height: 200px;
}
.subtitle-stitch-preview-container.has-image::before { display: none; }
.subtitle-stitch-preview-container::before {
  content: '点击或拖拽图片到此';
  position: absolute;
  color: var(--text-light);
  font-size: 0.9rem;
  pointer-events: none;
}

.subtitle-stitch-preview-container.has-image::before {
  display: none;
}

#subtitleCanvas { max-width: 100%; max-height: 100%; object-fit: contain; }
.subtitle-toolbar { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-bottom: 10px; }
.toolbar-btn { background: #f0f0f0; color: #333; border: 1px solid var(--border); width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 13px; transition: all 0.2s; padding: 0; }
.toolbar-btn:hover { background: #e2e8f0; }
.toolbar-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.font-select { flex: 1 1 25px; min-width: 25px; }
.font-size-input { flex: 0 1 80px; }
.slider-group { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.slider-group .form-label { margin-bottom: 0; white-space: nowrap; font-size: 0.85rem; flex-basis: 65px; }
.slider-group input[type="range"] { flex-grow: 1; }
.mode-switch { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.mode-switch label { font-weight: 500; color: var(--text); cursor: pointer; font-size: 0.9rem; }

#gridResult { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
#gridResult img { max-width: 100%; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
#gridResult.empty:before { content: "切割结果将在此处预览"; color: var(--text-light); display: flex; justify-content: center; align-items: center; min-height: 90px; grid-column: 1 / -1; font-size: 0.9rem; }

.collage-maker { display: flex; flex-direction: column; gap: 10px; }
.collage-controls { display: flex; flex-direction: column; gap: 10px; }
.layout-editor-area { display: flex; gap: 10px; align-items: flex-start; }
.template-selector-group { flex: 0 0 110px; margin-bottom: 0; }
.style-details summary { font-weight: 500; color: var(--text); cursor: pointer; padding: 7px; border-radius: 6px; list-style: none; font-size: 0.9rem; }
.style-details summary::-webkit-details-marker { display: none; }
.style-details summary:before { content: '▶ '; font-size: 0.75em; }
.style-details[open] summary:before { content: '▼ '; }
.style-details summary:hover { background-color: #f7fafc; }
.style-controls { padding: 8px 0 0 12px; border-left: 2px solid var(--border); margin-top: 4px; }
.style-controls .form-group { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
.style-controls label { flex-basis: 45px; font-size: 0.85rem; }
.style-controls input[type="range"] { flex-grow: 1; }
.style-controls input[type="color"] { padding: 0; border: none; width: 30px; height: 30px; cursor: pointer; background: none; }

.collage-canvas-container { min-height: 150px; max-height: 30vh; background: #f0f0f0; border-radius: 9px; display: flex; justify-content: center; align-items: center; padding: 8px; overflow: auto; cursor: pointer; }
#collageCanvas { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
.collage-thumbnails { display: flex; flex-wrap: wrap; gap: 7px; padding: 7px; background-color: #f7fafc; border-radius: 7px; min-height: 45px; flex-grow: 1; max-height: 100px; overflow-y: auto; }
.thumbnail-item { position: relative; width: 40px; height: 40px; cursor: grab; transition: transform 0.2s; }
.thumbnail-item.dragging { opacity: 0.5; transform: scale(1.1); }
.thumbnail-item img { width: 100%; height: 100%; object-fit: cover; border-radius: 5px; pointer-events: none; }
.thumbnail-item .delete-btn { position: absolute; top: -4px; right: -4px; width: 15px; height: 15px; background-color: rgba(0,0,0,0.6); color: white; border: none; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; font-size: 10px; font-weight: bold; }

.download-options { padding: 10px; border: 1px solid var(--border); border-radius: 7px; background-color: #f7fafc; }
#compressionOptions { display: flex; flex-direction: column; gap: 4px; margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--border); }

.venn-diagram-maker { display: flex; flex-direction: column; gap: 10px; }
.venn-canvas-container { background-color: #f7fafc; border: 1px solid var(--border); border-radius: 8px; padding: 8px; max-height: 35vh; overflow: auto; }
#vennCanvas { width: 100%; height: auto; display: block; background-color: white; }
.venn-interactive-controls { display: grid; grid-template-columns: 1fr auto 1fr; grid-template-rows: auto auto auto; gap: 4px; grid-template-areas: ". top ." "left-mid center right-mid" "left-bottom bottom-mid right-bottom"; margin-bottom: 10px; align-items: center; }
.venn-control-group { display: flex; align-items: center; gap: 4px; }
.venn-control-group .form-input { flex-grow: 1; }
.color-label { cursor: pointer; }
.color-indicator { display: inline-block; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--border); }

.pixelator-tool { display: flex; flex-direction: column; gap: 10px; }
.pixelator-controls { display: flex; flex-direction: column; gap: 10px; }
.pixelator-sliders { display: flex; flex-direction: column; gap: 7px; }
.pixelator-actions { display: flex; gap: 7px; justify-content: flex-end; }
.pixelator-preview-container { display: flex; justify-content: center; align-items: center; background-color: #f7fafc; border-radius: 8px; min-height: 150px; max-height: 30vh; padding: 8px; overflow: auto; position: relative; border: 1px solid var(--border); }
#pixelatorCanvas { max-width: 100%; max-height: 100%; object-fit: contain; image-rendering: pixelated; }
.placeholder-text { color: #a0aec0; text-align: center; pointer-events: none; position: absolute; }
.placeholder-text span { font-size: 36px; }
.placeholder-text p { margin: 4px 0 0; font-weight: 500; font-size: 0.9rem; }

.color-palette-tool { display: flex; flex-direction: column; gap: 8px; }
.color-palette-content { display: none; }
.color-palette-content.active { display: block; }
.color-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 7px; padding: 7px 4px; max-height: 250px; overflow-y: auto; }
.color-swatch { display: flex; align-items: center; gap: 7px; cursor: pointer; padding: 4px; border-radius: 5px; transition: background-color 0.2s; border: 1px solid transparent; }
.color-swatch:hover { background-color: #f7fafc; border-color: var(--border); }
.color-swatch .color-box { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,0.1); flex-shrink: 0; }
.color-swatch .color-info { display: flex; flex-direction: column; line-height: 1.2; overflow: hidden; }
.color-swatch .color-name { font-size: 0.8em; font-weight: 500; white-space: nowrap; }
.color-swatch .color-hex { font-size: 0.75em; color: var(--text-light); }

.form-hint { font-size: 11px; color: var(--text-light); margin-top: -7px; margin-bottom: 7px; }

@media (max-width: 768px) {
  .header h1 { font-size: 1.9rem; }
  .section-title { font-size: 1.2rem; }
  .tools-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
  .tool-modal-content { padding: 20px; margin: 15px auto; max-height: 92vh; }
}
