/* ===== CSS Custom Properties ===== */
:root {
  --primary: #e5322d;
  --primary-dark: #c62828;
  --primary-light: #ff6659;
  --primary-gradient: linear-gradient(135deg, #e5322d 0%, #ff6659 100%);
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --border: #e9ecef;
  --shadow: 0 2px 16px rgba(0,0,0,0.06);
  --shadow-hover: 0 8px 30px rgba(229,50,45,0.13);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.3s cubic-bezier(.4,0,.2,1);
  --header-height: 68px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #1e1e34;
  --text: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #5c5c78;
  --border: #2a2a44;
  --shadow: 0 2px 16px rgba(0,0,0,0.3);
  --shadow-hover: 0 8px 30px rgba(229,50,45,0.22);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
  line-height: 1.6;
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; display: block; }

/* ===== Utility ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.35rem;
  color: var(--text);
  text-decoration: none;
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: var(--primary-gradient);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
}

.nav { display: flex; align-items: center; gap: 8px; }

.nav a {
  padding: 8px 16px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.92rem;
  transition: all var(--transition);
}
.nav a:hover, .nav a.active {
  background: rgba(229,50,45,0.08);
  color: var(--primary);
}

.dark-toggle {
  width: 42px;
  height: 42px;
  border: none;
  background: var(--bg-secondary);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--text);
  transition: all var(--transition);
  margin-left: 8px;
}
.dark-toggle:hover { background: var(--border); transform: rotate(20deg); }

.mobile-menu-btn {
  display: none;
  width: 42px;
  height: 42px;
  border: none;
  background: none;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.mobile-menu-btn span {
  display: block;
  width: 24px;
  height: 2.5px;
  background: var(--text);
  border-radius: 2px;
  transition: all var(--transition);
}

/* ===== Hero ===== */
.hero {
  padding: 80px 0 60px;
  text-align: center;
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(229,50,45,0.08) 0%, transparent 70%);
  top: -200px;
  right: -100px;
  pointer-events: none;
}
.hero::after {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(229,50,45,0.06) 0%, transparent 70%);
  bottom: -150px;
  left: -100px;
  pointer-events: none;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  margin-bottom: 16px;
  line-height: 1.15;
}
.hero h1 span { color: var(--primary); }

.hero p {
  font-size: clamp(1rem, 2vw, 1.2rem);
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 32px;
}

.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  background: var(--primary-gradient);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 20px rgba(229,50,45,0.3);
}
.hero-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(229,50,45,0.4);
  color: #fff;
}

/* ===== Section ===== */
.section {
  padding: 60px 0;
}

.section-title {
  text-align: center;
  font-size: 1.9rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.section-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 40px;
  font-size: 1.05rem;
}

/* ===== Category Tabs ===== */
.category-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 36px;
}

.cat-tab {
  padding: 8px 20px;
  border-radius: 50px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
}
.cat-tab:hover, .cat-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== Tools Grid ===== */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tool-card:hover {
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}
.tool-card:hover .tool-icon {
  transform: scale(1.1);
}

.tool-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 14px;
  transition: transform var(--transition);
  color: #fff;
}

