/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --font: 'Outfit', system-ui, -apple-system, sans-serif;
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface2: #1e1e2a;
  --text: #f0f0f5;
  --text2: #8888aa;
  --accent: #d946ef;
  --accent2: #a21caf;
  --radius: 24px;
  --radius-sm: 16px;
  --shadow: 0 25px 45px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04);
  --transition: 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.01em;
}

/* ===== Particles ===== */
.particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.particle {
  position: absolute;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0.12;
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  0% { transform: translateY(0) scale(1); opacity: 0; }
  10% { opacity: 0.15; }
  90% { opacity: 0.15; }
  100% { transform: translateY(-110vh) scale(0.2); opacity: 0; }
}

/* ===== App Container ===== */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  margin: 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  background: var(--surface);
  backdrop-filter: blur(30px);
  border-radius: 40px;
  padding: 28px 22px 32px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.06);
  transition: all var(--transition);
}

/* ===== Header ===== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #f0abfc, #d946ef);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
  text-transform: lowercase;
  line-height: 1.2;
  padding: 0.15em 0;
  display: inline-block;
}
.icon-btn {
  background: var(--surface2);
  border: none;
  color: var(--text2);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  padding: 0;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn:active { transform: scale(0.9); background: var(--accent); color: white; }
.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--accent);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  box-shadow: 0 0 12px var(--accent);
  animation: pulseBadge 2s infinite;
  line-height: 1.3;
}
@keyframes pulseBadge {
  0% { box-shadow: 0 0 0 0 rgba(217,70,239,0.7); }
  70% { box-shadow: 0 0 0 12px rgba(217,70,239,0); }
  100% { box-shadow: 0 0 0 0 rgba(217,70,239,0); }
}

/* ===== Prompt Area ===== */
.prompt-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== Input Wrapper (اصلاح شده) ===== */
.input-wrapper {
  display: flex;
  align-items: center;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 10px 10px 10px 20px;
  border: 1px solid rgba(255,255,255,0.06);
  transition: all 0.25s;
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: none;  /* حذف بازتاب داخلی */
}
#promptInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1rem;
  padding: 12px 0;
  outline: none;
  font-family: var(--font);
  resize: none;
  min-height: 26px;
  font-weight: 400;
  line-height: 1.5;
}
#promptInput:focus {
  box-shadow: none;  /* حذف بازتاب داخلی */
  outline: none;
}
#promptInput::placeholder { color: var(--text2); font-weight: 300; }

