/* MediForge: Image & Media Tools (vanilla HTML/CSS/JS)
   Optimized for fast loading: small CSS surface area, no heavy effects. */

:root{
  --bg:#f7f8fc;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#475569;
  --brand:#2563eb;
  --brand2:#7c3aed;
  --border:rgba(2,6,23,.10);
  --shadow:0 10px 25px rgba(2,6,23,.06);
  --shadow2:0 12px 30px rgba(37,99,235,.12);
  --ring:rgba(37,99,235,.25);
  --radius:18px;
  --success:#10b981;
  --error:#ef4444;
  --warning:#f59e0b;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:'Outfit',ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;
  background:
    radial-gradient(circle at 0% 0%, rgba(37,99,235,.08) 0, transparent 50%),
    radial-gradient(circle at 100% 0%, rgba(124,58,237,.06) 0, transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(37,99,235,.04) 0, transparent 50%),
    radial-gradient(circle at 0% 100%, rgba(124,58,237,.06) 0, transparent 50%),
    var(--bg);
  color:var(--text);
}

img{max-width:100%;height:auto}
button,input,select,textarea{font:inherit}
a{color:inherit;text-decoration:none}

.container{
  width:100%;
  max-width:1120px;
  margin:0 auto;
  padding:0 16px;
}

/* Header */
.site-header{
  position:sticky;
  top:0;
  z-index:50;
  background:rgba(247,248,252,.72);
  backdrop-filter:saturate(1.2) blur(10px);
  border-bottom:1px solid var(--border);
}
.nav{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:12px 0;
}
.brand{
  display:flex;
  align-items:center;
  gap:10px;
  font-weight:800;
  letter-spacing:.2px;
}
.logo{
  width:34px;height:34px;border-radius:12px;
  background:linear-gradient(135deg,var(--brand),var(--brand2));
  box-shadow:var(--shadow2);
  display:grid;place-items:center;color:#fff;font-weight:900;
}
.nav-links{
  display:flex;
  align-items:center;
  gap:16px;
}
.nav-links a{
  color:var(--muted);
  font-weight:650;
  font-size:14px;
  padding:10px 12px;
  border-radius:12px;
  transition:background .15s ease,color .15s ease,transform .15s ease;
}
.nav-links a:hover{
  background:rgba(37,99,235,.08);
  color:var(--text);
  transform:translateY(-1px);
}
.menu-btn{
  display:none;
  border:1px solid var(--border);
  background:rgba(255,255,255,.7);
  border-radius:12px;
  padding:10px 12px;
  cursor:pointer;
}
.menu-btn:focus{outline:none;box-shadow:0 0 0 4px var(--ring)}

/* Mobile nav */
@media (max-width: 860px){
  .nav-links{display:none}
  .menu-btn{display:block}
}
.mobile-nav{
  display:none;
  padding:10px 0 18px;
}
.mobile-nav.open{display:block}
.mobile-nav a{
  display:block;
  padding:12px 12px;
  border-radius:14px;
  margin:6px 0;
  background:rgba(255,255,255,.65);
  border:1px solid rgba(2,6,23,.08);
  color:var(--muted);
  font-weight:700;
}

/* Hero */
.hero{
  padding:34px 0 18px;
}
.hero-grid{
  display:grid;
  grid-template-columns: 1.1fr .9fr;
  gap:22px;
  align-items:center;
}
@media (max-width: 900px){
  .hero-grid{grid-template-columns:1fr;gap:16px}
}
.kicker{
  display:inline-flex;
  align-items:center;
  gap:10px;
  font-weight:800;
  color:var(--brand);
  background:rgba(37,99,235,.10);
  border:1px solid rgba(37,99,235,.18);
  padding:8px 12px;
  border-radius:999px;
}
.hero h1{
  margin:14px 0 8px;
  font-size:clamp(28px, 4.2vw, 44px);
  line-height:1.08;
}
.hero p{
  margin:0;
  color:var(--muted);
  font-size:16px;
  line-height:1.6;
  max-width:62ch;
}
.hero-actions{
  display:flex;
  gap:12px;
  margin-top:18px;
  flex-wrap:wrap;
}