.tool-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.tool-card p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Icon color variants */
.icon-red { background: linear-gradient(135deg, #e5322d, #ff6659); }
.icon-blue { background: linear-gradient(135deg, #2196F3, #42a5f5); }
.icon-green { background: linear-gradient(135deg, #4CAF50, #66bb6a); }
.icon-orange { background: linear-gradient(135deg, #FF9800, #ffb74d); }
.icon-purple { background: linear-gradient(135deg, #9C27B0, #ba68c8); }
.icon-teal { background: linear-gradient(135deg, #009688, #4db6ac); }
.icon-pink { background: linear-gradient(135deg, #E91E63, #f06292); }
.icon-indigo { background: linear-gradient(135deg, #3F51B5, #7986cb); }

/* ===== Features ===== */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
  margin-top: 40px;
}

.feature-card {
  padding: 32px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  transition: all var(--transition);
}
.feature-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
}

.feature-icon {
  width: 52px;
  height: 52px;
  background: rgba(229,50,45,0.08);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--primary);
  margin: 0 auto 16px;
}

.feature-card h3 {
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.feature-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ===== Footer ===== */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 48px 0 24px;
  transition: background var(--transition), border-color var(--transition);
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 32px;
  margin-bottom: 32px;
}

.footer-brand p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 12px;
  line-height: 1.6;
}

.footer h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.footer ul { list-style: none; }
.footer ul li { margin-bottom: 10px; }
.footer ul a {
  color: var(--text-secondary);
  font-size: 0.88rem;
  transition: color var(--transition);
}
.footer ul a:hover { color: var(--primary); }

.footer-bottom {
  text-align: center;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ===== Tool Page ===== */
.tool-page {
  padding: 32px 0 60px;
  min-height: calc(100vh - var(--header-height));
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--primary); }

.tool-header {
  text-align: center;
  margin-bottom: 36px;
}
.tool-header h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 10px;
}
.tool-header p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 540px;
  margin: 0 auto;
}

/* Upload Area */
.upload-area {
  max-width: 680px;
  margin: 0 auto 32px;
  border: 2.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 60px 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-card);
  position: relative;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
  background: rgba(229,50,45,0.03);
}
[data-theme="dark"] .upload-area:hover,
[data-theme="dark"] .upload-area.drag-over {
  background: rgba(229,50,45,0.06);
}

.upload-icon {
  font-size: 3rem;
  color: var(--primary);
  margin-bottom: 16px;
}

.upload-area h3 {
  font-size: 1.15rem;
  margin-bottom: 8px;
}
.upload-area p {
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 12px 28px;
  background: var(--primary-gradient);
  color: #fff;
  font-weight: 700;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all var(--transition);
  box-shadow: 0 4px 16px rgba(229,50,45,0.25);
}
.upload-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(229,50,45,0.35);
}

.upload-area input[type="file"] { display: none; }

/* File List */
.file-list {
  max-width: 680px;
  margin: 0 auto 24px;
  display: none;
}
.file-list.show { display: block; }

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: all var(--transition);
}

.file-item:hover { border-color: var(--primary); }

.file-item-icon {
  width: 40px;
  height: 40px;
  background: rgba(229,50,45,0.08);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 1.1rem;
  flex-shrink: 0;
}

.file-item-info { flex: 1; min-width: 0; }
.file-item-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-item-size {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.file-item-remove {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(229,50,45,0.08);
  color: var(--primary);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.file-item-remove:hover {
  background: var(--primary);
  color: #fff;
}

/* Drag handle for sortable */
.file-item-drag {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* Tool Options */
.tool-options {
  max-width: 680px;
  margin: 0 auto 24px;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: none;
}
.tool-options.show { display: block; }

.tool-options label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 8px;
}

.tool-options select,
.tool-options input[type="text"],
.tool-options input[type="number"],
.tool-options input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 16px;
}
.tool-options select:focus,
.tool-options input:focus {
  border-color: var(--primary);
}

.tool-options input[type="range"] {
  width: 100%;
  margin-bottom: 16px;
  accent-color: var(--primary);
}

.option-row {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.option-row > div { flex: 1; min-width: 160px; }

/* Process Button */
.process-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: 680px;
  margin: 0 auto 24px;
  width: 100%;
  padding: 16px;
  background: var(--primary-gradient);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 20px rgba(229,50,45,0.25);
  display: none;
}
.process-btn.show { display: flex; }
.process-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(229,50,45,0.35);
}
.process-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Progress */
.progress-area {
  max-width: 680px;
  margin: 0 auto 24px;
  display: none;
}
.progress-area.show { display: block; }

.progress-bar-container {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 50px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar {
  height: 100%;
  background: var(--primary-gradient);
  border-radius: 50px;
  width: 0%;
  transition: width 0.4s ease;
}

.progress-text {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Result */
.result-area {
  max-width: 680px;
  margin: 0 auto 24px;
  text-align: center;
  display: none;
  padding: 40px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.result-area.show { display: block; }

.result-icon {
  font-size: 3.5rem;
  color: #4CAF50;
  margin-bottom: 16px;
}

.result-area h3 {
  font-size: 1.3rem;
  margin-bottom: 8px;
}

.result-area p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  background: linear-gradient(135deg, #4CAF50, #66bb6a);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 20px rgba(76,175,80,0.3);
  margin-right: 10px;
}
.download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(76,175,80,0.4);
  color: #fff;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  background: #25D366;
  color: #fff;
  font-weight: 700;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: all var(--transition);
}
.share-btn:hover { opacity: 0.9; }

.restart-btn {
  display: block;
  margin: 16px auto 0;
  padding: 10px 24px;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 50px;
  color: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition);
}
.restart-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Canvas / Preview area */
.preview-area {
  max-width: 680px;
  margin: 0 auto 24px;
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow: auto;
  max-height: 500px;
}
.preview-area.show { display: block; }

/* ===== Notification Toast ===== */
.toast {
  position: fixed;
  bottom: 32px;
  right: 32px;
  padding: 14px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 500;
  z-index: 9999;
  transform: translateY(120%);
  transition: transform 0.4s cubic-bezier(.4,0,.2,1);
  max-width: 360px;
}
.toast.show { transform: translateY(0); }
.toast.error { border-left: 4px solid var(--primary); }
.toast.success { border-left: 4px solid #4CAF50; }

/* ===== Loader Spinner ===== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Responsive ===== */
@media (max-width: 992px) {
  .footer-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .nav { display: none; }
  .mobile-menu-btn { display: flex; }

  .nav.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  }

  .hero { padding: 50px 0 40px; }

  .tools-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }

  .tool-card { padding: 20px 14px; }
  .tool-icon { width: 48px; height: 48px; font-size: 1.3rem; }

  .footer-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .upload-area { padding: 40px 20px; }

  .option-row { flex-direction: column; gap: 0; }
  .option-row > div { min-width: 100%; }
}

@media (max-width: 480px) {
  .tools-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .tool-card h3 { font-size: 0.85rem; }
  .tool-card p { display: none; }
  .section-title { font-size: 1.5rem; }
  .hero h1 { font-size: 1.7rem; }
}

/* ===== Animations ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: fadeInUp 0.5s ease both;
}

.tool-card:nth-child(1) { animation-delay: 0.02s; }
.tool-card:nth-child(2) { animation-delay: 0.04s; }
.tool-card:nth-child(3) { animation-delay: 0.06s; }
.tool-card:nth-child(4) { animation-delay: 0.08s; }
.tool-card:nth-child(5) { animation-delay: 0.10s; }
.tool-card:nth-child(6) { animation-delay: 0.12s; }
.tool-card:nth-child(7) { animation-delay: 0.14s; }
.tool-card:nth-child(8) { animation-delay: 0.16s; }
.tool-card:nth-child(9) { animation-delay: 0.18s; }
.tool-card:nth-child(10) { animation-delay: 0.20s; }
.tool-card:nth-child(11) { animation-delay: 0.22s; }
.tool-card:nth-child(12) { animation-delay: 0.24s; }
.tool-card:nth-child(13) { animation-delay: 0.26s; }
.tool-card:nth-child(14) { animation-delay: 0.28s; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Sign canvas */
.sign-canvas-wrap {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
}
.sign-canvas-wrap canvas {
  width: 100%;
  height: 200px;
  cursor: crosshair;
  display: block;
  background: #fff;
}
.sign-actions { display: flex; gap: 10px; margin-bottom: 16px; }
.sign-actions button {
  padding: 8px 18px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.88rem;
  transition: all var(--transition);
}
.sign-actions button:hover {
  border-color: var(--primary);
  color: var(--primary);
}
