:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --secondary: #8b5cf6;

  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border: #334155;
  --gradient: linear-gradient(135deg, var(--primary), var(--secondary));
  --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);

  --font-en: "Inter", sans-serif;
  --font-fa: "Vazirmatn", sans-serif;
}

/* Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
}

body {
  font-family: var(--font-en);
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
}

/* RTL / Persian font */
body[dir="rtl"] {
  font-family: var(--font-fa);
}

/* Ensure form controls inherit font (fix Persian button text) */
button,
input,
textarea,
select {
  font-family: inherit;
}

/* Background Animation */
.bg-animation {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}

.bg-animation::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 20% 80%, rgba(59, 130, 246, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(139, 92, 246, 0.1) 0%, transparent 50%);
  animation: bgMove 20s ease-in-out infinite;
}

@keyframes bgMove {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-5%, 5%);
  }
}

/* Navigation */
nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 1rem 2rem;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  transition: all 0.3s ease;
}

nav.scrolled {
  padding: 0.75rem 2rem;
  box-shadow: var(--shadow);
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-links {
  display: flex;
  gap: 2rem;
  list-style: none;
}

.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s ease;
  position: relative;
}

.nav-links a::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--gradient);
  transition: width 0.3s ease;
}

.nav-links a:hover {
  color: var(--text-primary);
}

.nav-links a:hover::after {
  width: 100%;
}

.lang-switcher {
  display: flex;
  gap: 0.5rem;
}

.lang-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.3s ease;
}

.lang-btn:hover,
.lang-btn.active {
  background: var(--gradient);
  border-color: transparent;
  color: white;
}

.mobile-menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.mobile-menu-btn span {
  width: 25px;
  height: 2px;
  background: var(--text-primary);
  transition: all 0.3s ease;
}

/* Hero Section */
.hero {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8rem 2rem 4rem;
  position: relative;
}

.hero-content {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: center;
}

.hero-text h1 {
  font-size: 3.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  line-height: 1.2;
}

.hero-text h1 span {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-text .subtitle {
  font-size: 1.5rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.hero-text p {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 1.1rem;
}

/* Buttons */
.hero-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn {
  padding: 1rem 2rem;
  border-radius: 0.75rem;
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
  cursor: pointer;
  border: none;
  font-family: inherit;
}

.btn-primary {
  background: var(--gradient);
  color: white;
  box-shadow: 0 10px 30px -10px rgba(59, 130, 246, 0.5);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 40px -10px rgba(59, 130, 246, 0.6);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

.btn-full {
  width: 100%;
  justify-content: center;
}

/* Hero Image */
.hero-image {
  display: flex;
  justify-content: center;
  align-items: center;
}

.profile-container {
  position: relative;
  width: 350px;
  height: 350px;
}

.profile-ring {
  position: absolute;
  top: -20px;
  left: -20px;
  right: -20px;
  bottom: -20px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--gradient) border-box;
  -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: spin 8s linear infinite;
}

@keyframes spin {
  100% {
    transform: rotate(360deg);
  }
}

.profile-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8rem;
  color: white;
  overflow: hidden;
}

.profile-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.floating-icon {
  position: absolute;
  background: var(--bg-card);
  padding: 1rem;
  border-radius: 1rem;
  box-shadow: var(--shadow);
  animation: float 3s ease-in-out infinite;
}

.floating-icon i {
  font-size: 1.5rem;
  color: var(--text-primary);
}

/* floating icons are children 3/4/5 in .profile-container */
.profile-container .floating-icon:nth-child(3) {
  top: 0;
  right: 0;
  animation-delay: 0s;
}
.profile-container .floating-icon:nth-child(4) {
  bottom: 20%;
  right: -10%;
  animation-delay: 1s;
}
.profile-container .floating-icon:nth-child(5) {
  bottom: 0;
  left: 10%;
  animation-delay: 2s;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* Sections */
section {
  padding: 6rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.section-title {
  font-size: 2.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1rem;
}

.section-title span {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.section-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 4rem;
  max-width: 650px;
  margin-left: auto;
  margin-right: auto;
}

/* About */
.about-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: center;
}

.about-text p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  font-size: 1.1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-top: 2rem;
}

.stat-item {
  text-align: center;
  padding: 1.5rem;
  background: var(--bg-card);
  border-radius: 1rem;
  border: 1px solid var(--border);
  transition: all 0.3s ease;
}

.stat-item:hover {
  border-color: var(--primary);
  transform: translateY(-5px);
}

.stat-number {
  font-size: 2.5rem;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* Skills */
.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.skill-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  padding: 2rem;
  transition: all 0.3s ease;
}

.skill-card:hover {
  border-color: var(--primary);
  transform: translateY(-5px);
  box-shadow: var(--shadow);
}

.skill-icon {
  width: 60px;
  height: 60px;
  background: var(--gradient);
  border-radius: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.skill-icon i {
  font-size: 1.5rem;
  color: white;
}

.skill-card h3 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.skill-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.skill-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.skill-tag {
  padding: 0.375rem 0.75rem;
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary);
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
}

/* Projects (updated with bottom source link) */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 2rem;
}

.project-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  overflow: hidden;
  transition: all 0.3s ease;
}

.project-card:hover {
  border-color: var(--primary);
  transform: translateY(-5px);
  box-shadow: var(--shadow);
}