.btn{
  border:none;
  cursor:pointer;
  border-radius:14px;
  padding:12px 14px;
  font-weight:850;
  letter-spacing:.2px;
  transition:transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  display:inline-flex;
  align-items:center;
  gap:10px;
}
.btn:focus{outline:none;box-shadow:0 0 0 4px var(--ring)}
.btn-primary{
  background:linear-gradient(135deg,var(--brand),var(--brand2));
  color:#fff;
  box-shadow:0 10px 25px rgba(37,99,235,.20);
}
.btn-primary:hover{transform:translateY(-1px)}
.btn-secondary{
  background:#fff;
  border:1px solid rgba(2,6,23,.10);
  color:var(--text);
}
.btn-secondary:hover{
  transform:translateY(-1px);
  box-shadow:var(--shadow);
}
.btn-ghost{
  background:transparent;
  border:1px solid rgba(2,6,23,.10);
  color:var(--muted);
}
.btn-ghost:hover{
  transform:translateY(-1px);
  background:rgba(255,255,255,.6);
}
.btn[disabled]{opacity:.6;cursor:not-allowed;transform:none;box-shadow:none}

/* Cards / Grid */
.tools-grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap:14px;
  margin:20px 0 30px;
}
.tool-card{
  grid-column: span 4;
  background:rgba(255,255,255,.78);
  border:1px solid rgba(2,6,23,.08);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:16px;
  transition:transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease;
  position:relative;
  overflow:hidden;
}
.tool-card::after{
  content:"";
  position:absolute; inset:-2px;
  background:radial-gradient(600px 160px at var(--x, 50%) 0%, rgba(37,99,235,.16), transparent 55%);
  opacity:0;
  transition:opacity .25s ease;
  pointer-events:none;
}
.tool-card:hover{
  transform:translateY(-3px);
  border-color:rgba(37,99,235,.25);
  box-shadow:0 18px 40px rgba(2,6,23,.08);
  background:rgba(255,255,255,.92);
}
.tool-card:hover::after{opacity:1}
.tool-card h3{
  margin:10px 0 6px;
  font-size:18px;
  letter-spacing:.1px;
}
.tool-card p{margin:0;color:var(--muted);line-height:1.6}
.tool-card .card-top{
  display:flex;
  gap:12px;
  align-items:flex-start;
}
.tool-ico{
  width:42px;height:42px;border-radius:16px;
  background:rgba(37,99,235,.12);
  display:grid;place-items:center;
  border:1px solid rgba(37,99,235,.18);
  color:var(--brand);
  flex:0 0 auto;
}
.tool-card .card-actions{
  margin-top:12px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}
.tool-card .mini-link{
  font-weight:850;
  color:var(--brand);
  font-size:14px;
  display:inline-flex;
  align-items:center;
  gap:8px;
}

@media (max-width: 1000px){
  .tool-card{grid-column:span 6}
}
@media (max-width: 680px){
  .tool-card{grid-column:span 12}
}

/* Tool pages */
.tool-ui{
  background:rgba(255,255,255,.78);
  border:1px solid rgba(2,6,23,.08);
  border-radius:var(--radius);
  padding:16px;
  box-shadow:var(--shadow);
}
.tool-top{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.tool-top h1{
  font-size:clamp(22px, 3vw, 34px);
  margin:0;
}
.tool-top .sub{
  color:var(--muted);
  margin-top:6px;
  line-height:1.6;
}

.tool-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:14px;
  margin-top:14px;
}
@media (max-width: 900px){
  .tool-grid{grid-template-columns:1fr}
}

.dropzone{
  border:1.5px dashed rgba(37,99,235,.35);
  background:rgba(255,255,255,.55);
  border-radius:16px;
  padding:16px;
  min-height:168px;
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  justify-content:center;
  gap:10px;
  transition:transform .15s ease, background .15s ease, border-color .15s ease;
}
.dropzone.drag{
  background:rgba(37,99,235,.08);
  border-color:rgba(37,99,235,.55);
  transform:translateY(-1px);
}
.dz-row{
  display:flex;
  gap:12px;
  align-items:center;
  flex-wrap:wrap;
}
.dropzone .dz-title{
  font-weight:900;
}
.dz-files{
  width:100%;
  font-weight:900;
  font-size:14px;
  color:var(--text);
  line-height:1.35;
  word-break:break-word;
}
.dz-files .muted{
  font-weight:800;
  color:var(--muted);
  font-size:12px;
}
.hint{
  color:var(--muted);
  font-size:13px;
  line-height:1.5;
}
.file-input{
  display:none;
}

