:root {
  --primary: #4F46E5;
  --primary-dark: #3730A3;
  --primary-light: #818CF8;
  --secondary: #06B6D4;
  --bg: #F8FAFC;
  --bg-card: #FFFFFF;
  --text: #0F172A;
  --text-muted: #64748B;
  --border: #E2E8F0;
  --success: #10B981;
  --warning: #F59E0B;
  --error: #EF4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

/* ─── DARK THEME ──────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #0F172A;
  --bg-card: #1E293B;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -2px rgba(0,0,0,0.2);
}

[data-theme="dark"] .site-header {
  background: linear-gradient(135deg, #0d0b2a 0%, #3730A3 55%, #5B21B6 100%);
}
[data-theme="dark"] .site-footer { background: #020617; }
[data-theme="dark"] .form-control { background: var(--bg-card); color: var(--text); }
[data-theme="dark"] .drop-zone { background: rgba(79,70,229,0.06); }
[data-theme="dark"] .file-item,
[data-theme="dark"] .output-item { background: var(--bg); }
[data-theme="dark"] .btn-secondary { background: var(--bg-card); }
[data-theme="dark"] input[type="color"] { background: var(--bg-card); }
[data-theme="dark"] .thumbnail-item { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .thumbnail-canvas { background: var(--bg); }
[data-theme="dark"] .tool-card-container { background: var(--border); }
[data-theme="dark"] .tool-section { background: var(--bg-card); }
[data-theme="dark"] .alert-error   { background: #2D1B1B; border-color: #7F1D1D; color: #FCA5A5; }
[data-theme="dark"] .alert-success { background: #0D2E22; border-color: #065F46; color: #6EE7B7; }
[data-theme="dark"] .alert-info    { background: #0C1F3D; border-color: #1E40AF; color: #93C5FD; }
[data-theme="dark"] .alert-warning { background: #2A1F06; border-color: #92400E; color: #FCD34D; }

/* ─── THEME TOGGLE ────────────────────────────────────── */
.theme-toggle {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  color: white;
  border-radius: 8px;
  padding: 7px 11px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.theme-toggle:hover { background: rgba(255,255,255,0.22); }

/* ─── SEARCH BAR ──────────────────────────────────────── */
.search-wrap {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 48px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.search-inner {
  max-width: 1700px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.search-field-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon-el {
  position: absolute;
  left: 13px;
  font-size: 0.95rem;
  pointer-events: none;
  color: var(--text-muted);
  z-index: 1;
}

.search-input {
  width: 100%;
  padding: 9px 38px 9px 38px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.search-input::placeholder { color: var(--text-muted); }

.search-clear {
  position: absolute;
  right: 9px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 3px 7px;
  border-radius: 5px;
  line-height: 1;
  transition: color 0.15s;
}
.search-clear:hover { color: var(--text); }

.search-count {
  font-size: 0.8375rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 80px;
  text-align: right;
}

.search-no-results {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}
.search-no-results-icon { font-size: 2.75rem; margin-bottom: 14px; }
.search-no-results-title { font-size: 1.0625rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.search-no-results-sub  { font-size: 0.875rem; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── SITE HEADER ─────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #1e1b4b 0%, var(--primary) 55%, #7C3AED 100%);
  color: white;
}

.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 48px;
  max-width: 1700px;
  margin: 0 auto;
}

.site-logo {
  font-size: 1.375rem;
  font-weight: 800;
  color: white;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.02em;
}

.hero {
  text-align: center;
  padding: 56px 48px 80px;
  max-width: 820px;
  margin: 0 auto;
}

.hero h1 {
  font-size: 2.875rem;
  font-weight: 800;
  margin-bottom: 14px;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hero p {
  font-size: 1.15rem;
  opacity: 0.88;
  max-width: 500px;
  margin: 0 auto;
}

/* ─── MAIN CONTENT ────────────────────────────────────── */
.main-content {
  max-width: 1700px;
  margin: 0 auto;
  padding: 48px 48px 64px;
  flex: 1;
}

/* ─── CATEGORIES ──────────────────────────────────────── */
.category { margin-bottom: 44px; }

.category-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}

.category-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.category-icon {
  width: 34px;
  height: 34px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
  flex-shrink: 0;
}

/* ─── TOOL CARDS ──────────────────────────────────────── */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}

.tool-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1), var(--shadow-lg);
  transform: translateY(-2px);
}

.tool-card-icon { font-size: 1.625rem; line-height: 1; }
.tool-card-name { font-weight: 600; font-size: 0.9375rem; line-height: 1.3; }
.tool-card-desc { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }

/* ─── TOOL PAGE HEADER ────────────────────────────────── */
.tool-header {
  background: linear-gradient(135deg, #1e1b4b 0%, var(--primary) 100%);
  color: white;
  padding: 20px 48px 44px;
}

.tool-header-nav {
  max-width: 1300px;
  margin: 0 auto;
}

.back-btn {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 14px;
  transition: color 0.15s;
}
.back-btn:hover { color: white; }

.tool-header h1 {
  font-size: 1.875rem;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.tool-header p { font-size: 0.9875rem; opacity: 0.85; }

/* ─── TOOL MAIN ───────────────────────────────────────── */
.tool-main {
  max-width: 1300px;
  margin: -24px auto 0;
  padding: 0 48px 64px;
  flex: 1;
}

.tool-card-container {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.tool-section {
  padding: 28px 36px;
  border-bottom: 1px solid var(--border);
}
.tool-section:last-child { border-bottom: none; }

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ─── DROP ZONE ───────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 44px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
  background: #FAFBFF;
  position: relative;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(79,70,229,0.035);
}

.drop-zone.dragover { box-shadow: 0 0 0 4px rgba(79,70,229,0.1); }

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  font-size: 0;
}

.drop-zone-icon { font-size: 2.75rem; margin-bottom: 10px; }
.drop-zone-title { font-size: 1.0625rem; font-weight: 600; margin-bottom: 4px; }
.drop-zone-subtitle { font-size: 0.875rem; color: var(--text-muted); }
.drop-zone-subtitle span { color: var(--primary); font-weight: 500; }

/* ─── FILE LIST ───────────────────────────────────────── */
.file-list { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }

.file-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.drag-handle { color: var(--text-muted); cursor: grab; font-size: 1rem; padding: 0 2px; }
.drag-handle:active { cursor: grabbing; }
.file-item-icon { color: var(--primary); flex-shrink: 0; }
.file-item-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item-size { color: var(--text-muted); font-size: 0.8rem; flex-shrink: 0; }

.file-item-remove {
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 1.125rem;
  line-height: 1;
  flex-shrink: 0;
}
.file-item-remove:hover { color: var(--error); background: #FEF2F2; }

.file-item.dragging { opacity: 0.4; }
.file-item.drag-over { border-color: var(--primary); background: rgba(79,70,229,0.04); }

/* ─── FORMS ───────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 5px;
}

.form-help { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.form-control {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9375rem;
  color: var(--text);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

textarea.form-control { min-height: 200px; resize: vertical; font-family: monospace; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.form-check { display: flex; align-items: center; gap: 8px; font-size: 0.9375rem; cursor: pointer; }
.form-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }

.range-group { display: flex; align-items: center; gap: 12px; }
.range-value {
  min-width: 40px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary);
  background: rgba(79,70,229,0.08);
  padding: 3px 8px;
  border-radius: 6px;
}

input[type="range"] {
  -webkit-appearance: none;
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input[type="color"] {
  width: 42px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  cursor: pointer;
  background: white;
}

.color-row { display: flex; align-items: center; gap: 10px; }

/* ─── BUTTONS ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary { background: white; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-secondary:hover:not(:disabled) { background: rgba(79,70,229,0.05); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #059669; }

.btn-danger { background: var(--error); color: white; }
.btn-danger:hover:not(:disabled) { background: #DC2626; }

.btn-lg { padding: 12px 26px; font-size: 1rem; border-radius: 10px; }
.btn-full { width: 100%; }

/* ─── PROGRESS ────────────────────────────────────────── */
.progress-container { margin: 12px 0 4px; }

.progress-bar {
  background: var(--border);
  border-radius: 999px;
  height: 7px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 999px;
  transition: width 0.25s ease;
  width: 0%;
}

.progress-text { font-size: 0.8375rem; color: var(--text-muted); }

/* ─── ALERTS ──────────────────────────────────────────── */
.alert {
  padding: 11px 15px;
  border-radius: 8px;
  font-size: 0.9rem;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 14px;
}
.alert-icon { flex-shrink: 0; margin-top: 1px; }

.alert-error { background: #FEF2F2; border: 1px solid #FECACA; color: #991B1B; }
.alert-success { background: #ECFDF5; border: 1px solid #A7F3D0; color: #065F46; }
.alert-info { background: #EFF6FF; border: 1px solid #BFDBFE; color: #1E40AF; }
.alert-warning { background: #FFFBEB; border: 1px solid #FDE68A; color: #92400E; }

/* ─── RESULT ──────────────────────────────────────────── */
.result-section { text-align: center; padding: 6px 0 2px; }
.result-filename { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.result-info { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 18px; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ─── THUMBNAILS ──────────────────────────────────────── */
.thumbnails-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.thumbnail-item {
  background: white;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 7px;
  cursor: grab;
  transition: all 0.15s;
  text-align: center;
  user-select: none;
  position: relative;
}
.thumbnail-item:hover { border-color: var(--primary-light); box-shadow: var(--shadow); }
.thumbnail-item.dragging { opacity: 0.35; cursor: grabbing; }
.thumbnail-item.drag-over { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.18); }

.thumbnail-canvas {
  width: 100%;
  aspect-ratio: 1/1.414;
  object-fit: contain;
  display: block;
  background: #F1F5F9;
  border-radius: 3px;
  margin-bottom: 5px;
}

.thumbnail-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }

.thumbnail-cb {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* ─── OUTPUT LIST ─────────────────────────────────────── */
.output-list { display: flex; flex-direction: column; gap: 8px; }

.output-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.output-item-name { flex: 1; font-size: 0.9rem; font-weight: 500; }
.output-item-btn { flex-shrink: 0; }

/* ─── SITE FOOTER ─────────────────────────────────────── */
.site-footer {
  background: var(--text);
  color: rgba(255,255,255,0.5);
  text-align: center;
  padding: 20px;
  font-size: 0.8375rem;
  margin-top: auto;
}

/* ─── UTILITIES ───────────────────────────────────────── */
.mt-16 { margin-top: 16px; }
.mt-12 { margin-top: 12px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.hidden { display: none !important; }

/* ─── TWO-COLUMN PANEL LAYOUT (tool pages, wide screens) ─ */
@media (min-width: 900px) {
  /* Upload + options panels sit side by side; result spans full width */
  .tool-card-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    background: var(--border); /* shows through gaps as dividers */
    gap: 1px;
  }
  .tool-section {
    background: var(--bg-card);
    border-bottom: none;
    height: 100%;
  }
  /* Result section always spans the full width */
  #resultSection {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
    height: auto;
  }
  /* Single-section tools (no split needed) */
  .tool-card-container > .tool-section:only-child {
    grid-column: 1 / -1;
  }
}

/* ─── RESPONSIVE ──────────────────────────────────────── */
@media (max-width: 900px) {
  /* Collapse 2-col grid back to single column on narrower screens */
  .tool-card-container {
    display: block;
  }
  .tool-section {
    border-bottom: 1px solid var(--border);
  }
  .tool-section:last-child { border-bottom: none; }
}

@media (max-width: 768px) {
  .hero h1 { font-size: 1.875rem; }
  .hero { padding: 40px 20px 60px; }
  .main-content { padding: 32px 16px 48px; }
  .tool-header { padding: 16px 20px 40px; }
  .tool-main { padding: 0 16px 48px; }
  .tool-section { padding: 20px 18px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .tools-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .site-nav { padding: 14px 20px; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.625rem; }
  .tools-grid { grid-template-columns: 1fr 1fr; }
  .result-actions { flex-direction: column; }
  .result-actions .btn { width: 100%; }
}

@media (max-width: 960px) {
  .search-wrap { padding: 11px 20px; }
}
@media (max-width: 500px) {
  .search-wrap { padding: 10px 14px; }
  .search-count { display: none; }
}
