:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel-2: #1a243a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --border: #293449;
  --danger: #ef4444;
  --success: #22c55e;
  --max: 960px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

header, main, footer { max-width: var(--max); margin: 0 auto; padding: 1rem; }
header { padding-top: 1.5rem; text-align: center; }
header h1 { font-size: 1.85rem; margin: 0 0 0.4rem; letter-spacing: -0.01em; }
.subtitle { color: var(--muted); margin: 0 auto; max-width: 32em; font-size: 0.95rem; }

.tool {
  background: var(--panel);
  border-radius: 14px;
  padding: 1.25rem;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  outline: none;
}
.dropzone:focus-visible { border-color: var(--accent); }
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.06);
}
.dz-title { font-size: 1.1rem; margin: 0; font-weight: 600; }
.dz-or { color: var(--muted); margin: 0.4rem 0; font-size: 0.85rem; }
.dz-formats { color: var(--muted); font-size: 0.8rem; margin: 1rem 0 0.25rem; }
.dz-hint { color: var(--muted); font-size: 0.75rem; margin: 0.25rem 0 0; }

.btn-primary, .btn-secondary {
  font-size: 0.95rem;
  padding: 0.7rem 1.4rem;
  border-radius: 8px;
  border: 0;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.hidden { display: none !important; }

.error {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid var(--danger);
  color: #fecaca;
  font-size: 0.9rem;
}

.progress { margin-top: 1rem; }
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width .15s ease;
}
#progress-text {
  text-align: center;
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.editor { display: grid; gap: 1rem; }

.editor-canvas-wrap {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 280px;
  touch-action: none;
}
.editor-canvas-wrap canvas {
  max-width: 100%;
  height: auto;
  display: block;
  -webkit-user-drag: none;
}
.mask-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
.zoom-hint {
  position: absolute;
  bottom: 0.5rem;
  right: 0.75rem;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.7rem;
}

.editor-controls {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.tool-row, .brush-row, .action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.tool-row { padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.tool-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.3rem 0;
}
.brush-row label {
  flex: 1;
  min-width: 200px;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brush-row input[type="range"] { flex: 1; }
.action-row { gap: 0.75rem; }
.action-row .btn-primary { flex: 1; min-width: 140px; }

.result { text-align: center; }
.result h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.result img {
  max-width: 100%;
  border-radius: 10px;
  margin: 0.5rem 0;
  background: #fff;
}
.result-info {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.25rem 0 1rem;
}
.result .btn-primary,
.result .btn-secondary { margin: 0.25rem; min-width: 120px; }

.explainer {
  margin: 2rem 0 1rem;
  padding: 0 0.25rem;
}
.explainer h2 {
  margin: 2rem 0 0.75rem;
  font-size: 1.25rem;
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}
.explainer h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
  color: var(--accent);
}
.explainer p { margin: 0.5rem 0; }
.explainer ul { padding-left: 1.25rem; margin: 0.5rem 0; }
.explainer li { margin: 0.3rem 0; font-size: 0.9rem; }
.explainer details {
  margin: 0.5rem 0;
  padding: 0.6rem 0.85rem;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.explainer summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.2rem 0;
}
.explainer details[open] summary { color: var(--accent); margin-bottom: 0.4rem; }
.explainer details p { margin: 0.4rem 0 0; color: var(--muted); }


/* Site-wide top navigation */
.site-nav {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.site-nav .brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}
.site-nav nav {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.site-nav nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  font-size: 0.85rem;
  white-space: nowrap;
}
.site-nav nav a:hover {
  color: var(--text);
  background: var(--panel-2);
}
.site-nav nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--panel-2);
}

/* Site-wide footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  margin-top: 2rem;
}
.site-footer-row {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.8rem;
}
.site-footer-row nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}
.site-footer-row nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
}
.site-footer-row nav a:hover {
  color: var(--text);
  background: var(--panel);
}
.site-footer-row nav a[aria-current="page"] {
  color: var(--accent);
}

/* Legal / about / contact pages */
.page { padding: 1.5rem 1rem 2rem; }
.page h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.page h2 { font-size: 1.1rem; margin-top: 1.5rem; margin-bottom: 0.5rem; }
.page p, .page li { line-height: 1.55; color: var(--text); }
.page ul { padding-left: 1.25rem; margin: 0.5rem 0; }
.page ul li { margin-bottom: 0.4rem; }
.page-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.25rem; }
.contact-email { font-size: 1.05rem; margin: 0.75rem 0 1.25rem; }
.contact-email a { color: var(--accent); font-weight: 600; }
.back-link { margin-top: 1.5rem; font-size: 0.9rem; }
.back-link a { color: var(--accent); text-decoration: none; }
.back-link a:hover { text-decoration: underline; }
footer {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem 3rem;
  font-size: 0.78rem;
}

@media (max-width: 640px) {
  header { padding-top: 0.75rem; }
  header h1 { font-size: 1.4rem; }
  .tool { padding: 0.85rem; border-radius: 12px; }
  .dropzone { padding: 1.5rem 0.5rem; }
  .dz-title { font-size: 1rem; }
  .btn-primary, .btn-secondary { padding: 0.8rem 1rem; font-size: 1rem; }
  .editor-canvas-wrap { min-height: 220px; }
  .action-row { flex-direction: column; align-items: stretch; }
  .action-row .btn-primary,
  .action-row .btn-secondary { width: 100%; }
  .explainer h2 { font-size: 1.1rem; }
}

  .site-nav { flex-direction: column; align-items: stretch; gap: 0.5rem; padding: 0.75rem 1rem; }
  .site-nav nav { justify-content: flex-start; }
  .site-footer-row { flex-direction: column; align-items: flex-start; }
  .site-footer-row nav { width: 100%; justify-content: flex-start; }
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --panel: #ffffff;
    --panel-2: #f1f5f9;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --accent: #0284c7;
    --accent-hover: #0369a1;
  }
  .result img { background: var(--panel-2); }
  .editor-canvas-wrap { background: #1e293b; }
}