.controls{
  border:1px solid rgba(2,6,23,.08);
  background:rgba(255,255,255,.6);
  border-radius:16px;
  padding:14px;
}
.control-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:12px;
}
@media (max-width: 520px){
  .control-grid{grid-template-columns:1fr}
}
.field label{
  display:block;
  font-weight:850;
  margin-bottom:6px;
  font-size:13px;
  color:var(--muted);
}
.field input[type="text"],
.field input[type="number"],
.field select,
.field input[type="color"]{
  width:100%;
  padding:11px 12px;
  border-radius:14px;
  border:1px solid rgba(2,6,23,.10);
  background:#fff;
}
.field input[type="range"]{width:100%}
.field .inline{
  display:flex;gap:10px;align-items:center;
}
.toggle{
  display:flex;
  gap:10px;
  align-items:center;
  margin-top:10px;
}
.toggle input{width:18px;height:18px}

.progress{
  margin-top:12px;
  display:flex;
  gap:12px;
  align-items:center;
}
.progress-bar{
  height:10px;
  background:rgba(2,6,23,.06);
  border-radius:999px;
  overflow:hidden;
  flex:1;
}
.progress-bar > div{
  height:100%;
  width:0%;
  background:linear-gradient(90deg,var(--brand),var(--brand2));
  transition:width .2s ease;
}
.progress .pct{
  min-width:48px;
  text-align:right;
  font-weight:900;
  color:var(--muted);
  font-size:13px;
}

.results{
  margin-top:12px;
  display:grid;
  grid-template-columns: 1fr;
  gap:12px;
}
.result-item{
  border:1px solid rgba(2,6,23,.08);
  background:rgba(255,255,255,.66);
  border-radius:16px;
  padding:12px;
}
.result-head{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:12px;
  flex-wrap:wrap;
}
.file-meta{
  display:flex;
  flex-direction:column;
  gap:4px;
}
.file-name{
  font-weight:950;
}
.file-sizes{
  color:var(--muted);
  font-size:13px;
}
.preview-row{
  display:grid;
  grid-template-columns: 120px 1fr;
  gap:12px;
  align-items:center;
  margin-top:10px;
}
@media (max-width: 520px){
  .preview-row{grid-template-columns:1fr}
}
.preview{
  width:120px;height:120px;
  border-radius:14px;
  background:rgba(2,6,23,.04);
  border:1px solid rgba(2,6,23,.06);
  overflow:hidden;
  display:grid;place-items:center;
}
.preview img{width:100%;height:100%;object-fit:cover}
.actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}
.small-btn{
  padding:10px 12px;
  border-radius:14px;
  font-weight:900;
}
.actions .btn-ghost{
  border-radius:14px;
}

.preview-solo{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  align-items:center;
}
.canvas-holder{
  width:100%;
  border-radius:16px;
  border:1px solid rgba(2,6,23,.08);
  background:rgba(255,255,255,.55);
  overflow:hidden;
  padding:10px;
}
.canvas-holder img{
  border-radius:14px;
  border:1px solid rgba(2,6,23,.06);
}

/* Before/After slider */
.ba{
  position:relative;
  width:100%;
  border-radius:16px;
  border:1px solid rgba(2,6,23,.08);
  background:rgba(255,255,255,.55);
  overflow:hidden;
  min-height:220px;
}
.ba img{
  width:100%;
  height:100%;
  object-fit:contain;
  display:block;
  user-select:none;
  -webkit-user-drag:none;
}
.ba .ba-before, .ba .ba-after{
  position:absolute;
  inset:0;
}
.ba .ba-after{
  width:50%;
  overflow:hidden;
  border-left:2px solid rgba(255,255,255,.9);
}
.ba .ba-line{
  position:absolute;
  top:0; bottom:0;
  left:50%;
  width:2px;
  background:rgba(255,255,255,.95);
  box-shadow:0 0 0 1px rgba(2,6,23,.15);
  pointer-events:none;
}
.ba .ba-handle{
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
  width:44px;
  height:44px;
  border-radius:999px;
  background:rgba(2,6,23,.55);
  border:1px solid rgba(255,255,255,.35);
  display:grid;place-items:center;
  pointer-events:none;
}
.ba .ba-handle span{
  color:#fff;
  font-weight:900;
  font-size:16px;
  line-height:1;
}
.ba .ba-label{
  position:absolute;
  top:12px;
  padding:8px 10px;
  font-weight:900;
  font-size:12px;
  border-radius:999px;
  background:rgba(2,6,23,.52);
  color:#fff;
  border:1px solid rgba(255,255,255,.22);
  pointer-events:none;
}
.ba .ba-label.after{right:12px;left:auto}
.ba input[type="range"]{
  position:absolute;
  inset:0;
  opacity:0;
  cursor:ew-resize;
}