.project-image {
  height: 200px;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.project-image i {
  font-size: 4rem;
  color: rgba(255, 255, 255, 0.28);
}

.project-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.project-card:hover .project-overlay {
  opacity: 1;
}

.project-link {
  width: 50px;
  height: 50px;
  background: var(--gradient);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  text-decoration: none;
  transition: transform 0.3s ease;
}

.project-link:hover {
  transform: scale(1.1);
}

.project-info {
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 200px;
}

.project-info h3 {
  font-size: 1.25rem;
  margin: 0;
}

.project-info p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.7;
}

.project-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.project-source {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;

  padding-top: 0.9rem;
  border-top: 1px solid rgba(148, 163, 184, 0.12);

  color: var(--text-muted);
  font-size: 0.88rem;
  text-decoration: none;

  transition: color 0.25s ease, transform 0.25s ease;
}

.project-source i {
  opacity: 0.9;
}

.project-source:hover {
  color: var(--text-secondary);
  transform: translateY(-1px);
}

body[dir="rtl"] .project-info {
  text-align: right;
}

body[dir="rtl"] .project-source {
  flex-direction: row-reverse;
}

/* Contact */
.contact-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
}

.contact-info h3 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.contact-info p {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.contact-links {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.contact-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  transition: all 0.3s ease;

  /* important: in RTL we want icon + text on the right */
  justify-content: flex-start;
}

.contact-link:hover {
  border-color: var(--primary);
  color: var(--text-primary);
}

.contact-link i {
  width: 40px;
  height: 40px;
  background: var(--gradient);
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

/* This wrapper controls alignment while preserving correct bidi for phone/email */
.contact-text {
  flex: 1;
  text-align: left; /* default for EN/DE */
  color: var(--text-secondary);
}

/* RTL: keep icon on the RIGHT and text aligned right */
body[dir="rtl"] .contact-link {
  direction: rtl;
  justify-content: flex-start;
}

body[dir="rtl"] .contact-text {
  text-align: right;
}

/* Keep phone/email order correct inside RTL */
.contact-text bdi[dir="ltr"] {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
}

/* Contact Form */
.contact-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  padding: 2rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 1rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group textarea {
  min-height: 150px;
  resize: vertical;
}

.field-error {
  margin-top: 0.5rem;
  color: #fca5a5;
  font-size: 0.9rem;
  min-height: 1.1rem;
}

.form-note {
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Footer */
footer {
  padding: 3rem 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
}

.social-links {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.social-link {
  width: 50px;
  height: 50px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.3s ease;
}

.social-link:hover {
  background: var(--gradient);
  border-color: transparent;
  color: white;
  transform: translateY(-3px);
}

.copyright {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 5.25rem;
  right: 1.25rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

body[dir="rtl"] .toast-container {
  right: auto;
  left: 1.25rem;
}

.toast {
  width: min(380px, calc(100vw - 2.5rem));
  background: rgba(30, 41, 59, 0.92);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  overflow: hidden;
  pointer-events: auto;
  transform: translateY(-8px);
  opacity: 0;
  animation: toastIn 200ms ease-out forwards;
}

@keyframes toastIn {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toast-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
}

.toast-icon {
  width: 38px;
  height: 38px;
  border-radius: 0.75rem;
  display: grid;
  place-items: center;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.toast-title {
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.toast-close {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 0.5rem;
}

.toast-close:hover {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-primary);
}

body[dir="rtl"] .toast-close {
  margin-left: 0;
  margin-right: auto;
}

.toast-body {
  padding: 0 1rem 1rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.toast-bar {
  height: 3px;
  background: var(--gradient);
}

.toast.success .toast-icon {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.25);
}

.toast.error .toast-icon {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.25);
}

.toast.warning .toast-icon {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.25);
}

.toast.info .toast-icon {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.25);
}

.toast-out {
  animation: toastOut 180ms ease-in forwards;
}

@keyframes toastOut {
  to {
    transform: translateY(-8px);
    opacity: 0;
  }
}

/* Responsive */
@media (max-width: 968px) {
  .hero-content,
  .about-content,
  .contact-content {
    grid-template-columns: 1fr;
    gap: 3rem;
  }

  .hero-text {
    text-align: center;
  }

  .hero-text h1 {
    font-size: 2.5rem;
  }

  .hero-buttons {
    justify-content: center;
  }

  .profile-container {
    width: 280px;
    height: 280px;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-dark);
    flex-direction: column;
    padding: 2rem;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
  }

  .nav-links.active {
    display: flex;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .stats-grid {
    gap: 1rem;
  }

  .stat-item {
    padding: 1rem;
  }

  .stat-number {
    font-size: 1.75rem;
  }
}

@media (max-width: 640px) {
  .projects-grid {
    grid-template-columns: 1fr;
  }

  .section-title {
    font-size: 2rem;
  }

  .lang-switcher {
    gap: 0.25rem;
  }

  .lang-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}



/* RTL tweaks */
body[dir="rtl"] .hero-buttons {
  flex-direction: row-reverse;
}

/* RTL fix for floating icons positioning */
body[dir="rtl"] .profile-container .floating-icon:nth-child(3) {
  left: 0;
  right: auto;
}
body[dir="rtl"] .profile-container .floating-icon:nth-child(4) {
  left: -10%;
  right: auto;
}
