/* ===== CSS Variables & Reset ===== */
:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text: #1c1917;
  --text-secondary: #57534e;
  --text-muted: #a8a29e;
  --border: #e7e5e4;
  --primary: #e11d48;
  --primary-hover: #be123c;
  --primary-soft: #fff1f2;
  --accent: #f43f5e;
  --success: #10b981;
  --danger: #dc2626;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.08);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #0c0a09;
  --bg-card: #1c1917;
  --bg-elevated: #292524;
  --text: #fafaf9;
  --text-secondary: #a8a29e;
  --text-muted: #78716c;
  --border: #292524;
  --primary: #fb7185;
  --primary-hover: #f43f5e;
  --primary-soft: #4c0519;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 25px -5px rgb(0 0 0 / 0.4);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

button, input, label { font: inherit; }

/* ===== Layout ===== */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.25rem;
}

.logo-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}

.logo-text span { color: var(--primary); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.install-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.45rem 0.9rem 0.45rem 0.7rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 35%, transparent);
}
.install-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}
.install-btn svg { flex-shrink: 0; }
.install-btn.hidden { display: none !important; }

@media (max-width: 420px) {
  .install-btn .install-label { display: none; }
  .install-btn { padding: 0.5rem; border-radius: 50%; width: 42px; height: 42px; justify-content: center; }
}

.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: var(--transition);
}
.theme-toggle:hover { background: var(--primary-soft); }
.theme-toggle .moon { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .moon { display: inline; }

/* Install modal (iOS guide) */
.install-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}
.install-modal.hidden { display: none !important; }
.install-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(4px);
}
.install-modal-content {
  position: relative;
  background: var(--bg-card);
  color: var(--text);
  border-radius: 20px 20px 16px 16px;
  padding: 1.75rem 1.5rem 1.5rem;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: none; }
}
.install-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.install-modal-icon img {
  border-radius: 14px;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}
.install-modal-content h2 {
  font-size: 1.25rem;
  margin-bottom: 0.4rem;
}
.install-modal-content > p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.1rem;
  line-height: 1.45;
}
.install-steps {
  text-align: left;
  margin: 0 0 1.25rem;
  padding-left: 1.25rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}
.install-steps li { margin-bottom: 0.35rem; }
.install-steps strong { color: var(--text); }
.install-modal-content .btn { width: 100%; }

.main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  padding-bottom: calc(2rem + var(--safe-bottom));
}

.view { display: none; animation: fadeIn 0.3s ease; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ===== Hero ===== */
.hero {
  text-align: center;
  margin-bottom: 2rem;
  padding: 0.5rem 0 1rem;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

.hero-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.hero h1 {
  font-size: clamp(2.25rem, 8vw, 3.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 0.75rem;
}

.hero h1 span {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 420px;
  margin: 0 auto;
}

/* ===== Tools Grid ===== */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}

@media (min-width: 640px) {
  .tools-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1.25rem; }
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  min-height: 140px;
  position: relative;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}

.tool-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 40%, color-mix(in srgb, var(--card-color, var(--primary)) 8%, transparent));
  opacity: 0;
  transition: opacity var(--transition);
}

.tool-card:hover, .tool-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--card-color, var(--primary)) 40%, var(--border));
}

.tool-card:hover::before { opacity: 1; }

.tool-card:active { transform: translateY(-1px); }

.tool-icon {
  font-size: 2.25rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgb(0 0 0 / 0.1));
}

.tool-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.tool-card-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ===== Tool View ===== */
.tool-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.back-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 1.25rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: var(--transition);
  color: var(--text);
}
.back-btn:hover { background: var(--primary-soft); color: var(--primary); }

.tool-title-wrap h2 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tool-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