/* ===== Generate Button ===== */
.generate-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  color: white;
  font-weight: 600;
  font-size: 1.1rem;
  padding: 16px 28px;
  border-radius: 50px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: 0.5px;
  box-shadow: 0 12px 30px rgba(217,70,239,0.5);
  transition: all var(--transition);
  text-transform: uppercase;
  line-height: 1.2;
}
.generate-btn:hover { transform: translateY(-2px); box-shadow: 0 16px 35px rgba(217,70,239,0.6); }
.generate-btn:active { transform: scale(0.95); }
.generate-btn:disabled { opacity: 0.5; transform: none; pointer-events: none; }
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,0.25);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Result Card ===== */
.result-card {
  background: var(--surface2);
  border-radius: var(--radius);
  overflow: hidden;
  animation: fadeSlideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  display: none;
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
.result-card img {
  width: 100%;
  display: block;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.result-actions {
  display: flex;
  justify-content: space-around;
  padding: 14px;
  gap: 8px;
}
.action-btn {
  background: transparent;
  border: none;
  color: var(--text2);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.3;
}
.action-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.action-btn:active { background: rgba(255,255,255,0.08); color: white; }

/* ===== Panels ===== */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 420px;
  height: 100dvh;
  background: var(--surface);
  backdrop-filter: blur(45px);
  z-index: 100;
  transform: translateX(110%);
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
  padding: 28px 22px;
  overflow-y: auto;
  box-shadow: -15px 0 40px rgba(0,0,0,0.8);
  border-left: 1px solid rgba(255,255,255,0.04);
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.panel.open { transform: translateX(0); }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-header h2 {
  font-size: 1.8rem;
  font-weight: 600;
  background: linear-gradient(135deg, #f0abfc, #d946ef);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-transform: lowercase;
  letter-spacing: -0.02em;
  line-height: 1.2;
  padding: 0.15em 0;
  display: inline-block;
}
.close-panel {
  background: var(--surface2);
  border: none;
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.setting-row label {
  font-size: 0.75rem;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  line-height: 1.4;
}
.model-select-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.model-select-row select { flex: 1; }
.refresh-btn {
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text2);
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
  flex-shrink: 0;
}
.refresh-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.refresh-btn:active { background: var(--accent); color: white; }

input, select, .setting-row input {
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 0.95rem;
  outline: none;
  transition: border 0.2s;
  font-family: var(--font);
  font-weight: 400;
  width: 100%;
  box-sizing: border-box;
  line-height: 1.4;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217,70,239,0.15);
}
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 400;
  line-height: 1.4;
}
.toggle {
  width: 50px;
  height: 28px;
  background: #3a3a4a;
  border-radius: 28px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle.active { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toggle.active::after { transform: translateX(22px); }

/* ===== History ===== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.history-item {
  background: var(--surface2);
  border-radius: 20px;
  padding: 14px;
  display: flex;
  gap: 14px;
  animation: slideIn 0.3s ease;
  transition: transform 0.2s, box-shadow 0.2s;
  align-items: center;
  cursor: pointer;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.history-item:active { transform: scale(0.98); background: #252533; }
.history-thumb {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  object-fit: cover;
  background: #2a2a35;
  flex-shrink: 0;
}
.history-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.history-prompt {
  font-weight: 500;
  font-size: 0.9rem;
  line-height: 1.35;
  overflow: hidden;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.history-meta {
  display: flex;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--text2);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  flex-wrap: wrap;
  line-height: 1.4;
}
.history-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.history-actions button {
  background: transparent;
  border: none;
  color: var(--text2);
  font-size: 1.2rem;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.2s;
  line-height: 1;
}
.history-actions button:active { color: white; background: rgba(255,255,255,0.1); }
.empty-state {
  text-align: center;
  color: var(--text2);
  padding: 50px 20px;
  font-weight: 400;
  line-height: 1.5;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 35px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: var(--surface2);
  color: white;
  padding: 14px 28px;
  border-radius: 40px;
  font-weight: 500;
  box-shadow: 0 15px 35px rgba(0,0,0,0.7);
  z-index: 200;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  line-height: 1.3;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== Overlay & Modals ===== */
.overlay-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}
.overlay-bg.active { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: var(--surface);
  padding: 30px 26px;
  border-radius: 32px;
  z-index: 110;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 40px 60px rgba(0,0,0,0.9);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal.active { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.modal h3 {
  font-weight: 600;
  font-size: 1.3rem;
  margin: 0;
  line-height: 1.35;
}
.modal p { line-height: 1.5; font-weight: 300; }
.modal input { width: 100%; margin: 8px 0; }
.modal img { width: 100%; border-radius: 16px; }

.btn-group {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 14px 28px;
  border-radius: 40px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: 0.2s;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.2;
}
.btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.btn:active { transform: scale(0.95); }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--text2);
  color: var(--text2);
}
.detail-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.detail-actions .btn { font-size: 0.9rem; padding: 12px 22px; }
#detailPrompt { word-break: break-word; font-size: 1.1rem; line-height: 1.35; }
#modelLoading { font-size: 0.75rem; color: var(--text2); }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .app { padding: 20px 16px 24px; margin: 10px; border-radius: 32px; }
  h1 { font-size: 1.6rem; }
  .generate-btn { font-size: 0.95rem; padding: 14px 20px; }
  .panel { padding: 20px 16px; max-width: 100%; }
  .result-actions { flex-direction: column; align-items: stretch; }
  .action-btn { justify-content: center; }
  .history-item { padding: 12px; }
  .history-thumb { width: 50px; height: 50px; }
  .modal { padding: 24px 18px; }
  .toast { padding: 12px 20px; font-size: 0.9rem; white-space: normal; max-width: 90%; }
}