Sada8888 commited on
Commit
1df78e5
·
verified ·
1 Parent(s): 1aa8c20

Update templates/editor.html

Browse files
Files changed (1) hide show
  1. templates/editor.html +499 -186
templates/editor.html CHANGED
@@ -6,277 +6,590 @@
6
  <title>AI Photoshop Pro (Hugging Face Version)</title>
7
  <link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap" rel="stylesheet">
8
  <style>
9
- /* CSS کامل شما بدون هیچ تغییری */
10
  :root {
11
- --app-font: 'Vazirmatn', sans-serif; --app-bg: #F8F9FC; --panel-bg: #FFFFFF;
12
- --panel-border: #EAEFF7; --input-bg: #F6F8FB; --input-border: #E1E7EF;
13
- --text-primary: #1A202C; --text-secondary: #626F86; --text-tertiary: #8A94A6;
14
- --accent-primary: #4A6CFA; --accent-primary-hover: #3553D6;
15
- --accent-primary-glow: rgba(74, 108, 250, 0.25); --accent-secondary: #0FD4A8;
16
- --danger-color: #e53e3e; --danger-color-hover: #c53030;
17
- --radius-card: 24px; --radius-btn: 14px; --radius-input: 12px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  --transition-smooth: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
 
 
 
 
 
 
 
 
 
 
 
 
19
  }
 
20
  @keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
21
  @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