/* ===== Dropzone ===== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 2.5rem 1.5rem;
  text-align: center;
  transition: var(--transition);
  cursor: pointer;
}

.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: scale(1.01);
}

.drop-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.drop-text { font-weight: 600; font-size: 1.1rem; margin-bottom: 0.25rem; }
.drop-hint { color: var(--text-muted); font-size: 0.9rem; margin: 0.5rem 0; }
.drop-formats { color: var(--text-muted); font-size: 0.8rem; margin-top: 1rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  min-height: 48px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 35%, transparent);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--primary); }

.file-label { cursor: pointer; }

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== File List ===== */
.file-list {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  animation: fadeIn 0.25s ease;
}

.file-icon { font-size: 1.5rem; flex-shrink: 0; }

.file-info { flex: 1; min-width: 0; }
.file-name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-meta { font-size: 0.75rem; color: var(--text-muted); }

.file-actions { display: flex; gap: 0.35rem; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  transition: var(--transition);
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }
.icon-btn.danger:hover { background: #fef2f2; color: var(--danger); }

/* ===== Options Panel ===== */
.options-panel {
  margin-top: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.options-panel h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.option-group {
  margin-bottom: 1rem;
}
.option-group:last-child { margin-bottom: 0; }

.option-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.option-group input[type="text"],
.option-group input[type="url"],
.option-group input[type="number"],
.option-group select {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  transition: var(--transition);
}
.option-group input:focus,
.option-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.option-group textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  resize: vertical;
  min-height: 140px;
  transition: var(--transition);
}
.option-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.range-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.range-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.range-value {
  min-width: 3ch;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary);
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.radio-pill {
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: var(--transition);
}
.radio-pill:has(input:checked),
.radio-pill.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.radio-pill input { display: none; }

/* ===== Action Bar ===== */
.action-bar {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ===== Progress ===== */
.progress-wrap {
  margin-top: 1.5rem;
  text-align: center;
}
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s ease;
}
.progress-text { font-size: 0.9rem; color: var(--text-secondary); }

/* ===== Result ===== */
.result-panel {
  margin-top: 1.5rem;
  text-align: center;
  padding: 2rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.result-icon { font-size: 2.5rem; }
.result-panel h3 { margin: 0.5rem 0; font-size: 1.3rem; }
.result-panel p { color: var(--text-secondary); margin-bottom: 1.25rem; }
.result-panel .btn { margin: 0.35rem; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--bg);
  padding: 0.85rem 1.4rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Utilities ===== */
.hidden { display: none !important; }

.footer {
  margin-top: 3rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.footer-links {
  margin-top: 0.6rem;
}
.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
}
.footer-links a:hover { color: var(--primary); text-decoration: underline; }
.footer-links span { margin: 0 0.4rem; color: var(--text-muted); }

/* ===== Categories ===== */
.category-section {
  margin-bottom: 2rem;
}
.category-title {
  font-size: 1.25rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
  margin-bottom: 0.85rem;
  padding-left: 0.15rem;
}

/* ===== Legal / Static Pages ===== */
.legal-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.5rem 0 2rem;
}
.legal-page h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}
.legal-page .updated {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 2rem;
}
.legal-page h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 1.75rem 0 0.65rem;
}
.legal-page p, .legal-page li {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 0.75rem;
}
.legal-page ul { padding-left: 1.25rem; margin-bottom: 0.75rem; }
.legal-page a { color: var(--primary); }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}
.back-link:hover { color: var(--primary); }

/* ===== Contact Form ===== */
.contact-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1.5rem;
  box-shadow: var(--shadow);
}
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text);
}
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color var(--transition);
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 130px; }
.form-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}
.contact-alt {
  margin-top: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
}
.contact-alt a { color: var(--primary); font-weight: 600; text-decoration: none; }

/* Mobile refinements */
@media (max-width: 480px) {
  .tools-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
  .tool-card { min-height: 120px; padding: 1rem 0.75rem; }
  .tool-icon { font-size: 1.9rem; }
  .action-bar { flex-direction: column-reverse; }
  .action-bar .btn { width: 100%; }
}