/* SEO */
.seo{
  margin:18px 0 30px;
}
.seo h2{
  font-size:18px;
  margin:18px 0 10px;
}
.seo p{
  color:var(--muted);
  line-height:1.75;
  margin:0 0 12px;
}
.seo ul{
  margin:0 0 12px;
  padding-left:18px;
  color:var(--muted);
}
.seo li{margin:6px 0}
.faqs{
  display:grid;
  gap:10px;
}
.faq{
  border:1px solid rgba(2,6,23,.08);
  background:rgba(255,255,255,.62);
  border-radius:16px;
  padding:12px;
}
.faq summary{
  cursor:pointer;
  font-weight:950;
}
.faq p{
  margin-top:8px;
}

/* Footer */
.site-footer{
  margin-top:30px;
  border-top:1px solid var(--border);
  padding:22px 0 32px;
  color:var(--muted);
}
.footer-grid{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.footer-links{
  display:flex;
  gap:16px;
  flex-wrap:wrap;
}
.footer-links a{
  color:var(--muted);
  font-weight:800;
  font-size:14px;
}
.footer-links a:hover{color:var(--text)}

/* Loading overlay + spinner */
.loading-overlay{
  position:fixed;
  inset:0;
  background:rgba(2,6,23,.25);
  display:none;
  z-index:100;
  place-items:center;
  padding:16px;
}
.loading-overlay.open{display:grid}
.loading-card{
  width:min(520px,100%);
  background:rgba(255,255,255,.92);
  border:1px solid rgba(2,6,23,.10);
  border-radius:22px;
  box-shadow:0 20px 60px rgba(2,6,23,.22);
  padding:16px;
}
.spinner{
  width:44px;height:44px;
  border-radius:50%;
  border:4px solid rgba(37,99,235,.18);
  border-top-color:rgba(37,99,235,.95);
  animation:spin 1s linear infinite;
  margin:0 auto;
}
@keyframes spin{to{transform:rotate(360deg)}}
.loading-msg{
  text-align:center;
  margin-top:10px;
  font-weight:950;
}
.loading-sub{
  text-align:center;
  margin-top:6px;
  color:var(--muted);
  font-size:13px;
  line-height:1.5;
}

/* Toasts */
.toast-container{
  position:fixed;
  top:70px;
  right:14px;
  z-index:120;
  display:flex;
  flex-direction:column;
  gap:10px;
  pointer-events:none;
}
.toast{
  min-width:260px;
  max-width:360px;
  border-radius:16px;
  padding:12px 12px;
  border:1px solid rgba(2,6,23,.10);
  box-shadow:0 18px 40px rgba(2,6,23,.16);
  background:rgba(255,255,255,.95);
  pointer-events:none;
}
.toast .t-title{
  font-weight:1000;
  font-size:14px;
}
.toast .t-msg{
  color:var(--muted);
  margin-top:4px;
  line-height:1.45;
  font-size:13px;
}
.toast.success{border-color:rgba(16,185,129,.35)}
.toast.success .t-title{color:#059669}
.toast.error{border-color:rgba(239,68,68,.35)}
.toast.error .t-title{color:#dc2626}
.toast.info{border-color:rgba(37,99,235,.35)}
.toast.info .t-title{color:var(--brand)}

/* Accessibility */
@media (prefers-reduced-motion: reduce){
  *{scroll-behavior:auto!important;transition:none!important;animation:none!important}
}