22
- body { font-family: var(--app-font); background-color: var(--app-bg); margin: 0; padding: 2.5rem 1rem; display: flex; justify-content: center; align-items: flex-start; min-height: 100vh; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  .container { max-width: 820px; width: 100%; }
24
- header { text-align: center; margin-bottom: 2.5rem; padding: 2rem 0; animation: fadeIn 0.8s ease-out; }
25
- h1 { font-size: 2.8rem; font-weight: 800; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
26
- main, .gallery-section { padding: 3rem; background-color: var(--panel-bg); border-radius: var(--radius-card); box-shadow: 0 10px 15px rgba(0,0,0,0.05); border: 1px solid var(--panel-border); animation: fadeIn 0.8s ease-out; }
27
- .gallery-section { margin-top: 3rem; }
 
 
 
 
 
 
 
 
 
 
28
  .form-group { margin-bottom: 2.5rem; }
29
- .form-label { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; font-size: 1.2em; margin-bottom: 1.2rem; }
 
30
  .form-label svg { width: 24px; height: 24px; color: var(--accent-primary); }
31
- #upload-area { position: relative; border: 2px dashed var(--input-border); border-radius: var(--radius-input); padding: 2.5rem; text-align: center; cursor: pointer; min-height: 200px; display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; }
32
- #upload-area.has-file { padding: 0; }
 
33
  #upload-content { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
34
- #upload-icon svg { width: 48px; height: 48px; color: var(--accent-primary); }
 
35
  #preview-image-main { display: none; width: 100%; height: 100%; object-fit: contain; position: absolute; top: 0; left: 0; }
36
- #remove-file-btn-main { display: none; position: absolute; top: 12px; right: 12px; background: rgba(26,32,44,0.6); color: white; border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; z-index: 10; padding: 0; }
 
37
  #upload-area.has-file #upload-content { display: none; }
38
  #upload-area.has-file #preview-image-main, #upload-area.has-file #remove-file-btn-main { display: block; }
39
- textarea { width: 100%; padding: 1rem; border-radius: var(--radius-input); border: 1px solid var(--input-border); background-color: var(--input-bg); font-family: inherit; resize: vertical; min-height: 90px; }
40
- #submit-btn { display: flex; align-items: center; justify-content: center; gap: 0.75rem; width: 100%; padding: 1.1rem; font-size: 1.2rem; font-weight: 700; background: linear-gradient(95deg, var(--accent-secondary) 0%, var(--accent-primary) 100%); color: #fff; border: none; border-radius: var(--radius-btn); cursor: pointer; transition: all 0.3s ease; margin-top: 1rem; }
41
- #submit-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; opacity: 0.7; }
42
- .spinner { width: 20px; height: 20px; border: 3px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
43
- #result-container { min-height: 350px; position: relative; padding: 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); border: 2px dashed var(--input-border); display: flex; align-items: center; justify-content: center; }
44
- .generator-container { position: relative; width: 400px; max-width: 100%; height: 250px; border-radius: 20px; overflow: hidden; background-color: #161b22; color: #f0f6fc; display: none; flex-direction: column; justify-content: center; align-items: center; }
45
- .text-overlay { font-size: 18px; font-weight: 700; text-align: center; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  #result-grid { display: none; grid-template-columns: 1fr; gap: 1.5rem; width: 100%; }
47
- #result-grid img { width: 100%; object-fit: contain; border-radius: var(--radius-input); cursor: pointer; border: 1px solid var(--panel-border); }
 
 
 
48
  .gallery-header { display: flex; justify-content: space-between; align-items: center; }
49
- #clear-history-btn { background: none; border: 1px solid var(--panel-border); color: var(--text-secondary); padding: 0.5rem 1rem; border-radius: var(--radius-btn); cursor: pointer; display: none; }
 
 
50
  #history-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; margin-top: 1.5rem; }
51
- .history-item { position: relative; background-color: var(--input-bg); border-radius: var(--radius-card); padding: 1rem; }
52
- .history-item-grid img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: var(--radius-input); cursor: pointer; }
53
- .history-delete-btn { position: absolute; top: 0.75rem; right: 0.75rem; background: none; border: none; cursor: pointer; padding: 0.5rem; }
54
- #lightbox { position: fixed; inset: 0; background-color: rgba(18,24,38,0.6); backdrop-filter: blur(10px); display: none; align-items: center; justify-content: center; z-index: 1000; }
55
- #lightbox-img { max-width: 85vw; max-height: 80vh; object-fit: contain; }
56
- .lightbox-btn { position: absolute; background-color: rgba(255,255,255,0.1); color: white; border: 1px solid rgba(255,255,255,0.2); width: 44px; height: 44px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; }
 
 
 
 
 
 
 
 
57
  #lightbox-close { top: -50px; right: 0; }
58
  #lightbox-download { top: -50px; left: 0; }
59
- #confirmation-modal { position: fixed; inset: 0; background: rgba(18,24,38,0.6); backdrop-filter: blur(10px); display: none; align-items: center; justify-content: center; z-index: 2000; }
60
- .modal-dialog { background: var(--panel-bg); border-radius: var(--radius-card); padding: 2rem; width: 90%; max-width: 400px; text-align: center; }
61
- .modal-buttons { display: flex; gap: 1rem; margin-top: 2rem; }
62
- .modal-btn { flex: 1; padding: 0.8rem 1rem; border-radius: var(--radius-btn); border: none; cursor: pointer; }
 
 
 
 
 
 
 
63
  .modal-btn.confirm-btn { background-color: var(--danger-color); color: white; }
64
- .modal-btn.cancel-btn { background-color: var(--input-bg); border: 1px solid var(--input-border); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  </style>
66
  </head>
67
  <body>
68
  <div class="container">
69
  <header>
 
70
  <h1>فتوشاپ هوش مصنوعی ✨</h1>
71
  <p class="subtitle">تصاویر خود را با قدرت هوش مصنوعی و به زبان ساده ویرایش کنید</p>
 
72
  </header>
73
 
74
  <main>
75
  <div class="form-group">
76
- <div class="form-label"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7"/><path d="M18.5 2.5a2.12 2.12 0 0 1 3 3L12 15l-4 1 1-4Z"/></svg>۱. تصویر خود را انتخاب کنید</div>
 
 
 
77
  <label id="upload-area" for="file-input">
78
- <div id="upload-content"><div id="upload-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg></div><p>فایل تصویر را اینجا بکشید</p></div>
 
 
 
79
  <img id="preview-image-main" src="" alt="Preview">
80
  <button type="button" id="remove-file-btn-main" title="حذف تصویر">&times;</button>
81
  </label>
82
  <input type="file" id="file-input" accept="image/*" hidden>
83
  </div>
84
  <div class="form-group">
85
- <div class="form-label"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg>۲. دستور ویرایش</div>
 
 
 
86
  <textarea id="prompt-input" rows="3" placeholder="مثال: پس‌زمینه را حذف کن و یک ساحل آفتابی قرار بده"></textarea>
 
 
 
87
  <button id="submit-btn" disabled>
88
- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M10 3L12 8L17 10L12 12L10 17L8 12L3 10L8 8L10 3z"/></svg>
89
  <span id="btn-text">ایجاد کن</span>
90
  <div class="spinner"></div>
91
  </button>
 
 
 
 
 
92
  </div>
93
  <div class="form-group">
94
- <div class="form-label"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M10 3L12 8L17 10L12 12L10 17L8 12L3 10L8 8L10 3z"/></svg>۳. نتیجه</div>
 
 
 
95
  <div id="result-container">
96
- <p id="idle-text">برای شروع عکس و متن را وارد کنید.</p>
 
 
 
 
 
 
 
97
  </div>
98
  </div>
99
  </main>
100
-
101
  <section class="gallery-section">
102
  <div class="gallery-header">
103
- <div class="form-label"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>گالری شما</div>
104
- <button id="clear-history-btn">پاک کردن همه</button>
 
 
 
 
 
 
105
  </div>
106
  <div id="history-grid"></div>
107
  </section>
108
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
- <!-- بخش‌های مودال و لایت‌باکس (بدون تغییر) -->
111
- <div id="lightbox"><div id="lightbox-content"><img id="lightbox-img" src=""><button id="lightbox-close">&times;</button><a id="lightbox-download" download>دانلود</a></div></div>
112
- <div id="confirmation-modal"><div class="modal-dialog"><h3>تایید حذف</h3><p id="modal-message-text"></p><div class="modal-buttons"><button id="modal-cancel-btn" class="modal-btn cancel-btn">انصراف</button><button id="modal-confirm-btn" class="modal-btn confirm-btn">حذف</button></div></div></div>
113
-
114
- <script>
115
- const uploadArea = document.getElementById('upload-area');
116
- const fileInput = document.getElementById('file-input');
117
- const previewImage = document.getElementById('preview-image-main');
118
- const removeFileBtn = document.getElementById('remove-file-btn-main');
119
- const promptInput = document.getElementById('prompt-input');
120
- const submitBtn = document.getElementById('submit-btn');
121
- const resultContainer = document.getElementById('result-container');
122
- const historyGrid = document.getElementById('history-grid');
123
- const clearHistoryBtn = document.getElementById('clear-history-btn');
124
 
125
- let uploadedFile = null;
 
 
126
  let pollTimer = null;
 
 
 
127
 
128
- // --- بخش مدیریت پایگاه داده IndexedDB برای تاریخچه ---
129
- const dbHandler = {
130
- db: null,
131
- initDB() {
132
- return new Promise((resolve) => {
133
- const request = indexedDB.open('aiPhotoshopDB', 1);
134
- request.onupgradeneeded = e => e.target.result.createObjectStore('history', { keyPath: 'id', autoIncrement: true });
135
- request.onsuccess = e => { this.db = e.target.result; resolve(); };
136
- });
137
- },
138
- add(item) {
139
- const tx = this.db.transaction('history', 'readwrite');
140
- tx.objectStore('history').add({ ...item, timestamp: Date.now() });
141
- },
142
- getAll: () => new Promise(res => {
143
- const tx = dbHandler.db.transaction('history', 'readonly');
144
- const req = tx.objectStore('history').getAll();
145
- req.onsuccess = () => res(req.result.sort((a,b) => b.timestamp - a.timestamp));
146
- }),
147
- delete: (id) => dbHandler.db.transaction('history', 'readwrite').objectStore('history').delete(id),
148
- clear: () => dbHandler.db.transaction('history', 'readwrite').objectStore('history').clear(),
149
- };
150
 
151
- // --- مدیریت آپلود و نمایش عکس ورودی ---
152
- const handleFile = file => {
153
- if (!file || !file.type.startsWith('image/')) return;
154
- uploadedFile = file;
155
- previewImage.src = URL.createObjectURL(file);
156
- uploadArea.classList.add('has-file');
157
- checkFormState();
158
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
- const resetUploader = () => {
161
- uploadedFile = null; fileInput.value = ''; previewImage.src = '';
162
- uploadArea.classList.remove('has-file');
163
- checkFormState();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  };
165
-
166
- removeFileBtn.onclick = e => { e.preventDefault(); e.stopPropagation(); resetUploader(); };
167
- fileInput.onchange = e => handleFile(e.target.files[0]);
168
- ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(e => { uploadArea.addEventListener(e, p => p.preventDefault()); });
169
- uploadArea.ondragover = () => uploadArea.classList.add('drag-over');
170
- uploadArea.ondragleave = () => uploadArea.classList.remove('drag-over');
171
- uploadArea.ondrop = e => handleFile(e.dataTransfer.files[0]);
172
 
173
- const checkFormState = () => submitBtn.disabled = !(uploadedFile && promptInput.value.trim() !== '');
174
- promptInput.oninput = checkFormState;
 
 
 
 
 
175
 
176
- // --- مدیریت ارسال درخواست به سرور ---
177
- submitBtn.onclick = async () => {
178
- const btnText = document.getElementById('btn-text');
179
- const spinner = submitBtn.querySelector('.spinner');
180
 
181
- submitBtn.disabled = true;
182
- spinner.style.display = 'block';
183
- btnText.textContent = 'در حال ارسال...';
184
- resultContainer.innerHTML = `<div class="generator-container"><div class="text-overlay">در حال ترجمه متن...</div></div>`;
 
 
 
 
 
 
 
 
 
 
 
185
 
186
- const formData = new FormData();
187
- formData.append('image', uploadedFile);
188
- formData.append('prompt', promptInput.value.trim());
 
 
 
 
 
 
 
189
 
 
 
 
 
 
 
 
 
190
  try {
191
- const res = await fetch('/api/edit', { method: 'POST', body: formData });
192
- const data = await res.json();
 
 
 
193
 
 
 
 
 
 
 
 
 
 
 
 
194
  if (data.status === 'success') {
195
- resultContainer.querySelector('.text-overlay').innerHTML = `ترجمه شد: ${data.translated.substring(0,30)}...<br>در حال ساخت تصویر...`;
196
- pollTimer = setInterval(() => checkResult(data.run_id), 3000);
 
197
  } else {
198
- alert('خطا در ارسال به گیت‌هاب!');
199
- resetUI();
200
  }
201
- } catch (e) {
202
- alert('خطای ارتباط با سرور!');
203
- resetUI();
204
  }
205
  };
206
 
207
- async function checkResult(run_id) {
208
  try {
209
  const res = await fetch(`/api/status/${run_id}`);
210
  const data = await res.json();
211
 
212
  if (data.status === 'ready') {
213
  clearInterval(pollTimer);
214
- resultContainer.innerHTML = `
215
- <div id="result-grid">
216
- <img src="${data.url}" alt="تصویر ویرایش شده">
217
- </div>`;
218
 
219
- const newItem = { prompt: promptInput.value.trim(), urls: [data.url] };
220
- await dbHandler.add(newItem);
221
- await renderHistory();
222
 
223
- resetUI();
 
 
 
 
 
 
 
224
  }
225
- } catch(e) { console.log('Polling for result...', e); }
 
 
226
  }
 
227
 
228
- const resetUI = () => {
229
- submitBtn.disabled = false;
230
- submitBtn.querySelector('.spinner').style.display = 'none';
231
- document.getElementById('btn-text').textContent = 'ایجاد کن';
232
- checkFormState();
233
- };
234
-
235
- // --- مدیریت تاریخچه (History) ---
236
- const renderHistory = async () => {
237
- const history = await dbHandler.getAll();
238
- historyGrid.innerHTML = '';
239
- clearHistoryBtn.style.display = history.length > 0 ? 'block' : 'none';
240
- history.forEach(item => {
241
- const card = document.createElement('div');
242
- card.className = 'history-item';
243
- card.innerHTML = `
244
- <button class="history-delete-btn" title="حذف">&times;</button>
245
- <div class="history-item-grid">
246
- <img src="${item.urls[0]}" alt="${item.prompt}">
247
- </div>`;
248
- card.querySelector('img').onclick = () => openLightbox(item.urls[0], item.urls);
249
- card.querySelector('.history-delete-btn').onclick = () => showConfirmation('حذف این مورد؟', async () => { await dbHandler.delete(item.id); renderHistory(); });
250
- historyGrid.appendChild(card);
251
- });
252
- };
253
-
254
- clearHistoryBtn.onclick = () => showConfirmation('پاک کردن کل تاریخچه؟', async () => { await dbHandler.clear(); renderHistory(); });
255
-
256
- // --- مدیریت لایت‌باکس و مودال تایید ---
257
- const lightbox = document.getElementById('lightbox');
258
- const confirmationModal = document.getElementById('confirmation-modal');
259
-
260
- const openLightbox = (url, urls) => {
261
- document.getElementById('lightbox-img').src = url;
262
- document.getElementById('lightbox-download').href = url;
263
- lightbox.style.display = 'flex';
264
- };
265
- document.getElementById('lightbox-close').onclick = () => lightbox.style.display = 'none';
266
-
267
- const showConfirmation = (msg, onConfirm) => {
268
- document.getElementById('modal-message-text').textContent = msg;
269
- confirmationModal.style.display = 'flex';
270
- document.getElementById('modal-confirm-btn').onclick = () => { onConfirm(); confirmationModal.style.display = 'none'; };
271
- document.getElementById('modal-cancel-btn').onclick = () => confirmationModal.style.display = 'none';
272
- };
273
-
274
- // شروع به کار برنامه
275
- document.addEventListener('DOMContentLoaded', async () => {
276
- await dbHandler.initDB();
277
- await renderHistory();
278
- resetUI();
279
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  </script>
281
  </body>
282
  </html>
 
6
  <title>AI Photoshop Pro (Hugging Face Version)</title>
7
  <link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap" rel="stylesheet">
8
  <style>
 
9
  :root {
10
+ --app-font: 'Vazirmatn', sans-serif;
11
+ --app-bg: #F8F9FC;
12
+ --panel-bg: #FFFFFF;
13
+ --panel-border: #EAEFF7;
14
+ --input-bg: #F6F8FB;
15
+ --input-border: #E1E7EF;
16
+ --text-primary: #1A202C;
17
+ --text-secondary: #626F86;
18
+ --text-tertiary: #8A94A6;
19
+ --accent-primary: #4A6CFA;
20
+ --accent-primary-hover: #3553D6;
21
+ --accent-primary-glow: rgba(74, 108, 250, 0.25);
22
+ --accent-secondary: #0FD4A8;
23
+ --accent-premium: #FFC107;
24
+ --accent-premium-glow: rgba(255, 193, 7, 0.3);
25
+ --danger-color: #e53e3e;
26
+ --danger-color-hover: #c53030;
27
+ --shadow-sm: 0 1px 2px 0 rgba(26, 32, 44, 0.03);
28
+ --shadow-md: 0 4px 6px -1px rgba(26, 32, 44, 0.05), 0 2px 4px -2px rgba(26, 32, 44, 0.04);
29
+ --shadow-lg: 0 10px 15px -3px rgba(26, 32, 44, 0.06), 0 4px 6px -4px rgba(26, 32, 44, 0.05);
30
+ --shadow-xl: 0 20px 25px -5px rgba(26, 32, 44, 0.07), 0 8px 10px -6px rgba(26, 32, 44, 0.05);
31
+ --radius-card: 24px;
32
+ --radius-btn: 14px;
33
+ --radius-input: 12px;
34
  --transition-smooth: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
35
+
36
+ /* === START: متغیرهای CSS جدید برای راهنمای خطا === */
37
+ --guide-bg: rgba(255, 255, 255, 0.98);
38
+ --guide-border: rgba(102, 126, 234, 0.2);
39
+ --guide-text-title: #2d3748;
40
+ --guide-text-body: #4a5568;
41
+ --guide-accent: #667eea;
42
+ --primary-gradient-guide: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
43
+ --success-gradient-guide: linear-gradient(135deg, #56ab2f 0%, #a8e063 100%);
44
+ --radius-md-guide: 12px;
45
+ --radius-lg-guide: 20px;
46
+ /* === END: متغیرهای CSS جدید برای راهنمای خطا === */
47
  }
48
+
49
  @keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
50
  @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
51
+ @keyframes badge-fade-in { from { opacity: 0; transform: translateY(-10px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
52
+
53
+ /* === START: KEYFRAMES FOR IP RESET GUIDE === */
54
+ @keyframes float {
55
+ 0%, 100% { transform: translateY(0px); }
56
+ 50% { transform: translateY(-10px); }
57
+ }
58
+ @keyframes slideInUp {
59
+ from { opacity: 0; transform: translateY(30px); }
60
+ to { opacity: 1; transform: translateY(0); }
61
+ }
62
+ /* === END: KEYFRAMES FOR IP RESET GUIDE === */
63
+
64
+ /* === START: انیمیشن‌های مربوط به هشدار محتوای نامناسب === */
65
+ @keyframes popIn {
66
+ 0% { opacity: 0; transform: translateY(-10px) scale(0.95); }
67
+ 100% { opacity: 1; transform: translateY(0) scale(1); }
68
+ }
69
+
70
+ @keyframes popOut {
71
+ 0% { opacity: 1; transform: translateY(0) scale(1); }
72
+ 100% { opacity: 0; transform: translateY(10px) scale(0.95); }
73
+ }
74
+
75
+ #content-warning {
76
+ display: none;
77
+ background: linear-gradient(135deg, #fff5f5 0%, #fed7d7 100%);
78
+ color: #c53030;
79
+ border: 1px solid #feb2b2;
80
+ padding: 1rem;
81
+ border-radius: var(--radius-btn);
82
+ text-align: center;
83
+ margin-top: 1rem;
84
+ font-weight: 700;
85
+ box-shadow: 0 4px 12px rgba(229, 62, 62, 0.15);
86
+ font-size: 1rem;
87
+ overflow: hidden;
88
+ position: relative;
89
+ }
90
+
91
+ #content-warning.show {
92
+ display: block;
93
+ animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
94
+ }
95
+
96
+ #content-warning.hide {
97
+ animation: popOut 0.4s cubic-bezier(0.6, -0.28, 0.735, 0.045) forwards;
98
+ }
99
+ /* === END: انیمیشن‌های مربوط به هشدار محتوای نامناسب === */
100
+
101
+ body { font-family: var(--app-font); background-color: var(--app-bg); color: var(--text-primary); margin: 0; padding: 2.5rem 1rem; display: flex; justify-content: center; align-items: flex-start; min-height: 100vh; }
102
  .container { max-width: 820px; width: 100%; }
103
+ header { position: relative; text-align: center; margin-bottom: 2.5rem; padding: 2rem 0; animation: fadeIn 0.8s 0.1s ease-out backwards; overflow: hidden; }
104
+ #neural-network-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }
105
+ h1, .subtitle, #subscription-status-badge { position: relative; z-index: 2; }
106
+ h1 { font-size: 2.8rem; font-weight: 800; margin: 0 0 0.8rem 0; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; letter-spacing: -1px; }
107
+ .subtitle { font-size: 1.1rem; color: var(--text-secondary); margin-top: 0; }
108
+
109
+ #subscription-status-badge { display: none; padding: 6px 16px; border-radius: 20px; font-size: 0.9em; font-weight: 700; margin-top: 1.25rem; letter-spacing: 0.5px; animation: badge-fade-in 0.6s 0.5s ease-out backwards; }
110
+ #subscription-status-badge.free-badge { background: linear-gradient(45deg, #6c757d, #495057); color: white; box-shadow: 0 4px 10px rgba(108, 117, 125, 0.3); }
111
+ #subscription-status-badge.paid-badge { background: linear-gradient(45deg, var(--accent-premium), #ffca2c); color: #333; box-shadow: 0 4px 10px var(--accent-premium-glow); }
112
+ #credit-info-section { margin-top: 1.5rem; padding: 1rem; background-color: var(--input-bg); border-radius: var(--radius-input); text-align: center; font-size: 0.95rem; font-weight: 500; color: var(--text-secondary); border: 1px solid var(--input-border); display: none; }
113
+ #upgrade-button { margin-top: 1rem; width: 100%; padding: 1rem; font-size: 1.1rem; font-weight: 700; background: linear-gradient(95deg, #FFD54F, #FFC107 100%); color: #212529; border: none; border-radius: var(--radius-btn); cursor: pointer; box-shadow: 0 8px 20px -5px rgba(255, 193, 7, 0.3); display: none; }
114
+
115
+ main, .gallery-section { padding: 3rem; background-color: var(--panel-bg); border-radius: var(--radius-card); box-shadow: var(--shadow-xl); border: 1px solid var(--panel-border); animation: fadeIn 0.8s 0.3s ease-out backwards; }
116
+ .gallery-section { margin-top: 3rem; animation-delay: 0.5s; }
117
  .form-group { margin-bottom: 2.5rem; }
118
+ .form-group:last-child { margin-bottom: 0; }
119
+ .form-label { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; color: var(--text-primary); font-size: 1.2em; margin-bottom: 1.2rem; }
120
  .form-label svg { width: 24px; height: 24px; color: var(--accent-primary); }
121
+ #upload-area { position: relative; border: 2px dashed var(--input-border); border-radius: var(--radius-input); padding: 2.5rem; text-align: center; cursor: pointer; transition: var(--transition-smooth); background-color: var(--input-bg); min-height: 200px; display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; }
122
+ #upload-area.drag-over, #upload-area:hover:not(.has-file) { border-color: var(--accent-primary); background-color: #fff; box-shadow: 0 0 15px var(--accent-primary-glow); }
123
+ #upload-area.has-file { border-style: solid; border-color: var(--panel-border); padding: 0; cursor: default; }
124
  #upload-content { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
125
+ #upload-icon svg { width: 48px; height: 48px; color: var(--accent-primary); stroke-width: 1.5; opacity: 0.8; }
126
+ #upload-area p { margin: 0; color: var(--text-secondary); font-weight: 500; }
127
  #preview-image-main { display: none; width: 100%; height: 100%; object-fit: contain; position: absolute; top: 0; left: 0; }
128
+ #remove-file-btn-main { display: none; position: absolute; top: 12px; right: 12px; background-color: rgba(26, 32, 44, 0.6); color: white; border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; line-height: 1; z-index: 10; transition: var(--transition-smooth); padding: 0; }
129
+ #remove-file-btn-main:hover { background-color: var(--danger-color); transform: scale(1.1); }
130
  #upload-area.has-file #upload-content { display: none; }
131
  #upload-area.has-file #preview-image-main, #upload-area.has-file #remove-file-btn-main { display: block; }
132
+ textarea { width: 100%; padding: 1rem 1.2rem; border-radius: var(--radius-input); border: 1px solid var(--input-border); background-color: var(--input-bg); color: var(--text-primary); box-shadow: var(--shadow-sm) inset; font-family: var(--app-font); font-size: 1rem; box-sizing: border-box; transition: var(--transition-smooth); min-height: 90px; resize: vertical; }
133
+ textarea:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-primary-glow), var(--shadow-sm) inset; background-color: var(--panel-bg); }
134
+ #submit-btn { display: flex; align-items: center; justify-content: center; gap: 0.75rem; width: 100%; padding: 1.1rem; font-size: 1.2rem; font-weight: 700; background: linear-gradient(95deg, var(--accent-secondary) 0%, var(--accent-primary) 100%); color: #fff; border: none; border-radius: var(--radius-btn); cursor: pointer; transition: all 0.3s ease; box-shadow: 0 6px 12px -3px var(--accent-primary-glow), 0 6px 12px -3px rgba(15, 212, 168, 0.25); margin-top: 1rem; }
135
+ #submit-btn svg { width: 24px; height: 24px; margin-left: 4px; filter: drop-shadow(0 0 5px rgba(255,255,255,0.5)); }
136
+ #submit-btn:hover:not(:disabled) { transform: translateY(-5px) scale(1.02); box-shadow: 0 8px 20px -4px var(--accent-primary-glow), 0 8px 20px -4px rgba(15, 212, 168, 0.3); }
137
+ #submit-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; box-shadow: none; opacity: 0.7; }
138
+ #submit-btn .spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
139
+
140
+ #result-container { min-height: 350px; position: relative; padding: 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); border: 2px dashed var(--input-border); box-shadow: var(--shadow-sm) inset; transition: var(--transition-smooth); display: flex; align-items: center; justify-content: center; }
141
+ #result-container.loading { border-style: solid; border-color: var(--panel-border); }
142
+ #result-container.has-content { border-style: solid; border-color: var(--panel-border); }
143
+ /* === START: استایل جدید برای نمایش راهنما === */
144
+ #result-container.has-content:has(.ip-reset-guide-container) {
145
+ padding: 0;
146
+ border: none;
147
+ background-color: transparent;
148
+ box-shadow: none;
149
+ }
150
+ /* === END: استایل جدید برای نمایش راهنما === */
151
+
152
+ #loading-placeholder { display: none; }
153
+ #result-container.loading #loading-placeholder { display: flex; animation: fadeIn 0.5s; justify-content: center; align-items: center; width: 100%; flex-direction: column;}
154
+ .generator-container { position: relative; width: 400px; max-width: 100%; height: 300px; border: 2px solid #38bdf8; border-radius: 20px; overflow: hidden; box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); animation: pulse 5s infinite cubic-bezier(0.4, 0, 0.6, 1); background-color: #161b22; color: #f0f6fc; }
155
+ @keyframes pulse { 0% { box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); } 50% { box-shadow: 0 0 60px rgba(56, 189, 248, 0.7); } 100% { box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); } }
156
+ .noise-layer, .sketch-layer, .building-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
157
+ .noise-layer { background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="none"/><filter id="noise"><feTurbulence type="fractalNoise" baseFrequency="0.5" numOctaves="4" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noise)" opacity="0.6"/></svg>') repeat; opacity: 1; animation: fade-noise 7s infinite ease-in-out; }
158
+ @keyframes fade-noise { 0% { opacity: 1; filter: blur(5px); } 30% { opacity: 0.8; filter: blur(2px); } 100% { opacity: 0; filter: blur(0px); } }
159
+ .sketch-layer { filter: grayscale(1) contrast(1.5) blur(3px); opacity: 0; animation: reveal-sketch 7s infinite ease-in-out; }
160
+ @keyframes reveal-sketch { 0% { opacity: 0; } 20% { opacity: 1; } 60% { opacity: 0.5; } 100% { opacity: 0; } }
161
+ .building-layer { filter: blur(15px); opacity: 0; animation: denoise-color 7s infinite ease-in-out; }
162
+ @keyframes denoise-color { 0% { opacity: 0; } 40% { opacity: 0.6; filter: blur(5px); } 100% { opacity: 1; filter: blur(0px); } }
163
+ .pixel-grid { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: repeating-linear-gradient(0deg, transparent 0 1px, rgba(255,255,255,0.1) 1px 2px), repeating-linear-gradient(90deg, transparent 0 1px, rgba(255,255,255,0.1) 1px 2px); opacity: 1; animation: dissolve-grid 7s infinite ease-in-out; }
164
+ @keyframes dissolve-grid { 0% { opacity: 1; } 70% { opacity: 0.5; } 100% { opacity: 0; } }
165
+ .particles { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(circle, rgba(56, 189, 248, 0.2) 0%, transparent 50%); animation: flow-particles 7s infinite cubic-bezier(0.4, 0, 0.6, 1); }
166
+ @keyframes flow-particles { 0% { transform: translate(0, 0) scale(1); } 50% { transform: translate(10px, -15px) scale(1.05); } 100% { transform: translate(0, 0) scale(1); } }
167
+ .text-overlay { position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%); font-size: 18px; font-weight: 700; text-shadow: 0 0 20px rgba(56, 189, 248, 0.8); animation: glow-text 7s infinite ease-in-out; font-family: var(--app-font); width: 90%; text-align: center;}
168
+ @keyframes glow-text { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } }
169
+ .progress-bar { position: absolute; bottom: 0; left: 0; width: 0%; height: 6px; background: linear-gradient(to right, #38bdf8, #bb86fc, #facc15); animation: progress 7s infinite linear; }
170
+ @keyframes progress { 0% { width: 0%; } 100% { width: 100%; } }
171
  #result-grid { display: none; grid-template-columns: 1fr; gap: 1.5rem; width: 100%; }
172
+ #result-container.has-content #result-grid { display: grid; }
173
+ #result-grid img { width: 100%; object-fit: contain; border-radius: var(--radius-input); cursor: pointer; transition: var(--transition-smooth); box-shadow: var(--shadow-md); border: 1px solid var(--panel-border); }
174
+ #result-grid img:hover { transform: scale(1.05); box-shadow: var(--shadow-lg); z-index: 10; position: relative; }
175
+ #error-message { color: #d93025; text-align: center; margin-top: 1rem; display: none; font-weight: 500; }
176
  .gallery-header { display: flex; justify-content: space-between; align-items: center; }
177
+ #clear-history-btn { background: none; border: 1px solid var(--panel-border); color: var(--text-secondary); padding: 0.5rem 1rem; border-radius: var(--radius-btn); cursor: pointer; display: none; align-items: center; gap: 0.5rem; font-family: var(--app-font); font-weight: 500; transition: all 0.2s; }
178
+ #clear-history-btn:hover { border-color: var(--danger-color); color: var(--danger-color); }
179
+ #clear-history-btn svg { width: 18px; height: 18px; }
180
  #history-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; margin-top: 1.5rem; }
181
+ #history-grid:empty::before { content: 'هنوز تصویری ویرایش نکرده‌اید. اولین ویرایش شما اینجا ذخیره خواهد شد.'; color: var(--text-secondary); grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); }
182
+ .history-item { position: relative; background-color: var(--input-bg); border-radius: var(--radius-card); border: 1px solid var(--panel-border); padding: 1rem; transition: var(--transition-smooth); }
183
+ .history-item:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }
184
+ .history-item-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
185
+ .history-item-grid img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: var(--radius-input); cursor: pointer; transition: transform 0.2s ease, box-shadow 0.2s ease; border: 1px solid var(--panel-border); }
186
+ .history-item-grid img:hover { transform: scale(1.1); box-shadow: var(--shadow-md); z-index: 5; position: relative; }
187
+ .history-delete-btn { position: absolute; top: 0.75rem; right: 0.75rem; background: none; border: none; cursor: pointer; padding: 0.5rem; border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--text-tertiary); transition: var(--transition-smooth); z-index: 5; }
188
+ .history-delete-btn:hover { background-color: var(--panel-border); color: var(--danger-color); }
189
+ #lightbox { position: fixed; inset: 0; background-color: rgba(18, 24, 38, 0.6); backdrop-filter: blur(10px) saturate(150%); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
190
+ #lightbox.visible { opacity: 1; pointer-events: auto; }
191
+ #lightbox-content { position: relative; animation: fadeIn 0.3s ease; display: flex; align-items: center; justify-content: center; }
192
+ #lightbox-img { max-width: 85vw; max-height: 80vh; object-fit: contain; border-radius: var(--radius-card); box-shadow: var(--shadow-xl); }
193
+ .lightbox-btn { position: absolute; background-color: rgba(255, 255, 255, 0.1); color: white; border: 1px solid rgba(255,255,255,0.2); width: 44px; height: 44px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: all 0.2s; text-decoration: none; font-size: 24px; }
194
+ .lightbox-btn:hover { background-color: rgba(255, 255, 255, 0.2); transform: scale(1.1); }
195
  #lightbox-close { top: -50px; right: 0; }
196
  #lightbox-download { top: -50px; left: 0; }
197
+ #lightbox-next { right: -60px; top: 50%; transform: translateY(-50%); }
198
+ #lightbox-download svg { width: 22px; height: 22px; }
199
+ #lightbox-download .spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
200
+ #confirmation-modal { position: fixed; inset: 0; background-color: rgba(18, 24, 38, 0.6); backdrop-filter: blur(10px); display: flex; align-items: center; justify-content: center; z-index: 2000; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
201
+ #confirmation-modal.visible { opacity: 1; pointer-events: auto; }
202
+ .modal-dialog { background: var(--panel-bg); color: var(--text-primary); border-radius: var(--radius-card); padding: 2rem; width: 90%; max-width: 400px; text-align: center; box-shadow: var(--shadow-xl); animation: fadeIn 0.3s ease-out backwards; }
203
+ .modal-icon { width: 48px; height: 48px; margin: 0 auto 1.5rem; color: var(--danger-color); }
204
+ .modal-dialog h3 { font-size: 1.5rem; margin: 0 0 0.75rem; font-weight: 700; }
205
+ .modal-dialog p { font-size: 1rem; color: var(--text-secondary); margin: 0 0 2rem; }
206
+ .modal-buttons { display: flex; gap: 1rem; }
207
+ .modal-btn { flex: 1; padding: 0.8rem 1rem; border-radius: var(--radius-btn); border: none; cursor: pointer; font-family: var(--app-font); font-weight: 600; font-size: 1rem; transition: var(--transition-smooth); }
208
  .modal-btn.confirm-btn { background-color: var(--danger-color); color: white; }
209
+ .modal-btn.confirm-btn:hover { background-color: var(--danger-color-hover); transform: translateY(-2px); }
210
+ .modal-btn.cancel-btn { background-color: var(--input-bg); color: var(--text-secondary); border: 1px solid var(--input-border); }
211
+ .modal-btn.cancel-btn:hover { background-color: var(--panel-border); color: var(--text-primary); }
212
+
213
+ /* === START: CSS FOR IP RESET GUIDE (NEW) === */
214
+ .ip-reset-guide-container { text-align: right; background: var(--panel-bg); padding: 10px; border-radius: var(--radius-lg-guide); animation: slideInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) both; max-width: 100%; width: 100%; position: relative; overflow: hidden; box-sizing: border-box; }
215
+ .ip-reset-guide-container::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 5px; background: var(--primary-gradient-guide); }
216
+ .guide-header { display: flex; align-items: center; margin-bottom: 20px; position: relative; }
217
+ .guide-header-icon { width: 50px; height: 50px; margin-left: 15px; animation: float 3s ease-in-out infinite; flex-shrink: 0; }
218
+ .guide-header h2 { font-size: 1.2rem; color: var(--guide-text-title); font-weight: 700; margin: 0; }
219
+ .guide-header p { color: var(--guide-text-body); font-size: 0.85rem; margin-top: 5px; }
220
+ .guide-content { font-size: 0.95rem; color: var(--guide-text-body); line-height: 1.8; }
221
+ .info-card { background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%); border: 1px solid rgba(102, 126, 234, 0.2); border-radius: var(--radius-md-guide); padding: 15px; margin: 15px 0; position: relative; overflow: hidden; }
222
+ .info-card p { font-size: 0.85rem; line-height: 1.7; }
223
+ .info-card::before { content: ''; position: absolute; top: 0; right: 0; width: 4px; height: 100%; background: var(--primary-gradient-guide); }
224
+ .info-card-header { display: flex; align-items: center; margin-bottom: 10px; }
225
+ .info-card-icon { width: 22px; height: 22px; margin-left: 10px; }
226
+ .info-card-title { font-weight: 600; color: var(--guide-text-title); font-size: 1rem; }
227
+ .method-cards { display: grid; gap: 15px; margin: 20px 0; }
228
+ .method-card { background: linear-gradient(135deg, #f6f8fb 0%, #ffffff 100%); border: 1px solid #e2e8f0; border-radius: var(--radius-md-guide); padding: 15px; display: flex; align-items: flex-start; transition: var(--transition-smooth); }
229
+ .method-card-icon { width: 35px; height: 35px; margin-left: 15px; flex-shrink: 0; }
230
+ .method-card-content { flex: 1; }
231
+ .method-card-title { font-weight: 600; color: var(--guide-text-title); margin-bottom: 8px; display: flex; align-items: center; font-size: 0.9rem; }
232
+ .method-badge { background: var(--success-gradient-guide); color: white; font-size: 0.7rem; padding: 2px 8px; border-radius: 12px; margin-right: 8px; font-weight: 500; }
233
+ .method-card-desc { color: var(--guide-text-body); font-size: 0.85rem; line-height: 1.6; }
234
+ .summary-section { margin-top: 20px; padding: 15px; border-radius: var(--radius-md-guide); background: linear-gradient(135deg, #56ab2f15 0%, #a8e06315 100%); border: 1px solid rgba(86, 171, 47, 0.2); position: relative; overflow: hidden; }
235
+ .summary-section::before { content: ''; position: absolute; top: 0; right: 0; width: 4px; height: 100%; background: var(--success-gradient-guide); }
236
+ .summary-header { display: flex; align-items: center; margin-bottom: 10px; }
237
+ .summary-icon { width: 22px; height: 22px; margin-left: 10px; }
238
+ .summary-title { font-weight: 600; color: #2f5a33; font-size: 1rem; }
239
+ .summary-text { color: #2f5a33; font-size: 0.9rem; line-height: 1.7; }
240
+ .guide-actions { display: flex; gap: 15px; margin-top: 25px; padding-top: 20px; border-top: 1px solid #e2e8f0; }
241
+ .action-button { padding: 12px 20px; border: none; border-radius: var(--radius-md-guide); font-size: 0.9rem; font-weight: 600; cursor: pointer; font-family: inherit; flex: 1; transition: var(--transition-smooth); position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
242
+ .action-button-icon { width: 18px; height: 18px; margin-right: 8px; margin-left: 0; }
243
+ .back-button { background: white; color: var(--guide-text-body); border: 2px solid #e2e8f0; flex: 0.4; }
244
+ .back-button:hover { background: #f7fafc; border-color: var(--guide-accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }
245
+ .retry-button { background: var(--primary-gradient-guide); color: white; flex: 0.6; box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3); }
246
+ .retry-button:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4); }
247
+ .video-button-container { text-align: center; margin: 25px 0 10px 0; }
248
+ .elegant-video-button { display: inline-flex; align-items: center; justify-content: center; padding: 7px 18px; background-color: #f0f2f5; color: var(--guide-accent); border: 1px solid #e2e8f0; text-decoration: none; border-radius: var(--radius-md-guide); font-weight: 600; font-size: 0.8rem; cursor: pointer; font-family: inherit; transition: all 0.3s ease; box-shadow: var(--shadow-sm); }
249
+ .elegant-video-button:hover { background: var(--primary-gradient-guide); color: white; border-color: transparent; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(102, 126, 234, 0.3); }
250
+ .elegant-video-button-icon { width: 16px; height: 16px; margin-left: 8px; fill: currentColor; }
251
+ /* === END: CSS FOR IP RESET GUIDE (NEW) === */
252
+
253
+ @media (max-width: 768px) { main, .gallery-section { padding: 1.5rem; } h1 { font-size: 2.2rem; } #lightbox-next { right: 5px; background-color: rgba(26, 32, 44, 0.5); } }
254
  </style>
255
  </head>
256
  <body>
257
  <div class="container">
258
  <header>
259
+ <canvas id="neural-network-canvas"></canvas>
260
  <h1>فتوشاپ هوش مصنوعی ✨</h1>
261
  <p class="subtitle">تصاویر خود را با قدرت هوش مصنوعی و به زبان ساده ویرایش کنید</p>
262
+ <div id="subscription-status-badge" style="display:inline-block;"></div>
263
  </header>
264
 
265
  <main>
266
  <div class="form-group">
267
+ <div class="form-label">
268
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4Z"/></svg>
269
+ ۱. تصویر خود را انتخاب کنید
270
+ </div>
271
  <label id="upload-area" for="file-input">
272
+ <div id="upload-content">
273
+ <div id="upload-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg></div>
274
+ <p>فایل تصویر را اینجا بکشید یا برای انتخاب کلیک کنید</p>
275
+ </div>
276
  <img id="preview-image-main" src="" alt="Preview">
277
  <button type="button" id="remove-file-btn-main" title="حذف تصویر">&times;</button>
278
  </label>
279
  <input type="file" id="file-input" accept="image/*" hidden>
280
  </div>
281
  <div class="form-group">
282
+ <label for="prompt-input" class="form-label">
283
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg>
284
+ ۲. دستور ویرایش را بنویسید
285
+ </label>
286
  <textarea id="prompt-input" rows="3" placeholder="مثال: پس‌زمینه را حذف کن و یک ساحل آفتابی قرار بده"></textarea>
287
+ <div id="credit-info-section"></div>
288
+ <button id="upgrade-button">⭐️ ارتقا به نسخه کامل و نامحدود</button>
289
+
290
  <button id="submit-btn" disabled>
291
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3L12 8L17 10L12 12L10 3z"/></svg>
292
  <span id="btn-text">ایجاد کن</span>
293
  <div class="spinner"></div>
294
  </button>
295
+
296
+ <!-- المان جدید برای نمایش هشدار محتوای نامناسب -->
297
+ <div id="content-warning">متن شما حاوی کلمات نامناسب است. لطفاً متن را اصلاح کرده و مجدداً تلاش کنید.</div>
298
+
299
+ <p id="error-message"></p>
300
  </div>
301
  <div class="form-group">
302
+ <div class="form-label">
303
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3L12 8L17 10L12 12L10 17L8 12L3 10L8 8L10 3z"/><path d="M21 14l-1.5 3-3-1.5 3-3 1.5 3z"/><path d="M19.5 2.5l-3 1.5 1.5 3 3-1.5-1.5-3z"/></svg>
304
+ ۳. نتیجه را ببینید
305
+ </div>
306
  <div id="result-container">
307
+ <div id="loading-placeholder">
308
+ <div class="generator-container">
309
+ <div class="noise-layer"></div><div class="sketch-layer"></div><div class="building-layer"></div><div class="pixel-grid"></div><div class="particles"></div>
310
+ <div class="text-overlay" id="loading-status-text">در حال ویرایش تصویر...</div>
311
+ <div class="progress-bar"></div>
312
+ </div>
313
+ </div>
314
+ <div id="result-grid"></div>
315
  </div>
316
  </div>
317
  </main>
 
318
  <section class="gallery-section">
319
  <div class="gallery-header">
320
+ <div class="form-label">
321
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18"/><path d="M9 21V9"/></svg>
322
+ گالری و تاریخچه شما
323
+ </div>
324
+ <button id="clear-history-btn">
325
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
326
+ <span>پاک کردن همه</span>
327
+ </button>
328
  </div>
329
  <div id="history-grid"></div>
330
  </section>
331
  </div>
332
+ <div id="lightbox">
333
+ <div id="lightbox-content">
334
+ <img id="lightbox-img" src="">
335
+ <button id="lightbox-close" class="lightbox-btn" title="بستن">&times;</button>
336
+ <button id="lightbox-download" title="دانلود تصویر" class="lightbox-btn">
337
+ <svg fill="white" viewBox="0 0 24 24"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>
338
+ <div class="spinner"></div>
339
+ </button>
340
+ <button id="lightbox-next" title="بعدی" class="lightbox-btn">
341
+ <svg fill="white" viewBox="0 0 24 24" width="24" height="24"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z"/></svg>
342
+ </button>
343
+ </div>
344
+ </div>
345
+ <div id="confirmation-modal">
346
+ <div class="modal-dialog">
347
+ <div class="modal-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg></div>
348
+ <h3>تایید حذف</h3>
349
+ <p id="modal-message-text">آیا از انجام این عمل مطمئن هستید؟</p>
350
+ <div class="modal-buttons">
351
+ <button id="modal-cancel-btn" class="modal-btn cancel-btn">انصراف</button>
352
+ <button id="modal-confirm-btn" class="modal-btn confirm-btn">بله، حذف کن</button>
353
+ </div>
354
+ </div>
355
+ </div>
356
 
357
+ <script type="module">
358
+ // === START: بخش مدیریت کاربر و ارتباط با والد ===
359
+ let userSubscriptionStatus = 'free'; let userFingerprint = null; let countdownInterval = null; const PREMIUM_PAGE_ID = '1149636';
360
+ async function getBrowserFingerprint() { const components = [navigator.userAgent, navigator.language, screen.width + 'x' + screen.height, new Date().getTimezoneOffset()]; try { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); ctx.fillText("a1b2c3d4e5f6g7h8i9j0", 2, 15); components.push(canvas.toDataURL()); } catch (e) { components.push("canvas-error"); } const fingerprintString = components.join('---'); let hash = 0; for (let i = 0; i < fingerprintString.length; i++) { hash = ((hash << 5) - hash) + fingerprintString.charCodeAt(i); hash |= 0; } return 'fp_' + Math.abs(hash).toString(16); }
361
+ function isUserPaid(userObject) { return userObject && userObject.isLogin && userObject.accessible_pages && (userObject.accessible_pages.includes(PREMIUM_PAGE_ID) || userObject.accessible_pages.includes(parseInt(PREMIUM_PAGE_ID))); }
362
+ function updateUIForSubscriptionStatus(status) { userSubscriptionStatus = status; const creditInfoDiv = document.getElementById('credit-info-section'); const upgradeBtn = document.getElementById('upgrade-button'); const subscriptionBadge = document.getElementById('subscription-status-badge'); if (status === 'paid') { subscriptionBadge.textContent = 'نسخه نامحدود'; subscriptionBadge.className = 'paid-badge'; creditInfoDiv.style.display = 'none'; upgradeBtn.style.display = 'none'; if(countdownInterval) clearInterval(countdownInterval); checkFormState(); } else { subscriptionBadge.textContent = 'نسخه رایگان'; subscriptionBadge.className = 'free-badge'; checkFreeUserCredit(); } subscriptionBadge.style.display = 'inline-block'; }
363
+ async function checkFreeUserCredit() { if (!userFingerprint) return; const creditInfoDiv = document.getElementById('credit-info-section'); const upgradeBtn = document.getElementById('upgrade-button'); const genBtn = document.getElementById('submit-btn'); try { const response = await fetch('/api/check-credit', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ fingerprint: userFingerprint }) }); const result = await response.json(); creditInfoDiv.style.display = 'block'; if (result.limit_reached) { upgradeBtn.style.display = 'block'; startCountdown(result.reset_timestamp); checkFormState(); } else { upgradeBtn.style.display = 'none'; if(countdownInterval) clearInterval(countdownInterval); creditInfoDiv.textContent = `شما ${result.credits_remaining} اعتبار ویرایش رایگان در این هفته دارید.`; checkFormState(); } } catch (error) { creditInfoDiv.textContent = "خطا در بررسی اعتبار."; genBtn.disabled = true; } }
364
+ function startCountdown(resetTimestamp) { if (countdownInterval) clearInterval(countdownInterval); const creditInfoDiv = document.getElementById('credit-info-section'); const updateTimer = () => { const timeLeft = Math.max(0, resetTimestamp - (Date.now() / 1000)); if (timeLeft === 0) { clearInterval(countdownInterval); creditInfoDiv.textContent = 'در حال بروزرسانی اعتبار...'; setTimeout(checkFreeUserCredit, 2000); return; } const d = Math.floor(timeLeft / 86400); const h = Math.floor((timeLeft % 86400) / 3600); const m = Math.floor((timeLeft % 3600) / 60); creditInfoDiv.textContent = `اعتبار شما تمام شده. زمان باقی‌مانده: ${d} روز و ${h} ساعت و ${m} دقیقه`; }; updateTimer(); countdownInterval = setInterval(updateTimer, 60000); }
365
+ window.addEventListener('message', (event) => { if (event.data && event.data.type === 'USER_DATA_RESPONSE') { if (event.data.error || !event.data.payload) { updateUIForSubscriptionStatus('free'); return; } try { const userObject = JSON.parse(event.data.payload); const status = isUserPaid(userObject) ? 'paid' : 'free'; updateUIForSubscriptionStatus(status); } catch (e) { updateUIForSubscriptionStatus('free'); } } });
366
+ document.getElementById('upgrade-button').addEventListener('click', () => { parent.postMessage({ type: 'NAVIGATE_TO_PREMIUM' }, '*'); });
 
 
 
 
367
 
368
+ // === START: منطق اصلی برنامه ===
369
+ const uploadArea = document.getElementById('upload-area'); const fileInput = document.getElementById('file-input'); const previewImage = document.getElementById('preview-image-main'); const removeFileBtn = document.getElementById('remove-file-btn-main'); const promptInput = document.getElementById('prompt-input'); const submitBtn = document.getElementById('submit-btn'); const resultContainer = document.getElementById('result-container'); let resultGrid = document.getElementById('result-grid'); const errorMessage = document.getElementById('error-message'); const lightbox = document.getElementById('lightbox'); const lightboxImg = document.getElementById('lightbox-img'); const lightboxClose = document.getElementById('lightbox-close'); const lightboxDownload = document.getElementById('lightbox-download'); const lightboxNext = document.getElementById('lightbox-next'); const historyGrid = document.getElementById('history-grid'); const clearHistoryBtn = document.getElementById('clear-history-btn'); const confirmationModal = document.getElementById('confirmation-modal'); const modalMessageText = document.getElementById('modal-message-text'); const modalConfirmBtn = document.getElementById('modal-confirm-btn'); const modalCancelBtn = document.getElementById('modal-cancel-btn');
370
+ let uploadedFile = null; let currentLightboxUrl = null; let currentLightboxGroup = []; let currentLightboxIndex = 0;
371
  let pollTimer = null;
372
+
373
+ // --- START: IndexedDB Handler ---
374
+ const dbHandler = { db: null, dbName: 'aiPhotoshopDB', storeName: 'history', initDB() { return new Promise((resolve, reject) => { const request = indexedDB.open(this.dbName, 1); request.onerror = (event) => { console.error("IndexedDB error:", event.target.error); reject("Error opening DB"); }; request.onsuccess = (event) => { this.db = event.target.result; resolve(); }; request.onupgradeneeded = (event) => { const db = event.target.result; const store = db.createObjectStore(this.storeName, { keyPath: 'id', autoIncrement: true }); store.createIndex('timestamp', 'timestamp', { unique: false }); }; }); }, add(item) { return new Promise((resolve, reject) => { const transaction = this.db.transaction([this.storeName], 'readwrite'); const store = transaction.objectStore(this.storeName); const request = store.add(item); request.onsuccess = () => resolve(); request.onerror = (event) => reject(event.target.error); }); }, getAll() { return new Promise((resolve, reject) => { const transaction = this.db.transaction([this.storeName], 'readonly'); const store = transaction.objectStore(this.storeName); const request = store.getAll(); request.onsuccess = () => { resolve(request.result.sort((a, b) => b.timestamp - a.timestamp)); }; request.onerror = (event) => reject(event.target.error); }); }, delete(id) { return new Promise((resolve, reject) => { const transaction = this.db.transaction([this.storeName], 'readwrite'); const store = transaction.objectStore(this.storeName); const request = store.delete(id); request.onsuccess = () => resolve(); request.onerror = (event) => reject(event.target.error); }); }, clear() { return new Promise((resolve, reject) => { const transaction = this.db.transaction([this.storeName], 'readwrite'); const store = transaction.objectStore(this.storeName); const request = store.clear(); request.onsuccess = () => resolve(); request.onerror = (event) => reject(event.target.error); }); }, deleteOlderThan(timestamp) { return new Promise((resolve, reject) => { const transaction = this.db.transaction([this.storeName], 'readwrite'); const store = transaction.objectStore(this.storeName); const index = store.index('timestamp'); const keyRange = IDBKeyRange.upperBound(timestamp); const request = index.openCursor(keyRange); request.onsuccess = (event) => { const cursor = event.target.result; if (cursor) { store.delete(cursor.primaryKey); cursor.continue(); } else { resolve(); } }; request.onerror = (event) => reject(event.target.error); }); } };
375
 
376
+ function enhancePrompt(prompt) {
377
+ const words = prompt.trim().split(/\s+/);
378
+ if (words.length === 1) {
379
+ const commonVerbs = ["add", "put", "make", "change", "remove", "turn", "create"];
380
+ const hasVerb = commonVerbs.some(verb => prompt.toLowerCase().includes(verb));
381
+ if (!hasVerb) return `Add a ${prompt}`;
382
+ }
383
+ return prompt;
384
+ }
385
+
386
+ // --- بررسی کلمات ممنوعه ---
387
+ const forbiddenWords = ['سکس', 'سکسی', 'پورن', 'عریان', 'لخت', 'شهوانی', 'برهنه', 'آلت', 'جنسی', 'xxx', 'پورنو', 'تجاوز', 'sex', 'sexy', 'porn', 'nsfw', 'nude', 'naked', 'erotic', 'penis', 'vagina', 'hentai', 'boobs', 'ass', 'dick'];
388
+ let warningTimeout;
389
+ function checkContentSafety(text) { const lowerText = text.toLowerCase(); return forbiddenWords.some(word => lowerText.includes(word)); }
390
+ function showContentWarning() { const warningDiv = document.getElementById('content-warning'); if (warningTimeout) clearTimeout(warningTimeout); warningDiv.classList.remove('hide'); warningDiv.classList.add('show'); warningTimeout = setTimeout(() => { warningDiv.classList.remove('show'); warningDiv.classList.add('hide'); }, 3000); }
 
 
 
 
 
 
 
391
 
392
+ const GPU_QUOTA_ERROR_HTML = `
393
+ <div class="ip-reset-guide-container">
394
+ <div class="guide-header">
395
+ <svg class="guide-header-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10" stroke="#667eea" stroke-width="2" fill="rgba(102, 126, 234, 0.1)"/><path d="M8 12.5l2.5 2.5L16 9" stroke="#667eea" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
396
+ <div><h2>یک قدم تا ویرایش تصاویر جدید</h2><p>نیازمند تغییر نقطه دستیابی</p></div>
397
+ </div>
398
+ <div class="guide-content">
399
+ <div class="info-card">
400
+ <div class="info-card-header"><svg class="info-card-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" stroke="#667eea" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="info-card-title">راه حل سریع</span></div>
401
+ <p>طبق ویدیو آموزشی پایین بین نقطه دستیابی جابجا شوید تلاش مجدد بزنید تا تصویر مجدداً پردازش بشه.</p>
402
+ </div>
403
+ </div>
404
+ <div class="video-button-container">
405
+ <button id="tutorialLinkBtn" class="elegant-video-button">
406
+ <svg class="elegant-video-button-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8 5v14l11-7z"></path></svg>
407
+ دیدن ویدیو آموزشی
408
+ </button>
409
+ </div>
410
+ <div class="guide-actions">
411
+ <button class="action-button back-button" id="guide-back-btn"><svg class="action-button-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 12H5M12 19l-7-7 7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>بازگشت</button>
412
+ <button class="action-button retry-button" id="guide-retry-btn"><svg class="action-button-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M23 4v6h-6M1 20v-6h6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg> تلاش مجدد</button>
413
+ </div>
414
+ </div>
415
+ `;
416
+ const ORIGINAL_RESULT_CONTAINER_HTML = `
417
+ <div id="loading-placeholder">
418
+ <div class="generator-container">
419
+ <div class="noise-layer"></div><div class="sketch-layer"></div><div class="building-layer"></div><div class="pixel-grid"></div><div class="particles"></div>
420
+ <div class="text-overlay" id="loading-status-text">در حال ویرایش تصویر...</div>
421
+ <div class="progress-bar"></div>
422
+ </div>
423
+ </div>
424
+ <div id="result-grid"></div>
425
+ `;
426
 
427
+ const convertToPNG = (file) => new Promise((resolve, reject) => { const image = new Image(); const reader = new FileReader(); image.onload = () => { const canvas = document.createElement('canvas'); canvas.width = image.width; canvas.height = image.height; const ctx = canvas.getContext('2d'); ctx.drawImage(image, 0, 0); canvas.toBlob((blob) => { if (!blob) { reject(new Error('تبدیل به PNG ناموفق بود.')); return; } const originalName = file.name.substring(0, file.name.lastIndexOf('.')) || file.name; const pngFile = new File([blob], `${originalName}.png`, { type: 'image/png' }); resolve(pngFile); }, 'image/png', 1.0); }; image.onerror = () => reject(new Error('فایل تصویر قابل خواندن نیست.')); reader.onload = e => { image.src = e.target.result; }; reader.onerror = () => reject(new Error('خطا در خواندن فایل.')); reader.readAsDataURL(file); });
428
+ const handleFile = async (file) => { if (!file || !file.type.startsWith('image/')) { displayError('لطفا یک فایل تصویری معتبر انتخاب کنید.'); return; } let fileToProcess = file; if (file.type !== 'image/png' && file.type !== 'image/jpeg') { try { fileToProcess = await convertToPNG(file); } catch (error) { console.error('Image conversion failed:', error); displayError('خطا در تبدیل فرمت تصویر.'); resetUploader(); return; } } uploadedFile = fileToProcess; const reader = new FileReader(); reader.onload = (e) => { previewImage.src = e.target.result; }; reader.readAsDataURL(file); uploadArea.classList.add('has-file'); checkFormState(); clearResult(); };
429
+ const resetUploader = () => { uploadedFile = null; fileInput.value = ''; previewImage.src = ''; uploadArea.classList.remove('has-file'); checkFormState(); };
430
+ const checkFormState = () => { const isReady = uploadedFile && promptInput.value.trim() !== ''; if (userSubscriptionStatus === 'free' && document.getElementById('upgrade-button').style.display === 'block') { submitBtn.disabled = true; } else { submitBtn.disabled = !isReady; } };
431
+
432
+ const setLoading = (isLoading, message = 'در حال پردازش...') => {
433
+ const btnSpinner = submitBtn.querySelector('.spinner'); const btnText = document.getElementById('btn-text'); const btnIcon = submitBtn.querySelector('svg');
434
+ if (isLoading) {
435
+ clearResult();
436
+ resultContainer.classList.add('loading');
437
+ btnSpinner.style.display = 'inline-block'; btnIcon.style.display = 'none'; btnText.textContent = message; submitBtn.disabled = true;
438
+ if(resultGrid) resultGrid.innerHTML = ''; errorMessage.style.display = 'none';
439
+ } else {
440
+ resultContainer.classList.remove('loading'); btnSpinner.style.display = 'none'; btnIcon.style.display = 'inline-block'; btnText.textContent = 'ایجاد کن'; checkFormState();
441
+ }
442
+ };
443
+
444
+ const displayResult = (imageUrls) => {
445
+ if (!resultGrid) return;
446
+ resultGrid.innerHTML = '';
447
+ imageUrls.forEach((url) => {
448
+ const img = document.createElement('img');
449
+ img.src = url; img.alt = 'تصویر ویرایش شده';
450
+ img.addEventListener('click', () => openLightbox(url, imageUrls));
451
+ resultGrid.appendChild(img);
452
+ });
453
+ resultContainer.classList.add('has-content');
454
  };
 
 
 
 
 
 
 
455
 
456
+ const clearResult = () => {
457
+ resultContainer.innerHTML = ORIGINAL_RESULT_CONTAINER_HTML;
458
+ resultGrid = document.getElementById('result-grid');
459
+ errorMessage.style.display = 'none';
460
+ resultContainer.classList.remove('has-content');
461
+ resultContainer.classList.remove('loading', 'has-error-guide');
462
+ };
463
 
464
+ const displayError = (message) => {
465
+ setLoading(false);
466
+ const triggers = ['پاسخ معتبری از سرور دریافت نشد', 'free generation limit', 'You have reached the free generation limit'];
467
+ const shouldShowGuide = triggers.some(trigger => message.includes(trigger));
468
 
469
+ if (shouldShowGuide) {
470
+ resultContainer.innerHTML = GPU_QUOTA_ERROR_HTML;
471
+ resultContainer.classList.add('has-content', 'has-error-guide');
472
+
473
+ document.getElementById('guide-back-btn').addEventListener('click', clearResult);
474
+ document.getElementById('guide-retry-btn').addEventListener('click', () => submitBtn.click());
475
+ document.getElementById('tutorialLinkBtn').addEventListener('click', () => {
476
+ const tutorialUrl = '#/nav/online/news/getSingle/1149635/eyJpdiI6IjhHVGhPQWJwb3E0cjRXbnFWTW5BaUE9PSIsInZhbHVlIjoiS1V0dTdvT21wbXAwSXZaK1RCTG1pVXZqdlFJa1hXV1RKa2FLem9zU3pXMjd5MmlVOGc2YWY0NVdNR3h3Smp1aSIsIm1hYyI6IjY1NTA5ZDYzMjAzMTJhMGQyMWQ4NjA4ZDgyNGZjZDVlY2MyNjdiMjA2NWYzOWRjY2M4ZmVjYWRlMWNlMWQ3ODEiLCJ0YWciOiIifQ==/21135210';
477
+ window.parent.postMessage({ type: 'NAVIGATE_TO_URL', url: tutorialUrl }, '*');
478
+ });
479
+ } else {
480
+ errorMessage.textContent = message;
481
+ errorMessage.style.display = 'block';
482
+ }
483
+ };
484
 
485
+ const openLightbox = (clickedUrl, urlGroup) => { currentLightboxGroup = urlGroup; currentLightboxIndex = urlGroup.indexOf(clickedUrl); updateLightboxImage(); lightboxNext.style.display = urlGroup.length > 1 ? 'flex' : 'none'; lightbox.classList.add('visible'); };
486
+ const closeLightbox = () => { lightbox.classList.remove('visible'); };
487
+ const updateLightboxImage = () => { const newUrl = currentLightboxGroup[currentLightboxIndex]; lightboxImg.src = newUrl; currentLightboxUrl = newUrl; };
488
+ const handleDownload = () => { if (!currentLightboxUrl) return; parent.postMessage({ type: 'DOWNLOAD_REQUEST', url: currentLightboxUrl }, '*'); };
489
+ const addToHistory = async (item) => { const newItem = { ...item, timestamp: Date.now() }; try { await dbHandler.add(newItem); const history = await dbHandler.getAll(); if (history.length > 15) { await dbHandler.delete(history[history.length - 1].id); } } catch (error) { console.error("Failed to add to history:", error); } await renderHistory(); };
490
+ const showConfirmationModal = (message, onConfirm) => { modalMessageText.textContent = message; confirmationModal.classList.add('visible'); modalConfirmBtn.onclick = () => { onConfirm(); hideConfirmationModal(); }; modalCancelBtn.onclick = () => { hideConfirmationModal(); }; };
491
+ const hideConfirmationModal = () => { confirmationModal.classList.remove('visible'); };
492
+ const handleClearHistory = () => { showConfirmationModal('آیا از پاک کردن تمام تاریخچه مطمئن هستید؟', async () => { await dbHandler.clear(); await renderHistory(); }); };
493
+ const handleDeleteItem = (id) => { showConfirmationModal('آیا از حذف این مورد مطمئن هستید؟', async () => { await dbHandler.delete(id); await renderHistory(); }); };
494
+ const renderHistory = async () => { try { const expirationTime = 23 * 60 * 60 * 1000; const expirationTimestamp = Date.now() - expirationTime; await dbHandler.deleteOlderThan(expirationTimestamp); const history = await dbHandler.getAll(); historyGrid.innerHTML = ''; clearHistoryBtn.style.display = history.length > 0 ? 'flex' : 'none'; history.forEach((item) => { const card = document.createElement('div'); card.className = 'history-item'; const deleteBtn = document.createElement('button'); deleteBtn.className = 'history-delete-btn'; deleteBtn.title = 'حذف'; deleteBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>`; deleteBtn.onclick = () => handleDeleteItem(item.id); card.appendChild(deleteBtn); const imageGrid = document.createElement('div'); imageGrid.className = 'history-item-grid'; item.urls.forEach(url => { const img = document.createElement('img'); img.src = url; img.alt = 'تصویر تاریخچه'; img.addEventListener('click', () => openLightbox(url, item.urls)); imageGrid.appendChild(img); }); card.appendChild(imageGrid); historyGrid.appendChild(card); }); } catch (error) { console.error("Could not render history:", error); historyGrid.innerHTML = '<p style="color: var(--danger-color); grid-column: 1 / -1; text-align: center;">خطا در بارگذاری تاریخچه.</p>'; } };
495
 
496
+ // === START: اتصال به داکر بجای اتصال مستقیم ===
497
+ const proceedWithImageGeneration = async () => {
498
+ if (checkContentSafety(promptInput.value)) { showContentWarning(); return; }
499
+ if (submitBtn.disabled) return;
500
+
501
+ clearResult();
502
+ setLoading(true, 'در حال آپلود و ترجمه...');
503
+
504
  try {
505
+ const loadingStatusText = document.getElementById('loading-status-text');
506
+ if(loadingStatusText) loadingStatusText.innerHTML = 'در حال آپلود و ترجمه...<br><small>مرحله ۱ از ۳</small>';
507
+
508
+ let rawPrompt = promptInput.value.trim();
509
+ let finalPrompt = enhancePrompt(rawPrompt);
510
 
511
+ const formData = new FormData();
512
+ formData.append('image', uploadedFile);
513
+ formData.append('prompt', finalPrompt);
514
+
515
+ // ارسال به سرور داکر
516
+ const res = await fetch('/api/edit', {
517
+ method: 'POST',
518
+ body: formData
519
+ });
520
+ const data = await res.json();
521
+
522
  if (data.status === 'success') {
523
+ if(loadingStatusText) loadingStatusText.innerHTML = `دستور ترجمه شد: ${data.translated}<br><small>مرحله ۲ از ۳: در حال ویرایش تصویر در سرور... (حدود ۱ دقیقه)</small>`;
524
+
525
+ pollTimer = setInterval(() => checkEditorResult(data.run_id), 3000);
526
  } else {
527
+ throw new Error('خطا در ارتباط با سرور.');
 
528
  }
529
+ } catch (error) {
530
+ displayError(`متاسفانه خطایی رخ داد: ${error.message}`);
531
+ setLoading(false);
532
  }
533
  };
534
 
535
+ async function checkEditorResult(run_id) {
536
  try {
537
  const res = await fetch(`/api/status/${run_id}`);
538
  const data = await res.json();
539
 
540
  if (data.status === 'ready') {
541
  clearInterval(pollTimer);
 
 
 
 
542
 
543
+ const imageUrls = [data.url];
 
 
544
 
545
+ if (userSubscriptionStatus === 'free') {
546
+ await fetch('/api/use-credit', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ fingerprint: userFingerprint }) });
547
+ checkFreeUserCredit();
548
+ }
549
+
550
+ displayResult(imageUrls);
551
+ await addToHistory({ prompt: promptInput.value.trim(), urls: imageUrls });
552
+ setLoading(false);
553
  }
554
+ } catch (e) {
555
+ console.log('Polling...', e);
556
+ }
557
  }
558
+ // === END: اتصال به داکر بجای اتصال مستقیم ===
559
 
560
+ submitBtn.addEventListener('click', async () => {
561
+ if (checkContentSafety(promptInput.value)) { showContentWarning(); return; }
562
+ if (userSubscriptionStatus === 'paid') {
563
+ await proceedWithImageGeneration();
564
+ } else {
565
+ try {
566
+ const response = await fetch('/api/check-credit', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ fingerprint: userFingerprint }) });
567
+ const result = await response.json();
568
+ if (result.limit_reached) { updateUIForSubscriptionStatus('free'); return; }
569
+ await proceedWithImageGeneration();
570
+ } catch (err) { displayError(`خطا در سیستم اعتبار: ${err.message}`); }
571
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
572
  });
573
+
574
+ // Event Listeners
575
+ document.addEventListener('DOMContentLoaded', async () => { try { await dbHandler.initDB(); await renderHistory(); } catch (error) { console.error("Failed to initialize the application:", error); displayError("خطا در راه اندازی اولیه برنامه. لطفا صفحه را رفرش کنید."); } userFingerprint = await getBrowserFingerprint(); parent.postMessage({ type: 'REQUEST_USER_DATA' }, '*'); checkFormState(); });
576
+ removeFileBtn.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); resetUploader(); });
577
+ fileInput.addEventListener('change', (e) => handleFile(e.target.files[0]));
578
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(e => { uploadArea.addEventListener(e, p => { p.preventDefault(); p.stopPropagation(); }); });
579
+ ['dragenter', 'dragover'].forEach(e => { uploadArea.addEventListener(e, () => { if (!uploadArea.classList.contains('has-file')) uploadArea.classList.add('drag-over'); }); });
580
+ ['dragleave', 'drop'].forEach(e => { uploadArea.addEventListener(e, () => uploadArea.classList.remove('drag-over')); });
581
+ uploadArea.addEventListener('drop', e => { if (!uploadArea.classList.contains('has-file')) handleFile(e.dataTransfer.files[0]); });
582
+ promptInput.addEventListener('input', checkFormState);
583
+ lightboxClose.addEventListener('click', closeLightbox);
584
+ lightbox.addEventListener('click', (e) => { if (e.target === lightbox) closeLightbox(); });
585
+ lightboxDownload.addEventListener('click', handleDownload);
586
+ lightboxNext.addEventListener('click', () => { currentLightboxIndex = (currentLightboxIndex + 1) % currentLightboxGroup.length; updateLightboxImage(); });
587
+ clearHistoryBtn.addEventListener('click', handleClearHistory);
588
+ </script>
589
+
590
+ <script>
591
+ // --- Header Animation Script ---
592
+ document.addEventListener('DOMContentLoaded', () => { const canvas = document.getElementById('neural-network-canvas'); if (!canvas) return; const header = canvas.parentElement; const ctx = canvas.getContext('2d'); let particles = []; const particleCount = 20; const maxDistance = 100; const computedStyles = getComputedStyle(document.documentElement); const particleColor = computedStyles.getPropertyValue('--accent-primary').trim(); const lineColor = computedStyles.getPropertyValue('--text-tertiary').trim(); function resizeCanvas() { canvas.width = header.clientWidth; canvas.height = header.clientHeight; init(); } class Particle { constructor() { this.x = Math.random() * canvas.width; this.y = Math.random() * canvas.height; this.vx = (Math.random() - 0.5) * 0.3; this.vy = (Math.random() - 0.5) * 0.3; this.radius = 1.2; } update() { this.x += this.vx; this.y += this.vy; if (this.x < 0 || this.x > canvas.width) this.vx *= -1; if (this.y < 0 || this.y > canvas.height) this.vy *= -1; } draw() { ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2); ctx.fillStyle = particleColor; ctx.fill(); } } function init() { particles = []; for (let i = 0; i < particleCount; i++) { particles.push(new Particle()); } } function connectParticles() { for (let i = 0; i < particles.length; i++) { for (let j = i + 1; j < particles.length; j++) { const dx = particles[i].x - particles[j].x; const dy = particles[i].y - particles[j].y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance < maxDistance) { ctx.beginPath(); ctx.moveTo(particles[i].x, particles[i].y); ctx.lineTo(particles[j].x, particles[j].y); ctx.strokeStyle = lineColor; ctx.lineWidth = 0.2; ctx.globalAlpha = 1 - distance / maxDistance; ctx.stroke(); } } } ctx.globalAlpha = 1; } function animate() { ctx.clearRect(0, 0, canvas.width, canvas.height); particles.forEach(particle => { particle.update(); particle.draw(); }); connectParticles(); requestAnimationFrame(animate); } window.addEventListener('resize', resizeCanvas); resizeCanvas(); animate(); });
593
  </script>
594
  </body>
595
  </html>