
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --error: #ef4444;
  --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);
  --radius: 12px;
}

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

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

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: white;
  padding: 8px 16px;
  z-index: 1000;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.search-box {
  flex: 1;
  max-width: 400px;
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--bg);
  transition: all 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  background: white;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Main layout */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* Hero */
.hero {
  text-align: center;
  margin-bottom: 40px;
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  color: var(--text-muted);
  font-size: 1.1rem;
  max-width: 600px;
  margin: 0 auto;
}

.home-intro {
  max-width: 900px;
  margin: 0 auto 28px;
  color: var(--text-muted);
}
.home-intro h2 { margin-bottom: 8px; color: var(--text); font-size: 1.2rem; }
.home-intro p { margin-bottom: 10px; }
.home-intro nav { display: flex; flex-wrap: wrap; gap: 8px 18px; }

/* Category tabs */
.categories {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 32px;
}

.cat-btn {
  padding: 8px 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
}

.cat-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.cat-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

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

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  font-family: inherit;
  font-size: inherit;
  text-decoration: none;
  color: inherit;
}

.tool-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

.tool-card:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.tool-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
}

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

.tool-card p {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.tool-content { max-width: 760px; margin: 40px auto 0; }
.tool-content h2 { margin: 28px 0 8px; font-size: 1.3rem; }
.tool-content h3 { margin: 18px 0 4px; font-size: 1rem; }
.tool-content p { margin-bottom: 12px; color: var(--text-muted); }
.tool-content a, main a { color: var(--primary-dark); }
.info-page { max-width: 820px; margin: 0 auto; }
.info-page h1 { font-size: 2rem; margin-bottom: 10px; }
.info-page h2 { margin: 30px 0 8px; font-size: 1.3rem; }
.info-page h3 { margin: 20px 0 6px; font-size: 1rem; }
.info-page p, .info-page li { color: var(--text-muted); }
.info-page ul { padding-left: 22px; margin: 8px 0 16px; }
.info-page .updated { font-size: .875rem; color: var(--text-muted); margin-bottom: 24px; }
.category-page { max-width: 1000px; margin: 0 auto; }
.category-page > p { color: var(--text-muted); max-width: 720px; }
nav[aria-label="Breadcrumb"] { margin: 0 0 20px; color: var(--text-muted); font-size: .9rem; }
.site-links { display:flex; justify-content:center; flex-wrap:wrap; gap:16px; margin-top:16px; }
.site-links a { color:var(--primary-dark); }
.category-links { display:flex; justify-content:center; flex-wrap:wrap; gap:10px; margin:0 auto 28px; }
.category-links a { border:1px solid var(--border); background:white; border-radius:8px; padding:8px 12px; text-decoration:none; }

/* Tool view */
.tool-view {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tool-view.active { display: block; }

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

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  transition: all 0.2s;
  font-family: inherit;
}

.back-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tool-header {
  margin-bottom: 24px;
}

.tool-header h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.tool-header p {
  color: var(--text-muted);
}

.tool-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

/* Form controls */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg);
  transition: all 0.2s;
  resize: vertical;
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  background: white;
}

textarea {
  min-height: 150px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.85rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-secondary:hover {
  background: var(--border);
}

.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* File drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: #eef2ff;
}

.drop-zone-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: block;
}

.drop-zone p {
  color: var(--text-muted);
  margin-bottom: 4px;
}

.drop-zone small {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #eef2ff;
  border-radius: 8px;
  margin-top: 12px;
  font-size: 0.9rem;
}

.file-info .remove {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
}

/* Output area */
.output-area {
  margin-top: 24px;
  padding: 20px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  display: none;
}

.output-area.visible { display: block; }

.output-area h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.output-content {
  background: white;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow: auto;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease;
  z-index: 2000;
  pointer-events: none;
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }

/* Image preview */
.img-preview {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  margin-top: 12px;
  display: block;
}

/* Grid helpers */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* Range input */
input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.range-value {
  font-weight: 600;
  color: var(--primary);
}

/* Checkbox */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.checkbox-group label {
  margin: 0;
  cursor: pointer;
  font-weight: 400;
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* No results */
.no-results {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  grid-column: 1 / -1;
}

/* Footer */
footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 32px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

footer a { color: var(--primary); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 768px) {
  .header-inner { flex-wrap: wrap; }
  .search-box { max-width: 100%; order: 3; width: 100%; }
  .hero h1 { font-size: 1.8rem; }
  .tools-grid { grid-template-columns: 1fr; }
  .tool-panel { padding: 20px; }
  main { padding: 20px 16px 48px; }
}

#sw-display { font-size: clamp(2.2rem, 13vw, 4rem) !important; }

/* Print */
@media print {
  header, footer, .back-btn, .btn-group { display: none; }
}

/* Hidden utility */
.hidden { display: none !important; }
